diff --git a/.gitignore b/.gitignore index 2aea196..0232149 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ .vscode .idea -*.bmp \ No newline at end of file +*.bmp +watchfaces/libraries diff --git a/watchfaces/tetris-2.0/Watchy_Tetris.cpp b/watchfaces/tetris-2.0/Watchy_Tetris.cpp index 542df44..6bfb09e 100644 --- a/watchfaces/tetris-2.0/Watchy_Tetris.cpp +++ b/watchfaces/tetris-2.0/Watchy_Tetris.cpp @@ -30,6 +30,8 @@ void WatchyTetris::drawWatchFace() // Background display.drawBitmap(0, 0, tetrisbg, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_BLACK); + readWorldTime(); + //Hour display.drawBitmap(25, 20, tetris_nums_0[currentTime.Hour / 10], 40, 60, GxEPD_BLACK); //first digit display.drawBitmap(75, 20, tetris_nums_1[currentTime.Hour % 10], 40, 60, GxEPD_BLACK); //second digit diff --git a/watchfaces/tetris-2.0/Watchy_Tetris.h b/watchfaces/tetris-2.0/Watchy_Tetris.h index b17841f..54265bc 100644 --- a/watchfaces/tetris-2.0/Watchy_Tetris.h +++ b/watchfaces/tetris-2.0/Watchy_Tetris.h @@ -3,8 +3,12 @@ #include #include "tetris.h" +#include "wta.h" -class WatchyTetris : public Watchy +#undef WTA_TIMEZONE +#define WTA_TIMEZONE "Europe/Paris" + +class WatchyTetris : public WatchySynced { public: WatchyTetris(); diff --git a/watchfaces/tetris-2.0/wta.cpp b/watchfaces/tetris-2.0/wta.cpp new file mode 100644 index 0000000..28afea2 --- /dev/null +++ b/watchfaces/tetris-2.0/wta.cpp @@ -0,0 +1,42 @@ +#include "wta.h" + +RTC_DATA_ATTR int worldTimeIntervalCounter = WTA_UPDATE_INTERVAL; + +void WatchySynced::readWorldTime() +{ + if (worldTimeIntervalCounter >= WTA_UPDATE_INTERVAL) + { + if (connectWiFi()) + { + HTTPClient http; + http.setConnectTimeout(10000); + String queryURL = String(WTA_URL) + String(WTA_TIMEZONE); + http.begin(queryURL.c_str()); + int httpResponseCode = http.GET(); + if (httpResponseCode == 200) + { + String payload = http.getString(); + JSONVar responseObject = JSON.parse(payload); + tmElements_t tm; + String datetime = String((const char *)responseObject["datetime"]); + tm.Year = datetime.substring(0, 4).toInt() - YEAR_OFFSET; + tm.Month = datetime.substring(5, 7).toInt(); + tm.Day = datetime.substring(8, 10).toInt(); + tm.Hour = datetime.substring(11, 13).toInt(); + tm.Minute = datetime.substring(14, 16).toInt(); + tm.Second = 0; + time_t t = makeTime(tm); + RTC.set(t); + RTC.read(currentTime); + } + http.end(); + WiFi.mode(WIFI_OFF); + btStop(); + } + worldTimeIntervalCounter = 0; + } + else + { + worldTimeIntervalCounter++; + } +} \ No newline at end of file diff --git a/watchfaces/tetris-2.0/wta.h b/watchfaces/tetris-2.0/wta.h new file mode 100644 index 0000000..a350c78 --- /dev/null +++ b/watchfaces/tetris-2.0/wta.h @@ -0,0 +1,16 @@ +#ifndef WTA_H +#define WTA_H + +#include + +#define WTA_URL "http://worldtimeapi.org/api/timezone/" +#define WTA_TIMEZONE "Etc/UTC" +#define WTA_UPDATE_INTERVAL 60 //minutes + +class WatchySynced : public Watchy +{ +public: + void readWorldTime(); +}; + +#endif \ No newline at end of file