blackhat_scene_console_output.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "../blackhat_app_i.h"
  2. void blackhat_console_output_handle_rx_data_cb(
  3. uint8_t* buf, size_t len, void* context
  4. )
  5. {
  6. furi_assert(context);
  7. BlackhatApp* app = context;
  8. // If text box store gets too big, then truncate it
  9. app->text_box_store_strlen += len;
  10. if (app->text_box_store_strlen >= BLACKHAT_TEXT_BOX_STORE_SIZE - 1) {
  11. furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
  12. app->text_box_store_strlen =
  13. furi_string_size(app->text_box_store) + len;
  14. }
  15. // Null-terminate buf and append to text box store
  16. buf[len] = '\0';
  17. furi_string_cat_printf(app->text_box_store, "%s", buf);
  18. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  19. }
  20. void blackhat_scene_console_output_on_enter(void* context)
  21. {
  22. BlackhatApp* app = context;
  23. TextBox* text_box = app->text_box;
  24. text_box_reset(app->text_box);
  25. text_box_set_font(text_box, TextBoxFontText);
  26. if (app->focus_console_start) {
  27. text_box_set_focus(text_box, TextBoxFocusStart);
  28. } else {
  29. text_box_set_focus(text_box, TextBoxFocusEnd);
  30. }
  31. furi_string_reset(app->text_box_store);
  32. app->text_box_store_strlen = 0;
  33. if (!strncmp(
  34. SET_INET_SSID_CMD,
  35. app->selected_tx_string,
  36. strlen(SET_INET_SSID_CMD)
  37. )) {
  38. scene_manager_next_scene(app->scene_manager, BlackhatSceneRename);
  39. return;
  40. }
  41. snprintf(
  42. app->text_store,
  43. sizeof(app->text_store),
  44. "%s %s\n",
  45. app->selected_tx_string,
  46. app->selected_option_item_text
  47. );
  48. FURI_LOG_I("tag/app name", "%s", app->text_store);
  49. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  50. scene_manager_set_scene_state(
  51. app->scene_manager, BlackhatSceneConsoleOutput, 0
  52. );
  53. view_dispatcher_switch_to_view(
  54. app->view_dispatcher, BlackhatAppViewConsoleOutput
  55. );
  56. // Register callback to receive data
  57. blackhat_uart_set_handle_rx_data_cb(
  58. app->uart, blackhat_console_output_handle_rx_data_cb
  59. );
  60. blackhat_uart_tx(app->uart, app->text_store, strlen(app->text_store));
  61. }
  62. bool blackhat_scene_console_output_on_event(
  63. void* context, SceneManagerEvent event
  64. )
  65. {
  66. UNUSED(context);
  67. bool consumed = false;
  68. if (event.type == SceneManagerEventTypeTick) {
  69. consumed = true;
  70. }
  71. return consumed;
  72. }
  73. void blackhat_scene_console_output_on_exit(void* context)
  74. {
  75. BlackhatApp* app = context;
  76. // Unregister rx callback
  77. blackhat_uart_set_handle_rx_data_cb(app->uart, NULL);
  78. }