From c1a009aed0e335badc4a004d1243c01dd8a6390a Mon Sep 17 00:00:00 2001 From: Anna Antonenko Date: Tue, 10 Sep 2024 19:58:44 +0300 Subject: [PATCH] fix: exit screen stopping bridge prematurely --- applications/main/gpio/gpio_custom_event.h | 1 + .../gpio/scenes/gpio_scene_exit_confirm.c | 7 +++-- .../main/gpio/scenes/gpio_scene_usb_uart.c | 26 ++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/applications/main/gpio/gpio_custom_event.h b/applications/main/gpio/gpio_custom_event.h index 72b8feccd0..b18ad698a1 100644 --- a/applications/main/gpio/gpio_custom_event.h +++ b/applications/main/gpio/gpio_custom_event.h @@ -10,4 +10,5 @@ typedef enum { GpioUsbUartEventConfig, GpioUsbUartEventConfigSet, + GpioUsbUartEventStop, } GpioCustomEvent; diff --git a/applications/main/gpio/scenes/gpio_scene_exit_confirm.c b/applications/main/gpio/scenes/gpio_scene_exit_confirm.c index efb0734a31..32977e5167 100644 --- a/applications/main/gpio/scenes/gpio_scene_exit_confirm.c +++ b/applications/main/gpio/scenes/gpio_scene_exit_confirm.c @@ -24,10 +24,9 @@ bool gpio_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) { 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); + consumed = scene_manager_previous_scene(app->scene_manager); + if(consumed && event.event == DialogExResultLeft) { + view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventStop); } } else if(event.type == SceneManagerEventTypeBack) { consumed = true; diff --git a/applications/main/gpio/scenes/gpio_scene_usb_uart.c b/applications/main/gpio/scenes/gpio_scene_usb_uart.c index 9a3514ca4f..6c6fdb23d4 100644 --- a/applications/main/gpio/scenes/gpio_scene_usb_uart.c +++ b/applications/main/gpio/scenes/gpio_scene_usb_uart.c @@ -8,6 +8,11 @@ typedef struct { static SceneUsbUartBridge* scene_usb_uart; +typedef enum { + UsbUartSceneStateInitialize, + UsbUartSceneStateKeep, +} UsbUartSceneState; + void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) { furi_assert(context); GpioApp* app = context; @@ -16,8 +21,9 @@ void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) { 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) { + UsbUartSceneState state = + scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart); + if(state == UsbUartSceneStateInitialize) { scene_usb_uart = malloc(sizeof(SceneUsbUartBridge)); scene_usb_uart->cfg.vcp_ch = 0; scene_usb_uart->cfg.uart_ch = 0; @@ -39,10 +45,18 @@ 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); + if(event.event == GpioUsbUartEventConfig) { + scene_manager_set_scene_state( + app->scene_manager, GpioSceneUsbUart, UsbUartSceneStateKeep); + scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg); + } else if(event.event == GpioUsbUartEventStop) { + scene_manager_set_scene_state( + app->scene_manager, GpioSceneUsbUart, UsbUartSceneStateInitialize); + scene_manager_search_and_switch_to_previous_scene(app->scene_manager, GpioSceneStart); + } return true; } else if(event.type == SceneManagerEventTypeBack) { + scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, UsbUartSceneStateKeep); scene_manager_next_scene(app->scene_manager, GpioSceneExitConfirm); return true; } else if(event.type == SceneManagerEventTypeTick) { @@ -61,8 +75,8 @@ 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) { + uint32_t state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart); + if(state == UsbUartSceneStateInitialize) { usb_uart_disable(app->usb_uart_bridge); free(scene_usb_uart); }