Added auto DST on NTP
This commit is contained in:
+52
-2
@@ -62,6 +62,7 @@ bool afpage;
|
||||
bool afscreen;
|
||||
bool aftest;
|
||||
bool artheadold;
|
||||
bool autoDST;
|
||||
bool autolog;
|
||||
bool autologged;
|
||||
bool autosquelch = true;
|
||||
@@ -188,7 +189,7 @@ byte amgain;
|
||||
byte freqoldcount;
|
||||
byte HighCutLevel;
|
||||
byte HighCutOffset;
|
||||
byte items[10] = {10, static_cast<byte>(dynamicspi ? 10 : 9), 7, 10, 10, 10, 9, 7, 10, 9};
|
||||
byte items[10] = {10, static_cast<byte>(dynamicspi ? 10 : 9), 7, 10, 10, 10, 9, 8, 10, 9};
|
||||
byte iMSEQ;
|
||||
byte iMSset;
|
||||
byte language;
|
||||
@@ -584,6 +585,7 @@ void setup() {
|
||||
invertdisplay = EEPROM.readByte(EE_BYTE_INVERTDISPLAY);
|
||||
NTPoffset = EEPROM.readByte(EE_BYTE_NTPOFFSET);
|
||||
autolog = EEPROM.readByte(EE_BYTE_AUTOLOG);
|
||||
autoDST = EEPROM.readByte(EE_BYTE_AUTODST);
|
||||
|
||||
if (spispeed == SPI_SPEED_DEFAULT) {
|
||||
tft.setSPISpeed(SPI_FREQUENCY / 1000000);
|
||||
@@ -4565,6 +4567,7 @@ void DefaultSettings() {
|
||||
EEPROM.writeUInt(EE_UINT16_CALTOUCH5, 3);
|
||||
EEPROM.writeByte(EE_BYTE_NTPOFFSET, 1);
|
||||
EEPROM.writeByte(EE_BYTE_AUTOLOG, 1);
|
||||
EEPROM.writeByte(EE_BYTE_AUTODST, 1);
|
||||
|
||||
#ifdef DEEPELEC_DP_66X
|
||||
EEPROM.writeByte(EE_BYTE_ROTARYMODE, 1);
|
||||
@@ -4816,6 +4819,7 @@ void endMenu() {
|
||||
EEPROM.writeByte(EE_BYTE_WAITONLYONSIGNAL, scanholdonsignal);
|
||||
EEPROM.writeByte(EE_BYTE_NTPOFFSET, NTPoffset);
|
||||
EEPROM.writeByte(EE_BYTE_AUTOLOG, autolog);
|
||||
EEPROM.writeByte(EE_BYTE_AUTODST, autoDST);
|
||||
EEPROM.commit();
|
||||
if (af == 2) radio.rds.afreg = true; else radio.rds.afreg = false;
|
||||
Serial.end();
|
||||
@@ -5661,8 +5665,21 @@ String getCurrentDateTime() {
|
||||
|
||||
// Adjust timeInfo using the GMT offset
|
||||
time_t currentEpoch = mktime(&timeInfo); // Convert struct tm to time_t format
|
||||
|
||||
// Calculate GMT offset
|
||||
currentEpoch += (NTPupdated ? NTPoffset * 3600 : radio.rds.offset); // Apply GMT offset if NTPupdated, else RDS offset
|
||||
localtime_r(¤tEpoch, &timeInfo); // Convert adjusted time back to struct tm format
|
||||
|
||||
// Apply DST adjustment if NTPupdated and autoDST are true
|
||||
if (NTPupdated && autoDST) {
|
||||
struct tm tempTimeInfo;
|
||||
localtime_r(¤tEpoch, &tempTimeInfo); // Convert to struct tm for DST calculation
|
||||
if (isDST(mktime(&tempTimeInfo))) { // Check if DST is in effect
|
||||
currentEpoch += 3600; // Add 1-hour DST offset
|
||||
}
|
||||
}
|
||||
|
||||
// Convert adjusted time back to struct tm format
|
||||
localtime_r(¤tEpoch, &timeInfo);
|
||||
|
||||
// Buffer for formatted date-time string
|
||||
char buf[20];
|
||||
@@ -5689,6 +5706,39 @@ String getCurrentDateTime() {
|
||||
}
|
||||
}
|
||||
|
||||
bool isDST(time_t t) {
|
||||
struct tm timeInfo;
|
||||
localtime_r(&t, &timeInfo); // Convert time_t to struct tm
|
||||
|
||||
int month = timeInfo.tm_mon + 1; // tm_mon is 0-based, so add 1
|
||||
int day = timeInfo.tm_mday; // tm_mday is the day of the month
|
||||
int hour = timeInfo.tm_hour; // tm_hour is the hour of the day
|
||||
int weekday = timeInfo.tm_wday; // tm_wday is the day of the week (0 = Sunday)
|
||||
|
||||
// DST starts last Sunday in March at 2:00 AM
|
||||
if (month == 3) {
|
||||
int lastSunday = 31 - ((weekday + 31 - day) % 7);
|
||||
if (day > lastSunday || (day == lastSunday && hour >= 2)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// DST ends last Sunday in October at 3:00 AM
|
||||
if (month == 10) {
|
||||
int lastSunday = 31 - ((weekday + 31 - day) % 7);
|
||||
if (day < lastSunday || (day == lastSunday && hour < 3)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// DST is active from April to September
|
||||
if (month > 3 && month < 10) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void handleLogo() {
|
||||
fs::File file = SPIFFS.open("/logo.png", "r");
|
||||
if (!file) {
|
||||
|
||||
+5
-4
@@ -225,9 +225,9 @@
|
||||
#define EE_CHECKBYTE_VALUE 10 // 0 ~ 255,add new entry, change for new value
|
||||
#define EE_PRESETS_FREQUENCY 0 // Default value when memory channel should be skipped!
|
||||
#ifdef HAS_AIR_BAND
|
||||
#define EE_TOTAL_CNT 2282 // Total occupied eeprom bytes
|
||||
#define EE_TOTAL_CNT 2283 // Total occupied eeprom bytes
|
||||
#else
|
||||
#define EE_TOTAL_CNT 2277 // Total occupied eeprom bytes
|
||||
#define EE_TOTAL_CNT 2278 // Total occupied eeprom bytes
|
||||
#endif
|
||||
|
||||
#define EE_PRESETS_BAND_START 0 // 99 * 1 byte
|
||||
@@ -347,9 +347,10 @@
|
||||
#define EE_BYTE_INVERTDISPLAY 2274
|
||||
#define EE_BYTE_NTPOFFSET 2275
|
||||
#define EE_BYTE_AUTOLOG 2276
|
||||
#define EE_BYTE_AUTODST 2277
|
||||
#ifdef HAS_AIR_BAND
|
||||
#define EE_BYTE_AIRSTEPSIZE 2277
|
||||
#define EE_UINT16_FREQUENCY_AIR 2278
|
||||
#define EE_BYTE_AIRSTEPSIZE 2278
|
||||
#define EE_UINT16_FREQUENCY_AIR 2279
|
||||
#endif
|
||||
// End of EEPROM index defines
|
||||
|
||||
|
||||
+40
@@ -1407,6 +1407,16 @@ void ShowOneLine(byte position, byte item, bool selected) {
|
||||
FullLineSprite.drawString("kHz", 298, 2);
|
||||
break;
|
||||
|
||||
case CONNECTIVITY:
|
||||
FullLineSprite.setTextDatum(TL_DATUM);
|
||||
FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
||||
FullLineSprite.drawString(removeNewline(myLanguage[language][299]), 6, 2);
|
||||
|
||||
FullLineSprite.setTextDatum(TR_DATUM);
|
||||
FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
||||
FullLineSprite.drawString((autoDST ? myLanguage[language][42] : myLanguage[language][30]), 298, 2);
|
||||
break;
|
||||
|
||||
case DXMODE:
|
||||
FullLineSprite.setTextDatum(TL_DATUM);
|
||||
FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
||||
@@ -2486,6 +2496,15 @@ void ShowOneButton(byte position, byte item, bool selected) {
|
||||
PSSprite.drawString("kHz", 77, 15);
|
||||
break;
|
||||
|
||||
case CONNECTIVITY:
|
||||
PSSprite.setTextDatum(TC_DATUM);
|
||||
PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
||||
PSSprite.drawString(shortLine(removeNewline(myLanguage[language][299])), 75, 1);
|
||||
|
||||
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
||||
PSSprite.drawString((autoDST ? myLanguage[language][42] : myLanguage[language][30]), 75, 15);
|
||||
break;
|
||||
|
||||
case DXMODE:
|
||||
PSSprite.setTextDatum(TC_DATUM);
|
||||
PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
||||
@@ -3800,6 +3819,13 @@ void MenuUp() {
|
||||
OneBigLineSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset), 155, 0);
|
||||
OneBigLineSprite.pushSprite(24, 118);
|
||||
break;
|
||||
|
||||
case ITEM8:
|
||||
autoDST = !autoDST;
|
||||
|
||||
OneBigLineSprite.drawString((autoDST ? myLanguage[language][42] : myLanguage[language][30]), 135, 0);
|
||||
OneBigLineSprite.pushSprite(24, 118);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -4771,6 +4797,13 @@ void MenuDown() {
|
||||
OneBigLineSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset), 155, 0);
|
||||
OneBigLineSprite.pushSprite(24, 118);
|
||||
break;
|
||||
|
||||
case ITEM8:
|
||||
autoDST = !autoDST;
|
||||
|
||||
OneBigLineSprite.drawString((autoDST ? myLanguage[language][42] : myLanguage[language][30]), 135, 0);
|
||||
OneBigLineSprite.pushSprite(24, 118);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -5800,6 +5833,13 @@ void DoMenu() {
|
||||
OneBigLineSprite.drawString((NTPoffset > -1 ? "+" : "") + String(NTPoffset), 155, 0);
|
||||
OneBigLineSprite.pushSprite(24, 118);
|
||||
break;
|
||||
|
||||
case ITEM8:
|
||||
Infoboxprint(myLanguage[language][299]);
|
||||
|
||||
OneBigLineSprite.drawString((autoDST ? myLanguage[language][42] : myLanguage[language][30]), 135, 0);
|
||||
OneBigLineSprite.pushSprite(24, 118);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ extern bool afmethodBold;
|
||||
extern bool afpage;
|
||||
extern bool afscreen;
|
||||
extern bool artheadold;
|
||||
extern bool autoDST;
|
||||
extern bool autolog;
|
||||
extern bool autosquelch;
|
||||
extern bool BWreset;
|
||||
|
||||
+57
-21
@@ -5,7 +5,7 @@
|
||||
|
||||
// [number of languages][number of texts]
|
||||
|
||||
static const char* const myLanguage[18][298] PROGMEM = {
|
||||
static const char* const myLanguage[18][300] PROGMEM = {
|
||||
{ "English", // English
|
||||
"Rotary direction changed", // 1
|
||||
"Please release button", // 2
|
||||
@@ -303,7 +303,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Nederlands", // Dutch
|
||||
@@ -601,9 +603,11 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Logboek legen", // 292
|
||||
"Logboek geleegd", // 293
|
||||
"Legen mislukt", // 294
|
||||
"NTP tijdverschil instellen", // 295
|
||||
"NTP tijdverschil\ninstellen", // 295
|
||||
"Automatisch loggen", // 296
|
||||
"Logboek vol!" // 297
|
||||
"Logboek vol!", // 297
|
||||
"Klok methode", // 298
|
||||
"Auto zomertijd\nop NTP tijd" // 299
|
||||
},
|
||||
|
||||
{ "Polski", // Polish
|
||||
@@ -903,7 +907,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Błąd wyczyszczenia", // 294
|
||||
"Ustaw odchyl. czasu NTP", // 295
|
||||
"Autologowanie stacji", // 296
|
||||
"Wykaz pełny!" // 297
|
||||
"Wykaz pełny!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Hrvatski", // Croatian
|
||||
@@ -1203,7 +1209,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Ελληνικά", // Greek
|
||||
@@ -1503,7 +1511,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Η εκκαθάριση απέτυχε", // 294
|
||||
"Ολίσθηση ώρας NTP", // 295
|
||||
"Αυτόματη καταγραφή", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Română", // Romanian
|
||||
@@ -1803,7 +1813,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Deutsch", // German
|
||||
@@ -2103,7 +2115,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Löschen fehlgeschlagen", // 294
|
||||
"NTP-Zeitversatz einstellen", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Český", // Czech
|
||||
@@ -2403,7 +2417,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Magyar", // Hungarian
|
||||
@@ -2703,7 +2719,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Français", // French
|
||||
@@ -3003,7 +3021,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Échec de l'effacement", // 294
|
||||
"Décalage horaire NTP", // 295
|
||||
"Journal automatique", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Български", // Bulgarian
|
||||
@@ -3303,7 +3323,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Русский", // Russian
|
||||
@@ -3603,7 +3625,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Українська", // Ukranian
|
||||
@@ -3903,7 +3927,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Italiano", // Italian
|
||||
@@ -4203,7 +4229,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Cancellazione non riuscita", // 294
|
||||
"Imposta offset orario NTP", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Simplified Chinese", // Simplified Chinese
|
||||
@@ -4503,7 +4531,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Clear failed", // 294
|
||||
"Set NTP time offset", // 295
|
||||
"Autologger", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Norsk", // Norwegian
|
||||
@@ -4803,7 +4833,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Slett mislyktes", // 294
|
||||
"Angi NTP-tidsforskyvning", // 295
|
||||
"Autologger", // 296
|
||||
"Loggbok full!" // 297
|
||||
"Loggbok full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Español", // Spanish
|
||||
@@ -5103,7 +5135,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Error al borrar", // 294
|
||||
"Desfase de tiempo NTP", // 295
|
||||
"Registrador automático", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
},
|
||||
|
||||
{ "Português", // Portuguese
|
||||
@@ -5403,7 +5437,9 @@ static const char* const myLanguage[18][298] PROGMEM = {
|
||||
"Falha ao limpar", // 294
|
||||
"Deslocamento de\ntempo NTP", // 295
|
||||
"Registrador automático", // 296
|
||||
"Logbook full!" // 297
|
||||
"Logbook full!", // 297
|
||||
"Clock mode", // 298
|
||||
"Auto DST on NTP time" // 299
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
@@ -801,6 +801,11 @@ void showCT() {
|
||||
// Apply the GMT offset only if NTPupdated is true
|
||||
if (NTPupdated) {
|
||||
t += NTPoffset * 3600; // Convert offset from hours to seconds
|
||||
|
||||
// Apply DST adjustment if autoDST is enabled
|
||||
if (autoDST && isDST(t)) {
|
||||
t += 3600; // Add 1 hour for DST
|
||||
}
|
||||
}
|
||||
|
||||
// Format the time based on region
|
||||
|
||||
@@ -13,6 +13,7 @@ extern bool afmethodBold;
|
||||
extern bool afpage;
|
||||
extern bool afscreen;
|
||||
extern bool aftest;
|
||||
extern bool autoDST;
|
||||
extern bool artheadold;
|
||||
extern bool BWreset;
|
||||
extern bool compressedold;
|
||||
@@ -154,4 +155,5 @@ extern void ShowRDSLogo(bool RDSstatus);
|
||||
extern void DataPrint(String string);
|
||||
extern void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, uint8_t fontsize);
|
||||
extern void tftReplace(int8_t offset, const String & textold, const String & text, int16_t x, int16_t y, int color, int smoothcolor, int background, uint8_t fontsize);
|
||||
extern bool isDST(time_t t);
|
||||
#endif
|
||||
Reference in New Issue
Block a user