1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

Merge remote-tracking branch 'OFW/portasynthinca3/usbuart-stay-fix' into dev

This commit is contained in:
MX
2024-09-11 01:44:29 +03:00
3 changed files with 24 additions and 10 deletions

View File

@@ -10,4 +10,5 @@ typedef enum {
GpioUsbUartEventConfig, GpioUsbUartEventConfig,
GpioUsbUartEventConfigSet, GpioUsbUartEventConfigSet,
GpioUsbUartEventStop,
} GpioCustomEvent; } GpioCustomEvent;

View File

@@ -24,10 +24,9 @@ bool gpio_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) {
bool consumed = false; bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultRight) { consumed = scene_manager_previous_scene(app->scene_manager);
consumed = scene_manager_previous_scene(app->scene_manager); if(consumed && event.event == DialogExResultLeft) {
} else if(event.event == DialogExResultLeft) { view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventStop);
scene_manager_search_and_switch_to_previous_scene(app->scene_manager, GpioSceneStart);
} }
} else if(event.type == SceneManagerEventTypeBack) { } else if(event.type == SceneManagerEventTypeBack) {
consumed = true; consumed = true;

View File

@@ -8,6 +8,11 @@ typedef struct {
static SceneUsbUartBridge* scene_usb_uart; static SceneUsbUartBridge* scene_usb_uart;
typedef enum {
UsbUartSceneStateInitialize,
UsbUartSceneStateKeep,
} UsbUartSceneState;
void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) { void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) {
furi_assert(context); furi_assert(context);
GpioApp* app = 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) { void gpio_scene_usb_uart_on_enter(void* context) {
GpioApp* app = context; GpioApp* app = context;
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart); UsbUartSceneState state =
if(prev_state == 0) { scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
if(state == UsbUartSceneStateInitialize) {
scene_usb_uart = malloc(sizeof(SceneUsbUartBridge)); scene_usb_uart = malloc(sizeof(SceneUsbUartBridge));
scene_usb_uart->cfg.vcp_ch = 0; scene_usb_uart->cfg.vcp_ch = 0;
scene_usb_uart->cfg.uart_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) { bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
GpioApp* app = context; GpioApp* app = context;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 1); if(event.event == GpioUsbUartEventConfig) {
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg); 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; return true;
} else if(event.type == SceneManagerEventTypeBack) { } else if(event.type == SceneManagerEventTypeBack) {
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, UsbUartSceneStateKeep);
scene_manager_next_scene(app->scene_manager, GpioSceneExitConfirm); scene_manager_next_scene(app->scene_manager, GpioSceneExitConfirm);
return true; return true;
} else if(event.type == SceneManagerEventTypeTick) { } 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) { void gpio_scene_usb_uart_on_exit(void* context) {
GpioApp* app = context; GpioApp* app = context;
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart); uint32_t state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart);
if(prev_state == 0) { if(state == UsbUartSceneStateInitialize) {
usb_uart_disable(app->usb_uart_bridge); usb_uart_disable(app->usb_uart_bridge);
free(scene_usb_uart); free(scene_usb_uart);
} }