Commit 21f76bb7 authored by Federico Vaga's avatar Federico Vaga

fwatch: convert menu application to new model

Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent 40fc588c
......@@ -169,7 +169,7 @@ static void run(menu_entry *entry) {
static void go_back() {
if(current_menu == menu_stack) {
clock_app.main(NULL);
fwatch_application_run(&clock_app);
} else {
menu_size = 0;
selected_item = 0;
......@@ -181,44 +181,45 @@ static void go_back() {
menu_ui_init();
}
void menu_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int ret;
static int menu_setup(application* app) {
battery_update();
menu_size = get_menu_size(*current_menu);
// run clock as the the initial application
clock_app.main(NULL);
fwatch_application_run(&clock_app);
menu_ui_init();
return 0;
}
static void menu_loop(application* app)
{
struct event evt;
int ret;
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
return;
// Once it is deactivated - display the menu
while(1) {
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
continue;
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
go_back();
} else if(evt.data.button == BUT_TR) {
// run the selected application or submenu
run(&(*current_menu)->entries[selected_item]);
} else {
ui_update(&evt);
}
break;
default: // suppress warnings
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
go_back();
} else if(evt.data.button == BUT_TR) {
// run the selected application or submenu
run(&(*current_menu)->entries[selected_item]);
} else {
ui_update(&evt);
break;
}
break;
default: // suppress warnings
ui_update(&evt);
break;
}
}
application menu = {
.name = "Menu",
.main = menu_main
.setup = menu_setup,
.loop = menu_loop,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment