menu_data_reset()

This commit is contained in:
Alex Voinea 2020-03-04 22:20:53 +02:00
parent 40ebd455f2
commit 355b003b7f
No known key found for this signature in database
GPG key ID: F5034E7CFCF2F973
3 changed files with 12 additions and 9 deletions

View file

@ -39,6 +39,12 @@ menu_func_t menu_menu = 0;
static_assert(sizeof(menu_data)>= sizeof(menu_data_edit_t),"menu_data_edit_t doesn't fit into menu_data"); static_assert(sizeof(menu_data)>= sizeof(menu_data_edit_t),"menu_data_edit_t doesn't fit into menu_data");
void menu_data_reset(void)
{
// Resets the global shared C union.
// This ensures, that the menu entered will find out, that it shall initialize itself.
memset(&menu_data, 0, sizeof(menu_data));
}
void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state) void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state)
{ {
@ -49,11 +55,8 @@ void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bo
lcd_encoder = encoder; lcd_encoder = encoder;
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
if (reset_menu_state) if (reset_menu_state)
{ menu_data_reset();
// Resets the global shared C union.
// This ensures, that the menu entered will find out, that it shall initialize itself.
memset(&menu_data, 0, sizeof(menu_data));
}
if (feedback) lcd_quick_feedback(); if (feedback) lcd_quick_feedback();
} }
else else

View file

@ -64,7 +64,7 @@ extern uint8_t menu_leaving;
//function pointer to the currently active menu //function pointer to the currently active menu
extern menu_func_t menu_menu; extern menu_func_t menu_menu;
extern void menu_data_reset(void);
extern void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state); extern void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state);

View file

@ -7100,7 +7100,7 @@ static void lcd_sd_refresh()
#endif #endif
menu_top = 0; menu_top = 0;
lcd_encoder = 0; lcd_encoder = 0;
memset(&menu_data, 0, sizeof(menu_data)); //reset menu state. Forces reloading of cached variables. menu_data_reset(); //Forces reloading of cached variables.
} }
static void lcd_sd_updir() static void lcd_sd_updir()
@ -7108,7 +7108,7 @@ static void lcd_sd_updir()
card.updir(); card.updir();
menu_top = 0; menu_top = 0;
lcd_encoder = 0; lcd_encoder = 0;
memset(&menu_data, 0, sizeof(menu_data)); //reset menu state. Forces reloading of cached variables. menu_data_reset(); //Forces reloading of cached variables.
} }
void lcd_print_stop() void lcd_print_stop()
@ -8683,7 +8683,7 @@ void menu_action_sddirectory(const char* filename)
MYSERIAL.println(dir_names[depth]); MYSERIAL.println(dir_names[depth]);
card.chdir(filename); card.chdir(filename);
lcd_encoder = 0; lcd_encoder = 0;
memset(&menu_data, 0, sizeof(menu_data)); //reset menu state. Forces reloading of cached variables. menu_data_reset(); //Forces reloading of cached variables.
} }
/** LCD API **/ /** LCD API **/