[FL-1489] IRDA: move to FileWorker (#594)
* [FL-1489] IRDA: move to FileWorker, fixes * Use FileWorker * Use file_select to select remotes * Fix some crashes * Add RAW parsing restrictions * Remove excess scene (LearnDoneAfter) * Move all file system logic to standalone object
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
#include "../irda-app.hpp"
|
||||
#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) {
|
||||
}
|
@@ -24,11 +24,7 @@ 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);
|
||||
}
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "irda.h"
|
||||
#include "../irda-app-file-parser.hpp"
|
||||
#include <memory>
|
||||
|
||||
static void dialog_result_callback(DialogExResult result, void* context) {
|
||||
auto app = static_cast<IrdaApp*>(context);
|
||||
@@ -61,15 +63,18 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
signal.transmit();
|
||||
break;
|
||||
}
|
||||
case DialogExResultRight:
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
if(remote_manager->check_fs()) {
|
||||
case DialogExResultRight: {
|
||||
IrdaAppFileParser file_parser;
|
||||
if(file_parser.check_errors()) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
@@ -1,75 +1,30 @@
|
||||
#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);
|
||||
}
|
||||
#include "irda/irda-app-event.hpp"
|
||||
|
||||
void IrdaAppSceneRemoteList::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
IrdaAppFileParser file_parser;
|
||||
bool success = false;
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
int i = 0;
|
||||
auto last_selected_remote = remote_manager->get_remote_name();
|
||||
auto selected_file = file_parser.file_select(
|
||||
last_selected_remote.size() ? last_selected_remote.c_str() : nullptr);
|
||||
if(!selected_file.empty()) {
|
||||
if(remote_manager->load(selected_file)) {
|
||||
app->switch_to_next_scene(IrdaApp::Scene::Remote);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool result = remote_manager->get_remote_list(remote_names);
|
||||
if(!result) {
|
||||
if(!success) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
break;
|
||||
default:
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneRemoteList::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
@@ -61,5 +61,6 @@ void IrdaAppSceneStart::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
app->get_remote_manager()->reset_remote();
|
||||
submenu_clean(submenu);
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ static bool irda_popup_brut_input_callback(InputEvent* event, void* context) {
|
||||
consumed = true;
|
||||
IrdaAppEvent irda_event;
|
||||
|
||||
irda_event.type = IrdaAppEvent::Type::ButtonPanelPopupBackPressed;
|
||||
irda_event.type = IrdaAppEvent::Type::Back;
|
||||
app->get_view_manager()->send_event(&irda_event);
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ void IrdaAppSceneUniversalCommon::progress_popup(IrdaApp* app) {
|
||||
bool IrdaAppSceneUniversalCommon::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::Tick) {
|
||||
if(brute_force_started) {
|
||||
if(brute_force_started) {
|
||||
if(event->type == IrdaAppEvent::Type::Tick) {
|
||||
auto view_manager = app->get_view_manager();
|
||||
IrdaAppEvent tick_event = {.type = IrdaAppEvent::Type::Tick};
|
||||
view_manager->send_event(&tick_event);
|
||||
@@ -70,26 +70,27 @@ bool IrdaAppSceneUniversalCommon::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
brute_force_started = false;
|
||||
remove_popup(app);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == IrdaAppEvent::Type::Back) {
|
||||
brute_force_started = false;
|
||||
brute_force.stop_bruteforce();
|
||||
remove_popup(app);
|
||||
consumed = true;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::ButtonPanelPopupBackPressed) {
|
||||
consumed = true;
|
||||
brute_force_started = false;
|
||||
brute_force.stop_bruteforce();
|
||||
remove_popup(app);
|
||||
} else if(event->type == IrdaAppEvent::Type::ButtonPanelPressed) {
|
||||
int record_amount = 0;
|
||||
if(brute_force.start_bruteforce(event->payload.menu_index, record_amount)) {
|
||||
if(record_amount > 0) {
|
||||
} else {
|
||||
if(event->type == IrdaAppEvent::Type::ButtonPanelPressed) {
|
||||
int record_amount = 0;
|
||||
if(brute_force.start_bruteforce(event->payload.menu_index, record_amount)) {
|
||||
brute_force_started = true;
|
||||
show_popup(app, record_amount);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
} else {
|
||||
consumed = true;
|
||||
} else if(event->type == IrdaAppEvent::Type::Back) {
|
||||
app->switch_to_previous_scene();
|
||||
consumed = true;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
@@ -65,13 +65,6 @@ public:
|
||||
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;
|
||||
@@ -155,14 +148,14 @@ protected:
|
||||
class IrdaAppSceneUniversalTV : public IrdaAppSceneUniversalCommon {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
IrdaAppSceneUniversalTV() : IrdaAppSceneUniversalCommon("/irda/universal/tv.ir") {}
|
||||
IrdaAppSceneUniversalTV() : IrdaAppSceneUniversalCommon("/assets/ext/irda/tv.ir") {}
|
||||
~IrdaAppSceneUniversalTV() {}
|
||||
};
|
||||
|
||||
class IrdaAppSceneUniversalAudio : public IrdaAppSceneUniversalCommon {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
IrdaAppSceneUniversalAudio() : IrdaAppSceneUniversalCommon("/irda/universal/audio.ir") {}
|
||||
IrdaAppSceneUniversalAudio() : IrdaAppSceneUniversalCommon("/assets/ext/irda/audio.ir") {}
|
||||
~IrdaAppSceneUniversalAudio() {}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user