legoEv3/ev3dev2/__pycache__/button.cpython-35.pyc



h ^[p)ã@s9ddlZejdkr'edƒ‚ddlZddlZddlZddlmZmZej    e
ƒZyddlZWn(e
k
rªejeddƒƒYnXyddlZWn(e
k
råejed    dƒƒYnXeƒZed
krddlmZmZnÉedkr9ddlmZmZn¤ed
kr^ddlmZmZnedkrƒddlmZmZnZedkr¨ddlmZmZn5edkrÍddlmZmZnedeƒ‚Gdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)éNééz"Must be using Python 3.4 or higheré)Úget_current_platformÚlibrary_load_warning_messageÚfcntlÚButtonÚevdevZev3)ÚBUTTONS_FILENAMEÚEVDEV_DEVICE_NAMEZevbZpistormsZbrickpiZbrickpi3ZfakezUnsupported platform '%s'c@seZdZdS)Ú
MissingButtonN)Ú__name__Ú
__module__Ú__qualname__©rrú0/usr/lib/python3/dist-packages/ev3dev2/button.pyrPsrc@sÓeZdZdZegƒZdd„Zedd„ƒZdd„Z    gdd    „Z
ed
d„ƒZdd
d„Z
dd„Zedd„ƒZdd„Zddd„Zddd„Zddd„ZdS)Ú
ButtonBasez$
    Abstract button interface.
    cCs
|jjS)N)Ú    __class__r
)ÚselfrrrÚ__str__ZszButtonBase.__str__cCsdS)zÝ
        This handler is called by `process()` whenever state of any button has
        changed since last `process()` call. `changed_buttons` is a list of
        tuples of changed button names and their states.
        Nr)Zchanged_buttonsrrrÚ    on_change]szButtonBase.on_changecCs
t|jƒS)z2
        Checks if any button is pressed.
        )ÚboolÚbuttons_pressed)rrrrÚanyfszButtonBase.anycCst|jƒt|ƒkS)zR
        Check if currently pressed buttons exactly match the given list.
        )Úsetr)rÚbuttonsrrrÚ
check_buttonslszButtonBase.check_buttonscCs]dd„tjƒDƒ}x$|D]}|j|jkr |Sq Wtd||jfƒ‚dS)z>
        Return our corresponding evdev device object
        cSsg|]}tj|ƒ‘qSr)r    ZInputDevice)Ú.0Úfnrrrú
<listcomp>ws    z+ButtonBase.evdev_device.<locals>.<listcomp>z$%s: could not find evdev device '%s'N)r    Zlist_devicesÚnameÚevdev_device_nameÚ    Exception)rZdevicesZdevicerrrÚevdev_devicers

zButtonBase.evdev_deviceNcsµˆdkrt|jƒ‰|j}ˆ|_ˆj|ƒ}x=|D]5}t|d|ƒ}|dk    rC||ˆkƒqCW|jdk    r±|r±|j‡fdd†|DƒƒdS)z–
        Check for currenly pressed buttons. If the new state differs from the
        old state, call the appropriate button event handlers.
        NZon_cs"g|]}||ˆkf‘qSrr)rÚbutton)Ú    new_staterrr‘s    z&ButtonBase.process.<locals>.<listcomp>)rrÚ_stateÚsymmetric_differenceÚgetattrr)rr%Z    old_stateZ
state_diffr$Zhandlerr)r%rÚprocesss        
zButtonBase.processcCs=x6|jjƒD]%}|jtjjkr|jƒqWdS)N)r#Ú    read_loopÚtyper    ÚecodesÚEV_KEYr))rÚeventrrrÚprocess_forever“szButtonBase.process_forevercCs
tƒ‚dS)N)ÚNotImplementedError)rrrrr˜szButtonBase.buttons_pressedc
Cstjƒ}t|tƒr$|g}t|tƒr<|g}xÃ|jjƒD]²}|jtjjkrLd}d}|j    }x!|D]}    |    |krƒd}PqƒWx!|D]}    |    |kr§d}Pq§W|rÔ|rÔdS|dk    rLtjƒ||dkrLdSqLWdS)NTFiè)
ÚtimeÚ
isinstanceÚstrr#r*r+r    r,r-r)
rZwait_for_button_pressZwait_for_button_releaseÚ
timeout_msZticr.Zall_pressedZall_releasedÚpressedr$rrrÚ_waitœs,            

