2022-02-25 15:22:58 +00:00
|
|
|
#include "../infrared_app.h"
|
|
|
|
#include "infrared.h"
|
|
|
|
#include "infrared/scene/infrared_app_scene.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
static void dialog_result_callback(DialogExResult result, void* context) {
|
2022-02-25 15:22:58 +00:00
|
|
|
auto app = static_cast<InfraredApp*>(context);
|
|
|
|
InfraredAppEvent event;
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
event.type = InfraredAppEvent::Type::DialogExSelected;
|
2021-06-02 15:16:05 +00:00
|
|
|
event.payload.dialog_ex_result = result;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppSceneEditDelete::on_enter(InfraredApp* app) {
|
|
|
|
InfraredAppViewManager* view_manager = app->get_view_manager();
|
2021-06-02 15:16:05 +00:00
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
|
|
|
|
|
|
|
auto remote_manager = app->get_remote_manager();
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
if(app->get_edit_element() == InfraredApp::EditElement::Button) {
|
2021-07-16 16:43:54 +00:00
|
|
|
auto signal = remote_manager->get_button_data(app->get_current_button());
|
2022-02-16 11:09:47 +00:00
|
|
|
dialog_ex_set_header(dialog_ex, "Delete button?", 64, 0, AlignCenter, AlignTop);
|
2021-07-16 16:43:54 +00:00
|
|
|
if(!signal.is_raw()) {
|
|
|
|
auto message = &signal.get_message();
|
|
|
|
app->set_text_store(
|
|
|
|
0,
|
|
|
|
"%s\n%s\nA=0x%0*lX C=0x%0*lX",
|
|
|
|
remote_manager->get_button_name(app->get_current_button()).c_str(),
|
2022-02-25 15:22:58 +00:00
|
|
|
infrared_get_protocol_name(message->protocol),
|
|
|
|
ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4),
|
2021-07-16 16:43:54 +00:00
|
|
|
message->address,
|
2022-02-25 15:22:58 +00:00
|
|
|
ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4),
|
2021-07-16 16:43:54 +00:00
|
|
|
message->command);
|
|
|
|
} else {
|
|
|
|
app->set_text_store(
|
|
|
|
0,
|
|
|
|
"%s\nRAW\n%ld samples",
|
|
|
|
remote_manager->get_button_name(app->get_current_button()).c_str(),
|
|
|
|
signal.get_raw_signal().timings_cnt);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
} else {
|
2022-02-16 11:09:47 +00:00
|
|
|
dialog_ex_set_header(dialog_ex, "Delete remote?", 64, 0, AlignCenter, AlignTop);
|
2021-06-02 15:16:05 +00:00
|
|
|
app->set_text_store(
|
|
|
|
0,
|
|
|
|
"%s\n with %lu buttons",
|
2021-06-09 13:04:49 +00:00
|
|
|
remote_manager->get_remote_name().c_str(),
|
|
|
|
remote_manager->get_number_of_buttons());
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 11:09:47 +00:00
|
|
|
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 64, 31, AlignCenter, AlignCenter);
|
2021-07-07 08:57:49 +00:00
|
|
|
dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
|
2022-04-19 15:15:42 +00:00
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Cancel");
|
2021-06-02 15:16:05 +00:00
|
|
|
dialog_ex_set_right_button_text(dialog_ex, "Delete");
|
|
|
|
dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
|
|
|
|
dialog_ex_set_context(dialog_ex, app);
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
view_manager->switch_to(InfraredAppViewManager::ViewId::DialogEx);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppSceneEditDelete::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::DialogExSelected) {
|
2021-06-02 15:16:05 +00:00
|
|
|
switch(event->payload.dialog_ex_result) {
|
|
|
|
case DialogExResultLeft:
|
|
|
|
app->switch_to_previous_scene();
|
|
|
|
break;
|
|
|
|
case DialogExResultCenter:
|
|
|
|
furi_assert(0);
|
|
|
|
break;
|
2022-02-18 20:16:22 +00:00
|
|
|
case DialogExResultRight: {
|
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;
|
2022-02-25 15:22:58 +00:00
|
|
|
if(app->get_edit_element() == InfraredApp::EditElement::Remote) {
|
2021-06-09 13:04:49 +00:00
|
|
|
result = remote_manager->delete_remote();
|
2021-06-02 15:16:05 +00:00
|
|
|
} else {
|
2021-06-09 13:04:49 +00:00
|
|
|
result = remote_manager->delete_button(app->get_current_button());
|
2022-02-25 15:22:58 +00:00
|
|
|
app->set_current_button(InfraredApp::ButtonNA);
|
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::RemoteList, InfraredApp::Scene::Start});
|
2021-06-09 13:04:49 +00:00
|
|
|
} else {
|
2022-02-25 15:22:58 +00:00
|
|
|
app->switch_to_next_scene(InfraredApp::Scene::EditDeleteDone);
|
2021-06-09 13:04:49 +00:00
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-02-18 20:16:22 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:37:10 +00:00
|
|
|
void InfraredAppSceneEditDelete::on_exit(InfraredApp*) {
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|