Skip to content

Commit 06f9f09

Browse files
committed
rg_system: Moved led animation to update_indicators
Right now it's just the blinking.
1 parent dfac63d commit 06f9f09

3 files changed

Lines changed: 36 additions & 30 deletions

File tree

components/retro-go/rg_display.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
static rg_task_t *display_task_queue;
1111
static rg_display_counters_t counters;
1212
static rg_display_config_t config;
13-
static rg_surface_t *osd;
13+
// static rg_surface_t *osd;
1414
static rg_surface_t *border;
1515
static rg_display_t display;
1616
static int16_t map_viewport_to_source_x[RG_SCREEN_WIDTH + 1];
@@ -214,12 +214,6 @@ static inline void write_update(const rg_surface_t *update)
214214
lines_remaining -= lines_to_copy;
215215
}
216216

217-
if (osd != NULL)
218-
{
219-
// TODO: Draw on screen display. By default it should be bottom left which is fine
220-
// for both virtual keyboard and info labels. Maybe make it configurable later...
221-
}
222-
223217
if (lines_updated > draw_height * 0.80f)
224218
counters.fullFrames++;
225219
else

components/retro-go/rg_system.c

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

253245
static 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

10451035
void 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

10521044
bool 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+
10691079
void rg_system_set_log_level(rg_log_level_t level)
10701080
{
10711081
if (level >= 0 && level < RG_LOG_MAX)

components/retro-go/rg_system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ void rg_system_set_indicator(rg_indicator_t indicator, bool on);
216216
bool rg_system_get_indicator(rg_indicator_t indicator);
217217
void rg_system_set_indicator_mask(rg_indicator_t indicator, bool on);
218218
bool rg_system_get_indicator_mask(rg_indicator_t indicator);
219+
bool rg_system_set_led_color(rg_color_t color);
220+
rg_color_t rg_system_get_led_color(void);
219221
void rg_system_set_tick_rate(int tickRate);
220222
int rg_system_get_tick_rate(void);
221223
void rg_system_set_overclock(int level);

0 commit comments

Comments
 (0)