v0.9.250
This commit is contained in:
@@ -34,6 +34,17 @@ bool Config::_isFSempty() {
|
||||
void Config::init() {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
sdog.begin();
|
||||
bootInfo();
|
||||
#if RTCSUPPORTED
|
||||
_rtcFound = false;
|
||||
BOOTLOG("RTC begin(SDA=%d,SCL=%d)", RTC_SDA, RTC_SCL);
|
||||
if(rtc.init()){
|
||||
BOOTLOG("done");
|
||||
_rtcFound = true;
|
||||
}else{
|
||||
BOOTLOG("[ERROR] - Couldn't find RTC");
|
||||
}
|
||||
#endif
|
||||
emptyFS = true;
|
||||
#if IR_PIN!=255
|
||||
irindex=-1;
|
||||
@@ -69,7 +80,7 @@ void Config::init() {
|
||||
backupSDStation = 0;
|
||||
//checkSD();
|
||||
_bootDone=false;
|
||||
bootInfo();
|
||||
//bootInfo();
|
||||
}
|
||||
|
||||
#ifdef USE_SD
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <SPIFFS.h>
|
||||
#include "SD.h"
|
||||
#include "options.h"
|
||||
#include "rtcsupport.h"
|
||||
|
||||
#define EEPROM_SIZE 768
|
||||
#define EEPROM_START 500
|
||||
@@ -220,11 +221,17 @@ class Config {
|
||||
void clearCardStatus() { if(_cardStatus!=CS_NONE) _cardStatus=CS_NONE; }
|
||||
bool spiffsCleanup();
|
||||
FS* SDPLFS(){ return _SDplaylistFS; }
|
||||
#if RTCSUPPORTED
|
||||
bool isRTCFound(){ return _rtcFound; };
|
||||
#endif
|
||||
private:
|
||||
template <class T> int eepromWrite(int ee, const T& value);
|
||||
template <class T> int eepromRead(int ee, T& value);
|
||||
cardStatus_e _cardStatus;
|
||||
bool _bootDone;
|
||||
#if RTCSUPPORTED
|
||||
bool _rtcFound;
|
||||
#endif
|
||||
FS* _SDplaylistFS;
|
||||
void setDefaults();
|
||||
Ticker _sleepTimer;
|
||||
|
||||
@@ -18,8 +18,13 @@ void ticks() {
|
||||
|
||||
static const uint16_t weatherSyncInterval=1800;
|
||||
//static const uint16_t weatherSyncIntervalFail=10;
|
||||
static const uint16_t timeSyncInterval=3600;
|
||||
static uint16_t timeSyncTicks = 0;
|
||||
#if RTCSUPPORTED
|
||||
static const uint32_t timeSyncInterval=86400;
|
||||
static uint32_t timeSyncTicks = 0;
|
||||
#else
|
||||
static const uint16_t timeSyncInterval=3600;
|
||||
static uint16_t timeSyncTicks = 0;
|
||||
#endif
|
||||
static uint16_t weatherSyncTicks = 0;
|
||||
static bool divrssi;
|
||||
timeSyncTicks++;
|
||||
@@ -36,12 +41,17 @@ void ticks() {
|
||||
weatherSyncTicks=0;
|
||||
network.forceWeather = true;
|
||||
}
|
||||
|
||||
if(network.timeinfo.tm_year>100) {
|
||||
#if RTCSUPPORTED
|
||||
rtc.getTime(&network.timeinfo);
|
||||
mktime(&network.timeinfo);
|
||||
display.putRequest(CLOCK);
|
||||
#else
|
||||
if(network.timeinfo.tm_year>100 || network.status == SDREADY) {
|
||||
network.timeinfo.tm_sec++;
|
||||
mktime(&network.timeinfo);
|
||||
display.putRequest(CLOCK);
|
||||
}
|
||||
#endif
|
||||
if(player.isRunning() && config.getMode()==PM_SDCARD) netserver.requestOnChange(SDPOS, 0);
|
||||
if(divrssi) {
|
||||
netserver.setRSSI(WiFi.RSSI());
|
||||
@@ -137,6 +147,11 @@ void Network::begin() {
|
||||
}else if(strlen(config.store.sntp1)>0){
|
||||
configTime(config.store.tzHour * 3600 + config.store.tzMin * 60, config.getTimezoneOffset(), config.store.sntp1);
|
||||
}
|
||||
#if RTCSUPPORTED
|
||||
rtc.getTime(&network.timeinfo);
|
||||
mktime(&network.timeinfo);
|
||||
display.putRequest(CLOCK);
|
||||
#endif
|
||||
ctimer.attach(1, ticks);
|
||||
if (network_on_connect) network_on_connect();
|
||||
}
|
||||
@@ -187,6 +202,9 @@ void doSync( void * pvParameters ) {
|
||||
mktime(&network.timeinfo);
|
||||
display.putRequest(CLOCK);
|
||||
network.requestTimeSync(true);
|
||||
#if RTCSUPPORTED
|
||||
if (config.isRTCFound()) rtc.setTime(&network.timeinfo);
|
||||
#endif
|
||||
}else{
|
||||
if(tsFailCnt<4){
|
||||
network.forceTimeSync = true;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <Ticker.h>
|
||||
#include "time.h"
|
||||
#include "WiFi.h"
|
||||
#include "rtcsupport.h"
|
||||
|
||||
#define apSsid "yoRadioAP"
|
||||
#define apPassword "12345987"
|
||||
@@ -10,7 +11,7 @@
|
||||
#define TSYNC_DELAY 3600000 // 1000*60*60 = 1 hour
|
||||
#define WEATHER_STRING_L 254
|
||||
|
||||
enum n_Status_e { CONNECTED, SOFT_AP, FAILED };
|
||||
enum n_Status_e { CONNECTED, SOFT_AP, FAILED, SDREADY };
|
||||
|
||||
class Network {
|
||||
public:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef options_h
|
||||
#define options_h
|
||||
|
||||
#define YOVERSION "0.9.242"
|
||||
#define YOVERSION "0.9.250"
|
||||
|
||||
/*******************************************************
|
||||
DO NOT EDIT THIS FILE.
|
||||
@@ -121,9 +121,6 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#endif
|
||||
|
||||
/* SDCARD */
|
||||
#ifndef SDC_SPI
|
||||
#define SDC_SPI 18, 19, 23 // SDCARD SPI pins (SCK, MISO, MOSI)
|
||||
#endif
|
||||
#ifndef SDC_CS
|
||||
#define SDC_CS 255 // SDCARD CS pin
|
||||
#endif
|
||||
@@ -245,6 +242,21 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
|
||||
#define LCD_D7 255
|
||||
#endif
|
||||
|
||||
/* RTC */
|
||||
#define RTC_MODULE_UNDEFINED 0
|
||||
#define DS3231 1
|
||||
#define DS1307 2
|
||||
|
||||
#ifndef RTC_MODULE
|
||||
#define RTC_MODULE RTC_MODULE_UNDEFINED /* DS3231 or DS1307 */
|
||||
#endif
|
||||
#ifndef RTC_SDA
|
||||
#define RTC_SDA 255
|
||||
#endif
|
||||
#ifndef RTC_SCL
|
||||
#define RTC_SCL 255
|
||||
#endif
|
||||
|
||||
/* ESP DEVBOARD */
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 255
|
||||
|
||||
43
yoRadio/src/core/rtcsupport.cpp
Normal file
43
yoRadio/src/core/rtcsupport.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "rtcsupport.h"
|
||||
|
||||
#if RTCSUPPORTED
|
||||
#include <Wire.h>
|
||||
|
||||
TwoWire RTCWire = TwoWire(0);
|
||||
|
||||
RTC rtc;
|
||||
|
||||
bool RTC::init(){
|
||||
RTCWire.begin(RTC_SDA, RTC_SCL);
|
||||
return begin(&RTCWire);
|
||||
}
|
||||
|
||||
bool RTC::isRunning(){
|
||||
#if RTC_MODULE==DS3231
|
||||
return !lostPower();
|
||||
#elif RTC_MODULE==DS1307
|
||||
return isrunning();
|
||||
#endif
|
||||
}
|
||||
|
||||
void RTC::getTime(struct tm* tinfo){
|
||||
if(isRunning()){
|
||||
DateTime nowTm = now();
|
||||
tinfo->tm_sec = nowTm.second();
|
||||
tinfo->tm_min = nowTm.minute();
|
||||
tinfo->tm_hour = nowTm.hour();
|
||||
tinfo->tm_wday = nowTm.dayOfTheWeek();
|
||||
tinfo->tm_mday = nowTm.day();
|
||||
tinfo->tm_mon = nowTm.month() - 1;
|
||||
tinfo->tm_year = nowTm.year() - 1900;
|
||||
}else{
|
||||
tinfo->tm_sec++;
|
||||
mktime(tinfo);
|
||||
}
|
||||
}
|
||||
|
||||
void RTC::setTime(struct tm* tinfo){
|
||||
adjust(DateTime(tinfo->tm_year + 1900, tinfo->tm_mon + 1, tinfo->tm_mday, tinfo->tm_hour, tinfo->tm_min, tinfo->tm_sec));
|
||||
}
|
||||
|
||||
#endif
|
||||
26
yoRadio/src/core/rtcsupport.h
Normal file
26
yoRadio/src/core/rtcsupport.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef rtcsupport_h
|
||||
#define rtcsupport_h
|
||||
#include "options.h"
|
||||
|
||||
#define RTCSUPPORTED (RTC_SDA!=255 && RTC_SCL!=255 && (RTC_MODULE==DS3231 || RTC_MODULE==DS1307))
|
||||
|
||||
#if RTCSUPPORTED
|
||||
#include "RTClib.h"
|
||||
|
||||
#if RTC_MODULE==DS3231
|
||||
class RTC: public RTC_DS3231 {
|
||||
#elif RTC_MODULE==DS1307
|
||||
class RTC: public RTC_DS1307 {
|
||||
#else
|
||||
# error ONLY DS3231 OR DS1307 MODULE SUPPORTED
|
||||
#endif
|
||||
public:
|
||||
bool init();
|
||||
bool isRunning();
|
||||
void getTime(struct tm* tinfo);
|
||||
void setTime(struct tm* tinfo);
|
||||
};
|
||||
extern RTC rtc;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user