flipperzero-firmware/applications/irda/irda-app.cpp
Albert Kharisov 31c31db479
[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>
2021-06-02 18:16:05 +03:00

157 lines
3.7 KiB
C++

#include "irda-app.hpp"
#include <furi.h>
#include <gui/gui.h>
#include <input/input.h>
#include <stdarg.h>
#include <stdio.h>
#include <callback-connector.h>
void IrdaApp::run(void) {
IrdaAppEvent event;
bool consumed;
bool exit = false;
scenes[current_scene]->on_enter(this);
while(!exit) {
view_manager.receive_event(&event);
consumed = scenes[current_scene]->on_event(this, &event);
if(!consumed) {
if(event.type == IrdaAppEvent::Type::Back) {
exit = switch_to_previous_scene();
}
}
};
scenes[current_scene]->on_exit(this);
};
IrdaAppViewManager* IrdaApp::get_view_manager() {
return &view_manager;
}
void IrdaApp::set_learn_new_remote(bool value) {
learn_new_remote = value;
}
bool IrdaApp::get_learn_new_remote() {
return learn_new_remote;
}
void IrdaApp::switch_to_next_scene(Scene next_scene) {
previous_scenes_list.push_front(current_scene);
switch_to_next_scene_without_saving(next_scene);
}
void IrdaApp::switch_to_next_scene_without_saving(Scene next_scene) {
if(next_scene != Scene::Exit) {
scenes[current_scene]->on_exit(this);
current_scene = next_scene;
scenes[current_scene]->on_enter(this);
}
}
void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list<Scene>& scenes_list) {
Scene previous_scene = Scene::Start;
bool scene_found = false;
while(!scene_found) {
previous_scene = get_previous_scene();
for(Scene element : scenes_list) {
if(previous_scene == element) {
scene_found = true;
break;
}
}
}
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) {
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);
return false;
}
IrdaApp::Scene IrdaApp::get_previous_scene() {
Scene scene = Scene::Exit;
if(!previous_scenes_list.empty()) {
scene = previous_scenes_list.front();
previous_scenes_list.pop_front();
}
return scene;
}
IrdaAppRemoteManager* IrdaApp::get_remote_manager() {
return &remote_manager;
}
IrdaAppSignalReceiver* IrdaApp::get_receiver() {
return &receiver;
}
void IrdaApp::set_text_store(uint8_t index, const char* text...) {
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);
}
char* IrdaApp::get_text_store(uint8_t index) {
furi_check(index < text_store_max);
return text_store[index];
}
uint8_t IrdaApp::get_text_store_size() {
return text_store_size;
}
void IrdaApp::text_input_callback(void* context, char* text) {
IrdaApp* app = static_cast<IrdaApp*>(context);
IrdaAppEvent event;
event.type = IrdaAppEvent::Type::TextEditDone;
app->get_view_manager()->send_event(&event);
}
void IrdaApp::popup_callback(void* context) {
IrdaApp* app = static_cast<IrdaApp*>(context);
IrdaAppEvent event;
event.type = IrdaAppEvent::Type::PopupTimer;
app->get_view_manager()->send_event(&event);
}
void IrdaApp::set_edit_element(IrdaApp::EditElement value) {
element = value;
}
IrdaApp::EditElement IrdaApp::get_edit_element(void) {
return element;
}
void IrdaApp::set_edit_action(IrdaApp::EditAction value) {
action = value;
}
IrdaApp::EditAction IrdaApp::get_edit_action(void) {
return action;
}