diff --git a/examples/WatchFaces/7_SEG/7_SEG.ino b/examples/WatchFaces/7_SEG/7_SEG.ino index 37c2e1d..2ab7607 100644 --- a/examples/WatchFaces/7_SEG/7_SEG.ino +++ b/examples/WatchFaces/7_SEG/7_SEG.ino @@ -1,6 +1,7 @@ #include "Watchy_7_SEG.h" +#include "settings.h" -Watchy7SEG watchy; +Watchy7SEG watchy(settings); void setup(){ watchy.init(); diff --git a/examples/WatchFaces/7_SEG/Watchy_7_SEG.cpp b/examples/WatchFaces/7_SEG/Watchy_7_SEG.cpp index 275722d..f0c616a 100644 --- a/examples/WatchFaces/7_SEG/Watchy_7_SEG.cpp +++ b/examples/WatchFaces/7_SEG/Watchy_7_SEG.cpp @@ -8,8 +8,6 @@ const uint8_t BATTERY_SEGMENT_SPACING = 9; const uint8_t WEATHER_ICON_WIDTH = 48; const uint8_t WEATHER_ICON_HEIGHT = 32; -Watchy7SEG::Watchy7SEG(){} //constructor - void Watchy7SEG::drawWatchFace(){ display.fillScreen(DARKMODE ? GxEPD_BLACK : GxEPD_WHITE); display.setTextColor(DARKMODE ? GxEPD_WHITE : GxEPD_BLACK); @@ -124,7 +122,7 @@ void Watchy7SEG::drawWeather(){ display.setCursor(159 - w - x1, 136); } display.println(temperature); - display.drawBitmap(165, 110, strcmp(TEMP_UNIT, "metric") == 0 ? celsius : fahrenheit, 26, 20, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK); + display.drawBitmap(165, 110, currentWeather.isMetric ? celsius : fahrenheit, 26, 20, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK); const unsigned char* weatherIcon; //https://openweathermap.org/weather-conditions diff --git a/examples/WatchFaces/7_SEG/Watchy_7_SEG.h b/examples/WatchFaces/7_SEG/Watchy_7_SEG.h index 89242bd..b3d85f1 100644 --- a/examples/WatchFaces/7_SEG/Watchy_7_SEG.h +++ b/examples/WatchFaces/7_SEG/Watchy_7_SEG.h @@ -9,8 +9,8 @@ #include "icons.h" class Watchy7SEG : public Watchy{ + using Watchy::Watchy; public: - Watchy7SEG(); void drawWatchFace(); void drawTime(); void drawDate(); diff --git a/examples/WatchFaces/7_SEG/settings.h b/examples/WatchFaces/7_SEG/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/7_SEG/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 * -5 //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/examples/WatchFaces/Basic/Basic.ino b/examples/WatchFaces/Basic/Basic.ino index aeffc3b..5bc949b 100644 --- a/examples/WatchFaces/Basic/Basic.ino +++ b/examples/WatchFaces/Basic/Basic.ino @@ -1,6 +1,7 @@ #include +#include "settings.h" -Watchy watchy; +Watchy watchy(settings); void setup(){ watchy.init(); diff --git a/examples/WatchFaces/Basic/settings.h b/examples/WatchFaces/Basic/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/Basic/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 * -5 //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/examples/WatchFaces/DOS/DOS.ino b/examples/WatchFaces/DOS/DOS.ino index 7ea4ef8..ca9682b 100644 --- a/examples/WatchFaces/DOS/DOS.ino +++ b/examples/WatchFaces/DOS/DOS.ino @@ -1,6 +1,7 @@ #include "Watchy_DOS.h" +#include "settings.h" -WatchyDOS watchy; +WatchyDOS watchy(settings); void setup(){ watchy.init(); diff --git a/examples/WatchFaces/DOS/Watchy_DOS.cpp b/examples/WatchFaces/DOS/Watchy_DOS.cpp index 0d8364e..0b807f4 100644 --- a/examples/WatchFaces/DOS/Watchy_DOS.cpp +++ b/examples/WatchFaces/DOS/Watchy_DOS.cpp @@ -1,7 +1,5 @@ #include "Watchy_DOS.h" -WatchyDOS::WatchyDOS(){} //constructor - void WatchyDOS::drawWatchFace(){ char time[6]; time[0] = '0' + ((currentTime.Hour/10)%10); diff --git a/examples/WatchFaces/DOS/Watchy_DOS.h b/examples/WatchFaces/DOS/Watchy_DOS.h index dbb9798..94c2fbd 100644 --- a/examples/WatchFaces/DOS/Watchy_DOS.h +++ b/examples/WatchFaces/DOS/Watchy_DOS.h @@ -5,8 +5,8 @@ #include "Px437_IBM_BIOS5pt7b.h" class WatchyDOS : public Watchy{ + using Watchy::Watchy; public: - WatchyDOS(); void drawWatchFace(); }; diff --git a/examples/WatchFaces/DOS/settings.h b/examples/WatchFaces/DOS/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/DOS/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 * -5 //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/examples/WatchFaces/MacPaint/MacPaint.ino b/examples/WatchFaces/MacPaint/MacPaint.ino index 7373c95..1b4df6b 100644 --- a/examples/WatchFaces/MacPaint/MacPaint.ino +++ b/examples/WatchFaces/MacPaint/MacPaint.ino @@ -1,6 +1,7 @@ #include "Watchy_MacPaint.h" +#include "settings.h" -WatchyMacPaint watchy; +WatchyMacPaint watchy(settings); void setup(){ watchy.init(); diff --git a/examples/WatchFaces/MacPaint/Watchy_MacPaint.cpp b/examples/WatchFaces/MacPaint/Watchy_MacPaint.cpp index 734c9cd..1f2bab0 100644 --- a/examples/WatchFaces/MacPaint/Watchy_MacPaint.cpp +++ b/examples/WatchFaces/MacPaint/Watchy_MacPaint.cpp @@ -2,8 +2,6 @@ const unsigned char *numbers [10] = {numbers0, numbers1, numbers2, numbers3, numbers4, numbers5, numbers6, numbers7, numbers8, numbers9}; -WatchyMacPaint::WatchyMacPaint(){} //constructor - void WatchyMacPaint::drawWatchFace(){ display.fillScreen(GxEPD_WHITE); display.drawBitmap(0, 0, window, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_BLACK); diff --git a/examples/WatchFaces/MacPaint/Watchy_MacPaint.h b/examples/WatchFaces/MacPaint/Watchy_MacPaint.h index e9242da..a3999ad 100644 --- a/examples/WatchFaces/MacPaint/Watchy_MacPaint.h +++ b/examples/WatchFaces/MacPaint/Watchy_MacPaint.h @@ -5,8 +5,8 @@ #include "macpaint.h" class WatchyMacPaint : public Watchy{ + using Watchy::Watchy; public: - WatchyMacPaint(); void drawWatchFace(); }; diff --git a/examples/WatchFaces/MacPaint/settings.h b/examples/WatchFaces/MacPaint/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/MacPaint/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 * -5 //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/examples/WatchFaces/Pokemon/Pokemon.ino b/examples/WatchFaces/Pokemon/Pokemon.ino index eaccd44..56f48b3 100644 --- a/examples/WatchFaces/Pokemon/Pokemon.ino +++ b/examples/WatchFaces/Pokemon/Pokemon.ino @@ -1,6 +1,7 @@ #include "Watchy_Pokemon.h" +#include "settings.h" -WatchyPokemon watchy; +WatchyPokemon watchy(settings); void setup(){ watchy.init(); diff --git a/examples/WatchFaces/Pokemon/Watchy_Pokemon.cpp b/examples/WatchFaces/Pokemon/Watchy_Pokemon.cpp index 660bbad..e514558 100644 --- a/examples/WatchFaces/Pokemon/Watchy_Pokemon.cpp +++ b/examples/WatchFaces/Pokemon/Watchy_Pokemon.cpp @@ -1,7 +1,5 @@ #include "Watchy_Pokemon.h" -WatchyPokemon::WatchyPokemon(){} //constructor - void WatchyPokemon::drawWatchFace(){ display.fillScreen(GxEPD_WHITE); display.drawBitmap(0, 0, pokemon, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_BLACK); diff --git a/examples/WatchFaces/Pokemon/Watchy_Pokemon.h b/examples/WatchFaces/Pokemon/Watchy_Pokemon.h index 08ca8ed..581f915 100644 --- a/examples/WatchFaces/Pokemon/Watchy_Pokemon.h +++ b/examples/WatchFaces/Pokemon/Watchy_Pokemon.h @@ -5,8 +5,8 @@ #include "pokemon.h" class WatchyPokemon : public Watchy{ + using Watchy::Watchy; public: - WatchyPokemon(); void drawWatchFace(); }; diff --git a/examples/WatchFaces/Pokemon/settings.h b/examples/WatchFaces/Pokemon/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/Pokemon/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 * -5 //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/examples/WatchFaces/StarryHorizon/StarryHorizon.ino b/examples/WatchFaces/StarryHorizon/StarryHorizon.ino index 2878de1..f165405 100644 --- a/examples/WatchFaces/StarryHorizon/StarryHorizon.ino +++ b/examples/WatchFaces/StarryHorizon/StarryHorizon.ino @@ -6,6 +6,7 @@ #include //include any fonts you want to use #include "MadeSunflower39pt7b.h" #include "stars.h" +#include "settings.h" #define STAR_COUNT 900 @@ -50,9 +51,9 @@ struct xyPoint rotatePointAround(int x, int y, int ox, int oy, double angle) { class StarryHorizon : public Watchy { public: - StarryHorizon() { + StarryHorizon(const watchySettings& s) : Watchy(s) { // uncomment to re-generate stars -// initStars(); + // initStars(); } void drawWatchFace(){ display.fillScreen(GxEPD_BLACK); @@ -139,7 +140,7 @@ class StarryHorizon : public Watchy { } }; -StarryHorizon face; //instantiate watchface +StarryHorizon face(settings); //instantiate watchface void setup() { face.init(); //call init in setup diff --git a/examples/WatchFaces/StarryHorizon/settings.h b/examples/WatchFaces/StarryHorizon/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/StarryHorizon/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 * -5 //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/examples/WatchFaces/Tetris/Tetris.ino b/examples/WatchFaces/Tetris/Tetris.ino index 4f12fc2..2cef539 100644 --- a/examples/WatchFaces/Tetris/Tetris.ino +++ b/examples/WatchFaces/Tetris/Tetris.ino @@ -1,6 +1,7 @@ #include "Watchy_Tetris.h" +#include "settings.h" -WatchyTetris watchy; +WatchyTetris watchy(settings); void setup(){ watchy.init(); diff --git a/examples/WatchFaces/Tetris/Watchy_Tetris.h b/examples/WatchFaces/Tetris/Watchy_Tetris.h index e67b996..ba05f83 100644 --- a/examples/WatchFaces/Tetris/Watchy_Tetris.h +++ b/examples/WatchFaces/Tetris/Watchy_Tetris.h @@ -5,6 +5,7 @@ #include "tetris.h" class WatchyTetris : public Watchy{ + using Watchy::Watchy; public: WatchyTetris(); void drawWatchFace(); diff --git a/examples/WatchFaces/Tetris/settings.h b/examples/WatchFaces/Tetris/settings.h new file mode 100644 index 0000000..acf4169 --- /dev/null +++ b/examples/WatchFaces/Tetris/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 * -5 //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/src/Watchy.cpp b/src/Watchy.cpp index ca3161c..555f5d4 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -9,11 +9,9 @@ RTC_DATA_ATTR BMA423 sensor; RTC_DATA_ATTR bool WIFI_CONFIGURED; RTC_DATA_ATTR bool BLE_CONFIGURED; RTC_DATA_ATTR weatherData currentWeather; -RTC_DATA_ATTR int weatherIntervalCounter = WEATHER_UPDATE_INTERVAL; +RTC_DATA_ATTR int weatherIntervalCounter = -1; RTC_DATA_ATTR bool displayFullInit = true; -Watchy::Watchy(){} //constructor - void Watchy::init(String datetime){ esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); //get wake up reason @@ -561,18 +559,27 @@ void Watchy::drawWatchFace(){ } weatherData Watchy::getWeatherData(){ - if(weatherIntervalCounter >= WEATHER_UPDATE_INTERVAL){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes + return getWeatherData(settings.cityID, settings.weatherUnit, settings.weatherLang, settings.weatherURL, settings.weatherAPIKey, settings.weatherUpdateInterval); +} + +weatherData Watchy::getWeatherData(String cityID, String units, String lang, String url, String apiKey, uint8_t updateInterval){ + if(weatherIntervalCounter < 0){ //-1 on first run, set to updateInterval + weatherIntervalCounter = updateInterval; + } + if(weatherIntervalCounter >= updateInterval){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes if(connectWiFi()){ HTTPClient http; //Use Weather API for live data if WiFi is connected http.setConnectTimeout(3000);//3 second max timeout - String weatherQueryURL = String(OPENWEATHERMAP_URL) + String(CITY_NAME) + String(",") + String(COUNTRY_CODE) + String("&units=") + String(TEMP_UNIT) + String("&appid=") + String(OPENWEATHERMAP_APIKEY); + String weatherQueryURL = url + cityID + String("&units=") + units + String("&lang=") + lang + String("&appid=") + apiKey; http.begin(weatherQueryURL.c_str()); int httpResponseCode = http.GET(); if(httpResponseCode == 200) { String payload = http.getString(); JSONVar responseObject = JSON.parse(payload); currentWeather.temperature = int(responseObject["main"]["temp"]); - currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]); + currentWeather.isMetric = settings.weatherUnit == String("metric"); + currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]); + currentWeather.weatherDescription = responseObject["weather"][0]["main"]; }else{ //http error } @@ -582,7 +589,7 @@ weatherData Watchy::getWeatherData(){ btStop(); }else{//No WiFi, use internal temperature sensor uint8_t temperature = sensor.readTemperature(); //celsius - if(strcmp(TEMP_UNIT, "imperial") == 0){ + if(units != String("metric")){ temperature = temperature * 9. / 5. + 32.; //fahrenheit } currentWeather.temperature = temperature; @@ -904,7 +911,11 @@ void Watchy::showSyncNTP(){ } bool Watchy::syncNTP(){ //NTP sync - call after connecting to WiFi and remember to turn it back off - configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER); + return syncNTP(settings.gmtOffset, settings.dstOffset, settings.ntpServer.c_str()); +} + +bool Watchy::syncNTP(long gmt, int dst, String ntpServer){ //NTP sync - call after connecting to WiFi and remember to turn it back off + configTime(gmt, dst, ntpServer.c_str()); struct tm timeinfo; if(!getLocalTime(&timeinfo)){ return false; //NTP sync failed diff --git a/src/Watchy.h b/src/Watchy.h index 62f1a6d..c15e57c 100644 --- a/src/Watchy.h +++ b/src/Watchy.h @@ -17,15 +17,32 @@ typedef struct weatherData{ int8_t temperature; int16_t weatherConditionCode; + bool isMetric; + String weatherDescription; }weatherData; +typedef struct watchySettings{ + //Weather Settings + String cityID; + String weatherAPIKey; + String weatherURL; + String weatherUnit; + String weatherLang; + int8_t weatherUpdateInterval; + //NTP Settings + String ntpServer; + int gmtOffset; + int dstOffset; +}watchySettings; + class Watchy { public: static WatchyRTC RTC; static GxEPD2_BW display; tmElements_t currentTime; + watchySettings settings; public: - Watchy(); + explicit Watchy(const watchySettings& s) : settings(s){} //constructor void init(String datetime = ""); void deepSleep(); static void displayBusyCallback(const void*); @@ -41,10 +58,12 @@ class Watchy { void showUpdateFW(); void showSyncNTP(); bool syncNTP(); + bool syncNTP(long gmt, int dst, String ntpServer); void setTime(); void setupWifi(); bool connectWiFi(); weatherData getWeatherData(); + weatherData getWeatherData(String cityID, String units, String lang, String url, String apiKey, uint8_t updateInterval); void updateFWBegin(); void showWatchFace(bool partialRefresh); diff --git a/src/config.h b/src/config.h index f18bfc1..8f223d2 100644 --- a/src/config.h +++ b/src/config.h @@ -25,13 +25,6 @@ //display #define DISPLAY_WIDTH 200 #define DISPLAY_HEIGHT 200 -//weather api -#define CITY_NAME "NEW+YORK" //if your city name has a space, replace with '+' -#define COUNTRY_CODE "US" -#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :) -#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?q=" -#define TEMP_UNIT "metric" //use "imperial" for Fahrenheit" -#define WEATHER_UPDATE_INTERVAL 30 //minutes //wifi #define WIFI_AP_TIMEOUT 60 #define WIFI_AP_SSID "Watchy AP" @@ -49,9 +42,6 @@ #define SET_MONTH 3 #define SET_DAY 4 #define HOUR_12_24 24 -#define NTP_SERVER "pool.ntp.org" -#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 -#define DST_OFFSET_SEC 3600 //BLE OTA #define BLE_DEVICE_NAME "Watchy BLE OTA" #define WATCHFACE_NAME "Watchy 7 Segment"