Skip to content

Commit be77ea3

Browse files
authored
Optimistically check the mode of the sensor before setting it on property read (ev3dev#502)
Plus sensor docs improvements.
1 parent 3434e6d commit be77ea3

File tree

3 files changed

+145
-61
lines changed

3 files changed

+145
-61
lines changed

ev3dev2/sensor/__init__.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,7 @@
6262
class Sensor(Device):
6363
"""
6464
The sensor class provides a uniform interface for using most of the
65-
sensors available for the EV3. The various underlying device drivers will
66-
create a `lego-sensor` device for interacting with the sensors.
67-
68-
Sensors are primarily controlled by setting the `mode` and monitored by
69-
reading the `value<N>` attributes. Values can be converted to floating point
70-
if needed by `value<N>` / 10.0 ^ `decimals`.
71-
72-
Since the name of the `sensor<N>` device node does not correspond to the port
73-
that a sensor is plugged in to, you must look at the `address` attribute if
74-
you need to know which port a sensor is plugged in to. However, if you don't
75-
have more than one sensor of each type, you can just look for a matching
76-
`driver_name`. Then it will not matter which port a sensor is plugged in to - your
77-
program will still work.
65+
sensors available for the EV3.
7866
"""
7967

8068
SYSTEM_CLASS_NAME = 'lego-sensor'
@@ -286,7 +274,10 @@ def bin_data(self, fmt=None):
286274
if fmt is None: return raw
287275

288276
return unpack(fmt, raw)
289-
277+
278+
def _ensure_mode(self, mode):
279+
if self.mode != mode:
280+
self.mode = mode
290281

291282
def list_sensors(name_pattern=Sensor.SYSTEM_DEVICE_NAME_CONVENTION, **kwargs):
292283
"""

0 commit comments

Comments
 (0)