Skip to content

Commit

Permalink
Merge remote-tracking branch 'OFW/portasynthinca3/usbuart-stay-fix' i…
Browse files Browse the repository at this point in the history
…nto dev
  • Loading branch information
xMasterX committed Sep 10, 2024
2 parents c1d31ed + c1a009a commit 2aa4797
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions applications/main/gpio/gpio_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ typedef enum {

GpioUsbUartEventConfig,
GpioUsbUartEventConfigSet,
GpioUsbUartEventStop,
} GpioCustomEvent;
7 changes: 3 additions & 4 deletions applications/main/gpio/scenes/gpio_scene_exit_confirm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 20 additions & 6 deletions applications/main/gpio/scenes/gpio_scene_usb_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 2aa4797

Please sign in to comment.