mirror of https://github.com/sqfmi/Watchy.git
Update Watchy_Basic.ino
parent
8b303796c2
commit
2ddb8a1c6c
|
@ -2,7 +2,8 @@
|
||||||
* Watchy - Basic Example
|
* Watchy - Basic Example
|
||||||
* Sets the RTC time if not set, goes to sleep and wakes up every minute to update the time on the display
|
* Sets the RTC time if not set, goes to sleep and wakes up every minute to update the time on the display
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
#include <DS3232RTC.h>
|
#include <DS3232RTC.h>
|
||||||
#include <GxEPD.h>
|
#include <GxEPD.h>
|
||||||
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
||||||
|
@ -18,50 +19,55 @@ GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
detect_wakeup_reason();
|
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||||
delay(100);
|
wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||||
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
|
switch(wakeup_reason)
|
||||||
esp_deep_sleep_start();
|
{
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT0: updateTime(false); break; //RTC Alarm Interrupt
|
||||||
|
default: updateTime(true); //Hard Reset
|
||||||
|
}
|
||||||
|
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
|
||||||
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){}
|
void loop(){}
|
||||||
|
|
||||||
void updateTime(bool fullRefresh)
|
void updateTime(bool reset)
|
||||||
{
|
{
|
||||||
RTC.begin();
|
RTC.begin();
|
||||||
if(RTC.oscStopped(false)){ //check if RTC has been stopped
|
if(reset){
|
||||||
RTC.squareWave(SQWAVE_NONE); //disable square wave output
|
RTC.squareWave(SQWAVE_NONE); //disable square wave output
|
||||||
RTC.set(compileTime()); //set RTC time to compile time
|
RTC.set(compileTime()); //set RTC time to compile time
|
||||||
RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 1); //set alarm to every minute
|
RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0);
|
||||||
RTC.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
RTC.alarmInterrupt(ALARM_2, true); //enable alarm interrupt
|
||||||
}
|
}
|
||||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||||
tmElements_t currentTime;
|
tmElements_t currentTime;
|
||||||
RTC.read(currentTime);
|
RTC.read(currentTime);
|
||||||
|
|
||||||
display.init();
|
display.init();
|
||||||
display.fillScreen(GxEPD_BLACK);
|
display.fillScreen(GxEPD_BLACK);
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
display.setFont(&DSEG7_Classic_Bold_48);
|
display.setFont(&DSEG7_Classic_Bold_48);
|
||||||
display.setCursor(15, 120);
|
display.setCursor(15, 120);
|
||||||
|
|
||||||
if(currentTime.Hour < 10){
|
if(currentTime.Hour < 10){
|
||||||
display.print('0');
|
display.print('0');
|
||||||
}
|
}
|
||||||
display.print(currentTime.Hour);
|
display.print(currentTime.Hour);
|
||||||
display.print(':');
|
display.print(':');
|
||||||
if(currentTime.Minute < 10){
|
if(currentTime.Minute < 10){
|
||||||
display.print('0');
|
display.print('0');
|
||||||
}
|
}
|
||||||
display.print(currentTime.Minute);
|
display.print(currentTime.Minute);
|
||||||
|
|
||||||
if(fullRefresh){
|
if(reset){
|
||||||
display.update();
|
display.update();
|
||||||
}else{
|
}else{
|
||||||
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true);
|
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
display.deepSleep();
|
display.deepSleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t compileTime()
|
time_t compileTime()
|
||||||
|
@ -85,15 +91,3 @@ time_t compileTime()
|
||||||
time_t t = makeTime(tm);
|
time_t t = makeTime(tm);
|
||||||
return t + FUDGE; //add fudge factor to allow for compile time
|
return t + FUDGE; //add fudge factor to allow for compile time
|
||||||
}
|
}
|
||||||
|
|
||||||
void detect_wakeup_reason(){
|
|
||||||
esp_sleep_wakeup_cause_t wakeup_reason;
|
|
||||||
|
|
||||||
wakeup_reason = esp_sleep_get_wakeup_cause();
|
|
||||||
|
|
||||||
switch(wakeup_reason)
|
|
||||||
{
|
|
||||||
case ESP_SLEEP_WAKEUP_EXT0: updateTime(false); break; //RTC Alarm
|
|
||||||
default: updateTime(true); //Reset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue