Skip to content

Commit 6905609

Browse files
committed
pybricks.common.LightArray: Fix off method.
Fixes pybricks/support#1098
1 parent 5850509 commit 6905609

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
is a tuple of `(name, num_values, data_type)` tuples for each available mode.
1010

1111
### Changed
12-
- Changed internal drivers for LEGO devices on all platforms.
12+
- Changed internal drivers for LEGO devices (motors and sensors) on all platforms.
1313

1414
### Fixed
1515
- Fixed hub will not power off when Bluetooth chip crashes on City and Technic hubs ([support#1095]).
16+
- Fixed `off()` method in `ColorLightMatrix`, `UltrasonicSensor`, `ColorSensor` ([support#1098]).
1617

1718
[support#1095]: https://github.com/pybricks/support/issues/1095
19+
[support#1098]: https://github.com/pybricks/support/issues/1098
1820

1921
## [3.3.0b6] - 2023-06-02
2022

pybricks/common/pb_type_lightarray.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ STATIC mp_obj_t common_LightArray_on(size_t n_args, const mp_obj_t *pos_args, mp
5454
}
5555

5656
// Set the brightness values and wait or await it.
57-
return pb_type_device_set_data(self->sensor, self->light_mode, brightness_values, sizeof(brightness_values));
57+
return pb_type_device_set_data(self->sensor, self->light_mode, brightness_values, self->number_of_lights);
5858
}
5959
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(common_LightArray_on_obj, 1, common_LightArray_on);
6060

6161
// pybricks._common.LightArray.off
6262
STATIC mp_obj_t common_LightArray_off(mp_obj_t self_in) {
63-
const mp_obj_t pos_args[] = {self_in, MP_OBJ_NEW_SMALL_INT(0) };
64-
common_LightArray_on(MP_ARRAY_SIZE(pos_args), pos_args, NULL);
65-
return mp_const_none;
63+
common_LightArray_obj_t *self = MP_OBJ_TO_PTR(self_in);
64+
int8_t brightness_values[4] = { };
65+
return pb_type_device_set_data(self->sensor, self->light_mode, brightness_values, self->number_of_lights);
6666
}
6767
STATIC MP_DEFINE_CONST_FUN_OBJ_1(common_LightArray_off_obj, common_LightArray_off);
6868

pybricks/pupdevices/pb_type_pupdevices_colorlightmatrix.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pupdevices_ColorLightMatrix_on_obj, 1, pupdevi
8888

8989
// pybricks.pupdevices.ColorLightMatrix.off
9090
STATIC mp_obj_t pupdevices_ColorLightMatrix_off(mp_obj_t self_in) {
91-
const mp_obj_t pos_args[] = { self_in, MP_OBJ_FROM_PTR(&pb_Color_NONE_obj) };
92-
return pupdevices_ColorLightMatrix_on(MP_ARRAY_SIZE(pos_args), pos_args, NULL);
91+
pupdevices_ColorLightMatrix_obj_t *self = MP_OBJ_TO_PTR(self_in);
92+
int8_t color_ids[9] = { };
93+
return pb_type_device_set_data(&self->device_base, PBDRV_LEGODEV_MODE_PUP_COLOR_LIGHT_MATRIX__PIX_O, color_ids, sizeof(color_ids));
9394
}
9495
MP_DEFINE_CONST_FUN_OBJ_1(pupdevices_ColorLightMatrix_off_obj, pupdevices_ColorLightMatrix_off);
9596

0 commit comments

Comments
 (0)