blackhat_scene_console_output.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. text_box_set_focus(text_box, TextBoxFocusEnd);
  27. furi_string_reset(app->text_box_store);
  28. app->text_box_store_strlen = 0;
  29. if (app->text_input_req) {
  30. scene_manager_next_scene(app->scene_manager, BlackhatSceneRename);
  31. return;
  32. }
  33. snprintf(
  34. app->text_store,
  35. sizeof(app->text_store),
  36. "%s %s\n",
  37. app->selected_tx_string,
  38. app->selected_option_item_text
  39. );
  40. FURI_LOG_I("tag/app name", "%s", app->text_store);
  41. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  42. scene_manager_set_scene_state(
  43. app->scene_manager, BlackhatSceneConsoleOutput, 0
  44. );
  45. view_dispatcher_switch_to_view(
  46. app->view_dispatcher, BlackhatAppViewConsoleOutput
  47. );
  48. // Register callback to receive data
  49. blackhat_uart_set_handle_rx_data_cb(
  50. app->uart, blackhat_console_output_handle_rx_data_cb
  51. );
  52. blackhat_uart_tx(app->uart, app->text_store, strlen(app->text_store));
  53. }
  54. bool blackhat_scene_console_output_on_event(
  55. void* context, SceneManagerEvent event
  56. )
  57. {
  58. UNUSED(context);
  59. bool consumed = false;
  60. if (event.type == SceneManagerEventTypeTick) {
  61. consumed = true;
  62. }
  63. return consumed;
  64. }
  65. void blackhat_scene_console_output_on_exit(void* context)
  66. {
  67. BlackhatApp* app = context;
  68. // Unregister rx callback
  69. blackhat_uart_set_handle_rx_data_cb(app->uart, NULL);
  70. }