Optimise LCD update RAII
It's currently only used in one place. But with these changes it becomes much much more cheaper to use in more places. Change in memory: Flash: -14 bytes
This commit is contained in:
parent
3c64874e20
commit
5f102007a8
|
|
@ -139,22 +139,23 @@ extern void lcd_buttons_update(void);
|
|||
//! When destroyed (gone out of scope), original state of LCD update is restored.
|
||||
//! It has zero overhead compared to storing bool saved = lcd_update_enabled
|
||||
//! and calling lcd_update_enable(false) and lcd_update_enable(saved).
|
||||
class LcdUpdateDisabler
|
||||
struct LCDUpdateEnableRAII
|
||||
{
|
||||
public:
|
||||
LcdUpdateDisabler(): m_updateEnabled(lcd_update_enabled)
|
||||
explicit inline __attribute__((always_inline)) LCDUpdateEnableRAII(): m_updateEnabled(lcd_update_enabled)
|
||||
{
|
||||
lcd_update_enable(false);
|
||||
lcd_update_enabled = 0;
|
||||
}
|
||||
~LcdUpdateDisabler()
|
||||
{
|
||||
lcd_update_enable(m_updateEnabled);
|
||||
inline __attribute__((always_inline)) ~LCDUpdateEnableRAII() {
|
||||
lcd_update_enabled = m_updateEnabled;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_updateEnabled;
|
||||
uint8_t m_updateEnabled;
|
||||
};
|
||||
|
||||
static_assert(sizeof(LCDUpdateEnableRAII) == 1);
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
//! @brief Was button clicked?
|
||||
|
|
|
|||
|
|
@ -2942,7 +2942,7 @@ const char* lcd_display_message_fullscreen_P(const char *msg)
|
|||
*/
|
||||
void lcd_show_fullscreen_message_and_wait_P(const char *msg)
|
||||
{
|
||||
LcdUpdateDisabler lcdUpdateDisabler;
|
||||
LCDUpdateEnableRAII lcdUpdateDisabler;
|
||||
const char *msg_next = lcd_display_message_fullscreen_P(msg);
|
||||
bool multi_screen = msg_next != NULL;
|
||||
lcd_consume_click();
|
||||
|
|
|
|||
Loading…
Reference in New Issue