|
|
@@ -6,19 +6,19 @@ void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo
|
|
|
FuriString* new_str = furi_string_alloc();
|
|
|
|
|
|
if(app->hex_mode) {
|
|
|
- while (len--) {
|
|
|
+ while(len--) {
|
|
|
uint8_t byte = *(buf++);
|
|
|
if(byte == '\0') break;
|
|
|
furi_string_cat_printf(new_str, "%02X ", byte);
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
buf[len] = '\0';
|
|
|
furi_string_cat_printf(new_str, "%s", buf);
|
|
|
}
|
|
|
|
|
|
// If text box store gets too big, then truncate it
|
|
|
- app->text_box_store_strlen += furi_string_size(new_str);;
|
|
|
+ app->text_box_store_strlen += furi_string_size(new_str);
|
|
|
+ ;
|
|
|
while(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;
|
|
|
@@ -33,13 +33,13 @@ void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo
|
|
|
|
|
|
static uint8_t hex_char_to_byte(const char c) {
|
|
|
if(c >= '0' && c <= '9') {
|
|
|
- return c-'0';
|
|
|
+ return c - '0';
|
|
|
}
|
|
|
if(c >= 'A' && c <= 'F') {
|
|
|
- return c-'A'+10;
|
|
|
+ return c - 'A' + 10;
|
|
|
}
|
|
|
- if (c >= 'a' && c <= 'f') {
|
|
|
- return c-'a'+10;
|
|
|
+ if(c >= 'a' && c <= 'f') {
|
|
|
+ return c - 'a' + 10;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -86,19 +86,17 @@ void uart_terminal_scene_console_output_on_enter(void* context) {
|
|
|
uart_terminal_uart_set_handle_rx_data_cb(
|
|
|
app->uart, uart_terminal_console_output_handle_rx_data_cb); // setup callback for rx thread
|
|
|
|
|
|
- uint8_t uart_ch = app->uart_ch;
|
|
|
-
|
|
|
if(app->hex_mode) {
|
|
|
// Send binary packet
|
|
|
if(app->selected_tx_string) {
|
|
|
- const char *str = app->selected_tx_string;
|
|
|
+ const char* str = app->selected_tx_string;
|
|
|
uint8_t digit_num = 0;
|
|
|
uint8_t byte = 0;
|
|
|
- while (*str) {
|
|
|
+ while(*str) {
|
|
|
byte |= (hex_char_to_byte(*str) << ((1 - digit_num) * 4));
|
|
|
|
|
|
if(++digit_num == 2) {
|
|
|
- uart_terminal_uart_tx(uart_ch, &byte, 1);
|
|
|
+ uart_terminal_uart_tx(app->uart, &byte, 1);
|
|
|
digit_num = 0;
|
|
|
byte = 0;
|
|
|
}
|
|
|
@@ -106,20 +104,24 @@ void uart_terminal_scene_console_output_on_enter(void* context) {
|
|
|
}
|
|
|
|
|
|
if(digit_num) {
|
|
|
- uart_terminal_uart_tx(uart_ch, &byte, 1);
|
|
|
+ uart_terminal_uart_tx(app->uart, &byte, 1);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
// Send command with CR+LF or newline '\n'
|
|
|
if(app->is_command && app->selected_tx_string) {
|
|
|
- if(app->TERMINAL_MODE == 1){
|
|
|
- uart_terminal_uart_tx(uart_ch,
|
|
|
- (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
|
|
- uart_terminal_uart_tx(uart_ch, (uint8_t*)("\r\n"), 2);
|
|
|
+ if(app->TERMINAL_MODE == 1) {
|
|
|
+ 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*)("\r\n"), 2);
|
|
|
} else {
|
|
|
- uart_terminal_uart_tx(uart_ch,
|
|
|
- (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
|
|
- uart_terminal_uart_tx(uart_ch, (uint8_t*)("\n"), 1);
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
}
|