infrared_scene_learn.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "../infrared_i.h"
  2. void infrared_scene_learn_on_enter(void* context) {
  3. Infrared* infrared = context;
  4. Popup* popup = infrared->popup;
  5. InfraredWorker* worker = infrared->worker;
  6. infrared_worker_rx_set_received_signal_callback(
  7. worker, infrared_signal_received_callback, context);
  8. infrared_worker_rx_start(worker);
  9. popup_set_icon(popup, 0, 32, &I_InfraredLearnShort_128x31);
  10. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignCenter);
  11. popup_set_text(
  12. popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter);
  13. popup_set_callback(popup, NULL);
  14. view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewPopup);
  15. }
  16. bool infrared_scene_learn_on_event(void* context, SceneManagerEvent event) {
  17. Infrared* infrared = context;
  18. bool consumed = false;
  19. if(event.type == SceneManagerEventTypeTick) {
  20. infrared_play_notification_message(infrared, InfraredNotificationMessageBlinkRead);
  21. consumed = true;
  22. } else if(event.type == SceneManagerEventTypeCustom) {
  23. if(event.event == InfraredCustomEventTypeSignalReceived) {
  24. infrared_worker_rx_set_received_signal_callback(infrared->worker, NULL, NULL);
  25. infrared_play_notification_message(infrared, InfraredNotificationMessageSuccess);
  26. scene_manager_next_scene(infrared->scene_manager, InfraredSceneLearnSuccess);
  27. consumed = true;
  28. }
  29. }
  30. return consumed;
  31. }
  32. void infrared_scene_learn_on_exit(void* context) {
  33. Infrared* infrared = context;
  34. Popup* popup = infrared->popup;
  35. infrared_worker_rx_stop(infrared->worker);
  36. popup_set_icon(popup, 0, 0, NULL);
  37. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignCenter);
  38. }