From 46add610e1d780deb2e9fa9c482d7eb7d3f719b5 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sat, 31 Oct 2020 13:58:09 +0100 Subject: [PATCH] UI: Add battery indicator --- openrtx/src/ui.c | 16 +++++++++++++--- platform/targets/linux/platform.c | 5 ++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index dc0d5530..533162e7 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -58,17 +58,27 @@ #include "ui.h" #include "graphics.h" #include "rtc.h" +#include "platform.h" color_t color_white = {255, 255, 255}; void ui_drawTopBar() { - // Print clock on top bar, use 4 px padding - point_t clock_pos = {0, 5}; + // Top bar printing position, uses 4 px padding + point_t top_bar_pos = {0, 5}; + + // Print clock on top bar char clock_buf[6] = ""; curTime_t time = rtc_getTime(); snprintf(clock_buf, sizeof(clock_buf), "%2d:%2d", time.hour, time.minute); - gfx_print(clock_pos, clock_buf, FONT_SIZE_1, TEXT_ALIGN_CENTER, color_white); + gfx_print(top_bar_pos, clock_buf, FONT_SIZE_1, TEXT_ALIGN_CENTER, color_white); + + // Print battery voltage on top bar, use 4 px padding + // TODO: Replace with battery icon + char bat_buf[6] = ""; + float v_bat = platform_getVbat(); + snprintf(bat_buf, sizeof(bat_buf), "%.1fV", v_bat); + gfx_print(top_bar_pos, bat_buf, FONT_SIZE_1, TEXT_ALIGN_RIGHT, color_white); } void ui_drawMainScreen() diff --git a/platform/targets/linux/platform.c b/platform/targets/linux/platform.c index d5c4aace..cc6af635 100644 --- a/platform/targets/linux/platform.c +++ b/platform/targets/linux/platform.c @@ -34,10 +34,9 @@ void platform_setBacklightLevel(uint8_t level) printf("platform_setBacklightLevel(%u)\n", level); } - +// Simulate a fully charged lithium battery float platform_getVbat(){ - printf("platform_getVbat()\n"); - return 0.69; + return 7.8; }