Skip to content

Commit

Permalink
add of the ability to change baudrate
Browse files Browse the repository at this point in the history
  • Loading branch information
cool4uma committed Jan 9, 2023
1 parent 6519b50 commit e5fa5ff
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
54 changes: 52 additions & 2 deletions scenes/uart_terminal_scene_console_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,59 @@ void uart_terminal_scene_console_output_on_enter(void* context) {
} else {
text_box_set_focus(text_box, TextBoxFocusEnd);
}

//Change baudrate ///////////////////////////////////////////////////////////////////////////
if(0 == strncmp("2400", app->selected_tx_string, strlen("2400")) && app->BAUDRATE != 2400) {
uart_terminal_uart_free(app->uart);
app->BAUDRATE = 2400;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("9600", app->selected_tx_string, strlen("9600")) && app->BAUDRATE != 9600) {
uart_terminal_uart_free(app->uart);
app->BAUDRATE = 9600;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("19200", app->selected_tx_string, strlen("19200")) && app->BAUDRATE != 19200) {
uart_terminal_uart_free(app->uart);
;
app->BAUDRATE = 19200;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("38400", app->selected_tx_string, strlen("38400")) && app->BAUDRATE != 38400) {
uart_terminal_uart_free(app->uart);
;
app->BAUDRATE = 38400;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("57600", app->selected_tx_string, strlen("57600")) && app->BAUDRATE != 57600) {
uart_terminal_uart_free(app->uart);
app->BAUDRATE = 57600;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("230400", app->selected_tx_string, strlen("230400")) &&
app->BAUDRATE != 230400) {
uart_terminal_uart_free(app->uart);
app->BAUDRATE = 230400;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("460800", app->selected_tx_string, strlen("460800")) &&
app->BAUDRATE != 460800) {
uart_terminal_uart_free(app->uart);
app->BAUDRATE = 460800;
app->uart = uart_terminal_uart_init(app);
}
if(0 == strncmp("921600", app->selected_tx_string, strlen("921600")) &&
app->BAUDRATE != 921600) {
uart_terminal_uart_free(app->uart);
app->BAUDRATE = 921600;
app->uart = uart_terminal_uart_init(app);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////

if(app->is_command) {
furi_string_reset(app->text_box_store);
app->text_box_store_strlen = 0;

if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
const char* help_msg =
"UART terminal for Flipper\n\nI'm in github: cool4uma\n\nThis app is a modified\nWiFi Marauder companion,\nThanks 0xchocolate(github)\nfor great code and app.\n\n";
Expand Down Expand Up @@ -88,6 +138,6 @@ void uart_terminal_scene_console_output_on_exit(void* context) {

// Automatically logut when exiting view
//if(app->is_command) {
// uart_terminal_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n"));
// uart_terminal_uart_tx((uint8_t*)("exit\n"), strlen("exit\n"));
//}
}
}
2 changes: 1 addition & 1 deletion scenes/uart_terminal_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const UART_TerminalItem items[NUM_MENU_ITEMS] = {
{"Console",
{"115200", "2400", "9600", "19200", "38400", "57600", "230400", "460800", "921600"},
9,
{"", ""},
{"115200", "2400", "9600", "19200", "38400", "57600", "230400", "460800", "921600"},
NO_ARGS,
FOCUS_CONSOLE_TOGGLE,
NO_TIP},
Expand Down
3 changes: 2 additions & 1 deletion uart_terminal_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#define UART_TERMINAL_TEXT_BOX_STORE_SIZE (4096)
#define UART_TERMINAL_TEXT_INPUT_STORE_SIZE (512)
#define UART_CH (FuriHalUartIdUSART1)

struct UART_TerminalApp {
Gui* gui;
Expand All @@ -27,7 +28,6 @@ struct UART_TerminalApp {
size_t text_box_store_strlen;
TextBox* text_box;
UART_TextInput* text_input;
//Widget* widget;

VariableItemList* var_item_list;

Expand All @@ -39,6 +39,7 @@ struct UART_TerminalApp {
bool is_custom_tx_string;
bool focus_console_start;
bool show_stopscan_tip;
int BAUDRATE;
};

typedef enum {
Expand Down
9 changes: 6 additions & 3 deletions uart_terminal_uart.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "uart_terminal_app_i.h"
#include "uart_terminal_uart.h"

#define UART_CH (FuriHalUartIdUSART1)
#define BAUDRATE (115200)
//#define UART_CH (FuriHalUartIdUSART1)
//#define BAUDRATE (115200)

struct UART_TerminalUart {
UART_TerminalApp* app;
Expand Down Expand Up @@ -66,7 +66,10 @@ UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) {
UART_TerminalUart* uart = malloc(sizeof(UART_TerminalUart));

furi_hal_console_disable();
furi_hal_uart_set_br(UART_CH, BAUDRATE);
if(app->BAUDRATE == 0) {
app->BAUDRATE = 115200;
}
furi_hal_uart_set_br(UART_CH, app->BAUDRATE);
furi_hal_uart_set_irq_cb(UART_CH, uart_terminal_uart_on_irq_cb, uart);

uart->app = app;
Expand Down

0 comments on commit e5fa5ff

Please sign in to comment.