uart_terminal_scene_console_output.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "../uart_terminal_app_i.h"
  2. void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
  3. furi_assert(context);
  4. UART_TerminalApp* app = context;
  5. // If text box store gets too big, then truncate it
  6. app->text_box_store_strlen += len;
  7. if(app->text_box_store_strlen >= UART_TERMINAL_TEXT_BOX_STORE_SIZE - 1) {
  8. furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
  9. app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
  10. }
  11. // Null-terminate buf and append to text box store
  12. buf[len] = '\0';
  13. furi_string_cat_printf(app->text_box_store, "%s", buf);
  14. view_dispatcher_send_custom_event(
  15. app->view_dispatcher, UART_TerminalEventRefreshConsoleOutput);
  16. }
  17. void uart_terminal_scene_console_output_on_enter(void* context) {
  18. UART_TerminalApp* app = context;
  19. TextBox* text_box = app->text_box;
  20. text_box_reset(app->text_box);
  21. text_box_set_font(text_box, TextBoxFontText);
  22. if(app->focus_console_start) {
  23. text_box_set_focus(text_box, TextBoxFocusStart);
  24. } else {
  25. text_box_set_focus(text_box, TextBoxFocusEnd);
  26. }
  27. if(app->is_command) {
  28. furi_string_reset(app->text_box_store);
  29. app->text_box_store_strlen = 0;
  30. // app->show_stopscan_tip in the if is just a hack to get the help displayed since there is no commands in this app
  31. if(app->show_stopscan_tip || 0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
  32. const char* help_msg =
  33. "Morse Flasher for\nMayhem Fin\n\nBased on UART terminal by\ncool4uma, which is a\nmodified WiFi Marauder\ncompanion by 0xchocolate\n\n";
  34. furi_string_cat_str(app->text_box_store, help_msg);
  35. app->text_box_store_strlen += strlen(help_msg);
  36. }
  37. if(app->show_stopscan_tip) {
  38. const char* help_msg = "Press BACK to return\n";
  39. furi_string_cat_str(app->text_box_store, help_msg);
  40. app->text_box_store_strlen += strlen(help_msg);
  41. }
  42. }
  43. // Set starting text - for "View Log", this will just be what was already in the text box store
  44. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  45. scene_manager_set_scene_state(app->scene_manager, UART_TerminalSceneConsoleOutput, 0);
  46. view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewConsoleOutput);
  47. // Register callback to receive data
  48. uart_terminal_uart_set_handle_rx_data_cb(
  49. app->uart, uart_terminal_console_output_handle_rx_data_cb); // setup callback for rx thread
  50. // Send command with newline '\n'
  51. /*if(!app->is_command && app->selected_tx_string)*/ {
  52. uart_terminal_uart_tx(
  53. (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
  54. uart_terminal_uart_tx((uint8_t*)("\n"), 1);
  55. }
  56. }
  57. bool uart_terminal_scene_console_output_on_event(void* context, SceneManagerEvent event) {
  58. UART_TerminalApp* app = context;
  59. bool consumed = false;
  60. if(event.type == SceneManagerEventTypeCustom) {
  61. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  62. consumed = true;
  63. } else if(event.type == SceneManagerEventTypeTick) {
  64. consumed = true;
  65. }
  66. return consumed;
  67. }
  68. void uart_terminal_scene_console_output_on_exit(void* context) {
  69. UART_TerminalApp* app = context;
  70. // Unregister rx callback
  71. uart_terminal_uart_set_handle_rx_data_cb(app->uart, NULL);
  72. // Automatically logut when exiting view
  73. //if(app->is_command) {
  74. // uart_terminal_uart_tx((uint8_t*)("exit\n"), strlen("exit\n"));
  75. //}
  76. }