[FL-1369, FL-1397, FL-1420] IRDA + SDcard (#513)
* Add saving to SD-Card (not ready yet) * Add saving to SD-card (done) * Select previous menu item * Fix central button * Fix current_button * Refactoring * Add notifications * [FL-1417] Add IRDA CLI CLI commands: 1) ir_rx Receives all IR-trafic, decodes and prints result to stdout 2) ir_tx <protocol> <address> <command> Transmits IR-signal. Address and command are hex-formatted * Fix BUG with random memory corruption at random time in random place in random universe in random unknown space and time forever amen * Fix submenu set_selected_item * Bring protocol order back * Add TODO sdcard check
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "irda.h"
|
||||
#include "irda/scene/irda-app-scene.hpp"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -20,12 +21,12 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
|
||||
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());
|
||||
auto message = remote_manager->get_button_data(app->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(),
|
||||
remote_manager->get_button_name(app->get_current_button()).c_str(),
|
||||
irda_get_protocol_name(message->protocol),
|
||||
irda_get_protocol_address_length(message->protocol),
|
||||
message->address,
|
||||
@@ -36,8 +37,8 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
|
||||
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());
|
||||
remote_manager->get_remote_name().c_str(),
|
||||
remote_manager->get_number_of_buttons());
|
||||
}
|
||||
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 64, 32, AlignCenter, AlignCenter);
|
||||
@@ -63,13 +64,20 @@ bool IrdaAppSceneEditDelete::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
break;
|
||||
case DialogExResultRight:
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
bool result = false;
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Remote) {
|
||||
remote_manager->delete_current_remote();
|
||||
result = remote_manager->delete_remote();
|
||||
} else {
|
||||
remote_manager->delete_current_button();
|
||||
result = remote_manager->delete_button(app->get_current_button());
|
||||
app->set_current_button(IrdaApp::ButtonNA);
|
||||
}
|
||||
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditDeleteDone);
|
||||
if(!result) {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{IrdaApp::Scene::RemoteList, IrdaApp::Scene::Start});
|
||||
} else {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::EditDeleteDone);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ static void submenu_callback(void* context, uint32_t index) {
|
||||
void IrdaAppSceneEditKeySelect::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
int i = 0;
|
||||
int item_number = 0;
|
||||
|
||||
const char* header = app->get_edit_action() == IrdaApp::EditAction::Rename ? "Rename key:" :
|
||||
"Delete key:";
|
||||
@@ -23,7 +23,11 @@ void IrdaAppSceneEditKeySelect::on_enter(IrdaApp* app) {
|
||||
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);
|
||||
submenu_add_item(submenu, it.c_str(), item_number++, submenu_callback, app);
|
||||
}
|
||||
if((item_number > 0) && (app->get_current_button() != IrdaApp::ButtonNA)) {
|
||||
submenu_set_selected_item(submenu, app->get_current_button());
|
||||
app->set_current_button(IrdaApp::ButtonNA);
|
||||
}
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
@@ -33,8 +37,7 @@ 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);
|
||||
app->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);
|
||||
|
||||
@@ -7,10 +7,11 @@ void IrdaAppSceneEditRename::on_enter(IrdaApp* app) {
|
||||
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
||||
auto button_name = remote_manager->get_current_button_name();
|
||||
furi_assert(app->get_current_button() != IrdaApp::ButtonNA);
|
||||
auto button_name = remote_manager->get_button_name(app->get_current_button());
|
||||
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();
|
||||
auto remote_name = remote_manager->get_remote_name();
|
||||
strncpy(app->get_text_store(0), remote_name.c_str(), app->get_text_store_size());
|
||||
}
|
||||
|
||||
@@ -30,12 +31,20 @@ bool IrdaAppSceneEditRename::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::TextEditDone) {
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
bool result = false;
|
||||
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
||||
remote_manager->rename_button(app->get_text_store(0));
|
||||
result =
|
||||
remote_manager->rename_button(app->get_current_button(), app->get_text_store(0));
|
||||
app->set_current_button(IrdaApp::ButtonNA);
|
||||
} else {
|
||||
remote_manager->rename_remote(app->get_text_store(0));
|
||||
result = remote_manager->rename_remote(app->get_text_store(0));
|
||||
}
|
||||
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::EditRenameDone);
|
||||
}
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::EditRenameDone);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "gui/modules/submenu.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexAddKey,
|
||||
@@ -27,6 +28,8 @@ void IrdaAppSceneEdit::on_enter(IrdaApp* 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);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
submenu_item_selected = 0;
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
@@ -35,8 +38,10 @@ bool IrdaAppSceneEdit::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexAddKey:
|
||||
app->set_learn_new_remote(false);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
case SubmenuIndexRenameKey:
|
||||
|
||||
@@ -35,14 +35,21 @@ bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
if(event->type == IrdaAppEvent::Type::TextEditDone) {
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
auto receiver = app->get_receiver();
|
||||
bool result = false;
|
||||
if(app->get_learn_new_remote()) {
|
||||
remote_manager->add_remote_with_button(
|
||||
result = 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());
|
||||
result =
|
||||
remote_manager->add_button(app->get_text_store(0), receiver->get_last_message());
|
||||
}
|
||||
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnDone);
|
||||
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);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
|
||||
app->notify_green_on();
|
||||
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_message();
|
||||
|
||||
@@ -32,6 +34,7 @@ void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
|
||||
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_center_button_text(dialog_ex, "Send");
|
||||
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);
|
||||
@@ -47,11 +50,20 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
case DialogExResultLeft:
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
case DialogExResultCenter:
|
||||
furi_assert(0);
|
||||
case DialogExResultCenter: {
|
||||
app->notify_space_blink();
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_message();
|
||||
irda_send(message, 1);
|
||||
break;
|
||||
}
|
||||
case DialogExResultRight:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
if(remote_manager->check_fs()) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -60,4 +72,8 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
}
|
||||
|
||||
void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
dialog_ex_set_center_button_text(dialog_ex, nullptr);
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
@@ -14,13 +14,22 @@ void IrdaAppSceneLearn::on_enter(IrdaApp* app) {
|
||||
popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter);
|
||||
popup_set_callback(popup, NULL);
|
||||
|
||||
if(app->get_learn_new_remote()) {
|
||||
app->notify_double_vibro();
|
||||
}
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Popup);
|
||||
}
|
||||
|
||||
bool IrdaAppSceneLearn::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::Tick) {
|
||||
consumed = true;
|
||||
app->notify_red_blink();
|
||||
}
|
||||
if(event->type == IrdaAppEvent::Type::IrdaMessageReceived) {
|
||||
app->notify_success();
|
||||
app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnSuccess);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,26 @@ void IrdaAppSceneRemoteList::on_enter(IrdaApp* app) {
|
||||
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);
|
||||
bool result = remote_manager->get_remote_list(remote_names);
|
||||
if(!result) {
|
||||
app->switch_to_previous_scene();
|
||||
return;
|
||||
}
|
||||
|
||||
for(auto& name : remote_names) {
|
||||
submenu_add_item(submenu, name.c_str(), i++, submenu_callback, app);
|
||||
}
|
||||
submenu_add_item(
|
||||
submenu, " +", SubmenuIndexPlus, submenu_callback, app);
|
||||
|
||||
if((SubmenuIndex)submenu_item_selected == SubmenuIndexPlus) {
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
} else {
|
||||
int remote_index = remote_manager->find_remote_name(remote_names);
|
||||
submenu_set_selected_item(submenu, (remote_index >= 0) ? remote_index : 0);
|
||||
}
|
||||
|
||||
submenu_item_selected = 0;
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
|
||||
@@ -38,11 +51,14 @@ bool IrdaAppSceneRemoteList::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
case SubmenuIndexPlus:
|
||||
app->set_learn_new_remote(true);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
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);
|
||||
bool result = remote_manager->load(remote_names.at(event->payload.menu_index));
|
||||
if(result) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
typedef enum {
|
||||
ButtonIndexPlus = -2,
|
||||
ButtonIndexEdit = -1,
|
||||
ButtonIndexNA = 0,
|
||||
} ButtonIndex;
|
||||
|
||||
static void button_menu_callback(void* context, int32_t index) {
|
||||
@@ -35,8 +36,12 @@ void IrdaAppSceneRemote::on_enter(IrdaApp* 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());
|
||||
app->set_text_store(0, "%s", remote_manager->get_remote_name().c_str());
|
||||
button_menu_set_header(button_menu, app->get_text_store(0));
|
||||
if(buttonmenu_item_selected != ButtonIndexNA) {
|
||||
button_menu_set_selected_item(button_menu, buttonmenu_item_selected);
|
||||
buttonmenu_item_selected = ButtonIndexNA;
|
||||
}
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::ButtonMenu);
|
||||
}
|
||||
|
||||
@@ -46,12 +51,18 @@ bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
switch(event->payload.menu_index) {
|
||||
case ButtonIndexPlus:
|
||||
app->notify_click();
|
||||
buttonmenu_item_selected = event->payload.menu_index;
|
||||
app->set_learn_new_remote(false);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Learn);
|
||||
break;
|
||||
case ButtonIndexEdit:
|
||||
app->notify_click();
|
||||
buttonmenu_item_selected = event->payload.menu_index;
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Edit);
|
||||
break;
|
||||
default:
|
||||
app->notify_click_and_blink();
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
auto message = remote_manager->get_button_data(event->payload.menu_index);
|
||||
app->get_receiver()->send_message(message);
|
||||
|
||||
@@ -25,6 +25,8 @@ void IrdaAppSceneStart::on_enter(IrdaApp* app) {
|
||||
submenu_add_item(
|
||||
submenu, "Learn new remote", SubmenuIndexLearnNewRemote, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Saved remotes", SubmenuIndexSavedRemotes, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
submenu_item_selected = 0;
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
@@ -33,6 +35,7 @@ bool IrdaAppSceneStart::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexUniversalLibrary:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Universal);
|
||||
@@ -44,6 +47,9 @@ bool IrdaAppSceneStart::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
case SubmenuIndexSavedRemotes:
|
||||
app->switch_to_next_scene(IrdaApp::Scene::RemoteList);
|
||||
break;
|
||||
default:
|
||||
furi_assert(0);
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ void IrdaAppSceneUniversal::on_enter(IrdaApp* app) {
|
||||
submenu_add_item(submenu, "Audio Players", SubmenuIndexUniversalAudio, submenu_callback, app);
|
||||
submenu_add_item(
|
||||
submenu, "Air Conditioners", SubmenuIndexUniversalAirConditioner, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
submenu_item_selected = 0;
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu);
|
||||
}
|
||||
@@ -32,6 +34,7 @@ bool IrdaAppSceneUniversal::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::MenuSelected) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexUniversalTV:
|
||||
// app->switch_to_next_scene(IrdaApp::Scene::UniversalTV);
|
||||
|
||||
@@ -23,6 +23,8 @@ public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
|
||||
class IrdaAppSceneUniversal : public IrdaAppScene {
|
||||
@@ -30,6 +32,8 @@ public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
|
||||
class IrdaAppSceneLearn : public IrdaAppScene {
|
||||
@@ -74,6 +78,7 @@ public:
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
std::vector<std::string> buttons_names;
|
||||
uint32_t buttonmenu_item_selected = 0;
|
||||
};
|
||||
|
||||
class IrdaAppSceneRemoteList : public IrdaAppScene {
|
||||
@@ -81,6 +86,8 @@ public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
uint32_t submenu_item_selected = 0;
|
||||
std::vector<std::string> remote_names;
|
||||
};
|
||||
|
||||
@@ -89,6 +96,8 @@ public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
private:
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
|
||||
class IrdaAppSceneEditKeySelect : public IrdaAppScene {
|
||||
|
||||
Reference in New Issue
Block a user