[FL-1250, FL-1252, FL-1323, FL-1324] New IRDA Application (part 1) (#497)
* Add new IrdaApp (half ready), add ButtonMenu * Fix NEC's extension * clang-format * Fix leak * Add submenu optional header * IRDA: add Edit button * clang-format * IrdaApp: Fix scene flow * Add IRDA NEC extended protocol * IRDA: Add address/command length Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
35
applications/irda/scene/irda-app-scene-edit-delete-done.cpp
Normal file
35
applications/irda/scene/irda-app-scene-edit-delete-done.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
void IrdaAppSceneEditDeleteDone::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 0, 2, I_DolphinMafia_115x62);
|
||||
popup_set_text(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, IrdaApp::popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneEditDeleteDone::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::PopupTimer) {
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Remote) {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList});
|
||||
} else {
|
||||
app->search_and_switch_to_previous_scene({IrdaApp::Scene::Remote});
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneEditDeleteDone::on_exit(IrdaApp* app) {
|
||||
}
|
81
applications/irda/scene/irda-app-scene-edit-delete.cpp
Normal file
81
applications/irda/scene/irda-app-scene-edit-delete.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "irda.h"
|
||||
#include <string>
|
||||
#include <stdio.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 IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
||||
auto message = remote_manager->get_button_data(remote_manager->get_current_button());
|
||||
dialog_ex_set_header(dialog_ex, "Delete button?", 64, 6, AlignCenter, AlignCenter);
|
||||
app->set_text_store(
|
||||
0,
|
||||
"%s\n%s\nA=0x%0*lX C=0x%0*lX",
|
||||
remote_manager->get_current_button_name().c_str(),
|
||||
irda_get_protocol_name(message->protocol),
|
||||
irda_get_protocol_address_length(message->protocol),
|
||||
message->address,
|
||||
irda_get_protocol_command_length(message->protocol),
|
||||
message->command);
|
||||
} else {
|
||||
dialog_ex_set_header(dialog_ex, "Delete remote?", 64, 6, AlignCenter, AlignCenter);
|
||||
app->set_text_store(
|
||||
0,
|
||||
"%s\n with %lu buttons",
|
||||
remote_manager->get_current_remote_name().c_str(),
|
||||
remote_manager->get_current_remote_buttons_number());
|
||||
}
|
||||
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 64, 32, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_icon(dialog_ex, -1, -1, I_ButtonCenter_7x7);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
||||
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);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneEditDelete::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_previous_scene();
|
||||
break;
|
||||
case DialogExResultCenter:
|
||||
furi_assert(0);
|
||||
break;
|
||||
case DialogExResultRight:
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Remote) {
|
||||
remote_manager->delete_current_remote();
|
||||
} else {
|
||||
remote_manager->delete_current_button();
|
||||
}
|
||||
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditDeleteDone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneEditDelete::on_exit(IrdaApp* app) {
|
||||
}
|
54
applications/irda/scene/irda-app-scene-edit-key-select.cpp
Normal file
54
applications/irda/scene/irda-app-scene-edit-key-select.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "gui/modules/submenu.h"
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::MenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void IrdaAppSceneEditKeySelect::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
int i = 0;
|
||||
|
||||
const char* header = app->get_edit_action() == IrdaApp::EditAction::Rename ? "Rename key:" :
|
||||
"Delete key:";
|
||||
submenu_set_header(submenu, header);
|
||||
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
buttons_names = remote_manager->get_button_list();
|
||||
for(const auto& it : buttons_names) {
|
||||
submenu_add_item(submenu, it.c_str(), i++, submenu_callback, app);
|
||||
}
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneEditKeySelect::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
remote_manager->set_current_button(event->payload.menu_index);
|
||||
consumed = true;
|
||||
if(app->get_edit_action() == IrdaApp::EditAction::Rename) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditRename);
|
||||
} else {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditDelete);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneEditKeySelect::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
31
applications/irda/scene/irda-app-scene-edit-rename-done.cpp
Normal file
31
applications/irda/scene/irda-app-scene-edit-rename-done.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
void IrdaAppSceneEditRenameDone::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 32, 5, I_DolphinNice_96x59);
|
||||
|
||||
popup_set_text(popup, "Saved!", 13, 22, AlignLeft, AlignTop);
|
||||
|
||||
popup_set_callback(popup, IrdaApp::popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneEditRenameDone::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::PopupTimer) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneEditRenameDone::on_exit(IrdaApp* app) {
|
||||
}
|
46
applications/irda/scene/irda-app-scene-edit-rename.cpp
Normal file
46
applications/irda/scene/irda-app-scene-edit-rename.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
void IrdaAppSceneEditRename::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
TextInput* text_input = view_manager->get_text_input();
|
||||
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
||||
auto button_name = remote_manager->get_current_button_name();
|
||||
strncpy(app->get_text_store(0), button_name.c_str(), app->get_text_store_size());
|
||||
} else {
|
||||
auto remote_name = remote_manager->get_current_remote_name();
|
||||
strncpy(app->get_text_store(0), remote_name.c_str(), app->get_text_store_size());
|
||||
}
|
||||
|
||||
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),
|
||||
app->get_text_store_size());
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneEditRename::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::TextEditDone) {
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
||||
remote_manager->rename_button(app->get_text_store(0));
|
||||
} else {
|
||||
remote_manager->rename_remote(app->get_text_store(0));
|
||||
}
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::EditRenameDone);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneEditRename::on_exit(IrdaApp* app) {
|
||||
}
|
74
applications/irda/scene/irda-app-scene-edit.cpp
Normal file
74
applications/irda/scene/irda-app-scene-edit.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexAddKey,
|
||||
SubmenuIndexRenameKey,
|
||||
SubmenuIndexDeleteKey,
|
||||
SubmenuIndexRenameRemote,
|
||||
SubmenuIndexDeleteRemote,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::MenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void IrdaAppSceneEdit::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_add_item(submenu, "Add key", SubmenuIndexAddKey, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Rename key", SubmenuIndexRenameKey, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Delete key", SubmenuIndexDeleteKey, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Rename remote", SubmenuIndexRenameRemote, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Delete remote", SubmenuIndexDeleteRemote, submenu_callback, app);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneEdit::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexAddKey:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
case SubmenuIndexRenameKey:
|
||||
app->set_edit_action(IrdaApp::EditAction::Rename);
|
||||
app->set_edit_element(IrdaApp::EditElement::Button);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditKeySelect);
|
||||
break;
|
||||
case SubmenuIndexDeleteKey:
|
||||
app->set_edit_action(IrdaApp::EditAction::Delete);
|
||||
app->set_edit_element(IrdaApp::EditElement::Button);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditKeySelect);
|
||||
break;
|
||||
case SubmenuIndexRenameRemote:
|
||||
app->set_edit_action(IrdaApp::EditAction::Rename);
|
||||
app->set_edit_element(IrdaApp::EditElement::Remote);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditRename);
|
||||
break;
|
||||
case SubmenuIndexDeleteRemote:
|
||||
app->set_edit_action(IrdaApp::EditAction::Delete);
|
||||
app->set_edit_element(IrdaApp::EditElement::Remote);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditDelete);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneEdit::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
34
applications/irda/scene/irda-app-scene-learn-done-after.cpp
Normal file
34
applications/irda/scene/irda-app-scene-learn-done-after.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <gui/modules/popup.h>
|
||||
|
||||
void IrdaAppSceneLearnDoneAfter::on_enter(IrdaApp* app) {
|
||||
auto view_manager = app->get_view_manager();
|
||||
auto popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 0, 30, I_IrdaSendShort_128x34);
|
||||
popup_set_text(
|
||||
popup, "Get ready!\nPoint flipper at target.", 64, 16, AlignCenter, AlignCenter);
|
||||
|
||||
popup_set_callback(popup, IrdaApp::popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneLearnDoneAfter::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::PopupTimer) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneLearnDoneAfter::on_exit(IrdaApp* app) {
|
||||
}
|
42
applications/irda/scene/irda-app-scene-learn-done.cpp
Normal file
42
applications/irda/scene/irda-app-scene-learn-done.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
void IrdaAppSceneLearnDone::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 32, 5, I_DolphinNice_96x59);
|
||||
|
||||
if(app->get_learn_new_remote()) {
|
||||
popup_set_text(popup, "New remote\ncreated!", 5, 7, AlignLeft, AlignTop);
|
||||
} else {
|
||||
popup_set_text(popup, "Saved!", 5, 7, AlignLeft, AlignTop);
|
||||
}
|
||||
|
||||
popup_set_callback(popup, IrdaApp::popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneLearnDone::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::PopupTimer) {
|
||||
if(app->get_learn_new_remote()) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::LearnDoneAfter);
|
||||
} else {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneLearnDone::on_exit(IrdaApp* app) {
|
||||
app->set_learn_new_remote(false);
|
||||
}
|
51
applications/irda/scene/irda-app-scene-learn-enter-name.cpp
Normal file
51
applications/irda/scene/irda-app-scene-learn-enter-name.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "gui/modules/text_input.h"
|
||||
#include <callback-connector.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
TextInput* text_input = view_manager->get_text_input();
|
||||
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_message();
|
||||
|
||||
app->set_text_store(
|
||||
0,
|
||||
"%.4s_%0*lX",
|
||||
irda_get_protocol_name(message->protocol),
|
||||
irda_get_protocol_command_length(message->protocol),
|
||||
message->command);
|
||||
|
||||
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),
|
||||
app->get_text_store_size());
|
||||
|
||||
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();
|
||||
auto receiver = app->get_receiver();
|
||||
if(app->get_learn_new_remote()) {
|
||||
remote_manager->add_remote_with_button(
|
||||
app->get_text_store(0), receiver->get_last_message());
|
||||
} else {
|
||||
remote_manager->add_button(app->get_text_store(0), receiver->get_last_message());
|
||||
}
|
||||
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnDone);
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneLearnEnterName::on_exit(IrdaApp* app) {
|
||||
}
|
63
applications/irda/scene/irda-app-scene-learn-success.cpp
Normal file
63
applications/irda/scene/irda-app-scene-learn-success.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "irda.h"
|
||||
#include <string>
|
||||
#include <stdio.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();
|
||||
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_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);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "Save");
|
||||
dialog_ex_set_icon(dialog_ex, 0, 1, I_DolphinExcited_64x63);
|
||||
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;
|
||||
case DialogExResultCenter:
|
||||
furi_assert(0);
|
||||
break;
|
||||
case DialogExResultRight:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) {
|
||||
}
|
31
applications/irda/scene/irda-app-scene-learn.cpp
Normal file
31
applications/irda/scene/irda-app-scene-learn.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
void IrdaAppSceneLearn::on_enter(IrdaApp* app) {
|
||||
auto view_manager = app->get_view_manager();
|
||||
auto receiver = app->get_receiver();
|
||||
auto event_queue = view_manager->get_event_queue();
|
||||
|
||||
receiver->capture_once_start(event_queue);
|
||||
|
||||
auto popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 0, 32, I_IrdaLearnShort_128x31);
|
||||
popup_set_text(
|
||||
popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter);
|
||||
popup_set_callback(popup, NULL);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneLearn::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::IrdaMessageReceived) {
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnSuccess);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneLearn::on_exit(IrdaApp* app) {
|
||||
}
|
59
applications/irda/scene/irda-app-scene-remote-list.cpp
Normal file
59
applications/irda/scene/irda-app-scene-remote-list.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexPlus = -1,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::MenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void IrdaAppSceneRemoteList::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
int i = 0;
|
||||
|
||||
remote_names = remote_manager->get_remote_list();
|
||||
for(auto& a : remote_names) {
|
||||
submenu_add_item(submenu, a.c_str(), i++, submenu_callback, app);
|
||||
}
|
||||
submenu_add_item(
|
||||
submenu, " +", SubmenuIndexPlus, submenu_callback, app);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneRemoteList::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexPlus:
|
||||
app->set_learn_new_remote(true);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
default:
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
remote_manager->set_current_remote(event->payload.menu_index);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneRemoteList::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
75
applications/irda/scene/irda-app-scene-remote.cpp
Normal file
75
applications/irda/scene/irda-app-scene-remote.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "gui/modules/button_menu.h"
|
||||
|
||||
typedef enum {
|
||||
ButtonIndexPlus = -2,
|
||||
ButtonIndexEdit = -1,
|
||||
} ButtonIndex;
|
||||
|
||||
static void button_menu_callback(void* context, int32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::MenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
app->set_text_store(0, "%s", remote_manager->get_current_remote_name().c_str());
|
||||
button_menu_set_header(button_menu, app->get_text_store(0));
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::ButtonMenu);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = true;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case ButtonIndexPlus:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
case ButtonIndexEdit:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Edit);
|
||||
break;
|
||||
default:
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
auto message = remote_manager->get_button_data(event->payload.menu_index);
|
||||
app->get_receiver()->send_message(message);
|
||||
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) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
ButtonMenu* button_menu = view_manager->get_button_menu();
|
||||
|
||||
button_menu_clean(button_menu);
|
||||
}
|
59
applications/irda/scene/irda-app-scene-start.cpp
Normal file
59
applications/irda/scene/irda-app-scene-start.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexUniversalLibrary,
|
||||
SubmenuIndexLearnNewRemote,
|
||||
SubmenuIndexSavedRemotes,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::MenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void IrdaAppSceneStart::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Universal library", SubmenuIndexUniversalLibrary, submenu_callback, app);
|
||||
submenu_add_item(
|
||||
submenu, "Learn new remote", SubmenuIndexLearnNewRemote, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Saved remotes", SubmenuIndexSavedRemotes, submenu_callback, app);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneStart::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexUniversalLibrary:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Universal);
|
||||
break;
|
||||
case SubmenuIndexLearnNewRemote:
|
||||
app->set_learn_new_remote(true);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
case SubmenuIndexSavedRemotes:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::RemoteList);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneStart::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
57
applications/irda/scene/irda-app-scene-universal.cpp
Normal file
57
applications/irda/scene/irda-app-scene-universal.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "../irda-app.hpp"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexUniversalTV,
|
||||
SubmenuIndexUniversalAudio,
|
||||
SubmenuIndexUniversalAirConditioner,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::MenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void IrdaAppSceneUniversal::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_add_item(submenu, "TV's", SubmenuIndexUniversalTV, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Audio Players", SubmenuIndexUniversalAudio, submenu_callback, app);
|
||||
submenu_add_item(
|
||||
submenu, "Air Conditioners", SubmenuIndexUniversalAirConditioner, submenu_callback, app);
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneUniversal::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexUniversalTV:
|
||||
// app->switch_to_next_scene(IrdaApp::Scene::UniversalTV);
|
||||
break;
|
||||
case SubmenuIndexUniversalAudio:
|
||||
// app->switch_to_next_scene(IrdaApp::Scene::UniversalAudio);
|
||||
break;
|
||||
case SubmenuIndexUniversalAirConditioner:
|
||||
// app->switch_to_next_scene(IrdaApp::Scene::UniversalAirConditioner);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneUniversal::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
130
applications/irda/scene/irda-app-scene.hpp
Normal file
130
applications/irda/scene/irda-app-scene.hpp
Normal file
@@ -0,0 +1,130 @@
|
||||
#pragma once
|
||||
#include "../irda-app.hpp"
|
||||
#include <api-hal-irda.h>
|
||||
#include "irda.h"
|
||||
#include <gui/elements.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class IrdaApp;
|
||||
|
||||
class IrdaAppScene {
|
||||
public:
|
||||
virtual void on_enter(IrdaApp* app) = 0;
|
||||
virtual bool on_event(IrdaApp* app, IrdaAppEvent* event) = 0;
|
||||
virtual void on_exit(IrdaApp* app) = 0;
|
||||
virtual ~IrdaAppScene(){};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class IrdaAppSceneStart : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneUniversal : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneLearn : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneLearnSuccess : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneLearnEnterName : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneLearnDone : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneLearnDoneAfter : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneRemote : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
std::vector<std::string> buttons_names;
|
||||
};
|
||||
|
||||
class IrdaAppSceneRemoteList : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
std::vector<std::string> remote_names;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEdit : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEditKeySelect : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
std::vector<std::string> buttons_names;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEditRename : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEditDelete : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEditRenameDone : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEditDeleteDone : public IrdaAppScene {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
Reference in New Issue
Block a user