esp_flasher_scene_console_output.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "../esp_flasher_app_i.h"
  2. #include "../esp_flasher_worker.h"
  3. void esp_flasher_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
  4. furi_assert(context);
  5. EspFlasherApp* app = context;
  6. // If text box store gets too big, then truncate it
  7. app->text_box_store_strlen += len;
  8. if(app->text_box_store_strlen >= ESP_FLASHER_TEXT_BOX_STORE_SIZE - 1) {
  9. furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
  10. app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
  11. }
  12. // Null-terminate buf and append to text box store
  13. buf[len] = '\0';
  14. furi_string_cat_printf(app->text_box_store, "%s", buf);
  15. view_dispatcher_send_custom_event(app->view_dispatcher, EspFlasherEventRefreshConsoleOutput);
  16. }
  17. void esp_flasher_scene_console_output_on_enter(void* context) {
  18. EspFlasherApp* app = context;
  19. // Reset text box and set font
  20. TextBox* text_box = app->text_box;
  21. text_box_reset(text_box);
  22. text_box_set_font(text_box, TextBoxFontText);
  23. // Set focus on end
  24. text_box_set_focus(text_box, TextBoxFocusEnd);
  25. // Set starting text
  26. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  27. // Set scene state and switch view
  28. scene_manager_set_scene_state(app->scene_manager, EspFlasherSceneConsoleOutput, 0);
  29. view_dispatcher_switch_to_view(app->view_dispatcher, EspFlasherAppViewConsoleOutput);
  30. // Register callbacks to receive data
  31. // setup callback for general log rx thread
  32. esp_flasher_uart_set_handle_rx_data_cb(
  33. app->uart,
  34. esp_flasher_worker_handle_rx_data_cb); // setup callback for general log rx thread
  35. // Start flash worker
  36. esp_flasher_worker_start_thread(app);
  37. }
  38. bool esp_flasher_scene_console_output_on_event(void* context, SceneManagerEvent event) {
  39. EspFlasherApp* app = context;
  40. bool consumed = false;
  41. if(event.type == SceneManagerEventTypeCustom) {
  42. text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
  43. consumed = true;
  44. } else if(event.type == SceneManagerEventTypeTick) {
  45. consumed = true;
  46. } else {
  47. if(app->flash_worker_busy) {
  48. // ignore button presses while flashing
  49. consumed = true;
  50. }
  51. }
  52. return consumed;
  53. }
  54. void esp_flasher_scene_console_output_on_exit(void* context) {
  55. EspFlasherApp* app = context;
  56. esp_flasher_worker_stop_thread(app);
  57. // Unregister rx callback
  58. esp_flasher_uart_set_handle_rx_data_cb(app->uart, NULL);
  59. }