Skip to content

Commit b92d3f4

Browse files
committed
pybricks.ev3devices.ColorSensor: Re-enable it.
1 parent 9a178c9 commit b92d3f4

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

pybricks/ev3devices.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#if PYBRICKS_PY_EV3DEVICES
1212

1313
extern const mp_obj_type_t pb_type_ev3devices_TouchSensor;
14+
extern const mp_obj_type_t pb_type_ev3devices_ColorSensor;
1415

1516
#endif // PYBRICKS_PY_EV3DEVICES
1617

1718
#if PYBRICKS_PY_EV3DEVDEVICES
1819

19-
extern const mp_obj_type_t pb_type_ev3devices_ColorSensor;
2020
extern const mp_obj_type_t pb_type_ev3devices_InfraredSensor;
2121
extern const mp_obj_type_t pb_type_ev3devices_GyroSensor;
2222
extern const mp_obj_type_t pb_type_ev3devices_UltrasonicSensor;

pybricks/ev3devices/pb_module_ev3devices.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ static const mp_rom_map_elem_t ev3devices_globals_table[] = {
1414
{ MP_ROM_QSTR(MP_QSTR_Motor), MP_ROM_PTR(&pb_type_Motor) },
1515
#endif
1616
{ MP_ROM_QSTR(MP_QSTR_TouchSensor), MP_ROM_PTR(&pb_type_ev3devices_TouchSensor) },
17+
{ MP_ROM_QSTR(MP_QSTR_ColorSensor), MP_ROM_PTR(&pb_type_ev3devices_ColorSensor) },
1718
#if PYBRICKS_PY_EV3DEVDEVICES
1819
{ MP_ROM_QSTR(MP_QSTR_InfraredSensor), MP_ROM_PTR(&pb_type_ev3devices_InfraredSensor) },
19-
{ MP_ROM_QSTR(MP_QSTR_ColorSensor), MP_ROM_PTR(&pb_type_ev3devices_ColorSensor) },
2020
{ MP_ROM_QSTR(MP_QSTR_UltrasonicSensor), MP_ROM_PTR(&pb_type_ev3devices_UltrasonicSensor)},
2121
{ MP_ROM_QSTR(MP_QSTR_GyroSensor), MP_ROM_PTR(&pb_type_ev3devices_GyroSensor) },
2222
#endif

pybricks/ev3devices/pb_type_ev3devices_colorsensor.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2018-2023 The Pybricks Authors
2+
// Copyright (c) 2018-2025 The Pybricks Authors
33

44
#include "py/mpconfig.h"
55

6-
#if PYBRICKS_PY_EV3DEVDEVICES
6+
#if PYBRICKS_PY_EV3DEVICES
7+
78

89
#include <pybricks/common.h>
9-
#include <pybricks/ev3devices.h>
1010
#include <pybricks/parameters.h>
11+
#include <pybricks/ev3devices.h>
12+
#include <pybricks/common/pb_type_device.h>
1113

1214
#include <pybricks/util_mp/pb_kwarg_helper.h>
1315
#include <pybricks/util_mp/pb_obj_helper.h>
14-
#include <pybricks/common/pb_type_device.h>
1516

16-
// pybricks.ev3devices.ColorSensor class object
17+
// Class structure for ColorSensor
1718
typedef struct _ev3devices_ColorSensor_obj_t {
1819
pb_type_device_obj_base_t device_base;
1920
} ev3devices_ColorSensor_obj_t;
@@ -29,7 +30,7 @@ static mp_obj_t ev3devices_ColorSensor_make_new(const mp_obj_type_t *type, size_
2930

3031
// pybricks.ev3devices.ColorSensor.color
3132
static mp_obj_t get_color(mp_obj_t self_in) {
32-
int8_t *color = pb_type_device_get_data_blocking(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__COLOR);
33+
int8_t *color = pb_type_device_get_data(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__COLOR);
3334
switch (color[0]) {
3435
case 1:
3536
return MP_OBJ_FROM_PTR(&pb_Color_BLACK_obj);
@@ -53,21 +54,22 @@ static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_color_obj, LEGO_DEVICE_MODE_EV
5354

5455
// pybricks.ev3devices.ColorSensor.ambient
5556
static mp_obj_t get_ambient(mp_obj_t self_in) {
56-
int8_t *ambient = pb_type_device_get_data_blocking(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__AMBIENT);
57-
return mp_obj_new_int(ambient[0]);
57+
int8_t *data = pb_type_device_get_data(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__AMBIENT);
58+
return mp_obj_new_int(data[0]);
5859
}
5960
static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_ambient_obj, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__AMBIENT, get_ambient);
6061

6162
// pybricks.ev3devices.ColorSensor.reflection
6263
static mp_obj_t get_reflection(mp_obj_t self_in) {
63-
int8_t *reflection = pb_type_device_get_data_blocking(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__REFLECT);
64-
return mp_obj_new_int(reflection[0]);
64+
int8_t *data = pb_type_device_get_data(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__REFLECT);
65+
return mp_obj_new_int(data[0]);
6566
}
6667
static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_reflection_obj, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__REFLECT, get_reflection);
6768

69+
6870
// pybricks.ev3devices.ColorSensor.rgb
6971
static mp_obj_t get_rgb(mp_obj_t self_in) {
70-
int16_t *rgb = pb_type_device_get_data_blocking(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__RGB_RAW);
72+
int16_t *rgb = pb_type_device_get_data(self_in, LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__RGB_RAW);
7173
mp_obj_t tup[3];
7274

7375
rgb[0] = (int)((0.258 * rgb[0]) - 0.3);
@@ -86,9 +88,9 @@ static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_rgb_obj, LEGO_DEVICE_MODE_EV3_
8688
// dir(pybricks.ev3devices.ColorSensor)
8789
static const mp_rom_map_elem_t ev3devices_ColorSensor_locals_dict_table[] = {
8890
{ MP_ROM_QSTR(MP_QSTR_reflection), MP_ROM_PTR(&get_reflection_obj) },
89-
{ MP_ROM_QSTR(MP_QSTR_ambient), MP_ROM_PTR(&get_ambient_obj) },
90-
{ MP_ROM_QSTR(MP_QSTR_color), MP_ROM_PTR(&get_color_obj) },
91-
{ MP_ROM_QSTR(MP_QSTR_rgb), MP_ROM_PTR(&get_rgb_obj) },
91+
{ MP_ROM_QSTR(MP_QSTR_ambient), MP_ROM_PTR(&get_ambient_obj) },
92+
{ MP_ROM_QSTR(MP_QSTR_color), MP_ROM_PTR(&get_color_obj) },
93+
{ MP_ROM_QSTR(MP_QSTR_rgb), MP_ROM_PTR(&get_rgb_obj) },
9294
};
9395
static MP_DEFINE_CONST_DICT(ev3devices_ColorSensor_locals_dict, ev3devices_ColorSensor_locals_dict_table);
9496

@@ -99,4 +101,4 @@ MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3devices_ColorSensor,
99101
make_new, ev3devices_ColorSensor_make_new,
100102
locals_dict, &ev3devices_ColorSensor_locals_dict);
101103

102-
#endif // PYBRICKS_PY_EV3DEVDEVICES
104+
#endif // PYBRICKS_PY_EV3DEVICES

0 commit comments

Comments
 (0)