From bf9a32db44157ddaa6f224e1a9a1dbaa37063fc9 Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Mon, 15 Jul 2024 21:09:49 +0200 Subject: [PATCH 01/13] move comment --- minidisc_namer_RM-D27M.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/minidisc_namer_RM-D27M.ino b/minidisc_namer_RM-D27M.ino index 3063f50..4060e35 100644 --- a/minidisc_namer_RM-D27M.ino +++ b/minidisc_namer_RM-D27M.ino @@ -49,7 +49,7 @@ void setup() void loop() { - // blink(); //! Der Loop wird gerade nur einmal ausgeführt und stoppt bei der serial monitor eingabe. Bei jeder Eingabe erfolgt ein neue Loop. Alle test-Funktionen laufen durch. + // blink(); // simpleButtonTest(); buttonPlayTest(); @@ -102,7 +102,7 @@ void buttonPlayTest() /* end testing code */ } -void oldSerialInput() +void oldSerialInput() //! Der Loop wird gerade nur einmal ausgeführt und stoppt bei der serial monitor eingabe. Bei jeder Eingabe erfolgt ein neue Loop. Alle test-Funktionen laufen durch. { if (commandMode) From c1d3e39f8f1b14ad79d18a8a93aec400480a278e Mon Sep 17 00:00:00 2001 From: StrangeD0s <47105931+StrangeD0s@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:44:50 +0200 Subject: [PATCH 02/13] rework into arduino webserver --- minidisc_namer_RM-D27M.ino | 957 +++++-------------------------------- 1 file changed, 115 insertions(+), 842 deletions(-) diff --git a/minidisc_namer_RM-D27M.ino b/minidisc_namer_RM-D27M.ino index 3063f50..1159503 100644 --- a/minidisc_namer_RM-D27M.ino +++ b/minidisc_namer_RM-D27M.ino @@ -1,866 +1,139 @@ -// modified for use with Sony RM-D27M -// based on https://hackaday.io/project/165504-sony-minidisc-namer by smartroad +/* + WiFi Web Server LED Blink -#include // Muss installiert werden. Funktioniert mit v2.5.0 Siehe https://github.com/Arduino-IRremote/Arduino-IRremote -#include "defines.h" + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi Shield (once connected) + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 5. -IRsend irsend; + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off -char inputChars[64]; -byte charCount = 0; + This example is written for a network using WPA2 encryption. For insecure + WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly. -byte mode = 0; // Capitals = 0, Lowercase = 1 -byte targetMode = 0; -boolean commandMode = true; // True = control playback | False = name entry mode + Circuit: + * LED attached to pin 13 + * IR Transmitter attached to pin 4 -int totalCount = 0; -byte blockCount = 0; + created for arduino 25 Nov 2012 + by Tom Igoe -// define the IT sendPin: -uint8_t tSendPin = 4; // IO4 auf AZ D1 +ported for sparkfun esp32 +31.01.2017 by Jan Hendrik Berlin + + */ -/* start testing code for hardware button*/ -// constants won't change. They're used here to set pin numbers: -uint8_t buttonPin = 14; // the number of the pushbutton pin -uint8_t ledPin = 2; // the number of the LED pin +#include +#include -// variables will change: -uint8_t buttonState = 0; // variable for reading the pushbutton status -/* end testing code */ +const char* ssid = "FritzBox-7590-NB"; +const char* password = "60762265561727730801"; + +WiFiServer server(80); void setup() { - pinMode(2, OUTPUT); - // Initialize serial monitor: - Serial.begin(115200); - while (!Serial) - ; - // helpText(); - pinMode(tSendPin, OUTPUT); - digitalWrite(tSendPin, LOW); - /* start testing code */ - // initialize the LED pin as an output: - pinMode(ledPin, OUTPUT); - // initialize the pushbutton pin as an input: - pinMode(buttonPin, INPUT); - digitalWrite(ledPin, HIGH); - /* end testing code */ + Serial.begin(115200); + pinMode(13, OUTPUT); // set the LED pin mode + + delay(10); + + // We start by connecting to a WiFi network + + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + // Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN + uint8_t tSendPin = 4; + IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin + // You can change send pin later with IrSender.setSendPin(); + Serial.println(); + Serial.print(F("Send IR signals at pin ")); + Serial.println(tSendPin); + + Serial.println(); + Serial.println("WiFi connected."); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + server.begin(); + } -void loop() -{ - // blink(); //! Der Loop wird gerade nur einmal ausgeführt und stoppt bei der serial monitor eingabe. Bei jeder Eingabe erfolgt ein neue Loop. Alle test-Funktionen laufen durch. - // simpleButtonTest(); - buttonPlayTest(); - // oldSerialInput(); -} -void simpleButtonTest() -{ - /* start testing code */ - // read the state of the pushbutton value: - buttonState = digitalRead(buttonPin); +void loop(){ + WiFiClient client = server.available(); // listen for incoming clients - // check if the pushbutton is pressed. If it is, the buttonState is HIGH: - if (buttonState == HIGH) - { - // write to serial monitor: - Serial.println(F("button state is HIGH")); - // turn LED on: - digitalWrite(ledPin, HIGH); - } - else - { - // turn LED off: - digitalWrite(ledPin, LOW); - } - /* end testing code */ -} + if (client) { // if you get a client, + Serial.println("New Client."); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character -void buttonPlayTest() -{ - /* start testing code */ - // read the state of the pushbutton value: - buttonState = digitalRead(buttonPin); + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); - // check if the pushbutton is pressed. If it is, the buttonState is HIGH: - if (buttonState == HIGH) - { - // write to serial monitor: - Serial.println(F("button state is HIGH")); - // turn LED on: - digitalWrite(ledPin, HIGH); - Serial.println(F("Play")); - sendButton(PLAY); - } - else - { - // turn LED off: - digitalWrite(ledPin, LOW); - } - /* end testing code */ -} + // the content of the HTTP response follows the header: + client.print("Click here to turn the LED on pin 13 on.
"); + client.print("Click here to turn the LED on pin 13 off.
"); + client.print("play
"); + client.print("

"); + client.print("

"); -void oldSerialInput() -{ + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } - if (commandMode) - { - if (charCount > 0) - { - Serial.println(F("\n\r\u001b[34;1mCONFIRM NAME INPUT\u001b[0m")); - Serial.println(F("Y - Yes or N - NO")); - } - else - { - Serial.print(F("\n\r\n\rEnter Command (H for help): ")); - } - } - - while (!Serial.available()) - { - } - - if (commandMode) - { - - char serialChar = Serial.read(); - if (charCount == 0) - { - if (serialChar == 'b') - { - Serial.println(F("Next Track")); - sendButton(AMSNEXT); - } - else if (serialChar == 'z') - { - Serial.println(F("Previous Track")); - sendButton(AMSPREV); - } - else if (serialChar == 'x') - { - Serial.println(F("Play")); - sendButton(PLAY); - } - else if (serialChar == 'c') - { - Serial.println(F("Pause")); - sendButton(PAUSE); - } - else if (serialChar == 'v') - { - Serial.println(F("Stop")); - sendButton(STOP); - } - else if (serialChar == 'l') - { - Serial.println(F("Eject")); - sendButton(EJECT); - } - else if (serialChar == 's') - { - Serial.println(F("Starting Record")); - sendButton(RECORD); - } - else if (serialChar == 'S') - { - Serial.println(F("Music Sync Recording")); - sendButton(MUSICSYNC); - } - else if (serialChar == 'd') - { - Serial.println(F("Display Mode")); - sendButton(DISPLAY); - } - else if (serialChar == 'D') - { - Serial.println(F("Scrolling Display")); - sendButton(SCROLL); - } - else if (serialChar == 'r') - { - Serial.println(F("Repeat Mode")); - sendButton(REPEATMODE); - } - else if (serialChar == 'R') - { - Serial.println(F("Section Repeat (A<>B)")); - sendButton(ATOB); - } - else if (serialChar == '1') - { - Serial.print(F("1")); - // sendButton(NUMBER1); - digitalWrite(ledPin, HIGH); - Serial.print(F("set ledPin HIGH")); - } - else if (serialChar == '2') - { - Serial.print(F("2")); - // sendButton(NUMBER2); - digitalWrite(ledPin, LOW); - Serial.print(F("set ledPin LOW")); - } - else if (serialChar == '3') - { - Serial.print(F("3")); - sendButton(NUMBER3); - } - else if (serialChar == '4') - { - Serial.print(F("4")); - sendButton(NUMBER4); - } - else if (serialChar == '5') - { - Serial.print(F("5")); - sendButton(NUMBER5); - } - else if (serialChar == '6') - { - Serial.print(F("6")); - sendButton(NUMBER6); - } - else if (serialChar == '7') - { - Serial.print(F("7")); - sendButton(NUMBER7); - } - else if (serialChar == '8') - { - Serial.print(F("8")); - sendButton(NUMBER8); - } - else if (serialChar == '9') - { - Serial.print(F("9")); - sendButton(NUMBER9); - } - else if (serialChar == '0') - { - Serial.print(F("0")); - sendButton(NUMBER10); - } - else if (serialChar == '=' || serialChar == '+') - { - Serial.print(F(">10")); - sendButton(LARGER25); - } - else if (serialChar == '#') - { - Serial.print(F("CLEARING MEMUSAGE")); - totalCount = 0; - blockCount = 0; - memUsed(); - } - else if (serialChar == '`') - { // change to naming mode - Serial.println(F("Name Mode")); - commandMode = false; - memUsed(); - Serial.println(F("\n\rType name and press enter to send:\u001b[37;1m")); - } - else if (serialChar == 'H' || serialChar == 'h') - { // stop - Serial.println(F("Help\r\n\r\n")); - helpText(); + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(13, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(13, LOW); // GET /L turns the LED off + } + if (currentLine.endsWith("GET /play")) { + Serial.println("MD play"); + Serial.flush(); + IrSender.sendSony(0xF, 0x2A, 2, 12); + } + if (currentLine.endsWith("POST /api/control-deck")) { + + Serial.println("POST"); + char c = client.read(); + Serial.print(c); + } } } - else - { - if (serialChar == 'Y' || serialChar == 'y') - { // confirm name - totalCount += charCount; - blockCount += (charCount + 6) / 7; - memUsed(); - charCount = 0; - sendButton(NAME); - } - else if (serialChar == 'N' || serialChar == 'n') - { // cancel name - memUsed(); - charCount = 0; - sendButton(STOP); - } - } - } - else - { - inputChars[charCount] = Serial.read(); - if (inputChars[charCount] == 10 || inputChars[charCount] == 13) - { - Serial.print(F("\u001b[0m")); - if (nameCheck()) - sendName(); - else - charCount = 0; - commandMode = true; - } - else if (inputChars[charCount] == 127) - { - Serial.print(inputChars[charCount]); - charCount--; - } - else - { - Serial.print(inputChars[charCount]); - charCount++; - } + // close the connection: + client.stop(); + Serial.println("Client Disconnected."); } } - -void memUsed() -{ - float countPercent = (float(totalCount) / 1785) * 100; - float blockPercent = (float(blockCount) / 255) * 100; - Serial.print(F("\n\rTotal characters used: \u001b[1m")); - if (countPercent >= 75 && countPercent < 90) - Serial.print(F("\u001b[33m")); - else if (countPercent >= 90) - Serial.print(F("\u001b[31m")); - else - Serial.print(F("\u001b[32m")); - Serial.print(countPercent); - Serial.print(F("%\u001b[0m\u001b[0m\n\rTotal blocks used: \u001b[1m")); - if (blockPercent >= 75 && blockPercent < 90) - Serial.print(F("\u001b[33m")); - else if (blockPercent >= 90) - Serial.print(F("\u001b[31m")); - else - Serial.print(F("\u001b[32m")); - Serial.print(blockPercent); - Serial.print(F("%\u001b[0m\n\r")); -} - -void sendName() -{ - Serial.println(F("\n\r\n\rActivating Name Edit on Player - \u001b[31mPress any key when player ready\u001b[0m")); - sendButton(NAME); - mode = 0; - targetMode = 0; - // delay(2000); - while (!Serial.available()) - { - } - - char purge = Serial.read(); // dump the character - - Serial.print(F("\n\rSending: \u001b[32;1m")); - - for (byte c = 0; c < charCount; c++) - { - if (inputChars[c] >= 65 && inputChars[c] <= 90) - { // Check if char is capital and switch to correct mode - targetMode = 0; - } - else if (inputChars[c] >= 97 && inputChars[c] <= 122) - { // Check if char is lower and switch to correct mode - targetMode = 1; - } - - while (mode != targetMode) - { - sendButton(CHAR); - delay(1000); - mode++; - if (mode > 1) - mode = 0; - } - - if (inputChars[c] == 'A') - { - Serial.print(inputChars[c]); - sendCmd(CONTINUE, 1); - } - else if (inputChars[c] == 'B') - { - Serial.print(inputChars[c]); - sendCmd(SHUFFLE, 1); - } - else if (inputChars[c] == 'C') - { - Serial.print(inputChars[c]); - sendCmd(PROGRAM, 1); - } - else if (inputChars[c] == 'D') - { - Serial.print(inputChars[c]); - sendCmd(KEY_D, 1); - } - else if (inputChars[c] == 'E') - { - Serial.print(inputChars[c]); - sendCmd(KEY_E, 1); - } - else if (inputChars[c] == 'F') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER1, 1); - } - else if (inputChars[c] == 'G') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER2, 1); - } - else if (inputChars[c] == 'H') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER3, 1); - } - else if (inputChars[c] == 'I') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER4, 1); - } - else if (inputChars[c] == 'J') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER5, 1); - } - else if (inputChars[c] == 'K') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER6, 1); - } - else if (inputChars[c] == 'L') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER7, 1); - } - else if (inputChars[c] == 'M') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER8, 1); - } - else if (inputChars[c] == 'N') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER9, 1); - } - else if (inputChars[c] == 'O') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER10, 1); - } - else if (inputChars[c] == 'P') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER11, 1); - } - else if (inputChars[c] == 'Q') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER12, 1); - } - else if (inputChars[c] == 'R') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER13, 1); - } - else if (inputChars[c] == 'S') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER14, 1); - } - else if (inputChars[c] == 'T') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER15, 1); - } - else if (inputChars[c] == 'U') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER16, 1); - } - else if (inputChars[c] == 'V') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER17, 1); - } - else if (inputChars[c] == 'W') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER18, 1); - } - else if (inputChars[c] == 'X') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER19, 1); - } - else if (inputChars[c] == 'Y') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER20, 1); - } - else if (inputChars[c] == 'Z') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER21, 1); - } - - else if (inputChars[c] == 'a') - { - Serial.print(inputChars[c]); - sendCmd(CONTINUE, 1); - } - else if (inputChars[c] == 'b') - { - Serial.print(inputChars[c]); - sendCmd(SHUFFLE, 1); - } - else if (inputChars[c] == 'c') - { - Serial.print(inputChars[c]); - sendCmd(PROGRAM, 1); - } - else if (inputChars[c] == 'd') - { - Serial.print(inputChars[c]); - sendCmd(KEY_D, 1); - } - else if (inputChars[c] == 'e') - { - Serial.print(inputChars[c]); - sendCmd(KEY_E, 1); - } - else if (inputChars[c] == 'f') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER1, 1); - } - else if (inputChars[c] == 'g') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER2, 1); - } - else if (inputChars[c] == 'h') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER3, 1); - } - else if (inputChars[c] == 'i') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER4, 1); - } - else if (inputChars[c] == 'j') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER5, 1); - } - else if (inputChars[c] == 'k') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER6, 1); - } - else if (inputChars[c] == 'l') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER7, 1); - } - else if (inputChars[c] == 'm') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER8, 1); - } - else if (inputChars[c] == 'n') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER9, 1); - } - else if (inputChars[c] == 'o') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER10, 1); - } - else if (inputChars[c] == 'p') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER11, 1); - } - else if (inputChars[c] == 'q') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER12, 1); - } - else if (inputChars[c] == 'r') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER13, 1); - } - else if (inputChars[c] == 's') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER14, 1); - } - else if (inputChars[c] == 't') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER15, 1); - } - else if (inputChars[c] == 'u') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER16, 1); - } - else if (inputChars[c] == 'v') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER17, 1); - } - else if (inputChars[c] == 'w') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER18, 1); - } - else if (inputChars[c] == 'x') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER19, 1); - } - else if (inputChars[c] == 'y') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER20, 1); - } - else if (inputChars[c] == 'z') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER21, 1); - } - - else if (inputChars[c] == 39 || inputChars[c] == 96) - { // ' and ` - Serial.print(inputChars[c]); - sendCmd(NUMBER25, 1); - } - else if (inputChars[c] == 45 || inputChars[c] == 95) - { // - or _ - Serial.print(inputChars[c]); - sendCmd(NUMBER22, 1); - } - else if (inputChars[c] == 47 || inputChars[c] == 92) - { // slash or backslash - Serial.print(inputChars[c]); - sendCmd(LARGER25, 1); - } - else if (inputChars[c] == 44) - { // , not supported - Serial.print(inputChars[c]); - sendCmd(NUMBER1, 1); - } - else if (inputChars[c] == '.') - { - Serial.print(inputChars[c]); - sendCmd(NUMBER24, 1); - } - else if (inputChars[c] == '(') - { - Serial.print(inputChars[c]); - sendCmd(ASPACE, 1); - } - else if (inputChars[c] == ')') - { - Serial.print(inputChars[c]); - sendCmd(MSCAN, 1); - } - else if (inputChars[c] == ':') - { // : not supported - Serial.print(inputChars[c]); - sendCmd(NUMBER1, 8); - } - else if (inputChars[c] == '!') - { - Serial.print(inputChars[c]); - sendCmd(ATOB, 1); - } - else if (inputChars[c] == '?') - { - Serial.print(inputChars[c]); - sendCmd(REPEATMODE, 1); - } - - else if (inputChars[c] == '1') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER1, 1); - } - else if (inputChars[c] == '2') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER2, 1); - } - else if (inputChars[c] == '3') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER3, 1); - } - else if (inputChars[c] == '4') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER4, 1); - } - else if (inputChars[c] == '5') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER5, 1); - } - else if (inputChars[c] == '6') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER6, 1); - } - else if (inputChars[c] == '7') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER7, 1); - } - else if (inputChars[c] == '8') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER8, 1); - } - else if (inputChars[c] == '9') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER9, 1); - } - else if (inputChars[c] == '0') - { - Serial.print(inputChars[c]); - sendNumCmd(NUMBER10, 1); - } - - else if (inputChars[c] == ' ') - { // space - Serial.print(inputChars[c]); - sendCmd(NUMBER23, 1); - } - } - - Serial.print(F("\u001b[0m\n\r\n\rTotal characters needed: ")); - Serial.print(charCount); - Serial.print(F("\n\rTotal blocks needed: ")); - Serial.print((charCount + 6) / 7); - Serial.print(F("\n\r")); -} - -void sendCmd(int command, byte repeats) -{ - for (int i = 0; i <= repeats - 1; i++) - { - sendButton(command); - delay(100); - } -} - -void sendButton(int bts) -{ - digitalWrite(tSendPin, HIGH); - for (int i = 0; i < 3; i++) - { - irsend.sendSony(bts, 12); //! Hier wird das Command gesendet! Es besteht aus dem command und der bitlänge. - delay(25); - } - digitalWrite(tSendPin, LOW); -} - -void sendNumCmd(int command, byte repeats) -{ - for (int i = 0; i <= repeats - 1; i++) - { - sendButton(NUM); - delay(1000); - sendButton(command); - delay(100); - sendButton(NUM); - delay(1000); - } -} - -void helpText() -{ - Serial.print(F("\u001b[1m\u001b[7mMinidisc Namer\u001b[0m\n\r\ -\n\r\ -\u001b[1mCommands:\u001b[0m\n\r\ -\n\r\ -\u001b[32mGeneral:\n\r\ -\u001b[0mz Previous Track\n\r\ -x Play\n\r\ -c Pause\n\r\ -v Stop\n\r\ -b Next Track\n\r\ -l Eject\n\r\ -\n\r\ -\u001b[31mRecording:\n\r\ -\u001b[0ms Record\n\r\ -S Music Sync Recording\n\r\ -i Input Selection\n\r\ -q Recording Mode\n\r\ -\n\r\ -\u001b[33mNumbers:\n\r\ -\u001b[0m0-9 Number Entry\n\r\ -=/+ >10 Entry\n\r\ -\n\r\ -\u001b[34;1mDisplay:\n\r\ -\u001b[0md Display\n\r\ -D Scroll Display\n\r\ -\n\r\ -\u001b[36mPlaymodes/Repeating:\n\r\ -\u001b[0mp Play Mode (Normal/Shuffle/Program)\n\r\ -r Repeat\n\r\ -R A <-> B\n\r\ -\n\r\ -\u001b[32;1mNaming Disc/Tracks:\n\r\ -\u001b[0m` Name Entry Mode\n\r\ -# Reset Memory Usage Stats\n\r\ -\n\r\ -\u001b[37;1mh This help list\u001b[0m\n\r\n\r")); -} - -boolean nameCheck() -{ - Serial.print(F("\n\r\n\r\n\rSend this to player (Y/N):\n\r\u001b[37;1m")); - for (byte c = 0; c < charCount; c++) - { - Serial.print(inputChars[c]); - } - Serial.print(F("\n\r\u001b[0m")); - while (!Serial.available()) - { - } - char serialChar = Serial.read(); - if (serialChar == 'Y' || serialChar == 'y') - return 1; - else - return 0; -} - -void blink() -{ - /* start testing code */ - // read the state of the pushbutton value: - buttonState = digitalRead(buttonPin); - - // check if the pushbutton is pressed. If it is, the buttonState is HIGH: - if (buttonState == HIGH) - { - // write to serial monitor: - Serial.println(F("button state is HIGH")); - // turn LED on: - digitalWrite(ledPin, HIGH); - } - else - { - // turn LED off: - digitalWrite(ledPin, LOW); - } - /* end testing code */ - - Serial.print(F("blink")); - // digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) - // delay(1000); // wait for a second - // digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW - // delay(1000); -} From 6201d0ab2b745dc26a4d5bb3985a4a6d642bdcce Mon Sep 17 00:00:00 2001 From: StrangeD0s <47105931+StrangeD0s@users.noreply.github.com> Date: Wed, 17 Jul 2024 23:15:12 +0200 Subject: [PATCH 03/13] add html and css --- Index.html | 113 +++++++++++++++++++++++++++++++++++++++++++ style.css | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+) create mode 100644 Index.html create mode 100644 style.css diff --git a/Index.html b/Index.html new file mode 100644 index 0000000..8b71a48 --- /dev/null +++ b/Index.html @@ -0,0 +1,113 @@ + + + + SONY RM-D20P Pico Remote + + + + + + + + +
+

SONY RM-D27M Remote

+ LED Test Mode +
+ +
+ + +
+
+ + + Title Editing +
+ + +
+ +
+
+ + + +
+
+ +
+
+ + + + + + + +
+
+
+ + + + + + +
+
+
+

KEY BOARD REMOTE COMMANDER

+
+ + /* + + */ + + diff --git a/style.css b/style.css new file mode 100644 index 0000000..0bc6915 --- /dev/null +++ b/style.css @@ -0,0 +1,137 @@ +:root { + --main-bg-color: #212121; + } + + body { + background-color: var(--main-bg-color); + display: flex; + flex-direction: column; + align-items: center; + font-family: Verdana, Geneva, Tahoma, sans-serif; + } + h2 { + color: white; + } + p { + color: white; + } + + textarea { + width: 100%; + height: 150px; + padding: 12px 20px; + box-sizing: border-box; + border: 2px solid #ccc; + border-radius: 4px; + background-color: #f8f8f8; + font-size: 16px; + resize: none; + } + + button { + background-color: #454545; + border: none; + border-radius: 4px; + color: white; + text-align: center; + text-decoration: none; + display: inline-flex; + font-size: 16px; + cursor: pointer; + justify-content: center; + align-items: center; + box-shadow: 2px 2px black; + height: 42px; + width: 48px; + } + + button:active { + -webkit-box-shadow: inset 0px 0px 2px black; + -moz-box-shadow: inset 0px 0px 2px black; + box-shadow: inset 0px 0px 2px black; + outline: none; + } + + .text-white { + color: white; + } + .text-orange { + color: orange; + } + + .text-with-line { + text-transform: uppercase; + display: flex; + flex-direction: row; + } + + .text-with-line:before, + .text-with-line:after { + content: ""; + flex: 1 1; + border-bottom: 2px solid currentColor; + margin: auto 5px; + } + + .smallbutton { + height: 28px; + width: 56px; + background-color: #8a8a8a; + font-size: 12px; + } + + .roundbutton { + border-radius: 50%; + width: 26px; + height: 26px; + } + + .upper-buttonbox { + margin-top: 8px; + margin-bottom: 8px; + border-radius: 8px; + background-color: #4d4d4d; + padding: 8px; + display: flex; + gap: 12px; + border: 2px solid grey; + border-bottom-color: black; + border-right-color: black; + } + + .lower-buttonbox { + margin-top: 8px; + margin-bottom: 8px; + border-radius: 8px; + background-color: #333333; + padding: 8px; + display: flex; + gap: 12px; + border: 2px solid grey; + border-bottom-color: black; + border-right-color: black; + } + + .textinput-wrapper { + display: flex; + flex-direction: column; + gap: 12px; + margin-top: 8px; + margin-bottom: 8px; + color: white; + } + + .textinput { + width: 100%; + padding: 12px 20px; + box-sizing: border-box; + border: 2px solid #ccc; + border-radius: 4px; + background-color: #f8f8f8; + font-size: 16px; + resize: none; + } + + .headline { + text-align: center; + } From 83ca883312d1e1be867a97ede2a2c7f972f1ae42 Mon Sep 17 00:00:00 2001 From: StrangeD0s <47105931+StrangeD0s@users.noreply.github.com> Date: Thu, 18 Jul 2024 23:24:43 +0200 Subject: [PATCH 04/13] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a059397..90aa4f9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Arduino Sony RM-D27M Minidisc Namer This is an arduino sketch to make an IR-remote control for easier title renaming on a Sony MDS-JE510 minidisc deck. + +- Add webserver +- Add ir remote library +- Add SD-Card support to load html and css From f48752f1c4c038d09d827850ad8023f0e60d4e5e Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sat, 20 Jul 2024 09:17:38 +0200 Subject: [PATCH 05/13] rename ino file to match folder name --- minidisc_namer_RM-D27M.ino => arduino-sony-minidisc-ir-remote.ino | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename minidisc_namer_RM-D27M.ino => arduino-sony-minidisc-ir-remote.ino (100%) diff --git a/minidisc_namer_RM-D27M.ino b/arduino-sony-minidisc-ir-remote.ino similarity index 100% rename from minidisc_namer_RM-D27M.ino rename to arduino-sony-minidisc-ir-remote.ino From 6fdba62d0e3f1013015a2533c72359adefb406e2 Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sat, 20 Jul 2024 10:22:12 +0200 Subject: [PATCH 06/13] add defines, create simple sendButton function --- .gitignore | 2 + README.md | 7 ++ arduino-sony-minidisc-ir-remote.ino | 124 ++++++++++++++-------------- defines.h | 25 ++++-- 4 files changed, 90 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index 259148f..04ae9f5 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ *.exe *.out *.app + +secrets.h \ No newline at end of file diff --git a/README.md b/README.md index 90aa4f9..f4fb913 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,10 @@ This is an arduino sketch to make an IR-remote control for easier title renaming - Add webserver - Add ir remote library - Add SD-Card support to load html and css + +Store WiFi secrets in a secrets.h like this: + +``` +#define SSID "your-ssid" +#define PASSWORD "your-password" +``` \ No newline at end of file diff --git a/arduino-sony-minidisc-ir-remote.ino b/arduino-sony-minidisc-ir-remote.ino index 1159503..1b12005 100644 --- a/arduino-sony-minidisc-ir-remote.ino +++ b/arduino-sony-minidisc-ir-remote.ino @@ -1,89 +1,81 @@ /* - WiFi Web Server LED Blink - A simple web server that lets you blink an LED via the web. - This sketch will print the IP address of your WiFi Shield (once connected) - to the Serial monitor. From there, you can open that address in a web browser - to turn on and off the LED on pin 5. + WebServer to use as replacement for Sony RM-D27M to control Sony MiniDisc decks. + + Based on the the following sketches: + - SimpleWifiServer example + - SD_Test + - IRremote/SendDemo + If the IP address of your shield is yourAddress: http://yourAddress/H turns the LED on http://yourAddress/L turns it off - This example is written for a network using WPA2 encryption. For insecure - WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly. + Circuit: - * LED attached to pin 13 + * LED attached to pin 13 (optional) * IR Transmitter attached to pin 4 + * SD-Module to load HTML and CSS from SD-card - created for arduino 25 Nov 2012 - by Tom Igoe - -ported for sparkfun esp32 -31.01.2017 by Jan Hendrik Berlin + developed for the ESP32vn IoT Uni board 2024 */ #include #include - -const char* ssid = "FritzBox-7590-NB"; -const char* password = "60762265561727730801"; +#include "secrets.h" +#include "defines.h" WiFiServer server(80); -void setup() -{ - Serial.begin(115200); - pinMode(13, OUTPUT); // set the LED pin mode +void setup() { + Serial.begin(115200); + pinMode(LED_PIN, OUTPUT); // set the LED pin mode - delay(10); + delay(10); - // We start by connecting to a WiFi network + // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(SSID); - WiFi.begin(ssid, password); + WiFi.begin(SSID, PASSWORD); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } - // Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN - uint8_t tSendPin = 4; - IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin - // You can change send pin later with IrSender.setSendPin(); - Serial.println(); - Serial.print(F("Send IR signals at pin ")); - Serial.println(tSendPin); + IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin + Serial.println(); + Serial.print(F("Send IR signals at pin ")); + Serial.println(IR_SEND_PIN); - Serial.println(); - Serial.println("WiFi connected."); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - - server.begin(); + Serial.println(); + Serial.println("WiFi connected."); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + server.begin(); } -void loop(){ - WiFiClient client = server.available(); // listen for incoming clients +void loop() { + WiFiClient client = server.available(); // listen for incoming clients - if (client) { // if you get a client, - Serial.println("New Client."); // print a message out the serial port - String currentLine = ""; // make a String to hold incoming data from the client - while (client.connected()) { // loop while the client's connected - if (client.available()) { // if there's bytes to read from the client, - char c = client.read(); // read a byte, then - Serial.write(c); // print it out the serial monitor - if (c == '\n') { // if the byte is a newline character + if (client) { // if you get a client, + Serial.println("New Client."); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: @@ -99,13 +91,13 @@ void loop(){ client.print("Click here to turn the LED on pin 13 off.
"); client.print("play
"); client.print("

"); - client.print("

"); + client.print("

"); // The HTTP response ends with another blank line: client.println(); // break out of the while loop: break; - } else { // if you got a newline, then clear currentLine: + } else { // if you got a newline, then clear currentLine: currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, @@ -114,18 +106,19 @@ void loop(){ // Check to see if the client request was "GET /H" or "GET /L": if (currentLine.endsWith("GET /H")) { - digitalWrite(13, HIGH); // GET /H turns the LED on + digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on } if (currentLine.endsWith("GET /L")) { - digitalWrite(13, LOW); // GET /L turns the LED off + digitalWrite(LED_PIN, LOW); // GET /L turns the LED off } if (currentLine.endsWith("GET /play")) { - Serial.println("MD play"); - Serial.flush(); - IrSender.sendSony(0xF, 0x2A, 2, 12); + //Serial.println("MD play"); + //Serial.flush(); + //IrSender.sendSony(0xF, PLAY, 2, 12); + sendButton(PLAY); } if (currentLine.endsWith("POST /api/control-deck")) { - + Serial.println("POST"); char c = client.read(); Serial.print(c); @@ -137,3 +130,10 @@ void loop(){ Serial.println("Client Disconnected."); } } + +void sendButton(int command) +{ + Serial.println(command); + Serial.flush(); + IrSender.sendSony(0xF, command, 2, 12); +} diff --git a/defines.h b/defines.h index 79cb0a6..bc0077a 100644 --- a/defines.h +++ b/defines.h @@ -1,5 +1,18 @@ +// Pin definitions +#define IR_SEND_PIN 4 +#define LED_PIN 13 + +// IR commands (Sony 12bit) +#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 POWER 0xA9E #define DISPLAY 0x19E #define SCROLL 0x99E #define CONTINUE 0xB9E @@ -41,11 +54,11 @@ #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 PLAY 0x55E +// #define PAUSE 0x95E +// #define STOP 0x15E +// #define AMSPREV 0x05E +// #define AMSNEXT 0x85E #define RECORD 0xB5E #define REWIND 0xD5E #define FASTFORWARD 0x35E From 1de3c787cf338b41eac23c3cdddb135660db2ef9 Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sat, 20 Jul 2024 10:45:24 +0200 Subject: [PATCH 07/13] add more control buttons for testing --- arduino-sony-minidisc-ir-remote.ino | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/arduino-sony-minidisc-ir-remote.ino b/arduino-sony-minidisc-ir-remote.ino index 1b12005..56de543 100644 --- a/arduino-sony-minidisc-ir-remote.ino +++ b/arduino-sony-minidisc-ir-remote.ino @@ -16,7 +16,7 @@ Circuit: * LED attached to pin 13 (optional) - * IR Transmitter attached to pin 4 + * IR Transmitter attached to pin 4 (needs 5v) * SD-Module to load HTML and CSS from SD-card developed for the ESP32vn IoT Uni board 2024 @@ -89,7 +89,12 @@ void loop() { // the content of the HTTP response follows the header: client.print("Click here to turn the LED on pin 13 on.
"); client.print("Click here to turn the LED on pin 13 off.
"); + client.print("power
"); client.print("play
"); + client.print("pause
"); + client.print("stop
"); + client.print("previous track
"); + client.print("next track
"); client.print("

"); client.print("

"); @@ -111,12 +116,24 @@ void loop() { if (currentLine.endsWith("GET /L")) { digitalWrite(LED_PIN, LOW); // GET /L turns the LED off } + if (currentLine.endsWith("GET /power")) { + sendButton(POWER); + } if (currentLine.endsWith("GET /play")) { - //Serial.println("MD play"); - //Serial.flush(); - //IrSender.sendSony(0xF, PLAY, 2, 12); sendButton(PLAY); } + if (currentLine.endsWith("GET /pause")) { + sendButton(PAUSE); + } + if (currentLine.endsWith("GET /stop")) { + sendButton(STOP); + } + if (currentLine.endsWith("GET /prev")) { + sendButton(PREV); + } + if (currentLine.endsWith("GET /next")) { + sendButton(NEXT); + } if (currentLine.endsWith("POST /api/control-deck")) { Serial.println("POST"); From 8a3d2ca5229b2da8e725ffe7a99a2ab330f44b59 Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sat, 20 Jul 2024 10:46:42 +0200 Subject: [PATCH 08/13] update voltage comment --- arduino-sony-minidisc-ir-remote.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-sony-minidisc-ir-remote.ino b/arduino-sony-minidisc-ir-remote.ino index 56de543..bcd1df1 100644 --- a/arduino-sony-minidisc-ir-remote.ino +++ b/arduino-sony-minidisc-ir-remote.ino @@ -16,7 +16,7 @@ Circuit: * LED attached to pin 13 (optional) - * IR Transmitter attached to pin 4 (needs 5v) + * IR Transmitter attached to pin 4 (connect to 5v or 3v3) * SD-Module to load HTML and CSS from SD-card developed for the ESP32vn IoT Uni board 2024 From 1201c81251a3013d28dd1cf160562fe1fcd600d5 Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sat, 20 Jul 2024 10:52:07 +0200 Subject: [PATCH 09/13] move html and css to sd-card folder --- Index.html => sd-card/Index.html | 0 style.css => sd-card/style.css | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Index.html => sd-card/Index.html (100%) rename style.css => sd-card/style.css (100%) diff --git a/Index.html b/sd-card/Index.html similarity index 100% rename from Index.html rename to sd-card/Index.html diff --git a/style.css b/sd-card/style.css similarity index 100% rename from style.css rename to sd-card/style.css From 11808fa87e1dccba6a463596a3c728c685e1e3bd Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sun, 21 Jul 2024 16:09:31 +0200 Subject: [PATCH 10/13] move all css inside html --- sd-card/Index.html | 167 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 144 insertions(+), 23 deletions(-) diff --git a/sd-card/Index.html b/sd-card/Index.html index 8b71a48..278a76f 100644 --- a/sd-card/Index.html +++ b/sd-card/Index.html @@ -8,8 +8,146 @@ name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> + + @@ -17,7 +155,6 @@

SONY RM-D27M Remote

LED Test Mode
-
- Title Editing
@@ -38,11 +174,11 @@
- +
- +
- - - From 0203f6c6937e93d8d5ed7582bac1650ee78e899f Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sun, 21 Jul 2024 16:38:43 +0200 Subject: [PATCH 11/13] add basic SD-card support for reading files --- arduino-sony-minidisc-ir-remote.ino | 186 ++++++++++++++++++++++++---- 1 file changed, 159 insertions(+), 27 deletions(-) diff --git a/arduino-sony-minidisc-ir-remote.ino b/arduino-sony-minidisc-ir-remote.ino index bcd1df1..f4efa5d 100644 --- a/arduino-sony-minidisc-ir-remote.ino +++ b/arduino-sony-minidisc-ir-remote.ino @@ -4,7 +4,7 @@ Based on the the following sketches: - SimpleWifiServer example - - SD_Test + - ESP32/SD_Test - IRremote/SendDemo @@ -13,15 +13,26 @@ http://yourAddress/L turns it off - Circuit: * LED attached to pin 13 (optional) * IR Transmitter attached to pin 4 (connect to 5v or 3v3) * SD-Module to load HTML and CSS from SD-card + * + * Connect the SD card to the following pins: + * + * SD Card | ESP32 + * 3v3 3.3V + * CS 5 + * MOSI 23 + * CLK 18 + * MISO 19 + * GND GND developed for the ESP32vn IoT Uni board 2024 - */ +#include "FS.h" +#include "SD.h" +#include "SPI.h" #include #include @@ -30,12 +41,153 @@ WiFiServer server(80); + +/**** SD-Card Functions ****/ +void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if(!root){ + Serial.println("Failed to open directory"); + return; + } + if(!root.isDirectory()){ + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while(file){ + if(file.isDirectory()){ + Serial.print(" DIR : "); + Serial.println(file.name()); + if(levels){ + listDir(fs, file.path(), levels -1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); + } + file = root.openNextFile(); + } +} + +void readFile(fs::FS &fs, const char * path){ + Serial.printf("Reading file: %s\n", path); + + File file = fs.open(path); + if(!file){ + Serial.println("Failed to open file for reading"); + return; + } + + Serial.print("Read from file: "); + while(file.available()){ + Serial.write(file.read()); + } + file.close(); +} + +void testFileIO(fs::FS &fs, const char * path){ + File file = fs.open(path); + static uint8_t buf[512]; + size_t len = 0; + uint32_t start = millis(); + uint32_t end = start; + if(file){ + len = file.size(); + size_t flen = len; + start = millis(); + while(len){ + size_t toRead = len; + if(toRead > 512){ + toRead = 512; + } + file.read(buf, toRead); + len -= toRead; + } + end = millis() - start; + Serial.printf("%u bytes read for %u ms\n", flen, end); + file.close(); + } else { + Serial.println("Failed to open file for reading"); + } + + + file = fs.open(path, FILE_WRITE); + if(!file){ + Serial.println("Failed to open file for writing"); + return; + } + + size_t i; + start = millis(); + for(i=0; i<2048; i++){ + file.write(buf, 512); + } + end = millis() - start; + Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end); + file.close(); +} + +/* ============ IR Functions ============ */ +void sendButton(int command) +{ + Serial.println(command); + Serial.flush(); + IrSender.sendSony(0xF, command, 2, 12); +} + +/* ============ Setup ============ */ void setup() { Serial.begin(115200); - pinMode(LED_PIN, OUTPUT); // set the LED pin mode + pinMode(LED_PIN, OUTPUT); // set the LED pin mode + delay(10); + /* ============ SD-Card Setup ============ */ + if(!SD.begin()){ + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); + + if(cardType == CARD_NONE){ + Serial.println("No SD card attached"); + return; + } + + Serial.print("SD Card Type: "); + if(cardType == CARD_MMC){ + Serial.println("MMC"); + } else if(cardType == CARD_SD){ + Serial.println("SDSC"); + } else if(cardType == CARD_SDHC){ + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } + + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); + + listDir(SD, "/", 0); + readFile(SD, "/index.html"); + Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); + Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); + + + /* ============ IR Setup ============ */ + IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin + Serial.println(); + Serial.print(F("Send IR signals at pin ")); + Serial.println(IR_SEND_PIN); + + /* ============ Webserver Setup ============ */ + // We start by connecting to a WiFi network Serial.println(); @@ -50,11 +202,6 @@ void setup() { Serial.print("."); } - IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin - Serial.println(); - Serial.print(F("Send IR signals at pin ")); - Serial.println(IR_SEND_PIN); - Serial.println(); Serial.println("WiFi connected."); Serial.println("IP address: "); @@ -63,8 +210,6 @@ void setup() { server.begin(); } - - void loop() { WiFiClient client = server.available(); // listen for incoming clients @@ -87,16 +232,8 @@ void loop() { client.println(); // the content of the HTTP response follows the header: - client.print("Click here to turn the LED on pin 13 on.
"); - client.print("Click here to turn the LED on pin 13 off.
"); - client.print("power
"); - client.print("play
"); - client.print("pause
"); - client.print("stop
"); - client.print("previous track
"); - client.print("next track
"); - client.print("
"); - client.print("

"); + client.print("Click here to turn the LED on pin 13 on.
Click here to turn the LED on pin 13 off.
power
play
pause
stop
previous track
next track
"); + client.print("


"); // The HTTP response ends with another blank line: client.println(); @@ -148,9 +285,4 @@ void loop() { } } -void sendButton(int command) -{ - Serial.println(command); - Serial.flush(); - IrSender.sendSony(0xF, command, 2, 12); -} + From 5ba38120f285c07431504be9790747f21af94cb1 Mon Sep 17 00:00:00 2001 From: StrangeD0s <47105931+StrangeD0s@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:11:58 +0200 Subject: [PATCH 12/13] remove unused css file --- README.md | 4 +- sd-card/style.css | 137 ---------------------------------------------- 2 files changed, 2 insertions(+), 139 deletions(-) delete mode 100644 sd-card/style.css diff --git a/README.md b/README.md index f4fb913..48ecb6d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This is an arduino sketch to make an IR-remote control for easier title renaming Store WiFi secrets in a secrets.h like this: -``` +```c #define SSID "your-ssid" #define PASSWORD "your-password" -``` \ No newline at end of file +``` diff --git a/sd-card/style.css b/sd-card/style.css deleted file mode 100644 index 0bc6915..0000000 --- a/sd-card/style.css +++ /dev/null @@ -1,137 +0,0 @@ -:root { - --main-bg-color: #212121; - } - - body { - background-color: var(--main-bg-color); - display: flex; - flex-direction: column; - align-items: center; - font-family: Verdana, Geneva, Tahoma, sans-serif; - } - h2 { - color: white; - } - p { - color: white; - } - - textarea { - width: 100%; - height: 150px; - padding: 12px 20px; - box-sizing: border-box; - border: 2px solid #ccc; - border-radius: 4px; - background-color: #f8f8f8; - font-size: 16px; - resize: none; - } - - button { - background-color: #454545; - border: none; - border-radius: 4px; - color: white; - text-align: center; - text-decoration: none; - display: inline-flex; - font-size: 16px; - cursor: pointer; - justify-content: center; - align-items: center; - box-shadow: 2px 2px black; - height: 42px; - width: 48px; - } - - button:active { - -webkit-box-shadow: inset 0px 0px 2px black; - -moz-box-shadow: inset 0px 0px 2px black; - box-shadow: inset 0px 0px 2px black; - outline: none; - } - - .text-white { - color: white; - } - .text-orange { - color: orange; - } - - .text-with-line { - text-transform: uppercase; - display: flex; - flex-direction: row; - } - - .text-with-line:before, - .text-with-line:after { - content: ""; - flex: 1 1; - border-bottom: 2px solid currentColor; - margin: auto 5px; - } - - .smallbutton { - height: 28px; - width: 56px; - background-color: #8a8a8a; - font-size: 12px; - } - - .roundbutton { - border-radius: 50%; - width: 26px; - height: 26px; - } - - .upper-buttonbox { - margin-top: 8px; - margin-bottom: 8px; - border-radius: 8px; - background-color: #4d4d4d; - padding: 8px; - display: flex; - gap: 12px; - border: 2px solid grey; - border-bottom-color: black; - border-right-color: black; - } - - .lower-buttonbox { - margin-top: 8px; - margin-bottom: 8px; - border-radius: 8px; - background-color: #333333; - padding: 8px; - display: flex; - gap: 12px; - border: 2px solid grey; - border-bottom-color: black; - border-right-color: black; - } - - .textinput-wrapper { - display: flex; - flex-direction: column; - gap: 12px; - margin-top: 8px; - margin-bottom: 8px; - color: white; - } - - .textinput { - width: 100%; - padding: 12px 20px; - box-sizing: border-box; - border: 2px solid #ccc; - border-radius: 4px; - background-color: #f8f8f8; - font-size: 16px; - resize: none; - } - - .headline { - text-align: center; - } From 3cc2172d5ac458903e1c9724670a88b97def3ccf Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Sun, 21 Jul 2024 19:07:58 +0200 Subject: [PATCH 13/13] update instructions --- README.md | 19 ++ arduino-sony-minidisc-ir-remote.ino | 323 ++++++++++++++++------------ 2 files changed, 203 insertions(+), 139 deletions(-) diff --git a/README.md b/README.md index 48ecb6d..0eae959 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,22 @@ Store WiFi secrets in a secrets.h like this: #define SSID "your-ssid" #define PASSWORD "your-password" ``` + +## Circuit + +Circuit: + +- LED attached to pin 13 (optional) +- IR Transmitter attached to pin 4 (connect to 5v or 3v3) +- SD-Module to load HTML and CSS from SD-card + +Connect the SD card to the following pins: + +SD Card | ESP32 +------- | ----- +3v3 | 3.3V +CS | 5 +MOSI | 23 +CLK | 18 +MISO | 19 +GND | GND diff --git a/arduino-sony-minidisc-ir-remote.ino b/arduino-sony-minidisc-ir-remote.ino index f4efa5d..e17c0dc 100644 --- a/arduino-sony-minidisc-ir-remote.ino +++ b/arduino-sony-minidisc-ir-remote.ino @@ -14,19 +14,20 @@ Circuit: - * LED attached to pin 13 (optional) - * IR Transmitter attached to pin 4 (connect to 5v or 3v3) - * SD-Module to load HTML and CSS from SD-card - * - * Connect the SD card to the following pins: - * - * SD Card | ESP32 - * 3v3 3.3V - * CS 5 - * MOSI 23 - * CLK 18 - * MISO 19 - * GND GND + - LED attached to pin 13 (optional) + - IR Transmitter attached to pin 4 (connect to 5v or 3v3) + - SD-Module to load HTML and CSS from SD-card + + Connect the SD card to the following pins: + + SD Card | ESP32 + ------- | ----- + 3v3 | 3.3V + CS | 5 + MOSI | 23 + CLK | 18 + MISO | 19 + GND | GND developed for the ESP32vn IoT Uni board 2024 */ @@ -41,98 +42,115 @@ WiFiServer server(80); +/**** SD-Card Functions ****/ +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) +{ + Serial.printf("Listing directory: %s\n", dirname); -/**** SD-Card Functions ****/ -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); + File root = fs.open(dirname); + if (!root) + { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) + { + Serial.println("Not a directory"); + return; + } - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; + File file = root.openNextFile(); + while (file) + { + if (file.isDirectory()) + { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) + { + listDir(fs, file.path(), levels - 1); + } } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.println(file.size()); - } - file = root.openNextFile(); + else + { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) +{ + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) + { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) + { + Serial.write(file.read()); + } + file.close(); } -void testFileIO(fs::FS &fs, const char * path){ - File file = fs.open(path); - static uint8_t buf[512]; - size_t len = 0; - uint32_t start = millis(); - uint32_t end = start; - if(file){ - len = file.size(); - size_t flen = len; - start = millis(); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - len -= toRead; - } - end = millis() - start; - Serial.printf("%u bytes read for %u ms\n", flen, end); - file.close(); - } else { - Serial.println("Failed to open file for reading"); - } - - - file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - - size_t i; +void testFileIO(fs::FS &fs, const char *path) +{ + File file = fs.open(path); + static uint8_t buf[512]; + size_t len = 0; + uint32_t start = millis(); + uint32_t end = start; + if (file) + { + len = file.size(); + size_t flen = len; start = millis(); - for(i=0; i<2048; i++){ - file.write(buf, 512); + while (len) + { + size_t toRead = len; + if (toRead > 512) + { + toRead = 512; + } + file.read(buf, toRead); + len -= toRead; } end = millis() - start; - Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end); + Serial.printf("%u bytes read for %u ms\n", flen, end); file.close(); + } + else + { + Serial.println("Failed to open file for reading"); + } + + file = fs.open(path, FILE_WRITE); + if (!file) + { + Serial.println("Failed to open file for writing"); + return; + } + + size_t i; + start = millis(); + for (i = 0; i < 2048; i++) + { + file.write(buf, 512); + } + end = millis() - start; + Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end); + file.close(); } -/* ============ IR Functions ============ */ +/* ============ IR Functions ============ */ void sendButton(int command) { Serial.println(command); @@ -140,35 +158,45 @@ void sendButton(int command) IrSender.sendSony(0xF, command, 2, 12); } -/* ============ Setup ============ */ -void setup() { +/* ============ Setup ============ */ +void setup() +{ Serial.begin(115200); - pinMode(LED_PIN, OUTPUT); // set the LED pin mode - + pinMode(LED_PIN, OUTPUT); // set the LED pin mode + delay(10); /* ============ SD-Card Setup ============ */ - if(!SD.begin()){ - Serial.println("Card Mount Failed"); - return; - } + if (!SD.begin()) + { + Serial.println("Card Mount Failed"); + return; + } uint8_t cardType = SD.cardType(); - if(cardType == CARD_NONE){ - Serial.println("No SD card attached"); - return; + if (cardType == CARD_NONE) + { + Serial.println("No SD card attached"); + return; } Serial.print("SD Card Type: "); - if(cardType == CARD_MMC){ - Serial.println("MMC"); - } else if(cardType == CARD_SD){ - Serial.println("SDSC"); - } else if(cardType == CARD_SDHC){ - Serial.println("SDHC"); - } else { - Serial.println("UNKNOWN"); + if (cardType == CARD_MMC) + { + Serial.println("MMC"); + } + else if (cardType == CARD_SD) + { + Serial.println("SDSC"); + } + else if (cardType == CARD_SDHC) + { + Serial.println("SDHC"); + } + else + { + Serial.println("UNKNOWN"); } uint64_t cardSize = SD.cardSize() / (1024 * 1024); @@ -179,14 +207,13 @@ void setup() { Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); - /* ============ IR Setup ============ */ - IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin + IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin Serial.println(); Serial.print(F("Send IR signals at pin ")); Serial.println(IR_SEND_PIN); - /* ============ Webserver Setup ============ */ + /* ============ Webserver Setup ============ */ // We start by connecting to a WiFi network @@ -197,7 +224,8 @@ void setup() { WiFi.begin(SSID, PASSWORD); - while (WiFi.status() != WL_CONNECTED) { + while (WiFi.status() != WL_CONNECTED) + { delay(500); Serial.print("."); } @@ -210,21 +238,27 @@ void setup() { server.begin(); } -void loop() { - WiFiClient client = server.available(); // listen for incoming clients +void loop() +{ + WiFiClient client = server.available(); // listen for incoming clients - if (client) { // if you get a client, - Serial.println("New Client."); // print a message out the serial port - String currentLine = ""; // make a String to hold incoming data from the client - while (client.connected()) { // loop while the client's connected - if (client.available()) { // if there's bytes to read from the client, - char c = client.read(); // read a byte, then - Serial.write(c); // print it out the serial monitor - if (c == '\n') { // if the byte is a newline character + if (client) + { // if you get a client, + Serial.println("New Client."); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) + { // loop while the client's connected + if (client.available()) + { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') + { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: - if (currentLine.length() == 0) { + if (currentLine.length() == 0) + { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); @@ -239,39 +273,52 @@ void loop() { client.println(); // break out of the while loop: break; - } else { // if you got a newline, then clear currentLine: + } + else + { // if you got a newline, then clear currentLine: currentLine = ""; } - } else if (c != '\r') { // if you got anything else but a carriage return character, - currentLine += c; // add it to the end of the currentLine + } + else if (c != '\r') + { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine } // Check to see if the client request was "GET /H" or "GET /L": - if (currentLine.endsWith("GET /H")) { - digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on + if (currentLine.endsWith("GET /H")) + { + digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on } - if (currentLine.endsWith("GET /L")) { - digitalWrite(LED_PIN, LOW); // GET /L turns the LED off + if (currentLine.endsWith("GET /L")) + { + digitalWrite(LED_PIN, LOW); // GET /L turns the LED off } - if (currentLine.endsWith("GET /power")) { + if (currentLine.endsWith("GET /power")) + { sendButton(POWER); } - if (currentLine.endsWith("GET /play")) { + if (currentLine.endsWith("GET /play")) + { sendButton(PLAY); } - if (currentLine.endsWith("GET /pause")) { + if (currentLine.endsWith("GET /pause")) + { sendButton(PAUSE); } - if (currentLine.endsWith("GET /stop")) { + if (currentLine.endsWith("GET /stop")) + { sendButton(STOP); } - if (currentLine.endsWith("GET /prev")) { + if (currentLine.endsWith("GET /prev")) + { sendButton(PREV); } - if (currentLine.endsWith("GET /next")) { + if (currentLine.endsWith("GET /next")) + { sendButton(NEXT); } - if (currentLine.endsWith("POST /api/control-deck")) { + if (currentLine.endsWith("POST /api/control-deck")) + { Serial.println("POST"); char c = client.read(); @@ -284,5 +331,3 @@ void loop() { Serial.println("Client Disconnected."); } } - -