nfc_scene_save_name.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <nfc/scenes/nfc_scene_save_name.h>
  2. #include <furi.h>
  3. #include "../nfc_i.h"
  4. #include "../views/nfc_detect.h"
  5. #include <gui/view_dispatcher.h>
  6. #define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL)
  7. void nfc_scene_save_name_text_input_callback(void* context) {
  8. Nfc* nfc = (Nfc*)context;
  9. view_dispatcher_send_custom_event(
  10. nfc->nfc_common.view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
  11. }
  12. const void nfc_scene_save_name_on_enter(void* context) {
  13. Nfc* nfc = (Nfc*)context;
  14. // Setup view
  15. TextInput* text_input = nfc->text_input;
  16. nfc_set_text_store(nfc, "");
  17. text_input_set_header_text(text_input, "Name the card");
  18. text_input_set_result_callback(
  19. text_input,
  20. nfc_scene_save_name_text_input_callback,
  21. nfc,
  22. nfc->text_store,
  23. sizeof(nfc->text_store));
  24. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewTextInput);
  25. }
  26. const bool nfc_scene_save_name_on_event(void* context, uint32_t event) {
  27. Nfc* nfc = (Nfc*)context;
  28. if(event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
  29. memcpy(&nfc->device.dev_name, nfc->text_store, strlen(nfc->text_store));
  30. if(nfc_device_save(&nfc->device, "test")) {
  31. view_dispatcher_add_scene(nfc->nfc_common.view_dispatcher, nfc->scene_save_success);
  32. view_dispatcher_send_navigation_event(
  33. nfc->nfc_common.view_dispatcher, ViewNavigatorEventNext);
  34. } else {
  35. view_dispatcher_send_back_search_scene_event(
  36. nfc->nfc_common.view_dispatcher, NfcSceneStart);
  37. }
  38. return true;
  39. }
  40. return false;
  41. }
  42. const void nfc_scene_save_name_on_exit(void* context) {
  43. Nfc* nfc = (Nfc*)context;
  44. // Clear view
  45. text_input_set_header_text(nfc->text_input, NULL);
  46. }
  47. AppScene* nfc_scene_save_name_alloc() {
  48. AppScene* scene = furi_alloc(sizeof(AppScene));
  49. scene->id = NfcSceneSaveName;
  50. scene->on_enter = nfc_scene_save_name_on_enter;
  51. scene->on_event = nfc_scene_save_name_on_event;
  52. scene->on_exit = nfc_scene_save_name_on_exit;
  53. return scene;
  54. }
  55. void nfc_scene_save_name_free(AppScene* scene) {
  56. free(scene);
  57. }