2022-02-25 15:22:58 +00:00
|
|
|
#include "infrared_app.h"
|
|
|
|
#include <infrared_worker.h>
|
2021-06-02 15:16:05 +00:00
|
|
|
#include <furi.h>
|
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <input/input.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <callback-connector.h>
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
int32_t InfraredApp::run(void* args) {
|
|
|
|
InfraredAppEvent event;
|
2021-06-02 15:16:05 +00:00
|
|
|
bool consumed;
|
|
|
|
bool exit = false;
|
|
|
|
|
2021-07-16 16:50:18 +00:00
|
|
|
if(args) {
|
2022-05-27 14:14:43 +00:00
|
|
|
std::string path = static_cast<const char*>(args);
|
|
|
|
std::string remote_name(path, path.find_last_of('/') + 1, path.size());
|
|
|
|
auto last_dot = remote_name.find_last_of('.');
|
|
|
|
if(last_dot != std::string::npos) {
|
|
|
|
remote_name.erase(last_dot);
|
|
|
|
path.erase(path.find_last_of('/'));
|
|
|
|
bool result = remote_manager.load(path, remote_name);
|
2022-04-23 01:56:59 +00:00
|
|
|
if(result) {
|
|
|
|
current_scene = InfraredApp::Scene::Remote;
|
|
|
|
} else {
|
2022-05-27 14:14:43 +00:00
|
|
|
printf("Failed to load remote \'%s\'\r\n", remote_name.c_str());
|
2022-04-23 01:56:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-07-16 16:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
scenes[current_scene]->on_enter(this);
|
|
|
|
|
|
|
|
while(!exit) {
|
|
|
|
view_manager.receive_event(&event);
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
if(event.type == InfraredAppEvent::Type::Exit) break;
|
2021-07-16 16:50:18 +00:00
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
consumed = scenes[current_scene]->on_event(this, &event);
|
|
|
|
|
|
|
|
if(!consumed) {
|
2022-02-25 15:22:58 +00:00
|
|
|
if(event.type == InfraredAppEvent::Type::Back) {
|
2021-06-02 15:16:05 +00:00
|
|
|
exit = switch_to_previous_scene();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
scenes[current_scene]->on_exit(this);
|
2021-07-16 16:50:18 +00:00
|
|
|
|
|
|
|
return 0;
|
2021-06-02 15:16:05 +00:00
|
|
|
};
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp::InfraredApp() {
|
|
|
|
furi_check(InfraredAppRemoteManager::max_button_name_length < get_text_store_size());
|
2021-08-19 00:18:42 +00:00
|
|
|
notification = static_cast<NotificationApp*>(furi_record_open("notification"));
|
2022-04-21 15:36:53 +00:00
|
|
|
dialogs = static_cast<DialogsApp*>(furi_record_open("dialogs"));
|
2022-02-25 15:22:58 +00:00
|
|
|
infrared_worker = infrared_worker_alloc();
|
2021-08-19 00:18:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp::~InfraredApp() {
|
|
|
|
infrared_worker_free(infrared_worker);
|
2021-08-19 00:18:42 +00:00
|
|
|
furi_record_close("notification");
|
2022-04-21 15:36:53 +00:00
|
|
|
furi_record_close("dialogs");
|
2021-08-19 00:18:42 +00:00
|
|
|
for(auto& [key, scene] : scenes) delete scene;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppViewManager* InfraredApp::get_view_manager() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return &view_manager;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::set_learn_new_remote(bool value) {
|
2021-06-02 15:16:05 +00:00
|
|
|
learn_new_remote = value;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredApp::get_learn_new_remote() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return learn_new_remote;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::switch_to_next_scene(Scene next_scene) {
|
2021-06-02 15:16:05 +00:00
|
|
|
previous_scenes_list.push_front(current_scene);
|
|
|
|
switch_to_next_scene_without_saving(next_scene);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::switch_to_next_scene_without_saving(Scene next_scene) {
|
2021-06-02 15:16:05 +00:00
|
|
|
if(next_scene != Scene::Exit) {
|
|
|
|
scenes[current_scene]->on_exit(this);
|
|
|
|
current_scene = next_scene;
|
|
|
|
scenes[current_scene]->on_enter(this);
|
2021-07-22 00:07:00 +00:00
|
|
|
view_manager.clear_events();
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::search_and_switch_to_previous_scene(
|
|
|
|
const std::initializer_list<Scene>& scenes_list) {
|
2021-06-02 15:16:05 +00:00
|
|
|
Scene previous_scene = Scene::Start;
|
|
|
|
bool scene_found = false;
|
|
|
|
|
|
|
|
while(!scene_found) {
|
|
|
|
previous_scene = get_previous_scene();
|
2021-07-16 16:50:18 +00:00
|
|
|
|
|
|
|
if(previous_scene == Scene::Exit) break;
|
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
for(Scene element : scenes_list) {
|
|
|
|
if(previous_scene == element) {
|
|
|
|
scene_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 16:50:18 +00:00
|
|
|
if(previous_scene == Scene::Exit) {
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppEvent event;
|
|
|
|
event.type = InfraredAppEvent::Type::Exit;
|
2021-07-16 16:50:18 +00:00
|
|
|
view_manager.send_event(&event);
|
|
|
|
} else {
|
|
|
|
scenes[current_scene]->on_exit(this);
|
|
|
|
current_scene = previous_scene;
|
|
|
|
scenes[current_scene]->on_enter(this);
|
2021-07-22 00:07:00 +00:00
|
|
|
view_manager.clear_events();
|
2021-07-16 16:50:18 +00:00
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredApp::switch_to_previous_scene(uint8_t count) {
|
2021-06-02 15:16:05 +00:00
|
|
|
Scene previous_scene = Scene::Start;
|
|
|
|
|
|
|
|
for(uint8_t i = 0; i < count; i++) previous_scene = get_previous_scene();
|
|
|
|
|
|
|
|
if(previous_scene == Scene::Exit) return true;
|
|
|
|
|
|
|
|
scenes[current_scene]->on_exit(this);
|
|
|
|
current_scene = previous_scene;
|
|
|
|
scenes[current_scene]->on_enter(this);
|
2021-07-22 00:07:00 +00:00
|
|
|
view_manager.clear_events();
|
2021-06-02 15:16:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp::Scene InfraredApp::get_previous_scene() {
|
2021-06-02 15:16:05 +00:00
|
|
|
Scene scene = Scene::Exit;
|
|
|
|
|
|
|
|
if(!previous_scenes_list.empty()) {
|
|
|
|
scene = previous_scenes_list.front();
|
|
|
|
previous_scenes_list.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppRemoteManager* InfraredApp::get_remote_manager() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return &remote_manager;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::set_text_store(uint8_t index, const char* text...) {
|
2021-06-02 15:16:05 +00:00
|
|
|
furi_check(index < text_store_max);
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, text);
|
|
|
|
|
|
|
|
vsnprintf(text_store[index], text_store_size, text, args);
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
char* InfraredApp::get_text_store(uint8_t index) {
|
2021-06-02 15:16:05 +00:00
|
|
|
furi_check(index < text_store_max);
|
|
|
|
|
|
|
|
return text_store[index];
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
uint8_t InfraredApp::get_text_store_size() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return text_store_size;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::text_input_callback(void* context) {
|
|
|
|
InfraredApp* app = static_cast<InfraredApp*>(context);
|
|
|
|
InfraredAppEvent event;
|
|
|
|
event.type = InfraredAppEvent::Type::TextEditDone;
|
2021-06-02 15:16:05 +00:00
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::popup_callback(void* context) {
|
|
|
|
InfraredApp* app = static_cast<InfraredApp*>(context);
|
|
|
|
InfraredAppEvent event;
|
|
|
|
event.type = InfraredAppEvent::Type::PopupTimer;
|
2021-06-02 15:16:05 +00:00
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::set_edit_element(InfraredApp::EditElement value) {
|
2021-06-02 15:16:05 +00:00
|
|
|
element = value;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp::EditElement InfraredApp::get_edit_element(void) {
|
2021-06-02 15:16:05 +00:00
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::set_edit_action(InfraredApp::EditAction value) {
|
2021-06-02 15:16:05 +00:00
|
|
|
action = value;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp::EditAction InfraredApp::get_edit_action(void) {
|
2021-06-02 15:16:05 +00:00
|
|
|
return action;
|
|
|
|
}
|
2021-06-09 13:04:49 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::set_current_button(int value) {
|
2021-06-09 13:04:49 +00:00
|
|
|
current_button = value;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
int InfraredApp::get_current_button() {
|
2021-06-09 13:04:49 +00:00
|
|
|
return current_button;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::notify_success() {
|
2021-06-09 13:04:49 +00:00
|
|
|
notification_message(notification, &sequence_success);
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:20:59 +00:00
|
|
|
void InfraredApp::notify_blink_read() {
|
|
|
|
notification_message(notification, &sequence_blink_cyan_10);
|
2021-06-09 13:04:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 17:20:59 +00:00
|
|
|
void InfraredApp::notify_blink_send() {
|
|
|
|
notification_message(notification, &sequence_blink_magenta_10);
|
2021-08-11 17:51:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 15:36:53 +00:00
|
|
|
DialogsApp* InfraredApp::get_dialogs() {
|
|
|
|
return dialogs;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::notify_green_on() {
|
2021-06-09 13:04:49 +00:00
|
|
|
notification_message(notification, &sequence_set_only_green_255);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::notify_green_off() {
|
2021-06-09 13:04:49 +00:00
|
|
|
notification_message(notification, &sequence_reset_green);
|
|
|
|
}
|
2021-07-16 16:43:54 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredWorker* InfraredApp::get_infrared_worker() {
|
|
|
|
return infrared_worker;
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
const InfraredAppSignal& InfraredApp::get_received_signal() const {
|
2021-07-16 16:43:54 +00:00
|
|
|
return received_signal;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::set_received_signal(const InfraredAppSignal& signal) {
|
2021-07-16 16:43:54 +00:00
|
|
|
received_signal = signal;
|
|
|
|
}
|
2022-02-18 20:16:22 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredApp::signal_sent_callback(void* context) {
|
|
|
|
InfraredApp* app = static_cast<InfraredApp*>(context);
|
2022-04-28 17:20:59 +00:00
|
|
|
app->notify_blink_send();
|
2022-02-18 20:16:22 +00:00
|
|
|
}
|