Skip to content

Commit

Permalink
v0.6.110
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002 committed Apr 5, 2022
1 parent 864d8f9 commit 40f194a
Show file tree
Hide file tree
Showing 40 changed files with 523 additions and 360 deletions.
4 changes: 3 additions & 1 deletion Images.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
\
![ёRadio](images/img19.jpg)\
\
![ёRadio](images/img20.jpg)
![ёRadio](images/img20.jpg)\
\
![ёRadio](images/img21.jpg)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ Work is in progress...

---
## Version history
#### v0.6.110
- the logic of division by cores has been changed
- fixed choppy playback (again)
- improvements in the stability of the web interface
- increased smoothness of the encoder
- bug fixes
- bug fixes

#### v0.6.012
- fixed choppy playback

Expand Down
88 changes: 61 additions & 27 deletions exsamples/displayhandlers.ino
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/**************************************************************
*
* An example of displaying user information on the display.
* This file must be in the root directory of the sketch.
*
An example of displaying user information on the display.
This file must be in the root directory of the sketch.
**************************************************************/

#if DSP_MODEL==DSP_ST7735
// 3600s = 60 minutes to not flooding
#define WEATHER_REQUEST_INTERVAL 3600 // 60min

#include <JSON_Decoder.h> // https://github.com/Bodmer/OpenWeather
#include <OpenWeather.h> // https://github.com/Bodmer/JSON_Decoder
#include <Ticker.h>

String api_key = "********************************"; // openweathermap.org API key

Expand All @@ -19,59 +22,90 @@ String units = "metric";
String language = "ru";

OW_Weather ow;
Ticker ticker;

/***********************************************
* scrolled line
scrolled line
***********************************************/
Scroll hello;

char weather[140] = { 0 };
bool weatherRequest = false;
TaskHandle_t weatherUpdateTaskHandle;

void getWeather( void * pvParameters ) {
OW_current *current = new OW_current;
OW_hourly *hourly = new OW_hourly;
OW_daily *daily = new OW_daily;
delay(5000);
ow.getForecast(current, hourly, daily, api_key, latitude, longitude, units, language);
sprintf(weather, "TEMP: %.1f C * PRESS: %d HG * HUM: %d%%", current->temp, (int)(current->pressure / 1.333), current->humidity);
weatherRequest = true;
vTaskDelete( NULL );
}

void updateWeather() {
xTaskCreatePinnedToCore(
getWeather, /* Task function. */
"getWeather1", /* name of task. */
8192, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&weatherUpdateTaskHandle, /* Task handle to keep track of created task */
0); /* pin task to core CORE_FOR_LOOP_CONTROLS */
}

