Skip to content

Commit

Permalink
rg_system: Do not update LED if color unchanged
Browse files Browse the repository at this point in the history
gpio LED isn't very costly to update, but if there's an error it can be.

Also if we ever have support for neopixel, it would be absurd to constantly send the same color.
  • Loading branch information
ducalex committed Sep 17, 2024
1 parent 1209a7a commit 4e0caf8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions components/retro-go/rg_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static RTC_NOINIT_ATTR time_t rtcValue;
static bool panicTraceCleared = false;
static bool exitCalled = false;
static uint32_t indicators;
static rg_color_t ledColor = -1;
static rg_stats_t statistics;
static rg_app_t app;
static rg_task_t tasks[8];
Expand Down Expand Up @@ -183,20 +184,25 @@ static void update_statistics(void)
static void update_indicators(void)
{
uint32_t visibleIndicators = indicators & app.indicatorsMask;
rg_color_t ledColor = 0; // C_GREEN
rg_color_t newColor = 0; // C_GREEN

if (indicators & (3 << RG_INDICATOR_CRITICAL))
ledColor = C_RED; // Make it flash rapidly!
newColor = C_RED; // Make it flash rapidly!
else if (visibleIndicators & (1 << RG_INDICATOR_POWER_LOW))
ledColor = C_RED;
newColor = C_RED;
else if (visibleIndicators)
ledColor = C_BLUE;
newColor = C_BLUE;

// In some cases it can be costly to update the LED status, skip if unchanged
if (newColor == ledColor)
return;

#if defined(ESP_PLATFORM) && defined(RG_GPIO_LED)
// GPIO LED doesn't support colors, so any color = on
if (RG_GPIO_LED != GPIO_NUM_NC)
gpio_set_level(RG_GPIO_LED, ledColor != 0);
#endif
ledColor = newColor;
}

static void system_monitor_task(void *arg)
Expand Down

0 comments on commit 4e0caf8

Please sign in to comment.