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




[0@sddlZejdkr'edddZddZddlZddlZddlZddlZddl    Z    ddl
Z
dd    lmZd
Z
d
ZddZd
dZddZGdddeZGdddeZddZdS)Nz"Must be using Python 3.4 or highercCstjjdkS)NZmicropython)sysimplementationnamerr2/usr/lib/python3/dist-packages/ev3dev2/__init__.pyis_micropythonsr    cCstr|n    ||dS)N)r    )Z    exceptioncauserrrchain_exception"s        r)abspathcCsd}tjj|sdSxtj|D]}tjj||d}tjj|r,t|d}x|jD]}|jjd\}}|dkr{|dkrdS|dkrdS|dkrd
S|dkrdS|dkrdS|dkr{dSq{WWdQRXq,WdS)z
    Look in /sys/class/board-info/ to determine the platform type.

    This can return 'ev3', 'evb', 'pistorms', 'brickpi', 'brickpi3' or 'fake'.
    z/sys/class/board-info/ZfakeZueventr=ZBOARD_INFO_MODELzLEGO MINDSTORMS EV3Zev3
FatcatLab EVB    QuestCapeZevbZPiStormsZpistormszDexter Industries BrickPiZbrickpizDexter Industries BrickPi3Zbrickpi3zFAKE-SYSN)rr)    ospathexistslistdirjoinopen    readlinesstripsplit)Zboard_info_dirZboardZuevent_filenameZfhlinekeyvaluerrrget_current_platform4s.rc+stjj|sdSddxatj|D]P}tj||r2|d|tfddDr2|Vq2WdS)a
    This is a generator function that lists names of all devices matching the
    provided parameters.

    Parameters:
        class_path: class path of the device, a subdirectory of /sys/class.
            For example, '/sys/class/tacho-motor'.
        name_pattern: pattern that device name should match.
            For example, 'sensor*' or 'motor*'. Default value: '*'.
        keyword arguments: used for matching the corresponding device
            attributes. For example, address='outA', or
            driver_name=['lego-ev3-us', 'lego-nxt-us']. When argument value
            is a list, then a match against any entry of the list is
            enough.
    Ncsy5tj|}|jjjWdQRXWndSYnXt|trptfdd|DSj|dkSdS)NFcs%g|]}j|dkqS)r)find).0p)rrr
