2021-08-11 17:51:06 +00:00
|
|
|
#include "../irda-app.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
#include "gui/modules/button_menu.h"
|
2021-08-11 17:51:06 +00:00
|
|
|
#include "input/input.h"
|
|
|
|
#include "irda_worker.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ButtonIndexPlus = -2,
|
|
|
|
ButtonIndexEdit = -1,
|
2021-06-09 13:04:49 +00:00
|
|
|
ButtonIndexNA = 0,
|
2021-06-02 15:16:05 +00:00
|
|
|
} ButtonIndex;
|
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
static void button_menu_callback(void* context, int32_t index, InputType type) {
|
2021-06-02 15:16:05 +00:00
|
|
|
IrdaApp* app = static_cast<IrdaApp*>(context);
|
|
|
|
IrdaAppEvent event;
|
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
if(type == InputTypePress) {
|
|
|
|
event.type = IrdaAppEvent::Type::MenuSelectedPress;
|
|
|
|
} else if(type == InputTypeRelease) {
|
|
|
|
event.type = IrdaAppEvent::Type::MenuSelectedRelease;
|
|
|
|
} else if(type == InputTypeShort) {
|
|
|
|
event.type = IrdaAppEvent::Type::MenuSelected;
|
|
|
|
} else {
|
|
|
|
furi_assert(0);
|
|
|
|
}
|
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
event.payload.menu_index = index;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
static void irda_app_message_sent_callback(void* context) {
|
|
|
|
IrdaApp* app = static_cast<IrdaApp*>(context);
|
|
|
|
app->notify_blink_green();
|
|
|
|
}
|
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
void IrdaAppSceneRemote::on_enter(IrdaApp* app) {
|
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
ButtonMenu* button_menu = view_manager->get_button_menu();
|
|
|
|
auto remote_manager = app->get_remote_manager();
|
|
|
|
int i = 0;
|
2021-08-11 17:51:06 +00:00
|
|
|
button_pressed = false;
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
irda_worker_tx_set_get_signal_callback(
|
|
|
|
app->get_irda_worker(), irda_worker_tx_get_signal_steady_callback, app);
|
|
|
|
irda_worker_tx_set_signal_sent_callback(
|
|
|
|
app->get_irda_worker(), irda_app_message_sent_callback, app);
|
2021-06-02 15:16:05 +00:00
|
|
|
buttons_names = remote_manager->get_button_list();
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for(auto& name : buttons_names) {
|
|
|
|
button_menu_add_item(
|
|
|
|
button_menu, name.c_str(), i++, button_menu_callback, ButtonMenuItemTypeCommon, app);
|
|
|
|
}
|
|
|
|
|
|
|
|
button_menu_add_item(
|
|
|
|
button_menu, "+", ButtonIndexPlus, button_menu_callback, ButtonMenuItemTypeControl, app);
|
|
|
|
button_menu_add_item(
|
|
|
|
button_menu, "Edit", ButtonIndexEdit, button_menu_callback, ButtonMenuItemTypeControl, app);
|
|
|
|
|
2021-06-09 13:04:49 +00:00
|
|
|
app->set_text_store(0, "%s", remote_manager->get_remote_name().c_str());
|
2021-06-02 15:16:05 +00:00
|
|
|
button_menu_set_header(button_menu, app->get_text_store(0));
|
2021-06-09 13:04:49 +00:00
|
|
|
if(buttonmenu_item_selected != ButtonIndexNA) {
|
|
|
|
button_menu_set_selected_item(button_menu, buttonmenu_item_selected);
|
|
|
|
buttonmenu_item_selected = ButtonIndexNA;
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::ButtonMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = true;
|
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
if((event->type == IrdaAppEvent::Type::MenuSelected) ||
|
|
|
|
(event->type == IrdaAppEvent::Type::MenuSelectedPress) ||
|
|
|
|
(event->type == IrdaAppEvent::Type::MenuSelectedRelease)) {
|
2021-06-02 15:16:05 +00:00
|
|
|
switch(event->payload.menu_index) {
|
|
|
|
case ButtonIndexPlus:
|
2021-08-11 17:51:06 +00:00
|
|
|
furi_assert(event->type == IrdaAppEvent::Type::MenuSelected);
|
2021-06-09 13:04:49 +00:00
|
|
|
app->notify_click();
|
|
|
|
buttonmenu_item_selected = event->payload.menu_index;
|
|
|
|
app->set_learn_new_remote(false);
|
2021-06-02 15:16:05 +00:00
|
|
|
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
|
|
|
break;
|
|
|
|
case ButtonIndexEdit:
|
2021-08-11 17:51:06 +00:00
|
|
|
furi_assert(event->type == IrdaAppEvent::Type::MenuSelected);
|
2021-06-09 13:04:49 +00:00
|
|
|
app->notify_click();
|
|
|
|
buttonmenu_item_selected = event->payload.menu_index;
|
2021-06-02 15:16:05 +00:00
|
|
|
app->switch_to_next_scene(IrdaApp::Scene::Edit);
|
|
|
|
break;
|
|
|
|
default:
|
2021-08-11 17:51:06 +00:00
|
|
|
furi_assert(event->type != IrdaAppEvent::Type::MenuSelected);
|
|
|
|
bool pressed = (event->type == IrdaAppEvent::Type::MenuSelectedPress);
|
|
|
|
|
|
|
|
if(pressed && !button_pressed) {
|
|
|
|
button_pressed = true;
|
|
|
|
app->notify_click_and_green_blink();
|
|
|
|
|
|
|
|
auto button_signal =
|
|
|
|
app->get_remote_manager()->get_button_data(event->payload.menu_index);
|
|
|
|
if(button_signal.is_raw()) {
|
|
|
|
irda_worker_set_raw_signal(
|
|
|
|
app->get_irda_worker(),
|
|
|
|
button_signal.get_raw_signal().timings,
|
|
|
|
button_signal.get_raw_signal().timings_cnt);
|
|
|
|
} else {
|
|
|
|
irda_worker_set_decoded_signal(
|
|
|
|
app->get_irda_worker(), &button_signal.get_message());
|
|
|
|
}
|
|
|
|
|
|
|
|
irda_worker_tx_start(app->get_irda_worker());
|
|
|
|
} else if(!pressed && button_pressed) {
|
|
|
|
button_pressed = false;
|
|
|
|
irda_worker_tx_stop(app->get_irda_worker());
|
|
|
|
app->notify_green_off();
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if(event->type == IrdaAppEvent::Type::Back) {
|
|
|
|
app->search_and_switch_to_previous_scene(
|
|
|
|
{IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList});
|
|
|
|
} else {
|
|
|
|
consumed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneRemote::on_exit(IrdaApp* app) {
|
2021-08-11 17:51:06 +00:00
|
|
|
irda_worker_tx_set_get_signal_callback(app->get_irda_worker(), nullptr, nullptr);
|
|
|
|
irda_worker_tx_set_signal_sent_callback(app->get_irda_worker(), nullptr, nullptr);
|
2021-06-02 15:16:05 +00:00
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
ButtonMenu* button_menu = view_manager->get_button_menu();
|
|
|
|
|
|
|
|
button_menu_clean(button_menu);
|
|
|
|
}
|