You've already forked TEF6686_ESP32
fix for incorrect time
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <EEPROM.h>
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
#include <TimeLib.h>
|
||||
#include <ESP32Time.h> // https://github.com/fbiego/ESP32Time/archive/refs/heads/main.zip
|
||||
#include <TFT_eSPI.h> // https://github.com/ohmytime/TFT_eSPI_DynamicSpeed/archive/refs/heads/master.zip (please then edit the User_Setup.h as described in the Wiki)
|
||||
#include <Hash.h> // https://github.com/bbx10/Hash_tng/archive/refs/heads/master.zip
|
||||
@@ -935,7 +936,9 @@ void loop() {
|
||||
byte i = (frequency / 10 - 881) / 2;
|
||||
if (!rabbitearspi[i]) {
|
||||
rabbitearspi[i] = radio.rds.correctPI;
|
||||
rtc.getTime("%FT%TZ").toCharArray(rabbitearstime[i], 21);
|
||||
|
||||
const time_t epoch = rtc.getEpoch() + rtc.offset;
|
||||
strftime(rabbitearstime[i], 21, "%FT%TZ", localtime(&epoch));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1339,6 +1339,8 @@ void TEF6686::readRDS(byte showrdserrors) {
|
||||
mjd = (rds.rdsB & 0x03);
|
||||
mjd <<= 15;
|
||||
mjd += ((rds.rdsC >> 1) & 0x7FFF);
|
||||
uint16_t hour, minute, day, month, year;
|
||||
int32_t timeoffset;
|
||||
|
||||
long J, C, Y, M;
|
||||
J = mjd + 2400001 + 68569;
|
||||
@@ -1348,20 +1350,42 @@ void TEF6686::readRDS(byte showrdserrors) {
|
||||
J = J - 1461 * Y / 4 + 31;
|
||||
M = 80 * (J + 0) / 2447;
|
||||
|
||||
if ((J - 2447 * M / 80) < 32) rds.day = J - 2447 * M / 80;
|
||||
if ((J - 2447 * M / 80) < 32) day = J - 2447 * M / 80;
|
||||
J = M / 11;
|
||||
|
||||
if ((M + 2 - (12 * J)) < 13) rds.month = M + 2 - (12 * J);
|
||||
if ((100 * (C - 49) + Y + J) > 2022) rds.year = 100 * (C - 49) + Y + J;
|
||||
if ((((rds.rdsD >> 12) & 0x0f)) < 25) {
|
||||
rds.hour = ((rds.rdsD >> 12) & 0x0f);
|
||||
rds.hour += ((rds.rdsC << 4) & 0x0010);
|
||||
rds.offset = ((bitRead(rds.rdsD, 5) ? -rds.rdsD & 0x3f : rds.rdsD & 0x3f) / 2);
|
||||
if (bitRead(rds.rdsD, 5) & 0x3f) rds.hour -= rds.offset; else rds.hour += rds.offset;
|
||||
rds.hour = (((byte)rds.hour + 24) % 24);
|
||||
if ((M + 2 - (12 * J)) < 13) month = M + 2 - (12 * J);
|
||||
if ((100 * (C - 49) + Y + J) > 2022) year = 100 * (C - 49) + Y + J;
|
||||
|
||||
hour = ((rds.rdsD >> 12) & 0x000f);
|
||||
hour += ((rds.rdsC << 4) & 0x0010);
|
||||
timeoffset = rds.rdsD & 0x000f;
|
||||
if (bitRead(rds.rdsD, 5)) timeoffset *= -1;
|
||||
timeoffset *= 1800;
|
||||
minute = (rds.rdsD & 0x0fc0) >> 6;
|
||||
if (year < 2024 || hour > 23 || minute > 59 || timeoffset > 27900 || timeoffset < -27900) break;
|
||||
|
||||
struct tm tm;
|
||||
tm.tm_year = year - 1900;
|
||||
tm.tm_mon = month - 1;
|
||||
tm.tm_mday = day;
|
||||
tm.tm_hour = hour;
|
||||
tm.tm_min = minute;
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_isdst = -1;
|
||||
time_t rdstime = mktime(&tm);
|
||||
if (lastrdstime == 0) {
|
||||
lastrdstime = rdstime;
|
||||
lasttimeoffset = timeoffset;
|
||||
}
|
||||
if (((rds.rdsD >> 6) & 0x3f) < 60) rds.minute = (rds.rdsD >> 6) & 0x3f;
|
||||
rds.hasCT = true;
|
||||
if (rdstime == lastrdstime + 60 && timeoffset == lasttimeoffset) {
|
||||
rds.hasCT = true;
|
||||
rds.time = rdstime;
|
||||
rds.offset = timeoffset;
|
||||
} else {
|
||||
rds.hasCT = false;
|
||||
}
|
||||
lastrdstime = rdstime;
|
||||
lasttimeoffset = timeoffset;
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -2066,4 +2090,4 @@ String TEF6686::ucs2ToUtf8(const char* ucs2Input) {
|
||||
}
|
||||
}
|
||||
return utf8Output;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,12 +578,13 @@ typedef struct _rds_ {
|
||||
char stationState[3];
|
||||
char dabafeid[5];
|
||||
char dabafchannel[4];
|
||||
uint16_t hour, minute, day, month, year, rdsA, rdsB, rdsC, rdsD, rdsErr, rdsStat, correctPI, rdsplusTag1, rdsplusTag2;
|
||||
uint16_t rdsA, rdsB, rdsC, rdsD, rdsErr, rdsStat, correctPI, rdsplusTag1, rdsplusTag2;
|
||||
time_t time;
|
||||
int32_t offset;
|
||||
uint16_t aid[10];
|
||||
uint32_t dabaffreq;
|
||||
byte aid_counter;
|
||||
byte fastps;
|
||||
int8_t offset;
|
||||
unsigned int ECC;
|
||||
unsigned int LIC;
|
||||
byte pinMin;
|
||||
@@ -777,5 +778,7 @@ class TEF6686 {
|
||||
uint8_t eRTblock;
|
||||
uint8_t doublecounter;
|
||||
uint16_t doubletestfreq;
|
||||
time_t lastrdstime;
|
||||
int32_t lasttimeoffset;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
15
src/rds.cpp
15
src/rds.cpp
@@ -736,20 +736,23 @@ void showPS() {
|
||||
}
|
||||
|
||||
void showCT() {
|
||||
char str[6];
|
||||
time_t t;
|
||||
if (!screenmute && showclock) {
|
||||
if (radio.rds.hasCT && !dropout) {
|
||||
rds_clock = ((radio.rds.hour < 10 ? "0" : "") + String(radio.rds.hour) + ":" + (radio.rds.minute < 10 ? "0" : "") + String(radio.rds.minute));
|
||||
t = radio.rds.time + radio.rds.offset;
|
||||
} else if (!radio.rds.hasCT || dropout) {
|
||||
rds_clock = ((rtc.getHour(true) < 10 ? "0" : "") + String(rtc.getHour(true)) + ":" + (rtc.getMinute() < 10 ? "0" : "") + String(rtc.getMinute()));
|
||||
t = rtc.getEpoch() + radio.rds.offset;
|
||||
if (dropout) {
|
||||
radio.rds.hour = rtc.getHour(true);
|
||||
radio.rds.minute = rtc.getMinute();
|
||||
radio.rds.time = static_cast<time_t>(rtc.getEpoch());
|
||||
}
|
||||
}
|
||||
strftime(str, 6, "%H:%M", localtime(&t));
|
||||
rds_clock = String(str);
|
||||
if (rds_clock != rds_clockold || hasCTold != radio.rds.hasCT) {
|
||||
if (radio.rds.hasCT && RDSstatus) {
|
||||
rtcset = true;
|
||||
rtc.setTime(0, radio.rds.minute, radio.rds.hour, radio.rds.day, radio.rds.month, radio.rds.year);
|
||||
rtc.setTime(radio.rds.time);
|
||||
if (advancedRDS) {
|
||||
tftReplace(1, rds_clockold, rds_clock, 208, 109, RDSColor, RDSColorSmooth, BackgroundColor, 16);
|
||||
} else {
|
||||
@@ -1025,4 +1028,4 @@ void ShowAFEON() {
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
Reference in New Issue
Block a user