wifi_deauther_scene_console_output.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "../wifi_deauther_app_i.h"
  2. void wifi_deauther_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
  3. furi_assert(context);
  4. WifideautherApp* 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 >= WIFI_deauther_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);
  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(app->view_dispatcher, WifideautherEventRefreshConsoleOutput);
  15. }
  16. void wifi_deauther_scene_console_output_on_enter(void* context) {
  17. WifideautherApp* app = context;
  18. TextBox* text_box = app->text_box;
  19. text_box_reset(app->text_box);
  20. text_box_set_font(text_box, TextBoxFontText);
  21. if(app->focus_console_start) {
  22. text_box_set_focus(text_box, TextBoxFocusStart);
  23. } else {
  24. text_box_set_focus(text_box, TextBoxFocusEnd);
  25. }
  26. if(app->is_command) {
  27. furi_string_reset(app->text_box_store);
  28. app->text_box_store_strlen = 0;
  29. if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
  30. const char* help_msg = "No help here\nonly pain\n";
  31. furi_string_cat_str(app->text_box_store, help_msg);
  32. app->text_box_store_strlen += strlen(help_msg);
  33. }
  34. if(app->show_stopscan_tip) {
  35. const char* help_msg = "Press BACK to send stopscan\n";
  36. furi_string_cat_str(app->text_box_store, help_msg);
  37. app->text_box_store_strlen += strlen(help_msg);
  38. }
  39. }
  40. // "View Log" menu action
  41. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  42. scene_manager_set_scene_state(app->scene_manager, WifideautherSceneConsoleOutput, 0);
  43. view_dispatcher_switch_to_view(app->view_dispatcher, WifideautherAppViewConsoleOutput);
  44. // Register callback to receive data
  45. wifi_deauther_uart_set_handle_rx_data_cb(
  46. app->uart, wifi_deauther_console_output_handle_rx_data_cb); // setup callback for rx thread
  47. // Send command with newline '\n'
  48. if(app->is_command && app->selected_tx_string) {
  49. wifi_deauther_uart_tx(
  50. app->uart, (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
  51. wifi_deauther_uart_tx(app->uart, (uint8_t*)("\n"), 1);
  52. }
  53. }
  54. bool wifi_deauther_scene_console_output_on_event(void* context, SceneManagerEvent event) {
  55. WifideautherApp* app = context;
  56. bool consumed = false;
  57. if(event.type == SceneManagerEventTypeCustom) {
  58. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  59. consumed = true;
  60. } else if(event.type == SceneManagerEventTypeTick) {
  61. consumed = true;
  62. }
  63. return consumed;
  64. }
  65. void wifi_deauther_scene_console_output_on_exit(void* context) {
  66. WifideautherApp* app = context;
  67. // Unregister rx callback
  68. wifi_deauther_uart_set_handle_rx_data_cb(app->uart, NULL);
  69. // Automatically stop the scan when exiting view
  70. if(app->is_command) {
  71. wifi_deauther_uart_tx(app->uart, (uint8_t*)("stopscan\n"), strlen("stopscan\n"));
  72. }
  73. }