mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-07 19:01:54 -07:00
Power off from locked (flipperdevices/flipperzero-firmware#1567)
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include "desktop_scene.h"
|
||||
#include "desktop_scene_i.h"
|
||||
|
||||
#define TAG "DesktopSrv"
|
||||
|
||||
#define WRONG_PIN_HEADER_TIMEOUT 3000
|
||||
#define INPUT_PIN_VIEW_TIMEOUT 15000
|
||||
|
||||
@@ -83,6 +85,14 @@ bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DesktopLockedEventOpenPowerOff: {
|
||||
LoaderStatus status = loader_start(desktop->loader, "Power", "off");
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
case DesktopLockedEventUnlocked:
|
||||
desktop_unlock(desktop);
|
||||
consumed = true;
|
||||
|
||||
@@ -23,6 +23,7 @@ typedef enum {
|
||||
DesktopMainEventOpenSubRemote,
|
||||
DesktopMainEventOpenClock,
|
||||
|
||||
DesktopLockedEventOpenPowerOff,
|
||||
DesktopLockedEventUnlocked,
|
||||
DesktopLockedEventUpdate,
|
||||
DesktopLockedEventShowPinInput,
|
||||
|
||||
@@ -231,6 +231,12 @@ static bool desktop_view_locked_input(InputEvent* event, void* context) {
|
||||
|
||||
desktop_view_locked_update_hint_icon_timeout(locked_view);
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
if(event->type == InputTypeLong) {
|
||||
locked_view->callback(DesktopLockedEventOpenPowerOff, locked_view->context);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_locked) {
|
||||
if(event->key == InputKeyUp) {
|
||||
locked_view->callback(DesktopLockedEventShowPinInput, locked_view->context);
|
||||
|
||||
@@ -13,16 +13,8 @@ struct DesktopMainView {
|
||||
View* view;
|
||||
DesktopMainViewCallback callback;
|
||||
void* context;
|
||||
TimerHandle_t poweroff_timer;
|
||||
};
|
||||
|
||||
#define DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT 1300
|
||||
|
||||
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(
|
||||
DesktopMainView* main_view,
|
||||
DesktopMainViewCallback callback,
|
||||
@@ -68,13 +60,8 @@ bool desktop_main_input_callback(InputEvent* event, void* 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);
|
||||
if(event->type == InputTypeLong) {
|
||||
main_view->callback(DesktopMainEventOpenPowerOff, main_view->context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,19 +75,11 @@ DesktopMainView* desktop_main_alloc() {
|
||||
view_set_context(main_view->view, main_view);
|
||||
view_set_input_callback(main_view->view, desktop_main_input_callback);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void desktop_main_free(DesktopMainView* main_view) {
|
||||
furi_assert(main_view);
|
||||
view_free(main_view->view);
|
||||
furi_timer_free(main_view->poweroff_timer);
|
||||
free(main_view);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static void power_settings_tick_event_callback(void* context) {
|
||||
scene_manager_handle_tick_event(app->scene_manager);
|
||||
}
|
||||
|
||||
PowerSettingsApp* power_settings_app_alloc(uint32_t first_scene) {
|
||||
PowerSettingsApp* power_settings_app_alloc(uint32_t first_scene, ViewDispatcherType type) {
|
||||
PowerSettingsApp* app = malloc(sizeof(PowerSettingsApp));
|
||||
|
||||
app->about_battery = first_scene == PowerSettingsAppSceneBatteryInfo;
|
||||
@@ -42,7 +42,10 @@ PowerSettingsApp* power_settings_app_alloc(uint32_t first_scene) {
|
||||
app->view_dispatcher, power_settings_back_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
app->view_dispatcher, power_settings_tick_event_callback, 2000);
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, type);
|
||||
if(type == ViewDispatcherTypeDesktop) {
|
||||
gui_set_hide_statusbar(app->gui, true);
|
||||
}
|
||||
|
||||
// Views
|
||||
app->battery_info = battery_info_alloc();
|
||||
@@ -95,14 +98,16 @@ void power_settings_app_free(PowerSettingsApp* app) {
|
||||
|
||||
int32_t power_settings_app(void* p) {
|
||||
uint32_t first_scene = PowerSettingsAppSceneStart;
|
||||
ViewDispatcherType type = ViewDispatcherTypeFullscreen;
|
||||
if(p && strlen(p)) {
|
||||
if(!strcmp(p, "off")) {
|
||||
first_scene = PowerSettingsAppScenePowerOff;
|
||||
type = ViewDispatcherTypeDesktop;
|
||||
} else if(!strcmp(p, "about_battery")) {
|
||||
first_scene = PowerSettingsAppSceneBatteryInfo;
|
||||
}
|
||||
}
|
||||
PowerSettingsApp* app = power_settings_app_alloc(first_scene);
|
||||
PowerSettingsApp* app = power_settings_app_alloc(first_scene, type);
|
||||
while(true) {
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
if(app->battery_info->exit_to_about) {
|
||||
@@ -114,6 +119,9 @@ int32_t power_settings_app(void* p) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(type == ViewDispatcherTypeDesktop) {
|
||||
gui_set_hide_statusbar(app->gui, false);
|
||||
}
|
||||
power_settings_app_free(app);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user