22#include < EEPROM.h>
33#include < SPIFFS.h>
44#include " display.h"
5+ #include " player.h"
56Config config;
67
78void Config::init () {
9+ EEPROM.begin (EEPROM_SIZE);
810 eepromRead (EEPROM_START, store);
9- if (store.tz_set != 57 ){ // update to v0.4.200
11+ if (store.tz_set != 57 ) { // update to v0.4.200
1012 store.tz_set = 57 ;
1113 store.tzHour = 3 ;
1214 store.tzMin = 0 ;
@@ -29,22 +31,17 @@ void Config::init() {
2931template <class T > int Config::eepromWrite (int ee, const T& value) {
3032 const byte* p = (const byte*)(const void *)&value;
3133 int i;
32- EEPROM.begin (EEPROM_SIZE);
3334 for (i = 0 ; i < sizeof (value); i++)
3435 EEPROM.write (ee++, *p++);
3536 EEPROM.commit ();
36- delay (20 );
37- EEPROM.end ();
3837 return i;
3938}
4039
4140template <class T > int Config::eepromRead (int ee, T& value) {
4241 byte* p = (byte*)(void *)&value;
43- int i;
44- EEPROM.begin (EEPROM_SIZE);
42+ int i;;
4543 for (i = 0 ; i < sizeof (value); i++)
4644 *p++ = EEPROM.read (ee++);
47- EEPROM.end ();
4845 return i;
4946}
5047
@@ -67,13 +64,13 @@ void Config::setDefaults() {
6764}
6865
6966void Config::setTimezone (int8_t tzh, int8_t tzm) {
70- store.tzHour = tzh;
71- store.tzMin = tzm;
67+ store.tzHour = tzh;
68+ store.tzMin = tzm;
7269 save ();
7370}
7471
7572void Config::setTimezoneOffset (uint16_t tzo) {
76- store.timezoneOffset = tzo;
73+ store.timezoneOffset = tzo;
7774 save ();
7875}
7976
@@ -87,7 +84,11 @@ void Config::save() {
8784
8885byte Config::setVolume (byte val, bool dosave) {
8986 store.volume = val;
90- if (dosave) save ();
87+ if (dosave) {
88+ // save();
89+ EEPROM.write (EEPROM_START + sizeof (store.config_set ), store.volume );
90+ EEPROM.commit ();
91+ }
9192 return store.volume ;
9293}
9394
@@ -128,17 +129,17 @@ byte Config::setLastSSID(byte val) {
128129 return store.lastSSID ;
129130}
130131
131- void Config::setTitle (const char * title){
132+ void Config::setTitle (const char * title) {
132133 memset (config.station .title , 0 , BUFLEN);
133134 strlcpy (config.station .title , title, BUFLEN);
134- display.refreshTitle = true ;
135+ display.title () ;
135136}
136137
137- void Config::setStation (const char * station){
138+ void Config::setStation (const char * station) {
138139 memset (config.station .name , 0 , BUFLEN);
139140 strlcpy (config.station .name , station, BUFLEN);
140141}
141-
142+
142143void Config::indexPlaylist () {
143144 File playlist = SPIFFS.open (PLAYLIST_PATH, " r" );
144145 if (!playlist) {
@@ -244,16 +245,16 @@ bool Config::parseCSV(const char* line, char* name, char* url, int &ovol) {
244245 char *tmpe;
245246 const char * cursor = line;
246247 char buf[5 ];
247- tmpe= strstr (cursor, " \t " );
248- if (tmpe== NULL ) return false ;
249- strlcpy (name, cursor, tmpe- cursor+ 1 );
250- if (strlen (name)== 0 ) return false ;
251- cursor= tmpe+ 1 ;
252- tmpe= strstr (cursor, " \t " );
253- if (tmpe== NULL ) return false ;
254- strlcpy (url, cursor, tmpe- cursor+ 1 );
255- if (strlen (url)== 0 ) return false ;
256- cursor= tmpe+ 1 ;
248+ tmpe = strstr (cursor, " \t " );
249+ if (tmpe == NULL ) return false ;
250+ strlcpy (name, cursor, tmpe - cursor + 1 );
251+ if (strlen (name) == 0 ) return false ;
252+ cursor = tmpe + 1 ;
253+ tmpe = strstr (cursor, " \t " );
254+ if (tmpe == NULL ) return false ;
255+ strlcpy (url, cursor, tmpe - cursor + 1 );
256+ if (strlen (url) == 0 ) return false ;
257+ cursor = tmpe + 1 ;
257258 if (strlen (cursor) == 0 ) return false ;
258259 strlcpy (buf, cursor, 4 );
259260 ovol = atoi (buf);
@@ -264,68 +265,68 @@ bool Config::parseJSON(const char* line, char* name, char* url, int &ovol) {
264265 char * tmps, *tmpe;
265266 const char * cursor = line;
266267 char port[8 ], host[254 ], file[254 ];
267- tmps= strstr (cursor, " \" :\" " );
268- if (tmps== NULL ) return false ;
269- tmpe= strstr (tmps, " \" ,\" " );
270- if (tmpe== NULL ) return false ;
271- strlcpy (name, tmps+ 3 , tmpe- tmps- 3 + 1 );
272- if (strlen (name)== 0 ) return false ;
273- cursor= tmpe+ 3 ;
274- tmps= strstr (cursor, " \" :\" " );
275- if (tmps== NULL ) return false ;
276- tmpe= strstr (tmps, " \" ,\" " );
277- if (tmpe== NULL ) return false ;
278- strlcpy (host, tmps+ 3 , tmpe- tmps- 3 + 1 );
279- if (strlen (host)== 0 ) return false ;
280- if (strstr (host," http://" )== NULL && strstr (host," https://" )== NULL ) {
268+ tmps = strstr (cursor, " \" :\" " );
269+ if (tmps == NULL ) return false ;
270+ tmpe = strstr (tmps, " \" ,\" " );
271+ if (tmpe == NULL ) return false ;
272+ strlcpy (name, tmps + 3 , tmpe - tmps - 3 + 1 );
273+ if (strlen (name) == 0 ) return false ;
274+ cursor = tmpe + 3 ;
275+ tmps = strstr (cursor, " \" :\" " );
276+ if (tmps == NULL ) return false ;
277+ tmpe = strstr (tmps, " \" ,\" " );
278+ if (tmpe == NULL ) return false ;
279+ strlcpy (host, tmps + 3 , tmpe - tmps - 3 + 1 );
280+ if (strlen (host) == 0 ) return false ;
281+ if (strstr (host, " http://" ) == NULL && strstr (host, " https://" ) == NULL ) {
281282 sprintf (file, " http://%s" , host);
282- strlcpy (host, file, strlen (file)+ 1 );
283+ strlcpy (host, file, strlen (file) + 1 );
283284 }
284- cursor= tmpe+ 3 ;
285- tmps= strstr (cursor, " \" :\" " );
286- if (tmps== NULL ) return false ;
287- tmpe= strstr (tmps, " \" ,\" " );
288- if (tmpe== NULL ) return false ;
289- strlcpy (file, tmps+ 3 , tmpe- tmps- 3 + 1 );
290- cursor= tmpe+ 3 ;
291- tmps= strstr (cursor, " \" :\" " );
292- if (tmps== NULL ) return false ;
293- tmpe= strstr (tmps, " \" ,\" " );
294- if (tmpe== NULL ) return false ;
295- strlcpy (port, tmps+ 3 , tmpe- tmps- 3 + 1 );
285+ cursor = tmpe + 3 ;
286+ tmps = strstr (cursor, " \" :\" " );
287+ if (tmps == NULL ) return false ;
288+ tmpe = strstr (tmps, " \" ,\" " );
289+ if (tmpe == NULL ) return false ;
290+ strlcpy (file, tmps + 3 , tmpe - tmps - 3 + 1 );
291+ cursor = tmpe + 3 ;
292+ tmps = strstr (cursor, " \" :\" " );
293+ if (tmps == NULL ) return false ;
294+ tmpe = strstr (tmps, " \" ,\" " );
295+ if (tmpe == NULL ) return false ;
296+ strlcpy (port, tmps + 3 , tmpe - tmps - 3 + 1 );
296297 int p = atoi (port);
297- if (p> 0 ) {
298+ if (p > 0 ) {
298299 sprintf (url, " %s:%d%s" , host, p, file);
299- }else {
300+ } else {
300301 sprintf (url, " %s%s" , host, file);
301302 }
302- cursor= tmpe+ 3 ;
303- tmps= strstr (cursor, " \" :\" " );
304- if (tmps== NULL ) return false ;
305- tmpe= strstr (tmps, " \" }" );
306- if (tmpe== NULL ) return false ;
307- strlcpy (port, tmps+ 3 , tmpe- tmps- 3 + 1 );
303+ cursor = tmpe + 3 ;
304+ tmps = strstr (cursor, " \" :\" " );
305+ if (tmps == NULL ) return false ;
306+ tmpe = strstr (tmps, " \" }" );
307+ if (tmpe == NULL ) return false ;
308+ strlcpy (port, tmps + 3 , tmpe - tmps - 3 + 1 );
308309 ovol = atoi (port);
309310 return true ;
310311}
311312
312313bool Config::parseWsCommand (const char * line, char * cmd, char * val, byte cSize) {
313314 char *tmpe;
314- tmpe= strstr (line, " =" );
315- if (tmpe== NULL ) return false ;
315+ tmpe = strstr (line, " =" );
316+ if (tmpe == NULL ) return false ;
316317 memset (cmd, 0 , cSize);
317- strlcpy (cmd, line, tmpe- line+ 1 );
318- if (strlen (tmpe+ 1 ) == 0 ) return false ;
318+ strlcpy (cmd, line, tmpe - line + 1 );
319+ if (strlen (tmpe + 1 ) == 0 ) return false ;
319320 memset (val, 0 , cSize);
320- strlcpy (val, tmpe+ 1 , tmpe+ 1 - line+ 1 );
321+ strlcpy (val, tmpe + 1 , tmpe + 1 - line + 1 );
321322 return true ;
322323}
323324
324325bool Config::parseSsid (const char * line, char * ssid, char * pass) {
325326 char *tmpe;
326- tmpe= strstr (line, " \t " );
327- if (tmpe== NULL ) return false ;
328- uint16_t pos= tmpe- line;
327+ tmpe = strstr (line, " \t " );
328+ if (tmpe == NULL ) return false ;
329+ uint16_t pos = tmpe - line;
329330 if (pos > 19 || strlen (line) > 61 ) return false ;
330331 memset (ssid, 0 , 20 );
331332 strlcpy (ssid, line, pos + 1 );
0 commit comments