Skip to content

Commit f0cdf30

Browse files
committed
added python side
1 parent 46802b2 commit f0cdf30

4 files changed

Lines changed: 47 additions & 38 deletions

File tree

src/base_circuitpython/base_cp_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
EXPECTED_INPUT_BUTTONS = set(["button_a", "button_b"])
1111

12-
ALL_EXPECTED_INPUT_EVENTS = set([])
12+
ALL_EXPECTED_INPUT_EVENTS = set(["temperature", "light_r", "light_g", "light_b", "light_c", "motion_x", "motion_y", "motion_z", "humidity", "pressure", "proximity"])

src/clue/adafruit_clue.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ def __init__(self):
203203
"button_a": False,
204204
"button_b": False,
205205
"pressed_buttons": set(),
206-
"acceleration": {"x": 0, "y": 0, "z": 0},
207-
"color_sensor": {"r": 0, "g": 0, "b": 0, "c": 0},
208-
"magnetometer": {"x": 0, "y": 0, "z": 0},
209-
"gyro": {"x": 0, "y": 0, "z": 0},
210206
"sea_level_pressure": 1013.25,
211207
"temperature": 0,
212208
"proximity": 0,
@@ -216,6 +212,23 @@ def __init__(self):
216212
"pixel": neopixel.NeoPixel(
217213
pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB
218214
),
215+
# Accelerometer
216+
"motion_x": 0,
217+
"motion_y": 0,
218+
"motion_z": 0,
219+
# Light/color sensor
220+
"light_r": 0,
221+
"light_g": 0,
222+
"light_b": 0,
223+
"light_c": 0,
224+
# Magnetometer
225+
"magnet_x": 0,
226+
"magnet_y": 0,
227+
"magnet_z": 0,
228+
# Gyroscope
229+
"gyro_x": 0,
230+
"gyro_y": 0,
231+
"gyro_z": 0,
219232
}
220233

221234
@property
@@ -268,9 +281,9 @@ def acceleration(self):
268281
print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration))
269282
"""
270283
return (
271-
self.__state["acceleration"]["x"],
272-
self.__state["acceleration"]["y"],
273-
self.__state["acceleration"]["z"],
284+
self.__state["motion_x"],
285+
self.__state["motion_y"],
286+
self.__state["motion_z"],
274287
)
275288

276289
@property
@@ -285,10 +298,10 @@ def color(self):
285298
print("Color: R: {} G: {} B: {} C: {}".format(*clue.color))
286299
"""
287300
return (
288-
self.__state["color_sensor"]["r"],
289-
self.__state["color_sensor"]["g"],
290-
self.__state["color_sensor"]["b"],
291-
self.__state["color_sensor"]["c"],
301+
self.__state["light_r"],
302+
self.__state["light_g"],
303+
self.__state["light_b"],
304+
self.__state["light_c"],
292305
)
293306

