Esempio n. 1
0
def _create_control(properties):
    type = get_property(properties, 'Type')
    if type not in (kIOHIDElementTypeInput_Misc,
                    kIOHIDElementTypeInput_Axis, 
                    kIOHIDElementTypeInput_Button):
        return

    cookie = get_property(properties, 'ElementCookie')
    usage_page = get_property(properties, 'UsagePage')
    usage = get_property(properties, 'Usage')
    raw_name = get_property(properties, 'Name')
    if not raw_name:
        raw_name = '%d:%d' % (usage_page, usage)

    if type in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis):
        name = _axis_names.get((usage_page, usage))
        relative = get_property(properties, 'IsRelative')
        if relative:
            control = RelativeAxis(name, raw_name)
        else:
            min = get_property(properties, 'Min')
            max = get_property(properties, 'Max')
            control = AbsoluteAxis(name, min, max, raw_name)
    elif type == kIOHIDElementTypeInput_Button:
        name = _button_names.get((usage_page, usage))
        control = Button(name, raw_name)
    else:
        return

    control._cookie = cookie
    return control
Esempio n. 2
0
def _create_control(properties):
    type = get_property(properties, 'Type')
    if type not in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis,
                    kIOHIDElementTypeInput_Button):
        return

    cookie = get_property(properties, 'ElementCookie')
    usage_page = get_property(properties, 'UsagePage')
    usage = get_property(properties, 'Usage')
    raw_name = get_property(properties, 'Name')
    if not raw_name:
        raw_name = '%d:%d' % (usage_page, usage)

    if type in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis):
        name = _axis_names.get((usage_page, usage))
        relative = get_property(properties, 'IsRelative')
        if relative:
            control = RelativeAxis(name, raw_name)
        else:
            min = get_property(properties, 'Min')
            max = get_property(properties, 'Max')
            control = AbsoluteAxis(name, min, max, raw_name)
    elif type == kIOHIDElementTypeInput_Button:
        name = _button_names.get((usage_page, usage))
        control = Button(name, raw_name)
    else:
        return

    control._cookie = cookie
    return control
Esempio n. 3
0
def _create_control(properties):
    type = get_property(properties, "Type")
    if type not in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis, kIOHIDElementTypeInput_Button):
        return

    cookie = get_property(properties, "ElementCookie")
    usage_page = get_property(properties, "UsagePage")
    usage = get_property(properties, "Usage")
    raw_name = get_property(properties, "Name")
    if not raw_name:
        raw_name = "%d:%d" % (usage_page, usage)

    if type in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis):
        name = _axis_names.get((usage_page, usage))
        relative = get_property(properties, "IsRelative")
        if relative:
            control = RelativeAxis(name, raw_name)
        else:
            min = get_property(properties, "Min")
            max = get_property(properties, "Max")
            control = AbsoluteAxis(name, min, max, raw_name)
    elif type == kIOHIDElementTypeInput_Button:
        name = _button_names.get((usage_page, usage))
        control = Button(name, raw_name)
    else:
        return

    control._cookie = cookie
    return control
Esempio n. 4
0
def _create_control(fileno, event_type, event_code):
    if event_type == EV_ABS:
        raw_name = _abs_raw_names.get(event_code, 'EV_ABS(%x)' % event_code)
        name = _abs_names.get(event_code)
        absinfo = EVIOCGABS(fileno, event_code)
        value = absinfo.value
        min = absinfo.minimum
        max = absinfo.maximum
        control = AbsoluteAxis(name, min, max, raw_name)
        control._set_value(value)

        if name == 'hat_y':
            control.inverted = True
    elif event_type == EV_REL:
        raw_name = _rel_raw_names.get(event_code, 'EV_REL(%x)' % event_code)
        name = _rel_names.get(event_code)
        # TODO min/max?
        control = RelativeAxis(name, raw_name)
    elif event_type == EV_KEY:
        raw_name = _key_raw_names.get(event_code, 'EV_KEY(%x)' % event_code)
        name = None
        control = Button(name, raw_name)
    else:
        value = min = max = 0  # TODO
        return None
    control._event_type = event_type
    control._event_code = event_code
    return control
Esempio n. 5
0
    def _create_controls(self):
        self._controls = {}
        for element in self.device.elements:
            raw_name = element.name or "0x%x:%x" % (element.usagePage, element.usage)
            if element.type in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis):
                name = _axis_names.get((element.usagePage, element.usage))
                if element.isRelative:
                    control = RelativeAxis(name, raw_name)
                else:
                    control = AbsoluteAxis(name, element.logicalMin, element.logicalMax, raw_name)
            elif element.type == kIOHIDElementTypeInput_Button:
                name = _button_names.get((element.usagePage, element.usage))
                control = Button(name, raw_name)
            else:
                continue

            control._cookie = element.cookie
            self._controls[control._cookie] = control
Esempio n. 6
0
 def _create_controls(self):
     self._controls = {}
     for element in self.device.elements:
         raw_name = element.name or '0x%x:%x' % (element.usagePage, element.usage)
         if element.type in (kIOHIDElementTypeInput_Misc, kIOHIDElementTypeInput_Axis):
             name = _axis_names.get((element.usagePage, element.usage))
             if element.isRelative:
                 control = RelativeAxis(name, raw_name)
             else:
                 control = AbsoluteAxis(name, element.logicalMin, element.logicalMax, raw_name)
         elif element.type == kIOHIDElementTypeInput_Button:
             name = _button_names.get((element.usagePage, element.usage))
             control = Button(name, raw_name)
         else:
             continue
         
         control._cookie = element.cookie
         self._controls[control._cookie] = control