1212#include "rgb_led_status.h"
1313#include "samd21_pins.h"
1414
15+ uint8_t rgb_status_brightness = 255 ;
1516#ifdef MICROPY_HW_NEOPIXEL
1617static uint8_t status_neopixel_color [3 ];
1718static digitalio_digitalinout_obj_t status_neopixel ;
@@ -94,25 +95,26 @@ void new_status_color(uint32_t rgb) {
9495 if (current_status_color == rgb ) {
9596 return ;
9697 }
97- current_status_color = rgb ;
98+ uint32_t rgb_adjusted = color_brightness (rgb , rgb_status_brightness );
99+ current_status_color = rgb_adjusted ;
98100 #endif
99101
100102 #ifdef MICROPY_HW_NEOPIXEL
101103 if (neopixel_in_use ) {
102104 return ;
103105 }
104- status_neopixel_color [0 ] = (rgb >> 8 ) & 0xff ;
105- status_neopixel_color [1 ] = (rgb >> 16 ) & 0xff ;
106- status_neopixel_color [2 ] = rgb & 0xff ;
106+ status_neopixel_color [0 ] = (rgb_adjusted >> 8 ) & 0xff ;
107+ status_neopixel_color [1 ] = (rgb_adjusted >> 16 ) & 0xff ;
108+ status_neopixel_color [2 ] = rgb_adjusted & 0xff ;
107109 common_hal_neopixel_write (& status_neopixel , status_neopixel_color , 3 );
108110 #endif
109111 #if defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )
110112 if (apa102_mosi_in_use || apa102_sck_in_use ) {
111113 return ;
112114 }
113- status_apa102_color [5 ] = rgb & 0xff ;
114- status_apa102_color [6 ] = (rgb >> 8 ) & 0xff ;
115- status_apa102_color [7 ] = (rgb >> 16 ) & 0xff ;
115+ status_apa102_color [5 ] = rgb_adjusted & 0xff ;
116+ status_apa102_color [6 ] = (rgb_adjusted >> 8 ) & 0xff ;
117+ status_apa102_color [7 ] = (rgb_adjusted >> 16 ) & 0xff ;
116118
117119 #ifdef CIRCUITPY_BITBANG_APA102
118120 shared_module_bitbangio_spi_write (& status_apa102 , status_apa102_color , 8 );
@@ -123,18 +125,22 @@ void new_status_color(uint32_t rgb) {
123125}
124126
125127void temp_status_color (uint32_t rgb ) {
128+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
129+ uint32_t rgb_adjusted = rgb ;
130+ rgb_adjusted = color_brightness (rgb , rgb_status_brightness );
131+ #endif
126132 #ifdef MICROPY_HW_NEOPIXEL
127133 if (neopixel_in_use ) {
128134 return ;
129135 }
130- uint8_t colors [3 ] = {(rgb >> 8 ) & 0xff , (rgb >> 16 ) & 0xff , rgb & 0xff };
136+ uint8_t colors [3 ] = {(rgb_adjusted >> 8 ) & 0xff , (rgb_adjusted >> 16 ) & 0xff , rgb_adjusted & 0xff };
131137 common_hal_neopixel_write (& status_neopixel , colors , 3 );
132138 #endif
133139 #if defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )
134140 if (apa102_mosi_in_use || apa102_sck_in_use ) {
135141 return ;
136142 }
137- uint8_t colors [12 ] = {0 , 0 , 0 , 0 , 0xff , rgb & 0xff , (rgb >> 8 ) & 0xff , (rgb >> 16 ) & 0xff , 0x0 , 0x0 , 0x0 , 0x0 };
143+ uint8_t colors [12 ] = {0 , 0 , 0 , 0 , 0xff , rgb_adjusted & 0xff , (rgb_adjusted >> 8 ) & 0xff , (rgb_adjusted >> 16 ) & 0xff , 0x0 , 0x0 , 0x0 , 0x0 };
138144 #ifdef CIRCUITPY_BITBANG_APA102
139145 shared_module_bitbangio_spi_write (& status_apa102 , colors , 12 );
140146 #else
@@ -166,3 +172,7 @@ uint32_t color_brightness(uint32_t color, uint8_t brightness) {
166172 return color ;
167173 #endif
168174}
175+
176+ void set_rgb_status_brightness (uint8_t level ){
177+ rgb_status_brightness = level ;
178+ }
0 commit comments