mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-22 05:14:46 -07:00
Merge remote-tracking branch 'OFW/dev' into dev
This commit is contained in:
@@ -6,7 +6,7 @@ typedef struct {
|
||||
UsbUartState state;
|
||||
} SceneUsbUartBridge;
|
||||
|
||||
static SceneUsbUartBridge* scene_usb_uart;
|
||||
static SceneUsbUartBridge* scene_usb_uart = NULL;
|
||||
|
||||
typedef enum {
|
||||
UsbUartSceneStateInitialize,
|
||||
@@ -19,11 +19,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;
|
||||
UsbUartSceneState state =
|
||||
scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
|
||||
if(state == UsbUartSceneStateInitialize) {
|
||||
if(!scene_usb_uart) {
|
||||
scene_usb_uart = malloc(sizeof(SceneUsbUartBridge));
|
||||
scene_usb_uart->cfg.vcp_ch = 0;
|
||||
scene_usb_uart->cfg.uart_ch = 0;
|
||||
@@ -37,7 +47,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);
|
||||
}
|
||||
@@ -45,19 +54,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) {
|
||||
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);
|
||||
}
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg);
|
||||
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);
|
||||
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;
|
||||
@@ -75,10 +81,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 state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart);
|
||||
if(state == UsbUartSceneStateInitialize) {
|
||||
usb_uart_disable(app->usb_uart_bridge);
|
||||
free(scene_usb_uart);
|
||||
}
|
||||
notification_message(app->notifications, &sequence_display_backlight_enforce_auto);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user