2023-10-30 19:20:35 +03:00
|
|
|
#include "../infrared_app_i.h"
|
2022-10-28 10:18:41 +03:00
|
|
|
#include <dolphin/dolphin.h>
|
2022-06-21 15:45:50 +03:00
|
|
|
|
|
|
|
void infrared_scene_learn_on_enter(void* context) {
|
2023-10-30 19:20:35 +03:00
|
|
|
InfraredApp* infrared = context;
|
2022-06-21 15:45:50 +03:00
|
|
|
Popup* popup = infrared->popup;
|
|
|
|
InfraredWorker* worker = infrared->worker;
|
|
|
|
|
|
|
|
infrared_worker_rx_set_received_signal_callback(
|
|
|
|
worker, infrared_signal_received_callback, context);
|
|
|
|
infrared_worker_rx_start(worker);
|
2022-08-04 15:11:01 +03:00
|
|
|
infrared_play_notification_message(infrared, InfraredNotificationMessageBlinkStartRead);
|
2022-06-21 15:45:50 +03:00
|
|
|
|
|
|
|
popup_set_icon(popup, 0, 32, &I_InfraredLearnShort_128x31);
|
|
|
|
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignCenter);
|
|
|
|
popup_set_text(
|
|
|
|
popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter);
|
|
|
|
popup_set_callback(popup, NULL);
|
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewPopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool infrared_scene_learn_on_event(void* context, SceneManagerEvent event) {
|
2023-10-30 19:20:35 +03:00
|
|
|
InfraredApp* infrared = context;
|
2022-06-21 15:45:50 +03:00
|
|
|
bool consumed = false;
|
|
|
|
|
2022-08-04 15:11:01 +03:00
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-06-21 15:45:50 +03:00
|
|
|
if(event.event == InfraredCustomEventTypeSignalReceived) {
|
|
|
|
infrared_play_notification_message(infrared, InfraredNotificationMessageSuccess);
|
|
|
|
scene_manager_next_scene(infrared->scene_manager, InfraredSceneLearnSuccess);
|
2023-06-09 14:02:47 +03:00
|
|
|
dolphin_deed(DolphinDeedIrLearnSuccess);
|
2022-06-21 15:45:50 +03:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void infrared_scene_learn_on_exit(void* context) {
|
2023-10-30 19:20:35 +03:00
|
|
|
InfraredApp* infrared = context;
|
2022-06-21 15:45:50 +03:00
|
|
|
Popup* popup = infrared->popup;
|
2022-08-30 12:20:35 +03:00
|
|
|
infrared_worker_rx_set_received_signal_callback(infrared->worker, NULL, NULL);
|
2022-06-21 15:45:50 +03:00
|
|
|
infrared_worker_rx_stop(infrared->worker);
|
2022-08-04 15:11:01 +03:00
|
|
|
infrared_play_notification_message(infrared, InfraredNotificationMessageBlinkStop);
|
2022-06-21 15:45:50 +03:00
|
|
|
popup_set_icon(popup, 0, 0, NULL);
|
|
|
|
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignCenter);
|
|
|
|
}
|