seos_scene_ble_peripheral.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "../seos_i.h"
  2. #include <dolphin/dolphin.h>
  3. #define TAG "SeosSceneBleReader"
  4. void seos_scene_ble_peripheral_on_enter(void* context) {
  5. Seos* seos = context;
  6. dolphin_deed(DolphinDeedNfcRead);
  7. // Setup view
  8. Popup* popup = seos->popup;
  9. popup_set_header(popup, "Starting", 68, 30, AlignLeft, AlignTop);
  10. if(seos->flow_mode == FLOW_READER) {
  11. popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  12. } else if(seos->flow_mode == FLOW_CRED) {
  13. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  14. }
  15. if(seos->has_external_ble) {
  16. seos->seos_characteristic = seos_characteristic_alloc(seos);
  17. seos_characteristic_start(seos->seos_characteristic, seos->flow_mode);
  18. } else {
  19. seos->native_peripheral = seos_native_peripheral_alloc(seos);
  20. seos_native_peripheral_start(seos->native_peripheral, seos->flow_mode);
  21. }
  22. seos_blink_start(seos);
  23. view_dispatcher_switch_to_view(seos->view_dispatcher, SeosViewPopup);
  24. }
  25. bool seos_scene_ble_peripheral_on_event(void* context, SceneManagerEvent event) {
  26. Seos* seos = context;
  27. Popup* popup = seos->popup;
  28. bool consumed = false;
  29. if(event.type == SceneManagerEventTypeCustom) {
  30. if(event.event == SeosCustomEventReaderSuccess) {
  31. notification_message(seos->notifications, &sequence_success);
  32. scene_manager_next_scene(seos->scene_manager, SeosSceneReadSuccess);
  33. consumed = true;
  34. } else if(event.event == SeosCustomEventReaderError) {
  35. scene_manager_next_scene(seos->scene_manager, SeosSceneReadError);
  36. consumed = true;
  37. } else if(event.event == SeosCustomEventHCIInit) {
  38. popup_set_header(popup, "Init", 68, 30, AlignLeft, AlignTop);
  39. consumed = true;
  40. } else if(event.event == SeosCustomEventAdvertising) {
  41. popup_set_header(popup, "Advertising", 68, 30, AlignLeft, AlignTop);
  42. consumed = true;
  43. } else if(event.event == SeosCustomEventConnected) {
  44. popup_set_header(popup, "Connected", 68, 30, AlignLeft, AlignTop);
  45. consumed = true;
  46. } else if(event.event == SeosCustomEventAuthenticated) {
  47. popup_set_header(popup, "Auth'd", 68, 30, AlignLeft, AlignTop);
  48. consumed = true;
  49. } else if(event.event == SeosCustomEventSIORequested) {
  50. popup_set_header(popup, "SIO\nRequested", 68, 30, AlignLeft, AlignTop);
  51. consumed = true;
  52. }
  53. } else if(event.type == SceneManagerEventTypeBack) {
  54. if(seos->credential->sio_len > 0) {
  55. scene_manager_search_and_switch_to_previous_scene(
  56. seos->scene_manager, SeosSceneSavedMenu);
  57. } else {
  58. scene_manager_previous_scene(seos->scene_manager);
  59. }
  60. consumed = true;
  61. }
  62. return consumed;
  63. }
  64. void seos_scene_ble_peripheral_on_exit(void* context) {
  65. Seos* seos = context;
  66. if(seos->seos_characteristic) {
  67. seos_characteristic_stop(seos->seos_characteristic);
  68. seos_characteristic_free(seos->seos_characteristic);
  69. seos->seos_characteristic = NULL;
  70. }
  71. if(seos->native_peripheral) {
  72. seos_native_peripheral_stop(seos->native_peripheral);
  73. seos_native_peripheral_free(seos->native_peripheral);
  74. seos->native_peripheral = NULL;
  75. }
  76. // Clear view
  77. popup_reset(seos->popup);
  78. seos_blink_stop(seos);
  79. }