Преглед изворни кода

Add mayhem_morseflash from https://github.com/eried/flipperzero-mayhem

git-subtree-dir: mayhem_morseflash
git-subtree-mainline: e667cf6bd72eb0299f33a4eb34574beab826c9aa
git-subtree-split: 416dc0bff9c6f269ca48ad73a0e58be51b1b31e7
Willy-JL пре 9 месеци
родитељ
комит
485696e09d

+ 1 - 0
mayhem_morseflash/.gitsubtree

@@ -0,0 +1 @@
+https://github.com/eried/flipperzero-mayhem next flipper_companion_apps/applications/external/mayhem_morseflash c400a80d2397543ca5d8160840ed6f2d281aa837

+ 24 - 0
mayhem_morseflash/LICENSE

@@ -0,0 +1,24 @@
+MIT License
+
+Copyright (c) 2023 Malik cool4uma
+
+Copyright (c) 2023 Erwin Ried
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+

+ 45 - 0
mayhem_morseflash/README.md

@@ -0,0 +1,45 @@
+# UART Terminal for Flipper Zero
+[Flipper Zero](https://flipperzero.one/) app to control various devices via UART interface.
+
+## Capabilities
+- Read log and command output by uart
+- Send commands by uart
+- Set baud rate
+- Fast commands
+
+## Connecting
+| Flipper Zero pin | UART interface  |
+| ---------------- | --------------- |
+| 13 TX            | RX              |
+| 14 RX            | TX              |
+|8, 18 GND         | GND             |
+
+Info: If possible, do not power your devices from 3V3 (pin 9) Flipper Zero. It does not support hot plugging.
+
+## Keyboard
+UART_terminal uses its own special keyboard for work, which has all the symbols necessary for working in the console.
+
+To accommodate more characters on a small display, some characters are called up by holding.
+
+![kbf](https://user-images.githubusercontent.com/122148894/212286637-7063f1ee-c6ff-46b9-8dc5-79a5f367fab1.png)
+
+
+## How to install
+Copy the contents of the repository to the applications_user/uart_terminal folder Flipper Zero firmware and build app with the command ./fbt fap_uart_terminal.
+
+Or use the tool [uFBT](https://github.com/flipperdevices/flipperzero-ufbt) for building applications for Flipper Zero.
+
+## How it works
+
+
+![1f](https://user-images.githubusercontent.com/122148894/211161450-6d177638-3bfa-42a8-9c73-0cf3af5e5ca7.jpg)
+
+
+![2f](https://user-images.githubusercontent.com/122148894/211161456-4d2be15b-4a05-4450-a62e-edcaab3772fd.jpg)
+
+
+![4f](https://user-images.githubusercontent.com/122148894/211161461-4507120b-42df-441f-9e01-e4517aa83537.jpg)
+
+## INFO:
+
+~70% of the source code is taken from the [Wifi Marauder](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion) project. Many thanks to the developers of the Wifi Marauder project.

+ 14 - 0
mayhem_morseflash/application.fam

@@ -0,0 +1,14 @@
+App(
+    appid="mayhem_morseflash",
+    name="[MAYHEM] Morse Flash",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="uart_terminal_app",
+    cdefines=["APP_UART_TERMINAL"],
+    requires=["gui"],
+    stack_size=1 * 1024,
+    order=90,
+    fap_icon_assets="assets",
+    fap_icon="icon.png",
+    fap_category="GPIO/MAYHEM",
+    fap_description="ESP32-CAM app to stream a message in morse using the powerful flashlight. [Unplug the USB cable to test with Mayhem]",
+)

BIN
mayhem_morseflash/assets/WarningDolphin_45x42.png


BIN
mayhem_morseflash/icon.png


+ 30 - 0
mayhem_morseflash/scenes/uart_terminal_scene.c

@@ -0,0 +1,30 @@
+#include "uart_terminal_scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const uart_terminal_scene_on_enter_handlers[])(void*) = {
+#include "uart_terminal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const uart_terminal_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "uart_terminal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const uart_terminal_scene_on_exit_handlers[])(void* context) = {
+#include "uart_terminal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers uart_terminal_scene_handlers = {
+    .on_enter_handlers = uart_terminal_scene_on_enter_handlers,
+    .on_event_handlers = uart_terminal_scene_on_event_handlers,
+    .on_exit_handlers = uart_terminal_scene_on_exit_handlers,
+    .scene_num = UART_TerminalSceneNum,
+};

+ 29 - 0
mayhem_morseflash/scenes/uart_terminal_scene.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) UART_TerminalScene##id,
+typedef enum {
+#include "uart_terminal_scene_config.h"
+    UART_TerminalSceneNum,
+} UART_TerminalScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers uart_terminal_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
+#include "uart_terminal_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(prefix, name, id) \
+    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "uart_terminal_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
+#include "uart_terminal_scene_config.h"
+#undef ADD_SCENE

+ 3 - 0
mayhem_morseflash/scenes/uart_terminal_scene_config.h

@@ -0,0 +1,3 @@
+ADD_SCENE(uart_terminal, start, Start)
+ADD_SCENE(uart_terminal, console_output, ConsoleOutput)
+ADD_SCENE(uart_terminal, text_input, TextInput)

+ 97 - 0
mayhem_morseflash/scenes/uart_terminal_scene_console_output.c

@@ -0,0 +1,97 @@
+#include "../uart_terminal_app_i.h"
+
+void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+
+    // If text box store gets too big, then truncate it
+    app->text_box_store_strlen += len;
+    if(app->text_box_store_strlen >= UART_TERMINAL_TEXT_BOX_STORE_SIZE - 1) {
+        furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
+        app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
+    }
+
+    // Null-terminate buf and append to text box store
+    buf[len] = '\0';
+    furi_string_cat_printf(app->text_box_store, "%s", buf);
+
+    view_dispatcher_send_custom_event(
+        app->view_dispatcher, UART_TerminalEventRefreshConsoleOutput);
+}
+
+void uart_terminal_scene_console_output_on_enter(void* context) {
+    UART_TerminalApp* app = context;
+
+    TextBox* text_box = app->text_box;
+    text_box_reset(app->text_box);
+    text_box_set_font(text_box, TextBoxFontText);
+    if(app->focus_console_start) {
+        text_box_set_focus(text_box, TextBoxFocusStart);
+    } else {
+        text_box_set_focus(text_box, TextBoxFocusEnd);
+    }
+
+    if(app->is_command) {
+        furi_string_reset(app->text_box_store);
+        app->text_box_store_strlen = 0;
+
+        // app->show_stopscan_tip in the if is just a hack to get the help displayed since there is no commands in this app
+        if(app->show_stopscan_tip ||
+           0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
+            const char* help_msg =
+                "Morse Flasher for\nMayhem Fin\n\nBased on UART terminal by\ncool4uma, which is a\nmodified WiFi Marauder\ncompanion by 0xchocolate\n\n";
+            furi_string_cat_str(app->text_box_store, help_msg);
+            app->text_box_store_strlen += strlen(help_msg);
+        }
+
+        if(app->show_stopscan_tip) {
+            const char* help_msg = "Press BACK to return\n";
+            furi_string_cat_str(app->text_box_store, help_msg);
+            app->text_box_store_strlen += strlen(help_msg);
+        }
+    }
+
+    // Set starting text - for "View Log", this will just be what was already in the text box store
+    text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
+
+    scene_manager_set_scene_state(app->scene_manager, UART_TerminalSceneConsoleOutput, 0);
+    view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewConsoleOutput);
+
+    // Register callback to receive data
+    uart_terminal_uart_set_handle_rx_data_cb(
+        app->uart, uart_terminal_console_output_handle_rx_data_cb); // setup callback for rx thread
+
+    // Send command with newline '\n'
+    /*if(!app->is_command && app->selected_tx_string)*/ {
+        uart_terminal_uart_tx(
+            app->uart, (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
+        uart_terminal_uart_tx(app->uart, (uint8_t*)("\n"), 1);
+    }
+}
+
+bool uart_terminal_scene_console_output_on_event(void* context, SceneManagerEvent event) {
+    UART_TerminalApp* app = context;
+
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeTick) {
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void uart_terminal_scene_console_output_on_exit(void* context) {
+    UART_TerminalApp* app = context;
+
+    // Unregister rx callback
+    uart_terminal_uart_set_handle_rx_data_cb(app->uart, NULL);
+
+    // Automatically logut when exiting view
+    //if(app->is_command) {
+    //    uart_terminal_uart_tx(app->uart,(uint8_t*)("exit\n"), strlen("exit\n"));
+    //}
+}

+ 145 - 0
mayhem_morseflash/scenes/uart_terminal_scene_start.c

@@ -0,0 +1,145 @@
+#include "../uart_terminal_app_i.h"
+
+// For each command, define whether additional arguments are needed
+// (enabling text input to fill them out), and whether the console
+// text box should focus at the start of the output or the end
+typedef enum {
+    NO_ARGS = 0,
+    INPUT_ARGS,
+    TOGGLE_ARGS
+} InputArgs;
+
+typedef enum {
+    FOCUS_CONSOLE_END = 0,
+    FOCUS_CONSOLE_START,
+    FOCUS_CONSOLE_TOGGLE
+} FocusConsole;
+
+#define SHOW_STOPSCAN_TIP (true)
+#define NO_TIP            (false)
+
+#define MAX_OPTIONS (9)
+typedef struct {
+    const char* item_string;
+    const char* options_menu[MAX_OPTIONS];
+    int num_options_menu;
+    const char* actual_commands[MAX_OPTIONS];
+    InputArgs needs_keyboard;
+    FocusConsole focus_console;
+    bool show_stopscan_tip;
+} UART_TerminalItem;
+
+// NUM_MENU_ITEMS defined in uart_terminal_app_i.h - if you add an entry here, increment it!
+const UART_TerminalItem items[NUM_MENU_ITEMS] = {
+    {"New custom message", {""}, 1, {""}, INPUT_ARGS, FOCUS_CONSOLE_END, NO_TIP},
+    {"Quick message",
+     {"SOS", "CQD", "VVV", "Eureka", "E.T ph...", "what h...", "Mayhem", "Flipper"},
+     8,
+     {"sos",
+      "cqd",
+      "vvv",
+      "eureka",
+      "e.t. phone home",
+      "what hath god wrought!",
+      "let the mayhem begin",
+      "flipper zero in da housa"},
+     NO_ARGS,
+     FOCUS_CONSOLE_END,
+     NO_TIP},
+    {"Help", {""}, 1, {""}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
+};
+
+static void uart_terminal_scene_start_var_list_enter_callback(void* context, uint32_t index) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+
+    furi_assert(index < NUM_MENU_ITEMS);
+    const UART_TerminalItem* item = &items[index];
+
+    const int selected_option_index = app->selected_option_index[index];
+    furi_assert(selected_option_index < item->num_options_menu);
+    app->selected_tx_string = item->actual_commands[selected_option_index];
+    app->is_command = (1 <= index);
+    app->is_custom_tx_string = false;
+    app->selected_menu_index = index;
+    app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE) ?
+                                   (selected_option_index == 0) :
+                                   item->focus_console;
+    app->show_stopscan_tip = item->show_stopscan_tip;
+
+    bool needs_keyboard = (item->needs_keyboard == TOGGLE_ARGS) ? (selected_option_index != 0) :
+                                                                  item->needs_keyboard;
+    if(needs_keyboard) {
+        view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartKeyboard);
+    } else {
+        view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartConsole);
+    }
+}
+
+static void uart_terminal_scene_start_var_list_change_callback(VariableItem* item) {
+    furi_assert(item);
+
+    UART_TerminalApp* app = variable_item_get_context(item);
+    furi_assert(app);
+
+    const UART_TerminalItem* menu_item = &items[app->selected_menu_index];
+    uint8_t item_index = variable_item_get_current_value_index(item);
+    furi_assert(item_index < menu_item->num_options_menu);
+    variable_item_set_current_value_text(item, menu_item->options_menu[item_index]);
+    app->selected_option_index[app->selected_menu_index] = item_index;
+}
+
+void uart_terminal_scene_start_on_enter(void* context) {
+    UART_TerminalApp* app = context;
+    VariableItemList* var_item_list = app->var_item_list;
+
+    variable_item_list_set_enter_callback(
+        var_item_list, uart_terminal_scene_start_var_list_enter_callback, app);
+
+    VariableItem* item;
+    for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
+        item = variable_item_list_add(
+            var_item_list,
+            items[i].item_string,
+            items[i].num_options_menu,
+            uart_terminal_scene_start_var_list_change_callback,
+            app);
+        variable_item_set_current_value_index(item, app->selected_option_index[i]);
+        variable_item_set_current_value_text(
+            item, items[i].options_menu[app->selected_option_index[i]]);
+    }
+
+    variable_item_list_set_selected_item(
+        var_item_list, scene_manager_get_scene_state(app->scene_manager, UART_TerminalSceneStart));
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewVarItemList);
+}
+
+bool uart_terminal_scene_start_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UART_TerminalApp* app = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UART_TerminalEventStartKeyboard) {
+            scene_manager_set_scene_state(
+                app->scene_manager, UART_TerminalSceneStart, app->selected_menu_index);
+            scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewTextInput);
+        } else if(event.event == UART_TerminalEventStartConsole) {
+            scene_manager_set_scene_state(
+                app->scene_manager, UART_TerminalSceneStart, app->selected_menu_index);
+            scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
+        }
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeTick) {
+        app->selected_menu_index = variable_item_list_get_selected_item_index(app->var_item_list);
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void uart_terminal_scene_start_on_exit(void* context) {
+    UART_TerminalApp* app = context;
+    variable_item_list_reset(app->var_item_list);
+}

+ 62 - 0
mayhem_morseflash/scenes/uart_terminal_scene_text_input.c

@@ -0,0 +1,62 @@
+#include "../uart_terminal_app_i.h"
+
+void uart_terminal_scene_text_input_callback(void* context) {
+    UART_TerminalApp* app = context;
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartConsole);
+}
+
+void uart_terminal_scene_text_input_on_enter(void* context) {
+    UART_TerminalApp* app = context;
+
+    if(false == app->is_custom_tx_string) {
+        // Fill text input with selected string so that user can add to it
+        size_t length = strlen(app->selected_tx_string);
+        furi_assert(length < UART_TERMINAL_TEXT_INPUT_STORE_SIZE);
+        bzero(app->text_input_store, UART_TERMINAL_TEXT_INPUT_STORE_SIZE);
+        strncpy(app->text_input_store, app->selected_tx_string, length);
+
+        // Add space - because flipper keyboard currently doesn't have a space
+        //app->text_input_store[length] = ' ';
+        app->text_input_store[length + 1] = '\0';
+        app->is_custom_tx_string = true;
+    }
+
+    // Setup view
+    TextInput* text_input = app->text_input;
+    // Add help message to header
+    text_input_set_header_text(text_input, "Send new morse message");
+    text_input_set_result_callback(
+        text_input,
+        uart_terminal_scene_text_input_callback,
+        app,
+        app->text_input_store,
+        UART_TERMINAL_TEXT_INPUT_STORE_SIZE,
+        false);
+
+    text_input_show_illegal_symbols(text_input, true);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
+}
+
+bool uart_terminal_scene_text_input_on_event(void* context, SceneManagerEvent event) {
+    UART_TerminalApp* app = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UART_TerminalEventStartConsole) {
+            // Point to custom string to send
+            app->selected_tx_string = app->text_input_store;
+            scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
+            consumed = true;
+        }
+    }
+
+    return consumed;
+}
+
+void uart_terminal_scene_text_input_on_exit(void* context) {
+    UART_TerminalApp* app = context;
+
+    text_input_reset(app->text_input);
+}

