From bdee6cf3b627db6e1b33265092cdc0330c9cf5f4 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 17 Feb 2022 14:21:03 -0800 Subject: [PATCH 1/2] Don't update status LED color on brightness change Brightness changes now happen when the LED isn't active or initialized. When not init, CP may crash. Fixes #5872 --- supervisor/shared/status_leds.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index 08b2935cb6..07ff9634e9 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -324,12 +324,9 @@ uint32_t color_brightness(uint32_t color, uint8_t brightness) { void set_status_brightness(uint8_t level) { #if CIRCUITPY_STATUS_LED rgb_status_brightness = level; - uint32_t current_color = current_status_color; - // Temporarily change the current color global to force the new_status_color call to update the - // LED. Usually duplicate calls of the same color are ignored without regard to brightness - // changes. - current_status_color = 0; - new_status_color(current_color); + // This is only called by user code and we're never controlling the status + // LED when user code is running. So, we don't need to update the current + // state (there is none.) #endif } From 7f3f4e409d2da94602d173ffd4803f855b2e4dc0 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 17 Feb 2022 14:37:25 -0800 Subject: [PATCH 2/2] Update set_rgb_status_brightness doc and arg check --- shared-bindings/supervisor/__init__.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index e7c4479d2a..c69f0e4174 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -76,16 +76,15 @@ STATIC mp_obj_t supervisor_disable_autoreload(void) { MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_autoreload_obj, supervisor_disable_autoreload); //| def set_rgb_status_brightness(brightness: int) -> None: -//| """Set brightness of status neopixel from 0-255 -//| `set_rgb_status_brightness` is called.""" +//| """Set brightness of status RGB LED from 0-255. This will take effect +//| after the current code finishes and the status LED is used to show +//| the finish state.""" //| ... //| STATIC mp_obj_t supervisor_set_rgb_status_brightness(mp_obj_t lvl) { // This must be int. If cast to uint8_t first, will never raise a ValueError. int brightness_int = mp_obj_get_int(lvl); - if (brightness_int < 0 || brightness_int > 255) { - mp_raise_ValueError(translate("Brightness must be between 0 and 255")); - } + mp_arg_validate_int_range(brightness_int, 0, 255, MP_QSTR_brightness); set_status_brightness((uint8_t)brightness_int); return mp_const_none; }