wiegand.c 4.2 KB

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