blackhat_scene_console_output.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // We gotta parse the output
  16. if (app->is_script_scan) {
  17. memcpy(&app->script_text[app->script_text_ptr], buf, len);
  18. app->script_text_ptr += len;
  19. }
  20. // Null-terminate buf and append to text box store
  21. buf[len] = '\0';
  22. furi_string_cat_printf(app->text_box_store, "%s", buf);
  23. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  24. }
  25. void blackhat_scene_console_output_on_enter(void* context)
  26. {
  27. BlackhatApp* app = context;
  28. TextBox* text_box = app->text_box;
  29. text_box_reset(app->text_box);
  30. text_box_set_font(text_box, TextBoxFontText);
  31. text_box_set_focus(text_box, TextBoxFocusEnd);
  32. furi_string_reset(app->text_box_store);
  33. app->text_box_store_strlen = 0;
  34. if (app->text_input_req) {
  35. scene_manager_next_scene(app->scene_manager, BlackhatSceneRename);
  36. return;
  37. }
  38. app->is_script_scan = false;
  39. if (!strcmp(app->selected_tx_string, SCAN_CMD)) {
  40. app->is_script_scan = true;
  41. app->script_text_ptr = 0;
  42. app->scanned = true;
  43. }
  44. if (!strcmp(app->selected_tx_string, RUN_CMD)) {
  45. if (app->scanned) {
  46. app->script_text_ptr++;
  47. app->script_text[app->script_text_ptr] = 0x00;
  48. scene_manager_next_scene(app->scene_manager, BlackhatSceneScripts);
  49. }
  50. return;
  51. }
  52. FURI_LOG_I("selected_tx_string", "%s", app->selected_tx_string);
  53. snprintf(
  54. app->text_store,
  55. sizeof(app->text_store),
  56. "%s %s\n",
  57. app->selected_tx_string,
  58. app->selected_option_item_text
  59. );
  60. FURI_LOG_I("tag/app name", "%s", app->text_store);
  61. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  62. scene_manager_set_scene_state(
  63. app->scene_manager, BlackhatSceneConsoleOutput, 0
  64. );
  65. view_dispatcher_switch_to_view(
  66. app->view_dispatcher, BlackhatAppViewConsoleOutput
  67. );
  68. // Register callback to receive data
  69. blackhat_uart_set_handle_rx_data_cb(
  70. app->uart, blackhat_console_output_handle_rx_data_cb
  71. );
  72. blackhat_uart_tx(app->uart, app->text_store, strlen(app->text_store));
  73. }
  74. bool blackhat_scene_console_output_on_event(
  75. void* context, SceneManagerEvent event
  76. )
  77. {
  78. UNUSED(context);
  79. bool consumed = false;
  80. if (event.type == SceneManagerEventTypeTick) {
  81. consumed = true;
  82. }
  83. return consumed;
  84. }
  85. void blackhat_scene_console_output_on_exit(void* context)
  86. {
  87. BlackhatApp* app = context;
  88. // Unregister rx callback
  89. blackhat_uart_set_handle_rx_data_cb(app->uart, NULL);
  90. }