nfc_maker.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "nfc_maker.h"
  2. static bool nfc_maker_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. NfcMaker* app = context;
  5. return scene_manager_handle_custom_event(app->scene_manager, event);
  6. }
  7. static bool nfc_maker_back_event_callback(void* context) {
  8. furi_assert(context);
  9. NfcMaker* app = context;
  10. return scene_manager_handle_back_event(app->scene_manager);
  11. }
  12. NfcMaker* nfc_maker_alloc() {
  13. NfcMaker* app = malloc(sizeof(NfcMaker));
  14. app->gui = furi_record_open(RECORD_GUI);
  15. // View Dispatcher and Scene Manager
  16. app->view_dispatcher = view_dispatcher_alloc();
  17. app->scene_manager = scene_manager_alloc(&nfc_maker_scene_handlers, app);
  18. view_dispatcher_enable_queue(app->view_dispatcher);
  19. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  20. view_dispatcher_set_custom_event_callback(
  21. app->view_dispatcher, nfc_maker_custom_event_callback);
  22. view_dispatcher_set_navigation_event_callback(
  23. app->view_dispatcher, nfc_maker_back_event_callback);
  24. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  25. // Gui Modules
  26. app->submenu = submenu_alloc();
  27. view_dispatcher_add_view(
  28. app->view_dispatcher, NfcMakerViewSubmenu, submenu_get_view(app->submenu));
  29. app->text_input = text_input_alloc();
  30. view_dispatcher_add_view(
  31. app->view_dispatcher, NfcMakerViewTextInput, text_input_get_view(app->text_input));
  32. app->byte_input = byte_input_alloc();
  33. view_dispatcher_add_view(
  34. app->view_dispatcher, NfcMakerViewByteInput, byte_input_get_view(app->byte_input));
  35. app->popup = popup_alloc();
  36. view_dispatcher_add_view(app->view_dispatcher, NfcMakerViewPopup, popup_get_view(app->popup));
  37. return app;
  38. }
  39. void nfc_maker_free(NfcMaker* app) {
  40. furi_assert(app);
  41. // Gui modules
  42. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewSubmenu);
  43. submenu_free(app->submenu);
  44. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewTextInput);
  45. text_input_free(app->text_input);
  46. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewByteInput);
  47. byte_input_free(app->byte_input);
  48. view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewPopup);
  49. popup_free(app->popup);
  50. // View Dispatcher and Scene Manager
  51. view_dispatcher_free(app->view_dispatcher);
  52. scene_manager_free(app->scene_manager);
  53. // Records
  54. furi_record_close(RECORD_GUI);
  55. free(app);
  56. }
  57. extern int32_t nfc_maker(void* p) {
  58. UNUSED(p);
  59. NfcMaker* app = nfc_maker_alloc();
  60. scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneStart, NfcMakerSceneHttps);
  61. scene_manager_next_scene(app->scene_manager, NfcMakerSceneStart);
  62. view_dispatcher_run(app->view_dispatcher);
  63. nfc_maker_free(app);
  64. return 0;
  65. }