mirror of https://github.com/sqfmi/Watchy.git
Compare commits
28 Commits
47976fa3de
...
a454e65ba2
Author | SHA1 | Date |
---|---|---|
sqfmi | a454e65ba2 | |
sqfmi | 12915a48e6 | |
SQFMI | 1bfbc55f4a | |
Guðni Þ. Björgvinsson | 9434ffd1fc | |
SQFMI | 0f585268d4 | |
Kyle Potts | 069d18f1cc | |
Kyle Potts | 678614aff9 | |
SQFMI | f8d92f21be | |
sqfmi | 48d06b9661 | |
SQFMI | 35eb14fadd | |
SQFMI | afb2e23dea | |
SQFMI | b794d8ee79 | |
SQFMI | c6483eebe0 | |
Daniel Ansorregui | 76e202739d | |
Daniel Ansorregui | d66f848ba6 | |
sqfmi | ac82f48c45 | |
sqfmi | e34fbac279 | |
sqfmi | 8fb1902cbe | |
SQFMI | ca8e170147 | |
sqfmi | 7a28210b41 | |
Metaln00b | ff48d8a241 | |
sqfmi | 6363caeac2 | |
SQFMI | c6085ad483 | |
SQFMI | bec2c895af | |
SQFMI | 6f918e5d4d | |
sqfmi | 241f568e71 | |
elasticdotventures | f3e7c73eff | |
SQFMI | 3e69aad334 |
11
README.md
11
README.md
|
@ -2,13 +2,18 @@
|
|||
|
||||
![Watchy](https://watchy.sqfmi.com/img/watchy_render.png)
|
||||
|
||||
[**Pre-order Watchy!**](https://www.crowdsupply.com/sqfmi/watchy)
|
||||
Now with injection molded or CNC'd aluminum case
|
||||
[**Buy Watchy!**](https://www.mouser.com/ProductDetail/SQFMI/SQFMI-WATCHY-10?qs=DRkmTr78QARN9VSJRzqRxw%3D%3D)
|
||||
|
||||
[**Watchy Case & Accessories**](https://shop.sqfmi.com)
|
||||
|
||||
|
||||
Visit [**https://watchy.sqfmi.com**](https://watchy.sqfmi.com) for documentation, hardware design files, and more!
|
||||
|
||||
## Setup
|
||||
1. In the Arduino IDE Boards Manager, install support for the ESP32. You can find instructions here: https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md
|
||||
1. In the Arduino IDE Boards Manager, install support for the ESP32. You can find instructions here: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html
|
||||
* Arduino > Preferences > Additional Board Manager URL's
|
||||
* ```https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json```
|
||||
|
||||
2. Install this library (search for **Watchy** in the library manager), and any other depdencies when prompted
|
||||
3. Check out the examples under ```Examples``` -> ```Watchy```
|
||||
4. Compile & Upload with these board settings:
|
||||
|
|
|
@ -52,6 +52,9 @@ void Watchy7SEG::drawDate(){
|
|||
|
||||
String dayOfWeek = dayStr(currentTime.Wday);
|
||||
display.getTextBounds(dayOfWeek, 5, 85, &x1, &y1, &w, &h);
|
||||
if(currentTime.Wday == 4){
|
||||
w = w - 5;
|
||||
}
|
||||
display.setCursor(85 - w, 85);
|
||||
display.println(dayOfWeek);
|
||||
|
||||
|
@ -67,7 +70,7 @@ void Watchy7SEG::drawDate(){
|
|||
}
|
||||
display.println(currentTime.Day);
|
||||
display.setCursor(5, 150);
|
||||
display.println(currentTime.Year + YEAR_OFFSET);// offset from 1970, since year is stored in uint8_t
|
||||
display.println(tmYearToCalendar(currentTime.Year));// offset from 1970, since year is stored in uint8_t
|
||||
}
|
||||
void Watchy7SEG::drawSteps(){
|
||||
// reset step counter at midnight
|
||||
|
@ -132,15 +135,15 @@ void Watchy7SEG::drawWeather(){
|
|||
}else if(weatherConditionCode == 800){//Clear
|
||||
weatherIcon = sunny;
|
||||
}else if(weatherConditionCode >=700){//Atmosphere
|
||||
weatherIcon = cloudy;
|
||||
weatherIcon = atmosphere;
|
||||
}else if(weatherConditionCode >=600){//Snow
|
||||
weatherIcon = snow;
|
||||
}else if(weatherConditionCode >=500){//Rain
|
||||
weatherIcon = rain;
|
||||
}else if(weatherConditionCode >=300){//Drizzle
|
||||
weatherIcon = rain;
|
||||
weatherIcon = drizzle;
|
||||
}else if(weatherConditionCode >=200){//Thunderstorm
|
||||
weatherIcon = rain;
|
||||
weatherIcon = thunderstorm;
|
||||
}else
|
||||
return;
|
||||
display.drawBitmap(145, 158, weatherIcon, WEATHER_ICON_WIDTH, WEATHER_ICON_HEIGHT, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
|
||||
|
|
|
@ -105,6 +105,51 @@ const unsigned char sunny [] PROGMEM = {
|
|||
0xc0, 0x00, 0x00, 0x18, 0x20, 0x10, 0x60, 0x00, 0x00, 0x00, 0x21, 0x08, 0x00, 0x00, 0x00, 0x00,
|
||||
0x41, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
|
||||
};
|
||||
// 'atmosphere', 48x32px
|
||||
const unsigned char atmosphere[] PROGMEM = {
|
||||
0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60,
|
||||
0x00, 0x00, 0x00, 0x08, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x20, 0x00, 0x00, 0x08, 0x00,
|
||||
0x00, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x00, 0x00, 0x07, 0x80, 0x00, 0xc0, 0x00, 0x00,
|
||||
0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x00,
|
||||
0x00, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08,
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x08, 0x04, 0x07, 0xff, 0xf8, 0xf0, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x80,
|
||||
0x00, 0x00, 0x00, 0x60, 0x00, 0x9f, 0x1f, 0xff, 0xfc, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0xff, 0xfc, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
// 'drizzle', 48x32px
|
||||
const unsigned char drizzle[] PROGMEM = {
|
||||
0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60,
|
||||
0x00, 0x00, 0x00, 0x08, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x20, 0x00, 0x00, 0x08, 0x00,
|
||||
0x00, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x00, 0x00, 0x07, 0x80, 0x00, 0xc0, 0x00, 0x00,
|
||||
0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x00,
|
||||
0x00, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08,
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x80,
|
||||
0x00, 0x00, 0x00, 0x60, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x20, 0x08, 0x00, 0x00
|
||||
};
|
||||
// 'thunderstorm', 48x32px
|
||||
const unsigned char thunderstorm[] PROGMEM = {
|
||||
0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60,
|
||||
0x00, 0x00, 0x00, 0x08, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x20, 0x00, 0x00, 0x08, 0x00,
|
||||
0x00, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x00, 0x00, 0x07, 0x80, 0x00, 0xc0, 0x0f, 0x80,
|
||||
0x00, 0xc0, 0x03, 0x00, 0x0f, 0x80, 0x00, 0x20, 0x02, 0x00, 0x1f, 0x00, 0x00, 0x10, 0x04, 0x00,
|
||||
0x1e, 0x00, 0x00, 0x18, 0x04, 0x00, 0x3e, 0x00, 0x00, 0x08, 0x08, 0x00, 0x3c, 0x00, 0x00, 0x08,
|
||||
0x08, 0x00, 0x7c, 0x00, 0x00, 0x08, 0x04, 0x00, 0x78, 0x00, 0x00, 0x08, 0x04, 0x00, 0xf8, 0x00,
|
||||
0x00, 0x08, 0x04, 0x00, 0xff, 0x00, 0x00, 0x10, 0x02, 0x00, 0x1f, 0x00, 0x00, 0x30, 0x01, 0x80,
|
||||
0x1e, 0x00, 0x00, 0x60, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
// 'steps', 19x23px
|
||||
const unsigned char steps [] PROGMEM = {
|
||||
0x00, 0x03, 0xc0, 0x00, 0x07, 0xe0, 0x00, 0x07, 0xe0, 0x00, 0x0f, 0xe0, 0x78, 0x0f, 0xe0, 0xfc,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Watchy",
|
||||
"version": "1.2.7",
|
||||
"version": "1.3.0",
|
||||
"description": "Watchy - An Open Source E-Paper Watch by SQFMI",
|
||||
"authors": [
|
||||
{
|
||||
|
@ -19,6 +19,10 @@
|
|||
{ "name": "Adafruit GFX Library" },
|
||||
{ "name": "Arduino_JSON" },
|
||||
{ "name": "DS3232RTC" },
|
||||
{
|
||||
"name": "Rtc_Pcf8563",
|
||||
"version": "https://github.com/orbitalair/Rtc_Pcf8563.git#master"
|
||||
},
|
||||
{ "name": "GxEPD2" },
|
||||
{
|
||||
"name": "WiFiManager",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name=Watchy
|
||||
version=1.2.7
|
||||
version=1.3.0
|
||||
author=SQFMI
|
||||
maintainer=SQFMI
|
||||
sentence=Watchy - An Open Source E-Paper Watch by SQFMI
|
||||
|
@ -7,4 +7,4 @@ paragraph=This library contains drivers and code samples for Watchy
|
|||
category=Other
|
||||
url=https://watchy.sqfmi.com
|
||||
architectures=esp32
|
||||
depends=Adafruit GFX Library,Arduino_JSON,DS3232RTC,GxEPD2,WiFiManager
|
||||
depends=Adafruit GFX Library,Arduino_JSON,DS3232RTC,Rtc_Pcf8563,GxEPD2,WiFiManager
|
||||
|
|
1893
src/Watchy.cpp
1893
src/Watchy.cpp
File diff suppressed because it is too large
Load Diff
|
@ -5,14 +5,14 @@
|
|||
#include <WiFiManager.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <Arduino_JSON.h>
|
||||
#include <DS3232RTC.h>
|
||||
#include <GxEPD2_BW.h>
|
||||
#include <Wire.h>
|
||||
#include <Fonts/FreeMonoBold9pt7b.h>
|
||||
#include "DSEG7_Classic_Bold_53.h"
|
||||
#include "WatchyRTC.h"
|
||||
#include "BLE.h"
|
||||
#include "bma.h"
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
|
||||
typedef struct weatherData{
|
||||
int8_t temperature;
|
||||
|
@ -21,13 +21,14 @@ typedef struct weatherData{
|
|||
|
||||
class Watchy {
|
||||
public:
|
||||
static DS3232RTC RTC;
|
||||
static WatchyRTC RTC;
|
||||
static GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display;
|
||||
tmElements_t currentTime;
|
||||
public:
|
||||
Watchy();
|
||||
void init(String datetime = "");
|
||||
void deepSleep();
|
||||
static void displayBusyCallback(const void*);
|
||||
float getBatteryVoltage();
|
||||
void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20);
|
||||
|
||||
|
@ -39,6 +40,7 @@ class Watchy {
|
|||
void showAccelerometer();
|
||||
void showUpdateFW();
|
||||
void setTime();
|
||||
void syncNTP();
|
||||
void setupWifi();
|
||||
bool connectWiFi();
|
||||
weatherData getWeatherData();
|
||||
|
@ -48,7 +50,6 @@ class Watchy {
|
|||
virtual void drawWatchFace(); //override this method for different watch faces
|
||||
|
||||
private:
|
||||
void _rtcConfig(String datetime);
|
||||
void _bmaConfig();
|
||||
static void _configModeCallback(WiFiManager *myWiFiManager);
|
||||
static uint16_t _readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len);
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
#include "WatchyRTC.h"
|
||||
|
||||
WatchyRTC::WatchyRTC()
|
||||
: rtc_ds(false) {}
|
||||
|
||||
void WatchyRTC::init(){
|
||||
byte error;
|
||||
Wire.beginTransmission(RTC_DS_ADDR);
|
||||
error = Wire.endTransmission();
|
||||
if(error == 0){
|
||||
rtcType = DS3231;
|
||||
}else{
|
||||
Wire.beginTransmission(RTC_PCF_ADDR);
|
||||
error = Wire.endTransmission();
|
||||
if(error == 0){
|
||||
rtcType = PCF8563;
|
||||
}else{
|
||||
//RTC Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WatchyRTC::config(String datetime){ //String datetime format is YYYY:MM:DD:HH:MM:SS
|
||||
if(rtcType == DS3231){
|
||||
_DSConfig(datetime);
|
||||
}else{
|
||||
_PCFConfig(datetime);
|
||||
}
|
||||
}
|
||||
|
||||
void WatchyRTC::clearAlarm(){
|
||||
if(rtcType == DS3231){
|
||||
rtc_ds.alarm(ALARM_2);
|
||||
}else{
|
||||
int nextAlarmMinute = 0;
|
||||
rtc_pcf.clearAlarm(); //resets the alarm flag in the RTC
|
||||
nextAlarmMinute = rtc_pcf.getMinute();
|
||||
nextAlarmMinute = (nextAlarmMinute == 59) ? 0 : (nextAlarmMinute + 1); //set alarm to trigger 1 minute from now
|
||||
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
|
||||
}
|
||||
}
|
||||
|
||||
void WatchyRTC::read(tmElements_t &tm){
|
||||
if(rtcType == DS3231){
|
||||
rtc_ds.read(tm);
|
||||
}else{
|
||||
tm.Year = y2kYearToTm(rtc_pcf.getYear());
|
||||
tm.Month = rtc_pcf.getMonth();
|
||||
tm.Day = rtc_pcf.getDay();
|
||||
tm.Wday = rtc_pcf.getWeekday() + 1; //TimeLib & DS3231 has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range
|
||||
tm.Hour = rtc_pcf.getHour();
|
||||
tm.Minute = rtc_pcf.getMinute();
|
||||
tm.Second = rtc_pcf.getSecond();
|
||||
}
|
||||
}
|
||||
|
||||
void WatchyRTC::set(tmElements_t tm){
|
||||
if(rtcType == DS3231){
|
||||
time_t t = makeTime(tm);
|
||||
rtc_ds.set(t);
|
||||
}else{
|
||||
time_t t = makeTime(tm); //make and break to calculate tm.Wday
|
||||
breakTime(t, tm);
|
||||
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||
rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year)); //TimeLib & DS3231 has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range
|
||||
//hr, min, sec
|
||||
rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
|
||||
clearAlarm();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t WatchyRTC::temperature(){
|
||||
if(rtcType == DS3231){
|
||||
return rtc_ds.temperature();
|
||||
}else{
|
||||
return 255; //error
|
||||
}
|
||||
}
|
||||
|
||||
void WatchyRTC::_DSConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:MM:SS
|
||||
if(datetime != ""){
|
||||
tmElements_t tm;
|
||||
tm.Year = CalendarYrToTm(_getValue(datetime, ':', 0).toInt()); //YYYY - 1970
|
||||
tm.Month = _getValue(datetime, ':', 1).toInt();
|
||||
tm.Day = _getValue(datetime, ':', 2).toInt();
|
||||
tm.Hour = _getValue(datetime, ':', 3).toInt();
|
||||
tm.Minute = _getValue(datetime, ':', 4).toInt();
|
||||
tm.Second = _getValue(datetime, ':', 5).toInt();
|
||||
time_t t = makeTime(tm);
|
||||
rtc_ds.set(t);
|
||||
}
|
||||
//https://github.com/JChristensen/DS3232RTC
|
||||
rtc_ds.squareWave(SQWAVE_NONE); //disable square wave output
|
||||
rtc_ds.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0); //alarm wakes up Watchy every minute
|
||||
rtc_ds.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
||||
}
|
||||
|
||||
void WatchyRTC::_PCFConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:MM:SS
|
||||
if(datetime != ""){
|
||||
tmElements_t tm;
|
||||
tm.Year = CalendarYrToTm(_getValue(datetime, ':', 0).toInt()); //YYYY - 1970
|
||||
tm.Month = _getValue(datetime, ':', 1).toInt();
|
||||
tm.Day = _getValue(datetime, ':', 2).toInt();
|
||||
tm.Hour = _getValue(datetime, ':', 3).toInt();
|
||||
tm.Minute = _getValue(datetime, ':', 4).toInt();
|
||||
tm.Second = _getValue(datetime, ':', 5).toInt();
|
||||
time_t t = makeTime(tm); //make and break to calculate tm.Wday
|
||||
breakTime(t, tm);
|
||||
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
|
||||
rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year)); //TimeLib & DS3231 has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range
|
||||
//hr, min, sec
|
||||
rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
|
||||
}
|
||||
//on POR event, PCF8563 sets month to 0, which will give an error since months are 1-12
|
||||
clearAlarm();
|
||||
}
|
||||
|
||||
bool WatchyRTC::syncNtpTime(){ //NTP sync - call after connecting to WiFi and remember to turn it back off
|
||||
configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER);
|
||||
struct tm timeinfo;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
return false; //NTP sync failed
|
||||
}
|
||||
/****************************************************
|
||||
struct tm
|
||||
{
|
||||
int tm_sec; // Seconds [0,60].
|
||||
int tm_min; // Minutes [0,59].
|
||||
int tm_hour; // Hour [0,23].
|
||||
int tm_mday; // Day of month [1,31].
|
||||
int tm_mon; // Month of year [0,11].
|
||||
int tm_year; // Years since 1900.
|
||||
int tm_wday; // Day of week [0,6] (Sunday =0).
|
||||
int tm_yday; // Day of year [0,365].
|
||||
int tm_isdst; // Daylight Savings flag.
|
||||
}
|
||||
****************************************************/
|
||||
tmElements_t tm;
|
||||
tm.Year = CalendarYrToTm(timeinfo.tm_year + 1900);
|
||||
tm.Month = timeinfo.tm_mon + 1; //tm.Month 1 - 12
|
||||
tm.Day = timeinfo.tm_mday;
|
||||
tm.Hour = timeinfo.tm_hour;
|
||||
tm.Minute = timeinfo.tm_min;
|
||||
tm.Second = timeinfo.tm_sec;
|
||||
set(tm);
|
||||
return true;
|
||||
}
|
||||
|
||||
String WatchyRTC::_getValue(String data, char separator, int index)
|
||||
{
|
||||
int found = 0;
|
||||
int strIndex[] = {0, -1};
|
||||
int maxIndex = data.length()-1;
|
||||
|
||||
for(int i=0; i<=maxIndex && found<=index; i++){
|
||||
if(data.charAt(i)==separator || i==maxIndex){
|
||||
found++;
|
||||
strIndex[0] = strIndex[1]+1;
|
||||
strIndex[1] = (i == maxIndex) ? i+1 : i;
|
||||
}
|
||||
}
|
||||
|
||||
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef WATCHY_RTC_H
|
||||
#define WATCHY_RTC_H
|
||||
|
||||
#include <DS3232RTC.h>
|
||||
#include <Rtc_Pcf8563.h>
|
||||
#include "config.h"
|
||||
#include "time.h"
|
||||
|
||||
#define DS3231 0
|
||||
#define PCF8563 1
|
||||
#define RTC_DS_ADDR 0x68
|
||||
#define RTC_PCF_ADDR 0x51
|
||||
#define YEAR_OFFSET_DS 1970
|
||||
#define YEAR_OFFSET_PCF 2000
|
||||
|
||||
class WatchyRTC {
|
||||
public:
|
||||
DS3232RTC rtc_ds;
|
||||
Rtc_Pcf8563 rtc_pcf;
|
||||
uint8_t rtcType;
|
||||
public:
|
||||
WatchyRTC();
|
||||
void init();
|
||||
void config(String datetime); //String datetime format is YYYY:MM:DD:HH:MM:SS
|
||||
void clearAlarm();
|
||||
void read(tmElements_t &tm);
|
||||
void set(tmElements_t tm);
|
||||
bool syncNtpTime();
|
||||
uint8_t temperature();
|
||||
private:
|
||||
void _DSConfig(String datetime);
|
||||
void _PCFConfig(String datetime);
|
||||
int _getDayOfWeek(int d, int m, int y);
|
||||
String _getValue(String data, char separator, int index);
|
||||
};
|
||||
|
||||
#endif
|
13
src/config.h
13
src/config.h
|
@ -4,7 +4,8 @@
|
|||
//pins
|
||||
#define SDA 21
|
||||
#define SCL 22
|
||||
#define ADC_PIN 33
|
||||
#define V10_ADC_PIN 33 //OG v1.0 Watchy
|
||||
#define V15_ADC_PIN 35 //v1.5 Watchy with PCF8563 RTC
|
||||
#define RTC_PIN GPIO_NUM_27
|
||||
#define CS 5
|
||||
#define DC 10
|
||||
|
@ -39,16 +40,18 @@
|
|||
#define MAIN_MENU_STATE 0
|
||||
#define APP_STATE 1
|
||||
#define FW_UPDATE_STATE 2
|
||||
#define MENU_HEIGHT 30
|
||||
#define MENU_LENGTH 6
|
||||
#define MENU_HEIGHT 25
|
||||
#define MENU_LENGTH 7
|
||||
//set time
|
||||
#define SET_HOUR 0
|
||||
#define SET_MINUTE 1
|
||||
#define SET_YEAR 2
|
||||
#define SET_MONTH 3
|
||||
#define SET_DAY 4
|
||||
#define YEAR_OFFSET 1970
|
||||
#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"
|
||||
|
@ -58,4 +61,4 @@
|
|||
#define HARDWARE_VERSION_MAJOR 1
|
||||
#define HARDWARE_VERSION_MINOR 0
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue