user definable settings

pull/135/head
sqfmi 2021-12-30 22:47:38 -05:00
parent 7ffb458385
commit 9f0ce88057
26 changed files with 257 additions and 41 deletions

View File

@ -1,6 +1,7 @@
#include "Watchy_7_SEG.h"
#include "settings.h"
Watchy7SEG watchy;
Watchy7SEG watchy(settings);
void setup(){
watchy.init();

View File

@ -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

View File

@ -9,8 +9,8 @@
#include "icons.h"
class Watchy7SEG : public Watchy{
using Watchy::Watchy;
public:
Watchy7SEG();
void drawWatchFace();
void drawTime();
void drawDate();

View File

@ -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

View File

@ -1,6 +1,7 @@
#include <Watchy.h>
#include "settings.h"
Watchy watchy;
Watchy watchy(settings);
void setup(){
watchy.init();

View File

@ -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

View File

@ -1,6 +1,7 @@
#include "Watchy_DOS.h"
#include "settings.h"
WatchyDOS watchy;
WatchyDOS watchy(settings);
void setup(){
watchy.init();

View File

@ -1,7 +1,5 @@
#include "Watchy_DOS.h"
WatchyDOS::WatchyDOS(){} //constructor
void WatchyDOS::drawWatchFace(){
char time[6];
time[0] = '0' + ((currentTime.Hour/10)%10);

View File

@ -5,8 +5,8 @@
#include "Px437_IBM_BIOS5pt7b.h"
class WatchyDOS : public Watchy{
using Watchy::Watchy;
public:
WatchyDOS();
void drawWatchFace();
};

View File

@ -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

View File

@ -1,6 +1,7 @@
#include "Watchy_MacPaint.h"
#include "settings.h"
WatchyMacPaint watchy;
WatchyMacPaint watchy(settings);
void setup(){
watchy.init();

View File

@ -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);

View File

@ -5,8 +5,8 @@
#include "macpaint.h"
class WatchyMacPaint : public Watchy{
using Watchy::Watchy;
public:
WatchyMacPaint();
void drawWatchFace();
};

View File

@ -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

View File

@ -1,6 +1,7 @@
#include "Watchy_Pokemon.h"
#include "settings.h"
WatchyPokemon watchy;
WatchyPokemon watchy(settings);
void setup(){
watchy.init();

View File

@ -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);

View File

@ -5,8 +5,8 @@
#include "pokemon.h"
class WatchyPokemon : public Watchy{
using Watchy::Watchy;
public:
WatchyPokemon();
void drawWatchFace();
};

View File

@ -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

View File

@ -6,6 +6,7 @@
#include <Fonts/FreeSansBold9pt7b.h> //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

View File

@ -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

View File

@ -1,6 +1,7 @@
#include "Watchy_Tetris.h"
#include "settings.h"
WatchyTetris watchy;
WatchyTetris watchy(settings);
void setup(){
watchy.init();

View File

@ -5,6 +5,7 @@
#include "tetris.h"
class WatchyTetris : public Watchy{
using Watchy::Watchy;
public:
WatchyTetris();
void drawWatchFace();

View File

@ -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

View File

@ -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

View File

@ -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<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> 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);

View File

@ -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"