[FL-2038] Power off and auto power off on first start screen (#821)
* Power: change power_off signature to match implementation * Desktop: auto power off on first start screen and with ok button. Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
parent
516a437305
commit
b3d8f0b950
@ -12,6 +12,7 @@
|
|||||||
#include <gui/scene_manager.h>
|
#include <gui/scene_manager.h>
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
|
#include <power/power_service/power.h>
|
||||||
|
|
||||||
#include "views/desktop_main.h"
|
#include "views/desktop_main.h"
|
||||||
#include "views/desktop_first_start.h"
|
#include "views/desktop_first_start.h"
|
||||||
|
@ -20,6 +20,7 @@ bool desktop_scene_first_start_on_event(void* context, SceneManagerEvent event)
|
|||||||
Desktop* desktop = (Desktop*)context;
|
Desktop* desktop = (Desktop*)context;
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
Storage* storage = NULL;
|
Storage* storage = NULL;
|
||||||
|
Power* power = NULL;
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
switch(event.event) {
|
switch(event.event) {
|
||||||
@ -30,6 +31,12 @@ bool desktop_scene_first_start_on_event(void* context, SceneManagerEvent event)
|
|||||||
scene_manager_previous_scene(desktop->scene_manager);
|
scene_manager_previous_scene(desktop->scene_manager);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
case DesktopFirstStartPoweroff:
|
||||||
|
power = furi_record_open("power");
|
||||||
|
power_off(power);
|
||||||
|
furi_record_close("power");
|
||||||
|
consumed = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -2,17 +2,21 @@
|
|||||||
#include "../desktop_i.h"
|
#include "../desktop_i.h"
|
||||||
#include "desktop_first_start.h"
|
#include "desktop_first_start.h"
|
||||||
|
|
||||||
void desktop_first_start_set_callback(
|
#define DESKTOP_FIRST_START_POWEROFF_SHORT 5000
|
||||||
DesktopFirstStartView* first_start_view,
|
#define DESKTOP_FIRST_START_POWEROFF_LONG (60 * 60 * 1000)
|
||||||
DesktopFirstStartViewCallback callback,
|
|
||||||
void* context) {
|
|
||||||
furi_assert(first_start_view);
|
|
||||||
furi_assert(callback);
|
|
||||||
first_start_view->callback = callback;
|
|
||||||
first_start_view->context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
void desktop_first_start_render(Canvas* canvas, void* model) {
|
struct DesktopFirstStartView {
|
||||||
|
View* view;
|
||||||
|
DesktopFirstStartViewCallback callback;
|
||||||
|
void* context;
|
||||||
|
osTimerId_t timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t page;
|
||||||
|
} DesktopFirstStartViewModel;
|
||||||
|
|
||||||
|
static void desktop_first_start_draw(Canvas* canvas, void* model) {
|
||||||
DesktopFirstStartViewModel* m = model;
|
DesktopFirstStartViewModel* m = model;
|
||||||
|
|
||||||
canvas_clear(canvas);
|
canvas_clear(canvas);
|
||||||
@ -62,46 +66,87 @@ void desktop_first_start_render(Canvas* canvas, void* model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
View* desktop_first_start_get_view(DesktopFirstStartView* first_start_view) {
|
static bool desktop_first_start_input(InputEvent* event, void* context) {
|
||||||
furi_assert(first_start_view);
|
|
||||||
return first_start_view->view;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool desktop_first_start_input(InputEvent* event, void* context) {
|
|
||||||
furi_assert(event);
|
furi_assert(event);
|
||||||
DesktopFirstStartView* first_start_view = context;
|
DesktopFirstStartView* instance = context;
|
||||||
|
|
||||||
if(event->type == InputTypeShort) {
|
if(event->type == InputTypeShort) {
|
||||||
DesktopFirstStartViewModel* model = view_get_model(first_start_view->view);
|
DesktopFirstStartViewModel* model = view_get_model(instance->view);
|
||||||
if(event->key == InputKeyLeft) {
|
if(event->key == InputKeyLeft) {
|
||||||
if(model->page > 0) model->page--;
|
if(model->page > 0) model->page--;
|
||||||
} else if(event->key == InputKeyRight) {
|
} else if(event->key == InputKeyRight) {
|
||||||
uint32_t page = ++model->page;
|
uint32_t page = ++model->page;
|
||||||
if(page > 8) {
|
if(page > 8) {
|
||||||
first_start_view->callback(DesktopFirstStartCompleted, first_start_view->context);
|
instance->callback(DesktopFirstStartCompleted, instance->context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view_commit_model(first_start_view->view, true);
|
view_commit_model(instance->view, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event->key == InputKeyOk) {
|
||||||
|
if(event->type == InputTypePress) {
|
||||||
|
osTimerStart(instance->timer, DESKTOP_FIRST_START_POWEROFF_SHORT);
|
||||||
|
} else if(event->type == InputTypeRelease) {
|
||||||
|
osTimerStop(instance->timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void desktop_first_start_timer_callback(void* context) {
|
||||||
|
DesktopFirstStartView* instance = context;
|
||||||
|
instance->callback(DesktopFirstStartPoweroff, instance->context);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void desktop_first_start_enter(void* context) {
|
||||||
|
DesktopFirstStartView* instance = context;
|
||||||
|
|
||||||
|
furi_assert(instance->timer == NULL);
|
||||||
|
instance->timer = osTimerNew(desktop_first_start_timer_callback, osTimerOnce, instance, NULL);
|
||||||
|
|
||||||
|
osTimerStart(instance->timer, DESKTOP_FIRST_START_POWEROFF_LONG);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void desktop_first_start_exit(void* context) {
|
||||||
|
DesktopFirstStartView* instance = context;
|
||||||
|
|
||||||
|
osTimerStop(instance->timer);
|
||||||
|
osTimerDelete(instance->timer);
|
||||||
|
instance->timer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
DesktopFirstStartView* desktop_first_start_alloc() {
|
DesktopFirstStartView* desktop_first_start_alloc() {
|
||||||
DesktopFirstStartView* first_start_view = furi_alloc(sizeof(DesktopFirstStartView));
|
DesktopFirstStartView* instance = furi_alloc(sizeof(DesktopFirstStartView));
|
||||||
first_start_view->view = view_alloc();
|
instance->view = view_alloc();
|
||||||
view_allocate_model(
|
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(DesktopFirstStartViewModel));
|
||||||
first_start_view->view, ViewModelTypeLocking, sizeof(DesktopFirstStartViewModel));
|
view_set_context(instance->view, instance);
|
||||||
view_set_context(first_start_view->view, first_start_view);
|
view_set_draw_callback(instance->view, (ViewDrawCallback)desktop_first_start_draw);
|
||||||
view_set_draw_callback(first_start_view->view, (ViewDrawCallback)desktop_first_start_render);
|
view_set_input_callback(instance->view, desktop_first_start_input);
|
||||||
view_set_input_callback(first_start_view->view, desktop_first_start_input);
|
view_set_enter_callback(instance->view, desktop_first_start_enter);
|
||||||
|
view_set_exit_callback(instance->view, desktop_first_start_exit);
|
||||||
|
|
||||||
return first_start_view;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void desktop_first_start_free(DesktopFirstStartView* first_start_view) {
|
void desktop_first_start_free(DesktopFirstStartView* instance) {
|
||||||
furi_assert(first_start_view);
|
furi_assert(instance);
|
||||||
|
|
||||||
view_free(first_start_view->view);
|
view_free(instance->view);
|
||||||
free(first_start_view);
|
free(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
View* desktop_first_start_get_view(DesktopFirstStartView* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->view;
|
||||||
|
}
|
||||||
|
|
||||||
|
void desktop_first_start_set_callback(
|
||||||
|
DesktopFirstStartView* instance,
|
||||||
|
DesktopFirstStartViewCallback callback,
|
||||||
|
void* context) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(callback);
|
||||||
|
instance->callback = callback;
|
||||||
|
instance->context = context;
|
||||||
}
|
}
|
||||||
|
@ -8,28 +8,20 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DesktopFirstStartCompleted,
|
DesktopFirstStartCompleted,
|
||||||
|
DesktopFirstStartPoweroff,
|
||||||
} DesktopFirstStartEvent;
|
} DesktopFirstStartEvent;
|
||||||
|
|
||||||
typedef struct DesktopFirstStartView DesktopFirstStartView;
|
typedef struct DesktopFirstStartView DesktopFirstStartView;
|
||||||
|
|
||||||
typedef void (*DesktopFirstStartViewCallback)(DesktopFirstStartEvent event, void* context);
|
typedef void (*DesktopFirstStartViewCallback)(DesktopFirstStartEvent event, void* context);
|
||||||
|
|
||||||
struct DesktopFirstStartView {
|
DesktopFirstStartView* desktop_first_start_alloc();
|
||||||
View* view;
|
|
||||||
DesktopFirstStartViewCallback callback;
|
|
||||||
void* context;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
void desktop_first_start_free(DesktopFirstStartView* main_view);
|
||||||
uint8_t page;
|
|
||||||
} DesktopFirstStartViewModel;
|
View* desktop_first_start_get_view(DesktopFirstStartView* main_view);
|
||||||
|
|
||||||
void desktop_first_start_set_callback(
|
void desktop_first_start_set_callback(
|
||||||
DesktopFirstStartView* main_view,
|
DesktopFirstStartView* main_view,
|
||||||
DesktopFirstStartViewCallback callback,
|
DesktopFirstStartViewCallback callback,
|
||||||
void* context);
|
void* context);
|
||||||
|
|
||||||
View* desktop_first_start_get_view(DesktopFirstStartView* main_view);
|
|
||||||
|
|
||||||
DesktopFirstStartView* desktop_first_start_alloc();
|
|
||||||
void desktop_first_start_free(DesktopFirstStartView* main_view);
|
|
||||||
|
@ -46,7 +46,7 @@ typedef struct {
|
|||||||
|
|
||||||
/** Power off device
|
/** Power off device
|
||||||
*/
|
*/
|
||||||
void power_off();
|
void power_off(Power* power);
|
||||||
|
|
||||||
/** Reboot device
|
/** Reboot device
|
||||||
* @param mode - PowerBootMode
|
* @param mode - PowerBootMode
|
||||||
|
Loading…
Reference in New Issue
Block a user