watchy lib 1.3 fixes
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
#include "Watchy_Below.h"
|
#include "Watchy_Below.h"
|
||||||
|
|
||||||
WatchyBelow::WatchyBelow()
|
|
||||||
{
|
|
||||||
} //constructor
|
|
||||||
|
|
||||||
void WatchyBelow::drawWatchFace()
|
void WatchyBelow::drawWatchFace()
|
||||||
{
|
{
|
||||||
|
readWorldTime();
|
||||||
|
|
||||||
display.fillScreen(GxEPD_BLACK);
|
display.fillScreen(GxEPD_BLACK);
|
||||||
|
|
||||||
display.drawBitmap(0, 0, background, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_WHITE);
|
display.drawBitmap(0, 0, background, DISPLAY_WIDTH, DISPLAY_HEIGHT, GxEPD_WHITE);
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
#include <Watchy.h>
|
#include <Watchy.h>
|
||||||
#include "below.h"
|
#include "below.h"
|
||||||
|
#include "wta.h"
|
||||||
|
|
||||||
class WatchyBelow : public Watchy
|
class WatchyBelow : public WatchySynced
|
||||||
{
|
{
|
||||||
public:
|
using WatchySynced::WatchySynced;
|
||||||
WatchyBelow();
|
public:
|
||||||
void drawWatchFace();
|
void drawWatchFace();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "watchy_below.h"
|
#include "watchy_below.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
WatchyBelow watchy;
|
WatchyBelow watchy(settings);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef WTA_H
|
||||||
|
#define WTA_H
|
||||||
|
|
||||||
|
#include <Watchy.h>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -13,8 +13,6 @@ const char *pokemon_names[151] = {"BULBASAUR","IVYSAUR","VENUSAUR","CHARMANDER",
|
|||||||
const float MAX_VBAT = 4.20;
|
const float MAX_VBAT = 4.20;
|
||||||
const float MIN_VBAT = 3.80;
|
const float MIN_VBAT = 3.80;
|
||||||
|
|
||||||
WatchyPokemon::WatchyPokemon(){} //constructor
|
|
||||||
|
|
||||||
void WatchyPokemon::drawWatchFace(){
|
void WatchyPokemon::drawWatchFace(){
|
||||||
|
|
||||||
readWorldTime();
|
readWorldTime();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "FreeMonoBold7pt7b.h"
|
#include "FreeMonoBold7pt7b.h"
|
||||||
#include "wta.h"
|
#include "wta.h"
|
||||||
|
|
||||||
|
#define FR
|
||||||
|
|
||||||
#ifdef FR
|
#ifdef FR
|
||||||
#include "pokemon_fr.h"
|
#include "pokemon_fr.h"
|
||||||
#else
|
#else
|
||||||
@@ -14,8 +16,8 @@
|
|||||||
|
|
||||||
class WatchyPokemon : public WatchySynced
|
class WatchyPokemon : public WatchySynced
|
||||||
{
|
{
|
||||||
public:
|
using WatchySynced::WatchySynced;
|
||||||
WatchyPokemon();
|
public:
|
||||||
void drawWatchFace();
|
void drawWatchFace();
|
||||||
double randomDay();
|
double randomDay();
|
||||||
double randomHour();
|
double randomHour();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Watchy_Pokemon.h"
|
#include "Watchy_Pokemon.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
WatchyPokemon watchy;
|
WatchyPokemon watchy(settings);
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
watchy.init();
|
watchy.init();
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -20,14 +20,13 @@ void WatchySynced::readWorldTime()
|
|||||||
JSONVar responseObject = JSON.parse(payload);
|
JSONVar responseObject = JSON.parse(payload);
|
||||||
tmElements_t tm;
|
tmElements_t tm;
|
||||||
String datetime = String((const char *)responseObject["datetime"]);
|
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.Month = datetime.substring(5, 7).toInt();
|
||||||
tm.Day = datetime.substring(8, 10).toInt();
|
tm.Day = datetime.substring(8, 10).toInt();
|
||||||
tm.Hour = datetime.substring(11, 13).toInt();
|
tm.Hour = datetime.substring(11, 13).toInt();
|
||||||
tm.Minute = datetime.substring(14, 16).toInt();
|
tm.Minute = datetime.substring(14, 16).toInt();
|
||||||
tm.Second = 0;
|
tm.Second = 0;
|
||||||
time_t t = makeTime(tm);
|
RTC.set(tm);
|
||||||
RTC.set(t);
|
|
||||||
RTC.read(currentTime);
|
RTC.read(currentTime);
|
||||||
worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL;
|
worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
class WatchySynced : public Watchy
|
class WatchySynced : public Watchy
|
||||||
{
|
{
|
||||||
public:
|
using Watchy::Watchy;
|
||||||
|
public:
|
||||||
void readWorldTime();
|
void readWorldTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,6 @@ const unsigned char *pieces[19] = {
|
|||||||
const float MAX_VBAT = 4.20;
|
const float MAX_VBAT = 4.20;
|
||||||
const float MIN_VBAT = 3.80;
|
const float MIN_VBAT = 3.80;
|
||||||
|
|
||||||
WatchyTetris::WatchyTetris()
|
|
||||||
{
|
|
||||||
} //constructor
|
|
||||||
|
|
||||||
void WatchyTetris::drawWatchFace()
|
void WatchyTetris::drawWatchFace()
|
||||||
{
|
{
|
||||||
readWorldTime();
|
readWorldTime();
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
class WatchyTetris : public WatchySynced
|
class WatchyTetris : public WatchySynced
|
||||||
{
|
{
|
||||||
public:
|
using WatchySynced::WatchySynced;
|
||||||
WatchyTetris();
|
public:
|
||||||
void drawWatchFace();
|
void drawWatchFace();
|
||||||
void drawNumber(int x, int y, int value, int max_digits);
|
void drawNumber(int x, int y, int value, int max_digits);
|
||||||
double random();
|
double random();
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Watchy_Tetris.h"
|
#include "Watchy_Tetris.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
WatchyTetris watchy;
|
WatchyTetris watchy(settings);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,14 +20,13 @@ void WatchySynced::readWorldTime()
|
|||||||
JSONVar responseObject = JSON.parse(payload);
|
JSONVar responseObject = JSON.parse(payload);
|
||||||
tmElements_t tm;
|
tmElements_t tm;
|
||||||
String datetime = String((const char *)responseObject["datetime"]);
|
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.Month = datetime.substring(5, 7).toInt();
|
||||||
tm.Day = datetime.substring(8, 10).toInt();
|
tm.Day = datetime.substring(8, 10).toInt();
|
||||||
tm.Hour = datetime.substring(11, 13).toInt();
|
tm.Hour = datetime.substring(11, 13).toInt();
|
||||||
tm.Minute = datetime.substring(14, 16).toInt();
|
tm.Minute = datetime.substring(14, 16).toInt();
|
||||||
tm.Second = 0;
|
tm.Second = 0;
|
||||||
time_t t = makeTime(tm);
|
RTC.set(tm);
|
||||||
RTC.set(t);
|
|
||||||
RTC.read(currentTime);
|
RTC.read(currentTime);
|
||||||
worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL;
|
worldTimeIntervalCounter = WTA_UPDATE_LONG_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
class WatchySynced : public Watchy
|
class WatchySynced : public Watchy
|
||||||
{
|
{
|
||||||
public:
|
using Watchy::Watchy;
|
||||||
|
public:
|
||||||
void readWorldTime();
|
void readWorldTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user