/***********************************************
* Occurs when the display is initialized
Occurs when the network is connected
***********************************************/
void dsp_on_init(){
hello.init(" * ", 1, TFT_LINEHGHT*4+6, 2000, ORANGE, TFT_BG);
void network_on_connect() {
ticker.attach(WEATHER_REQUEST_INTERVAL, updateWeather);
updateWeather();
}

/*********************************************************************************************
* The display has initialized, the network is connected, the player is ready to play.
* DspCore class documentation is missing :^( See the source in src/displays
The display has initialized, the network is connected, the player is ready to play.
DspCore class documentation is missing :^( See the source in src/displays
*********************************************************************************************/
void dsp_on_start(DspCore *dsp){
OW_current *current = new OW_current;
OW_hourly *hourly = new OW_hourly;
OW_daily *daily = new OW_daily;
char weather[140] = { 0 };
ow.getForecast(current, hourly, daily, api_key, latitude, longitude, units, language);
void dsp_on_start(DspCore *dsp) {

sprintf(weather, "temp: %.1f * pressure: %d * humidity: %d", current->temp, (int)(current->pressure/1.333), current->humidity);
}

hello.setText(dsp->utf8Rus(weather, true));
/***********************************************
Occurs when the display is initialized
***********************************************/
void dsp_on_init() {
hello.init(5, " * ", 1, TFT_LINEHGHT*4+6, 0, ORANGE, TFT_BG);
Serial.println(TFT_LINEHGHT*4+6);
}

/************************
* The loop cycle
The loop cycle
************************/
void dsp_on_loop(){
if(display.mode==PLAYER) hello.loop();
void dsp_on_loop() {
if (weatherRequest) {
weatherRequest = false;
hello.setText(weather);
}
if (display.mode == PLAYER) hello.loop();
}

/***********************************************
* Occurs when the display changes mode
Occurs when the display changes mode
***********************************************/
void dsp_on_newmode(displayMode_e newmode){
void dsp_on_newmode(displayMode_e newmode) {
if (newmode == PLAYER) {
hello.reset();
}else{
} else {
hello.lock();
}
}

/************************
* Before print the clock
Before print the clock
************************/
bool dsp_before_clock(DspCore *dsp, bool dots){
if(display.mode==PLAYER){
bool dsp_before_clock(DspCore *dsp, bool dots) {
if (display.mode == PLAYER) {
dsp->setFont();
dsp->setTextSize(1);
display.centerText(dsp->utf8Rus("Hello from plugin!", true), display.screenheight - TFT_FRAMEWDT * 2 - TFT_LINEHGHT * 2 - 2, PINK, TFT_BG);
Expand Down
4 changes: 0 additions & 4 deletions exsamples/myoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ Uncomment the lines you need, to override the default value and set the values a
The connection tables are located here https://github.com/e2002/yoradio#connection-tables
********************************************************/
/* CORE_FOR_LOOP_CONTROLS. See description/available values in the options.h file */
/* This setting was added to eliminate audio jerking when adjusting the volume/playlist. The default value is 2 */
#define CORE_FOR_LOOP_CONTROLS 2
/******************************************/

/* DSP_MODEL. See description/available values in the options.h file */
/* This option is required. Use DSP_DUMMY if no display is connected */
Expand Down
Binary file added images/img21.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 69 additions & 68 deletions yoRadio/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#include <EEPROM.h>
#include <SPIFFS.h>
#include "display.h"
#include "player.h"
Config config;

void Config::init() {
EEPROM.begin(EEPROM_SIZE);
eepromRead(EEPROM_START, store);
if (store.tz_set!=57){ // update to v0.4.200
if (store.tz_set != 57) { // update to v0.4.200
store.tz_set = 57;
store.tzHour = 3;
store.tzMin = 0;
Expand All @@ -29,22 +31,17 @@ void Config::init() {
template <class T> int Config::eepromWrite(int ee, const T& value) {
const byte* p = (const byte*)(const void*)&value;
int i;
EEPROM.begin(EEPROM_SIZE);
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
EEPROM.commit();
delay(20);
EEPROM.end();
return i;
}

template <class T> int Config::eepromRead(int ee, T& value) {
byte* p = (byte*)(void*)&value;
int i;
EEPROM.begin(EEPROM_SIZE);
int i;;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
EEPROM.end();
return i;
}

Expand All @@ -67,13 +64,13 @@ void Config::setDefaults() {
}

void Config::setTimezone(int8_t tzh, int8_t tzm) {
store.tzHour=tzh;
store.tzMin=tzm;
store.tzHour = tzh;
store.tzMin = tzm;
save();
}

void Config::setTimezoneOffset(uint16_t tzo) {
store.timezoneOffset=tzo;
store.timezoneOffset = tzo;
save();
}

Expand All @@ -87,7 +84,11 @@ void Config::save() {

byte Config::setVolume(byte val, bool dosave) {
store.volume = val;
if (dosave) save();
if (dosave) {
//save();
EEPROM.write(EEPROM_START + sizeof(store.config_set), store.volume);
EEPROM.commit();
}
return store.volume;
}

Expand Down Expand Up @@ -128,17 +129,17 @@ byte Config::setLastSSID(byte val) {
return store.lastSSID;
}

void Config::setTitle(const char* title){
void Config::setTitle(const char* title) {
memset(config.station.title, 0, BUFLEN);
strlcpy(config.station.title, title, BUFLEN);
display.refreshTitle = true;
display.title();
}

void Config::setStation(const char* station){
void Config::setStation(const char* station) {
memset(config.station.name, 0, BUFLEN);
strlcpy(config.station.name, station, BUFLEN);
}

void Config::indexPlaylist() {
File playlist = SPIFFS.open(PLAYLIST_PATH, "r");
if (!playlist) {
Expand Down Expand Up @@ -244,16 +245,16 @@ bool Config::parseCSV(const char* line, char* name, char* url, int &ovol) {
char *tmpe;
const char* cursor = line;
char buf[5];
tmpe=strstr(cursor, "\t");
if(tmpe==NULL) return false;
strlcpy(name, cursor, tmpe-cursor+1);
if(strlen(name)==0) return false;
cursor=tmpe+1;
tmpe=strstr(cursor, "\t");
if(tmpe==NULL) return false;
strlcpy(url, cursor, tmpe-cursor+1);
if(strlen(url)==0) return false;
cursor=tmpe+1;
tmpe = strstr(cursor, "\t");
if (tmpe == NULL) return false;
strlcpy(name, cursor, tmpe - cursor + 1);
if (strlen(name) == 0) return false;
cursor = tmpe + 1;
tmpe = strstr(cursor, "\t");
if (tmpe == NULL) return false;
strlcpy(url, cursor, tmpe - cursor + 1);
if (strlen(url) == 0) return false;
cursor = tmpe + 1;
if (strlen(cursor) == 0) return false;
strlcpy(buf, cursor, 4);
ovol = atoi(buf);
Expand All @@ -264,68 +265,68 @@ bool Config::parseJSON(const char* line, char* name, char* url, int &ovol) {
char* tmps, *tmpe;
const char* cursor = line;
char port[8], host[254], file[254];
tmps=strstr(cursor, "\":\"");
if(tmps==NULL) return false;
tmpe=strstr(tmps, "\",\"");
if(tmpe==NULL) return false;
strlcpy(name, tmps+3, tmpe-tmps-3+1);
if(strlen(name)==0) return false;
cursor=tmpe+3;
tmps=strstr(cursor, "\":\"");
if(tmps==NULL) return false;
tmpe=strstr(tmps, "\",\"");
if(tmpe==NULL) return false;
strlcpy(host, tmps+3, tmpe-tmps-3+1);
if(strlen(host)==0) return false;
if(strstr(host,"http://")==NULL && strstr(host,"https://")==NULL) {
tmps = strstr(cursor, "\":\"");
if (tmps == NULL) return false;
tmpe = strstr(tmps, "\",\"");
if (tmpe == NULL) return false;
strlcpy(name, tmps + 3, tmpe - tmps - 3 + 1);
if (strlen(name) == 0) return false;
cursor = tmpe + 3;
tmps = strstr(cursor, "\":\"");
if (tmps == NULL) return false;
tmpe = strstr(tmps, "\",\"");
if (tmpe == NULL) return false;
strlcpy(host, tmps + 3, tmpe - tmps - 3 + 1);
if (strlen(host) == 0) return false;
if (strstr(host, "http://") == NULL && strstr(host, "https://") == NULL) {
sprintf(file, "http://%s", host);
strlcpy(host, file, strlen(file)+1);
strlcpy(host, file, strlen(file) + 1);
}
cursor=tmpe+3;
tmps=strstr(cursor, "\":\"");
if(tmps==NULL) return false;
tmpe=strstr(tmps, "\",\"");
if(tmpe==NULL) return false;
strlcpy(file, tmps+3, tmpe-tmps-3+1);
cursor=tmpe+3;
tmps=strstr(cursor, "\":\"");
if(tmps==NULL) return false;
tmpe=strstr(tmps, "\",\"");
if(tmpe==NULL) return false;
strlcpy(port, tmps+3, tmpe-tmps-3+1);
cursor = tmpe + 3;
tmps = strstr(cursor, "\":\"");
if (tmps == NULL) return false;
tmpe = strstr(tmps, "\",\"");
if (tmpe == NULL) return false;
strlcpy(file, tmps + 3, tmpe - tmps - 3 + 1);
cursor = tmpe + 3;
tmps = strstr(cursor, "\":\"");
if (tmps == NULL) return false;
tmpe = strstr(tmps, "\",\"");
if (tmpe == NULL) return false;
strlcpy(port, tmps + 3, tmpe - tmps - 3 + 1);
int p = atoi(port);
if(p>0){
if (p > 0) {
sprintf(url, "%s:%d%s", host, p, file);
}else{
} else {
sprintf(url, "%s%s", host, file);
}
cursor=tmpe+3;
tmps=strstr(cursor, "\":\"");
if(tmps==NULL) return false;
tmpe=strstr(tmps, "\"}");
if(tmpe==NULL) return false;
strlcpy(port, tmps+3, tmpe-tmps-3+1);
cursor = tmpe + 3;
tmps = strstr(cursor, "\":\"");
if (tmps == NULL) return false;
tmpe = strstr(tmps, "\"}");
if (tmpe == NULL) return false;
strlcpy(port, tmps + 3, tmpe - tmps - 3 + 1);
ovol = atoi(port);
return true;
}

bool Config::parseWsCommand(const char* line, char* cmd, char* val, byte cSize) {
char *tmpe;
tmpe=strstr(line, "=");
if(tmpe==NULL) return false;
tmpe = strstr(line, "=");
if (tmpe == NULL) return false;
memset(cmd, 0, cSize);
strlcpy(cmd, line, tmpe-line+1);
if (strlen(tmpe+1) == 0) return false;
strlcpy(cmd, line, tmpe - line + 1);
if (strlen(tmpe + 1) == 0) return false;
memset(val, 0, cSize);
strlcpy(val, tmpe+1, tmpe+1-line+1);
strlcpy(val, tmpe + 1, tmpe + 1 - line + 1);
return true;
}

bool Config::parseSsid(const char* line, char* ssid, char* pass) {
char *tmpe;
tmpe=strstr(line, "\t");
if(tmpe==NULL) return false;
uint16_t pos= tmpe-line;
tmpe = strstr(line, "\t");
if (tmpe == NULL) return false;
uint16_t pos = tmpe - line;
if (pos > 19 || strlen(line) > 61) return false;
memset(ssid, 0, 20);
strlcpy(ssid, line, pos + 1);
Expand Down
Loading

0 comments on commit 40f194a

Please sign in to comment.