Skip to content

Commit

Permalink
added timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
pr3y committed May 28, 2024
1 parent 4efe028 commit f93a70c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "display.h"
#include "mykeyboard.h"
#include "wg.h" //for isConnectedWireguard to print wireguard lock
//#include "settings.h" //for timeStr
#include "settings.h" //for timeStr

#if defined(CARDPUTER) || defined(STICK_C_PLUS2) //Battery Calculation
#include <driver/adc.h>
Expand Down
30 changes: 17 additions & 13 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ void setBrightnessMenu() {
** Handles Menu to set timezone to NTP
**********************************************************************/
const char* ntpServer = "pool.ntp.org";
//const long selectedTimezone = -3 * 3600; // GMT -3 hours (Sao Paulo timezone)
long selectedTimezone;
const int daylightOffset_sec = 0;
int timeHour;

TimeChangeRule BRST = {"BRST", Last, Sun, Oct, 0, -180};
Timezone myTZ(BRST, BRST); // Create Timezone object with the same rule for standard and daylight time
TimeChangeRule BRST = {"BRST", Last, Sun, Oct, 0, timeHour};
Timezone myTZ(BRST, BRST);

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpServer, selectedTimezone, daylightOffset_sec);
Expand All @@ -123,16 +123,21 @@ NTPClient timeClient(ntpUDP, ntpServer, selectedTimezone, daylightOffset_sec);
void setClock() {

if(!wifiConnected) wifiConnectMenu();

options = {
{"Brasilia", [=]() { selectedTimezone = -3 * 3600; }},
{"New York", [=]() { selectedTimezone = -4 * 3600; }},
{"Lisbon", [=]() { selectedTimezone = 1 * 3600; }},
{"Hong Kong", [=]() { selectedTimezone = 8 * 3600; }},
{"Sydney", [=]() { selectedTimezone = 10 * 3600; }},
{"Tokyo", [=]() { selectedTimezone = 9 * 3600; }},
{"Brasilia", [=]() { timeClient.setTimeOffset(-3 * 3600); }},
{"Pernambuco", [=]() { timeClient.setTimeOffset(-2 * 3600); }},
{"New York", [=]() { timeClient.setTimeOffset(-4 * 3600); }},
{"Lisbon", [=]() { timeClient.setTimeOffset(1 * 3600); }},
{"Hong Kong", [=]() { timeClient.setTimeOffset(8 * 3600); }},
{"Sydney", [=]() { timeClient.setTimeOffset(10 * 3600); }},
{"Tokyo", [=]() { timeClient.setTimeOffset(9 * 3600); }},
{"Moscow", [=]() { timeClient.setTimeOffset(3 * 3600); }},
{"Amsterdan", [=]() { timeClient.setTimeOffset(2 * 3600); }},
};

delay(200);
loopOptions(options, true);
loopOptions(options);
delay(200);

timeClient.begin();
Expand All @@ -145,7 +150,7 @@ void runClockLoop() {
for (;;){

timeClient.update();
time_t localTime = myTZ.toLocal(timeClient.getEpochTime()); // Convert NTP time to local time in Sao Paulo timezone
time_t localTime = myTZ.toLocal(timeClient.getEpochTime());
struct tm* timeInfo = localtime(&localTime);

char timeStr[10];
Expand All @@ -154,6 +159,7 @@ void runClockLoop() {
Serial.print("Current time: ");
Serial.println(timeStr);
tft.fillScreen(BGCOLOR);
tft.drawRect(45,40,150,45, FGCOLOR);
tft.setCursor(60, 50);
tft.setTextSize(4);
tft.println(timeStr);
Expand Down Expand Up @@ -181,5 +187,3 @@ void runClockLoop() {
}
}



0 comments on commit f93a70c

Please sign in to comment.