ibutton_scene_read.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "../ibutton_i.h"
  2. #include <dolphin/dolphin.h>
  3. static void ibutton_scene_read_callback(void* context) {
  4. iButton* ibutton = context;
  5. view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventWorkerRead);
  6. }
  7. void ibutton_scene_read_on_enter(void* context) {
  8. iButton* ibutton = context;
  9. Popup* popup = ibutton->popup;
  10. iButtonKey* key = ibutton->key;
  11. iButtonWorker* worker = ibutton->worker;
  12. popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
  13. popup_set_text(popup, "Apply key to\nFlipper's back", 95, 30, AlignCenter, AlignTop);
  14. popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
  15. view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
  16. ibutton_worker_read_set_callback(worker, ibutton_scene_read_callback, ibutton);
  17. ibutton_worker_read_start(worker, key);
  18. ibutton_notification_message(ibutton, iButtonNotificationMessageReadStart);
  19. }
  20. bool ibutton_scene_read_on_event(void* context, SceneManagerEvent event) {
  21. iButton* ibutton = context;
  22. SceneManager* scene_manager = ibutton->scene_manager;
  23. bool consumed = false;
  24. if(event.type == SceneManagerEventTypeTick) {
  25. consumed = true;
  26. } else if(event.type == SceneManagerEventTypeCustom) {
  27. consumed = true;
  28. if(event.event == iButtonCustomEventWorkerRead) {
  29. if(ibutton_protocols_is_valid(ibutton->protocols, ibutton->key)) {
  30. ibutton_notification_message(ibutton, iButtonNotificationMessageSuccess);
  31. scene_manager_next_scene(scene_manager, iButtonSceneReadSuccess);
  32. DOLPHIN_DEED(DolphinDeedIbuttonReadSuccess);
  33. } else {
  34. scene_manager_next_scene(scene_manager, iButtonSceneReadError);
  35. }
  36. }
  37. }
  38. return consumed;
  39. }
  40. void ibutton_scene_read_on_exit(void* context) {
  41. iButton* ibutton = context;
  42. Popup* popup = ibutton->popup;
  43. ibutton_worker_stop(ibutton->worker);
  44. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  45. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  46. popup_set_icon(popup, 0, 0, NULL);
  47. ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
  48. }