2022-02-25 15:22:58 +00:00
|
|
|
#include "../infrared_app.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
#include "gui/modules/text_input.h"
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppSceneLearnEnterName::on_enter(InfraredApp* app) {
|
|
|
|
InfraredAppViewManager* view_manager = app->get_view_manager();
|
2021-06-02 15:16:05 +00:00
|
|
|
TextInput* text_input = view_manager->get_text_input();
|
|
|
|
|
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,
|
|
|
|
"%.4s_%0*lX",
|
2022-02-25 15:22:58 +00:00
|
|
|
infrared_get_protocol_name(message->protocol),
|
|
|
|
ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4),
|
2021-07-16 16:43:54 +00:00
|
|
|
message->command);
|
|
|
|
} else {
|
|
|
|
auto raw_signal = signal.get_raw_signal();
|
|
|
|
app->set_text_store(0, "RAW_%d", raw_signal.timings_cnt);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-04-19 11:07:14 +00:00
|
|
|
text_input_set_header_text(text_input, "Name the button");
|
2021-06-02 15:16:05 +00:00
|
|
|
text_input_set_result_callback(
|
|
|
|
text_input,
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp::text_input_callback,
|
2021-06-02 15:16:05 +00:00
|
|
|
app,
|
|
|
|
app->get_text_store(0),
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppRemoteManager::max_button_name_length,
|
2021-10-12 15:05:02 +00:00
|
|
|
true);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
view_manager->switch_to(InfraredAppViewManager::ViewId::TextInput);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppSceneLearnEnterName::on_event(InfraredApp* app, InfraredAppEvent* event) {
|
2021-06-02 15:16:05 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
if(event->type == InfraredAppEvent::Type::TextEditDone) {
|
2021-06-02 15:16:05 +00:00
|
|
|
auto remote_manager = app->get_remote_manager();
|
2021-06-09 13:04:49 +00:00
|
|
|
bool result = false;
|
2021-06-02 15:16:05 +00:00
|
|
|
if(app->get_learn_new_remote()) {
|
2021-06-09 13:04:49 +00:00
|
|
|
result = remote_manager->add_remote_with_button(
|
2021-07-16 16:43:54 +00:00
|
|
|
app->get_text_store(0), app->get_received_signal());
|
2021-06-02 15:16:05 +00:00
|
|
|
} else {
|
2021-07-16 16:43:54 +00:00
|
|
|
result =
|
|
|
|
remote_manager->add_button(app->get_text_store(0), app->get_received_signal());
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 13:04:49 +00:00
|
|
|
if(!result) {
|
|
|
|
app->search_and_switch_to_previous_scene(
|
2022-02-25 15:22:58 +00:00
|
|
|
{InfraredApp::Scene::Start, InfraredApp::Scene::RemoteList});
|
2021-06-09 13:04:49 +00:00
|
|
|
} else {
|
2022-02-25 15:22:58 +00:00
|
|
|
app->switch_to_next_scene_without_saving(InfraredApp::Scene::LearnDone);
|
2021-06-09 13:04:49 +00:00
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:37:10 +00:00
|
|
|
void InfraredAppSceneLearnEnterName::on_exit(InfraredApp*) {
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|