Small optimisation of UI management: perform an update and render of the graphics only when necessary

This commit is contained in:
Silvano Seva 2022-08-04 22:48:41 +02:00
parent 3ab36f3738
commit b26d783429
3 changed files with 25 additions and 6 deletions

View File

@ -243,8 +243,10 @@ void ui_updateFSM(bool *sync_rtx);
/** /**
* This function redraws the GUI based on the last radio state. * This function redraws the GUI based on the last radio state.
*
* @return true if GUI has been updated and a screen render is necessary.
*/ */
void ui_updateGUI(); bool ui_updateGUI();
/** /**
* Push an event to the UI event queue. * Push an event to the UI event queue.

View File

@ -100,9 +100,11 @@ void *ui_task(void *arg)
sync_rtx = false; sync_rtx = false;
} }
// Update UI and render on screen // Update UI and render on screen, if necessary
ui_updateGUI(); if(ui_updateGUI() == true)
gfx_render(); {
gfx_render();
}
// 40Hz update rate for keyboard and UI // 40Hz update rate for keyboard and UI
time += 25; time += 25;

View File

@ -722,6 +722,7 @@ void _ui_enterStandby()
return; return;
standby = true; standby = true;
redraw_needed = false;
platform_setBacklightLevel(0); platform_setBacklightLevel(0);
} }
@ -733,6 +734,7 @@ bool _ui_exitStandby(long long now)
return false; return false;
standby = false; standby = false;
redraw_needed = true;
platform_setBacklightLevel(state.settings.brightness); platform_setBacklightLevel(state.settings.brightness);
return true; return true;
} }
@ -945,6 +947,11 @@ void ui_updateFSM(bool *sync_rtx)
event_t event = evQueue[evQueue_rdPos]; event_t event = evQueue[evQueue_rdPos];
evQueue_rdPos = newTail; evQueue_rdPos = newTail;
// There is some event to process, we need an UI redraw.
// UI redraw request is cancelled if we're in standby mode.
redraw_needed = true;
if(standby) redraw_needed = false;
// Check if battery has enough charge to operate. // Check if battery has enough charge to operate.
// Check is skipped if there is an ongoing transmission, since the voltage // Check is skipped if there is an ongoing transmission, since the voltage
// drop caused by the RF PA power absorption causes spurious triggers of // drop caused by the RF PA power absorption causes spurious triggers of
@ -1668,8 +1675,11 @@ void ui_updateFSM(bool *sync_rtx)
} }
} }
void ui_updateGUI() bool ui_updateGUI()
{ {
if(redraw_needed == false)
return false;
if(!layout_ready) if(!layout_ready)
{ {
layout = _ui_calculateLayout(); layout = _ui_calculateLayout();
@ -1777,11 +1787,16 @@ void ui_updateGUI()
_ui_drawLowBatteryScreen(); _ui_drawLowBatteryScreen();
break; break;
} }
// If MACRO menu is active draw it // If MACRO menu is active draw it
if(macro_menu) { if(macro_menu)
{
_ui_drawDarkOverlay(); _ui_drawDarkOverlay();
_ui_drawMacroMenu(&last_state); _ui_drawMacroMenu(&last_state);
} }
redraw_needed = false;
return true;
} }
bool ui_pushEvent(const uint8_t type, const uint32_t data) bool ui_pushEvent(const uint8_t type, const uint32_t data)