+ 125 - 0
mayhem_morseflash/uart_terminal_app.c

@@ -0,0 +1,125 @@
+#include "uart_terminal_app_i.h"
+
+#include <furi.h>
+#include <furi_hal.h>
+#include <expansion/expansion.h>
+
+static bool uart_terminal_app_custom_event_callback(void* context, uint32_t event) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+    return scene_manager_handle_custom_event(app->scene_manager, event);
+}
+
+static bool uart_terminal_app_back_event_callback(void* context) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+    return scene_manager_handle_back_event(app->scene_manager);
+}
+
+static void uart_terminal_app_tick_event_callback(void* context) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+    scene_manager_handle_tick_event(app->scene_manager);
+}
+
+UART_TerminalApp* uart_terminal_app_alloc() {
+    UART_TerminalApp* app = malloc(sizeof(UART_TerminalApp));
+
+    app->gui = furi_record_open(RECORD_GUI);
+
+    app->view_dispatcher = view_dispatcher_alloc();
+    app->scene_manager = scene_manager_alloc(&uart_terminal_scene_handlers, app);
+
+    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+
+    view_dispatcher_set_custom_event_callback(
+        app->view_dispatcher, uart_terminal_app_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        app->view_dispatcher, uart_terminal_app_back_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        app->view_dispatcher, uart_terminal_app_tick_event_callback, 100);
+
+    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
+
+    app->var_item_list = variable_item_list_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        UART_TerminalAppViewVarItemList,
+        variable_item_list_get_view(app->var_item_list));
+
+    for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
+        app->selected_option_index[i] = 0;
+    }
+
+    app->text_box = text_box_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher, UART_TerminalAppViewConsoleOutput, text_box_get_view(app->text_box));
+    app->text_box_store = furi_string_alloc();
+    furi_string_reserve(app->text_box_store, UART_TERMINAL_TEXT_BOX_STORE_SIZE);
+
+    app->text_input = text_input_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher, UART_TerminalAppViewTextInput, text_input_get_view(app->text_input));
+
+    scene_manager_next_scene(app->scene_manager, UART_TerminalSceneStart);
+
+    return app;
+}
+
+void uart_terminal_app_free(UART_TerminalApp* app) {
+    furi_assert(app);
+
+    // Views
+    view_dispatcher_remove_view(app->view_dispatcher, UART_TerminalAppViewVarItemList);
+    view_dispatcher_remove_view(app->view_dispatcher, UART_TerminalAppViewConsoleOutput);
+    view_dispatcher_remove_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
+    text_box_free(app->text_box);
+    furi_string_free(app->text_box_store);
+    text_input_free(app->text_input);
+
+    // View dispatcher
+    view_dispatcher_free(app->view_dispatcher);
+    scene_manager_free(app->scene_manager);
+
+    uart_terminal_uart_free(app->uart);
+
+    // Close records
+    furi_record_close(RECORD_GUI);
+
+    free(app);
+}
+
+int32_t uart_terminal_app(void* p) {
+    UNUSED(p);
+
+    // Disable expansion protocol to avoid interference with UART Handle
+    Expansion* expansion = furi_record_open(RECORD_EXPANSION);
+    expansion_disable(expansion);
+
+    furi_hal_power_disable_external_3_3v();
+    furi_hal_power_disable_otg();
+    furi_delay_ms(200);
+    furi_hal_power_enable_external_3_3v();
+    furi_hal_power_enable_otg();
+    UART_TerminalApp* uart_terminal_app = uart_terminal_app_alloc();
+
+    uart_terminal_app->uart = uart_terminal_uart_init(uart_terminal_app);
+
+    for(int i = 0; i < 2; i++) {
+        furi_delay_ms(500);
+        uart_terminal_uart_tx(uart_terminal_app->uart, (uint8_t[1]){'.'}, 1);
+    }
+    furi_delay_ms(1);
+
+    view_dispatcher_run(uart_terminal_app->view_dispatcher);
+
+    uart_terminal_app_free(uart_terminal_app);
+
+    furi_hal_power_disable_otg();
+
+    // Return previous state of expansion
+    expansion_enable(expansion);
+    furi_record_close(RECORD_EXPANSION);
+
+    return 0;
+}