294307
@property
@@ -313,9 +326,9 @@ def magnetic(self):
313326
print("Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic))
314327
"""
315328
return (
316-
self.__state["magnetometer"]["x"],
317-
self.__state["magnetometer"]["y"],
318-
self.__state["magnetometer"]["z"],
329+
self.__state["magnet_x"],
330+
self.__state["magnet_y"],
331+
self.__state["magnet_z"],
319332
)
320333

321334
@property
@@ -338,9 +351,9 @@ def gyro(self):
338351
print("Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro))
339352
"""
340353
return (
341-
self.__state["gyro"]["x"],
342-
self.__state["gyro"]["y"],
343-
self.__state["gyro"]["z"],
354+
self.__state["gyro_x"],
355+
self.__state["gyro_y"],
356+
self.__state["gyro_z"],
344357
)
345358

346359
@property

src/clue/test/test_adafruit_clue.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def test_acceleration(self):
7777
MOCK_MOTION_Z = 3
7878
MOCK_MOTION_X_B = 4
7979

80-
clue._Clue__state["acceleration"].update(
81-
{"x": MOCK_MOTION_X_A, "y": MOCK_MOTION_Y, "z": MOCK_MOTION_Z,}
82-
)
80+
clue._Clue__state["motion_x"] = MOCK_MOTION_X_A
81+
clue._Clue__state["motion_y"] = MOCK_MOTION_Y
82+
clue._Clue__state["motion_z"] = MOCK_MOTION_Z
8383
assert clue.acceleration == (MOCK_MOTION_X_A, MOCK_MOTION_Y, MOCK_MOTION_Z)
8484
clue._Clue__state["acceleration"]["x"] = MOCK_MOTION_X_B
8585
assert clue.acceleration == (MOCK_MOTION_X_B, MOCK_MOTION_Y, MOCK_MOTION_Z)
@@ -91,14 +91,10 @@ def test_color(self):
9191
MOCK_COLOR_C = 4
9292
MOCK_COLOR_R_B = 5
9393

94-
clue._Clue__state["color_sensor"].update(
95-
{
96-
"r": MOCK_COLOR_R_A,
97-
"g": MOCK_COLOR_G,
98-
"b": MOCK_COLOR_B,
99-
"c": MOCK_COLOR_C,
100-
}
101-
)
94+
clue._Clue__state["light_r"] = MOCK_COLOR_R_A
95+
clue._Clue__state["light_g"] = MOCK_COLOR_G
96+
clue._Clue__state["light_b"] = MOCK_COLOR_B
97+
clue._Clue__state["light_c"] = MOCK_COLOR_C
10298
assert clue.color == (MOCK_COLOR_R_A, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C)
10399
clue._Clue__state["color_sensor"]["r"] = MOCK_COLOR_R_B
104100
assert clue.color == (MOCK_COLOR_R_B, MOCK_COLOR_G, MOCK_COLOR_B, MOCK_COLOR_C)
@@ -117,9 +113,9 @@ def test_magnetic(self):
117113
MOCK_MAGNETIC_Z = 3
118114
MOCK_MAGNETIC_X_B = 4
119115

120-
clue._Clue__state["magnetometer"].update(
121-
{"x": MOCK_MAGNETIC_X_A, "y": MOCK_MAGNETIC_Y, "z": MOCK_MAGNETIC_Z,}
122-
)
116+
clue._Clue__state["magnet_x"] = MOCK_MAGNETIC_X_A
117+
clue._Clue__state["magnet_y"] = MOCK_MAGNETIC_Y
118+
clue._Clue__state["magnet_z"] = MOCK_MAGNETIC_Z
123119
assert clue.magnetic == (MOCK_MAGNETIC_X_A, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,)
124120
clue._Clue__state["magnetometer"]["x"] = MOCK_MAGNETIC_X_B
125121
assert clue.magnetic == (MOCK_MAGNETIC_X_B, MOCK_MAGNETIC_Y, MOCK_MAGNETIC_Z,)
@@ -138,9 +134,9 @@ def test_gyro(self):
138134
MOCK_GYRO_Z = 3
139135
MOCK_GYRO_X_B = 4
140136

141-
clue._Clue__state["gyro"].update(
142-
{"x": MOCK_GYRO_X_A, "y": MOCK_GYRO_Y, "z": MOCK_GYRO_Z,}
143-
)
137+
clue._Clue__state["gyro_x"] = MOCK_GYRO_X_A
138+
clue._Clue__state["gyro_y"] = MOCK_GYRO_Y
139+
clue._Clue__state["gyro_z"] = MOCK_GYRO_Z
144140
assert clue.gyro == (MOCK_GYRO_X_A, MOCK_GYRO_Y, MOCK_GYRO_Z)
145141
clue._Clue__state["gyro"]["x"] = MOCK_GYRO_X_B
146142
assert clue.gyro == (MOCK_GYRO_X_B, MOCK_GYRO_Y, MOCK_GYRO_Z)

src/view/components/toolbar/motion/Accelerometer.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { Accelerometer } from "./Accelerometer";
77
describe("Accelerometer component ", () => {
88
const mockProps = {
99
axisValues: {
10-
X_AXIS: 1,
11-
Y_AXIS: 0,
12-
Z_AXIS: 1,
10+
X: 1,
11+
Y: 0,
12+
Z: 1,
1313
},
1414
onUpdateValue: () => {},
1515
};

0 commit comments

Comments
 (0)