From 281a7347bf2c1c94b4d47ac24337d017202ed1cc Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Mon, 22 Jul 2024 12:44:03 +0200 Subject: [PATCH] refactor sony 12 bit command function --- arduino-sony-minidisc-ir-remote.ino | 79 ++++++++++--- defines.h | 126 +++++++++++---------- sd-card/Index.html | 166 ++++++++++++++++++---------- 3 files changed, 239 insertions(+), 132 deletions(-) diff --git a/arduino-sony-minidisc-ir-remote.ino b/arduino-sony-minidisc-ir-remote.ino index e9812d7..825325d 100644 --- a/arduino-sony-minidisc-ir-remote.ino +++ b/arduino-sony-minidisc-ir-remote.ino @@ -147,14 +147,62 @@ void initIR() Serial.println(IR_SEND_PIN); } -void sendButton(int command) +void sendButton12(int command) { - Serial.println("sendButton command: "); + Serial.print("sendButton12 command: "); Serial.println(command); Serial.flush(); IrSender.sendSony(0xF, command, 2, 12); } +void sendCommand12(String commandString) +{ + if (commandString == "POWER") + sendButton12(POWER); + if (commandString == "PLAY") + sendButton12(PLAY); + if (commandString == "PAUSE") + sendButton12(PAUSE); + if (commandString == "STOP") + sendButton12(STOP); + if (commandString == "PREV") + sendButton12(PREV); + if (commandString == "NEXT") + sendButton12(NEXT); + else + { + Serial.println("wrong command!"); + } +} + +void sendButton20(int command) +{ + Serial.print(F("Send Sony/SIRCS with 7 command and 13 address bits: ")); + Serial.println(command); + Serial.flush(); + IrSender.sendSony(0xF & 0x1FFF, command & 0x7F, 2, SIRCS_20_PROTOCOL); +} + +void sendCommand20(String commandString) +{ + if (commandString == "Q") + sendButton20(Q); + if (commandString == "W") + sendButton20(W); + if (commandString == "E") + sendButton20(E); + if (commandString == "R") + sendButton20(R); + if (commandString == "T") + sendButton20(T); + if (commandString == "Z") + sendButton20(Z); + else + { + Serial.println("wrong command!"); + } +} + //------------------------------------------------ //------------- Webserver Functions -------------- @@ -236,20 +284,19 @@ void setup() String message; if (request->hasParam("control", true)) { message = request->getParam("control", true)->value(); - //Serial.print(message); - sendButton(message); - /* if (message == "POWER") - sendButton(POWER); - if (message == "PLAY") - sendButton(PLAY); - if (message == "PAUSE") - sendButton(PAUSE); - if (message == "STOP") - sendButton(STOP); - if (message == "PREV") - sendButton(PREV); - if (message == "NEXT") - sendButton(NEXT); */ + sendCommand12(message); + } else { + message = "No message sent"; + } + request->send(SD, "/index.html", "text/html"); }); + + // Send a POST request to /api/keyboard-input with a form field message set to + server.on("/api/keyboard-input", HTTP_POST, [](AsyncWebServerRequest *request) + { + String message; + if (request->hasParam("key", true)) { + message = request->getParam("key", true)->value(); + sendCommand20(message); } else { message = "No message sent"; } diff --git a/defines.h b/defines.h index 13bbfb2..b655ac7 100644 --- a/defines.h +++ b/defines.h @@ -1,70 +1,80 @@ // Pin definitions -#define IR_SEND_PIN 4 -#define LED_PIN 13 +#define IR_SEND_PIN 4 +#define LED_PIN 13 // IR commands (Sony 12bit) -int POWER = 0x15; //Das ist noch ein Fehler. Eigentlich brauche ich eine Möglichkeit key/value Paare auszulesen. +// int POWER = 0x15; //Das ist noch ein Fehler. Eigentlich brauche ich eine Möglichkeit key/value Paare auszulesen. -//#define POWER 0x15 -#define PLAY 0x2A -#define PAUSE 0x29 -#define STOP 0x28 -#define PREV 0x20 //geraten -#define NEXT 0x21 +#define POWER 0x15 +#define PLAY 0x2A +#define PAUSE 0x29 +#define STOP 0x28 +#define PREV 0x20 // geraten +#define NEXT 0x21 -//old commands -#define EJECT 0x69E -//#define POWER 0xA9E -#define DISPLAY 0x19E -#define SCROLL 0x99E -#define CONTINUE 0xB9E -#define SHUFFLE 0x79E -#define PROGRAM 0xF9E -#define KEY_D 0xD9E -#define KEY_E 0x59E -#define NUMBER1 0x01E -#define NUMBER2 0x81E -#define NUMBER3 0x41E -#define NUMBER4 0xC1E -#define NUMBER5 0x21E -#define NUMBER6 0xA1E -#define NUMBER7 0x61E -#define NUMBER8 0xE1E -#define NUMBER9 0x11E -#define NUMBER10 0x91E -#define NUMBER11 0x03E -#define NUMBER12 0x83E -#define NUMBER13 0x43E -#define NUMBER14 0xC3E -#define NUMBER15 0x23E -#define NUMBER16 0xA3E -#define NUMBER17 0x63E -#define NUMBER18 0xE3E -#define NUMBER19 0x13E -#define NUMBER20 0x93E -#define NUMBER21 0x53E -#define NUMBER22 0xD3E -#define NUMBER23 0x33E -#define NUMBER24 0xB3E -#define NUMBER25 0x73E -#define LARGER25 0x51E -#define REPEATMODE 0x65E -#define ATOB 0xE5E -#define ASPACE 0xCDE -#define MSCAN 0x2DE -#define NAME 0x3DE -#define CHAR 0x6DE -#define NUM 0xEDE -#define CLEAR 0xF1E +// IR commands (Sony 20bit) +#define Q 0x41 +#define W 0x47 +#define E 0x1A +#define R 0x42 +#define T 0x44 +#define Z 0x4A +#define SPACE 0x4C +#define COMMA 0x4E + +// old commands +#define EJECT 0x69E +// #define POWER 0xA9E +#define DISPLAY 0x19E +#define SCROLL 0x99E +#define CONTINUE 0xB9E +#define SHUFFLE 0x79E +#define PROGRAM 0xF9E +#define KEY_D 0xD9E +#define KEY_E 0x59E +#define NUMBER1 0x01E +#define NUMBER2 0x81E +#define NUMBER3 0x41E +#define NUMBER4 0xC1E +#define NUMBER5 0x21E +#define NUMBER6 0xA1E +#define NUMBER7 0x61E +#define NUMBER8 0xE1E +#define NUMBER9 0x11E +#define NUMBER10 0x91E +#define NUMBER11 0x03E +#define NUMBER12 0x83E +#define NUMBER13 0x43E +#define NUMBER14 0xC3E +#define NUMBER15 0x23E +#define NUMBER16 0xA3E +#define NUMBER17 0x63E +#define NUMBER18 0xE3E +#define NUMBER19 0x13E +#define NUMBER20 0x93E +#define NUMBER21 0x53E +#define NUMBER22 0xD3E +#define NUMBER23 0x33E +#define NUMBER24 0xB3E +#define NUMBER25 0x73E +#define LARGER25 0x51E +#define REPEATMODE 0x65E +#define ATOB 0xE5E +#define ASPACE 0xCDE +#define MSCAN 0x2DE +#define NAME 0x3DE +#define CHAR 0x6DE +#define NUM 0xEDE +#define CLEAR 0xF1E // #define PLAY 0x55E // #define PAUSE 0x95E // #define STOP 0x15E // #define AMSPREV 0x05E // #define AMSNEXT 0x85E -#define RECORD 0xB5E -#define REWIND 0xD5E +#define RECORD 0xB5E +#define REWIND 0xD5E #define FASTFORWARD 0x35E -#define TREC 0x0DE -#define MUSICSYNC 0xFDE -#define NAMESELECT 0x87E +#define TREC 0x0DE +#define MUSICSYNC 0xFDE +#define NAMESELECT 0x87E diff --git a/sd-card/Index.html b/sd-card/Index.html index 430f561..24205e8 100644 --- a/sd-card/Index.html +++ b/sd-card/Index.html @@ -63,6 +63,10 @@ outline: none; } + .width-full { + width: 100%; + } + .text-white { color: white; } @@ -123,7 +127,7 @@ border-right-color: black; } - .textinput-wrapper { + .form { display: flex; flex-direction: column; gap: 12px; @@ -132,8 +136,21 @@ color: white; } + .textinput-wrapper { + display: flex; + flex-direction: column; + gap: 12px; + margin-top: 8px; + margin-bottom: 8px; + } + + .textinput-group { + display: flex; + gap: 12px; + } + .textinput { - width: 100%; + /* width: 100%; */ padding: 12px 20px; box-sizing: border-box; border: 2px solid #ccc; @@ -152,75 +169,108 @@

SONY RM-D27M Remote

- LED Test Mode -
-
- - -
-
+ +
+ LED Test Mode +
+
+ + +
+
+
Title Editing -
+
-
+
- Deck Control -
-
- - - - - - - - -
-
-
- - - - - - -
+
+ Deck Control +
+
+ + + + + + + + +
+
+
+ +
+ 20 Bit Keyboard Input Test +
+
+ + + + + + +
+
+