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
1718typedef 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
3132static 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
5556static 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}
5960static 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
6263static 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}
6667static 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
6971static 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)
8789static 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};
9395static 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