Skip to content

Commit 1d1d850

Browse files
authored
pybricks.ev3devices.ColorSensor: Use blocking read calls (#273)
Other EV3 sensors in this module use the pb_type_device_get_data_blocking() method. I think that using pb_type_device_get_data() as it is used (only) in the color sensor class the sensor will not work for reading non-default modes. Fixes: 8a52c95 ("pbdrv/legodev: Refactor LEGO device abstraction.")
1 parent a062942 commit 1d1d850

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pybricks/ev3devices/pb_type_ev3devices_colorsensor.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static mp_obj_t ev3devices_ColorSensor_make_new(const mp_obj_type_t *type, size_
2929

3030
// pybricks.ev3devices.ColorSensor.color
3131
static mp_obj_t get_color(mp_obj_t self_in) {
32-
int8_t *color = pb_type_device_get_data(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__COLOR);
32+
int8_t *color = pb_type_device_get_data_blocking(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__COLOR);
3333
switch (color[0]) {
3434
case 1:
3535
return MP_OBJ_FROM_PTR(&pb_Color_BLACK_obj);
@@ -53,21 +53,21 @@ static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_color_obj, PBDRV_LEGODEV_MODE_
5353

5454
// pybricks.ev3devices.ColorSensor.ambient
5555
static mp_obj_t get_ambient(mp_obj_t self_in) {
56-
int8_t *ambient = pb_type_device_get_data(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__AMBIENT);
56+
int8_t *ambient = pb_type_device_get_data_blocking(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__AMBIENT);
5757
return mp_obj_new_int(ambient[0]);
5858
}
5959
static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_ambient_obj, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__AMBIENT, get_ambient);
6060

6161
// pybricks.ev3devices.ColorSensor.reflection
6262
static mp_obj_t get_reflection(mp_obj_t self_in) {
63-
int8_t *reflection = pb_type_device_get_data(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__REFLECT);
63+
int8_t *reflection = pb_type_device_get_data_blocking(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__REFLECT);
6464
return mp_obj_new_int(reflection[0]);
6565
}
6666
static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_reflection_obj, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__REFLECT, get_reflection);
6767

6868
// pybricks.ev3devices.ColorSensor.rgb
6969
static mp_obj_t get_rgb(mp_obj_t self_in) {
70-
int16_t *rgb = pb_type_device_get_data(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__RGB_RAW);
70+
int16_t *rgb = pb_type_device_get_data_blocking(self_in, PBDRV_LEGODEV_MODE_EV3_COLOR_SENSOR__RGB_RAW);
7171
mp_obj_t tup[3];
7272

7373
rgb[0] = (int)((0.258 * rgb[0]) - 0.3);

0 commit comments

Comments
 (0)