[FL-2749] New power off screen #1637
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
8992f8ac36
commit
9317ded1a9
@ -55,13 +55,14 @@ Power* power_alloc() {
|
||||
|
||||
// Gui
|
||||
power->view_dispatcher = view_dispatcher_alloc();
|
||||
power->popup = popup_alloc();
|
||||
popup_set_header(
|
||||
power->popup, "Disconnect USB for safe\nshutdown", 64, 26, AlignCenter, AlignTop);
|
||||
view_dispatcher_add_view(power->view_dispatcher, PowerViewPopup, popup_get_view(power->popup));
|
||||
power->power_off = power_off_alloc();
|
||||
view_dispatcher_add_view(
|
||||
power->view_dispatcher, PowerViewOff, power_off_get_view(power->power_off));
|
||||
power->power_unplug_usb = power_unplug_usb_alloc();
|
||||
view_dispatcher_add_view(
|
||||
power->view_dispatcher,
|
||||
PowerViewUnplugUsb,
|
||||
power_unplug_usb_get_view(power->power_unplug_usb));
|
||||
view_dispatcher_attach_to_gui(
|
||||
power->view_dispatcher, power->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
@ -78,8 +79,9 @@ void power_free(Power* power) {
|
||||
// Gui
|
||||
view_dispatcher_remove_view(power->view_dispatcher, PowerViewOff);
|
||||
power_off_free(power->power_off);
|
||||
view_dispatcher_remove_view(power->view_dispatcher, PowerViewPopup);
|
||||
popup_free(power->popup);
|
||||
view_dispatcher_remove_view(power->view_dispatcher, PowerViewUnplugUsb);
|
||||
power_unplug_usb_free(power->power_unplug_usb);
|
||||
|
||||
view_port_free(power->battery_view_port);
|
||||
|
||||
// State
|
||||
|
@ -8,8 +8,8 @@ void power_off(Power* power) {
|
||||
furi_hal_power_off();
|
||||
// Notify user if USB is plugged
|
||||
view_dispatcher_send_to_front(power->view_dispatcher);
|
||||
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewPopup);
|
||||
furi_delay_ms(10);
|
||||
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewUnplugUsb);
|
||||
furi_delay_ms(100);
|
||||
furi_halt("Disconnect USB for safe shutdown");
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <gui/modules/popup.h>
|
||||
#include "views/power_off.h"
|
||||
#include "views/power_unplug_usb.h"
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
@ -21,8 +22,8 @@ typedef enum {
|
||||
|
||||
struct Power {
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Popup* popup;
|
||||
PowerOff* power_off;
|
||||
PowerUnplugUsb* power_unplug_usb;
|
||||
|
||||
ViewPort* battery_view_port;
|
||||
Gui* gui;
|
||||
@ -42,6 +43,6 @@ struct Power {
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
PowerViewPopup,
|
||||
PowerViewOff,
|
||||
PowerViewUnplugUsb,
|
||||
} PowerView;
|
||||
|
43
applications/power/power_service/views/power_unplug_usb.c
Normal file
43
applications/power/power_service/views/power_unplug_usb.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include "power_unplug_usb.h"
|
||||
#include <furi.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
struct PowerUnplugUsb {
|
||||
View* view;
|
||||
};
|
||||
|
||||
static void power_unplug_usb_draw_callback(Canvas* canvas, void* _model) {
|
||||
UNUSED(_model);
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Unplug_bg_top_128x14);
|
||||
canvas_draw_box(canvas, 0, 14, 128, (64 - 10 - 14));
|
||||
canvas_draw_icon(canvas, 0, (64 - 10), &I_Unplug_bg_bottom_128x10);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_aligned(
|
||||
canvas, 64, 32, AlignCenter, AlignCenter, "It's now safe to unplug\nUSB cable");
|
||||
}
|
||||
|
||||
PowerUnplugUsb* power_unplug_usb_alloc() {
|
||||
PowerUnplugUsb* power_unplug_usb = malloc(sizeof(PowerUnplugUsb));
|
||||
|
||||
power_unplug_usb->view = view_alloc();
|
||||
view_set_context(power_unplug_usb->view, power_unplug_usb);
|
||||
view_set_draw_callback(power_unplug_usb->view, power_unplug_usb_draw_callback);
|
||||
view_set_input_callback(power_unplug_usb->view, NULL);
|
||||
|
||||
return power_unplug_usb;
|
||||
}
|
||||
|
||||
void power_unplug_usb_free(PowerUnplugUsb* power_unplug_usb) {
|
||||
furi_assert(power_unplug_usb);
|
||||
view_free(power_unplug_usb->view);
|
||||
free(power_unplug_usb);
|
||||
}
|
||||
|
||||
View* power_unplug_usb_get_view(PowerUnplugUsb* power_unplug_usb) {
|
||||
furi_assert(power_unplug_usb);
|
||||
return power_unplug_usb->view;
|
||||
}
|
11
applications/power/power_service/views/power_unplug_usb.h
Normal file
11
applications/power/power_service/views/power_unplug_usb.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct PowerUnplugUsb PowerUnplugUsb;
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
PowerUnplugUsb* power_unplug_usb_alloc();
|
||||
|
||||
void power_unplug_usb_free(PowerUnplugUsb* power_unplug_usb);
|
||||
|
||||
View* power_unplug_usb_get_view(PowerUnplugUsb* power_unplug_usb);
|
BIN
assets/icons/Power/Unplug_bg_bottom_128x10.png
Normal file
BIN
assets/icons/Power/Unplug_bg_bottom_128x10.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
assets/icons/Power/Unplug_bg_top_128x14.png
Normal file
BIN
assets/icons/Power/Unplug_bg_top_128x14.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Loading…
Reference in New Issue
Block a user