'Logitech Logitech RumblePad 2 USB'
]
-config1 = {
+config = {
"deadband": 0.1,
- "axes": [ABS_X, ABS_Y, ABS_RY, ABS_RX],
- "dir": [1, -1, -1, 1],
- "arrows": [ABS_HAT0X, ABS_HAT0Y],
- "speed": [0x133, 0x130, 0x131, 0x134],
- "lock": [0x136, 0x137],
-}
-
-config2 = {
- "deadband": 0.1,
- "axes": [ABS_X, ABS_Y, ABS_RZ, ABS_Z],
- "dir": [1, -1, -1, 1],
- "arrows": [ABS_HAT0X, ABS_HAT0Y],
- "speed": [0x120, 0x121, 0x122, 0x123],
- "lock": [0x124, 0x125],
+ "axes": [[ABS_X], [ABS_Y], [ABS_RY, ABS_RZ], [ABS_RX, ABS_Z]],
+ "dir": [1, -1, -1, 1],
+ "arrows": [[ABS_HAT0X], [ABS_HAT0Y]],
+ "speed": [[0x133, 0x120], [0x130, 0x121], [0x131, 0x122], [0x134, 0x123]],
+ "lock": [[0x136, 0x124], [0x137, 0x125]],
}
# From JobHandler
- def get_config(self, name):
- if name in type2: return config2
+ def match_code(self, type, code):
+ if not type in config: return None
+
+ index = 0
+ for codes in config[type]:
+ if code in codes: return index
+ index += 1
+
+
+ def get_config(self, type): return config[type]
+
- # Microsoft X-Box 360 pad
- # Logitech Gamepad F310
- return config1
+ def has_code(self, type, code):
+ return self.match_code(type, code) is not None
def up(self): self.ctrl.lcd.page_up()
self.changed()
- def get_config(self, name): raise Exception('No configs')
+ def get_config(self, type): raise Exception('Not implemented')
+ def match_code(self, type, code): raise Exception('Not implemented')
+ def has_code(self, type, code): raise Exception('Not implemented')
def event(self, event, state, dev_name):
if event.type not in [EV_ABS, EV_REL, EV_KEY]: return
- config = self.get_config(dev_name)
changed = False
+ old_axes = list(self.axes)
# Process event
- if event.type == EV_ABS and event.code in config['axes']:
- pass
+ if event.type == EV_ABS and self.has_code('axes', event.code):
+ axis = self.match_code('axes', event.code)
+
+ self.axes[axis] = event.stream.state.abs[event.code]
+ self.axes[axis] *= self.get_config('dir')[axis]
+
+ if abs(self.axes[axis]) < self.get_config('deadband'):
+ self.axes[axis] = 0
+
+ if self.horizontal_lock and axis not in [0, 3]:
+ self.axes[axis] = 0
+
+ if self.vertical_lock and axis not in [1, 2]:
+ self.axes[axis] = 0
+
+ if old_axes[axis] != self.axes[axis]: changed = True
- elif event.type == EV_ABS and event.code in config['arrows']:
- axis = config['arrows'].index(event.code)
+ elif event.type == EV_ABS and self.has_code('arrows', event.code):
+ axis = self.match_code('arrows', event.code)
if event.value < 0:
if axis == 1: self.up()
if axis == 1: self.down()
else: self.right()
- elif event.type == EV_KEY and event.code in config['speed']:
+ elif event.type == EV_KEY and self.has_code('speed', event.code):
old_speed = self.speed
- self.speed = config['speed'].index(event.code) + 1
+ self.speed = self.match_code('speed', event.code) + 1
if self.speed != old_speed: changed = True
- elif event.type == EV_KEY and event.code in config['lock']:
- index = config['lock'].index(event.code)
+ elif event.type == EV_KEY and self.has_code('lock', event.code):
+ index = self.match_code('lock', event.code)
self.horizontal_lock, self.vertical_lock = False, False
self.log.debug(event_to_string(event, state))
- # Update axes
- old_axes = list(self.axes)
-
- for axis in range(4):
- self.axes[axis] = event.stream.state.abs[config['axes'][axis]]
- self.axes[axis] *= config['dir'][axis]
-
- if abs(self.axes[axis]) < config['deadband']:
- self.axes[axis] = 0
-
- if self.horizontal_lock and axis not in [0, 3]:
- self.axes[axis] = 0
-
- if self.vertical_lock and axis not in [1, 2]:
- self.axes[axis] = 0
-
- if old_axes != self.axes: changed = True
-
if changed: self.changed()