From 2ddcca56ac5b7b123e14f43217915460219f9eb5 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 12 Sep 2024 08:50:59 +0200 Subject: [PATCH] version inicial --- MesaMezclasE/.theia/launch.json | 8 + MesaMezclasE/MesaMezclasE.ino | 322 ++++++++++++++++++++++ MesaMezclasE/pote.cpp | 97 +++++++ MesaMezclasE/pote.h | 53 ++++ mesa_mezclas_html/cmp_proc.py | 12 + mesa_mezclas_html/mesaMezclas - Copy.html | 51 ++++ mesa_mezclas_html/mesaMezclas.html | 45 +++ mesa_mezclas_html/mesaMezclas_comp.html | 51 ++++ mesa_mezclas_html/mesaMezclas_v2_com.html | 47 ++++ mesa_mezclas_html/out.html | 1 + 10 files changed, 687 insertions(+) create mode 100644 MesaMezclasE/.theia/launch.json create mode 100644 MesaMezclasE/MesaMezclasE.ino create mode 100644 MesaMezclasE/pote.cpp create mode 100644 MesaMezclasE/pote.h create mode 100644 mesa_mezclas_html/cmp_proc.py create mode 100644 mesa_mezclas_html/mesaMezclas - Copy.html create mode 100644 mesa_mezclas_html/mesaMezclas.html create mode 100644 mesa_mezclas_html/mesaMezclas_comp.html create mode 100644 mesa_mezclas_html/mesaMezclas_v2_com.html create mode 100644 mesa_mezclas_html/out.html diff --git a/MesaMezclasE/.theia/launch.json b/MesaMezclasE/.theia/launch.json new file mode 100644 index 0000000..7e4253b --- /dev/null +++ b/MesaMezclasE/.theia/launch.json @@ -0,0 +1,8 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + "version": "0.2.0", + "configurations": [ + + ] +} diff --git a/MesaMezclasE/MesaMezclasE.ino b/MesaMezclasE/MesaMezclasE.ino new file mode 100644 index 0000000..d5d1296 --- /dev/null +++ b/MesaMezclasE/MesaMezclasE.ino @@ -0,0 +1,322 @@ + +//#include +#include +#include +#include +#include + +#include "pote.h" //library file needed to read/write values to the DS1803 dual digital potentiometer +#define SDA_PIN 4 +#define SCL_PIN 5 +#ifndef STASSID +#define STASSID "IdhunAux" +#define STAPSK "Ardileorca1234." +#endif +char IPlocal[24]; +IPAddress ipest(192,168,2,10); +IPAddress gateway(192,168,2,1); +IPAddress subnet(255,255,255,0); +ADDRESS codes[5]; + +const char* ssid = STASSID; +const char* password = STAPSK; + +ESP8266WebServer server(80); +void setCodigos() +{ + codes[0]=A_111;//mater + codes[1]=A_001;//vinilo + codes[2]=A_010;//pc + codes[3]=A_100;//rad + codes[4]=A_000;//aux +} + +void PaginaPrincipal() { + //WiFi.localIP(); + + int v1=getvi(codes[0]); + int v2=getvi(codes[1]); + int v3=getvi(codes[2]); + int v4=getvi(codes[3]); + int v5=getvi(codes[4]); + + char st[2124]; + // sprintf(st, "", + sprintf(st, "\n\n\n\n \n Control Audio\n\n\n\n

Control Audio

