@@ -220,34 +220,26 @@ static void update_statistics(void)
220220 update_memory_statistics ();
221221}
222222
223- static void update_indicators (void )
223+ static void update_indicators (bool reset_animation )
224224{
225225 uint32_t visibleIndicators = indicators & app .indicatorsMask ;
226+ static int animation_step = 0 ;
226227 rg_color_t newColor = 0 ; // C_GREEN
227228
229+ if (reset_animation )
230+ animation_step = 0 ;
231+ else
232+ animation_step ++ ;
233+
228234 if (indicators & (3 << RG_INDICATOR_CRITICAL ))
229235 newColor = C_RED ; // Make it flash rapidly!
230236 else if (visibleIndicators & (1 << RG_INDICATOR_POWER_LOW ))
231- newColor = C_RED ;
237+ newColor = ( animation_step & 1 ) ? C_NONE : C_RED ;
232238 else if (visibleIndicators )
233239 newColor = C_BLUE ;
234240
235- // In some cases it can be costly to update the LED status, skip if unchanged
236- if (newColor == ledColor )
237- return ;
238-
239- ledColor = newColor ;
240-
241- #if defined(ESP_PLATFORM ) && defined(RG_GPIO_LED )
242- if (RG_GPIO_LED == GPIO_NUM_NC )
243- return ;
244- // GPIO LED doesn't support colors, so any color = on
245- int value = newColor != 0 ;
246- #ifdef RG_GPIO_LED_INVERT
247- value = !value ;
248- #endif
249- gpio_set_level (RG_GPIO_LED , value );
250- #endif
241+ if (newColor != ledColor )
242+ rg_system_set_led_color (newColor );
251243}
252244
253245static void system_monitor_task (void * arg )
@@ -263,12 +255,10 @@ static void system_monitor_task(void *arg)
263255 rtcValue = time (NULL );
264256
265257 update_statistics ();
266- // update_indicators(); // Implicitly called by rg_system_set_indicator below
267258
268259 rg_battery_t battery = rg_input_read_battery ();
269- // TODO: The flashing should eventually be handled by update_indicators instead of here...
270- rg_system_set_indicator (RG_INDICATOR_POWER_LOW , (battery .present && battery .level <= 2.f &&
271- !rg_system_get_indicator (RG_INDICATOR_POWER_LOW )));
260+ rg_system_set_indicator (RG_INDICATOR_POWER_LOW , (battery .present && battery .level <= 2.f ));
261+ update_indicators (false);
272262
273263 // Try to avoid complex conversions that could allocate, prefer rounding/ceiling if necessary.
274264 rg_system_log (RG_LOG_DEBUG , NULL , "STACK:%d, HEAP:%d+%d (%d+%d), BUSY:%d%%, FPS:%d (%d+%d+%d), BATT:%d\n" ,
@@ -1044,9 +1034,11 @@ bool rg_system_save_trace(const char *filename, bool panic_trace)
10441034
10451035void rg_system_set_indicator (rg_indicator_t indicator , bool on )
10461036{
1037+ uint32_t old_indicators = indicators ;
10471038 indicators &= ~(1 << indicator );
10481039 indicators |= (on << indicator );
1049- update_indicators ();
1040+ if (old_indicators != indicators )
1041+ update_indicators (true);
10501042}
10511043
10521044bool rg_system_get_indicator (rg_indicator_t indicator )
@@ -1066,6 +1058,24 @@ bool rg_system_get_indicator_mask(rg_indicator_t indicator)
10661058 return app .indicatorsMask & (1 << indicator );
10671059}
10681060
1061+ bool rg_system_set_led_color (rg_color_t color )
1062+ {
1063+ ledColor = color ;
1064+ #if defined(RG_GPIO_LED ) && defined(RG_GPIO_LED_INVERT )
1065+ return RG_GPIO_LED != GPIO_NUM_NC && gpio_set_level (RG_GPIO_LED , !(color > 0 )) == ESP_OK ;
1066+ #elif defined(RG_GPIO_LED )
1067+ // GPIO LED doesn't support colors, so any color = on
1068+ return RG_GPIO_LED != GPIO_NUM_NC && gpio_set_level (RG_GPIO_LED , (color > 0 )) == ESP_OK ;
1069+ #else
1070+ return true;
1071+ #endif
1072+ }
1073+
1074+ rg_color_t rg_system_get_led_color (void )
1075+ {
1076+ return ledColor ;
1077+ }
1078+
10691079void rg_system_set_log_level (rg_log_level_t level )
10701080{
10711081 if (level >= 0 && level < RG_LOG_MAX )
0 commit comments