A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add load cmd for infrared, load ir file from littlefs
Geoe8d74d98b12c
diff --git a/src/Controllers/InfraredController.cpp b/src/Controllers/InfraredController.cppindex 6049cc16..c4a743b0 100644--- a/src/Controllers/InfraredController.cpp+++ b/src/Controllers/InfraredController.cpp@@ -7,14 +7,18 @@ InfraredController::InfraredController(ITerminalView& view,IInput& terminalInput,InfraredService& service,+ LittleFsService& littleFsService,ArgTransformer& argTransformer,+ InfraredRemoteTransformer& infraredRemoteTransformer,UserInputManager& userInputManager,UniversalRemoteShell& universalRemoteShell): terminalView(view),terminalInput(terminalInput),infraredService(service),+ littleFsService(littleFsService),argTransformer(argTransformer),+ infraredRemoteTransformer(infraredRemoteTransformer),userInputManager(userInputManager),universalRemoteShell(universalRemoteShell){}@@ -29,6 +33,7 @@ void InfraredController::handleCommand(const TerminalCommand& command) {else if (command.getRoot() == "devicebgone") handleDeviceBgone();else if (command.getRoot() == "remote") handleRemote();else if (command.getRoot() == "replay") handleReplay(command);+ else if (command.getRoot() == "load") handleLoad(command);else if (command.getRoot() == "setprotocol") handleSetProtocol();else handleHelp();}@@ -311,6 +316,78 @@ void InfraredController::handleSetProtocol() {}}+/*+Load+*/+void InfraredController::handleLoad(TerminalCommand const& command) {+ if (!littleFsService.mounted()) {+ littleFsService.begin();+ return;+ }++ // Get IR files from LittleFS+ auto files = littleFsService.listFiles(/*root*/ "/", ".ir");+ if (files.empty()) {+ terminalView.println("INFRARED: No .ir files found in LittleFS root ('/').");+ return;+ }++ // Select file+ terminalView.println("\n=== '.ir' files in LittleFS ===");+ uint16_t idxFile = userInputManager.readValidatedChoiceIndex("File number", files, 0);+ const std::string& chosen = files[idxFile];++ // Load file content+ std::string text;+ if (!littleFsService.readAll("/" + chosen, text)) {+ terminalView.println("INFRARED: Failed to read file: " + chosen);+ return;+ }++ // Verify format+ if (!infraredRemoteTransformer.isValidInfraredFile(text)) {+ terminalView.println("INFRARED: Unrecognized .ir format or empty: " + chosen);+ return;+ }++ // Extract commands+ auto cmds = infraredRemoteTransformer.transformFromFileFormat(text);+ if (cmds.empty()) {+ terminalView.println("INFRARED: No commands found in: " + chosen);+ return;+ }++ // Cmds names+ auto cmdStrings = infraredRemoteTransformer.extractFunctionNames(cmds);+ cmdStrings.push_back("Exit File"); // for exit option++ while (true) {+ // Select command+ terminalView.println("\n=== Commands in file '" + chosen + "' ===");+ uint8_t idxCmd = userInputManager.readValidatedChoiceIndex("Command number", cmdStrings, 0);+ if (idxCmd == cmdStrings.size()-1) {+ terminalView.println("Exiting command send...\n");+ break;+ }++ // Convert+ const auto& ir = cmds[idxCmd];+ uint8_t device = static_cast<uint8_t>(ir.address & 0xFF);+ uint8_t sub = static_cast<uint8_t>((ir.address >> 8) & 0xFF);+ auto finalCmd = InfraredCommand(+ ir.protocol,+ device,+ sub,+ ir.function+ );++ // Send+ infraredService.sendInfraredCommand(finalCmd);+ terminalView.println("\n ✅ Sent command '" + ir.functionName + "' from file '" + chosen + "'");+ }+}++/*Config*/@@ -345,6 +422,7 @@ void InfraredController::handleHelp() {terminalView.println(" devicebgone");terminalView.println(" remote");terminalView.println(" replay");+ terminalView.println(" load");terminalView.println(" config");}diff --git a/src/Controllers/InfraredController.h b/src/Controllers/InfraredController.hindex 585091c6..ccacaa8c 100644--- a/src/Controllers/InfraredController.h+++ b/src/Controllers/InfraredController.h@@ -9,8 +9,10 @@#include "Interfaces/ITerminalView.h"#include "Interfaces/IInput.h"#include "Services/InfraredService.h"+#include "Services/LittleFsService.h"#include "Models/TerminalCommand.h"#include "Transformers/ArgTransformer.h"+#include "Transformers/InfraredRemoteTransformer.h"#include "Managers/UserInputManager.h"#include "States/GlobalState.h"#include "Shells/UniversalRemoteShell.h"@@ -19,7 +21,8 @@ class InfraredController {public:// ConstructorInfraredController(ITerminalView& view, IInput& terminalInput,- InfraredService& service, ArgTransformer& ArgTransformer,+ InfraredService& service, LittleFsService& littleFsService,+ ArgTransformer& argTransformer, InfraredRemoteTransformer& infraredRemoteTransformer,UserInputManager& userInputManager, UniversalRemoteShell& universalRemoteShell);// Entry point for Infraredcommand dispatch@@ -34,8 +37,10 @@ private:InfraredService& infraredService;GlobalState& state = GlobalState::getInstance();ArgTransformer& argTransformer;+ InfraredRemoteTransformer& infraredRemoteTransformer;UserInputManager& userInputManager;UniversalRemoteShell& universalRemoteShell;+ LittleFsService& littleFsService;bool configured = false;uint8_t MAX_IR_FRAMES = 64; // Maximum frames to record@@ -70,6 +75,9 @@ private:bool recordFrames(std::vector<IRFrame>& tape);void playbackFrames(const std::vector<IRFrame>& tape, uint32_t replayCount);+ // Load commands from .ir files (littlefs)+ void handleLoad(const TerminalCommand& command);+// Show help textvoid handleHelp();};