diff --git a/openrtx/include/state.h b/openrtx/include/state.h index 080ad6b3..a02fc7a2 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -36,6 +36,7 @@ typedef struct bool radioStateUpdated; curTime_t time; float v_bat; + float charge; uint8_t ui_screen; uint8_t backlight_level; diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 4e1e2f4a..ee06a0bd 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -20,6 +20,7 @@ #include #include +#include #include state_t state; @@ -35,6 +36,7 @@ void state_init() state.time = rtc_getTime(); #endif state.v_bat = platform_getVbat(); + state.charge = battery_getCharge(state.v_bat); state.backlight_level = 255; state.channelInfoUpdated = true; diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index f083128e..a3f04ab3 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -249,6 +250,7 @@ static void dev_task(void *arg) state.time = rtc_getTime(); #endif state.v_bat = platform_getVbat(); + state.charge = battery_getCharge(state.v_bat); OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index 756400d0..3840497d 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -49,12 +49,11 @@ void _ui_drawMainTop(state_t* last_state) #endif // Print battery icon on top bar, use 4 px padding - float charge = battery_getCharge(last_state->v_bat); uint16_t bat_width = SCREEN_WIDTH / 9; uint16_t bat_height = layout.top_h - (layout.status_v_pad * 2); point_t bat_pos = {SCREEN_WIDTH - bat_width - layout.horizontal_pad, layout.status_v_pad}; - gfx_drawBattery(bat_pos, bat_width, bat_height, charge); + gfx_drawBattery(bat_pos, bat_width, bat_height, last_state->charge); // Print radio mode on top bar char mode[4] = "";