
    i2                        d dl Z d dlZd dlmZmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZmZ 	 ddlmZmZ  e
dee      Z G d de      Z G d	 d
e      Z G d de      Z G d deee         Zy# e$ r ddlmZmZ Y Jw xY w)    N)
DictGenericIteratorListLiteral
NamedTupleTupleTypeVarUnionoverload   )_inputecodesutil)
EvdevErrorEventIO_AnyStrc                   T    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   d Zy	)
AbsInfoa  Absolute axis information.

    A ``namedtuple`` with absolute axis information -
    corresponds to the ``input_absinfo`` struct:

    Attributes
    ---------
    value
      Latest reported value for the axis.

    min
      Specifies minimum value for the axis.

    max
      Specifies maximum value for the axis.

    fuzz
      Specifies fuzz value that is used to filter noise from the
      event stream.

    flat
      Values that are within this value will be discarded by joydev
      interface and reported as 0 instead.

    resolution
      Specifies resolution for the values reported for the axis.
      Resolution for main axes (``ABS_X, ABS_Y, ABS_Z``) is reported
      in units per millimeter (units/mm), resolution for rotational
      axes (``ABS_RX, ABS_RY, ABS_RZ``) is reported in units per
      radian.

    Note
    ----
    The input core does not clamp reported values to the ``[minimum,
    maximum]`` limits, such task is left to userspace.

    valueminmaxfuzzflat
resolutionc                       dj                   |  S )Nz2value {}, min {}, max {}, fuzz {}, flat {}, res {}formatselfs    V/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/evdev/device.py__str__zAbsInfo.__str__=   s    JCJJDQQ    N__name__
__module____qualname____doc__int__annotations__r"    r#   r!   r   r      s.    $L J	H	H
I
IORr#   r   c                   ,    e Zd ZU dZeed<   eed<   d Zy)KbdInfozKeyboard repeat rate.

    Attributes
    ----------
    delay
      Amount of time that a key must be depressed before it will start
      to repeat (in milliseconds).

    repeat
      Keyboard repeat rate in characters per second.
    delayrepeatc                 N    dj                  | j                  | j                        S )Nzdelay {}, repeat {})r   r.   r/   r   s    r!   r"   zKbdInfo.__str__Q   s    $++DJJDDr#   Nr$   r+   r#   r!   r-   r-   A   s    
 JKEr#   r-   c                   F    e Zd ZU dZeed<   eed<   eed<   eed<   defdZy)	
DeviceInfozR
    Attributes
    ----------
    bustype
    vendor
    product
    version
    bustypevendorproductversionreturnc                 $    d} |j                   |  S )Nz:bus: {:04x}, vendor {:04x}, product {:04x}, version {:04x}r   r    msgs     r!   r"   zDeviceInfo.__str__d   s    Jszz4  r#   N)r%   r&   r'   r(   r)   r*   strr"   r+   r#   r!   r2   r2   U   s)     LKLL! !r#   r2   c                   <    e Zd ZdZdZdeedf   fdZd&dZd'd
e	fdZ
ed(ded   d
e	deeee   f   fd       Zed)ded	   d
e	deeeef   eeeef      f   fd       Zd*de	d
e	deeeee   f   eeeef   eeeef      f   f   fdZd+de	fdZd+de	fdZdededdfdZd ZdefdZdefdZd Zd& fdZd&dZd&dZej<                  ded   fd       Z d,dZ!d&dZ"e#d         Z$e$jJ                  deeef   fd!       Z$d+de	fd"Z&d#efd$Z'd-d#eddfd%Z( xZ)S ).InputDevicezC
    A linux input device from which input events can be read.
    )	pathfdinfonamephysuniq_rawcapabilitiesr6   ff_effects_countdevzos.PathLike[_AnyStr]c                    t        |d      s|n|j                         | _        	 t        j                  |t        j
                  t        j                  z        }|| _	        t        j                  | j                        }t        |dd  | _        |d   | _        |d   | _        |d   | _        t        j"                  | j                        | _        t        j&                  | j                        | _        t        j*                  | j                        | _        y# t        $ r9 t        j                  |t        j                  t        j                  z        }Y w xY w)zm
        Arguments
        ---------
        dev : str|bytes|PathLike
          Path to input device
        
