Skip to content

Commit 9ad82ac

Browse files
committed
v0.9.380
1 parent 3f5ed09 commit 9ad82ac

File tree

9 files changed

+77
-13
lines changed

9 files changed

+77
-13
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ Work is in progress...
234234

235235
---
236236
## Version history
237+
### v0.9.380
238+
- fixed compilation error for ESP32 cores >= 3.1.0
239+
- fixed freezing error with incorrectly configured RTC module
240+
- [www|uart|telnet] new command `mode` - change SD/WEB mode. (0 - WEB, 1 - SD, 2 - Toggle)
241+
example: http://<ipaddr>/?mode=2
242+
237243
#### v0.9.375
238244
- fixed the issue with saving settings for TIMEZONE.
239245

yoRadio/src/AsyncWebServer/AsyncTCP.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ extern "C"{
3131
}
3232
#include "esp_task_wdt.h"
3333

34+
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 1, 0)
35+
#define TCP_MUTEX_LOCK() \
36+
if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
37+
LOCK_TCPIP_CORE(); \
38+
}
39+
40+
#define TCP_MUTEX_UNLOCK() \
41+
if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
42+
UNLOCK_TCPIP_CORE(); \
43+
}
44+
#else
45+
#define TCP_MUTEX_LOCK()
46+
#define TCP_MUTEX_UNLOCK()
47+
#endif
3448
/*
3549
* TCP/IP Event Task
3650
* */
@@ -690,10 +704,11 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){
690704
ip_addr_t addr;
691705
addr.type = IPADDR_TYPE_V4;
692706
addr.u_addr.ip4.addr = ip;
693-
707+
TCP_MUTEX_LOCK();
694708
tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
695709
if (!pcb){
696710
log_e("pcb == NULL");
711+
TCP_MUTEX_UNLOCK();
697712
return false;
698713
}
699714

@@ -702,6 +717,7 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){
702717
tcp_recv(pcb, &_tcp_recv);
703718
tcp_sent(pcb, &_tcp_sent);
704719
tcp_poll(pcb, &_tcp_poll, 1);
720+
TCP_MUTEX_UNLOCK();
705721
//_tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
706722
_tcp_connect(pcb, _closed_slot, &addr, port,(tcp_connected_fn)&_tcp_connected);
707723
return true;
@@ -714,8 +730,9 @@ bool AsyncClient::connect(const char* host, uint16_t port){
714730
log_e("failed to start task");
715731
return false;
716732
}
717-
733+
TCP_MUTEX_LOCK();
718734
err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_tcp_dns_found, this);
735+
TCP_MUTEX_UNLOCK();
719736
if(err == ERR_OK) {
720737
return connect(IPAddress(addr.u_addr.ip4.addr), port);
721738
} else if(err == ERR_INPROGRESS) {
@@ -803,11 +820,13 @@ int8_t AsyncClient::_close(){
803820
int8_t err = ERR_OK;
804821
if(_pcb) {
805822
//log_i("");
823+
TCP_MUTEX_LOCK();
806824
tcp_arg(_pcb, NULL);
807825
tcp_sent(_pcb, NULL);
808826
tcp_recv(_pcb, NULL);
809827
tcp_err(_pcb, NULL);
810828
tcp_poll(_pcb, NULL, 0);
829+
TCP_MUTEX_UNLOCK();
811830
_tcp_clear_events(this);
812831
err = _tcp_close(_pcb, _closed_slot);
813832
if(err != ERR_OK) {
@@ -865,13 +884,15 @@ int8_t AsyncClient::_connected(void* pcb, int8_t err){
865884

866885
void AsyncClient::_error(int8_t err) {
867886
if(_pcb){
887+
TCP_MUTEX_LOCK();
868888
tcp_arg(_pcb, NULL);
869889
if(_pcb->state == LISTEN) {
870890
tcp_sent(_pcb, NULL);
871891
tcp_recv(_pcb, NULL);
872892
tcp_err(_pcb, NULL);
873893
tcp_poll(_pcb, NULL, 0);
874894
}
895+
TCP_MUTEX_UNLOCK();
875896
_pcb = NULL;
876897
}
877898
if(_error_cb) {
@@ -1274,12 +1295,14 @@ void AsyncServer::begin(){
12741295
return;
12751296
}
12761297
int8_t err;
1298+
TCP_MUTEX_LOCK();
12771299
_pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
12781300
if (!_pcb){
12791301
log_e("_pcb == NULL");
1302+
TCP_MUTEX_UNLOCK();
12801303
return;
12811304
}
1282-
1305+
TCP_MUTEX_UNLOCK();
12831306
ip_addr_t local_addr;
12841307
local_addr.type = IPADDR_TYPE_V4;
12851308
local_addr.u_addr.ip4.addr = (uint32_t) _addr;
@@ -1297,17 +1320,21 @@ void AsyncServer::begin(){
12971320
log_e("listen_pcb == NULL");
12981321
return;
12991322
}
1323+
TCP_MUTEX_LOCK();
13001324
tcp_arg(_pcb, (void*) this);
13011325
tcp_accept(_pcb, &_s_accept);
1326+
TCP_MUTEX_UNLOCK();
13021327
}
13031328

13041329
void AsyncServer::end(){
13051330
if(_pcb){
1331+
TCP_MUTEX_LOCK();
13061332
tcp_arg(_pcb, NULL);
13071333
tcp_accept(_pcb, NULL);
13081334
if(tcp_close(_pcb) != ERR_OK){
13091335
_tcp_abort(_pcb, -1);
13101336
}
1337+
TCP_MUTEX_UNLOCK();
13111338
_pcb = NULL;
13121339
}
13131340
}

yoRadio/src/AsyncWebServer/AsyncWebSynchronization.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#ifdef ESP32
99

10+
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 1, 0)
11+
#define pxCurrentTCB pxCurrentTCBs
12+
#endif
13+
1014
// This is the ESP32 version of the Sync Lock, using the FreeRTOS Semaphore
1115
class AsyncWebLock
1216
{

yoRadio/src/core/config.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void Config::init() {
5959

6060
if (store.config_set != 4262) {
6161
setDefaults();
62-
eepromWrite(EEPROM_START, store);
6362
}
6463
if(store.version>CONFIG_VERSION) store.version=1;
6564
while(store.version!=CONFIG_VERSION) _setupVersion();
@@ -285,7 +284,6 @@ template <class T> int Config::eepromRead(int ee, T& value) {
285284

286285
void Config::reset(){
287286
setDefaults();
288-
eepromWrite(EEPROM_START, store);
289287
delay(500);
290288
ESP.restart();
291289
}
@@ -341,6 +339,7 @@ void Config::setDefaults() {
341339
store.forcemono = false;
342340
store.i2sinternal = false;
343341
store.rotate90 = false;
342+
eepromWrite(EEPROM_START, store);
344343
}
345344

346345
void Config::setTimezone(int8_t tzh, int8_t tzm) {

yoRadio/src/core/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ class Config {
250250
if (strcmp(field, value) == 0 && !force) return;
251251
strlcpy(field, value, N);
252252
size_t address = getAddr(field);
253-
for (size_t i = 0; i <= strlen(field); i++) EEPROM.write(address + i, field[i]);
253+
size_t fieldlen = strlen(field);
254+
for (size_t i = 0; i <=fieldlen ; i++) EEPROM.write(address + i, field[i]);
254255
if(commit)
255256
EEPROM.commit();
256257
}

yoRadio/src/core/netserver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,18 @@ void handleHTTPArgs(AsyncWebServerRequest * request) {
840840
if (request->hasArg("next")) { player.next(); commandFound=true; }
841841
if (request->hasArg("volm")) { player.stepVol(false); commandFound=true; }
842842
if (request->hasArg("volp")) { player.stepVol(true); commandFound=true; }
843+
#ifdef USE_SD
844+
if (request->hasArg("mode")) {
845+
AsyncWebParameter* p = request->getParam("mode");
846+
int mm = atoi(p->value().c_str());
847+
if(mm>2) mm=0;
848+
if(mm==2)
849+
config.changeMode();
850+
else
851+
config.changeMode(mm);
852+
commandFound=true;
853+
}
854+
#endif
843855
if (request->hasArg("reset")) { request->redirect("/"); request->send(200); config.reset(); return; }
844856
if (request->hasArg("trebble") && request->hasArg("middle") && request->hasArg("bass")) {
845857
AsyncWebParameter* pt = request->getParam("trebble", request->method() == HTTP_POST);

yoRadio/src/core/network.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ void ticks() {
5050
}
5151
}
5252
#if RTCSUPPORTED
53-
rtc.getTime(&network.timeinfo);
54-
mktime(&network.timeinfo);
55-
display.putRequest(CLOCK);
53+
if(config.isRTCFound()){
54+
rtc.getTime(&network.timeinfo);
55+
mktime(&network.timeinfo);
56+
display.putRequest(CLOCK);
57+
}
5658
#else
5759
if(network.timeinfo.tm_year>100 || network.status == SDREADY) {
5860
network.timeinfo.tm_sec++;
@@ -185,9 +187,11 @@ void MyNetwork::begin() {
185187
if(REAL_LEDBUILTIN!=255) digitalWrite(REAL_LEDBUILTIN, LOW);
186188

187189
#if RTCSUPPORTED
188-
rtc.getTime(&network.timeinfo);
189-
mktime(&network.timeinfo);
190-
display.putRequest(CLOCK);
190+
if(config.isRTCFound()){
191+
rtc.getTime(&network.timeinfo);
192+
mktime(&network.timeinfo);
193+
display.putRequest(CLOCK);
194+
}
191195
#endif
192196
ctimer.attach(1, ticks);
193197
if (network_on_connect) network_on_connect();

yoRadio/src/core/options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef options_h
22
#define options_h
33

4-
#define YOVERSION "0.9.375"
4+
#define YOVERSION "0.9.380"
55

66
/*******************************************************
77
DO NOT EDIT THIS FILE.

yoRadio/src/core/telnet.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,17 @@ void Telnet::on_input(const char* str, uint8_t clientId) {
296296
player.sendCommand({PR_PLAY, (uint16_t)sb});
297297
return;
298298
}
299+
#ifdef USE_SD
300+
int mm;
301+
if (sscanf(str, "mode %d", &mm) == 1 ) {
302+
if (mm > 2) mm = 0;
303+
if(mm==2)
304+
config.changeMode();
305+
else
306+
config.changeMode(mm);
307+
return;
308+
}
309+
#endif
299310
if (strcmp(str, "sys.tzo") == 0 || strcmp(str, "tzo") == 0) {
300311
printf(clientId, "##SYS.TZO#: %d:%d\n> ", config.store.tzHour, config.store.tzMin);
301312
return;

0 commit comments

Comments
 (0)