From b0e405e187bf59fbb5ccc9504ad871fb49e713c5 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sun, 16 Oct 2022 00:20:05 +1100 Subject: [PATCH 1/3] Use designated initialisers for watchySettings This [0] allows to skip obsolete fields, and generally not have to rely on field ordering. [0] https://www.cppstories.com/2021/designated-init-cpp20/ Signed-off-by: Olivier Mehani --- examples/WatchFaces/7_SEG/settings.h | 16 ++++++++-------- examples/WatchFaces/Basic/settings.h | 16 ++++++++-------- examples/WatchFaces/DOS/settings.h | 16 ++++++++-------- examples/WatchFaces/MacPaint/settings.h | 16 ++++++++-------- examples/WatchFaces/Pokemon/settings.h | 16 ++++++++-------- examples/WatchFaces/StarryHorizon/settings.h | 16 ++++++++-------- examples/WatchFaces/Tetris/settings.h | 16 ++++++++-------- 7 files changed, 56 insertions(+), 56 deletions(-) diff --git a/examples/WatchFaces/7_SEG/settings.h b/examples/WatchFaces/7_SEG/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/7_SEG/settings.h +++ b/examples/WatchFaces/7_SEG/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file diff --git a/examples/WatchFaces/Basic/settings.h b/examples/WatchFaces/Basic/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/Basic/settings.h +++ b/examples/WatchFaces/Basic/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file diff --git a/examples/WatchFaces/DOS/settings.h b/examples/WatchFaces/DOS/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/DOS/settings.h +++ b/examples/WatchFaces/DOS/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file diff --git a/examples/WatchFaces/MacPaint/settings.h b/examples/WatchFaces/MacPaint/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/MacPaint/settings.h +++ b/examples/WatchFaces/MacPaint/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file diff --git a/examples/WatchFaces/Pokemon/settings.h b/examples/WatchFaces/Pokemon/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/Pokemon/settings.h +++ b/examples/WatchFaces/Pokemon/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file diff --git a/examples/WatchFaces/StarryHorizon/settings.h b/examples/WatchFaces/StarryHorizon/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/StarryHorizon/settings.h +++ b/examples/WatchFaces/StarryHorizon/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file diff --git a/examples/WatchFaces/Tetris/settings.h b/examples/WatchFaces/Tetris/settings.h index 654a219..53d47e3 100644 --- a/examples/WatchFaces/Tetris/settings.h +++ b/examples/WatchFaces/Tetris/settings.h @@ -13,14 +13,14 @@ #define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT watchySettings settings{ - CITY_ID, - OPENWEATHERMAP_APIKEY, - OPENWEATHERMAP_URL, - TEMP_UNIT, - TEMP_LANG, - WEATHER_UPDATE_INTERVAL, - NTP_SERVER, - GMT_OFFSET_SEC + .cityID = CITY_ID, + .weatherAPIKey = OPENWEATHERMAP_APIKEY, + .weatherURL = OPENWEATHERMAP_URL, + .weatherUnit = TEMP_UNIT, + .weatherLang = TEMP_LANG, + .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, + .ntpServer = NTP_SERVER, + .gmtOffset = GMT_OFFSET_SEC, }; #endif \ No newline at end of file From 5f07f2ec63d5b21fb1877f1c069b55509083c1f1 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sun, 16 Oct 2022 00:34:52 +1100 Subject: [PATCH 2/3] Add opion to vibrate every hour (and on reset) Set watchySettings.vibrateOClock to true Signed-off-by: Olivier Mehani --- examples/WatchFaces/7_SEG/settings.h | 1 + src/Watchy.cpp | 11 +++++++++++ src/Watchy.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/examples/WatchFaces/7_SEG/settings.h b/examples/WatchFaces/7_SEG/settings.h index 53d47e3..e4f2669 100644 --- a/examples/WatchFaces/7_SEG/settings.h +++ b/examples/WatchFaces/7_SEG/settings.h @@ -21,6 +21,7 @@ watchySettings settings{ .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL, .ntpServer = NTP_SERVER, .gmtOffset = GMT_OFFSET_SEC, + .vibrateOClock = true, }; #endif \ No newline at end of file diff --git a/src/Watchy.cpp b/src/Watchy.cpp index b95a036..e26479a 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -12,6 +12,7 @@ RTC_DATA_ATTR bool BLE_CONFIGURED; RTC_DATA_ATTR weatherData currentWeather; RTC_DATA_ATTR int weatherIntervalCounter = -1; RTC_DATA_ATTR bool displayFullInit = true; +RTC_DATA_ATTR bool alreadyVibrated = false; void Watchy::init(String datetime) { esp_sleep_wakeup_cause_t wakeup_reason; @@ -30,6 +31,15 @@ void Watchy::init(String datetime) { if (guiState == WATCHFACE_STATE) { RTC.read(currentTime); showWatchFace(true); // partial updates on tick + if (settings.vibrateOClock) { + if (currentTime.Minute == 0 + && !alreadyVibrated) { + vibMotor(75, 4); + alreadyVibrated = true; + } else { + alreadyVibrated = false; + } + } } break; case ESP_SLEEP_WAKEUP_EXT1: // button Press @@ -40,6 +50,7 @@ void Watchy::init(String datetime) { _bmaConfig(); RTC.read(currentTime); showWatchFace(false); // full update on reset + vibMotor(75, 4); break; } deepSleep(); diff --git a/src/Watchy.h b/src/Watchy.h index af6ae29..74140c9 100644 --- a/src/Watchy.h +++ b/src/Watchy.h @@ -35,6 +35,8 @@ typedef struct watchySettings { String ntpServer; int gmtOffset; int dstOffset; + // + bool vibrateOClock; } watchySettings; class Watchy { From cbb4820d85ecab0cbf1f2e7b70ad68feeaea5e4e Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 26 Oct 2022 23:31:36 +1100 Subject: [PATCH 3/3] fixup! Add opion to vibrate every hour (and on reset) --- src/Watchy.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Watchy.cpp b/src/Watchy.cpp index e26479a..a005180 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -12,7 +12,6 @@ RTC_DATA_ATTR bool BLE_CONFIGURED; RTC_DATA_ATTR weatherData currentWeather; RTC_DATA_ATTR int weatherIntervalCounter = -1; RTC_DATA_ATTR bool displayFullInit = true; -RTC_DATA_ATTR bool alreadyVibrated = false; void Watchy::init(String datetime) { esp_sleep_wakeup_cause_t wakeup_reason; @@ -32,12 +31,9 @@ void Watchy::init(String datetime) { RTC.read(currentTime); showWatchFace(true); // partial updates on tick if (settings.vibrateOClock) { - if (currentTime.Minute == 0 - && !alreadyVibrated) { + if (currentTime.Minute == 0) { + // The RTC wakes us up once per minute vibMotor(75, 4); - alreadyVibrated = true; - } else { - alreadyVibrated = false; } } }