-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
545 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
|
||
#include "fm.hpp" | ||
#include "gui.hpp" | ||
#include "../../../../include/pins.h" | ||
#include "pages/IR/IRMainPage.hpp" | ||
#include "pages/IR/IREmulateRC.hpp" | ||
#include "pages/IR/IRRecordSignalPage.hpp" | ||
#include "pages/FileBrowser/FileBrowserPage.hpp" | ||
#include "../navigation.hpp" | ||
#include "ir_attacks.hpp" | ||
#include "ArduinoJson.h" | ||
#include "posixsd.hpp" | ||
#include "sdcard_helper.hpp" | ||
|
||
static Gui *gui; | ||
|
||
static IRMainPage *ir_main_page = nullptr; | ||
IRRecordSignalPage *ir_record_signal_page = nullptr; | ||
static IREmulateRC *ir_emulate_rc = nullptr; | ||
static IrFramework *ir_framework = 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); | ||
} | ||
|
||
void ir_goto_home() { | ||
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); | ||
} | ||
|
||
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(); | ||
} | ||
|
||
#include <list> | ||
|
||
static std::list<string> ir_signal_files; | ||
void send_signal(const char *path) { | ||
ir_send_signal(ir_framework, ("/IR/signals/" + (String)path).c_str()); | ||
} | ||
|
||
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); | ||
} | ||
|
||
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); | ||
} | ||
|
||
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); | ||
} | ||
|
||
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); | ||
} | ||
|
||
void init_ir_navigation(Gui *_gui) { | ||
gui = _gui; | ||
ir_framework = new IrFramework(IR_RECEIVER_PIN, IR_EMITTER_PIN); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "gui.hpp" | ||
|
||
void goto_ir_gui(); | ||
void ir_goto_home(); | ||
void goto_lg_ac_gui(); | ||
void lg_ac_controller_go_back(); | ||
void init_ir_navigation(Gui *_gui); | ||
void goto_ir_record_signal_page(); | ||
void save_record_to_sd(); | ||
void goto_ir_send(); | ||
void goto_ir_rc_browser(); | ||
void emulate_ir_rc(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,7 @@ void init_subghz_ui(); | |
|
||
void init_nfc_ui(); | ||
|
||
void init_ir_ui(); | ||
|
||
void init_network_attacks_ui(); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "IREmulateRC.hpp" | ||
#include "style.h" | ||
#include "../../navigation/IR/IRNavigation.hpp" | ||
|
||
void IREmulateRC::display(const char* cmd[], size_t count) | ||
{ | ||
grid = new Grid(screen, 2, 4); | ||
for (size_t i = 0; i < count; i++) | ||
{ | ||
grid->add(new RectText(screen, cmd[i], HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT, | ||
HOME_ICON_RADIUS, HOME_ICON_COLOR, emulate_ir_rc)); | ||
} | ||
go_back = new List(screen, "Go back", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_gui); | ||
grid->add(go_back); | ||
grid->set_pos(0, 10); | ||
grid->set_space_between(10); | ||
grid->set_padding(0, 20); | ||
grid->display(); | ||
grid->set_selected(0, true); | ||
} | ||
|
||
void IREmulateRC::right() { | ||
if(position_limit <= 4) | ||
return; | ||
if (current_position >= 0 && current_position < position_limit) { | ||
grid->set_selected(current_position, false); | ||
current_position++; | ||
} | ||
grid->set_selected(current_position, true); | ||
} | ||
|
||
void IREmulateRC::left() { | ||
if(position_limit <= 4) | ||
return; | ||
if (current_position > 0 && current_position <= position_limit) { | ||
grid->set_selected(current_position, false); | ||
current_position--; | ||
} | ||
grid->set_selected(current_position, true); | ||
} | ||
|
||
void IREmulateRC::display() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
/* | ||
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or | ||
* https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "../Page.hpp" | ||
#include "Grid.hpp" | ||
#include "List.hpp" | ||
#include "widgets/RectText.hpp" | ||
|
||
#ifndef IR_EMULATE_RC_PAGE_H | ||
#define IR_EMULATE_RC_PAGE_H | ||
|
||
class IREmulateRC : public Page { | ||
private: | ||
List *go_back; | ||
|
||
public: | ||
IREmulateRC(uint8_t _position_limit, uint8_t _lower_limit, | ||
uint8_t _position_increment, GFXForms *screen, Gui *_gui) : Page(_position_limit, _lower_limit, _position_increment, screen, _gui) {}; | ||
~IREmulateRC() {}; | ||
void display(const char* cmd[], size_t count); | ||
void display(); | ||
void set_selected(int pos, bool status) { | ||
grid->set_selected(pos, status); | ||
}; | ||
void click(int pos, void callback()) { grid->click(pos, callback); }; | ||
void left(); | ||
void right(); | ||
size_t get_current_element() { return grid->get_selected(); }; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
/* | ||
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or | ||
* https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "IRMainPage.hpp" | ||
|
||
#include "../../i18n.hpp" | ||
#include "../../navigation/IR/IRNavigation.hpp" | ||
#include "gui.hpp" | ||
|
||
IRMainPage::~IRMainPage() {} | ||
|
||
void mock() { | ||
|
||
} | ||
|
||
void IRMainPage::display() { | ||
grid = new Grid(screen, 4, 1); | ||
record_signal = new List(screen, "Record signal", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_record_signal_page); | ||
emulate_signal = new List(screen, "Emulate signal", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_send); | ||
emulate_rc = new List(screen, "Emulate RC", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_rc_browser); | ||
go_back = new List(screen, "Go back", 2, ST77XX_WHITE, 20, ST77XX_BLACK, ir_goto_home); | ||
|
||
grid->add(record_signal); | ||
grid->add(emulate_signal); | ||
grid->add(emulate_rc); | ||
grid->add(go_back); | ||
grid->set_selected(0, true); | ||
grid->display(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
/* | ||
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or | ||
* https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "../Page.hpp" | ||
#include "Grid.hpp" | ||
#include "List.hpp" | ||
|
||
#ifndef IR_MAIN_PAGE_H | ||
#define IR_MAIN_PAGE_H | ||
|
||
class IRMainPage : public Page { | ||
private: | ||
List *record_signal; | ||
List *emulate_signal; | ||
List *emulate_list; | ||
List *emulate_rc; | ||
List *go_back; | ||
|
||
public: | ||
IRMainPage(uint8_t _position_limit, uint8_t _lower_limit, | ||
uint8_t _position_increment, GFXForms *screen, Gui *_gui) : Page(_position_limit, _lower_limit, _position_increment, screen, _gui) {}; | ||
~IRMainPage(); | ||
void display(); | ||
|
||
void set_selected(int pos, bool status) { | ||
grid->set_selected(pos, status); | ||
}; | ||
void click(int pos, void callback()) { grid->click(pos, callback); }; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.