seos_scene_ble_peripheral.c 3.2 KB

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