version inicial

main
Gerardo 2024-09-12 08:50:59 +02:00
commit 2ddcca56ac
10 changed files with 687 additions and 0 deletions

View File

@ -0,0 +1,8 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
]
}

View File

@ -0,0 +1,322 @@
//#include <ESP32WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#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<!DOCTYPE html>\n<html>\n<head>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <style> </style>\n<title> Control Audio</title>\n</head>\n<body>\n<body>\n<h1>Control Audio</h1>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vvin\">Vinilo\n</div>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vpc\">PC\n</div>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vrad\">Radio\n</div>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vaux\">Aux\n</div>\n\n<script>\nfunction httpGetAsync(theUrl)\n{\nvar xmlHttp = new XMLHttpRequest();\nxmlHttp.onreadystatechange = function() { };\nxmlHttp.open(\"GET\", theUrl, true);\nxmlHttp.send(null);\n}\n\nvar ip=\"http://%s\";\nvar s2 = document.getElementById(\"vvin\");\nvar s3 = document.getElementById(\"vpc\");\nvar s4 = document.getElementById(\"vrad\");\nvar s5 = document.getElementById(\"vaux\");\ns2.oninput = function() { httpGetAsync(ip+\"/set2?v=\"+this.value);}\ns3.oninput = function() { httpGetAsync(ip+\"/set3?v=\"+this.value);}\ns4.oninput = function() { httpGetAsync(ip+\"/set4?v=\"+this.value);}\ns5.oninput = function() { httpGetAsync(ip+\"/set5?v=\"+this.value);}\n\n\n</script>\n</body>\n</html>",
//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(i<corte)
{
res=i*(corte_max+1)/corte;
}
else
{
res=corte_max+1+((i-corte)*corte/(corte_max));
}
Serial.print(" out: ");
Serial.println(res);
Serial.print(" get: ");
Serial.println(getEscala(res));
return res;
}
float getEscala(float i)
{
float corte_max=100-corte;
float res=i;
if(i<corte_max)
{
res=i*(corte)/corte_max;
}
else
{
res=corte+((i-corte_max)*corte_max/corte);
}
return res;
}
void getv(ADDRESS id)
{
int vals[2];
readWipers(id, vals);
//int vmax=vals[0];
int vmax=254-vals[0];
int valor=(int)((vmax)*100./255 +0.5);
valor=(int) getEscala(valor);
String s="vol: ";
s.concat(valor+1);
server.send(200,"text/plain", s);
}
int getvi(ADDRESS id)
{
int vals[2];
readWipers(id, vals);
Serial.print("Getvi: ");
Serial.print(id);
//int vmax=254-vals[0];
int vmax=vals[0];
int valor=(int)((vmax)*100./255 +0.5);
valor=(int) getEscala(valor);
Serial.print(" out: ");
Serial.println(valor);
return valor;
}
void setv(ADDRESS id)
{
if(server.args()>0)
{
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);
}

97
MesaMezclasE/pote.cpp Normal file
View File

@ -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> <Chris Nichols. github/return5>
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 <https://www.gnu.org/licenses/>.
*/
//-------------------------------------------- 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
}

53
MesaMezclasE/pote.h Normal file
View File

@ -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> <Chris Nichols. github/return5>
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 <https://www.gnu.org/licenses/>.
*/
#ifndef DS1803_H //guard against including the file more than once
#define DS1803_H
//-------------------------------------------- headers --------------------------------------------
#include "Arduino.h" //give access to the arduino
#include <Wire.h> //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

View File

