subghz_scene_save_name.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "../subghz_i.h"
  2. #include <lib/toolbox/random_name.h>
  3. #include "file-worker.h"
  4. #define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL)
  5. void subghz_scene_save_name_text_input_callback(void* context) {
  6. SubGhz* subghz = context;
  7. view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
  8. }
  9. const void subghz_scene_save_name_on_enter(void* context) {
  10. SubGhz* subghz = context;
  11. // Setup view
  12. TextInput* text_input = subghz->text_input;
  13. bool dev_name_empty = false;
  14. set_random_name(subghz->text_store, sizeof(subghz->text_store));
  15. dev_name_empty = true;
  16. text_input_set_header_text(text_input, "Name the KEY");
  17. text_input_set_result_callback(
  18. text_input,
  19. subghz_scene_save_name_text_input_callback,
  20. subghz,
  21. subghz->text_store,
  22. 22, //Max len name
  23. dev_name_empty);
  24. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTextInput);
  25. }
  26. const bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
  27. SubGhz* subghz = context;
  28. if(event.type == SceneManagerEventTypeCustom) {
  29. if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
  30. if(subghz_save_protocol_to_file(subghz, subghz->text_store)) {
  31. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess);
  32. return true;
  33. } else {
  34. //Error save
  35. return true;
  36. }
  37. }
  38. }
  39. return false;
  40. }
  41. const void subghz_scene_save_name_on_exit(void* context) {
  42. SubGhz* subghz = context;
  43. // Clear view
  44. text_input_set_header_text(subghz->text_input, NULL);
  45. text_input_set_result_callback(subghz->text_input, NULL, NULL, NULL, 0, false);
  46. }