__fspath__N         )hasattrrH   r>   osopenO_RDWR
O_NONBLOCKOSErrorO_RDONLYr?   r   ioctl_devinfor2   r@   rA   rB   rC   ioctl_EVIOCGVERSIONr6   ioctl_capabilitiesrD   ioctl_EVIOCGEFFECTSrE   )r    rF   r?   info_ress       r!   __init__zInputDevice.__init__p   s    )0\(BSHX		;bii"--78B
  ''0 !-	 "!	 "!	 "!	 #66tww? !' 9 9$'' B !' : :477 C9  	;bkkBMM9:B	;s   5D >EEr7   Nc                     t        | d      r| j                  	 | j                          y y y # t        t        t
        f$ r Y y w xY w)Nr?   )rL   r?   closerQ   ImportErrorAttributeErrorr   s    r!   __del__zInputDevice.__del__   sF    4477#6

 $7 [.9 s   - AATabsinfoc                 8   i }| j                   j                         D ]z  \  }}|D ]p  }|j                  |g       }t        |t              r;|r$|d   }t        | }|j                  |d   |f       K|j                  |d          `|j                  |       r | |S )Nr   r   )rD   items
setdefault
isinstancetupler   append)	r    r^   resetype_ecodescodelais	            r!   _capabilitieszInputDevice._capabilities   s    "3399; 	#NE7 
#NN5"-dE* G#QK$q'1.a)HHTN
#	# 
r#   verboseFc                      y Nr+   r    rm   r^   s      r!   capabilitieszInputDevice.capabilities       r#   c                      y ro   r+   rp   s      r!   rq   zInputDevice.capabilities   rr   r#   c                     |r-t        t        j                  | j                  |                  S | j                  |      S )a  
        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)) ]}

        )dictr   resolve_ecodes_dictrl   rp   s      r!   rq   zInputDevice.capabilities   s:    P 001C1CG1LMNN%%g..r#   c                     t        j                  | j                        }|r$t        j                  t
        j                  |      S |S )aO  
        Get device properties and quirks.

        Example
        -------
        >>> device.input_props()
        [0, 5]

        If ``verbose`` is ``True``, input properties are resolved to their
        names. Unknown codes are resolved to ``'?'``::

        [('INPUT_PROP_POINTER', 0), ('INPUT_PROP_POINTING_STICK', 5)]

        )r   ioctl_EVIOCGPROPr?   r   resolve_ecodesr   
INPUT_PROP)r    rm   propss      r!   input_propszInputDevice.input_props   s9     ''0&&v'8'8%@@r#   c                     t        j                  | j                  t        j                        }|r$t        j                  t        j                  |      S |S )aN  
        Return currently set LED keys.

        Example
        -------
        >>> device.leds()
        [0, 1, 8, 9]

        If ``verbose`` is ``True``, event codes are resolved to their
        names. Unknown codes are resolved to ``'?'``::

        [('LED_NUML', 0), ('LED_CAPSL', 1), ('LED_MISC', 8), ('LED_MAIL', 9)]

        )r   ioctl_EVIOCG_bitsr?   r   EV_LEDr   ry   LED)r    rm   ledss      r!   r   zInputDevice.leds   s=     ''?&&vzz488r#   led_numr   c                 F    | j                  t        j                  ||       y)z
        Set the state of the selected LED.

        Example
        -------
        >>> device.set_led(ecodes.LED_NUML, 1)
        N)writer   r   )r    r   r   s      r!   set_ledzInputDevice.set_led  s     	

6=='51r#   c                     t        || j                        xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )zS
        Two devices are equal if their :data:`info` attributes are equal.
        )rb   	__class__r@   r>   )r    others     r!   __eq__zInputDevice.__eq__  s?     %0hTYY%**5LhQUQZQZ^c^h^hQhhr#   c                     d}|j                  | j                  | j                  | j                  | j                  xs d      S )Nz*device {}, name "{}", phys "{}", uniq "{}" )r   r>   rA   rB   rC   r9   s     r!   r"   zInputDevice.__str__"  s0    :zz$))TYY		499?KKr#   c                 d    | j                   j                  | j                  f} dj                  | S )Nz{}({!r}))r   r%   r>   r   r9   s     r!   __repr__zInputDevice.__repr__&  s-    ~~&&		2 z  #&&r#   c                     | j                   S ro   )r>   r   s    r!   rH   zInputDevice.__fspath__*  s    yyr#   c                     | j                   dkD  r6	 t        | 	          t        j                  | j                          d| _         y y # d| _         w xY w)N)r?   superrZ   rM   )r    r   s    r!   rZ   zInputDevice.close-  sC    77R<! 
 s   -A 	Ac                 D    t        j                  | j                  d       y)a9  
        Grab input device using ``EVIOCGRAB`` - other applications will
        be unable to receive events until the device is released. Only
        one process can hold a ``EVIOCGRAB`` on a device.

        Warning
        -------
        Grabbing an already grabbed device will raise an ``OSError``.
        r   Nr   ioctl_EVIOCGRABr?   r   s    r!   grabzInputDevice.grab5  s     	tww*r#   c                 D    t        j                  | j                  d       y)z
        Release device if it has been already grabbed (uses `EVIOCGRAB`).

        Warning
        -------
        Releasing an already released device will raise an
        ``OSError('Invalid argument')``.
        r   Nr   r   s    r!   ungrabzInputDevice.ungrabB  s     	tww*r#   c              #   T   K   | j                          d | j                          yw)z
        A context manager for the duration of which only the current
        process will be able to receive events from the device.
        N)r   r   r   s    r!   grab_contextzInputDevice.grab_contextN  s      			s   &(c                 x    t        |      j                         }t        j                  | j                  |      }|S )zL
        Upload a force feedback effect to a force feedback device.
        )
memoryviewtobytesr   upload_effectr?   )r    effectdataff_ids       r!   r   zInputDevice.upload_effectX  s2    
 &!))+$$TWWd3r#   c                 D    t        j                  | j                  |       y)zh
        Erase a force effect from a force feedback device. This also
        stops the effect.
        N)r   erase_effectr?   )r    r   s     r!   r   zInputDevice.erase_effecta  s     	DGGU+r#   c                 L    t        t        j                  | j                         S )zu
        Get or set the keyboard repeat rate (in characters per
        minute) and delay (in milliseconds).
        )r-   r   ioctl_EVIOCGREPr?   r   s    r!   r/   zInputDevice.repeati  s     ..tww788r#   c                 B    t        j                  | j                  g| S ro   )r   ioctl_EVIOCSREPr?   )r    r   s     r!   r/   zInputDevice.repeatr  s    %%dgg666r#   c                     t        j                  | j                  t        j                        }|r$t        j                  t        j                  |      S |S )aO  
        Return currently active keys.

        Example
        -------

        >>> device.active_keys()
        [1, 42]

        If ``verbose`` is ``True``, key codes are resolved to their
        verbose names. Unknown codes are resolved to ``'?'``. For
        example::

          [('KEY_ESC', 1), ('KEY_LEFTSHIFT', 42)]

        )r   r~   r?   r   EV_KEYr   ry   KEY)r    rm   active_keyss      r!   r   zInputDevice.active_keysv  s>    " ..twwF&&vzz;??r#   axis_numc                 N    t        t        j                  | j                  |       S )aX  
        Return current :class:`AbsInfo` for input device axis

        Arguments
        ---------
        axis_num : int
          EV_ABS keycode (example :attr:`ecodes.ABS_X`)

        Example
        -------
        >>> device.absinfo(ecodes.ABS_X)
        AbsInfo(value=1501, min=-32768, max=32767, fuzz=0, flat=128, resolution=0)
        )r   r   ioctl_EVIOCGABSr?   )r    r   s     r!   r^   zInputDevice.absinfo  s      ..twwABBr#   c                 0   | j                  |      }t        ||n|j                  ||n|j                  ||n|j                  ||n|j
                  ||n|j                  ||n|j                        }	t        j                  | j                  ||	       y)a  
        Update :class:`AbsInfo` values. Only specified values will be overwritten.

        Arguments
        ---------
        axis_num : int
          EV_ABS keycode (example :attr:`ecodes.ABS_X`)

        Example
        -------
        >>> device.set_absinfo(ecodes.ABS_X, min=-2000, max=2000)

        You can also unpack AbsInfo tuple that will overwrite all values

        >>> device.set_absinfo(ecodes.ABS_Y, *AbsInfo(0, -2000, 2000, 0, 15, 0))
        N)r^   r   r   r   r   r   r   r   r   ioctl_EVIOCSABSr?   )
r    r   r   r   r   r   r   r   cur_absinfonew_absinfos
             r!   set_absinfozInputDevice.set_absinfo  s    $ ll8,&EK,=,=?C?C$D+*:*:$D+*:*:$0Jk6L6L
 	tww+>r#   )r7   N)T)..).)FT)F)r   z	ff.Effect)NNNNNN)*r%   r&   r'   r(   	__slots__r   r   rX   r]   boolrl   r   r   r   r)   r   rq   r	   r;   r|   r   r   r   r"   r   rH   rZ   r   r   
contextlibcontextmanagerr   r   r   r   propertyr/   setterr   r^   r   __classcell__)r   s   @r!   r=   r=   i   s]    rI*DE'+A"AB *DXT $ GEN 4 RVWZ\`ad\eWeRf  GDM D 4PUVY[^V^P_aefkloqtltfuavPvKw  +/D +/4 +/5QUVY[_`c[dVdQegklqruwzrzl{  ~B  CH  IL  NQ  IQ  CR  ~S  mS  hT  RT  LU +/Z4 *D *2s 23 24 2iL L'# '+
+ htn  , 9 9 ]]7E#s(O 7 74 .C C ?C ?sw ?r#   r=   )r   rM   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   eventio_asyncr   r   r[   eventior;   bytesr   r   r-   r2   r=   r+   r#   r!   <module>r      s     	 f f f " "-2 )S%
(/Rj /RdEj E(! !(O?'77+ O?A  -,,-s   A/ /A?>A?