mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-30 08:20:21 +00:00
[FL-1905] Fix power off notification (#748)
* view dispatcher: add set view front API * power: add power off notification * Gui: rename ViewPort `send_to` API. * Makefile: add blackmagick support Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
parent
c8b36dd406
commit
5232d5daba
12 changed files with 66 additions and 34 deletions
|
@ -335,7 +335,7 @@ void gui_remove_view_port(Gui* gui, ViewPort* view_port) {
|
|||
gui_unlock(gui);
|
||||
}
|
||||
|
||||
void gui_send_view_port_front(Gui* gui, ViewPort* view_port) {
|
||||
void gui_view_port_send_to_front(Gui* gui, ViewPort* view_port) {
|
||||
furi_assert(gui);
|
||||
furi_assert(view_port);
|
||||
|
||||
|
@ -361,7 +361,7 @@ void gui_send_view_port_front(Gui* gui, ViewPort* view_port) {
|
|||
gui_unlock(gui);
|
||||
}
|
||||
|
||||
void gui_send_view_port_back(Gui* gui, ViewPort* view_port) {
|
||||
void gui_view_port_send_to_back(Gui* gui, ViewPort* view_port) {
|
||||
furi_assert(gui);
|
||||
furi_assert(view_port);
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ void gui_remove_view_port(Gui* gui, ViewPort* view_port);
|
|||
* @param gui Gui instance
|
||||
* @param view_port ViewPort instance
|
||||
*/
|
||||
void gui_send_view_port_front(Gui* gui, ViewPort* view_port);
|
||||
void gui_view_port_send_to_front(Gui* gui, ViewPort* view_port);
|
||||
|
||||
/** Send ViewPort to the back
|
||||
*
|
||||
|
@ -64,7 +64,7 @@ void gui_send_view_port_front(Gui* gui, ViewPort* view_port);
|
|||
* @param gui Gui instance
|
||||
* @param view_port ViewPort instance
|
||||
*/
|
||||
void gui_send_view_port_back(Gui* gui, ViewPort* view_port);
|
||||
void gui_view_port_send_to_back(Gui* gui, ViewPort* view_port);
|
||||
|
||||
/** Set gui canvas commit callback
|
||||
*
|
||||
|
|
|
@ -177,6 +177,18 @@ void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t vi
|
|||
}
|
||||
}
|
||||
|
||||
void view_dispatcher_send_to_front(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->gui);
|
||||
gui_view_port_send_to_front(view_dispatcher->gui, view_dispatcher->view_port);
|
||||
}
|
||||
|
||||
void view_dispatcher_send_to_back(ViewDispatcher* view_dispatcher) {
|
||||
furi_assert(view_dispatcher);
|
||||
furi_assert(view_dispatcher->gui);
|
||||
gui_view_port_send_to_front(view_dispatcher->gui, view_dispatcher->view_port);
|
||||
}
|
||||
|
||||
void view_dispatcher_attach_to_gui(
|
||||
ViewDispatcher* view_dispatcher,
|
||||
Gui* gui,
|
||||
|
|
|
@ -139,6 +139,18 @@ void view_dispatcher_remove_view(ViewDispatcher* view_dispatcher, uint32_t view_
|
|||
*/
|
||||
void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t view_id);
|
||||
|
||||
/** Send ViewPort of this ViewDispatcher instance to front
|
||||
*
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
*/
|
||||
void view_dispatcher_send_to_front(ViewDispatcher* view_dispatcher);
|
||||
|
||||
/** Send ViewPort of this ViewDispatcher instance to back
|
||||
*
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
*/
|
||||
void view_dispatcher_send_to_back(ViewDispatcher* view_dispatcher);
|
||||
|
||||
/** Attach ViewDispatcher to GUI
|
||||
*
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
#include <furi-hal.h>
|
||||
|
||||
void power_cli_poweroff(Cli* cli, string_t args, void* context) {
|
||||
power_off();
|
||||
Power* power = furi_record_open("power");
|
||||
printf("It's now safe to disconnect USB from your flipper\r\n");
|
||||
while(cli_getc(cli)) {
|
||||
}
|
||||
power_off(power);
|
||||
}
|
||||
|
||||
void power_cli_reboot(Cli* cli, string_t args, void* context) {
|
||||
|
|
9
applications/power/power_service/power.c
Normal file → Executable file
9
applications/power/power_service/power.c
Normal file → Executable file
|
@ -41,6 +41,10 @@ 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));
|
||||
|
@ -63,6 +67,8 @@ 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_port_free(power->battery_view_port);
|
||||
|
||||
// State
|
||||
|
@ -124,6 +130,7 @@ static void power_check_low_battery(Power* power) {
|
|||
// Check battery charge and vbus voltage
|
||||
if((power->info.charge == 0) && (power->info.voltage_vbus < 4.0f)) {
|
||||
if(!power->battery_low) {
|
||||
view_dispatcher_send_to_front(power->view_dispatcher);
|
||||
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewOff);
|
||||
}
|
||||
power->battery_low = true;
|
||||
|
@ -139,7 +146,7 @@ static void power_check_low_battery(Power* power) {
|
|||
if(power->power_off_timeout) {
|
||||
power_off_set_time_left(power->power_off, power->power_off_timeout--);
|
||||
} else {
|
||||
power_off();
|
||||
power_off(power);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,13 @@
|
|||
#include "furi-hal-power.h"
|
||||
#include "furi-hal-boot.h"
|
||||
|
||||
void power_off() {
|
||||
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);
|
||||
osDelay(10);
|
||||
furi_crash("Disconnect USB for safe shutdown");
|
||||
}
|
||||
|
||||
void power_reboot(PowerBootMode mode) {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <stdint.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/gui.h>
|
||||
|
||||
#include <gui/modules/popup.h>
|
||||
#include "views/power_off.h"
|
||||
|
||||
#include <notification/notification-messages.h>
|
||||
|
@ -17,6 +19,7 @@ typedef enum {
|
|||
|
||||
struct Power {
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Popup* popup;
|
||||
PowerOff* power_off;
|
||||
|
||||
ViewPort* battery_view_port;
|
||||
|
@ -34,4 +37,7 @@ struct Power {
|
|||
uint8_t power_off_timeout;
|
||||
};
|
||||
|
||||
typedef enum { PowerViewOff } PowerView;
|
||||
typedef enum {
|
||||
PowerViewPopup,
|
||||
PowerViewOff,
|
||||
} PowerView;
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#include "../power_settings_app.h"
|
||||
|
||||
void power_settings_scene_usb_disconnect_on_enter(void* context) {
|
||||
PowerSettingsApp* app = context;
|
||||
|
||||
dialog_ex_set_header(
|
||||
app->dialog, "Disconnect USB for safe\nshutdown", 64, 26, AlignCenter, AlignTop);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, PowerSettingsAppViewDialog);
|
||||
}
|
||||
|
||||
bool power_settings_scene_usb_disconnect_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void power_settings_scene_usb_disconnect_on_exit(void* context) {
|
||||
}
|
|
@ -2,4 +2,3 @@ ADD_SCENE(power_settings, start, Start)
|
|||
ADD_SCENE(power_settings, battery_info, BatteryInfo)
|
||||
ADD_SCENE(power_settings, reboot, Reboot)
|
||||
ADD_SCENE(power_settings, power_off, PowerOff)
|
||||
ADD_SCENE(power_settings, usb_disconnect, UsbDisconnect)
|
||||
|
|
|
@ -30,12 +30,7 @@ bool power_settings_scene_power_off_on_event(void* context, SceneManagerEvent ev
|
|||
if(event.event == DialogExResultLeft) {
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
} else if(event.event == DialogExResultRight) {
|
||||
power_off();
|
||||
// Check if USB is connected
|
||||
power_get_info(app->power, &app->info);
|
||||
if(app->info.voltage_vbus > 4.0f) {
|
||||
scene_manager_next_scene(app->scene_manager, PowerSettingsAppSceneUsbDisconnect);
|
||||
}
|
||||
power_off(app->power);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
|
|
@ -95,6 +95,20 @@ debug_other:
|
|||
-ex "source ../debug/PyCortexMDebug/PyCortexMDebug.py" \
|
||||
-ex "svd_load $(SVD_FILE)" \
|
||||
|
||||
|
||||
blackmagic: flash
|
||||
arm-none-eabi-gdb-py \
|
||||
-ex 'target extended-remote $(BLACKMAGIC)' \
|
||||
-ex 'monitor swdp_scan' \
|
||||
-ex 'monitor debug_bmp enable' \
|
||||
-ex 'attach 1' \
|
||||
-ex "set confirm off" \
|
||||
-ex "source ../debug/FreeRTOS/FreeRTOS.py" \
|
||||
-ex "source ../debug/PyCortexMDebug/PyCortexMDebug.py" \
|
||||
-ex "svd_load $(SVD_FILE)" \
|
||||
-ex "compare-sections" \
|
||||
$(OBJ_DIR)/$(PROJECT).elf; \
|
||||
|
||||
openocd:
|
||||
openocd $(OPENOCD_OPTS)
|
||||
|
||||
|
|
Loading…
Reference in a new issue