Desktop: poweroff timer and 5 seconds delay and other improvements (#1312)
* Desktop: poweroff timer and 5 seconds delay * Desktop: cleanup logic in settings application
This commit is contained in:
parent
47acf24801
commit
cc861dd92b
@ -38,7 +38,4 @@ typedef struct {
|
|||||||
bool pincode_buffer_filled;
|
bool pincode_buffer_filled;
|
||||||
|
|
||||||
uint8_t menu_idx;
|
uint8_t menu_idx;
|
||||||
|
|
||||||
bool setting_primary_favorite;
|
|
||||||
|
|
||||||
} DesktopSettingsApp;
|
} DesktopSettingsApp;
|
||||||
|
@ -21,10 +21,13 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
|
|||||||
app);
|
app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t primary_favorite =
|
||||||
|
scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||||
|
|
||||||
submenu_set_header(
|
submenu_set_header(
|
||||||
app->submenu,
|
app->submenu, primary_favorite ? "Primary favorite app:" : "Secondary favorite app:");
|
||||||
app->setting_primary_favorite ? "Primary favorite app:" : "Secondary favorite app:");
|
|
||||||
if(app->setting_primary_favorite) {
|
if(primary_favorite) {
|
||||||
submenu_set_selected_item(app->submenu, app->settings.favorite_primary);
|
submenu_set_selected_item(app->submenu, app->settings.favorite_primary);
|
||||||
} else {
|
} else {
|
||||||
submenu_set_selected_item(app->submenu, app->settings.favorite_secondary);
|
submenu_set_selected_item(app->submenu, app->settings.favorite_secondary);
|
||||||
@ -36,18 +39,17 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e
|
|||||||
DesktopSettingsApp* app = context;
|
DesktopSettingsApp* app = context;
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
|
uint32_t primary_favorite =
|
||||||
|
scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
switch(event.event) {
|
if(primary_favorite) {
|
||||||
default:
|
app->settings.favorite_primary = event.event;
|
||||||
if(app->setting_primary_favorite) {
|
} else {
|
||||||
app->settings.favorite_primary = event.event;
|
app->settings.favorite_secondary = event.event;
|
||||||
} else {
|
|
||||||
app->settings.favorite_secondary = event.event;
|
|
||||||
}
|
|
||||||
scene_manager_previous_scene(app->scene_manager);
|
|
||||||
consumed = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
scene_manager_previous_scene(app->scene_manager);
|
||||||
|
consumed = true;
|
||||||
}
|
}
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even
|
|||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
switch(event.event) {
|
switch(event.event) {
|
||||||
case SCENE_EVENT_SELECT_FAVORITE_PRIMARY:
|
case SCENE_EVENT_SELECT_FAVORITE_PRIMARY:
|
||||||
app->setting_primary_favorite = true;
|
scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 1);
|
||||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
case SCENE_EVENT_SELECT_FAVORITE_SECONDARY:
|
case SCENE_EVENT_SELECT_FAVORITE_SECONDARY:
|
||||||
app->setting_primary_favorite = false;
|
scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 0);
|
||||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
@ -13,8 +13,16 @@ struct DesktopMainView {
|
|||||||
View* view;
|
View* view;
|
||||||
DesktopMainViewCallback callback;
|
DesktopMainViewCallback callback;
|
||||||
void* context;
|
void* context;
|
||||||
|
TimerHandle_t poweroff_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT 5000
|
||||||
|
|
||||||
|
static void desktop_main_poweroff_timer_callback(TimerHandle_t timer) {
|
||||||
|
DesktopMainView* main_view = pvTimerGetTimerID(timer);
|
||||||
|
main_view->callback(DesktopMainEventOpenPowerOff, main_view->context);
|
||||||
|
}
|
||||||
|
|
||||||
void desktop_main_set_callback(
|
void desktop_main_set_callback(
|
||||||
DesktopMainView* main_view,
|
DesktopMainView* main_view,
|
||||||
DesktopMainViewCallback callback,
|
DesktopMainViewCallback callback,
|
||||||
@ -53,8 +61,17 @@ bool desktop_main_input(InputEvent* event, void* context) {
|
|||||||
main_view->callback(DesktopMainEventOpenDebug, main_view->context);
|
main_view->callback(DesktopMainEventOpenDebug, main_view->context);
|
||||||
} else if(event->key == InputKeyLeft) {
|
} else if(event->key == InputKeyLeft) {
|
||||||
main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context);
|
main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context);
|
||||||
} else if(event->key == InputKeyBack) {
|
}
|
||||||
main_view->callback(DesktopMainEventOpenPowerOff, main_view->context);
|
}
|
||||||
|
|
||||||
|
if(event->key == InputKeyBack) {
|
||||||
|
if(event->type == InputTypePress) {
|
||||||
|
xTimerChangePeriod(
|
||||||
|
main_view->poweroff_timer,
|
||||||
|
pdMS_TO_TICKS(DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT),
|
||||||
|
portMAX_DELAY);
|
||||||
|
} else if(event->type == InputTypeRelease) {
|
||||||
|
xTimerStop(main_view->poweroff_timer, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,11 +86,19 @@ DesktopMainView* desktop_main_alloc() {
|
|||||||
view_set_context(main_view->view, main_view);
|
view_set_context(main_view->view, main_view);
|
||||||
view_set_input_callback(main_view->view, desktop_main_input);
|
view_set_input_callback(main_view->view, desktop_main_input);
|
||||||
|
|
||||||
|
main_view->poweroff_timer = xTimerCreate(
|
||||||
|
NULL,
|
||||||
|
pdMS_TO_TICKS(DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT),
|
||||||
|
pdFALSE,
|
||||||
|
main_view,
|
||||||
|
desktop_main_poweroff_timer_callback);
|
||||||
|
|
||||||
return main_view;
|
return main_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void desktop_main_free(DesktopMainView* main_view) {
|
void desktop_main_free(DesktopMainView* main_view) {
|
||||||
furi_assert(main_view);
|
furi_assert(main_view);
|
||||||
view_free(main_view->view);
|
view_free(main_view->view);
|
||||||
|
osTimerDelete(main_view->poweroff_timer);
|
||||||
free(main_view);
|
free(main_view);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user