mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 06:54:19 +00:00
Fix USB-UART bridge exit screen stopping the bridge prematurely (#3892)
* fix: exit screen stopping bridge prematurely * refactor: merge exit confirmation scene into main usb uart scene
This commit is contained in:
parent
5f4f4fcc60
commit
0428e82b14
3 changed files with 21 additions and 56 deletions
|
@ -3,4 +3,3 @@ ADD_SCENE(gpio, test, Test)
|
|||
ADD_SCENE(gpio, usb_uart, UsbUart)
|
||||
ADD_SCENE(gpio, usb_uart_cfg, UsbUartCfg)
|
||||
ADD_SCENE(gpio, usb_uart_close_rpc, UsbUartCloseRpc)
|
||||
ADD_SCENE(gpio, exit_confirm, ExitConfirm)
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
#include "gpio_app_i.h"
|
||||
|
||||
void gpio_scene_exit_confirm_dialog_callback(DialogExResult result, void* context) {
|
||||
GpioApp* app = context;
|
||||
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, result);
|
||||
}
|
||||
|
||||
void gpio_scene_exit_confirm_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
DialogEx* dialog = app->dialog;
|
||||
|
||||
dialog_ex_set_context(dialog, app);
|
||||
dialog_ex_set_left_button_text(dialog, "Exit");
|
||||
dialog_ex_set_right_button_text(dialog, "Stay");
|
||||
dialog_ex_set_header(dialog, "Exit USB-UART?", 22, 12, AlignLeft, AlignTop);
|
||||
dialog_ex_set_result_callback(dialog, gpio_scene_exit_confirm_dialog_callback);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewExitConfirm);
|
||||
}
|
||||
|
||||
bool gpio_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
GpioApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == DialogExResultRight) {
|
||||
consumed = scene_manager_previous_scene(app->scene_manager);
|
||||
} else if(event.event == DialogExResultLeft) {
|
||||
scene_manager_search_and_switch_to_previous_scene(app->scene_manager, GpioSceneStart);
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void gpio_scene_exit_confirm_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
|
||||
// Clean view
|
||||
dialog_ex_reset(app->dialog);
|
||||
}
|
|
@ -6,7 +6,7 @@ typedef struct {
|
|||
UsbUartState state;
|
||||
} SceneUsbUartBridge;
|
||||
|
||||
static SceneUsbUartBridge* scene_usb_uart;
|
||||
static SceneUsbUartBridge* scene_usb_uart = NULL;
|
||||
|
||||
void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
|
@ -14,10 +14,21 @@ void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) {
|
|||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_dialog_callback(DialogExResult result, void* context) {
|
||||
GpioApp* app = context;
|
||||
if(result == DialogExResultLeft) {
|
||||
usb_uart_disable(app->usb_uart_bridge);
|
||||
free(scene_usb_uart);
|
||||
scene_usb_uart = NULL;
|
||||
scene_manager_search_and_switch_to_previous_scene(app->scene_manager, GpioSceneStart);
|
||||
} else {
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUart);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
|
||||
if(prev_state == 0) {
|
||||
if(!scene_usb_uart) {
|
||||
scene_usb_uart = malloc(sizeof(SceneUsbUartBridge));
|
||||
scene_usb_uart->cfg.vcp_ch = 0;
|
||||
scene_usb_uart->cfg.uart_ch = 0;
|
||||
|
@ -31,7 +42,6 @@ void gpio_scene_usb_uart_on_enter(void* context) {
|
|||
usb_uart_get_state(app->usb_uart_bridge, &scene_usb_uart->state);
|
||||
|
||||
gpio_usb_uart_set_callback(app->gpio_usb_uart, gpio_scene_usb_uart_callback, app);
|
||||
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 0);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUart);
|
||||
notification_message(app->notifications, &sequence_display_backlight_enforce_on);
|
||||
}
|
||||
|
@ -39,11 +49,16 @@ void gpio_scene_usb_uart_on_enter(void* context) {
|
|||
bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
|
||||
GpioApp* app = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 1);
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneExitConfirm);
|
||||
DialogEx* dialog = app->dialog;
|
||||
dialog_ex_set_context(dialog, app);
|
||||
dialog_ex_set_left_button_text(dialog, "Exit");
|
||||
dialog_ex_set_right_button_text(dialog, "Stay");
|
||||
dialog_ex_set_header(dialog, "Exit USB-UART?", 22, 12, AlignLeft, AlignTop);
|
||||
dialog_ex_set_result_callback(dialog, gpio_scene_usb_uart_dialog_callback);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewExitConfirm);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
uint32_t tx_cnt_last = scene_usb_uart->state.tx_cnt;
|
||||
|
@ -61,10 +76,5 @@ bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
|
|||
|
||||
void gpio_scene_usb_uart_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart);
|
||||
if(prev_state == 0) {
|
||||
usb_uart_disable(app->usb_uart_bridge);
|
||||
free(scene_usb_uart);
|
||||
}
|
||||
notification_message(app->notifications, &sequence_display_backlight_enforce_auto);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue