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




[+@sddlZejdkr'edddlZddlmZddlmZddlm    Z    m
Z
mZe    Zedkrdd    l
mZmZmZmZned
krdd    lmZmZmZmZnedkrdd    lmZmZmZmZnedkr<dd    lmZmZmZmZnred
krmdd    lmZmZmZmZnAedkrdd    lmZmZmZmZnedeGddde
ZejddZGdddeZdS)Nz"Must be using Python 3.4 or higher)abspath)unpack)get_current_platformDevicelist_device_namesZev3)INPUT_1INPUT_2INPUT_3INPUT_4ZevbZpistormsZbrickpiZbrickpi3ZfakezUnsupported platform '%s'cseZdZdZdZdZdddddd    d
ddd
ddddgZdedfddZddZe    ddZ
e    ddZejddZe    ddZ
e    dd Ze    d!d"Ze    d#d$Zejd%d$Ze    d&d'Ze    d(d)Ze    d*d+Zd,d-d.Ze    d/d0Zdd1d2Zd3d4ZS)5Sensorzp
    The sensor class provides a uniform interface for using most of the
    sensors available for the EV3.
    zlego-sensorzsensor*_address_command    _commands    _decimals_driver_name_mode_modes_num_values_units_value_bin_data_format_bin_data_size    _bin_data_mode_scaleNFcs|dk    r||d<tt|j|j|||d|_d|_d|_d|_d|_d|_    d|_
d|_d|_ddddddddg|_
d|_d|_d|_i|_dS)Naddress)superr
__init__SYSTEM_CLASS_NAMErrrrrrrrrrrrrr)selfrname_pattern
name_exactkwargs)    __class__9/usr/lib/python3/dist-packages/ev3dev2/sensor/__init__.pyrWs"
"                                    !            zSensor.__init__cCs>||jkr|j|}nd|j}||j|<|S)zG
        Returns value scaling coefficient for the given mode.
        
)rdecimals)r modeZscaler%r%r&_scalems

z
Sensor._scalecCs"|j|jd\|_}|S)z
        Returns the name of the port that the sensor is connected to, e.g. `ev3:in1`.
        I2C sensors also include the I2C address (decimal), e.g. `ev3:in1:i2c8`.
        r)get_attr_stringr)r valuer%r%r&ryszSensor.addresscCstddS)z0
        Sends a command to the sensor.
        z!command is a write-only property!N)    Exception)r r%r%r&commandszSensor.commandcCs|j|jd||_dS)Nr.)set_attr_stringr)r r,r%r%r&r.scCs"|j|jd\|_}|S)z
        Returns a list of the valid commands for the sensor.
        Returns -EOPNOTSUPP if no commands are supported.
        commands)get_attr_setr)r r,r%r%r&r0szSensor.commandscCs"|j|jd\|_}|S)z
        Returns the number of decimal places for the values in the `value<N>`
        attributes of the current mode.
        r()get_attr_intr)r r,r%r%r&r(szSensor.decimalscCs"|j|jd\|_}|S)z
        Returns the name of the sensor device/driver. See the list of [supported
        sensors] for a complete list of drivers.
        driver_name)r+r)r r,r%r%r&r3szSensor.driver_namecCs"|j|jd\|_}|S)z
        Returns the current mode. Writing one of the values returned by `modes`
        sets the sensor to that mode.
        r))r+r)r r,r%r%r&r)szSensor.modecCs|j|jd||_dS)Nr))r/r)r r,r%r%r&r)scCs"|j|jd\|_}|S)zC
        Returns a list of the valid modes for the sensor.
        modes)r1r)r r,r%r%r&r4szSensor.modescCs"|j|jd\|_}|S)zz
        Returns the number of `value<N>` attributes that will return a valid value
        for the current mode.
        
