mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-27 06:50:21 +00:00
[FL-1470] Support archive for IRDA (#582)
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
13c5a8cb20
commit
30ae16c2e1
6 changed files with 62 additions and 22 deletions
|
@ -6,6 +6,7 @@ class IrdaAppEvent {
|
|||
public:
|
||||
enum class Type : uint8_t {
|
||||
Tick,
|
||||
Exit,
|
||||
Back,
|
||||
MenuSelected,
|
||||
DialogExSelected,
|
||||
|
|
|
@ -53,10 +53,6 @@ bool IrdaAppRemoteManager::add_remote_with_button(
|
|||
return add_button(button_name, signal);
|
||||
}
|
||||
|
||||
IrdaAppRemote::IrdaAppRemote(const std::string& name)
|
||||
: name(name) {
|
||||
}
|
||||
|
||||
std::vector<std::string> IrdaAppRemoteManager::get_button_list(void) const {
|
||||
std::vector<std::string> name_vector;
|
||||
name_vector.reserve(remote->buttons.size());
|
||||
|
@ -77,15 +73,22 @@ const IrdaAppSignal& IrdaAppRemoteManager::get_button_data(size_t index) const {
|
|||
return buttons.at(index).signal;
|
||||
}
|
||||
|
||||
std::string IrdaAppRemoteManager::make_filename(const std::string& name) const {
|
||||
return std::string("/") + irda_directory + "/" + name + irda_extension;
|
||||
std::string IrdaAppRemoteManager::make_full_name(const std::string& remote_name) const {
|
||||
return std::string("/") + irda_directory + "/" + remote_name + irda_extension;
|
||||
}
|
||||
|
||||
std::string IrdaAppRemoteManager::make_remote_name(const std::string& full_name) const {
|
||||
std::string str(full_name, full_name.find_last_of('/') + 1, full_name.size());
|
||||
str.erase(str.find_last_of('.'));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
bool IrdaAppRemoteManager::delete_remote() {
|
||||
FS_Error fs_res;
|
||||
IrdaAppFileParser file_parser;
|
||||
|
||||
fs_res = file_parser.get_fs_api().common.remove(make_filename(remote->name).c_str());
|
||||
fs_res = file_parser.get_fs_api().common.remove(make_full_name(remote->name).c_str());
|
||||
if(fs_res != FSE_OK) {
|
||||
file_parser.get_sd_api().show_error(
|
||||
file_parser.get_sd_api().context, "Error deleting file");
|
||||
|
@ -140,7 +143,7 @@ bool IrdaAppRemoteManager::rename_remote(const char* str) {
|
|||
auto new_name = find_vacant_name(remote_list, str);
|
||||
IrdaAppFileParser file_parser;
|
||||
FS_Error fs_err = file_parser.get_fs_api().common.rename(
|
||||
make_filename(remote->name).c_str(), make_filename(new_name).c_str());
|
||||
make_full_name(remote->name).c_str(), make_full_name(new_name).c_str());
|
||||
remote->name = new_name;
|
||||
if(fs_err != FSE_OK) {
|
||||
file_parser.get_sd_api().show_error(
|
||||
|
@ -176,7 +179,7 @@ bool IrdaAppRemoteManager::store(void) {
|
|||
}
|
||||
|
||||
bool res = file_parser.get_fs_api().file.open(
|
||||
&file, make_filename(remote->name).c_str(), FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
||||
&file, make_full_name(remote->name).c_str(), FSAM_WRITE, FSOM_CREATE_ALWAYS);
|
||||
|
||||
if(!res) {
|
||||
file_parser.get_sd_api().show_error(
|
||||
|
@ -233,20 +236,30 @@ bool IrdaAppRemoteManager::get_remote_list(std::vector<std::string>& remote_name
|
|||
return true;
|
||||
}
|
||||
|
||||
bool IrdaAppRemoteManager::load(const std::string& name) {
|
||||
bool IrdaAppRemoteManager::load(const std::string& name_arg, bool fullpath) {
|
||||
bool fs_res = false;
|
||||
IrdaAppFileParser file_parser;
|
||||
File file;
|
||||
std::string full_filename;
|
||||
std::string remote_name;
|
||||
|
||||
if(fullpath) {
|
||||
full_filename = name_arg;
|
||||
remote_name = make_remote_name(name_arg);
|
||||
} else {
|
||||
full_filename = make_full_name(name_arg);
|
||||
remote_name = name_arg;
|
||||
}
|
||||
|
||||
fs_res = file_parser.get_fs_api().file.open(
|
||||
&file, make_filename(name).c_str(), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
&file, full_filename.c_str(), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
if(!fs_res) {
|
||||
file_parser.get_sd_api().show_error(
|
||||
file_parser.get_sd_api().context, "Error opening file");
|
||||
return false;
|
||||
}
|
||||
|
||||
remote = std::make_unique<IrdaAppRemote>(name);
|
||||
remote = std::make_unique<IrdaAppRemote>(remote_name);
|
||||
|
||||
while(1) {
|
||||
auto file_signal = file_parser.read_signal(&file);
|
||||
|
|
|
@ -25,7 +25,8 @@ class IrdaAppRemote {
|
|||
std::vector<IrdaAppRemoteButton> buttons;
|
||||
std::string name;
|
||||
public:
|
||||
IrdaAppRemote(const std::string& name);
|
||||
IrdaAppRemote(const std::string& name) : name(name) {}
|
||||
|
||||
IrdaAppRemote& operator=(std::string& new_name) noexcept
|
||||
{
|
||||
name = new_name;
|
||||
|
@ -38,7 +39,8 @@ class IrdaAppRemoteManager {
|
|||
static const char* irda_directory;
|
||||
static const char* irda_extension;
|
||||
std::unique_ptr<IrdaAppRemote> remote;
|
||||
std::string make_filename(const std::string& name) const;
|
||||
std::string make_full_name(const std::string& remote_name) const;
|
||||
std::string make_remote_name(const std::string& full_name) const;
|
||||
|
||||
public:
|
||||
bool add_remote_with_button(const char* button_name, const IrdaAppSignal& signal);
|
||||
|
@ -58,7 +60,7 @@ public:
|
|||
bool delete_remote();
|
||||
|
||||
bool store();
|
||||
bool load(const std::string& name);
|
||||
bool load(const std::string& name, bool fullpath = false);
|
||||
bool check_fs() const;
|
||||
};
|
||||
|
||||
|
|
|
@ -6,16 +6,29 @@
|
|||
#include <stdio.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
void IrdaApp::run(void) {
|
||||
int32_t IrdaApp::run(void* args) {
|
||||
IrdaAppEvent event;
|
||||
bool consumed;
|
||||
bool exit = false;
|
||||
|
||||
if(args) {
|
||||
const char* remote_name = static_cast<const char*>(args);
|
||||
bool result = remote_manager.load(std::string(remote_name), true);
|
||||
if(result) {
|
||||
current_scene = IrdaApp::Scene::Remote;
|
||||
} else {
|
||||
printf("Failed to load remote \'%s\'\r\n", remote_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
scenes[current_scene]->on_enter(this);
|
||||
|
||||
while(!exit) {
|
||||
view_manager.receive_event(&event);
|
||||
|
||||
if(event.type == IrdaAppEvent::Type::Exit) break;
|
||||
|
||||
consumed = scenes[current_scene]->on_event(this, &event);
|
||||
|
||||
if(!consumed) {
|
||||
|
@ -26,6 +39,8 @@ void IrdaApp::run(void) {
|
|||
};
|
||||
|
||||
scenes[current_scene]->on_exit(this);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
IrdaAppViewManager* IrdaApp::get_view_manager() {
|
||||
|
@ -59,6 +74,9 @@ void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list<Sc
|
|||
|
||||
while(!scene_found) {
|
||||
previous_scene = get_previous_scene();
|
||||
|
||||
if(previous_scene == Scene::Exit) break;
|
||||
|
||||
for(Scene element : scenes_list) {
|
||||
if(previous_scene == element) {
|
||||
scene_found = true;
|
||||
|
@ -67,9 +85,15 @@ void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list<Sc
|
|||
}
|
||||
}
|
||||
|
||||
scenes[current_scene]->on_exit(this);
|
||||
current_scene = previous_scene;
|
||||
scenes[current_scene]->on_enter(this);
|
||||
if(previous_scene == Scene::Exit) {
|
||||
IrdaAppEvent event;
|
||||
event.type = IrdaAppEvent::Type::Exit;
|
||||
view_manager.send_event(&event);
|
||||
} else {
|
||||
scenes[current_scene]->on_exit(this);
|
||||
current_scene = previous_scene;
|
||||
scenes[current_scene]->on_enter(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool IrdaApp::switch_to_previous_scene(uint8_t count) {
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
EditDeleteDone,
|
||||
};
|
||||
|
||||
void run(void);
|
||||
int32_t run(void* args);
|
||||
void switch_to_next_scene(Scene index);
|
||||
void switch_to_next_scene_without_saving(Scene index);
|
||||
bool switch_to_previous_scene(uint8_t count = 1);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
extern "C" int32_t irda(void* p) {
|
||||
IrdaApp* app = new IrdaApp();
|
||||
app->run();
|
||||
int32_t result = app->run(p);
|
||||
delete app;
|
||||
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue