Compare commits

...

2 Commits

2 changed files with 44 additions and 15 deletions

View File

@ -1,9 +1,13 @@
#include <Watchy.h> //include the Watchy library
#include "settings.h" // stupid static constants
#include "DIN_1451_Engschrift_Regular64pt7b.h"
#include "DIN_1451_Engschrift_Regular12pt7b.h"
#include "heavitas12pt7b.h"
// RTC_DATA_ATTR weatherData currentWeather;
class WatchFace : public Watchy { //inherit and extend Watchy class
using Watchy::Watchy;
public:
//! Change these if you want light background, dark text
uint16_t bg = GxEPD_BLACK;
@ -32,7 +36,7 @@ class WatchFace : public Watchy { //inherit and extend Watchy class
display.setFont(&DIN_1451_Engschrift_Regular12pt7b);
display.setTextColor(fg);
drawSteps( 8, 20 );
drawDate( 8, 130 );
drawDate( 8, 140 );
display.setFont(&DIN_1451_Engschrift_Regular12pt7b);
display.setTextColor(fg);
@ -40,18 +44,19 @@ class WatchFace : public Watchy { //inherit and extend Watchy class
lasty = 120;
// weather things
weatherData currentWeather = getWeatherData();
int8_t temperature = currentWeather.temperature;
int16_t weatherConditionCode = currentWeather.weatherConditionCode;
textstring = currentWeather.weatherDescription;
weatherData currentWeather = getWeatherData(settings.cityID, settings.weatherUnit,
settings.weatherLang, settings.weatherURL,
settings.weatherAPIKey, settings.weatherUpdateInterval);
textstring = "";
textstring += currentWeather.weatherDescription;
display.getTextBounds(textstring, 0, 0, &x1, &y1, &w, &h);
display.setCursor(16, lasty);
display.print(textstring);
lasty += -20;
// draw temperature
textstring = temperature;
if( weatherCelsius == true ) {
textstring = currentWeather.temperature;
if( currentWeather.isMetric ) {
textstring += "~ C"; // ~ will be rendered as º
} else {
textstring += "~ F"; // ~ will be rendered as º
@ -152,7 +157,7 @@ class WatchFace : public Watchy { //inherit and extend Watchy class
}
#define BOXX (60)
#define BOXY (60)
#define BOXY (50)
void drawDate( uint8_t x, uint8_t y ) {
int16_t x1;
@ -195,15 +200,11 @@ class WatchFace : public Watchy { //inherit and extend Watchy class
}
};
WatchFace m; //instantiate your watchface
WatchFace w(settings); //instantiate your watchface
void setup() {
// Change this to use your own API key!
// get an API key at: https://openweathermap.org/api
String APIkey = String ("ca4849c5f0c3949bda419307e34a669e");
// 4751935 == Chantilly, VA, USA
m.setupWeather( 4751935, false, 30, String("en"), APIkey );
m.init(); //call init in setup
// Weather settings are in settings.h now
w.init(); //call init in setup
}
void loop() {

28
settings.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef SETTINGS_H
#define SETTINGS_H
//Weather Settings
#define CITY_ID "4751935" // Chantilly, VA https://openweathermap.org/current#cityid
#define OPENWEATHERMAP_APIKEY "ca4849c5f0c3949bda419307e34a669e" //use your own API key :)
#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api
#define TEMP_UNIT "imperial" //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 "0.us.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