Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions ev3dev/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,18 +930,17 @@ def list_motors(name_pattern=Motor.SYSTEM_DEVICE_NAME_CONVENTION, **kwargs):

Parameters:
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
For example, 'motor*'. Default value: '*'.
keyword arguments: used for matching the corresponding device
attributes. For example, driver_name='lego-ev3-l-motor', or
address=['outB', 'outC']. When argument value
is a list, then a match against any entry of the list is
enough.
"""
classpath = abspath(Device.DEVICE_ROOT_PATH + '/' + Motor.SYSTEM_CLASS_NAME)
class_path = abspath(Device.DEVICE_ROOT_PATH + '/' + Motor.SYSTEM_CLASS_NAME)

return (Motor(name_pattern=name, name_exact=True)
for name in list_device_names(classpath, name_pattern, **kwargs))

for name in list_device_names(class_path, name_pattern, **kwargs))

# ~autogen generic-class classes.largeMotor>currentClass

Expand Down Expand Up @@ -1769,6 +1768,24 @@ def bin_data(self, fmt=None):

return unpack(fmt, raw)

def list_sensors(name_pattern=Sensor.SYSTEM_DEVICE_NAME_CONVENTION, **kwargs):
"""
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.
"""
class_path = abspath(Device.DEVICE_ROOT_PATH + '/' + Sensor.SYSTEM_CLASS_NAME)
return (Sensor(name_pattern=name, name_exact=True)
for name in list_device_names(class_path, name_pattern, **kwargs))


# ~autogen generic-class classes.i2cSensor>currentClass

class I2cSensor(Sensor):
Expand Down