2021-06-02 15:16:05 +00:00
|
|
|
#include "../irda-app.hpp"
|
|
|
|
#include "irda.h"
|
|
|
|
|
|
|
|
static void dialog_result_callback(DialogExResult result, void* context) {
|
|
|
|
auto app = static_cast<IrdaApp*>(context);
|
|
|
|
IrdaAppEvent event;
|
|
|
|
|
|
|
|
event.type = IrdaAppEvent::Type::DialogExSelected;
|
|
|
|
event.payload.dialog_ex_result = result;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
|
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
|
|
|
|
2021-06-09 13:04:49 +00:00
|
|
|
app->notify_green_on();
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
auto signal = app->get_received_signal();
|
|
|
|
|
|
|
|
if(!signal.is_raw()) {
|
|
|
|
auto message = &signal.get_message();
|
|
|
|
app->set_text_store(0, "%s", irda_get_protocol_name(message->protocol));
|
|
|
|
app->set_text_store(
|
|
|
|
1,
|
|
|
|
"A: 0x%0*lX\nC: 0x%0*lX\n",
|
|
|
|
irda_get_protocol_address_length(message->protocol),
|
|
|
|
message->address,
|
|
|
|
irda_get_protocol_command_length(message->protocol),
|
|
|
|
message->command);
|
|
|
|
dialog_ex_set_header(dialog_ex, app->get_text_store(0), 95, 10, AlignCenter, AlignCenter);
|
|
|
|
dialog_ex_set_text(dialog_ex, app->get_text_store(1), 75, 23, AlignLeft, AlignTop);
|
|
|
|
} else {
|
|
|
|
dialog_ex_set_header(dialog_ex, "Unknown", 95, 10, AlignCenter, AlignCenter);
|
|
|
|
app->set_text_store(0, "%d samples", signal.get_raw_signal().timings_cnt);
|
|
|
|
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 75, 23, AlignLeft, AlignTop);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
|
|
|
dialog_ex_set_right_button_text(dialog_ex, "Save");
|
2021-06-09 13:04:49 +00:00
|
|
|
dialog_ex_set_center_button_text(dialog_ex, "Send");
|
2021-07-07 08:57:49 +00:00
|
|
|
dialog_ex_set_icon(dialog_ex, 0, 1, &I_DolphinExcited_64x63);
|
2021-06-02 15:16:05 +00:00
|
|
|
dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
|
|
|
|
dialog_ex_set_context(dialog_ex, app);
|
|
|
|
|
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event->type == IrdaAppEvent::Type::DialogExSelected) {
|
|
|
|
switch(event->payload.dialog_ex_result) {
|
|
|
|
case DialogExResultLeft:
|
|
|
|
app->switch_to_next_scene_without_saving(IrdaApp::Scene::Learn);
|
|
|
|
break;
|
2021-06-09 13:04:49 +00:00
|
|
|
case DialogExResultCenter: {
|
|
|
|
app->notify_space_blink();
|
2021-07-16 16:43:54 +00:00
|
|
|
auto signal = app->get_received_signal();
|
|
|
|
signal.transmit();
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
2021-06-09 13:04:49 +00:00
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
case DialogExResultRight:
|
2021-06-09 13:04:49 +00:00
|
|
|
auto remote_manager = app->get_remote_manager();
|
|
|
|
if(remote_manager->check_fs()) {
|
|
|
|
app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
|
|
|
|
} else {
|
|
|
|
app->switch_to_previous_scene();
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) {
|
2021-06-09 13:04:49 +00:00
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
|
|
|
dialog_ex_set_center_button_text(dialog_ex, nullptr);
|
|
|
|
app->notify_green_off();
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|