Skip to content

Commit

Permalink
Format some missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
andreock committed Sep 13, 2024
1 parent 06d393e commit 00ff48c
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 217 deletions.
163 changes: 84 additions & 79 deletions lib/UI/navigation/IR/IRNavigation.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

#include "../../../../include/pins.h"
#include "../navigation.hpp"
#include "ArduinoJson.h"
#include "fm.hpp"
#include "gui.hpp"
#include "../../../../include/pins.h"
#include "pages/IR/IRMainPage.hpp"
#include "pages/FileBrowser/FileBrowserPage.hpp"
#include "pages/IR/IREmulateRC.hpp"
#include "pages/IR/IRRecordSignalPage.hpp"
#include "pages/IR/IRListsProgress.hpp"
#include "pages/FileBrowser/FileBrowserPage.hpp"
#include "../navigation.hpp"
#include "pages/IR/IRMainPage.hpp"
#include "pages/IR/IRRecordSignalPage.hpp"
#include "ir_attacks.hpp"
#include "ArduinoJson.h"
#include "posixsd.hpp"
#include "sdcard_helper.hpp"

Expand All @@ -23,47 +23,47 @@ static IRListsProgress *ir_list_progress = nullptr;
static FileBrowserPage *file_browser_page = nullptr;

void goto_ir_gui() {
gui->reset();
ir_main_page = new IRMainPage(3, 0, 1, gui->get_screen(), gui);
gui->set_current_page(ir_main_page);
gui->reset();
ir_main_page = new IRMainPage(3, 0, 1, gui->get_screen(), gui);
gui->set_current_page(ir_main_page);
}

void ir_goto_home() {
init_main_gui();
ir_main_page = nullptr;
delete ir_framework;
ir_framework = nullptr;
init_main_gui();
ir_main_page = nullptr;
delete ir_framework;
ir_framework = nullptr;
}

void goto_ir_record_signal_page() {
gui->reset();
ir_record_signal_page = new IRRecordSignalPage(1, 1, 0, gui->get_screen(), gui);
gui->set_current_page(ir_record_signal_page);
ir_record_signal(ir_record_signal_page, ir_framework);
gui->reset();
ir_record_signal_page =
new IRRecordSignalPage(1, 1, 0, gui->get_screen(), gui);
gui->set_current_page(ir_record_signal_page);
ir_record_signal(ir_record_signal_page, ir_framework);
}

void save_record_to_sd() {
Serial.println("Saving to SD");
RecordedSignal signal = ir_framework->get_decoded_signal();
JsonDocument doc;
doc["protocol"] = signal.protocol;
doc["address"] = signal.address;
doc["command"] = signal.command;
doc["number_of_bits"] = signal.numberOfBits;
doc["extra"] = signal.extra;
doc["decoded_raw_data"] = signal.decodedRawData;
doc["raw_len"] = signal.raw_len;
doc["flags"] = signal.flags;
JsonArray raw_data = doc["raw_data"].to<JsonArray>();
for (size_t i = 0; i < signal.raw_len; i++)
{
raw_data.add(signal.decodedRawDataArray[i]);
}
doc.shrinkToFit();
File res = open("/IR/signals/" + (String)millis() + ".json", "w");
serializeJsonPretty(doc, res);
res.close();
goto_ir_gui();
Serial.println("Saving to SD");
RecordedSignal signal = ir_framework->get_decoded_signal();
JsonDocument doc;
doc["protocol"] = signal.protocol;
doc["address"] = signal.address;
doc["command"] = signal.command;
doc["number_of_bits"] = signal.numberOfBits;
doc["extra"] = signal.extra;
doc["decoded_raw_data"] = signal.decodedRawData;
doc["raw_len"] = signal.raw_len;
doc["flags"] = signal.flags;
JsonArray raw_data = doc["raw_data"].to<JsonArray>();
for (size_t i = 0; i < signal.raw_len; i++) {
raw_data.add(signal.decodedRawDataArray[i]);
}
doc.shrinkToFit();
File res = open("/IR/signals/" + (String)millis() + ".json", "w");
serializeJsonPretty(doc, res);
res.close();
goto_ir_gui();
}

#include <list>
Expand All @@ -72,69 +72,74 @@ static std::list<string> ir_signal_files;
static TaskHandle_t list_sender_task_handle;

