From 084aa665caa24066a2c2acfdb3dbab4c63b2f2f7 Mon Sep 17 00:00:00 2001 From: Klemek Date: Sat, 9 Apr 2022 18:31:34 +0200 Subject: [PATCH] watchy lib 1.3 fixes --- watchfaces/below/Watchy_Below.cpp | 6 +- watchfaces/below/Watchy_Below.h | 9 +-- watchfaces/below/below.ino | 3 +- watchfaces/below/settings.h | 28 ++++++++ watchfaces/below/wta.cpp | 42 +++++++++++ watchfaces/below/wta.h | 19 +++++ watchfaces/pokemon-2.0/Watchy_Pokemon.cpp | 2 - watchfaces/pokemon-2.0/Watchy_Pokemon.h | 14 ++-- watchfaces/pokemon-2.0/pokemon-2.0.ino | 3 +- watchfaces/pokemon-2.0/settings.h | 28 ++++++++ watchfaces/pokemon-2.0/wta.cpp | 85 +++++++++++------------ watchfaces/pokemon-2.0/wta.h | 5 +- watchfaces/tetris-2.0/Watchy_Tetris.cpp | 4 -- watchfaces/tetris-2.0/Watchy_Tetris.h | 10 +-- watchfaces/tetris-2.0/settings.h | 28 ++++++++ watchfaces/tetris-2.0/tetris-2.0.ino | 3 +- watchfaces/tetris-2.0/wta.cpp | 7 +- watchfaces/tetris-2.0/wta.h | 5 +- 18 files changed, 222 insertions(+), 79 deletions(-) create mode 100644 watchfaces/below/settings.h create mode 100644 watchfaces/below/wta.cpp create mode 100644 watchfaces/below/wta.h create mode 100644 watchfaces/pokemon-2.0/settings.h create mode 100644 watchfaces/tetris-2.0/settings.h diff --git a/watchfaces/below/Watchy_Below.cpp b/watchfaces/below/Watchy_Below.cpp index bcffbd7..bd9000a 100644 --- a/watchfaces/below/Watchy_Below.cpp +++ b/watchfaces/below/Watchy_Below.cpp @@ -1,11 +1,9 @@ #include "Watchy_Below.h" -WatchyBelow::WatchyBelow() -{ -} //constructor - void WatchyBelow::drawWatchFace() { + readWorldTime(); + display.fillScreen(GxEPD_BLACK); display.drawBitmap(0, 0, background, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_WHITE); diff --git a/watchfaces/below/Watchy_Below.h b/watchfaces/below/Watchy_Below.h index d108c7f..f557f58 100644 --- a/watchfaces/below/Watchy_Below.h +++ b/watchfaces/below/Watchy_Below.h @@ -3,12 +3,13 @@ #include #include "below.h" +#include "wta.h" -class WatchyBelow : public Watchy +class WatchyBelow : public WatchySynced { -public: - WatchyBelow(); - void drawWatchFace(); + using WatchySynced::WatchySynced; + public: + void drawWatchFace(); }; #endif \ No newline at end of file diff --git a/watchfaces/below/below.ino b/watchfaces/below/below.ino index fa7eea4..172d281 100644 --- a/watchfaces/below/below.ino +++ b/watchfaces/below/below.ino @@ -1,6 +1,7 @@ #include "watchy_below.h" +#include "settings.h" -WatchyBelow watchy; +WatchyBelow watchy(settings); void setup() { diff --git a/watchfaces/below/settings.h b/watchfaces/below/settings.h new file mode 100644 index 0000000..4d0bf5f --- /dev/null +++ b/watchfaces/below/settings.h @@ -0,0 +1,28 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +//Weather Settings +#define CITY_ID "5128581" //New York City https://openweathermap.org/current#cityid +#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :) +#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api +#define TEMP_UNIT "metric" //metric = Celsius , imperial = Fahrenheit +#define TEMP_LANG "en" +#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes +//NTP Settings +#define NTP_SERVER "pool.ntp.org" +#define GMT_OFFSET_SEC 3600 * 1 //New York is UTC -5 +#define DST_OFFSET_SEC 3600 + +watchySettings settings{ + CITY_ID, + OPENWEATHERMAP_APIKEY, + OPENWEATHERMAP_URL, + TEMP_UNIT, + TEMP_LANG, + WEATHER_UPDATE_INTERVAL, + NTP_SERVER, + GMT_OFFSET_SEC, + DST_OFFSET_SEC +}; + +#endif \ No newline at end of file diff --git a/watchfaces/below/wta.cpp b/watchfaces/below/wta.cpp new file mode 100644 index 0000000..4fc5e5b --- /dev/null +++ b/watchfaces/below/wta.cpp @@ -0,0 +1,42 @@ +#include "wta.h" + +RTC_DATA_ATTR int worldTimeIntervalCounter = 0; + +void WatchySynced::readWorldTime() +{ + if (worldTimeIntervalCounter == 0) + { + worldTimeIntervalCounter = WTA_UPDATE_SHORT_INTERVAL; + if (connectWiFi()) + { + HTTPClient http; + http.setConnectTimeout(WTA_UPDATE_TIMEOUT); + 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 = y2kYearToTm(datetime.substring(0, 4).toInt()); + 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; + RTC.set(tm); + RTC.read(currentTime); + worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL; + } + http.end(); + WiFi.mode(WIFI_OFF); + btStop(); + } + } + else + { + worldTimeIntervalCounter = worldTimeIntervalCounter < 0 ? 0 : worldTimeIntervalCounter - 1; + } +} diff --git a/watchfaces/below/wta.h b/watchfaces/below/wta.h new file mode 100644 index 0000000..7703a56 --- /dev/null +++ b/watchfaces/below/wta.h @@ -0,0 +1,19 @@ +#ifndef WTA_H +#define WTA_H + +#include + +#define WTA_URL "http://worldtimeapi.org/api/timezone/" +#define WTA_TIMEZONE "Europe/Paris" +#define WTA_UPDATE_SHORT_INTERVAL 30 //minutes +#define WTA_UPDATE_LONG_INTERVAL 300 //minutes +#define WTA_UPDATE_TIMEOUT 10000 //ms + +class WatchySynced : public Watchy +{ + using Watchy::Watchy; + public: + void readWorldTime(); +}; + +#endif \ No newline at end of file diff --git a/watchfaces/pokemon-2.0/Watchy_Pokemon.cpp b/watchfaces/pokemon-2.0/Watchy_Pokemon.cpp index 4f8bf3f..669c680 100755 --- a/watchfaces/pokemon-2.0/Watchy_Pokemon.cpp +++ b/watchfaces/pokemon-2.0/Watchy_Pokemon.cpp @@ -13,8 +13,6 @@ const char *pokemon_names[151] = {"BULBASAUR","IVYSAUR","VENUSAUR","CHARMANDER", const float MAX_VBAT = 4.20; const float MIN_VBAT = 3.80; -WatchyPokemon::WatchyPokemon(){} //constructor - void WatchyPokemon::drawWatchFace(){ readWorldTime(); diff --git a/watchfaces/pokemon-2.0/Watchy_Pokemon.h b/watchfaces/pokemon-2.0/Watchy_Pokemon.h index 03a74b7..d3a7d28 100755 --- a/watchfaces/pokemon-2.0/Watchy_Pokemon.h +++ b/watchfaces/pokemon-2.0/Watchy_Pokemon.h @@ -6,6 +6,8 @@ #include "FreeMonoBold7pt7b.h" #include "wta.h" +#define FR + #ifdef FR #include "pokemon_fr.h" #else @@ -14,12 +16,12 @@ class WatchyPokemon : public WatchySynced { -public: - WatchyPokemon(); - void drawWatchFace(); - double randomDay(); - double randomHour(); - double randomMinute(); + using WatchySynced::WatchySynced; + public: + void drawWatchFace(); + double randomDay(); + double randomHour(); + double randomMinute(); }; #endif \ No newline at end of file diff --git a/watchfaces/pokemon-2.0/pokemon-2.0.ino b/watchfaces/pokemon-2.0/pokemon-2.0.ino index eaccd44..56f48b3 100755 --- a/watchfaces/pokemon-2.0/pokemon-2.0.ino +++ b/watchfaces/pokemon-2.0/pokemon-2.0.ino @@ -1,6 +1,7 @@ #include "Watchy_Pokemon.h" +#include "settings.h" -WatchyPokemon watchy; +WatchyPokemon watchy(settings); void setup(){ watchy.init(); diff --git a/watchfaces/pokemon-2.0/settings.h b/watchfaces/pokemon-2.0/settings.h new file mode 100644 index 0000000..4d0bf5f --- /dev/null +++ b/watchfaces/pokemon-2.0/settings.h @@ -0,0 +1,28 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +//Weather Settings +#define CITY_ID "5128581" //New York City https://openweathermap.org/current#cityid +#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :) +#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api +#define TEMP_UNIT "metric" //metric = Celsius , imperial = Fahrenheit +#define TEMP_LANG "en" +#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes +//NTP Settings +#define NTP_SERVER "pool.ntp.org" +#define GMT_OFFSET_SEC 3600 * 1 //New York is UTC -5 +#define DST_OFFSET_SEC 3600 + +watchySettings settings{ + CITY_ID, + OPENWEATHERMAP_APIKEY, + OPENWEATHERMAP_URL, + TEMP_UNIT, + TEMP_LANG, + WEATHER_UPDATE_INTERVAL, + NTP_SERVER, + GMT_OFFSET_SEC, + DST_OFFSET_SEC +}; + +#endif \ No newline at end of file diff --git a/watchfaces/pokemon-2.0/wta.cpp b/watchfaces/pokemon-2.0/wta.cpp index 7e55099..b79e8de 100644 --- a/watchfaces/pokemon-2.0/wta.cpp +++ b/watchfaces/pokemon-2.0/wta.cpp @@ -1,43 +1,42 @@ -#include "wta.h" - -RTC_DATA_ATTR int worldTimeIntervalCounter = 0; - -void WatchySynced::readWorldTime() -{ - if (worldTimeIntervalCounter == 0) - { - worldTimeIntervalCounter = WTA_UPDATE_SHORT_INTERVAL; - if (connectWiFi()) - { - HTTPClient http; - http.setConnectTimeout(WTA_UPDATE_TIMEOUT); - 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); - worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL; - } - http.end(); - WiFi.mode(WIFI_OFF); - btStop(); - } - } - else - { - worldTimeIntervalCounter = worldTimeIntervalCounter < 0 ? 0 : worldTimeIntervalCounter - 1; - } -} \ No newline at end of file +#include "wta.h" + +RTC_DATA_ATTR int worldTimeIntervalCounter = 0; + +void WatchySynced::readWorldTime() +{ + if (worldTimeIntervalCounter == 0) + { + worldTimeIntervalCounter = WTA_UPDATE_SHORT_INTERVAL; + if (connectWiFi()) + { + HTTPClient http; + http.setConnectTimeout(WTA_UPDATE_TIMEOUT); + 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 = y2kYearToTm(datetime.substring(0, 4).toInt()); + 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; + RTC.set(tm); + RTC.read(currentTime); + worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL; + } + http.end(); + WiFi.mode(WIFI_OFF); + btStop(); + } + } + else + { + worldTimeIntervalCounter = worldTimeIntervalCounter < 0 ? 0 : worldTimeIntervalCounter - 1; + } +} diff --git a/watchfaces/pokemon-2.0/wta.h b/watchfaces/pokemon-2.0/wta.h index 902d702..7703a56 100644 --- a/watchfaces/pokemon-2.0/wta.h +++ b/watchfaces/pokemon-2.0/wta.h @@ -11,8 +11,9 @@ class WatchySynced : public Watchy { -public: - void readWorldTime(); + using Watchy::Watchy; + public: + void readWorldTime(); }; #endif \ No newline at end of file diff --git a/watchfaces/tetris-2.0/Watchy_Tetris.cpp b/watchfaces/tetris-2.0/Watchy_Tetris.cpp index 97a37a3..c722c5a 100644 --- a/watchfaces/tetris-2.0/Watchy_Tetris.cpp +++ b/watchfaces/tetris-2.0/Watchy_Tetris.cpp @@ -19,10 +19,6 @@ const unsigned char *pieces[19] = { const float MAX_VBAT = 4.20; const float MIN_VBAT = 3.80; -WatchyTetris::WatchyTetris() -{ -} //constructor - void WatchyTetris::drawWatchFace() { readWorldTime(); diff --git a/watchfaces/tetris-2.0/Watchy_Tetris.h b/watchfaces/tetris-2.0/Watchy_Tetris.h index a3b0064..91809e0 100644 --- a/watchfaces/tetris-2.0/Watchy_Tetris.h +++ b/watchfaces/tetris-2.0/Watchy_Tetris.h @@ -7,11 +7,11 @@ class WatchyTetris : public WatchySynced { -public: - WatchyTetris(); - void drawWatchFace(); - void drawNumber(int x, int y, int value, int max_digits); - double random(); + using WatchySynced::WatchySynced; + public: + void drawWatchFace(); + void drawNumber(int x, int y, int value, int max_digits); + double random(); }; #endif \ No newline at end of file diff --git a/watchfaces/tetris-2.0/settings.h b/watchfaces/tetris-2.0/settings.h new file mode 100644 index 0000000..4d0bf5f --- /dev/null +++ b/watchfaces/tetris-2.0/settings.h @@ -0,0 +1,28 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +//Weather Settings +#define CITY_ID "5128581" //New York City https://openweathermap.org/current#cityid +#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :) +#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api +#define TEMP_UNIT "metric" //metric = Celsius , imperial = Fahrenheit +#define TEMP_LANG "en" +#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes +//NTP Settings +#define NTP_SERVER "pool.ntp.org" +#define GMT_OFFSET_SEC 3600 * 1 //New York is UTC -5 +#define DST_OFFSET_SEC 3600 + +watchySettings settings{ + CITY_ID, + OPENWEATHERMAP_APIKEY, + OPENWEATHERMAP_URL, + TEMP_UNIT, + TEMP_LANG, + WEATHER_UPDATE_INTERVAL, + NTP_SERVER, + GMT_OFFSET_SEC, + DST_OFFSET_SEC +}; + +#endif \ No newline at end of file diff --git a/watchfaces/tetris-2.0/tetris-2.0.ino b/watchfaces/tetris-2.0/tetris-2.0.ino index cb90e34..f5c98ce 100644 --- a/watchfaces/tetris-2.0/tetris-2.0.ino +++ b/watchfaces/tetris-2.0/tetris-2.0.ino @@ -1,6 +1,7 @@ #include "Watchy_Tetris.h" +#include "settings.h" -WatchyTetris watchy; +WatchyTetris watchy(settings); void setup() { diff --git a/watchfaces/tetris-2.0/wta.cpp b/watchfaces/tetris-2.0/wta.cpp index 7e55099..4fc5e5b 100644 --- a/watchfaces/tetris-2.0/wta.cpp +++ b/watchfaces/tetris-2.0/wta.cpp @@ -20,14 +20,13 @@ void WatchySynced::readWorldTime() 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.Year = y2kYearToTm(datetime.substring(0, 4).toInt()); 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.set(tm); RTC.read(currentTime); worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL; } @@ -40,4 +39,4 @@ void WatchySynced::readWorldTime() { worldTimeIntervalCounter = worldTimeIntervalCounter < 0 ? 0 : worldTimeIntervalCounter - 1; } -} \ No newline at end of file +} diff --git a/watchfaces/tetris-2.0/wta.h b/watchfaces/tetris-2.0/wta.h index 902d702..7703a56 100644 --- a/watchfaces/tetris-2.0/wta.h +++ b/watchfaces/tetris-2.0/wta.h @@ -11,8 +11,9 @@ class WatchySynced : public Watchy { -public: - void readWorldTime(); + using Watchy::Watchy; + public: + void readWorldTime(); }; #endif \ No newline at end of file