&zButtonBase._waitcCs|j|g|ƒS)N)r6)rrr4rrrÚwait_for_pressed¾szButtonBase.wait_for_pressedcCs|jg||ƒS)N)r6)rrr4rrrÚwait_for_releasedÁszButtonBase.wait_for_releasedcCs\tjƒ}|j||ƒrX|dk    rH|ttjƒ|dƒ8}|j||ƒSdS)z
        Wait for the button to be pressed down and then released.
        Both actions must happen within timeout_ms.
        NièF)r1r7Úintr8)rrr4Z
start_timerrrÚ
wait_for_bumpÄszButtonBase.wait_for_bump)r
rrÚ__doc__rr&rÚstaticmethodrrrÚpropertyr#r)r/rr6r7r8r:rrrrrTs    
"rc@sŒeZdZdZdZeeddƒZded>Bedƒd>BdBZiZ    d    d
„Z
dd„Zd
d„Ze
dd„ƒZdS)Ú
ButtonEVIOaV
    Provides a generic button reading mechanism that works with event interface
    and may be adapted to platform specific implementations.

    This implementation depends on the availability of the EVIOCGKEY ioctl
    to be able to read the button state buffer. See Linux kernel source
    in /include/uapi/linux/input.h for details.
    iÿééééÚEécCs¯tj|ƒi|_i|_x‰|jD]~}|j|d}|dkr\td|ƒ‚||jkr)t|ddƒ|j|<tjddg|jƒ|j|<q)WdS)Nr z-Button '%s' is not available on this platformÚrbrÚB)    rÚ__init__Ú_file_cacheÚ
_buffer_cacheÚ_buttonsrÚopenÚarrayÚKEY_BUF_LEN)rÚbr rrrrGãs
        zButtonEVIO.__init__cCs|j|S)N)rH)rr rrrÚ_button_fileòszButtonEVIO._button_filecCs|j|S)N)rI)rr rrrÚ_button_bufferõszButtonEVIO._button_buffercCs²x7|jD],}tj|j|ƒ|j|j|ƒq
Wg}xk|jjƒD]Z\}}|j|d}|d}t|t|dƒd|d>@ƒrP|j    |ƒqPW|S)z;
        Returns list of names of pressed buttons.
        r Úvaluer@r)
rIrZioctlrOÚ    EVIOCGKEYrJÚitemsrr9Úappend)rrNr5ÚkÚvZbufZbitrrrrøs*
&zButtonEVIO.buttons_pressedNéélé)r
rrr;ZKEY_MAXr9rMÚordrRrJrGrOrPr=rrrrrr>Ós r>c@seZdZdZddeddiddeddiddedd    id
deddiddedd
iddeddiiZeZdZdZ    dZ
dZdZdZ
edd„ƒZedd„ƒZedd„ƒZedd„ƒZedd„ƒZedd„ƒZdS)rz
    EVB Buttons
    Úupr rQégÚdownélÚleftéiÚrightéjÚenteréÚ    backspacerBNcCs
d|jkS)z2
        Check if 'up' button is pressed.
        r[)r)rrrrr[%sz    Button.upcCs
d|jkS)z4
        Check if 'down' button is pressed.
        r])r)rrrrr],szButton.downcCs
d|jkS)z4
        Check if 'left' button is pressed.
        r_)r)rrrrr_3szButton.leftcCs
d|jkS)z5
        Check if 'right' button is pressed.
        ra)r)rrrrra:szButton.rightcCs
d|jkS)z5
        Check if 'enter' button is pressed.
        rc)r)rrrrrcAszButton.entercCs
d|jkS)z9
        Check if 'backspace' button is pressed.
        re)r)rrrrreHszButton.backspace)r
rrr;r
rJrr!Zon_upZon_downZon_leftZon_rightZon_enterZon_backspacer=r[r]r_rarcrerrrrrs()rr)ÚsysÚversion_infoÚSystemErrorrLr1ZloggingÚrrZ    getLoggerr
ÚlogrÚImportErrorZwarningr    ÚplatformZ
_platform.ev3r
rZ
_platform.evbZ_platform.pistormsZ_platform.brickpiZ_platform.brickpi3Z_platform.faker"rÚobjectrr>rrrrrÚ<module>sB

    8