void send_signal(const char *path) {
File rc_file = open("/IR/signals/" + (String)path, "r");
JsonDocument *signal = new JsonDocument();
deserializeJson(*signal, rc_file);
if(signal->is<JsonArray>()) {
gui->reset();
ir_list_progress = new IRListsProgress(1, 1, 0, gui->get_screen(), gui);
gui->set_current_page(ir_list_progress, true, false);
}
ir_send_signal(ir_framework, signal, ir_list_progress, &list_sender_task_handle);
File rc_file = open("/IR/signals/" + (String)path, "r");
JsonDocument *signal = new JsonDocument();
deserializeJson(*signal, rc_file);
if (signal->is<JsonArray>()) {
gui->reset();
ir_list_progress = new IRListsProgress(1, 1, 0, gui->get_screen(), gui);
gui->set_current_page(ir_list_progress, true, false);
}
ir_send_signal(ir_framework, signal, ir_list_progress,
&list_sender_task_handle);
}

void stop_list_sender() {
vTaskDelete(list_sender_task_handle);
gui->reset();
gui->set_current_page(file_browser_page, true, false);
vTaskDelete(list_sender_task_handle);
gui->reset();
gui->set_current_page(file_browser_page, true, false);
}

static std::list<string> ir_rc_files;
JsonDocument rc_signals;

void goto_ir_rc_emulator(const char *path) {
gui->reset();
File rc_file = open("/IR/signal_rc/" + (String)path, "r");
deserializeJson(rc_signals, rc_file);
const char* cmds[rc_signals.size()];
for (size_t i = 0; i < rc_signals.size(); i++)
{
cmds[i] = rc_signals[i]["name"].as<const char*>();
}
ir_emulate_rc = new IREmulateRC(rc_signals.size(), 0,1, gui->get_screen(), gui);
ir_emulate_rc->display(cmds, rc_signals.size());
gui->set_current_page(ir_emulate_rc, false);
gui->reset();
File rc_file = open("/IR/signal_rc/" + (String)path, "r");
deserializeJson(rc_signals, rc_file);
const char *cmds[rc_signals.size()];
for (size_t i = 0; i < rc_signals.size(); i++) {
cmds[i] = rc_signals[i]["name"].as<const char *>();
}
ir_emulate_rc =
new IREmulateRC(rc_signals.size(), 0, 1, gui->get_screen(), gui);
ir_emulate_rc->display(cmds, rc_signals.size());
gui->set_current_page(ir_emulate_rc, false);
}

void goto_ir_rc_browser() {
gui->reset();
ir_rc_files = list_dir(open("/IR/signal_rc", "r"));
file_browser_page = new FileBrowserPage(ir_rc_files.size() + 1, 1, 1 , gui->get_screen(), gui);
file_browser_page->display("IR RC Emulator", &ir_rc_files, goto_ir_rc_emulator, goto_ir_gui);
gui->set_current_page(file_browser_page, false);
gui->reset();
ir_rc_files = list_dir(open("/IR/signal_rc", "r"));
file_browser_page =
new FileBrowserPage(ir_rc_files.size() + 1, 1, 1, gui->get_screen(), gui);
file_browser_page->display("IR RC Emulator", &ir_rc_files,
goto_ir_rc_emulator, goto_ir_gui);
gui->set_current_page(file_browser_page, false);
}

void emulate_ir_rc() {
size_t current_signal_index = ir_emulate_rc->get_current_element();
JsonDocument current_signal = rc_signals[current_signal_index];
ir_send_signal(ir_framework, &current_signal);
size_t current_signal_index = ir_emulate_rc->get_current_element();
JsonDocument current_signal = rc_signals[current_signal_index];
ir_send_signal(ir_framework, &current_signal);
}

void go_back_to_ir_browser() {
gui->reset();
gui->set_current_page(file_browser_page, true, false);
gui->reset();
gui->set_current_page(file_browser_page, true, false);
}

void goto_ir_send() {
gui->reset();
ir_signal_files = list_dir(open("/IR/signals", "r"));
file_browser_page = new FileBrowserPage(ir_signal_files.size() + 1, 1, 1,gui->get_screen(), gui);
file_browser_page->display("IR File Browser", &ir_signal_files, send_signal, goto_ir_gui);
gui->set_current_page(file_browser_page, false);
gui->reset();
ir_signal_files = list_dir(open("/IR/signals", "r"));
file_browser_page = new FileBrowserPage(ir_signal_files.size() + 1, 1, 1,
gui->get_screen(), gui);
file_browser_page->display("IR File Browser", &ir_signal_files, send_signal,
goto_ir_gui);
gui->set_current_page(file_browser_page, false);
}

void init_ir_navigation(Gui *_gui) {
gui = _gui;
ir_framework = new IrFramework(IR_RECEIVER_PIN, IR_EMITTER_PIN);
// TODO: Delete std::list
gui = _gui;
ir_framework = new IrFramework(IR_RECEIVER_PIN, IR_EMITTER_PIN);
// TODO: Delete std::list
}
Loading

0 comments on commit 00ff48c

Please sign in to comment.