PFW-1397 Implement ON_MENU_ENTER to simplify code
ON_MENU_ENTER runs code within the brackets only once after a new menu is entered. For the tool change menu, this allows us to display the data and read from EEPROM only once.
This commit is contained in:
parent
a896dfd4e0
commit
82bd9db1d6
|
|
@ -29,6 +29,7 @@ uint8_t menu_line = 0;
|
||||||
uint8_t menu_item = 0;
|
uint8_t menu_item = 0;
|
||||||
uint8_t menu_row = 0;
|
uint8_t menu_row = 0;
|
||||||
uint8_t menu_top = 0;
|
uint8_t menu_top = 0;
|
||||||
|
static bool menu_changed; // flag to indicate a new menu was entered
|
||||||
|
|
||||||
uint8_t menu_clicked = 0;
|
uint8_t menu_clicked = 0;
|
||||||
|
|
||||||
|
|
@ -53,6 +54,7 @@ void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bo
|
||||||
menu_menu = menu;
|
menu_menu = menu;
|
||||||
lcd_encoder = encoder;
|
lcd_encoder = encoder;
|
||||||
menu_top = 0; //reset menu view. Needed if menu_back() is called from deep inside a menu, such as Support
|
menu_top = 0; //reset menu view. Needed if menu_back() is called from deep inside a menu, such as Support
|
||||||
|
menu_changed = true;
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END;
|
||||||
if (reset_menu_state)
|
if (reset_menu_state)
|
||||||
menu_data_reset();
|
menu_data_reset();
|
||||||
|
|
@ -347,6 +349,11 @@ bool __attribute__((noinline)) menu_item_leave(){
|
||||||
return ((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving;
|
return ((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool menu_item_enter() {
|
||||||
|
menu_changed = false;
|
||||||
|
return !menu_changed;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t menu_item_function_P(const char* str, menu_func_t func)
|
uint8_t menu_item_function_P(const char* str, menu_func_t func)
|
||||||
{
|
{
|
||||||
if (menu_item == menu_line)
|
if (menu_item == menu_line)
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,11 @@ extern uint8_t menu_item_back_P(const char* str);
|
||||||
#define ON_MENU_LEAVE(func) do { if (menu_item_leave()){ func } } while (0)
|
#define ON_MENU_LEAVE(func) do { if (menu_item_leave()){ func } } while (0)
|
||||||
extern bool menu_item_leave();
|
extern bool menu_item_leave();
|
||||||
|
|
||||||
|
/// Entering a new menu
|
||||||
|
/// @param func lines of code to run once upon enter a menu or submenu
|
||||||
|
#define ON_MENU_ENTER(func) do { if (menu_item_enter()){ func } } while (0)
|
||||||
|
extern bool menu_item_enter();
|
||||||
|
|
||||||
#define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
|
#define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
|
||||||
extern uint8_t menu_item_function_P(const char* str, menu_func_t func);
|
extern uint8_t menu_item_function_P(const char* str, menu_func_t func);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1230,12 +1230,13 @@ static void lcd_menu_fails_stats_mmu_total()
|
||||||
//! @endcode
|
//! @endcode
|
||||||
static void lcd_menu_toolchange_stats_mmu_total()
|
static void lcd_menu_toolchange_stats_mmu_total()
|
||||||
{
|
{
|
||||||
lcd_clear();
|
ON_MENU_ENTER(
|
||||||
uint32_t toolchanges = eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT);
|
lcd_set_cursor(0, 0);
|
||||||
lcd_set_cursor(0, 0);
|
lcd_puts_P(PSTR("Toolchange count:"));
|
||||||
lcd_puts_P(PSTR("Toolchange count:"));
|
lcd_set_cursor(10, 1);
|
||||||
lcd_set_cursor(10, 1);
|
lcd_print(eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT));
|
||||||
lcd_print(toolchanges);
|
);
|
||||||
|
|
||||||
menu_back_if_clicked_fb();
|
menu_back_if_clicked_fb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue