Skip to content

Commit

Permalink
Fix USB-UART bridge exit screen stopping the bridge prematurely (#3892)
Browse files Browse the repository at this point in the history
* fix: exit screen stopping bridge prematurely
* refactor: merge exit confirmation scene into main usb uart scene
  • Loading branch information
portasynthinca3 authored Sep 12, 2024
1 parent 5f4f4fc commit 0428e82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 56 deletions.
1 change: 0 additions & 1 deletion applications/main/gpio/scenes/gpio_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
44 changes: 0 additions & 44 deletions applications/main/gpio/scenes/gpio_scene_exit_confirm.c

This file was deleted.

32 changes: 21 additions & 11 deletions applications/main/gpio/scenes/gpio_scene_usb_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@ 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);
GpioApp* app = 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;
Expand All @@ -31,19 +42,23 @@ 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);
}

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

0 comments on commit 0428e82

Please sign in to comment.