Skip to content

Commit 2edbd03

Browse files
maxnoeddemidov
authored andcommitted
Autocreate tuples of sensor properties (#320)
1 parent 183fc4f commit 2edbd03

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

ev3dev/core.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,11 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
18721872
MODE_TOUCH = 'TOUCH'
18731873

18741874

1875+
MODES = (
1876+
'TOUCH',
1877+
)
1878+
1879+
18751880
@property
18761881
def is_pressed(self):
18771882
"""
@@ -1940,6 +1945,26 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
19401945
COLOR_BROWN = 7
19411946

19421947

1948+
MODES = (
1949+
'COL-REFLECT',
1950+
'COL-AMBIENT',
1951+
'COL-COLOR',
1952+
'REF-RAW',
1953+
'RGB-RAW',
1954+
)
1955+
1956+
COLORS = (
1957+
'NoColor',
1958+
'Black',
1959+
'Blue',
1960+
'Green',
1961+
'Yellow',
1962+
'Red',
1963+
'White',
1964+
'Brown',
1965+
)
1966+
1967+
19431968
@property
19441969
def reflected_light_intensity(self):
19451970
"""
@@ -2057,6 +2082,15 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
20572082
MODE_US_SI_IN = 'US-SI-IN'
20582083

20592084

2085+
MODES = (
2086+
'US-DIST-CM',
2087+
'US-DIST-IN',
2088+
'US-LISTEN',
2089+
'US-SI-CM',
2090+
'US-SI-IN',
2091+
)
2092+
2093+
20602094
@property
20612095
def distance_centimeters(self):
20622096
"""
@@ -2125,6 +2159,15 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
21252159
MODE_GYRO_CAL = 'GYRO-CAL'
21262160

21272161

2162+
MODES = (
2163+
'GYRO-ANG',
2164+
'GYRO-RATE',
2165+
'GYRO-FAS',
2166+
'GYRO-G&A',
2167+
'GYRO-CAL',
2168+
)
2169+
2170+
21282171
@property
21292172
def angle(self):
21302173
"""
@@ -2191,6 +2234,15 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
21912234
MODE_IR_CAL = 'IR-CAL'
21922235

21932236

2237+
MODES = (
2238+
'IR-PROX',
2239+
'IR-SEEK',
2240+
'IR-REMOTE',
2241+
'IR-REM-A',
2242+
'IR-CAL',
2243+
)
2244+
2245+
21942246
@property
21952247
def proximity(self):
21962248
"""
@@ -2226,6 +2278,12 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
22262278
MODE_DBA = 'DBA'
22272279

22282280

2281+
MODES = (
2282+
'DB',
2283+
'DBA',
2284+
)
2285+
2286+
22292287
@property
22302288
def sound_pressure(self):
22312289
"""
@@ -2273,6 +2331,12 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
22732331
MODE_AMBIENT = 'AMBIENT'
22742332

22752333

2334+
MODES = (
2335+
'REFLECT',
2336+
'AMBIENT',
2337+
)
2338+
2339+
22762340
@property
22772341
def reflected_light_intensity(self):
22782342
"""

templates/special-sensors.liquid

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ endfor %}
6060
{{ propName }}_{{ value.name | upcase | underscore_non_wc }} = {{ val }}
6161
{% endfor %}{%
6262
endfor %}
63+
{% for prop in currentClass.propertyValues %}{%
64+
assign propName = prop.propertyName | upcase | underscore_spaces%}
65+
{{ propName }}S = ({%
66+
for value in prop.values %}
67+
'{{ value.name }}',{%
68+
endfor %}
69+
)
70+
{%endfor %}
6371
{% for mapping in currentClass.sensorValueMappings %}{%
6472
assign name = mapping.name | downcase | underscore_spaces %}{%
6573
assign mode = mapping.requiredMode | upcase | underscore_non_wc %}

0 commit comments

Comments
 (0)