avr_isp_scene_input_name.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "../avr_isp_app_i.h"
  2. #include <gui/modules/validators.h>
  3. #define MAX_TEXT_INPUT_LEN 22
  4. void avr_isp_scene_input_name_text_callback(void* context) {
  5. furi_assert(context);
  6. AvrIspApp* app = context;
  7. view_dispatcher_send_custom_event(app->view_dispatcher, AvrIspCustomEventSceneInputName);
  8. }
  9. void avr_isp_scene_input_name_get_timefilename(FuriString* name) {
  10. FuriHalRtcDateTime datetime = {0};
  11. furi_hal_rtc_get_datetime(&datetime);
  12. furi_string_printf(
  13. name,
  14. "AVR_dump-%.4d%.2d%.2d-%.2d%.2d%.2d",
  15. datetime.year,
  16. datetime.month,
  17. datetime.day,
  18. datetime.hour,
  19. datetime.minute,
  20. datetime.second);
  21. }
  22. void avr_isp_scene_input_name_on_enter(void* context) {
  23. furi_assert(context);
  24. AvrIspApp* app = context;
  25. // Setup view
  26. TextInput* text_input = app->text_input;
  27. bool dev_name_empty = false;
  28. FuriString* file_name = furi_string_alloc();
  29. avr_isp_scene_input_name_get_timefilename(file_name);
  30. furi_string_set(app->file_path, STORAGE_APP_DATA_PATH_PREFIX);
  31. //highlighting the entire filename by default
  32. dev_name_empty = true;
  33. strncpy(app->file_name_tmp, furi_string_get_cstr(file_name), AVR_ISP_MAX_LEN_NAME);
  34. text_input_set_header_text(text_input, "Name dump");
  35. text_input_set_result_callback(
  36. text_input,
  37. avr_isp_scene_input_name_text_callback,
  38. app,
  39. app->file_name_tmp,
  40. MAX_TEXT_INPUT_LEN, // buffer size
  41. dev_name_empty);
  42. ValidatorIsFile* validator_is_file =
  43. validator_is_file_alloc_init(STORAGE_APP_DATA_PATH_PREFIX, AVR_ISP_APP_EXTENSION, "");
  44. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  45. furi_string_free(file_name);
  46. view_dispatcher_switch_to_view(app->view_dispatcher, AvrIspViewTextInput);
  47. }
  48. bool avr_isp_scene_input_name_on_event(void* context, SceneManagerEvent event) {
  49. furi_assert(context);
  50. AvrIspApp* app = context;
  51. if(event.type == SceneManagerEventTypeBack) {
  52. scene_manager_previous_scene(app->scene_manager);
  53. return true;
  54. } else if(event.type == SceneManagerEventTypeCustom) {
  55. if(event.event == AvrIspCustomEventSceneInputName) {
  56. if(strcmp(app->file_name_tmp, "") != 0) {
  57. scene_manager_next_scene(app->scene_manager, AvrIspSceneReader);
  58. } else {
  59. }
  60. }
  61. }
  62. return false;
  63. }
  64. void avr_isp_scene_input_name_on_exit(void* context) {
  65. furi_assert(context);
  66. AvrIspApp* app = context;
  67. // Clear validator
  68. void* validator_context = text_input_get_validator_callback_context(app->text_input);
  69. text_input_set_validator(app->text_input, NULL, NULL);
  70. validator_is_file_free(validator_context);
  71. // Clear view
  72. text_input_reset(app->text_input);
  73. }