+ 11 - 0
mayhem_morseflash/uart_terminal_app.h

@@ -0,0 +1,11 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct UART_TerminalApp UART_TerminalApp;
+
+#ifdef __cplusplus
+}
+#endif

+ 49 - 0
mayhem_morseflash/uart_terminal_app_i.h

@@ -0,0 +1,49 @@
+#pragma once
+
+#include "uart_terminal_app.h"
+#include "scenes/uart_terminal_scene.h"
+#include "uart_terminal_custom_event.h"
+#include "uart_terminal_uart.h"
+
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/text_box.h>
+#include <gui/modules/text_input.h>
+#include <gui/modules/variable_item_list.h>
+
+#define NUM_MENU_ITEMS (3)
+
+#define UART_TERMINAL_TEXT_BOX_STORE_SIZE   (4096)
+#define UART_TERMINAL_TEXT_INPUT_STORE_SIZE (512)
+#define UART_CH                             (FuriHalSerialIdUsart)
+#define BAUDRATE                            (230400)
+
+struct UART_TerminalApp {
+    Gui* gui;
+    ViewDispatcher* view_dispatcher;
+    SceneManager* scene_manager;
+
+    char text_input_store[UART_TERMINAL_TEXT_INPUT_STORE_SIZE + 1];
+    FuriString* text_box_store;
+    size_t text_box_store_strlen;
+    TextBox* text_box;
+    TextInput* text_input;
+
+    VariableItemList* var_item_list;
+
+    UART_TerminalUart* uart;
+    int selected_menu_index;
+    int selected_option_index[NUM_MENU_ITEMS];
+    const char* selected_tx_string;
+    bool is_command;
+    bool is_custom_tx_string;
+    bool focus_console_start;
+    bool show_stopscan_tip;
+};
+
+typedef enum {
+    UART_TerminalAppViewVarItemList,
+    UART_TerminalAppViewConsoleOutput,
+    UART_TerminalAppViewTextInput,
+} UART_TerminalAppView;