\n
\nVinilo\n
\n
\nPC\n
\n
\nRadio\n
\n
\nAux\n
\n\n\n\n", + //v1, + v2, + v3, + v4, + v5, + //pan, + IPlocal); + + server.send(200,"text/html",st); + +} +float corte=20; +float setEscala(float i) +{ + float corte_max=100-corte; + Serial.print("setEscala to "); + Serial.print(i); + float res=i; + if(i0) + { + int vol=server.arg(0).toInt()-1; + vol=setEscala(vol); + //vol=101-vol;//se invierte + vol=vol; + vol=(2.55*(vol)); + if (vol>255) + vol=255; + setWiper(id,WIPER_0,vol); + setWiper(id,WIPER_1,vol); + } + server.send(200,"text/plain", "ok"); +} + +void get1() +{ + getv(codes[0]); +} +void get2() +{ + getv(codes[1]); +} +void get3() +{ + getv(codes[2]); +} +void get4() +{ + getv(codes[3]); +} +void get5() +{ + getv(codes[4]); +} + +void set1() { + setv(codes[0]); +} +void set2() { + setv(codes[1]); +} +void set3() { + setv(codes[2]); +} +void set4() { + setv(codes[3]); +} +void set5() { + setv(codes[4]); +} +/* +void setv() { + //WiFi.localIP(); + if(server.args()>0) + { + int vol=server.arg(0).toInt(); + vol=setEscala(vol); + vol=101-vol;//se invierte + /*if(vol>25) + { + int rang=vol-25; + + rang=(rang*25.0/75.); + vol=rang+75; + }* / + vol=(2.55*(vol)); + setWiper(A_000,WIPER_0,vol); + setWiper(A_000,WIPER_1,vol); + }*/ + // handleNotFound(); + + + +void otaConfig() +{ + + //ota---------------------------------- + // Port defaults to 8266 + // ArduinoOTA.setPort(8266); + + // Hostname defaults to esp8266-[ChipID] + ArduinoOTA.setHostname("ControlAudio"); + + // No authentication by default + // ArduinoOTA.setPassword("admin"); + + // Password can be set with it's md5 value as well + // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3 + // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3"); + + ArduinoOTA.onStart([]() { + String type; + if (ArduinoOTA.getCommand() == U_FLASH) { + type = "sketch"; + } else { // U_FS + type = "filesystem"; + } + #ifdef DEBUG_PS + // NOTE: if updating FS this would be the place to unmount FS using FS.end() + Serial.println("Start updating " + type); + #endif + }); + ArduinoOTA.onEnd([]() { + Serial.println("\nEnd"); + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + #ifdef DEBUG_PS + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + #endif + }); + ArduinoOTA.onError([](ota_error_t error) { + #ifdef DEBUG_PS + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) { + Serial.println("Auth Failed"); + } else if (error == OTA_BEGIN_ERROR) { + Serial.println("Begin Failed"); + } else if (error == OTA_CONNECT_ERROR) { + Serial.println("Connect Failed"); + } else if (error == OTA_RECEIVE_ERROR) { + Serial.println("Receive Failed"); + } else if (error == OTA_END_ERROR) { + Serial.println("End Failed"); + } + #endif + }); + ArduinoOTA.begin(); +} + + +void setup() { + + Wire.begin(SDA_PIN, SCL_PIN); + initDS1803(); + Serial.println("iniciando ...."); + setCodigos(); + WiFi.mode(WIFI_STA); + WiFi.config(ipest, gateway, subnet); + WiFi.begin(ssid, password); + Serial.println(""); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + strcpy(IPlocal, WiFi.localIP().toString().c_str()); + Serial.println(IPlocal); + if (MDNS.begin("esp8266")) { + Serial.println("MDNS responder started"); + } + config_URL(); + otaConfig(); +} + +void loop() { + server.handleClient(); + MDNS.update(); +} +void config_URL() +{ + server.onNotFound(handleNotFound); + server.on("/", PaginaPrincipal); + server.on("/set1", set1); + server.on("/get1", get1); + server.on("/set2", set2); + server.on("/get2", get2); + server.on("/set3", set3); + server.on("/get3", get3); + server.on("/set4", set4); + server.on("/get4", get4); + server.on("/set5", set5); + server.on("/get5", get5); + server.begin(); + Serial.println("HTTP server started"); +} + +void handleNotFound() { + String message = "File Not Found\n\n"; + message += "URI: "; + message += server.uri(); + message += "\nMethod: "; + message += (server.method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += server.args(); + message += "\n"; + for (uint8_t i = 0; i < server.args(); i++) { + message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; + } + server.send(404, "text/plain", message); +} diff --git a/MesaMezclasE/pote.cpp b/MesaMezclasE/pote.cpp new file mode 100644 index 0000000..f59adad --- /dev/null +++ b/MesaMezclasE/pote.cpp @@ -0,0 +1,97 @@ +/* ### description ### + Library file for using a DS1803 dual digital potentiometer with an arduino. + please see 'README.txt' for more information + + Copyright (C) <2020> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +//-------------------------------------------- headers -------------------------------------------- + +#include "pote.h" //header file for DS1803 library + +//-------------------------------------------- prototypes ----------------------------------------- + +//function checks to make sure only a valid wiper was selected +static int checkValidWiper(const int wiper); + +//function checks to makes sure value is a valid value in the range [0,255] +static int checkValidValue(const int value); + +//-------------------------------------------- code ----------------------------------------------- + +//function checks to make sure only a valid wiper was selected +static int checkValidWiper(const int wiper) { + char c[26]; //holds string to be printed + switch(wiper) { + case WIPER_0: //FALLTHROUGH + case WIPER_1: //FALLTHROUGH + case WIPER_BOTH: + return 1; //valid wiper so return 1; + default: + snprintf(c,26,"%#04x is incorrect wiper.",wiper); //format the string to print + Serial.println(c); //print the string to serial monitor + return 0; //invalid wiper so return 0; + } +} + +//function checks to makes sure value is a valid value in the range [0,255] +static int checkValidValue(const int value) { + char c[22]; //holds string to be printed + if(value<0 || value>255) + { + snprintf(c,22,"%d is out of range.",value); //format the string to print + Serial.println(c); //print the string to serial monitor + return 0; //incorrect value so return 0; + } + return 1; +} + +//function to set value of wiper. takes in which address of device, wiper to write to and the value to write to it. +void setWiper(const ADDRESS address,const int wiper, const int value) { + if(checkValidWiper(wiper) && checkValidValue(value)) { //if both value and wiper are valid + char c[25]; //holds string to be printed + Wire.beginTransmission(address); //begin transmiting to potentiometer at ADRESS + Wire.write(wiper); //tell it which wiper to write to + Wire.write(value); //write the value to the wiper + Wire.endTransmission(); //end transmission to the DS1803 + snprintf(c,25,"writing %d to wiper %#04x",value,wiper); //format the string to print + Serial.println(c); //print string to serial monitor + } +} + +//function which reads the current value for both wipers at given address and prints values to the serial monitor +void readWipers(const ADDRESS address, int *vals) { + int wiper = 0; //shows which wiper is being read. + char c[32]; //hold formatted string. + Wire.requestFrom(address,2);//write the value to the wiper + for(int i=0; i<50; i++) + { + while(Wire.available()) { + // slave may send less than requested + if(wiper<2) + vals[wiper]=(int)Wire.read(); + snprintf(c,15,"read w %d: %d",wiper++,(int)Wire.read()); //format the string before printing + Serial.println(c); // print the formatted string + } + delay(10); + } +} + +//function which starts serial communication and starts i2c communication with potentiometer +void initDS1803() { + Serial.begin(9600); //serial communication at 9600 baud + Wire.begin(); //init wire.h library and join the i2c bus +} diff --git a/MesaMezclasE/pote.h b/MesaMezclasE/pote.h new file mode 100644 index 0000000..8e9fa8d --- /dev/null +++ b/MesaMezclasE/pote.h @@ -0,0 +1,53 @@ +/* ### description ### + Library file for using a DS1803 dual digital potentiometer with an arduino. + please see 'README.txt' for more information + + Copyright (C) <2020> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef DS1803_H //guard against including the file more than once +#define DS1803_H +//-------------------------------------------- headers -------------------------------------------- + +#include "Arduino.h" //give access to the arduino +#include //allow library to use the arduino's I2C functions + +//-------------------------------------------- define --------------------------------------------- + +#define WIPER_0 0xA9 //write to wiper one +#define WIPER_1 0xAA //write to wiper two +#define WIPER_BOTH 0xAF //write to both wipers at once + +//---------------------------------------------- enums --------------------------------------------------- +//address of DS1803 based on the address lines A2,A1,A0. +//A_000 == address of DS1803 when A2,A1,A0 are all 0. +//A_101 is address of DS1803 when A2 = 1, A1 = 0, and A0 = 1. +enum ADDRESS_LIST {A_000 = 0x28, A_001, A_010, A_011, A_100, A_101,A_110,A_111}; + +//---------------------------------------------- typedefs ------------------------------------------------ +typedef enum ADDRESS_LIST ADDRESS; + +//-------------------------------------------- prototypes ----------------------------------------- + +//function to set value of wiper. takes in address of device, which wiper to write to and the value to write to it. +void setWiper(const ADDRESS address, const int wiper, const int value); + +//function which reads the current value for both wipers at given address and prints them to the serial monitor of the arduino +void readWipers(const ADDRESS address, int *vals);//int vals[2] + +//function which starts serial communications and starts i2c communication with potentiometer +void initDS1803(); +#endif diff --git a/mesa_mezclas_html/cmp_proc.py b/mesa_mezclas_html/cmp_proc.py new file mode 100644 index 0000000..ada0d98 --- /dev/null +++ b/mesa_mezclas_html/cmp_proc.py @@ -0,0 +1,12 @@ +import web +import os +f= open("mesaMezclas.html",'r') +res="" +for linea in f: + res=res+"\\n"+linea.strip().replace("\"","\\\"") + + +f.close() +dest =open("out.html",mode="w") +dest.write(res) +dest.close() diff --git a/mesa_mezclas_html/mesaMezclas - Copy.html b/mesa_mezclas_html/mesaMezclas - Copy.html new file mode 100644 index 0000000..860a3d2 --- /dev/null +++ b/mesa_mezclas_html/mesaMezclas - Copy.html @@ -0,0 +1,51 @@ + + + + + Control Audio + + +

Control Audio

+

Master

+
+ +
+

Entradas

+
+Vinilo +
+
+PC +
+
+Radio +
+
+Aux +
+ + + + \ No newline at end of file diff --git a/mesa_mezclas_html/mesaMezclas.html b/mesa_mezclas_html/mesaMezclas.html new file mode 100644 index 0000000..ab234f2 --- /dev/null +++ b/mesa_mezclas_html/mesaMezclas.html @@ -0,0 +1,45 @@ + + + + + Control Audio + + + +

Control Audio

+
+Vinilo +
+
+PC +
+
+Radio +
+
+Aux +
+ + + + \ No newline at end of file diff --git a/mesa_mezclas_html/mesaMezclas_comp.html b/mesa_mezclas_html/mesaMezclas_comp.html new file mode 100644 index 0000000..860a3d2 --- /dev/null +++ b/mesa_mezclas_html/mesaMezclas_comp.html @@ -0,0 +1,51 @@ + + + + + Control Audio + + +

Control Audio

+

Master

+
+ +
+

Entradas

+
+Vinilo +
+
+PC +
+
+Radio +
+
+Aux +
+ + + + \ No newline at end of file diff --git a/mesa_mezclas_html/mesaMezclas_v2_com.html b/mesa_mezclas_html/mesaMezclas_v2_com.html new file mode 100644 index 0000000..8f20ca7 --- /dev/null +++ b/mesa_mezclas_html/mesaMezclas_v2_com.html @@ -0,0 +1,47 @@ + + + + + Control Audio + + +

Control Audio

+as +
+Vinilo +
+
+PC +
+
+Radio +
+
+Aux +
+ + + + \ No newline at end of file diff --git a/mesa_mezclas_html/out.html b/mesa_mezclas_html/out.html new file mode 100644 index 0000000..37e02ee --- /dev/null +++ b/mesa_mezclas_html/out.html @@ -0,0 +1 @@ +\n\n\n\n \n Control Audio\n\n\n\n

Control Audio

\n
\nVinilo\n
\n
\nPC\n
\n
\nRadio\n
\n
\nAux\n
\n\n\n\n \ No newline at end of file