From 5232d5daba66640bf2fdf1955f9c723c377bd09e Mon Sep 17 00:00:00 2001 From: gornekich Date: Wed, 6 Oct 2021 18:41:22 +0300 Subject: [PATCH] [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 --- applications/gui/gui.c | 4 ++-- applications/gui/gui.h | 4 ++-- applications/gui/view_dispatcher.c | 12 ++++++++++++ applications/gui/view_dispatcher.h | 12 ++++++++++++ applications/power/power_cli.c | 5 ++--- applications/power/power_service/power.c | 9 ++++++++- applications/power/power_service/power_api.c | 7 ++++++- applications/power/power_service/power_i.h | 8 +++++++- .../power_settinfs_scene_usb_disconnect.c | 17 ----------------- .../scenes/power_settings_scene_config.h | 1 - .../scenes/power_settings_scene_power_off.c | 7 +------ make/rules.mk | 14 ++++++++++++++ 12 files changed, 66 insertions(+), 34 deletions(-) mode change 100644 => 100755 applications/power/power_service/power.c delete mode 100755 applications/power/power_settings_app/scenes/power_settinfs_scene_usb_disconnect.c diff --git a/applications/gui/gui.c b/applications/gui/gui.c index b167db70..a7e7f295 100644 --- a/applications/gui/gui.c +++ b/applications/gui/gui.c @@ -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); diff --git a/applications/gui/gui.h b/applications/gui/gui.h index e94278b5..eb68f520 100644 --- a/applications/gui/gui.h +++ b/applications/gui/gui.h @@ -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 * diff --git a/applications/gui/view_dispatcher.c b/applications/gui/view_dispatcher.c index b89e1c9b..c0246d97 100644 --- a/applications/gui/view_dispatcher.c +++ b/applications/gui/view_dispatcher.c @@ -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, diff --git a/applications/gui/view_dispatcher.h b/applications/gui/view_dispatcher.h index 7b22cfc9..07dc2ead 100755 --- a/applications/gui/view_dispatcher.h +++ b/applications/gui/view_dispatcher.h @@ -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 diff --git a/applications/power/power_cli.c b/applications/power/power_cli.c index 6ac955e6..4240ae45 100644 --- a/applications/power/power_cli.c +++ b/applications/power/power_cli.c @@ -5,10 +5,9 @@ #include 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) { diff --git a/applications/power/power_service/power.c b/applications/power/power_service/power.c old mode 100644 new mode 100755 index e17cad5d..de712fd4 --- a/applications/power/power_service/power.c +++ b/applications/power/power_service/power.c @@ -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); } } } diff --git a/applications/power/power_service/power_api.c b/applications/power/power_service/power_api.c index 388466d6..4147d17d 100644 --- a/applications/power/power_service/power_api.c +++ b/applications/power/power_service/power_api.c @@ -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) { diff --git a/applications/power/power_service/power_i.h b/applications/power/power_service/power_i.h index 35bba2d8..5bebd8cb 100755 --- a/applications/power/power_service/power_i.h +++ b/applications/power/power_service/power_i.h @@ -5,6 +5,8 @@ #include #include #include + +#include #include "views/power_off.h" #include @@ -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; diff --git a/applications/power/power_settings_app/scenes/power_settinfs_scene_usb_disconnect.c b/applications/power/power_settings_app/scenes/power_settinfs_scene_usb_disconnect.c deleted file mode 100755 index 1a76edcb..00000000 --- a/applications/power/power_settings_app/scenes/power_settinfs_scene_usb_disconnect.c +++ /dev/null @@ -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) { -} diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_config.h b/applications/power/power_settings_app/scenes/power_settings_scene_config.h index 569e907a..cc8656dc 100755 --- a/applications/power/power_settings_app/scenes/power_settings_scene_config.h +++ b/applications/power/power_settings_app/scenes/power_settings_scene_config.h @@ -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) diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c b/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c index 84a7910a..a389778a 100755 --- a/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c +++ b/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c @@ -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; } diff --git a/make/rules.mk b/make/rules.mk index fd50375a..0a8b2547 100644 --- a/make/rules.mk +++ b/make/rules.mk @@ -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)