diff --git a/openrtx/src/main.c b/openrtx/src/main.c index 750069a6..5b052835 100644 --- a/openrtx/src/main.c +++ b/openrtx/src/main.c @@ -18,17 +18,88 @@ * along with this program; if not, see * ***************************************************************************/ +#include +#include #include -#include "threads.h" -#include "platform.h" +#include +#include +#include +#include +#include +#include + +/* If battery level is below 0% draw low battery screen, wait and shutdown */ +void check_battery() { + OS_ERR os_err; + + // Check battery percentage + float vbat = platform_getVbat(); + float charge = battery_getCharge(vbat); + + // Draw low battery screen + if (charge <= 0) { + gfx_clearScreen(); + uint16_t bat_width = SCREEN_WIDTH / 2; + uint16_t bat_height = SCREEN_HEIGHT / 3; + point_t bat_pos = {SCREEN_WIDTH / 4, SCREEN_HEIGHT / 6}; + gfx_drawBattery(bat_pos, bat_width, bat_height, 0.1f); + point_t text_pos_1 = {0, SCREEN_HEIGHT * 3 / 4}; + point_t text_pos_2 = {0, SCREEN_HEIGHT * 3 / 4 + 16}; + const color_t color_white = {255, 255, 255}; + + gfx_print(text_pos_1, + "For emergency operation", + FONT_SIZE_6PT, + TEXT_ALIGN_CENTER, + color_white); + gfx_print(text_pos_2, + "press any button.", + FONT_SIZE_6PT, + TEXT_ALIGN_CENTER, + color_white); + gfx_render(); + + // Wait 5 seconds + OSTimeDlyHMSM(0u, 0u, 5u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); + + // TODO: Shut down radio unless a button is pressed + } +} int main(void) { + OS_ERR os_err; + // Initialize platform drivers platform_init(); + // Initialize graphics driver + gfx_init(); + + // Initialize user interface + ui_init(); + + // Check if battery has enough charge to operate + check_battery(); + + // Display splash screen + ui_drawSplashScreen(); + gfx_render(); + while(gfx_renderingInProgress()); + + // Wait 30ms before turning on backlight to hide random pixels on screen + OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); + platform_setBacklightLevel(255); + + // Keep the splash screen for 1 second + OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); + // Create OpenRTX threads create_threads(); - return 0; + // Auxiliary functions loop + while(true) { + check_battery(); + OSTimeDlyHMSM(0u, 1u, 0u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); + } } diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index ac054384..e0371ab8 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -79,23 +79,6 @@ static void ui_task(void *arg) OS_ERR os_err; OS_MSG_SIZE msg_size = 0; - // Initialize graphics driver - gfx_init(); - // Initialize user interface - ui_init(); - - // Display splash screen - ui_drawSplashScreen(); - gfx_render(); - while(gfx_renderingInProgress()); - - // Wait 30ms before turning on backlight to hide random pixels on screen - OSTimeDlyHMSM(0u, 0u, 0u, 30u, OS_OPT_TIME_HMSM_STRICT, &os_err); - platform_setBacklightLevel(255); - - // Keep the splash screen for 1 second - OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); - // Get initial state local copy OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); state_t last_state = state;