+ 7 - 0
mayhem_morseflash/uart_terminal_custom_event.h

@@ -0,0 +1,7 @@
+#pragma once
+
+typedef enum {
+    UART_TerminalEventRefreshConsoleOutput = 0,
+    UART_TerminalEventStartConsole,
+    UART_TerminalEventStartKeyboard,
+} UART_TerminalCustomEvent;

+ 98 - 0
mayhem_morseflash/uart_terminal_uart.c

@@ -0,0 +1,98 @@
+#include "uart_terminal_app_i.h"
+#include "uart_terminal_uart.h"
+
+struct UART_TerminalUart {
+    UART_TerminalApp* app;
+    FuriThread* rx_thread;
+    FuriStreamBuffer* rx_stream;
+    uint8_t rx_buf[RX_BUF_SIZE + 1];
+    void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context);
+    FuriHalSerialHandle* serial_handle;
+};
+
+typedef enum {
+    WorkerEvtStop = (1 << 0),
+    WorkerEvtRxDone = (1 << 1),
+} WorkerEvtFlags;
+
+void uart_terminal_uart_set_handle_rx_data_cb(
+    UART_TerminalUart* uart,
+    void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context)) {
+    furi_assert(uart);
+    uart->handle_rx_data_cb = handle_rx_data_cb;
+}
+
+#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
+
+void uart_terminal_uart_on_irq_cb(
+    FuriHalSerialHandle* handle,
+    FuriHalSerialRxEvent event,
+    void* context) {
+    UART_TerminalUart* uart = (UART_TerminalUart*)context;
+
+    if(event == FuriHalSerialRxEventData) {
+        uint8_t data = furi_hal_serial_async_rx(handle);
+        furi_stream_buffer_send(uart->rx_stream, &data, 1, 0);
+        furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtRxDone);
+    }
+}
+
+static int32_t uart_worker(void* context) {
+    UART_TerminalUart* uart = (void*)context;
+
+    while(1) {
+        uint32_t events =
+            furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
+        furi_check((events & FuriFlagError) == 0);
+        if(events & WorkerEvtStop) break;
+        if(events & WorkerEvtRxDone) {
+            size_t len = furi_stream_buffer_receive(uart->rx_stream, uart->rx_buf, RX_BUF_SIZE, 0);
+            if(len > 0) {
+                if(uart->handle_rx_data_cb) uart->handle_rx_data_cb(uart->rx_buf, len, uart->app);
+            }
+        }
+    }
+
+    furi_stream_buffer_free(uart->rx_stream);
+
+    return 0;
+}
+
+void uart_terminal_uart_tx(UART_TerminalUart* uart, uint8_t* data, size_t len) {
+    furi_hal_serial_tx(uart->serial_handle, data, len);
+}
+
+UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) {
+    UART_TerminalUart* uart = malloc(sizeof(UART_TerminalUart));
+
+    uart->app = app;
+    uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
+    uart->rx_thread = furi_thread_alloc();
+    furi_thread_set_name(uart->rx_thread, "UART_TerminalUartRxThread");
+    furi_thread_set_stack_size(uart->rx_thread, 1024);
+    furi_thread_set_context(uart->rx_thread, uart);
+    furi_thread_set_callback(uart->rx_thread, uart_worker);
+
+    furi_thread_start(uart->rx_thread);
+
+    uart->serial_handle = furi_hal_serial_control_acquire(UART_CH);
+    furi_check(uart->serial_handle);
+    furi_hal_serial_init(uart->serial_handle, BAUDRATE);
+    furi_hal_serial_async_rx_start(uart->serial_handle, uart_terminal_uart_on_irq_cb, uart, false);
+
+    return uart;
+}
+
+void uart_terminal_uart_free(UART_TerminalUart* uart) {
+    furi_assert(uart);
+
+    furi_hal_serial_async_rx_stop(uart->serial_handle);
+    furi_hal_serial_deinit(uart->serial_handle);
+    furi_hal_serial_control_release(uart->serial_handle);
+
+    furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
+    furi_thread_join(uart->rx_thread);
+    furi_thread_free(uart->rx_thread);
+
+    free(uart);
+}

