wiegand.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "wiegand.h"
  2. const GpioPin* const pinD0 = &gpio_ext_pa4;
  3. const GpioPin* const pinD1 = &gpio_ext_pa7;
  4. volatile int bit_count = 0;
  5. volatile bool data[MAX_BITS];
  6. volatile uint32_t data_fall[MAX_BITS];
  7. volatile uint32_t data_rise[MAX_BITS];
  8. bool data_saved = false;
  9. bool wiegand_empty_scene_on_event(void* _ctx, SceneManagerEvent _evt) {
  10. UNUSED(_ctx);
  11. UNUSED(_evt);
  12. return false;
  13. }
  14. void wiegand_empty_scene_on_exit(void* _ctx) {
  15. UNUSED(_ctx);
  16. }
  17. void (*const basic_scenes_scene_on_enter_handlers[])(void*) = {
  18. wiegand_main_menu_scene_on_enter,
  19. wiegand_instructions_scene_on_enter,
  20. wiegand_read_scene_on_enter,
  21. wiegand_data_scene_on_enter,
  22. wiegand_save_scene_on_enter,
  23. wiegand_load_scene_on_enter,
  24. };
  25. bool (*const basic_scenes_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
  26. wiegand_main_menu_scene_on_event,
  27. wiegand_empty_scene_on_event, // instructions
  28. wiegand_empty_scene_on_event, // read
  29. wiegand_data_scene_on_event,
  30. wiegand_save_scene_on_event,
  31. wiegand_empty_scene_on_event, // load
  32. };
  33. void (*const basic_scenes_scene_on_exit_handlers[])(void*) = {
  34. wiegand_empty_scene_on_exit, // main_menu
  35. wiegand_empty_scene_on_exit, // instructions
  36. wiegand_read_scene_on_exit,
  37. wiegand_empty_scene_on_exit, // data
  38. wiegand_empty_scene_on_exit, // save
  39. wiegand_empty_scene_on_exit, // load
  40. };
  41. const SceneManagerHandlers basic_scenes_scene_manager_handlers = {
  42. .on_enter_handlers = basic_scenes_scene_on_enter_handlers,
  43. .on_event_handlers = basic_scenes_scene_on_event_handlers,
  44. .on_exit_handlers = basic_scenes_scene_on_exit_handlers,
  45. .scene_num = WiegandSceneCount,
  46. };
  47. bool wiegand_custom_callback(void* context, uint32_t custom_event) {
  48. furi_assert(context);
  49. App* app = context;
  50. return scene_manager_handle_custom_event(app->scene_manager, custom_event);
  51. }
  52. bool wiegand_back_event_callback(void* context) {
  53. furi_assert(context);
  54. App* app = context;
  55. return scene_manager_handle_back_event(app->scene_manager);
  56. }
  57. App* app_alloc() {
  58. App* app = malloc(sizeof(App));
  59. app->scene_manager = scene_manager_alloc(&basic_scenes_scene_manager_handlers, app);
  60. app->view_dispatcher = view_dispatcher_alloc();
  61. view_dispatcher_enable_queue(app->view_dispatcher);
  62. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  63. view_dispatcher_set_custom_event_callback(app->view_dispatcher, wiegand_custom_callback);
  64. view_dispatcher_set_navigation_event_callback(
  65. app->view_dispatcher, wiegand_back_event_callback);
  66. app->submenu = submenu_alloc();
  67. view_dispatcher_add_view(
  68. app->view_dispatcher, WiegandSubmenuView, submenu_get_view(app->submenu));
  69. app->widget = widget_alloc();
  70. view_dispatcher_add_view(
  71. app->view_dispatcher, WiegandWidgetView, widget_get_view(app->widget));
  72. app->text_input = text_input_alloc();
  73. view_dispatcher_add_view(
  74. app->view_dispatcher, WiegandTextInputView, text_input_get_view(app->text_input));
  75. app->dialogs = furi_record_open(RECORD_DIALOGS);
  76. app->file_path = furi_string_alloc();
  77. app->timer = furi_timer_alloc(wiegand_timer_callback, FuriTimerTypePeriodic, app);
  78. return app;
  79. }
  80. void app_free(void* context) {
  81. App* app = context;
  82. furi_assert(app);
  83. view_dispatcher_remove_view(app->view_dispatcher, WiegandTextInputView);
  84. text_input_free(app->text_input);
  85. view_dispatcher_remove_view(app->view_dispatcher, WiegandWidgetView);
  86. widget_free(app->widget);
  87. view_dispatcher_remove_view(app->view_dispatcher, WiegandSubmenuView);
  88. submenu_free(app->submenu);
  89. scene_manager_free(app->scene_manager);
  90. view_dispatcher_free(app->view_dispatcher);
  91. furi_timer_free(app->timer);
  92. furi_record_close(RECORD_DIALOGS);
  93. free(app);
  94. }
  95. int wiegand_app(void* p) {
  96. UNUSED(p);
  97. App* app = app_alloc();
  98. Gui* gui = furi_record_open(RECORD_GUI);
  99. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  100. scene_manager_next_scene(app->scene_manager, WiegandMainMenuScene);
  101. view_dispatcher_run(app->view_dispatcher);
  102. app_free(app);
  103. return 0;
  104. }