<listcomp>}s    z6list_device_names.<locals>.matches.<locals>.<listcomp>r)    ioFileIOreadrdecode
isinstancelistanyr)    attributepatternfr)rrmatchesus#    z"list_device_names.<locals>.matches/cs+g|]!}d||qS)r.r)r k)kwargsr-rrrr"s    z%list_device_names.<locals>.<listcomp>)rrisdirrfnmatchall)Z
class_pathname_patternr0r,r)r0r-rrlist_device_namesas%r5cCsdj||S)Nz;Import warning: Failed to import "{}". {} will be unusable!)format)Zlibrary_nameZdependent_classrrrlibrary_load_warning_messagesr7c@seZdZdS)DeviceNotFoundN)__name__
__module____qualname__rrrrr8sr8c@seZdZdZdddgZdZejdZddd    d
Z    ddZ
d
dZddZddZ
ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zed'd(Zd)S)*DevicezThe ev3dev device base class_path
_device_indexr0z
/sys/classz    ^.*(\d+)$*FcKsttjd|}||_dd}|rU|d||_|||_nzy<tt|||}|d||_|||_Wn;tk
rd|_d|_t    t
d|dYnXdS)a`Spin through the Linux sysfs class for the device type and find
        a device that matches the provided name pattern and attributes (if any).

        Parameters:
            class_name: class name of the device, a subdirectory of /sys/class.
                For example, 'tacho-motor'.
            name_pattern: pattern that device name should match.
                For example, 'sensor*' or 'motor*'. Default value: '*'.
            name_exact: when True, assume that the name_pattern provided is the
                exact device name and use it directly.
            keyword arguments: used for matching the corresponding device
                attributes. For example, address='outA', or
                driver_name=['lego-ev3-us', 'lego-nxt-us']. When argument value
                is a list, then a match against any entry of the list is
                enough.

        Example::

            d = ev3dev.Device('tacho-motor', address='outA')
            s = ev3dev.Device('lego-sensor', driver_name=['lego-ev3-us', 'lego-nxt-us'])

        If there was no valid connected device, an error is thrown.
        r.cSs3tjj|}|r+t|jdSdSdS)N)r<
_DEVICE_INDEXmatchintgroup)filerBrrr    get_indexsz"Device.__init__.<locals>.get_indexNz%s is not connected.)rr<DEVICE_ROOT_PATHr0r=r>nextr5
StopIterationrr8)self
class_namer4
name_exactr0    classpathrFrrrr__init__s    
        zDevice.__init__cCs=d|jkr/d|jj|jjdfS|jjSdS)NZaddressz%s(%s))r0    __class__r9get)rJrrr__str__s zDevice.__str__cCs
|jS)N)rQ)rJrrr__repr__szDevice.__repr__cCstjj|j|}tjtj|tj}|tj@}|tj@}|rf|rfd}n|rud}nd}t    j
||S)Nzr+wr)rrrr=statS_IMODEST_MODES_IRGRPS_IWGRPr#r$)rJrrmodeZr_okZw_okZmode_strrrr_attribute_file_opens

        zDevice._attribute_file_opencCsyK|dkr!|j|}n
|jd||jjjfSWn5tk
r}z|j||WYdd}~XnXdS)zDevice attribute getterNr)rZseekr%rr&    Exception_raise_friendly_access_error)rJr*rexrrr_get_attributes
 zDevice._get_attributecCsya|dkr!|j|}n
|jdt|trI|j}|j||jWn5tk
r}z|j||WYdd}~XnX|S)zDevice attribute setterNr)    rZr[r'strencodewriteflushr\r])rJr*rrr^rrr_set_attributes

#zDevice._set_attributec
Cst|ts|tr+|jdn|j}|tjkr|dkry
|j}Wn+ttfk
rt    t
d|YnXt    t
dt||t    t
d|n5|tjks|tj
krt    td|||dS)NrZspeed_spz&The given speed value was out of rangez6The given speed value was out of range. Max speed: +/-z2One or more arguments were out of range or invalidz%s is no longer connected)r'OSErrorr    argserrnoZEINVAL    max_speedAttributeErrorr\r
ValueErrorr`ZENODEVENOENTr8)rJZdriver_errorr*Zdriver_errornorhrrrr]s
z#Device._raise_friendly_access_errorcCs(|j||\}}|t|fS)N)r_rC)rJr*rrrrrget_attr_intszDevice.get_attr_intcCs|j||tt|S)N)rdr`rC)rJr*rrrrrset_attr_intszDevice.set_attr_intcCs|j|||S)N)rd)rJr*rrrrrset_attr_rawszDevice.set_attr_rawcCs|j||S)N)r_)rJr*rrrrget_attr_stringszDevice.get_attr_stringcCs|j|||S)N)rd)rJr*rrrrrset_attr_string!szDevice.set_attr_stringcCs|j||S)N)r_)rJr*rrrr
get_attr_line$szDevice.get_attr_linecCs5|j||\}}|dd|jDfS)NcSsg|]}|jdqS)z[])r)r vrrrr")s    z'Device.get_attr_set.<locals>.<listcomp>)rqr)rJr*rrrrrget_attr_set'szDevice.get_attr_setcCsR|j||\}}x3|jD]%}|jd}||kr%|Sq%WdS)Nz[]r
)rqrr)rJr*rrarrrrrget_attr_from_set+szDevice.get_attr_from_setcCs|jS)N)r>)rJrrrdevice_index3szDevice.device_indexN)r9r:r;__doc__    __slots__rGrecompilerArNrQrRrZr_rdr]rlrmrnrorprqrsrupropertyrvrrrrr<s(1r<cs:ttjd}fddt|||DS)a
    This is a generator function that takes same arguments as `Device` class
    and enumerates all devices present in the system that match the provided
    arguments.

    Parameters:
        class_name: class name of the device, a subdirectory of /sys/class.
            For example, 'tacho-motor'.
        name_pattern: pattern that device name should match.
            For example, 'sensor*' or 'motor*'. Default value: '*'.
        keyword arguments: used for matching the corresponding device
            attributes. For example, address='outA', or
            driver_name=['lego-ev3-us', 'lego-nxt-us']. When argument value
            is a list, then a match against any entry of the list is
            enough.
    r.c3s$|]}t|ddVqdS)rLTN)r<)r r)rKrr    <genexpr>Kszlist_devices.<locals>.<genexpr>)rr<rGr5)rKr4r0rMr)rKrlist_devices8sr})rr)rversion_infoSystemErrorr    rrr#r2ryrTrgos.pathrZ
INPUT_AUTOZOUTPUT_AUTOrr5r7r\r8objectr<r}rrrr<module>s&-'