-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskript pro lorris na joystick.py
74 lines (56 loc) · 2.41 KB
/
skript pro lorris na joystick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Joystick example
joySelect = None
joystick = None
# Called on axes change. "axes" is Array of ints with ids of axes which were changed
def axesChanged(axes):
terminal.appendText("Axes changed: " + str(axes) + "\n");
res = "";
hodnoty = [0x80]
for i in range(0, joystick.getNumAxes()):
hodnoty.append(joystick.getAxisVal(i)>>8 )
res += str(i) + ": " + str(joystick.getAxisVal(i)) + ", "; # SEE THIS: Get actual axis value. From -32768 to 32767
terminal.appendText(res + "\n\n");
lorris.sendData(hodnoty)
# Called when button status is changed, for each button separatedly
# Pressed: state == 1
def buttonChanged(id, state):
terminal.appendText("Button " + str(id) + ", state " + str(state) + "\n");
lorris.sendData([0x81, id, state])
def dumpJoyInfo():
res = "Joystick Id: " + str(joystick.getId()) + "\n";
res += "Number of axes: " + str(joystick.getNumAxes()) + "\n";
res += "Number of buttons: " + str(joystick.getNumButtons()) + "\n";
# To get axis value, use joystick.getAxisVal(id);
# To get button state, use joystick.getButtonVal(id);
terminal.appendText(res);
def joystick_selected(idx):
global joystick;
if idx == -1:
return;
terminal.appendText("Joystick \"" + joySelect.currentText + "\" selected\n");
if joystick != None:
lorris.closeJoystick(joystick);
id_list = lorris.getJoystickIds();
joystick = lorris.getJoystick(id_list[idx]);
# If you don't wanna let user select the joystick and just
# grab the first one, you can use getFirstJoystick() function.
#joystick = lorris.getFirstJoystick()
if joystick != None:
# connect to signals
joystick.connect("axesChanged(QList<int>)", axesChanged);
joystick.connect("buttonChanged(int, quint8)", buttonChanged);
# SEE THIS: signal timer - maximal frequency of signals, default is 50 ms
joystick.setSignalTimer(50);
dumpJoyInfo();
def init():
global joySelect
terminal.clear();
# create input widget and joystick selection
inputW = lorris.newWidget(WIDGET_INPUT, "Joystick", 200, 80, script.width+20, 0);
label = inputW.newWidget("QLabel", 1);
label.setText("Select joystick:");
joySelect = inputW.newWidget("QComboBox");
joySelect.connect("currentIndexChanged(int)", joystick_selected);
# Add joystick names
lorris.AddComboBoxItems(joySelect, lorris.getJoystickNames());
init()