Exemplo n.º 1
0
def device_verbose_info(device):
    def axis_name(axis_code):
        try:
            return ecodes.ABS[axis_code]
        except KeyError:
            return 'EXTENDED_CODE_{}'.format(axis_code)

    def rel_axis_name(axis_code):
        try:
            return ecodes.REL[axis_code]
        except KeyError:
            return 'EXTENDED_CODE_{}'.format(axis_code)

    axes = None
    if device.capabilities().get(3) is not None:
        axes = {
            axis_name(axis_code): {
                'code': axis_code,
                'min': axis_info.min,
                'max': axis_info.max,
                'fuzz': axis_info.fuzz,
                'flat': axis_info.flat,
                'res': axis_info.resolution
            }
            for axis_code, axis_info in device.capabilities().get(3)
        }

    rel_axes = None
    if device.capabilities().get(2) is not None:
        print(device.capabilities().get(2))
        rel_axes = {
            axis_name(axis_code): {
                'code': axis_code
            }
            for axis_code in device.capabilities().get(2)
        }

    buttons = None
    if device.capabilities().get(1) is not None:
        buttons = {
            code: names
            for (names, code) in dict(
                util.resolve_ecodes_dict({1: device.capabilities().get(1)
                                          })).get(('EV_KEY', 1))
        }

    return {
        'fn': device.fn,
        'name': device.name,
        'phys': device.phys,
        'uniq': device.uniq,
        'vendor': device.info.vendor,
        'product': device.info.product,
        'version': device.info.version,
        'bus': device.info.bustype,
        'axes': axes,
        'rel_axes': rel_axes,
        'buttons': buttons,
        'unique_name': unique_name(device)
    }
Exemplo n.º 2
0
def test_match_ecodes_a():
    res = util.find_ecodes_by_regex('KEY_ZOOM.*')
    assert res == {1: [372, 418, 419, 420]}
    assert dict(util.resolve_ecodes_dict(res)) == {
        ('EV_KEY', 1): [
            (['KEY_FULL_SCREEN', 'KEY_ZOOM'], 372),
            ('KEY_ZOOMIN', 418),
            ('KEY_ZOOMOUT', 419),
            ('KEY_ZOOMRESET', 420)
        ]
    }

    res = util.find_ecodes_by_regex(r'(ABS|KEY)_BR(AKE|EAK)')
    assert res == {1: [411], 3: [10]}
    assert dict(util.resolve_ecodes_dict(res)) == {
        ('EV_KEY', 1): [('KEY_BREAK', 411)],
        ('EV_ABS', 3): [('ABS_BRAKE', 10)]
    }
Exemplo n.º 3
0
def device_verbose_info(device: InputDevice):
    """
    Gather and format as much info as possible about the supplied InputDevice. Used mostly for debugging at this point.

    :param device:
        An InputDevice to examine
    :return:
        A dict containing as much information as possible about the input device.
    """

    def axis_name(axis_code):
        try:
            return ecodes.ABS[axis_code]
        except KeyError:
            return 'EXTENDED_CODE_{}'.format(axis_code)

    def rel_axis_name(axis_code):
        try:
            return ecodes.REL[axis_code]
        except KeyError:
            return 'EXTENDED_CODE_{}'.format(axis_code)

    axes = None
    if device.capabilities().get(3) is not None:
        axes = {
            axis_name(axis_code): {'code': axis_code, 'min': axis_info.min, 'max': axis_info.max,
                                   'fuzz': axis_info.fuzz,
                                   'flat': axis_info.flat, 'res': axis_info.resolution} for
            axis_code, axis_info in device.capabilities().get(3)}

    rel_axes = None
    if device.capabilities().get(2) is not None:
        print(device.capabilities().get(2))
        rel_axes = {
            rel_axis_name(axis_code): {'code': axis_code} for
            axis_code in device.capabilities().get(2)}

    buttons = None
    if device.capabilities().get(1) is not None:
        buttons = {code: names for (names, code) in
                   dict(util.resolve_ecodes_dict({1: device.capabilities().get(1)})).get(('EV_KEY', 1))}

    return {'fn': device.fn, 'path': device.path, 'name': device.name, 'phys': device.phys, 'uniq': device.uniq,
            'vendor': device.info.vendor, 'product': device.info.product, 'version': device.info.version,
            'bus': device.info.bustype, 'axes': axes, 'rel_axes': rel_axes, 'buttons': buttons,
            'unique_name': unique_name(device)}
Exemplo n.º 4
0
    def capabilities(self, verbose=False, absinfo=True):
        '''
        Return the event types that this device supports as a mapping of
        supported event types to lists of handled event codes.

        Example
        --------
        >>> device.capabilities()
        { 1: [272, 273, 274],
          2: [0, 1, 6, 8] }

        If ``verbose`` is ``True``, event codes and types will be resolved
        to their names.

        ::

          { ('EV_KEY', 1): [('BTN_MOUSE', 272),
                            ('BTN_RIGHT', 273),
                            ('BTN_MIDDLE', 273)],
            ('EV_REL', 2): [('REL_X', 0),
                            ('REL_Y', 1),
                            ('REL_HWHEEL', 6),
                            ('REL_WHEEL', 8)] }

        Unknown codes or types will be resolved to ``'?'``.

        If ``absinfo`` is ``True``, the list of capabilities will also
        include absolute axis information in the form of
        :class:`AbsInfo` instances::

          { 3: [ (0, AbsInfo(min=0, max=255, fuzz=0, flat=0)),
                 (1, AbsInfo(min=0, max=255, fuzz=0, flat=0)) ]}

        Combined with ``verbose`` the above becomes::

          { ('EV_ABS', 3): [ (('ABS_X', 0), AbsInfo(min=0, max=255, fuzz=0, flat=0)),
                             (('ABS_Y', 1), AbsInfo(min=0, max=255, fuzz=0, flat=0)) ]}

        '''

        if verbose:
            return dict(util.resolve_ecodes_dict(self._capabilities(absinfo)))
        else:
            return self._capabilities(absinfo)
Exemplo n.º 5
0
    def capabilities(self, verbose=False, absinfo=True):
        '''
        Return the event types that this device supports as a mapping of
        supported event types to lists of handled event codes.

        Example
        --------
        >>> device.capabilities()
        { 1: [272, 273, 274],
          2: [0, 1, 6, 8] }

        If ``verbose`` is ``True``, event codes and types will be resolved
        to their names.

        ::

          { ('EV_KEY', 1): [('BTN_MOUSE', 272),
                            ('BTN_RIGHT', 273),
                            ('BTN_MIDDLE', 273)],
            ('EV_REL', 2): [('REL_X', 0),
                            ('REL_Y', 1),
                            ('REL_HWHEEL', 6),
                            ('REL_WHEEL', 8)] }

        Unknown codes or types will be resolved to ``'?'``.

        If ``absinfo`` is ``True``, the list of capabilities will also
        include absolute axis information in the form of
        :class:`AbsInfo` instances::

          { 3: [ (0, AbsInfo(min=0, max=255, fuzz=0, flat=0)),
                 (1, AbsInfo(min=0, max=255, fuzz=0, flat=0)) ]}

        Combined with ``verbose`` the above becomes::

          { ('EV_ABS', 3): [ (('ABS_X', 0), AbsInfo(min=0, max=255, fuzz=0, flat=0)),
                             (('ABS_Y', 1), AbsInfo(min=0, max=255, fuzz=0, flat=0)) ]}

        '''

        if verbose:
            return dict(util.resolve_ecodes_dict(self._capabilities(absinfo)))
        else:
            return self._capabilities(absinfo)