v0.7.490
This commit is contained in:
18
README.md
18
README.md
@@ -317,6 +317,24 @@ Work is in progress...
|
|||||||
|
|
||||||
---
|
---
|
||||||
## Version history
|
## Version history
|
||||||
|
#### v0.7.490
|
||||||
|
**!!! a [full update](#update-over-web-interface) with Sketch data upload is required. After updating please press CTRL+F5 in browser !!!** \
|
||||||
|
**Please backup playlist.csv and wifi.csv before updating.**
|
||||||
|
- fixed playlist break down when saving it
|
||||||
|
- fixed bug with cropped song titles on single line displays (GC9106, ST7735mini, N5110 etc.)
|
||||||
|
- netserver - optimization and refactoring
|
||||||
|
- web interface optimization
|
||||||
|
- the AUDIOBUFFER_MULTIPLIER parameter is deprecated. New parameter AUDIOBUFFER_MULTIPLIER2. If everything works fine, then it is better not to touch it.
|
||||||
|
- new setting VS_PATCH_ENABLE (see PS)
|
||||||
|
- fixing other bugs
|
||||||
|
|
||||||
|
_**PS:** A bug was found with the lack of sound on some (not all) green VS1053 boards.
|
||||||
|
If there is no sound, you need to assign in myoptions_
|
||||||
|
```
|
||||||
|
#define VS_PATCH_ENABLE false
|
||||||
|
```
|
||||||
|
_On red boards and normally working green boards, nothing else needs to be done._
|
||||||
|
|
||||||
#### v0.7.414
|
#### v0.7.414
|
||||||
- fixed non latin long titles of songs error
|
- fixed non latin long titles of songs error
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ void audio_info(const char *info) {
|
|||||||
player.mode = STOPPED;
|
player.mode = STOPPED;
|
||||||
player.stopInfo();
|
player.stopInfo();
|
||||||
}
|
}
|
||||||
if (strstr(info, "not supported") != NULL){
|
if (strstr(info, "not supported") != NULL || strstr(info, "Account already in use") != NULL){
|
||||||
config.setTitle(info);
|
config.setTitle(info);
|
||||||
netserver.requestOnChange(TITLE, 0);
|
netserver.requestOnChange(TITLE, 0);
|
||||||
player.setOutputPins(false);
|
player.setOutputPins(false);
|
||||||
@@ -47,20 +47,32 @@ bool printable(const char *info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void audio_showstation(const char *info) {
|
void audio_showstation(const char *info) {
|
||||||
|
DBGVB("[%s] info = %s", __func__, info);
|
||||||
if (strlen(info) > 0) {
|
if (strlen(info) > 0) {
|
||||||
bool p = printable(info);
|
bool p = printable(info);
|
||||||
config.setTitle(p?info:"*****");
|
config.setTitle(p?info:config.station.name);
|
||||||
netserver.requestOnChange(TITLE, 0);
|
netserver.requestOnChange(TITLE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_showstreamtitle(const char *info) {
|
void audio_showstreamtitle(const char *info) {
|
||||||
|
DBGVB("[%s] info = %s", __func__, info);
|
||||||
|
if (strstr(info, "Account already in use") != NULL){
|
||||||
|
config.setTitle(info);
|
||||||
|
netserver.requestOnChange(TITLE, 0);
|
||||||
|
player.setOutputPins(false);
|
||||||
|
player.setDefaults();
|
||||||
|
if (player_on_stop_play) player_on_stop_play();
|
||||||
|
player.mode = STOPPED;
|
||||||
|
player.stopInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (strlen(info) > 0) {
|
if (strlen(info) > 0) {
|
||||||
bool p = printable(info);
|
bool p = printable(info);
|
||||||
#ifdef DEBUG_TITLES
|
#ifdef DEBUG_TITLES
|
||||||
config.setTitle(DEBUG_TITLES);
|
config.setTitle(DEBUG_TITLES);
|
||||||
#else
|
#else
|
||||||
config.setTitle(p?info:"*****");
|
config.setTitle(p?info:config.station.name);
|
||||||
#endif
|
#endif
|
||||||
netserver.requestOnChange(TITLE, 0);
|
netserver.requestOnChange(TITLE, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ bool Config::parseSsid(const char* line, char* ssid, char* pass) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::saveWifi(const char* post) {
|
bool Config::saveWifiFromNextion(const char* post){
|
||||||
File file = SPIFFS.open(SSIDS_PATH, "w");
|
File file = SPIFFS.open(SSIDS_PATH, "w");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return false;
|
return false;
|
||||||
@@ -455,6 +455,14 @@ bool Config::saveWifi(const char* post) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Config::saveWifi() {
|
||||||
|
if (!SPIFFS.exists(TMP_PATH)) return false;
|
||||||
|
SPIFFS.remove(SSIDS_PATH);
|
||||||
|
SPIFFS.rename(TMP_PATH, SSIDS_PATH);
|
||||||
|
ESP.restart();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Config::initNetwork() {
|
bool Config::initNetwork() {
|
||||||
File file = SPIFFS.open(SSIDS_PATH, "r");
|
File file = SPIFFS.open(SSIDS_PATH, "r");
|
||||||
if (!file || file.isDirectory()) {
|
if (!file || file.isDirectory()) {
|
||||||
|
|||||||
@@ -147,7 +147,8 @@ class Config {
|
|||||||
bool parseSsid(const char* line, char* ssid, char* pass);
|
bool parseSsid(const char* line, char* ssid, char* pass);
|
||||||
void loadStation(uint16_t station);
|
void loadStation(uint16_t station);
|
||||||
bool initNetwork();
|
bool initNetwork();
|
||||||
bool saveWifi(const char* post);
|
bool saveWifi();
|
||||||
|
bool saveWifiFromNextion(const char* post);
|
||||||
void setSmartStart(byte ss);
|
void setSmartStart(byte ss);
|
||||||
void initPlaylist();
|
void initPlaylist();
|
||||||
void indexPlaylist();
|
void indexPlaylist();
|
||||||
|
|||||||
Binary file not shown.
@@ -177,6 +177,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-row last">
|
<div class="flex-row last">
|
||||||
|
<input id="file-upload" type="file" accept=".txt, .csv" hidden/>
|
||||||
<div class="button group group_system hidden" data-name="wifiexport">Export</div>
|
<div class="button group group_system hidden" data-name="wifiexport">Export</div>
|
||||||
<div class="button hlbutton" data-name="wifiupload">Save & Reboot</div>
|
<div class="button hlbutton" data-name="wifiupload">Save & Reboot</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ char *split(char *str, const char *delim) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Display::title() {
|
void Display::title() {
|
||||||
DBGVB("call of %s(), config.station.title=%s", __func__, config.station.title);
|
DBGVB("[%s] config.station.title = %s", __func__, config.station.title);
|
||||||
if (strlen(config.station.title) > 0) {
|
if (strlen(config.station.title) > 0) {
|
||||||
char tmpbuf[strlen(config.station.title)+1];
|
char tmpbuf[strlen(config.station.title)+1];
|
||||||
strlcpy(tmpbuf, config.station.title, strlen(config.station.title)+1);
|
strlcpy(tmpbuf, config.station.title, strlen(config.station.title)+1);
|
||||||
@@ -589,7 +589,7 @@ void Display::title() {
|
|||||||
title1.setText(dsp.utf8Rus(tmpbuf, true));
|
title1.setText(dsp.utf8Rus(tmpbuf, true));
|
||||||
title2.setText(dsp.utf8Rus(stitle, true));
|
title2.setText(dsp.utf8Rus(stitle, true));
|
||||||
}else{
|
}else{
|
||||||
title1.setText(dsp.utf8Rus(tmpbuf, true));
|
title1.setText(dsp.utf8Rus(config.station.title, true));
|
||||||
title2.setText(dsp.utf8Rus("", true));
|
title2.setText(dsp.utf8Rus("", true));
|
||||||
}
|
}
|
||||||
#ifdef USE_NEXTION
|
#ifdef USE_NEXTION
|
||||||
|
|||||||
@@ -25,10 +25,21 @@ AsyncUDP udp;
|
|||||||
|
|
||||||
String processor(const String& var);
|
String processor(const String& var);
|
||||||
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
|
void handleUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
|
void handleHTTPArgs(AsyncWebServerRequest * request);
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len);
|
||||||
void handleHTTPPost(AsyncWebServerRequest * request);
|
|
||||||
|
|
||||||
bool shouldReboot = false;
|
bool shouldReboot = false;
|
||||||
|
#ifdef MQTT_HOST
|
||||||
|
Ticker mqttplaylistticker;
|
||||||
|
bool mqttplaylistblock = false;
|
||||||
|
void mqttplaylistSend() {
|
||||||
|
mqttplaylistblock = true;
|
||||||
|
mqttplaylistticker.detach();
|
||||||
|
mqttPublishPlaylist();
|
||||||
|
mqttplaylistblock = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char* updateError() {
|
char* updateError() {
|
||||||
static char ret[140] = {0};
|
static char ret[140] = {0};
|
||||||
@@ -36,87 +47,45 @@ char* updateError(){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetServer::takeMallocDog(){
|
|
||||||
int mcb = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
|
||||||
int mci = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
|
||||||
(void)mci;
|
|
||||||
DBGVB("MALLOC_CAP_8BIT=%d, MALLOC_CAP_INTERNAL=%d", mcb, mci);
|
|
||||||
resumePlay = mcb < MIN_MALLOC;
|
|
||||||
if (resumePlay) {
|
|
||||||
player.toggle();
|
|
||||||
vTaskDelay(150);
|
|
||||||
xSemaphoreTake(player.playmutex, portMAX_DELAY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetServer::giveMallocDog(){
|
|
||||||
if (resumePlay) {
|
|
||||||
resumePlay = false;
|
|
||||||
vTaskDelay(150);
|
|
||||||
xSemaphoreGive(player.playmutex);
|
|
||||||
player.toggle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetServer::begin() {
|
bool NetServer::begin() {
|
||||||
importRequest = false;
|
importRequest = IMDONE;
|
||||||
irRecordEnable = false;
|
irRecordEnable = false;
|
||||||
webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
|
webserver.on("/", HTTP_ANY, handleHTTPArgs);
|
||||||
if (network.status == CONNECTED) {
|
webserver.on(PLAYLIST_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
netserver.htmlPath = PINDEX;
|
webserver.on(INDEX_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
netserver.chunkedHtmlPage(String(), request);
|
webserver.on(SSIDS_PATH, HTTP_GET, handleHTTPArgs);
|
||||||
}else{
|
webserver.on("/upload", HTTP_POST, beginUpload, handleUpload);
|
||||||
netserver.htmlPath = PSETTINGS;
|
webserver.on("/update", HTTP_GET, handleHTTPArgs);
|
||||||
netserver.chunkedHtmlPage(String(), request);
|
webserver.on("/update", HTTP_POST, beginUpdate, handleUpdate);
|
||||||
}
|
webserver.on("/settings", HTTP_GET, handleHTTPArgs);
|
||||||
});
|
if (IR_PIN != 255) webserver.on("/ir", HTTP_GET, handleHTTPArgs);
|
||||||
|
|
||||||
webserver.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=31536000");
|
webserver.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=31536000");
|
||||||
|
#ifdef CORS_DEBUG
|
||||||
webserver.on("/", HTTP_POST, [](AsyncWebServerRequest * request) {
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Origin"), F("*"));
|
||||||
handleHTTPPost(request);
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Headers"), F("content-type"));
|
||||||
});
|
|
||||||
webserver.on(PLAYLIST_PATH, HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
netserver.takeMallocDog();
|
|
||||||
request->send(SPIFFS, PLAYLIST_PATH, "application/octet-stream");
|
|
||||||
netserver.giveMallocDog();
|
|
||||||
DBGVB("PLAYLIST_PATH client ip=%s", request->client()->remoteIP().toString().c_str());
|
|
||||||
/*netserver.htmlPath = PPLAYLIST; // TODO
|
|
||||||
netserver.chunkedHtmlPage("application/octet-stream", request);
|
|
||||||
netserver.giveMallocDog();*/
|
|
||||||
});
|
|
||||||
webserver.on(INDEX_PATH, HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
request->send(SPIFFS, INDEX_PATH, "application/octet-stream");
|
|
||||||
});
|
|
||||||
webserver.on(SSIDS_PATH, HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
netserver.htmlPath = PSSIDS;
|
|
||||||
netserver.chunkedHtmlPage("application/octet-stream", request);
|
|
||||||
});
|
|
||||||
webserver.on("/upload", HTTP_POST, [](AsyncWebServerRequest * request) {
|
|
||||||
//request->send(200);
|
|
||||||
|
|
||||||
}, handleUpload);
|
|
||||||
webserver.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
||||||
netserver.htmlPath = PUPDATE;
|
|
||||||
netserver.chunkedHtmlPage(String(), request);
|
|
||||||
});
|
|
||||||
webserver.on("/settings", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
||||||
netserver.htmlPath = PSETTINGS;
|
|
||||||
netserver.chunkedHtmlPage(String(), request);
|
|
||||||
});
|
|
||||||
|
|
||||||
#if IR_PIN!=255
|
|
||||||
webserver.on("/ir", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
||||||
netserver.htmlPath = PIR;
|
|
||||||
netserver.chunkedHtmlPage(String(), request);
|
|
||||||
});
|
|
||||||
#endif
|
#endif
|
||||||
webserver.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
|
webserver.begin();
|
||||||
|
websocket.onEvent(onWsEvent);
|
||||||
|
webserver.addHandler(&websocket);
|
||||||
|
|
||||||
|
//echo -n "helle?" | socat - udp-datagram:255.255.255.255:44490,broadcast
|
||||||
|
if (udp.listen(44490)) {
|
||||||
|
udp.onPacket([](AsyncUDPPacket packet) {
|
||||||
|
if (strcmp((char*)packet.data(), "helle?") == 0)
|
||||||
|
packet.println(WiFi.localIP());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetServer::beginUpdate(AsyncWebServerRequest *request) {
|
||||||
shouldReboot = !Update.hasError();
|
shouldReboot = !Update.hasError();
|
||||||
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", shouldReboot ? "OK" : updateError());
|
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", shouldReboot ? "OK" : updateError());
|
||||||
response->addHeader("Connection", "close");
|
response->addHeader("Connection", "close");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
|
}
|
||||||
|
|
||||||
|
void handleUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
if (!index) {
|
if (!index) {
|
||||||
int target = (request->getParam("updatetarget", true)->value() == "spiffs") ? U_SPIFFS : U_FLASH;
|
int target = (request->getParam("updatetarget", true)->value() == "spiffs") ? U_SPIFFS : U_FLASH;
|
||||||
Serial.printf("Update Start: %s\n", filename.c_str());
|
Serial.printf("Update Start: %s\n", filename.c_str());
|
||||||
@@ -141,85 +110,70 @@ bool NetServer::begin() {
|
|||||||
request->send(200, "text/html", updateError());
|
request->send(200, "text/html", updateError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
#ifdef CORS_DEBUG
|
|
||||||
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Origin"), F("*"));
|
|
||||||
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Headers"), F("content-type"));
|
|
||||||
#endif
|
|
||||||
webserver.begin();
|
|
||||||
websocket.onEvent(onWsEvent);
|
|
||||||
webserver.addHandler(&websocket);
|
|
||||||
|
|
||||||
//echo -n "helle?" | socat - udp-datagram:255.255.255.255:44490,broadcast
|
|
||||||
if (udp.listen(44490)) {
|
|
||||||
udp.onPacket([](AsyncUDPPacket packet) {
|
|
||||||
if (strcmp((char*)packet.data(), "helle?") == 0)
|
|
||||||
packet.println(WiFi.localIP());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetServer::chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request){
|
void NetServer::beginUpload(AsyncWebServerRequest *request) {
|
||||||
max = heap_caps_get_free_size(MALLOC_CAP_8BIT) / 32;
|
if (request->hasParam("plfile", true, true)) {
|
||||||
htmlpos = 0;
|
netserver.importRequest = IMPL;
|
||||||
theend = false;
|
request->send(200);
|
||||||
DBGVB("chunkedHtmlPage client ip=%s", request->client()->remoteIP().toString().c_str());
|
} else if (request->hasParam("wifile", true, true)) {
|
||||||
AsyncWebServerResponse *response = request->beginChunkedResponse(contentType, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
|
netserver.importRequest = IMWIFI;
|
||||||
if(netserver.theend) return 0;
|
request->send(200);
|
||||||
File htmlpage;
|
} else {
|
||||||
switch(netserver.htmlPath){
|
request->send(404);
|
||||||
case PINDEX: {
|
|
||||||
htmlpage = SPIFFS.open("/www/index.html", "r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PSETTINGS: {
|
|
||||||
htmlpage = SPIFFS.open("/www/settings.html", "r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PUPDATE: {
|
|
||||||
htmlpage = SPIFFS.open("/www/update.html", "r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIR: {
|
|
||||||
htmlpage = SPIFFS.open("/www/ir.html", "r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PPLAYLIST: {
|
|
||||||
htmlpage = SPIFFS.open(PLAYLIST_PATH, "r");
|
|
||||||
DBGVB("SPIFFS.open(PLAYLIST_PATH)");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PSSIDS: {
|
|
||||||
htmlpage = SPIFFS.open(SSIDS_PATH, "r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!htmlpage) return 0;
|
|
||||||
uint32_t htmlpagesize = htmlpage.size();
|
size_t NetServer::chunkedHtmlPageCallback(uint8_t* buffer, size_t maxLen, size_t index){
|
||||||
uint32_t len = htmlpagesize - netserver.htmlpos;
|
File requiredfile = SPIFFS.open(netserver.chunkedPathBuffer, "r");
|
||||||
if (len > maxLen) len = maxLen;
|
if (!requiredfile) return 0;
|
||||||
if (len > netserver.max) len = netserver.max;
|
size_t filesize = requiredfile.size();
|
||||||
if (len + netserver.htmlpos > htmlpagesize) {
|
size_t needread = filesize - index;
|
||||||
netserver.theend = true;
|
if (!needread) return 0;
|
||||||
len = htmlpagesize - netserver.htmlpos;
|
size_t canread = (needread > maxLen) ? maxLen : needread;
|
||||||
|
DBGVB("[%s] seek to %d in %s and read %d bytes with maxLen=%d", __func__, index, netserver.chunkedPathBuffer, canread, maxLen);
|
||||||
|
requiredfile.seek(index, SeekSet);
|
||||||
|
requiredfile.read(buffer, canread);
|
||||||
|
index += canread;
|
||||||
|
if (requiredfile) requiredfile.close();
|
||||||
|
return canread;
|
||||||
}
|
}
|
||||||
if (len > 0) {
|
|
||||||
DBGVB("seek to %d in %s and read %d bytes", netserver.htmlpos, htmlpage.name(), len);
|
void NetServer::chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request, const char * path, bool gzip) {
|
||||||
htmlpage.seek(netserver.htmlpos, SeekSet);
|
memset(chunkedPathBuffer, 0, sizeof(chunkedPathBuffer));
|
||||||
htmlpage.read(buffer, len);
|
strlcpy(chunkedPathBuffer, path, sizeof(chunkedPathBuffer)-1);
|
||||||
netserver.htmlpos = netserver.htmlpos + len;
|
PLOW();
|
||||||
}
|
AsyncWebServerResponse *response = request->beginChunkedResponse(contentType, chunkedHtmlPageCallback, processor);
|
||||||
if(htmlpage) htmlpage.close();
|
xSemaphoreTake(player.playmutex, portMAX_DELAY);
|
||||||
return len;
|
|
||||||
}, processor); // AsyncWebServerResponse
|
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
xSemaphoreGive(player.playmutex); PHIG();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
void NetServer::chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request, const char * path, bool gzip) {
|
||||||
|
static char pathbuffer[40] = { 0 };
|
||||||
|
strlcpy(pathbuffer, path, 39);
|
||||||
|
PLOW();
|
||||||
|
AsyncWebServerResponse *response = request->beginChunkedResponse(contentType, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
|
||||||
|
File requiredfile = SPIFFS.open(pathbuffer, "r");
|
||||||
|
if (!requiredfile) return 0;
|
||||||
|
size_t filesize = requiredfile.size();
|
||||||
|
size_t needread = filesize - index;
|
||||||
|
if (!needread) return 0;
|
||||||
|
size_t canread = (needread > maxLen) ? maxLen : needread;
|
||||||
|
DBGVB("[%s] seek to %d in %s and read %d bytes with maxLen=%d", __func__, index, pathbuffer, canread, maxLen);
|
||||||
|
requiredfile.seek(index, SeekSet);
|
||||||
|
requiredfile.read(buffer, canread);
|
||||||
|
index += canread;
|
||||||
|
if (requiredfile) requiredfile.close();
|
||||||
|
return canread;
|
||||||
|
}, processor); // AsyncWebServerResponse
|
||||||
|
|
||||||
|
xSemaphoreTake(player.playmutex, portMAX_DELAY);
|
||||||
|
request->send(response);
|
||||||
|
xSemaphoreGive(player.playmutex);
|
||||||
|
PHIG();
|
||||||
|
}
|
||||||
|
*/
|
||||||
void NetServer::loop() {
|
void NetServer::loop() {
|
||||||
if (shouldReboot) {
|
if (shouldReboot) {
|
||||||
Serial.println("Rebooting...");
|
Serial.println("Rebooting...");
|
||||||
@@ -227,20 +181,15 @@ void NetServer::loop() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
websocket.cleanupClients();
|
websocket.cleanupClients();
|
||||||
if (playlistrequest > 0) {
|
//if (playlistrequest > 0) { requestOnChange(PLAYLIST, playlistrequest); playlistrequest = 0; } /* Cleanup this */
|
||||||
requestOnChange(PLAYLIST, playlistrequest);
|
switch (importRequest) {
|
||||||
playlistrequest = 0;
|
case IMPL: importPlaylist(); importRequest = IMDONE; break;
|
||||||
}
|
case IMWIFI: config.saveWifi(); importRequest = IMDONE; break;
|
||||||
if (importRequest) {
|
default: break;
|
||||||
if (importPlaylist()) {
|
|
||||||
requestOnChange(PLAYLIST, 0);
|
|
||||||
}
|
|
||||||
importRequest = false;
|
|
||||||
}
|
|
||||||
if (rssi < 255) {
|
|
||||||
requestOnChange(NRSSI, 0);
|
|
||||||
}
|
}
|
||||||
|
if (rssi < 255) requestOnChange(NRSSI, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IR_PIN!=255
|
#if IR_PIN!=255
|
||||||
void NetServer::irToWs(const char* protocol, uint64_t irvalue) {
|
void NetServer::irToWs(const char* protocol, uint64_t irvalue) {
|
||||||
char buf[BUFLEN] = { 0 };
|
char buf[BUFLEN] = { 0 };
|
||||||
@@ -254,45 +203,21 @@ void NetServer::irValsToWs(){
|
|||||||
websocket.textAll(buf);
|
websocket.textAll(buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t clientId) {
|
void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t clientId) {
|
||||||
AwsFrameInfo *info = (AwsFrameInfo*)arg;
|
AwsFrameInfo *info = (AwsFrameInfo*)arg;
|
||||||
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
|
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
|
||||||
data[len] = 0;
|
data[len] = 0;
|
||||||
char cmd[65], val[65];
|
char cmd[65], val[65];
|
||||||
if (config.parseWsCommand((const char*)data, cmd, val, 65)) {
|
if (config.parseWsCommand((const char*)data, cmd, val, 65)) {
|
||||||
if (strcmp(cmd, "getmode") == 0) {
|
if (strcmp(cmd, "getmode") == 0 ) { requestOnChange(GETMODE, clientId); return; }
|
||||||
requestOnChange(GETMODE,clientId);
|
if (strcmp(cmd, "getindex") == 0 ) { requestOnChange(GETINDEX, clientId); return; }
|
||||||
return;
|
if (strcmp(cmd, "getsystem") == 0 ) { requestOnChange(GETSYSTEM, clientId); return; }
|
||||||
}
|
if (strcmp(cmd, "getscreen") == 0 ) { requestOnChange(GETSCREEN, clientId); return; }
|
||||||
if (strcmp(cmd, "getindex") == 0) {
|
if (strcmp(cmd, "gettimezone") == 0 ) { requestOnChange(GETTIMEZONE, clientId); return; }
|
||||||
requestOnChange(GETINDEX,clientId);
|
if (strcmp(cmd, "getcontrols") == 0 ) { requestOnChange(GETCONTROLS, clientId); return; }
|
||||||
return;
|
if (strcmp(cmd, "getweather") == 0 ) { requestOnChange(GETWEATHER, clientId); return; }
|
||||||
}
|
if (strcmp(cmd, "getactive") == 0 ) { requestOnChange(GETACTIVE, clientId); return; }
|
||||||
if (strcmp(cmd, "getsystem") == 0) {
|
|
||||||
requestOnChange(GETSYSTEM,clientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (strcmp(cmd, "getscreen") == 0) {
|
|
||||||
requestOnChange(GETSCREEN,clientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (strcmp(cmd, "gettimezone") == 0) {
|
|
||||||
requestOnChange(GETTIMEZONE,clientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (strcmp(cmd, "getcontrols") == 0) {
|
|
||||||
requestOnChange(GETCONTROLS,clientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (strcmp(cmd, "getweather") == 0) {
|
|
||||||
requestOnChange(GETWEATHER,clientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (strcmp(cmd, "getactive") == 0) {
|
|
||||||
requestOnChange(GETACTIVE,clientId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(cmd, "smartstart") == 0) {
|
if (strcmp(cmd, "smartstart") == 0) {
|
||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
config.store.smartstart = valb == 1 ? 1 : 2;
|
config.store.smartstart = valb == 1 ? 1 : 2;
|
||||||
@@ -304,16 +229,14 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
config.store.audioinfo = valb;
|
config.store.audioinfo = valb;
|
||||||
config.save();
|
config.save();
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "vumeter") == 0) {
|
if (strcmp(cmd, "vumeter") == 0) {
|
||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
config.store.vumeter = valb;
|
config.store.vumeter = valb;
|
||||||
config.save();
|
config.save();
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "softap") == 0) {
|
if (strcmp(cmd, "softap") == 0) {
|
||||||
@@ -333,11 +256,9 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
config.store.numplaylist = valb;
|
config.store.numplaylist = valb;
|
||||||
config.save();
|
config.save();
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cmd, "fliptouch") == 0) {
|
if (strcmp(cmd, "fliptouch") == 0) {
|
||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
config.store.fliptouch = valb == 1;
|
config.store.fliptouch = valb == 1;
|
||||||
@@ -356,22 +277,18 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
config.store.flipscreen = valb;
|
config.store.flipscreen = valb;
|
||||||
config.save();
|
config.save();
|
||||||
display.flip();
|
display.flip();
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "brightness") == 0) {
|
if (strcmp(cmd, "brightness") == 0) {
|
||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
if (!config.store.dspon) requestOnChange(DSPON, 0);
|
if (!config.store.dspon) requestOnChange(DSPON, 0);
|
||||||
config.store.brightness = valb;
|
config.store.brightness = valb;
|
||||||
//display.setContrast();
|
|
||||||
config.setBrightness(true);
|
config.setBrightness(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "screenon") == 0) {
|
if (strcmp(cmd, "screenon") == 0) {
|
||||||
byte valb = atoi(val);
|
byte valb = atoi(val);
|
||||||
//config.store.dspon=valb==1;
|
|
||||||
//config.setBrightness(true);
|
|
||||||
config.setDspOn(valb == 1);
|
config.setDspOn(valb == 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -412,7 +329,6 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cmd, "volsteps") == 0) {
|
if (strcmp(cmd, "volsteps") == 0) {
|
||||||
uint8_t valb = atoi(val);
|
uint8_t valb = atoi(val);
|
||||||
config.store.volsteps = valb;
|
config.store.volsteps = valb;
|
||||||
@@ -439,8 +355,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
#ifdef USE_NEXTION
|
#ifdef USE_NEXTION
|
||||||
nextion.startWeather();
|
nextion.startWeather();
|
||||||
#endif
|
#endif
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "lat") == 0) {
|
if (strcmp(cmd, "lat") == 0) {
|
||||||
@@ -458,8 +373,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
#ifdef USE_NEXTION
|
#ifdef USE_NEXTION
|
||||||
nextion.startWeather();
|
nextion.startWeather();
|
||||||
#endif
|
#endif
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* RESETS */
|
/* RESETS */
|
||||||
@@ -470,8 +384,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
config.store.vumeter = false;
|
config.store.vumeter = false;
|
||||||
config.store.softapdelay = 0;
|
config.store.softapdelay = 0;
|
||||||
config.save();
|
config.save();
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
requestOnChange(GETSYSTEM, clientId);
|
requestOnChange(GETSYSTEM, clientId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -487,8 +400,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
display.setContrast();
|
display.setContrast();
|
||||||
config.store.numplaylist = false;
|
config.store.numplaylist = false;
|
||||||
config.save();
|
config.save();
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
requestOnChange(GETSCREEN, clientId);
|
requestOnChange(GETSCREEN, clientId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -513,8 +425,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
#ifdef USE_NEXTION
|
#ifdef USE_NEXTION
|
||||||
nextion.startWeather();
|
nextion.startWeather();
|
||||||
#endif
|
#endif
|
||||||
display.putRequest({NEWMODE, CLEAR});
|
display.putRequest({NEWMODE, CLEAR}); display.putRequest({NEWMODE, PLAYER});
|
||||||
display.putRequest({NEWMODE, PLAYER});
|
|
||||||
requestOnChange(GETWEATHER, clientId);
|
requestOnChange(GETWEATHER, clientId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -527,37 +438,11 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
requestOnChange(GETCONTROLS, clientId);
|
requestOnChange(GETCONTROLS, clientId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} /* RESETS */
|
} /* EOF RESETS */
|
||||||
if (strcmp(cmd, "volume") == 0) {
|
if (strcmp(cmd, "volume") == 0) {
|
||||||
byte v = atoi(val);
|
byte v = atoi(val);
|
||||||
player.setVol(v, false);
|
player.setVol(v, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* REMOVE FROM POST
|
|
||||||
* if (request->hasParam("trebble", true)) {
|
|
||||||
AsyncWebParameter* pt = request->getParam("trebble", true);
|
|
||||||
AsyncWebParameter* pm = request->getParam("middle", true);
|
|
||||||
AsyncWebParameter* pb = request->getParam("bass", true);
|
|
||||||
int t = atoi(pt->value().c_str());
|
|
||||||
int m = atoi(pm->value().c_str());
|
|
||||||
int b = atoi(pb->value().c_str());
|
|
||||||
//setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass)
|
|
||||||
player.setTone(b, m, t);
|
|
||||||
config.setTone(b, m, t);
|
|
||||||
netserver.requestOnChange(EQUALIZER, 0);
|
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (request->hasParam("ballance", true)) {
|
|
||||||
AsyncWebParameter* p = request->getParam("ballance", true);
|
|
||||||
int b = atoi(p->value().c_str());
|
|
||||||
player.setBalance(b);
|
|
||||||
config.setBalance(b);
|
|
||||||
netserver.requestOnChange(BALANCE, 0);
|
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (strcmp(cmd, "balance") == 0) {
|
if (strcmp(cmd, "balance") == 0) {
|
||||||
int8_t valb = atoi(val);
|
int8_t valb = atoi(val);
|
||||||
player.setBalance(valb);
|
player.setBalance(valb);
|
||||||
@@ -587,25 +472,19 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "submitplaylist") == 0) {
|
if (strcmp(cmd, "submitplaylist") == 0) {
|
||||||
if(player.isRunning()){
|
// xSemaphoreTake(player.playmutex, portMAX_DELAY);
|
||||||
player.toggle();
|
|
||||||
while (player.isRunning()) {
|
|
||||||
vTaskDelay(10);
|
|
||||||
}
|
|
||||||
vTaskDelay(50);
|
|
||||||
resumePlay=true;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "submitplaylistdone") == 0) {
|
if (strcmp(cmd, "submitplaylistdone") == 0) {
|
||||||
if(resumePlay){
|
|
||||||
vTaskDelay(100);
|
|
||||||
player.toggle();
|
|
||||||
resumePlay=false;
|
|
||||||
}
|
|
||||||
#ifdef MQTT_HOST
|
#ifdef MQTT_HOST
|
||||||
mqttPublishPlaylist();
|
//mqttPublishPlaylist();
|
||||||
|
mqttplaylistticker.attach(5, mqttplaylistSend);
|
||||||
#endif
|
#endif
|
||||||
|
// xSemaphoreGive(player.playmutex);
|
||||||
|
if (player.isRunning()) {
|
||||||
|
player.request.station = config.store.lastStation;
|
||||||
|
player.request.doSave = false;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if IR_PIN!=255
|
#if IR_PIN!=255
|
||||||
@@ -628,36 +507,10 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetServer::setRSSI(int val) {
|
|
||||||
rssi = val;
|
|
||||||
//requestOnChange(NRSSI, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetServer::getPlaylist(uint8_t clientId) {
|
void NetServer::getPlaylist(uint8_t clientId) {
|
||||||
char buf[160] = {0};
|
char buf[160] = {0};
|
||||||
sprintf(buf, "{\"file\": \"http://%s%s\"}", WiFi.localIP().toString().c_str(), PLAYLIST_PATH);
|
sprintf(buf, "{\"file\": \"http://%s%s\"}", WiFi.localIP().toString().c_str(), PLAYLIST_PATH);
|
||||||
if (clientId == 0) {
|
if (clientId == 0) { websocket.textAll(buf); } else { websocket.text(clientId, buf); }
|
||||||
websocket.textAll(buf);
|
|
||||||
} else {
|
|
||||||
websocket.text(clientId, buf);
|
|
||||||
}
|
|
||||||
if (resumePlay) {
|
|
||||||
resumePlay = false;
|
|
||||||
player.toggle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NetServer::savePlaylist(const char* post) {
|
|
||||||
File file = SPIFFS.open(PLAYLIST_PATH, "w");
|
|
||||||
if (!file) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
file.print(post);
|
|
||||||
file.close();
|
|
||||||
vTaskDelay(150);
|
|
||||||
netserver.requestOnChange(PLAYLISTSAVED, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetServer::importPlaylist() {
|
bool NetServer::importPlaylist() {
|
||||||
@@ -708,180 +561,71 @@ bool NetServer::importPlaylist() {
|
|||||||
void NetServer::requestOnChange(requestType_e request, uint8_t clientId) {
|
void NetServer::requestOnChange(requestType_e request, uint8_t clientId) {
|
||||||
char buf[BUFLEN * 2] = { 0 };
|
char buf[BUFLEN * 2] = { 0 };
|
||||||
switch (request) {
|
switch (request) {
|
||||||
case PLAYLIST: {
|
case PLAYLIST: getPlaylist(clientId); break;
|
||||||
getPlaylist(clientId);
|
case PLAYLISTSAVED: config.indexPlaylist(); config.initPlaylist(); getPlaylist(clientId); break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PLAYLISTSAVED: {
|
|
||||||
config.indexPlaylist();
|
|
||||||
config.initPlaylist();
|
|
||||||
getPlaylist(clientId);
|
|
||||||
/*#ifdef MQTT_HOST
|
|
||||||
mqttPublishPlaylist();
|
|
||||||
#endif*/
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GETACTIVE: {
|
case GETACTIVE: {
|
||||||
bool dbgact = false;
|
bool dbgact = false;
|
||||||
String act = "\"group_wifi\",";
|
String act = "\"group_wifi\",";
|
||||||
if (network.status == CONNECTED) {
|
if (network.status == CONNECTED) {
|
||||||
act += "\"group_system\",";
|
act += "\"group_system\",";
|
||||||
if(BRIGHTNESS_PIN!=255 || DSP_FLIPPED==1 || DSP_MODEL==DSP_NOKIA5110 || dbgact){
|
if (BRIGHTNESS_PIN != 255 || DSP_FLIPPED == 1 || DSP_MODEL == DSP_NOKIA5110 || dbgact) act += "\"group_display\",";
|
||||||
act+="\"group_display\",";
|
|
||||||
}
|
|
||||||
#ifdef USE_NEXTION
|
#ifdef USE_NEXTION
|
||||||
act += "\"group_nextion\",";
|
act += "\"group_nextion\",";
|
||||||
if (WEATHER_READY==0 || dbgact){
|
if (WEATHER_READY == 0 || dbgact) act += "\"group_weather\",";
|
||||||
act+="\"group_weather\",";
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(LCD_I2C) || DSP_OLED
|
#if defined(LCD_I2C) || DSP_OLED
|
||||||
act += "\"group_oled\",";
|
act += "\"group_oled\",";
|
||||||
#endif
|
#endif
|
||||||
if(VU_READY==1 || dbgact){
|
if (VU_READY == 1 || dbgact) act += "\"group_vu\",";
|
||||||
act+="\"group_vu\",";
|
if (BRIGHTNESS_PIN != 255 || dbgact) act += "\"group_brightness\",";
|
||||||
}
|
if (DSP_FLIPPED == 1 || dbgact) act += "\"group_tft\",";
|
||||||
if(BRIGHTNESS_PIN!=255 || dbgact){
|
if (TS_CS != 255 || dbgact) act += "\"group_touch\",";
|
||||||
act+="\"group_brightness\",";
|
if (DSP_MODEL == DSP_NOKIA5110) act += "\"group_nokia\",";
|
||||||
}
|
if (DSP_MODEL != DSP_DUMMY || dbgact) act += "\"group_timezone\",";
|
||||||
if(DSP_FLIPPED==1 || dbgact){
|
if (WEATHER_READY == 1 || dbgact) act += "\"group_weather\",";
|
||||||
act+="\"group_tft\",";
|
|
||||||
}
|
|
||||||
if(TS_CS!=255 || dbgact){
|
|
||||||
act+="\"group_touch\",";
|
|
||||||
}
|
|
||||||
if(DSP_MODEL==DSP_NOKIA5110){
|
|
||||||
act+="\"group_nokia\",";
|
|
||||||
}
|
|
||||||
if(DSP_MODEL!=DSP_DUMMY || dbgact){
|
|
||||||
act+="\"group_timezone\",";
|
|
||||||
|
|
||||||
}
|
|
||||||
if (WEATHER_READY==1 || dbgact){
|
|
||||||
act+="\"group_weather\",";
|
|
||||||
}
|
|
||||||
act += "\"group_controls\",";
|
act += "\"group_controls\",";
|
||||||
if(ENC_BTNL!=255 || ENC2_BTNL!=255 || dbgact){
|
if (ENC_BTNL != 255 || ENC2_BTNL != 255 || dbgact) act += "\"group_encoder\",";
|
||||||
act+="\"group_encoder\",";
|
if (IR_PIN != 255 || dbgact) act += "\"group_ir\",";
|
||||||
}
|
|
||||||
if(IR_PIN!=255 || dbgact){
|
|
||||||
act+="\"group_ir\",";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
act = act.substring(0, act.length() - 1);
|
act = act.substring(0, act.length() - 1);
|
||||||
sprintf (buf, "{\"act\":[%s]}", act.c_str());
|
sprintf (buf, "{\"act\":[%s]}", act.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GETMODE: {
|
case GETMODE: sprintf (buf, "{\"pmode\":\"%s\"}", network.status == CONNECTED ? "player" : "ap"); break;
|
||||||
sprintf (buf, "{\"pmode\":\"%s\"}", network.status == CONNECTED?"player":"ap");
|
case GETINDEX: requestOnChange(STATION, clientId); requestOnChange(TITLE, clientId); requestOnChange(VOLUME, clientId); requestOnChange(EQUALIZER, clientId); requestOnChange(BALANCE, clientId); requestOnChange(BITRATE, clientId); requestOnChange(MODE, clientId); return; break;
|
||||||
break;
|
case GETSYSTEM: sprintf (buf, "{\"sst\":%d,\"aif\":%d,\"vu\":%d,\"softr\":%d}", config.store.smartstart != 2, config.store.audioinfo, config.store.vumeter, config.store.softapdelay); break;
|
||||||
}
|
case GETSCREEN: sprintf (buf, "{\"flip\":%d,\"inv\":%d,\"nump\":%d,\"tsf\":%d,\"tsd\":%d,\"dspon\":%d,\"br\":%d,\"con\":%d}", config.store.flipscreen, config.store.invertdisplay, config.store.numplaylist, config.store.fliptouch, config.store.dbgtouch, config.store.dspon, config.store.brightness, config.store.contrast); break;
|
||||||
case GETINDEX: {
|
case GETTIMEZONE: sprintf (buf, "{\"tzh\":%d,\"tzm\":%d,\"sntp1\":\"%s\",\"sntp2\":\"%s\"}", config.store.tzHour, config.store.tzMin, config.store.sntp1, config.store.sntp2); break;
|
||||||
requestOnChange(STATION, clientId);
|
case GETWEATHER: sprintf (buf, "{\"wen\":%d,\"wlat\":\"%s\",\"wlon\":\"%s\",\"wkey\":\"%s\"}", config.store.showweather, config.store.weatherlat, config.store.weatherlon, config.store.weatherkey); break;
|
||||||
requestOnChange(TITLE, clientId);
|
case GETCONTROLS: sprintf (buf, "{\"vols\":%d,\"enca\":%d,\"irtl\":%d}", config.store.volsteps, config.store.encacc, config.store.irtlp); break;
|
||||||
requestOnChange(VOLUME, clientId);
|
case DSPON: sprintf (buf, "{\"dspontrue\":%d}", 1); break;
|
||||||
requestOnChange(EQUALIZER, clientId);
|
case STATION: sprintf (buf, "{\"nameset\": \"%s\"}", config.station.name); requestOnChange(ITEM, clientId); break;
|
||||||
requestOnChange(BALANCE, clientId);
|
case ITEM: sprintf (buf, "{\"current\": %d}", config.store.lastStation); break;
|
||||||
requestOnChange(BITRATE, clientId);
|
case TITLE: sprintf (buf, "{\"meta\": \"%s\"}", config.station.title); if (player.requestToStart) { telnet.info(); player.requestToStart = false; } else { telnet.printf("##CLI.META#: %s\n> ", config.station.title); } break;
|
||||||
requestOnChange(MODE, clientId);
|
case VOLUME: sprintf (buf, "{\"vol\": %d}", config.store.volume); break;
|
||||||
//playlistrequest = clientId; /* Cleanup this */
|
case NRSSI: sprintf (buf, "{\"rssi\": %d}", rssi); rssi = 255; break;
|
||||||
return;
|
case BITRATE: sprintf (buf, "{\"bitrate\": %d}", config.station.bitrate); break;
|
||||||
break;
|
case MODE: sprintf (buf, "{\"mode\": \"%s\"}", player.mode == PLAYING ? "playing" : "stopped"); break;
|
||||||
}
|
case EQUALIZER: sprintf (buf, "{\"bass\": %d, \"middle\": %d, \"trebble\": %d}", config.store.bass, config.store.middle, config.store.trebble); DBGVB("[%s] %s", __func__, buf); break;
|
||||||
case GETSYSTEM: {
|
case BALANCE: sprintf (buf, "{\"balance\": %d}", config.store.balance); break;
|
||||||
sprintf (buf, "{\"sst\":%d,\"aif\":%d,\"vu\":%d,\"softr\":%d}", config.store.smartstart!=2, config.store.audioinfo, config.store.vumeter, config.store.softapdelay);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GETSCREEN: {
|
|
||||||
sprintf (buf, "{\"flip\":%d,\"inv\":%d,\"nump\":%d,\"tsf\":%d,\"tsd\":%d,\"dspon\":%d,\"br\":%d,\"con\":%d}", config.store.flipscreen, config.store.invertdisplay, config.store.numplaylist, config.store.fliptouch, config.store.dbgtouch, config.store.dspon, config.store.brightness, config.store.contrast);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GETTIMEZONE: {
|
|
||||||
sprintf (buf, "{\"tzh\":%d,\"tzm\":%d,\"sntp1\":\"%s\",\"sntp2\":\"%s\"}", config.store.tzHour, config.store.tzMin, config.store.sntp1, config.store.sntp2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GETWEATHER: {
|
|
||||||
sprintf (buf, "{\"wen\":%d,\"wlat\":\"%s\",\"wlon\":\"%s\",\"wkey\":\"%s\"}", config.store.showweather, config.store.weatherlat, config.store.weatherlon, config.store.weatherkey);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GETCONTROLS: {
|
|
||||||
sprintf (buf, "{\"vols\":%d,\"enca\":%d,\"irtl\":%d}", config.store.volsteps, config.store.encacc, config.store.irtlp);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DSPON: {
|
|
||||||
sprintf (buf, "{\"dspontrue\":%d}", 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATION: {
|
|
||||||
sprintf (buf, "{\"nameset\": \"%s\"}", config.station.name);
|
|
||||||
requestOnChange(ITEM, clientId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ITEM: {
|
|
||||||
sprintf (buf, "{\"current\": %d}", config.store.lastStation);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TITLE: {
|
|
||||||
sprintf (buf, "{\"meta\": \"%s\"}", config.station.title);
|
|
||||||
if (player.requestToStart) {
|
|
||||||
telnet.info();
|
|
||||||
player.requestToStart = false;
|
|
||||||
} else {
|
|
||||||
telnet.printf("##CLI.META#: %s\n> ", config.station.title);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case VOLUME: {
|
|
||||||
sprintf (buf, "{\"vol\": %d}", config.store.volume);
|
|
||||||
#ifdef MQTT_HOST
|
|
||||||
if (clientId == 0) mqttPublishVolume();
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NRSSI: {
|
|
||||||
sprintf (buf, "{\"rssi\": %d}", rssi);
|
|
||||||
rssi = 255;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BITRATE: {
|
|
||||||
sprintf (buf, "{\"bitrate\": %d}", config.station.bitrate);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MODE: {
|
|
||||||
sprintf (buf, "{\"mode\": \"%s\"}", player.mode == PLAYING ? "playing" : "stopped");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case EQUALIZER: {
|
|
||||||
sprintf (buf, "{\"bass\": %d, \"middle\": %d, \"trebble\": %d}", config.store.bass, config.store.middle, config.store.trebble);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BALANCE: {
|
|
||||||
sprintf (buf, "{\"balance\": %d}", config.store.balance);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (strlen(buf) > 0) {
|
if (strlen(buf) > 0) {
|
||||||
if (clientId == 0) {
|
if (clientId == 0) { websocket.textAll(buf); }else{ websocket.text(clientId, buf); }
|
||||||
websocket.textAll(buf);
|
|
||||||
#ifdef MQTT_HOST
|
#ifdef MQTT_HOST
|
||||||
if (request == STATION || request == ITEM || request == TITLE || request == MODE) mqttPublishStatus();
|
if (clientId == 0 && (request == STATION || request == ITEM || request == TITLE || request == MODE)) mqttPublishStatus();
|
||||||
|
if (clientId == 0 && request == VOLUME) mqttPublishVolume();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
websocket.text(clientId, buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String processor(const String& var) { // %Templates%
|
String processor(const String& var) { // %Templates%
|
||||||
if (var == "VERSION") {
|
if (var == "VERSION") return VERSION;
|
||||||
return VERSION;
|
|
||||||
}
|
|
||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
if (!index) {
|
if (!index) {
|
||||||
netserver.takeMallocDog();
|
PLOW();
|
||||||
request->_tempFile = SPIFFS.open(TMP_PATH , "w");
|
request->_tempFile = SPIFFS.open(TMP_PATH , "w");
|
||||||
}
|
}
|
||||||
if (len) {
|
if (len) {
|
||||||
@@ -890,130 +634,97 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
|
|||||||
}
|
}
|
||||||
if (final) {
|
if (final) {
|
||||||
request->_tempFile.close();
|
request->_tempFile.close();
|
||||||
netserver.importRequest = true;
|
PHIG();
|
||||||
request->send(200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WS_EVT_CONNECT:
|
case WS_EVT_CONNECT: if (config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str()); break;
|
||||||
if(config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
|
case WS_EVT_DISCONNECT: if (config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u disconnected\n", client->id()); break;
|
||||||
/*netserver.requestOnChange(STATION, client->id());
|
case WS_EVT_DATA: netserver.onWsMessage(arg, data, len, client->id()); break;
|
||||||
netserver.requestOnChange(TITLE, client->id());
|
|
||||||
netserver.requestOnChange(VOLUME, client->id());
|
|
||||||
netserver.requestOnChange(EQUALIZER, client->id());
|
|
||||||
netserver.requestOnChange(BALANCE, client->id());
|
|
||||||
netserver.requestOnChange(BITRATE, client->id());
|
|
||||||
netserver.requestOnChange(MODE, client->id());
|
|
||||||
netserver.playlistrequest = client->id();*/
|
|
||||||
|
|
||||||
break;
|
|
||||||
case WS_EVT_DISCONNECT:
|
|
||||||
if(config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u disconnected\n", client->id());
|
|
||||||
break;
|
|
||||||
case WS_EVT_DATA:
|
|
||||||
netserver.onWsMessage(arg, data, len, client->id());
|
|
||||||
break;
|
|
||||||
case WS_EVT_PONG:
|
case WS_EVT_PONG:
|
||||||
case WS_EVT_ERROR:
|
case WS_EVT_ERROR:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHTTPPost(AsyncWebServerRequest * request) {
|
void handleHTTPArgs(AsyncWebServerRequest * request) {
|
||||||
if (request->hasParam("wifisettings", true)) {
|
if (request->method() == HTTP_GET) {
|
||||||
AsyncWebParameter* p = request->getParam("wifisettings", true);
|
DBGVB("[%s] client ip=%s request of %s", __func__, request->client()->remoteIP().toString().c_str(), request->url().c_str());
|
||||||
if (p->value() != "") {
|
if (strcmp(request->url().c_str(), PLAYLIST_PATH) == 0 || strcmp(request->url().c_str(), SSIDS_PATH) == 0 || strcmp(request->url().c_str(), INDEX_PATH) == 0 || strcmp(request->url().c_str(), TMP_PATH) == 0) {
|
||||||
config.saveWifi(p->value().c_str());
|
#ifdef MQTT_HOST
|
||||||
}
|
if (strcmp(request->url().c_str(), PLAYLIST_PATH) == 0) while (mqttplaylistblock) vTaskDelay(5);
|
||||||
request->send(200);
|
#endif
|
||||||
|
netserver.chunkedHtmlPage("application/octet-stream", request, request->url().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request->hasParam("playlist", true)) {
|
if (strcmp(request->url().c_str(), "/") == 0 && request->params() == 0) {
|
||||||
AsyncWebParameter* p = request->getParam("playlist", true);
|
netserver.chunkedHtmlPage(String(), request, network.status == CONNECTED ? "/www/index.html" : "/www/settings.html");
|
||||||
netserver.savePlaylist(p->value().c_str());
|
|
||||||
request->send(200);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (network.status != CONNECTED) {
|
if (strcmp(request->url().c_str(), "/update") == 0 || strcmp(request->url().c_str(), "/settings") == 0 || strcmp(request->url().c_str(), "/ir") == 0) {
|
||||||
request->send(404);
|
char buf[40] = { 0 };
|
||||||
|
sprintf(buf, "/www%s.html", request->url().c_str());
|
||||||
|
netserver.chunkedHtmlPage(String(), request, buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request->hasParam("start", true)) {
|
|
||||||
player.request.station = config.store.lastStation;
|
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (request->hasParam("stop", true)) {
|
if (network.status == CONNECTED) {
|
||||||
|
if (request->hasArg("start")) player.request.station = config.store.lastStation;
|
||||||
|
if (request->hasArg("stop")) {
|
||||||
player.mode = STOPPED;
|
player.mode = STOPPED;
|
||||||
//display.title("[stopped]");
|
|
||||||
config.setTitle("[stopped]");
|
config.setTitle("[stopped]");
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (request->hasParam("prev", true)) {
|
if (request->hasArg("prev")) player.prev();
|
||||||
player.prev();
|
if (request->hasArg("next")) player.next();
|
||||||
request->send(200);
|
if (request->hasArg("volm")) player.stepVol(false);
|
||||||
return;
|
if (request->hasArg("volp")) player.stepVol(true);
|
||||||
}
|
|
||||||
if (request->hasParam("next", true)) {
|
if (request->hasArg("trebble") && request->hasArg("middle") && request->hasArg("bass")) {
|
||||||
player.next();
|
AsyncWebParameter* pt = request->getParam("trebble", request->method() == HTTP_POST);
|
||||||
request->send(200);
|
AsyncWebParameter* pm = request->getParam("middle", request->method() == HTTP_POST);
|
||||||
return;
|
AsyncWebParameter* pb = request->getParam("bass", request->method() == HTTP_POST);
|
||||||
}
|
|
||||||
if (request->hasParam("volm", true)) {
|
|
||||||
player.stepVol(false);
|
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (request->hasParam("volp", true)) {
|
|
||||||
player.stepVol(true);
|
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (request->hasParam("vol", true)) {
|
|
||||||
AsyncWebParameter* p = request->getParam("vol", true);
|
|
||||||
int v = atoi(p->value().c_str());
|
|
||||||
if (v < 0) v = 0;
|
|
||||||
if (v > 254) v = 254;
|
|
||||||
player.setVol(v, false);
|
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (request->hasParam("trebble", true)) {
|
|
||||||
AsyncWebParameter* pt = request->getParam("trebble", true);
|
|
||||||
AsyncWebParameter* pm = request->getParam("middle", true);
|
|
||||||
AsyncWebParameter* pb = request->getParam("bass", true);
|
|
||||||
int t = atoi(pt->value().c_str());
|
int t = atoi(pt->value().c_str());
|
||||||
int m = atoi(pm->value().c_str());
|
int m = atoi(pm->value().c_str());
|
||||||
int b = atoi(pb->value().c_str());
|
int b = atoi(pb->value().c_str());
|
||||||
//setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass)
|
|
||||||
player.setTone(b, m, t);
|
player.setTone(b, m, t);
|
||||||
config.setTone(b, m, t);
|
config.setTone(b, m, t);
|
||||||
netserver.requestOnChange(EQUALIZER, 0);
|
netserver.requestOnChange(EQUALIZER, 0);
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (request->hasParam("ballance", true)) {
|
if (request->hasArg("ballance")) {
|
||||||
AsyncWebParameter* p = request->getParam("ballance", true);
|
AsyncWebParameter* p = request->getParam("ballance", request->method() == HTTP_POST);
|
||||||
int b = atoi(p->value().c_str());
|
int b = atoi(p->value().c_str());
|
||||||
player.setBalance(b);
|
player.setBalance(b);
|
||||||
config.setBalance(b);
|
config.setBalance(b);
|
||||||
netserver.requestOnChange(BALANCE, 0);
|
netserver.requestOnChange(BALANCE, 0);
|
||||||
request->send(200);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (request->hasParam("playstation", true)) {
|
if (request->hasArg("playstation") || request->hasArg("play")) {
|
||||||
AsyncWebParameter* p = request->getParam("playstation", true);
|
AsyncWebParameter* p = request->getParam(request->hasArg("playstation") ? "playstation" : "play", request->method() == HTTP_POST);
|
||||||
int id = atoi(p->value().c_str());
|
int id = atoi(p->value().c_str());
|
||||||
if (id < 1) id = 1;
|
if (id < 1) id = 1;
|
||||||
if (id > config.store.countStation) id = config.store.countStation;
|
if (id > config.store.countStation) id = config.store.countStation;
|
||||||
player.request.station = id;
|
player.request.station = id;
|
||||||
player.request.doSave = true;
|
player.request.doSave = true;
|
||||||
|
DBGVB("[%s] play=%d", __func__, id);
|
||||||
|
}
|
||||||
|
if (request->hasArg("vol")) {
|
||||||
|
AsyncWebParameter* p = request->getParam("vol", request->method() == HTTP_POST);
|
||||||
|
int v = atoi(p->value().c_str());
|
||||||
|
if (v < 0) v = 0;
|
||||||
|
if (v > 254) v = 254;
|
||||||
|
config.store.volume = v;
|
||||||
|
player.setVol(v, false);
|
||||||
|
DBGVB("[%s] vol=%d", __func__, v);
|
||||||
|
}
|
||||||
|
if (request->params() > 0) {
|
||||||
request->send(200);
|
request->send(200);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (request->params() > 0) {
|
||||||
request->send(404);
|
request->send(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,38 +6,38 @@
|
|||||||
#include "AsyncUDP.h"
|
#include "AsyncUDP.h"
|
||||||
|
|
||||||
enum requestType_e : uint8_t { PLAYLIST=1, STATION=2, ITEM=3, TITLE=4, VOLUME=5, NRSSI=6, BITRATE=7, MODE=8, EQUALIZER=9, BALANCE=10, PLAYLISTSAVED=11, GETMODE=12, GETINDEX=13, GETACTIVE=14, GETSYSTEM=15, GETSCREEN=16, GETTIMEZONE=17, GETWEATHER=18, GETCONTROLS=19, DSPON=20 };
|
enum requestType_e : uint8_t { PLAYLIST=1, STATION=2, ITEM=3, TITLE=4, VOLUME=5, NRSSI=6, BITRATE=7, MODE=8, EQUALIZER=9, BALANCE=10, PLAYLISTSAVED=11, GETMODE=12, GETINDEX=13, GETACTIVE=14, GETSYSTEM=15, GETSCREEN=16, GETTIMEZONE=17, GETWEATHER=18, GETCONTROLS=19, DSPON=20 };
|
||||||
enum htmlPath_e : uint8_t { PINDEX=1, PSETTINGS=2, PUPDATE=3, PIR=4, PPLAYLIST=5, PSSIDS=6 };
|
enum import_e : uint8_t { IMDONE=0, IMPL=1, IMWIFI=2 };
|
||||||
|
|
||||||
|
#define PLOW() //player.setBufsize(1600*2, -1); vTaskDelay(150)
|
||||||
|
#define PHIG() //vTaskDelay(150); player.setBufsize(1600*AUDIOBUFFER_MULTIPLIER2, -1)
|
||||||
|
|
||||||
class NetServer {
|
class NetServer {
|
||||||
public:
|
public:
|
||||||
uint8_t playlistrequest; // ClientId want the playlist
|
//uint8_t playlistrequest; // ClientId want the playlist/* Cleanup this */
|
||||||
bool importRequest;
|
import_e importRequest;
|
||||||
bool resumePlay;
|
bool resumePlay;
|
||||||
htmlPath_e htmlPath;
|
char chunkedPathBuffer[40];
|
||||||
public:
|
public:
|
||||||
NetServer() {};
|
NetServer() {};
|
||||||
bool begin();
|
bool begin();
|
||||||
void loop();
|
void loop();
|
||||||
void requestOnChange(requestType_e request, uint8_t clientId);
|
void requestOnChange(requestType_e request, uint8_t clientId);
|
||||||
void setRSSI(int val);
|
void setRSSI(int val) { rssi = val; };
|
||||||
|
void chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request, const char * path, bool gzip = false);
|
||||||
void onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t clientId);
|
void onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t clientId);
|
||||||
bool savePlaylist(const char* post);
|
|
||||||
void takeMallocDog();
|
|
||||||
void giveMallocDog();
|
|
||||||
uint32_t max, htmlpos;
|
|
||||||
bool theend;
|
|
||||||
#if IR_PIN!=255
|
#if IR_PIN!=255
|
||||||
bool irRecordEnable;
|
bool irRecordEnable;
|
||||||
void irToWs(const char* protocol, uint64_t irvalue);
|
void irToWs(const char* protocol, uint64_t irvalue);
|
||||||
void irValsToWs();
|
void irValsToWs();
|
||||||
void chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request);
|
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
requestType_e request;
|
requestType_e request;
|
||||||
int rssi;
|
int rssi;
|
||||||
|
|
||||||
void getPlaylist(uint8_t clientId);
|
void getPlaylist(uint8_t clientId);
|
||||||
bool importPlaylist();
|
bool importPlaylist();
|
||||||
|
static size_t chunkedHtmlPageCallback(uint8_t* buffer, size_t maxLen, size_t index);
|
||||||
|
static void beginUpload(AsyncWebServerRequest *request);
|
||||||
|
static void beginUpdate(AsyncWebServerRequest *request);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NetServer netserver;
|
extern NetServer netserver;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef options_h
|
#ifndef options_h
|
||||||
#define options_h
|
#define options_h
|
||||||
|
|
||||||
#define VERSION "0.7.414"
|
#define VERSION "0.7.490"
|
||||||
|
|
||||||
/*******************************************************
|
/*******************************************************
|
||||||
DO NOT EDIT THIS FILE.
|
DO NOT EDIT THIS FILE.
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ void Player::stopInfo() {
|
|||||||
|
|
||||||
void Player::loop() {
|
void Player::loop() {
|
||||||
if (mode == PLAYING) {
|
if (mode == PLAYING) {
|
||||||
|
xSemaphoreTake(playmutex, portMAX_DELAY);
|
||||||
Audio::loop();
|
Audio::loop();
|
||||||
|
xSemaphoreGive(playmutex);
|
||||||
|
vTaskDelay(2);
|
||||||
} else {
|
} else {
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
//digitalWrite(LED_BUILTIN, LOW);
|
//digitalWrite(LED_BUILTIN, LOW);
|
||||||
@@ -71,7 +74,6 @@ void Player::loop() {
|
|||||||
//stopSong();
|
//stopSong();
|
||||||
setDefaults();
|
setDefaults();
|
||||||
stopInfo();
|
stopInfo();
|
||||||
xSemaphoreGive(playmutex);
|
|
||||||
if (player_on_stop_play) player_on_stop_play();
|
if (player_on_stop_play) player_on_stop_play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,8 +114,6 @@ void Player::setOutputPins(bool isPlaying) {
|
|||||||
|
|
||||||
void Player::play(uint16_t stationId) {
|
void Player::play(uint16_t stationId) {
|
||||||
//stopSong();
|
//stopSong();
|
||||||
xSemaphoreGive(playmutex);
|
|
||||||
xSemaphoreTake(playmutex, portMAX_DELAY);
|
|
||||||
setDefaults();
|
setDefaults();
|
||||||
setOutputPins(false);
|
setOutputPins(false);
|
||||||
config.setTitle("[connecting]");
|
config.setTitle("[connecting]");
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
#include <FFat.h>
|
#include <FFat.h>
|
||||||
#endif // SDFATFS_USED
|
#endif // SDFATFS_USED
|
||||||
|
|
||||||
#ifndef AUDIOBUFFER_MULTIPLIER
|
#ifndef AUDIOBUFFER_MULTIPLIER2
|
||||||
#define AUDIOBUFFER_MULTIPLIER 12
|
#define AUDIOBUFFER_MULTIPLIER2 8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SDFATFS_USED
|
#ifdef SDFATFS_USED
|
||||||
@@ -140,7 +140,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
size_t m_buffSizePSRAM = 300000; // most webstreams limit the advance to 100...300Kbytes
|
size_t m_buffSizePSRAM = 300000; // most webstreams limit the advance to 100...300Kbytes
|
||||||
//size_t m_buffSizeRAM = 1600 * 5;
|
//size_t m_buffSizeRAM = 1600 * 5;
|
||||||
size_t m_buffSizeRAM = 1600 * AUDIOBUFFER_MULTIPLIER;
|
size_t m_buffSizeRAM = 1600 * AUDIOBUFFER_MULTIPLIER2;
|
||||||
size_t m_buffSize = 0;
|
size_t m_buffSize = 0;
|
||||||
size_t m_freeSpace = 0;
|
size_t m_freeSpace = 0;
|
||||||
size_t m_writeSpace = 0;
|
size_t m_writeSpace = 0;
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
* Updated on: Aug 15.2022
|
* Updated on: Aug 15.2022
|
||||||
* Author: Wolle
|
* Author: Wolle
|
||||||
*/
|
*/
|
||||||
|
#ifndef VS_PATCH_ENABLE
|
||||||
|
#define VS_PATCH_ENABLE true
|
||||||
|
#endif
|
||||||
#include "audioVS1053Ex.h"
|
#include "audioVS1053Ex.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -325,7 +327,7 @@ void Audio::begin(){
|
|||||||
setVUmeter();
|
setVUmeter();
|
||||||
m_endFillByte = wram_read(0x1E06) & 0xFF;
|
m_endFillByte = wram_read(0x1E06) & 0xFF;
|
||||||
// printDetails("After last clocksetting \n");
|
// printDetails("After last clocksetting \n");
|
||||||
loadUserCode(); // load in VS1053B if you want to play flac
|
if(VS_PATCH_ENABLE) loadUserCode(); // load in VS1053B if you want to play flac
|
||||||
startSong();
|
startSong();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -1613,6 +1615,7 @@ void Audio::setDefaults(){
|
|||||||
* \n The VU meter takes about 0.2MHz of processing power with 48 kHz samplerate.
|
* \n The VU meter takes about 0.2MHz of processing power with 48 kHz samplerate.
|
||||||
*/
|
*/
|
||||||
void Audio::setVUmeter() {
|
void Audio::setVUmeter() {
|
||||||
|
if(!VS_PATCH_ENABLE) return;
|
||||||
uint16_t MP3Status = read_register(SCI_STATUS);
|
uint16_t MP3Status = read_register(SCI_STATUS);
|
||||||
if(MP3Status==0) {
|
if(MP3Status==0) {
|
||||||
Serial.println("VS1053 Error: Unable to write SCI_STATUS");
|
Serial.println("VS1053 Error: Unable to write SCI_STATUS");
|
||||||
@@ -1636,6 +1639,7 @@ void Audio::setVUmeter() {
|
|||||||
* \warning This feature is only available with patches that support VU meter.
|
* \warning This feature is only available with patches that support VU meter.
|
||||||
*/
|
*/
|
||||||
void Audio::getVUlevel() {
|
void Audio::getVUlevel() {
|
||||||
|
if(!VS_PATCH_ENABLE) return;
|
||||||
if(!_vuInitalized) return;
|
if(!_vuInitalized) return;
|
||||||
int16_t reg = read_register(SCI_AICTRL3);
|
int16_t reg = read_register(SCI_AICTRL3);
|
||||||
uint8_t rl = map((uint8_t)reg, 85, 92, 0, 255);
|
uint8_t rl = map((uint8_t)reg, 85, 92, 0, 255);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#ifndef _vs1053_ext
|
#ifndef _vs1053_ext
|
||||||
#define _vs1053_ext
|
#define _vs1053_ext
|
||||||
|
|
||||||
#ifndef AUDIOBUFFER_MULTIPLIER
|
#ifndef AUDIOBUFFER_MULTIPLIER2
|
||||||
#define AUDIOBUFFER_MULTIPLIER 12
|
#define AUDIOBUFFER_MULTIPLIER2 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define VS1053VOLM 128 // 128 or 96 only
|
#define VS1053VOLM 128 // 128 or 96 only
|
||||||
@@ -97,7 +97,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
const size_t m_buffSizePSRAM = 300000; // most webstreams limit the advance to 100...300Kbytes
|
const size_t m_buffSizePSRAM = 300000; // most webstreams limit the advance to 100...300Kbytes
|
||||||
//const size_t m_buffSizeRAM = 1600 * 10;
|
//const size_t m_buffSizeRAM = 1600 * 10;
|
||||||
const size_t m_buffSizeRAM = 1600 * AUDIOBUFFER_MULTIPLIER;
|
const size_t m_buffSizeRAM = 1600 * AUDIOBUFFER_MULTIPLIER2;
|
||||||
size_t m_buffSize = 0;
|
size_t m_buffSize = 0;
|
||||||
size_t m_freeSpace = 0;
|
size_t m_freeSpace = 0;
|
||||||
size_t m_writeSpace = 0;
|
size_t m_writeSpace = 0;
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ void Nextion::loop() {
|
|||||||
wifisettings+=(String(scanBuf)+"\n");
|
wifisettings+=(String(scanBuf)+"\n");
|
||||||
}
|
}
|
||||||
if (sscanf(rxbuf, "wifidone=%d", &scanDigit) == 1){
|
if (sscanf(rxbuf, "wifidone=%d", &scanDigit) == 1){
|
||||||
config.saveWifi(wifisettings.c_str());
|
config.saveWifiFromNextion(wifisettings.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user