Skip to content

Commit fbe84ff

Browse files
committed
rg_display: Added on-screen battery icon when battery is low (<2%) (rel #188)
As of now there is no way to disable it, but I will add a toggle later, likely in the LED menu (and rename the menu to Indicators or something)..
1 parent d1ade35 commit fbe84ff

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

components/retro-go/rg_display.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
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;
1413
static rg_surface_t *border;
1514
static rg_display_t display;
1615
static int16_t map_viewport_to_source_x[RG_SCREEN_WIDTH + 1];
@@ -45,6 +44,38 @@ static inline void lcd_send_buffer(uint16_t *buffer, size_t length);
4544
#include "drivers/display/dummy.h"
4645
#endif
4746

47+
static inline bool draw_on_screen_display(int y1, int y2)
48+
{
49+
static unsigned area_dirty = 0;
50+
rg_margins_t margins = rg_gui_get_safe_area();
51+
int left = display.screen.width - margins.right - 28;
52+
int top = margins.top + 4;
53+
int border = 3;
54+
int width = 20;
55+
int height = 14;
56+
57+
// Check if the region contains OSD to draw
58+
if (y2 < top || y1 > top + height)
59+
return false;
60+
61+
// Low battery indicator
62+
if (rg_system_get_indicator(RG_INDICATOR_POWER_LOW) && ((counters.totalFrames / 20) & 1))
63+
{
64+
rg_display_clear_rect(left, top, width, height, C_RED); // Main body
65+
rg_display_clear_rect(left + width, top + height / 4, border, height / 2, C_RED); // The tab
66+
rg_display_clear_rect(left + border, top + border, width - border * 2, height - border * 2, C_BLACK); // The fill
67+
area_dirty |= 1 << RG_INDICATOR_POWER_LOW;
68+
}
69+
else if (area_dirty)
70+
{
71+
if (display.viewport.left || display.viewport.top)
72+
rg_display_clear_rect(left, top, width + border, height, C_BLACK);
73+
memset(&screen_line_checksum[top], 0, sizeof(uint32_t) * height);
74+
area_dirty = 0;
75+
}
76+
return true;
77+
}
78+
4879
static inline unsigned blend_pixels(unsigned a, unsigned b)
4980
{
5081
// Fast path (taken 80-90% of the time)
@@ -102,6 +133,7 @@ static inline void write_update(const rg_surface_t *update)
102133
int lines_remaining = draw_height;
103134
int lines_updated = 0;
104135
int window_top = -1;
136+
int osd_threshold = 24;
105137

106138
for (int y = 0; y < draw_height;)
107139
{
@@ -211,6 +243,13 @@ static inline void write_update(const rg_surface_t *update)
211243
lcd_send_buffer(line_buffer, 0);
212244
}
213245

246+
// if (draw_on_screen_display(draw_top + y - lines_to_copy, draw_top + y))
247+
if (draw_top + y > osd_threshold && draw_on_screen_display(0, draw_top + y))
248+
{
249+
osd_threshold = 9999;
250+
window_top = -1;
251+
}
252+
214253
lines_remaining -= lines_to_copy;
215254
}
216255

@@ -328,7 +367,7 @@ static void display_task(void *arg)
328367
}
329368

330369
write_update(msg.dataPtr);
331-
370+
// draw_on_screen_display(0, display.screen.height);
332371
rg_task_receive(&msg);
333372

334373
lcd_sync();

0 commit comments

Comments
 (0)