2022-01-05 16:10:18 +00:00
|
|
|
#include "../irda_app.h"
|
|
|
|
#include "../irda_app_event.h"
|
2022-01-10 17:13:41 +00:00
|
|
|
#include "irda.h"
|
2021-07-16 16:43:54 +00:00
|
|
|
#include <irda_worker.h>
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
static void signal_received_callback(void* context, IrdaWorkerSignal* received_signal) {
|
|
|
|
furi_assert(context);
|
|
|
|
furi_assert(received_signal);
|
|
|
|
|
|
|
|
IrdaApp* app = static_cast<IrdaApp*>(context);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
if(irda_worker_signal_is_decoded(received_signal)) {
|
2021-08-11 17:51:06 +00:00
|
|
|
IrdaAppSignal signal(irda_worker_get_decoded_signal(received_signal));
|
2021-07-16 16:43:54 +00:00
|
|
|
app->set_received_signal(signal);
|
|
|
|
} else {
|
|
|
|
const uint32_t* timings;
|
|
|
|
size_t timings_cnt;
|
|
|
|
irda_worker_get_raw_signal(received_signal, &timings, &timings_cnt);
|
2022-01-10 17:13:41 +00:00
|
|
|
IrdaAppSignal signal(
|
|
|
|
timings, timings_cnt, IRDA_COMMON_CARRIER_FREQUENCY, IRDA_COMMON_DUTY_CYCLE);
|
2021-07-16 16:43:54 +00:00
|
|
|
app->set_received_signal(signal);
|
|
|
|
}
|
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
irda_worker_rx_set_received_signal_callback(app->get_irda_worker(), NULL, NULL);
|
2021-07-16 16:43:54 +00:00
|
|
|
IrdaAppEvent event;
|
|
|
|
event.type = IrdaAppEvent::Type::IrdaMessageReceived;
|
|
|
|
auto view_manager = app->get_view_manager();
|
|
|
|
view_manager->send_event(&event);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
void IrdaAppSceneLearn::on_enter(IrdaApp* app) {
|
|
|
|
auto view_manager = app->get_view_manager();
|
2021-06-02 15:16:05 +00:00
|
|
|
auto popup = view_manager->get_popup();
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
auto worker = app->get_irda_worker();
|
2021-08-11 17:51:06 +00:00
|
|
|
irda_worker_rx_set_received_signal_callback(worker, signal_received_callback, app);
|
|
|
|
irda_worker_rx_start(worker);
|
2021-07-16 16:43:54 +00:00
|
|
|
|
2021-07-07 08:57:49 +00:00
|
|
|
popup_set_icon(popup, 0, 32, &I_IrdaLearnShort_128x31);
|
2021-06-02 15:16:05 +00:00
|
|
|
popup_set_text(
|
|
|
|
popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter);
|
|
|
|
popup_set_callback(popup, NULL);
|
|
|
|
|
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneLearn::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = false;
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
switch(event->type) {
|
|
|
|
case IrdaAppEvent::Type::Tick:
|
2021-06-09 13:04:49 +00:00
|
|
|
consumed = true;
|
|
|
|
app->notify_red_blink();
|
2021-07-16 16:43:54 +00:00
|
|
|
break;
|
|
|
|
case IrdaAppEvent::Type::IrdaMessageReceived:
|
2021-06-09 13:04:49 +00:00
|
|
|
app->notify_success();
|
2021-06-02 15:16:05 +00:00
|
|
|
app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnSuccess);
|
2021-07-16 16:43:54 +00:00
|
|
|
break;
|
|
|
|
case IrdaAppEvent::Type::Back:
|
|
|
|
consumed = true;
|
|
|
|
app->switch_to_previous_scene();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
furi_assert(0);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneLearn::on_exit(IrdaApp* app) {
|
2021-08-11 17:51:06 +00:00
|
|
|
irda_worker_rx_stop(app->get_irda_worker());
|
2022-02-16 11:09:47 +00:00
|
|
|
auto view_manager = app->get_view_manager();
|
|
|
|
auto popup = view_manager->get_popup();
|
|
|
|
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignCenter);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|