@ -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()

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <style> </style>
<title> Control Audio</title>
</head>
<body>
<h1>Control Audio</h1>
<h2>Master</h2>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vmas">
</div>
<h2>Entradas</h2>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vvin">Vinilo
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vpc">PC
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vrad">Radio
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vaux">Aux
</div>
<script>
function httpGetAsync(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { };
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
var ip="http://%s";
var sl = document.getElementById("vmas");
var s2 = document.getElementById("vvin");
var s3 = document.getElementById("vpc");
var s4 = document.getElementById("vrad");
var s5 = document.getElementById("vaux");
sl.oninput = function() { httpGetAsync(ip+"/set1?v="+this.value);}
s2.oninput = function() { httpGetAsync(ip+"/set2?v="+this.value);}
s3.oninput = function() { httpGetAsync(ip+"/set3?v="+this.value);}
s4.oninput = function() { httpGetAsync(ip+"/set4?v="+this.value);}
s5.oninput = function() { httpGetAsync(ip+"/set5?v="+this.value);}
</script>
</body>
</html>

View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <style> </style>
<title> Control Audio</title>
</head>
<body>
<body>
<h1>Control Audio</h1>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vvin">Vinilo
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vpc">PC
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vrad">Radio
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vaux">Aux
</div>
<script>
function httpGetAsync(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { };
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
var ip="http://%s";
var s2 = document.getElementById("vvin");
var s3 = document.getElementById("vpc");
var s4 = document.getElementById("vrad");
var s5 = document.getElementById("vaux");
s2.oninput = function() { httpGetAsync(ip+"/set2?v="+this.value);}
s3.oninput = function() { httpGetAsync(ip+"/set3?v="+this.value);}
s4.oninput = function() { httpGetAsync(ip+"/set4?v="+this.value);}
s5.oninput = function() { httpGetAsync(ip+"/set5?v="+this.value);}
</script>
</body>
</html>

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <style> </style>
<title> Control Audio</title>
</head>
<body>
<h1>Control Audio</h1>
<h2>Master</h2>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vmas">
</div>
<h2>Entradas</h2>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vvin">Vinilo
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vpc">PC
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vrad">Radio
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vaux">Aux
</div>
<script>
function httpGetAsync(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { };
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
var ip="http://%s";
var sl = document.getElementById("vmas");
var s2 = document.getElementById("vvin");
var s3 = document.getElementById("vpc");
var s4 = document.getElementById("vrad");
var s5 = document.getElementById("vaux");
sl.oninput = function() { httpGetAsync(ip+"/set1?v="+this.value);}
s2.oninput = function() { httpGetAsync(ip+"/set2?v="+this.value);}
s3.oninput = function() { httpGetAsync(ip+"/set3?v="+this.value);}
s4.oninput = function() { httpGetAsync(ip+"/set4?v="+this.value);}
s5.oninput = function() { httpGetAsync(ip+"/set5?v="+this.value);}
</script>
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <style> </style>
<title> Control Audio</title>
</head>
<body>
<h1>Control Audio</h1>
as</h2>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vvin">Vinilo
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vpc">PC
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vrad">Radio
</div>
<div class="slidecontainer">
<input type="range" min="1" max="101" value="%d" class="slider" id="vaux">Aux
</div>
<script>
function httpGetAsync(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() { };
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
var ip="http://%s";
var sl = document.getElementById("vmas");
var s2 = document.getElementById("vvin");
var s3 = document.getElementById("vpc");
var s4 = document.getElementById("vrad");
var s5 = document.getElementById("vaux");
sl.oninput = function() { httpGetAsync(ip+"/set1?v="+this.value);}
s2.oninput = function() { httpGetAsync(ip+"/set2?v="+this.value);}
s3.oninput = function() { httpGetAsync(ip+"/set3?v="+this.value);}
s4.oninput = function() { httpGetAsync(ip+"/set4?v="+this.value);}
s5.oninput = function() { httpGetAsync(ip+"/set5?v="+this.value);}
</script>
</body>
</html>

View File

@ -0,0 +1 @@
\n<!DOCTYPE html>\n<html>\n<head>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <style> </style>\n<title> Control Audio</title>\n</head>\n<body>\n<body>\n<h1>Control Audio</h1>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vvin\">Vinilo\n</div>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vpc\">PC\n</div>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vrad\">Radio\n</div>\n<div class=\"slidecontainer\">\n<input type=\"range\" min=\"1\" max=\"101\" value=\"%d\" class=\"slider\" id=\"vaux\">Aux\n</div>\n\n<script>\nfunction httpGetAsync(theUrl)\n{\nvar xmlHttp = new XMLHttpRequest();\nxmlHttp.onreadystatechange = function() { };\nxmlHttp.open(\"GET\", theUrl, true);\nxmlHttp.send(null);\n}\n\nvar ip=\"http://%s\";\nvar s2 = document.getElementById(\"vvin\");\nvar s3 = document.getElementById(\"vpc\");\nvar s4 = document.getElementById(\"vrad\");\nvar s5 = document.getElementById(\"vaux\");\ns2.oninput = function() { httpGetAsync(ip+\"/set2?v=\"+this.value);}\ns3.oninput = function() { httpGetAsync(ip+\"/set3?v=\"+this.value);}\ns4.oninput = function() { httpGetAsync(ip+\"/set4?v=\"+this.value);}\ns5.oninput = function() { httpGetAsync(ip+\"/set5?v=\"+this.value);}\n\n\n</script>\n</body>\n</html>