num_values)r2r)r r,r%r%r&r5szSensor.num_valuescCs"|j|jd\|_}|S)zo
        Returns the units of the measured value for the current mode. May return
        empty string
        units)r+r)r r,r%r%r&r6szSensor.unitsrcCs@t|}|j|j|dt|\|j|<}|S)a.
        Returns the value or values measured by the sensor. Check num_values to
        see how many values there are. Values with N >= num_values will return
        an error. The values are fixed point numbers, so check decimals to see
        if you need to divide to get the actual value.
        r,)intr2rstr)r nr,r%r%r&r,s0zSensor.valuecCs"|j|jd\|_}|S)a
        Returns the format of the values in `bin_data` for the current mode.
        Possible values are:

        - `u8`: Unsigned 8-bit integer (byte)
        - `s8`: Signed 8-bit integer (sbyte)
        - `u16`: Unsigned 16-bit integer (ushort)
        - `s16`: Signed 16-bit integer (short)
        - `s16_be`: Signed 16-bit integer, big endian
        - `s32`: Signed 32-bit integer (int)
        - `float`: IEEE 754 32-bit floating point (float)
        bin_data_format)r+r)r r,r%r%r&r:szSensor.bin_data_formatcCs|jdkrXddddddddddd    d
dd
ij|jd|j|_d|jkry|jd|_|jjd
t|jj|j}|dkr|St    ||S)a
        Returns the unscaled raw values in the `value<N>` attributes as raw byte
        array. Use `bin_data_format`, `num_values` and the individual sensor
        documentation to determine how to interpret the data.

        Use `fmt` to unpack the raw bytes into a struct.

        Example::

            >>> from ev3dev2.sensor.lego import InfraredSensor
            >>> ir = InfraredSensor()
            >>> ir.value()
            28
            >>> ir.bin_data('<b')
            (28,)
        Nu8Zs8u16Zs16Zs16_beZs32rfloatbin_datar)
rgetr:r5rZ_attribute_file_openseek    bytearrayreadr)r Zfmtrawr%r%r&r@s zSensor.bin_datacCs|j|kr||_dS)N)r))r r)r%r%r&_ensure_modeszSensor._ensure_mode)__name__
__module____qualname____doc__rSYSTEM_DEVICE_NAME_CONVENTION    __slots__rr*propertyrr.setterr0r(r3r)r4r5r6r,r:r@rFr%r%)r$r&r
>sD                                'r
cKs7ttjdtj}ddt|||DS)a
    This is a generator function that enumerates all sensors that match the
    provided arguments.

    Parameters:
        name_pattern: pattern that device name should match.
            For example, 'sensor*'. Default value: '*'.
        keyword arguments: used for matching the corresponding device
            attributes. For example, driver_name='lego-ev3-touch', or
            address=['in1', 'in3']. When argument value is a list,
            then a match against any entry of the list is enough.
    /css$|]}td|ddVqdS)r!r"TN)r
).0namer%r%r&    <genexpr>%szlist_sensors.<locals>.<genexpr>)rrZDEVICE_ROOT_PATHr
rr)r!r#Z
class_pathr%r%r&list_sensorss
    rScsyeZdZdZejZdZdedfddZeddZ    ed    d
Z
e
jdd
Z
S)    I2cSensorz>
    A generic interface to control I2C-type EV3 sensors.
    zsensor*NFcs>tt|j|||ddg|d|_d|_dS)Nr3znxt-i2c-sensor)rrTr_fw_version_poll_ms)r rr!r"r#)r$r%r&r1s(    zI2cSensor.__init__cCs"|j|jd\|_}|S)z
        Returns the firmware version of the sensor if available. Currently only
        I2C/NXT sensors support this.
        
fw_version)r+rU)r r,r%r%r&rW6szI2cSensor.fw_versioncCs"|j|jd\|_}|S)aI
        Returns the polling period of the sensor in milliseconds. Writing sets the
        polling period. Setting to 0 disables polling. Minimum value is hard
        coded as 50 msec. Returns -EOPNOTSUPP if changing polling is not supported.
        Currently only I2C/NXT sensors support changing the polling period.
        poll_ms)r2rV)r r,r%r%r&rX?szI2cSensor.poll_mscCs|j|jd||_dS)NrX)Zset_attr_intrV)r r,r%r%r&rXJs)rGrHrIrJr
rrKrrMrWrXrNr%r%)r$r&rT)s        rT)rr)sysversion_infoSystemErrorZnumbersos.pathrZstructrZev3dev2rrrplatformZev3dev2._platform.ev3r    r
rrZev3dev2._platform.evbZev3dev2._platform.pistormsZev3dev2._platform.brickpiZev3dev2._platform.brickpi3Zev3dev2._platform.faker-r
rKrSrTr%r%r%r&<module>s.    %%%%%%