Skip to content

Commit fb84df7

Browse files
committed
pybricks.pupdevices.Remote: Fix bad color due to aliasing violation.
In newer GCC version, this broke, causing the LED to get the wrong color.
1 parent 7073213 commit fb84df7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
pre-release ([pybricks-micropython#425]).
2626
- Fixed internal rounding error that could could cause a Drive Base to be 1 mm
2727
off after driving 3 meters, depending on configuration parameters ([support#2500]).
28-
28+
- Fixed Powered Up remote light getting the wrong color ([support#2497]).
2929

3030
[support#1962]: https://github.com/pybricks/support/issues/1962
3131
[support#2468]: https://github.com/pybricks/support/issues/2468
32+
[support#2497]: https://github.com/pybricks/support/issues/2497
3233
[support#2500]: https://github.com/pybricks/support/issues/2500
3334
[pybricks-micropython#405]: https://github.com/pybricks/pybricks-micropython/pull/405
3435
[pybricks-micropython#421]: https://github.com/pybricks/pybricks-micropython/pull/421

pybricks/iodevices/pb_type_iodevices_lwp3device.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,15 @@ static pbio_error_t pb_type_pupdevices_Remote_write_light_msg(mp_obj_t self_in,
241241
.cmd = LWP3_OUTPUT_CMD_WRITE_DIRECT_MODE_DATA,
242242
.mode = STATUS_LIGHT_MODE_RGB_0,
243243
};
244-
pbio_color_hsv_to_rgb(hsv, (pbio_color_rgb_t *)msg.payload);
244+
245+
pbio_color_rgb_t rgb;
246+
pbio_color_hsv_to_rgb(hsv, &rgb);
245247

246248
// The red LED on the handset is weak, so we have to reduce green and blue
247249
// to get the colors right.
248-
msg.payload[1] = msg.payload[1] * 3 / 8;
249-
msg.payload[2] = msg.payload[2] * 3 / 8;
250+
msg.payload[0] = rgb.r;
251+
msg.payload[1] = rgb.g * 3 / 8;
252+
msg.payload[2] = rgb.b * 3 / 8;
250253

251254
return pbdrv_bluetooth_peripheral_write_characteristic(pb_lwp3device_char.handle, (const uint8_t *)&msg, sizeof(msg));
252255
}

0 commit comments

Comments
 (0)