refactor sony 12 bit command function

This commit is contained in:
Norman Bos
2024-07-22 12:44:03 +02:00
parent 470a179285
commit 281a7347bf
3 changed files with 239 additions and 132 deletions
+63 -16
View File
@@ -147,14 +147,62 @@ void initIR()
Serial.println(IR_SEND_PIN); 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.println(command);
Serial.flush(); Serial.flush();
IrSender.sendSony(0xF, command, 2, 12); 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 -------------- //------------- Webserver Functions --------------
@@ -236,20 +284,19 @@ void setup()
String message; String message;
if (request->hasParam("control", true)) { if (request->hasParam("control", true)) {
message = request->getParam("control", true)->value(); message = request->getParam("control", true)->value();
//Serial.print(message); sendCommand12(message);
sendButton(message); } else {
/* if (message == "POWER") message = "No message sent";
sendButton(POWER); }
if (message == "PLAY") request->send(SD, "/index.html", "text/html"); });
sendButton(PLAY);
if (message == "PAUSE") // Send a POST request to <IP>/api/keyboard-input with a form field message set to <message>
sendButton(PAUSE); server.on("/api/keyboard-input", HTTP_POST, [](AsyncWebServerRequest *request)
if (message == "STOP") {
sendButton(STOP); String message;
if (message == "PREV") if (request->hasParam("key", true)) {
sendButton(PREV); message = request->getParam("key", true)->value();
if (message == "NEXT") sendCommand20(message);
sendButton(NEXT); */
} else { } else {
message = "No message sent"; message = "No message sent";
} }
+68 -58
View File
@@ -1,70 +1,80 @@
// Pin definitions // Pin definitions
#define IR_SEND_PIN 4 #define IR_SEND_PIN 4
#define LED_PIN 13 #define LED_PIN 13
// IR commands (Sony 12bit) // 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 POWER 0x15
#define PLAY 0x2A #define PLAY 0x2A
#define PAUSE 0x29 #define PAUSE 0x29
#define STOP 0x28 #define STOP 0x28
#define PREV 0x20 //geraten #define PREV 0x20 // geraten
#define NEXT 0x21 #define NEXT 0x21
//old commands // IR commands (Sony 20bit)
#define EJECT 0x69E #define Q 0x41
//#define POWER 0xA9E #define W 0x47
#define DISPLAY 0x19E #define E 0x1A
#define SCROLL 0x99E #define R 0x42
#define CONTINUE 0xB9E #define T 0x44
#define SHUFFLE 0x79E #define Z 0x4A
#define PROGRAM 0xF9E #define SPACE 0x4C
#define KEY_D 0xD9E #define COMMA 0x4E
#define KEY_E 0x59E
#define NUMBER1 0x01E // old commands
#define NUMBER2 0x81E #define EJECT 0x69E
#define NUMBER3 0x41E // #define POWER 0xA9E
#define NUMBER4 0xC1E #define DISPLAY 0x19E
#define NUMBER5 0x21E #define SCROLL 0x99E
#define NUMBER6 0xA1E #define CONTINUE 0xB9E
#define NUMBER7 0x61E #define SHUFFLE 0x79E
#define NUMBER8 0xE1E #define PROGRAM 0xF9E
#define NUMBER9 0x11E #define KEY_D 0xD9E
#define NUMBER10 0x91E #define KEY_E 0x59E
#define NUMBER11 0x03E #define NUMBER1 0x01E
#define NUMBER12 0x83E #define NUMBER2 0x81E
#define NUMBER13 0x43E #define NUMBER3 0x41E
#define NUMBER14 0xC3E #define NUMBER4 0xC1E
#define NUMBER15 0x23E #define NUMBER5 0x21E
#define NUMBER16 0xA3E #define NUMBER6 0xA1E
#define NUMBER17 0x63E #define NUMBER7 0x61E
#define NUMBER18 0xE3E #define NUMBER8 0xE1E
#define NUMBER19 0x13E #define NUMBER9 0x11E
#define NUMBER20 0x93E #define NUMBER10 0x91E
#define NUMBER21 0x53E #define NUMBER11 0x03E
#define NUMBER22 0xD3E #define NUMBER12 0x83E
#define NUMBER23 0x33E #define NUMBER13 0x43E
#define NUMBER24 0xB3E #define NUMBER14 0xC3E
#define NUMBER25 0x73E #define NUMBER15 0x23E
#define LARGER25 0x51E #define NUMBER16 0xA3E
#define REPEATMODE 0x65E #define NUMBER17 0x63E
#define ATOB 0xE5E #define NUMBER18 0xE3E
#define ASPACE 0xCDE #define NUMBER19 0x13E
#define MSCAN 0x2DE #define NUMBER20 0x93E
#define NAME 0x3DE #define NUMBER21 0x53E
#define CHAR 0x6DE #define NUMBER22 0xD3E
#define NUM 0xEDE #define NUMBER23 0x33E
#define CLEAR 0xF1E #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 PLAY 0x55E
// #define PAUSE 0x95E // #define PAUSE 0x95E
// #define STOP 0x15E // #define STOP 0x15E
// #define AMSPREV 0x05E // #define AMSPREV 0x05E
// #define AMSNEXT 0x85E // #define AMSNEXT 0x85E
#define RECORD 0xB5E #define RECORD 0xB5E
#define REWIND 0xD5E #define REWIND 0xD5E
#define FASTFORWARD 0x35E #define FASTFORWARD 0x35E
#define TREC 0x0DE #define TREC 0x0DE
#define MUSICSYNC 0xFDE #define MUSICSYNC 0xFDE
#define NAMESELECT 0x87E #define NAMESELECT 0x87E
+108 -58
View File
@@ -63,6 +63,10 @@
outline: none; outline: none;
} }
.width-full {
width: 100%;
}
.text-white { .text-white {
color: white; color: white;
} }
@@ -123,7 +127,7 @@
border-right-color: black; border-right-color: black;
} }
.textinput-wrapper { .form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 12px; gap: 12px;
@@ -132,8 +136,21 @@
color: white; color: white;
} }
.textinput-wrapper {
display: flex;
flex-direction: column;
gap: 12px;
margin-top: 8px;
margin-bottom: 8px;
}
.textinput-group {
display: flex;
gap: 12px;
}
.textinput { .textinput {
width: 100%; /* width: 100%; */
padding: 12px 20px; padding: 12px 20px;
box-sizing: border-box; box-sizing: border-box;
border: 2px solid #ccc; border: 2px solid #ccc;
@@ -152,75 +169,108 @@
<body> <body>
<main> <main>
<h2 class="headline">SONY RM-D27M Remote</h2> <h2 class="headline">SONY RM-D27M Remote</h2>
<span class="text-white text-with-line">LED Test Mode</span>
<div class="upper-buttonbox"> <section>
<form action="/api/control-led" method="post"> <span class="text-white text-with-line">LED Test Mode</span>
<button name="led" type="submit" value="1" class="smallbutton"> <div class="upper-buttonbox">
LED on <form action="/api/control-led" method="post">
</button> <button name="led" type="submit" value="1" class="smallbutton">
<button name="led" type="submit" value="0" class="smallbutton"> LED on
LED off </button>
</button> <button name="led" type="submit" value="0" class="smallbutton">
</form> LED off
</div> </button>
</form>
</div>
</section>
<span class="text-orange text-with-line">Title Editing</span> <span class="text-orange text-with-line">Title Editing</span>
<form action="/api/gettext" method="post" class="textinput-wrapper"> <form action="/api/gettext" method="post" class="form">
<textarea name="text_box" rows="4" cols="50"></textarea> <textarea name="text_box" rows="4" cols="50"></textarea>
<button type="submit">Submit</button> <button type="submit">Submit</button>
</form> </form>
<section> <section>
<form action="/api/gettextinput" method="get" class="textinput-wrapper"> <form action="/api/gettextinput" method="get" class="form">
<label for="text_input">Change Title</label> <label for="text_input">Change Title</label>
<input type="text" name="text_input" class="textinput" /> <input type="text" name="text_input" class="textinput" />
<button type="submit">Submit</button> <button type="submit">Submit</button>
</form> </form>
</section> </section>
<span class="text-orange text-with-line">Deck Control</span> <section>
<div class="upper-buttonbox"> <span class="text-orange text-with-line">Deck Control</span>
<form action="/api/control-deck" method="post"> <div class="upper-buttonbox">
<button <form action="/api/control-deck" method="post">
name="control" <button
type="submit" name="control"
value="POWER" type="submit"
class="smallbutton" value="POWER"
> class="smallbutton"
power >
</button> power
<button name="control" type="submit" value="PLAY" class="smallbutton"> </button>
play <button
</button> name="control"
<button type="submit"
name="control" value="PLAY"
type="submit" class="smallbutton"
value="PAUSE" >
class="smallbutton" play
> </button>
pause <button
</button> name="control"
<button name="control" type="submit" value="STOP" class="smallbutton"> type="submit"
stop value="PAUSE"
</button> class="smallbutton"
<button name="control" type="submit" value="PREV" class="smallbutton"> >
previous pause
</button> </button>
<button name="control" type="submit" value="NEXT" class="smallbutton"> <button
next name="control"
</button> type="submit"
<button class="roundbutton"></button> value="STOP"
<button class="roundbutton"></button> class="smallbutton"
</form> >
</div> stop
<div class="lower-buttonbox"> </button>
<button>Q</button> <button
<button>W</button> name="control"
<button>E</button> type="submit"
<button>R</button> value="PREV"
<button>T</button> class="smallbutton"
<button>Z</button> >
</div> previous
</button>
<button
name="control"
type="submit"
value="NEXT"
class="smallbutton"
>
next
</button>
<button class="roundbutton"></button>
<button class="roundbutton"></button>
</form>
</div>
</section>
<section>
<span class="text-orange text-with-line"
>20 Bit Keyboard Input Test</span
>
<div class="lower-buttonbox">
<form action="/api/keyboard-input" method="post">
<button name="key" type="submit" value="Q">Q</button>
<button name="key" type="submit" value="W">W</button>
<button name="key" type="submit" value="E">E</button>
<button name="key" type="submit" value="R">R</button>
<button name="key" type="submit" value="T">T</button>
<button name="key" type="submit" value="Z">Z</button>
</form>
</div>
</section>
</main> </main>
<footer> <footer>
<p>KEY BOARD REMOTE COMMANDER</p> <p>KEY BOARD REMOTE COMMANDER</p>