+ 14 - 0
mayhem_morseflash/uart_terminal_uart.h

@@ -0,0 +1,14 @@
+#pragma once
+
+#include "furi_hal.h"
+
+#define RX_BUF_SIZE (320)
+
+typedef struct UART_TerminalUart UART_TerminalUart;
+
+void uart_terminal_uart_set_handle_rx_data_cb(
+    UART_TerminalUart* uart,
+    void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
+void uart_terminal_uart_tx(UART_TerminalUart* uart, uint8_t* data, size_t len);
+UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app);
+void uart_terminal_uart_free(UART_TerminalUart* uart);

+ 57 - 0
mayhem_morseflash/uart_validators.c

@@ -0,0 +1,57 @@
+#include <furi.h>
+#include "uart_validators.h"
+#include <storage/storage.h>
+
+struct ValidatorIsFile {
+    char* app_path_folder;
+    const char* app_extension;
+    char* current_name;
+};
+
+bool validator_is_file_callback(const char* text, FuriString* error, void* context) {
+    furi_assert(context);
+    ValidatorIsFile* instance = context;
+
+    if(instance->current_name != NULL) {
+        if(strcmp(instance->current_name, text) == 0) {
+            return true;
+        }
+    }
+
+    bool ret = true;
+    FuriString* path = furi_string_alloc_printf(
+        "%s/%s%s", instance->app_path_folder, text, instance->app_extension);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK) {
+        ret = false;
+        furi_string_printf(error, "This name\nexists!\nChoose\nanother one.");
+    } else {
+        ret = true;
+    }
+    furi_string_free(path);
+    furi_record_close(RECORD_STORAGE);
+
+    return ret;
+}
+
+ValidatorIsFile* validator_is_file_alloc_init(
+    const char* app_path_folder,
+    const char* app_extension,
+    const char* current_name) {
+    ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
+
+    instance->app_path_folder = strdup(app_path_folder);
+    instance->app_extension = app_extension;
+    if(current_name != NULL) {
+        instance->current_name = strdup(current_name);
+    }
+
+    return instance;
+}
+
+void validator_is_file_free(ValidatorIsFile* instance) {
+    furi_assert(instance);
+    free(instance->app_path_folder);
+    free(instance->current_name);
+    free(instance);
+}

+ 21 - 0
mayhem_morseflash/uart_validators.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include <core/common_defines.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef struct ValidatorIsFile ValidatorIsFile;
+
+ValidatorIsFile* validator_is_file_alloc_init(
+    const char* app_path_folder,
+    const char* app_extension,
+    const char* current_name);
+
+void validator_is_file_free(ValidatorIsFile* instance);
+
+bool validator_is_file_callback(const char* text, FuriString* error, void* context);
+
+#ifdef __cplusplus
+}
+#endif