def _build_button_map(self, config):
"""
Returns button map readed from configuration, in format situable
for HIDDecoder.buttons.button_map field.
Generates default if config is not available.
"""
if config:
# Last possible value is default "maps-to-nothing" mapping
buttons = [BUTTON_COUNT - 1] * BUTTON_COUNT
for keycode, value in config.get('buttons', {}).items():
keycode = int(keycode) - FIRST_BUTTON
if keycode < 0 or keycode >= BUTTON_COUNT:
# Out of range
continue
if value in TRIGGERS:
# Not used here
pass
else:
buttons[keycode] = self.button_to_bit(getattr(SCButtons, value))
else:
buttons = list(xrange(BUTTON_COUNT))
return (ctypes.c_uint8 * BUTTON_COUNT)(*buttons)
评论列表
文章目录