2021-08-11 17:51:06 +00:00
|
|
|
#include "../irda-app.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
#include "gui/modules/text_input.h"
|
|
|
|
|
|
|
|
void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) {
|
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
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",
|
|
|
|
irda_get_protocol_name(message->protocol),
|
2021-09-09 21:37:32 +00:00
|
|
|
ROUND_UP_TO(irda_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
|
|
|
|
|
|
|
text_input_set_header_text(text_input, "Name the key");
|
|
|
|
text_input_set_result_callback(
|
|
|
|
text_input,
|
|
|
|
IrdaApp::text_input_callback,
|
|
|
|
app,
|
|
|
|
app->get_text_store(0),
|
2021-08-19 00:18:42 +00:00
|
|
|
IrdaAppRemoteManager::max_button_name_length,
|
2021-07-25 11:34:54 +00:00
|
|
|
false);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event->type == IrdaAppEvent::Type::TextEditDone) {
|
|
|
|
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(
|
|
|
|
{IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList});
|
|
|
|
} else {
|
|
|
|
app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnDone);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneLearnEnterName::on_exit(IrdaApp* app) {
|
|
|
|
}
|