Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

create universal remote shell for infrared

Geoa18c6e4cf705
diff --git a/src/Shells/UniversalRemoteShell.cpp b/src/Shells/UniversalRemoteShell.cpp
new file mode 100644
index 00000000..8f066b8d
--- /dev/null
+++ b/src/Shells/UniversalRemoteShell.cpp
@@ -0,0 +1,84 @@
+#include "UniversalRemoteShell.h"
+#include "Data/UniversalRemoteCommands.h"
+#include "Data/DeviceBgoneCommands.h"
+
+UniversalRemoteShell::UniversalRemoteShell(
+ ITerminalView& view,
+ IInput& input,
+ InfraredService& irService,
+ ArgTransformer& argTransformer,
+ UserInputManager& userInputManager
+) : infraredService(irService),
+ terminalView(view),
+ terminalInput(input),
+ argTransformer(argTransformer),
+ userInputManager(userInputManager) {}
+
+void UniversalRemoteShell::run() {
+ // Remote actions
+ const std::vector<std::string> actions = {
+ "⏻ ON/OFF",
+ "πŸ”‡ MUTE",
+ "▢️ PLAY",
+ "⏸️ PAUSE",
+ "πŸ”Š VOL UP",
+ "πŸ”‰ VOL DOWN",
+ "πŸ”Ό CH UP",
+ "πŸ”½ CH DOWN",
+ "πŸšͺ EXIT SHELL"
+ };
+
+ terminalView.println("INFRARED: Universal IR Remote started...\n");
+
+ while (true) {
+ // Display actions
+ int index = userInputManager.readValidatedChoiceIndex("Select a remote action", actions, 0);
+ if (index < 0 || index >= (int)actions.size()) {
+ terminalView.println("Invalid selection.\n");
+ continue;
+ }
+
+ // Handle exit
+ if (actions[index] == "πŸšͺ EXIT SHELL") {
+ terminalView.println("INFRARED: Exiting infrared remote shell...\n");
+ break;
+ }
+
+ // Send commands
+ terminalView.println("Sending all codes for: " + actions[index] + "... Press [ENTER] to stop.\n");
+ switch (index) {
+ case 0: sendCommandGroup(deviceBgoneCommands); break;
+ case 1: sendCommandGroup(universalMute); break;
+ case 2: sendCommandGroup(universalPlay); break;
+ case 3: sendCommandGroup(universalPause); break;
+ case 4: sendCommandGroup(universalVolUp); break;
+ case 5: sendCommandGroup(universalVolDown); break;
+ case 6: sendCommandGroup(universalChannelUp); break;
+ case 7: sendCommandGroup(universalChannelDown); break;
+ }
+ }
+}
+
+void UniversalRemoteShell::sendCommandGroup(const std::vector<InfraredCommand>& group) {
+ for (const auto& cmd : group) {
+ infraredService.sendInfraredCommand(cmd);
+ delay(100);
+
+ // Enter press to stop
+ char c = terminalInput.readChar();
+ if (c == '\n' || c == '\r') {
+ terminalView.println(" β›” Stopped by user.\n");
+ return;
+ }
+
+ // Display sent command info
+ terminalView.println(
+ " βœ… Sent to protocol=" + InfraredProtocolMapper::toString(cmd.getProtocol()) +
+ " device=" + std::to_string(cmd.getDevice()) +
+ " sub=" + std::to_string(cmd.getSubdevice()) +
+ " cmd=" + std::to_string(cmd.getFunction())
+ );
+ }
+ terminalView.println("");
+}
+
diff --git a/src/Shells/UniversalRemoteShell.h b/src/Shells/UniversalRemoteShell.h
new file mode 100644
index 00000000..f142b504
--- /dev/null
+++ b/src/Shells/UniversalRemoteShell.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <Arduino.h>
+#include "Services/InfraredService.h"
+#include "Interfaces/ITerminalView.h"
+#include "Interfaces/IInput.h"
+#include "Transformers/ArgTransformer.h"
+#include "Managers/UserInputManager.h"
+
+class UniversalRemoteShell {
+public:
+ UniversalRemoteShell( ITerminalView& view, IInput& input, InfraredService& irService, ArgTransformer& argTransformer, UserInputManager& userInputManager);
+ void run();
+
+private:
+ InfraredService& infraredService;
+ ITerminalView& terminalView;
+ IInput& terminalInput;
+ ArgTransformer& argTransformer;
+ UserInputManager& userInputManager;
+
+ void sendCommandGroup(const std::vector<InfraredCommand>& group);
+};