[FL-2749] New power off screen #1637

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov 2022-08-22 20:54:01 +03:00 committed by GitHub
parent 8992f8ac36
commit 9317ded1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 10 deletions

View File

@ -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

View File

@ -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");
}

View File

@ -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;

View 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;
}

View 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);

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB