-
Notifications
You must be signed in to change notification settings - Fork 0
/
x52.py
129 lines (103 loc) · 2.99 KB
/
x52.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#TODO: AxisZone has type checking on its methods which is just begging
# to be converted into a handy util to define valid input combinations.
# Likewise, I bet something interesting could be done to define valid
# values for the objects.
# Essentially, implement a type system...
# How big of a performance hit would it be?
# If it's a big hit, could use it in debug mode and pass through otherwise
class AxisZone(object):
zone = ([int, float], [int, float])
def __init__(self, start, end=None):
'''
# TODO: find a way to declare this programmatically
Can be created passing min,max as a tuple or as separate components
'''
# TODO: this is nice and succinct, but should it use exceptions?
assert start in [int, float, tuple]
if start is not tuple:
assert end in [int, float]
if type(start) is tuple:
zone = start
else:
zone = (start, end)
# we order zone to make the in_zone check simpler
self.zone = sorted(zone)
def in_zone(self, position):
assert position in [int, float]
return self.zone[0] <= position <= self.zone[1]
class Axis(object):
deadzone = AxisZone
maxrange = AxisZone
class Button(object):
pass
class Hat(object):
pass
class Joystick(object):
axes = list
buttons = list
hats = list
class X52(object):
LABELS = {
'axes': [
'up/down',
'left/right',
'throttle',
'small dial',
'top dial',
'rotate left/right',
'slider',
'mouse left/right',
'mouse up/down'
],
'buttons': [
# Buttons on the stick
'trigger',
'fire',
'A',
'B',
'C',
'pinky',
# Buttons on the throttle
'D',
'E',
# The toggle switches on the stick
'T1',
'T2',
'T3',
'T4',
'T5',
'T6',
# The second stage trigger
'second trigger',
# The hat on the top of the stick
'top hat up',
'top hat right',
'top hat down',
'top hat left',
# The hat on the throttle
'throttle hat up',
'throttle hat right',
'throttle hat down',
'throttle hat left',
# The rotary switch
'green',
'orange',
'red',
# The MFD buttons
'function',
'start/stop',
'reset',
# The info button
'info',
# The mouse button
'mouse btn',
# The scroll wheel - the wheel events seem to be flaky, btn is ok
'scroll btn',
'scroll down',
'scroll up'
],
'hats': [
# The main hat on the stick
'central hat'
]
}