mirror of https://github.com/sqfmi/Watchy.git
Update Watchy_Basic.ino
parent
8b303796c2
commit
2ddb8a1c6c
|
@ -3,6 +3,7 @@
|
|||
* 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 <GxEPD.h>
|
||||
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
|
||||
|
@ -18,21 +19,26 @@ GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16
|
|||
|
||||
void setup()
|
||||
{
|
||||
detect_wakeup_reason();
|
||||
delay(100);
|
||||
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 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 updateTime(bool fullRefresh)
|
||||
void updateTime(bool reset)
|
||||
{
|
||||
RTC.begin();
|
||||
if(RTC.oscStopped(false)){ //check if RTC has been stopped
|
||||
if(reset){
|
||||
RTC.squareWave(SQWAVE_NONE); //disable square wave output
|
||||
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.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||
|
@ -55,7 +61,7 @@ void updateTime(bool fullRefresh)
|
|||
}
|
||||
display.print(currentTime.Minute);
|
||||
|
||||
if(fullRefresh){
|
||||
if(reset){
|
||||
display.update();
|
||||
}else{
|
||||
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true);
|
||||
|
@ -85,15 +91,3 @@ time_t compileTime()
|
|||
time_t t = makeTime(tm);
|
||||
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