seos_scene_ble_central.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "../seos_i.h"
  2. #include "../seos_central.h"
  3. #include "../seos_common.h"
  4. #include <dolphin/dolphin.h>
  5. #define TAG "SeosSceneBleCentral"
  6. void seos_scene_ble_central_on_enter(void* context) {
  7. Seos* seos = context;
  8. dolphin_deed(DolphinDeedNfcRead);
  9. // Setup view
  10. Popup* popup = seos->popup;
  11. popup_set_header(popup, "Starting...", 68, 20, AlignLeft, AlignTop);
  12. // popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
  13. seos->seos_central = seos_central_alloc(seos);
  14. seos_central_start(seos->seos_central, seos->flow_mode);
  15. seos_blink_start(seos);
  16. view_dispatcher_switch_to_view(seos->view_dispatcher, SeosViewPopup);
  17. }
  18. bool seos_scene_ble_central_on_event(void* context, SceneManagerEvent event) {
  19. Seos* seos = context;
  20. Popup* popup = seos->popup;
  21. bool consumed = false;
  22. if(event.type == SceneManagerEventTypeCustom) {
  23. if(event.event == SeosCustomEventReaderSuccess) {
  24. notification_message(seos->notifications, &sequence_success);
  25. scene_manager_next_scene(seos->scene_manager, SeosSceneReadSuccess);
  26. consumed = true;
  27. } else if(event.event == SeosCustomEventReaderError) {
  28. notification_message(seos->notifications, &sequence_error);
  29. scene_manager_next_scene(seos->scene_manager, SeosSceneReadError);
  30. consumed = true;
  31. } else if(event.event == SeosCustomEventHCIInit) {
  32. popup_set_header(popup, "Init", 68, 20, AlignLeft, AlignTop);
  33. consumed = true;
  34. } else if(event.event == SeosCustomEventScan) {
  35. popup_set_header(popup, "Scanning...", 68, 20, AlignLeft, AlignTop);
  36. consumed = true;
  37. } else if(event.event == SeosCustomEventFound) {
  38. popup_set_header(popup, "Device\nfound", 68, 20, AlignLeft, AlignTop);
  39. consumed = true;
  40. } else if(event.event == SeosCustomEventConnected) {
  41. popup_set_header(popup, "Connected", 68, 20, AlignLeft, AlignTop);
  42. consumed = true;
  43. } else if(event.event == SeosCustomEventAuthenticated) {
  44. popup_set_header(popup, "Auth'd", 68, 20, AlignLeft, AlignTop);
  45. consumed = true;
  46. } else if(event.event == SeosCustomEventSIORequested) {
  47. popup_set_header(popup, "SIO\nRequested", 68, 20, AlignLeft, AlignTop);
  48. consumed = true;
  49. }
  50. } else if(event.type == SceneManagerEventTypeBack) {
  51. if(seos->credential->sio_len > 0) {
  52. scene_manager_search_and_switch_to_previous_scene(
  53. seos->scene_manager, SeosSceneSavedMenu);
  54. } else {
  55. scene_manager_previous_scene(seos->scene_manager);
  56. }
  57. consumed = true;
  58. }
  59. return consumed;
  60. }
  61. void seos_scene_ble_central_on_exit(void* context) {
  62. Seos* seos = context;
  63. if(seos->seos_central) {
  64. FURI_LOG_D(TAG, "Cleanup");
  65. seos_central_stop(seos->seos_central);
  66. seos_central_free(seos->seos_central);
  67. seos->seos_central = NULL;
  68. }
  69. // Clear view
  70. popup_reset(seos->popup);
  71. seos_blink_stop(seos);
  72. }