Version 1.3.

This commit is contained in:
GuruSR 2021-11-09 23:25:06 -05:00 committed by GitHub
parent ab29805b27
commit 57cef26340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 221 additions and 115 deletions

View File

@ -6,8 +6,8 @@
//display //display
#define SOFTWARE_VERSION_MAJOR 1 #define SOFTWARE_VERSION_MAJOR 1
#define SOFTWARE_VERSION_MINOR 2 #define SOFTWARE_VERSION_MINOR 3
#define SOFTWARE_VERSION_PATCH 1 #define SOFTWARE_VERSION_PATCH 0
#define HARDWARE_VERSION_MAJOR 1 #define HARDWARE_VERSION_MAJOR 1
#define HARDWARE_VERSION_MINOR 0 #define HARDWARE_VERSION_MINOR 0
@ -121,4 +121,8 @@
#define ACC_INT_MASK GPIO_SEL_14 #define ACC_INT_MASK GPIO_SEL_14
#define BTN_PIN_MASK MENU_BTN_MASK|BACK_BTN_MASK|UP_BTN_MASK|DOWN_BTN_MASK #define BTN_PIN_MASK MENU_BTN_MASK|BACK_BTN_MASK|UP_BTN_MASK|DOWN_BTN_MASK
//SetCPU defines.
#define CPUMAX 65280
#define CPUDEF 65281
#define CPUMID 65282
#endif #endif

View File

@ -1,3 +1,4 @@
#include "Watchy_GSR.h" #include "Watchy_GSR.h"
WatchyGSR watchy; WatchyGSR watchy;

View File

@ -27,6 +27,11 @@ RTC_DATA_ATTR struct GSRWireless {
bool Tried; // Tried to connect at least once. bool Tried; // Tried to connect at least once.
} GSRWiFi; } GSRWiFi;
RTC_DATA_ATTR struct CPUWork {
uint32_t Freq;
bool Locked;
} CPUSet;
RTC_DATA_ATTR struct Stepping { RTC_DATA_ATTR struct Stepping {
uint8_t Hour; uint8_t Hour;
uint8_t Minutes; uint8_t Minutes;
@ -55,7 +60,6 @@ RTC_DATA_ATTR struct Optional {
RTC_DATA_ATTR int GuiMode; RTC_DATA_ATTR int GuiMode;
RTC_DATA_ATTR bool ScreenOn; // Screen needs to be on. RTC_DATA_ATTR bool ScreenOn; // Screen needs to be on.
RTC_DATA_ATTR bool Darkness; // Whether or not the screen is darkened.
RTC_DATA_ATTR bool VibeMode; // Vibe Motor is On=True/Off=False, used for the Haptic and Alarms. RTC_DATA_ATTR bool VibeMode; // Vibe Motor is On=True/Off=False, used for the Haptic and Alarms.
RTC_DATA_ATTR String WatchyStatus; // Used for the indicator in the bottom left, so when it changes, it asks for a screen refresh, if not, it doesn't. RTC_DATA_ATTR String WatchyStatus; // Used for the indicator in the bottom left, so when it changes, it asks for a screen refresh, if not, it doesn't.
@ -73,6 +77,8 @@ RTC_DATA_ATTR struct TimeData {
bool NewMinute; // Set to True when New Minute happens. bool NewMinute; // Set to True when New Minute happens.
time_t TravelTest; // For Travel Testing. time_t TravelTest; // For Travel Testing.
int32_t Drifting; // The amount to add to UTC_RAW after reading from the RTC. int32_t Drifting; // The amount to add to UTC_RAW after reading from the RTC.
int64_t WatchyRTC; // Counts Microseconds from boot.
bool DeadRTC; // Set when Drift fails to get a good count less than 30 seconds.
} WatchTime; } WatchTime;
RTC_DATA_ATTR struct Countdown { RTC_DATA_ATTR struct Countdown {
@ -123,7 +129,12 @@ RTC_DATA_ATTR struct NTPUse {
bool NTPDone; // Sets it to Done when an NTP has happened in the past. bool NTPDone; // Sets it to Done when an NTP has happened in the past.
} NTPData; } NTPData;
struct dispUpdate { RTC_DATA_ATTR struct GoneDark {
bool Went;
unsigned long Last;
} Darkness; // Whether or not the screen is darkened.
RTC_DATA_ATTR struct dispUpdate {
bool Time; bool Time;
bool Day; bool Day;
bool Date; bool Date;
@ -134,14 +145,8 @@ struct dispUpdate {
bool Charge; bool Charge;
bool Full; bool Full;
bool Drawn; bool Drawn;
bool Dark;
} Updates; } Updates;
struct SpeedUp {
bool On;
time_t Last;
} Turbo;
DS3232RTC WatchyGSR::RTC(false); DS3232RTC WatchyGSR::RTC(false);
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> WatchyGSR::display(GxEPD2_154_D67(CS, DC, RESET, BUSY)); GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> WatchyGSR::display(GxEPD2_154_D67(CS, DC, RESET, BUSY));
@ -166,12 +171,15 @@ bool WatchyAPOn; // States Watchy's AP is on for connection. Puts in Active M
bool ActiveMode; // Moved so it can be checked. bool ActiveMode; // Moved so it can be checked.
bool Sensitive; // Loop code is sensitive, like OTAUpdate, TimeTest bool Sensitive; // Loop code is sensitive, like OTAUpdate, TimeTest
bool OTAUpdate; // Internet based OTA Update. bool OTAUpdate; // Internet based OTA Update.
bool AlarmReset; // Moved out here to work with Active Mode.
bool OTAEnd; // Means somewhere, it wants this to end, so end it. bool OTAEnd; // Means somewhere, it wants this to end, so end it.
int OTATry; // Tries to connect to WiFi. int OTATry; // Tries to connect to WiFi.
bool DoHaptic; // Want it to happen after screen update. bool DoHaptic; // Want it to happen after screen update.
bool UpdateDisp; // Display needs to be updated. bool UpdateDisp; // Display needs to be updated.
bool IDidIt; // Tells if the Drifting was done this minute. bool IDidIt; // Tells if the Drifting was done this minute.
unsigned long LastButton, LastUse, OTAFail; bool AlarmsOn; // Moved for CPU.
time_t TurboTime; // Moved here for less work.
unsigned long LastButton, OTAFail;
WatchyGSR::WatchyGSR(){} //constructor WatchyGSR::WatchyGSR(){} //constructor
@ -196,15 +204,13 @@ void WatchyGSR::setupDefaults(){
void WatchyGSR::init(){ void WatchyGSR::init(){
uint64_t wakeupBit; uint64_t wakeupBit;
int AlarmIndex, Pushed; // Alarm being played. int AlarmIndex, Pushed; // Alarm being played.
bool AlarmsOn, WaitForNext, Pulse, DoOnce, B; bool WaitForNext, Pulse, DoOnce, B;
unsigned long Since, AlarmReset, APLoop; unsigned long Since, APLoop;
String S; String S;
esp_sleep_wakeup_cause_t wakeup_reason; esp_sleep_wakeup_cause_t wakeup_reason;
Wire.begin(SDA, SCL); //init i2c Wire.begin(SDA, SCL); //init i2c
NVS.begin(); NVS.begin();
display.epd2.setDarkBorder(Options.Border);
display.init(0, false); //_initial_refresh to false to prevent full update on init (moved here so it isn't done repeatedly during loops).
pinMode(MENU_BTN_PIN, INPUT); // Prep these for the loop below. pinMode(MENU_BTN_PIN, INPUT); // Prep these for the loop below.
pinMode(BACK_BTN_PIN, INPUT); pinMode(BACK_BTN_PIN, INPUT);
@ -217,7 +223,8 @@ void WatchyGSR::init(){
IDidIt = false; IDidIt = false;
Updates.Drawn = false; Updates.Drawn = false;
LastButton = 0; LastButton = 0;
LastUse = 0; Darkness.Last = 0;
TurboTime = 0;
switch (wakeup_reason) switch (wakeup_reason)
{ {
@ -226,28 +233,34 @@ void WatchyGSR::init(){
IDidIt = true; IDidIt = true;
UpdateUTC(); UpdateUTC();
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
WatchTime.EPSMS = (millis() + (60000 - (1000 * WatchTime.UTC.Second))); WatchTime.EPSMS = (millis() + (1000 * (60 - WatchTime.UTC.Second)));
WatchTime.NewMinute = true;
RefreshCPU(CPUMAX);
UpdateClock(); UpdateClock();
detectBattery(); detectBattery();
UpdateDisp=Showing(); UpdateDisp=Showing();
break; break;
case ESP_SLEEP_WAKEUP_EXT1: //button Press case ESP_SLEEP_WAKEUP_EXT1: //button Press
RefreshCPU(CPUMAX);
UpdateUTC(); UpdateUTC();
WatchTime.EPSMS = (millis() + (60000 - (1000 * WatchTime.UTC.Second))); WatchTime.EPSMS = (millis() + (1000 * (60 - WatchTime.UTC.Second)));
UpdateDisp = !Showing(); UpdateDisp = !Showing();
Button = getButtonMaskToID(wakeupBit); Button = getButtonMaskToID(wakeupBit);
break; break;
default: //reset default: //reset
RefreshCPU(CPUMAX);
setupDefaults(); setupDefaults();
initZeros(); initZeros();
_rtcConfig(); _rtcConfig();
_bmaConfig(); _bmaConfig();
UpdateUTC();
B = NVS.getString("GSR-TZ",S); B = NVS.getString("GSR-TZ",S);
if (S.length() > 0) strcpy(WatchTime.POSIX,S.c_str()); if (S.length() > 0) strcpy(WatchTime.POSIX,S.c_str());
UpdateUTC();
WatchTime.EPSMS = (millis() + (60000 - (1000 * WatchTime.UTC.Second)));
UpdateClock();
RetrieveSettings(); RetrieveSettings();
WatchTime.WatchyRTC = esp_timer_get_time() + ((60 - WatchTime.UTC.Second) * 1000000);
WatchTime.EPSMS = (millis() + (1000 * (60 - WatchTime.UTC.Second)));
UpdateUTC();
UpdateClock();
AlarmIndex=0; AlarmIndex=0;
AlarmsOn=false; AlarmsOn=false;
WaitForNext=false; WaitForNext=false;
@ -260,6 +273,10 @@ void WatchyGSR::init(){
attachInterrupt(digitalPinToInterrupt(DOWN_BTN_PIN), std::bind(&WatchyGSR::handleInterrupt,this), HIGH); attachInterrupt(digitalPinToInterrupt(DOWN_BTN_PIN), std::bind(&WatchyGSR::handleInterrupt,this), HIGH);
break; break;
} }
display.init(0, false); //_initial_refresh to false to prevent full update on init (moved here so it isn't done repeatedly during loops).
display.epd2.setDarkBorder(Options.Border);
// Sometimes BMA crashes - simply try to reinitialize bma... // Sometimes BMA crashes - simply try to reinitialize bma...
if (sensor.getErrorCode() != 0) { if (sensor.getErrorCode() != 0) {
@ -273,24 +290,21 @@ void WatchyGSR::init(){
CalculateTones(); monitorSteps(); CalculateTones(); monitorSteps();
AlarmsOn =(Alarms_Times[0] > 0 || Alarms_Times[1] > 0 || Alarms_Times[2] > 0 || Alarms_Times[3] > 0 || TimerDown.ToneLeft > 0); AlarmsOn =(Alarms_Times[0] > 0 || Alarms_Times[1] > 0 || Alarms_Times[2] > 0 || Alarms_Times[3] > 0 || TimerDown.ToneLeft > 0);
ActiveMode = (InTurbo() || DarkWait() || NTPData.State > 0 || AlarmsOn || WatchyAPOn || OTAUpdate || NTPData.TimeTest); ActiveMode = (InTurbo() || DarkWait() || NTPData.State > 0 || AlarmsOn || WatchyAPOn || OTAUpdate || NTPData.TimeTest || WatchTime.DeadRTC);
Sensitive = ((OTAUpdate && Menu.SubItem == 3) || (NTPData.TimeTest && Menu.SubItem == 2)); Sensitive = ((OTAUpdate && Menu.SubItem == 3) || (NTPData.TimeTest && Menu.SubItem == 2));
RefreshCPU();
while(DoOnce || Button > 0){ while(DoOnce || Button > 0){
DoOnce = false; // Do this whole thing once, catch late button presses at the END of the loop just before Deep Sleep. DoOnce = false; // Do this whole thing once, catch late button presses at the END of the loop just before Deep Sleep.
ManageTime(); // Handle Time method. ManageTime(); // Handle Time method.
AlarmReset = millis();
if (UpdateDisp) showWatchFace(); //partial updates on tick if (UpdateDisp) showWatchFace(); //partial updates on tick
Since=millis(); if (ActiveMode == true){
AlarmReset = Since;
OTATimer = Since;
OTAFail = Since;
if (ActiveMode){
while (ActiveMode == true) { // Here, we hijack the init and LOOP until the NTP is done, watching for the proper time when we *SHOULD* update the screen to keep time with everything. while (ActiveMode == true) { // Here, we hijack the init and LOOP until the NTP is done, watching for the proper time when we *SHOULD* update the screen to keep time with everything.
Since=millis();
ManageTime(); // Handle Time method. ManageTime(); // Handle Time method.
processWiFiRequest(); // Process any WiFi requests.
processWiFiRequest(); // Process any WiFi requests.
if (!Sensitive){ if (!Sensitive){
if (NTPData.State > 0 && !WatchyAPOn && !OTAUpdate){ if (NTPData.State > 0 && !WatchyAPOn && !OTAUpdate){
if (NTPData.Pause == 0) ProcessNTP(); else NTPData.Pause--; if (NTPData.Pause == 0) ProcessNTP(); else NTPData.Pause--;
@ -341,7 +355,7 @@ void WatchyGSR::init(){
Pulse = (((TimerDown.Tone / 2) & 1) != 0); Pulse = (((TimerDown.Tone / 2) & 1) != 0);
if (!Pulse && TimerDown.Tone > 0) TimerDown.Tone--; if (!Pulse && TimerDown.Tone > 0) TimerDown.Tone--;
VibeTo(Pulse); // Turns Vibe on or off depending on bit state. VibeTo(Pulse); // Turns Vibe on or off depending on bit state.
LastUse=millis(); LastButton = LastUse; Darkness.Last=millis();
} }
}else WaitForNext=true; }else WaitForNext=true;
}else if (Alarms_Times[AlarmIndex] > 0){ }else if (Alarms_Times[AlarmIndex] > 0){
@ -349,14 +363,14 @@ void WatchyGSR::init(){
Alarms_Playing[AlarmIndex]--; Alarms_Playing[AlarmIndex]--;
if (Menu.SubItem > 0 && Menu.Item - MENU_ALARM1 == AlarmIndex){ if (Menu.SubItem > 0 && Menu.Item - MENU_ALARM1 == AlarmIndex){
VibeTo(false); VibeTo(false);
LastUse=millis(); LastButton = LastUse; Darkness.Last=millis();
DoHaptic = false; DoHaptic = false;
Alarms_Playing[AlarmIndex]=0; Alarms_Playing[AlarmIndex]=0;
Alarms_Times[AlarmIndex]=0; Alarms_Times[AlarmIndex]=0;
}else{ }else{
Pulse = ((AlarmVBs[AlarmIndex] & Bits[Alarms_Playing[AlarmIndex] / 3]) != 0); Pulse = ((AlarmVBs[AlarmIndex] & Bits[Alarms_Playing[AlarmIndex] / 3]) != 0);
VibeTo(Pulse); // Turns Vibe on or off depending on bit state. VibeTo(Pulse); // Turns Vibe on or off depending on bit state.
LastUse=millis(); LastButton = LastUse; Darkness.Last=millis();
DoHaptic = false; DoHaptic = false;
} }
if (Alarms_Playing[AlarmIndex] == 0 && Alarms_Times[AlarmIndex] > 0){ if (Alarms_Playing[AlarmIndex] == 0 && Alarms_Times[AlarmIndex] > 0){
@ -368,7 +382,7 @@ void WatchyGSR::init(){
}else WaitForNext = true; }else WaitForNext = true;
} }
if (WatchyAPOn && !OTAUpdate){ if (GSRWiFi.Requests == 0 && WatchyAPOn && !OTAUpdate){
switch (Menu.SubItem){ switch (Menu.SubItem){
case 0: // Turn off AP. case 0: // Turn off AP.
OTAEnd = true; OTAEnd = true;
@ -448,6 +462,7 @@ void WatchyGSR::init(){
*/ */
}); });
ArduinoOTA.begin(); ArduinoOTA.begin();
RefreshCPU(CPUMAX);
}else if (Menu.Item == MENU_OTAM){ }else if (Menu.Item == MENU_OTAM){
/*return index page which is stored in basicIndex */ /*return index page which is stored in basicIndex */
server.on("/", HTTP_GET, [=]() { server.on("/", HTTP_GET, [=]() {
@ -512,6 +527,7 @@ void WatchyGSR::init(){
} //else Update.printError(Serial); } //else Update.printError(Serial);
} }
}); });
RefreshCPU(CPUMAX);
server.begin(); server.begin();
} }
Menu.SubItem++; Menu.SubItem++;
@ -546,21 +562,21 @@ void WatchyGSR::init(){
// Don't do anything time sensitive while in OTA Update. // Don't do anything time sensitive while in OTA Update.
if (!Sensitive){ if (!Sensitive){
CalculateTones(); monitorSteps();
if (!DarkWait()) GoDark();
AlarmsOn =(Alarms_Times[0] > 0 || Alarms_Times[1] > 0 || Alarms_Times[2] > 0 || Alarms_Times[3] > 0 || TimerDown.ToneLeft > 0);
ActiveMode = (InTurbo() || DarkWait() || NTPData.State > 0 || AlarmsOn || WatchyAPOn || OTAUpdate || NTPData.TimeTest);
// Here, check for button presses and respond, done here to avoid turbo button presses. // Here, check for button presses and respond, done here to avoid turbo button presses.
if (!DarkWait()) GoDark();
handleInterrupt(); handleInterrupt();
if (Button > 0) { handleButtonPress(Button); Button = 0; } if (Button > 0) { handleButtonPress(Button); Button = 0; }
if (UpdateDisp) showWatchFace(); //partial updates on tick if (UpdateDisp) showWatchFace(); //partial updates on tick
CalculateTones(); monitorSteps();
AlarmsOn =(Alarms_Times[0] > 0 || Alarms_Times[1] > 0 || Alarms_Times[2] > 0 || Alarms_Times[3] > 0 || TimerDown.ToneLeft > 0);
ActiveMode = (InTurbo() || DarkWait() || NTPData.State > 0 || AlarmsOn || WatchyAPOn || OTAUpdate || NTPData.TimeTest || WatchTime.DeadRTC);
if (WatchTime.DeadRTC && Options.NeedsSaving) RecordSettings();
RefreshCPU(CPUDEF);
Since=50-(millis()-Since); Since=50-(millis()-Since);
if (Since <= 50) delay(Since); if (Since <= 50) delay(Since);
UpdateUTC();
Since=millis();
} }
WatchTime.NewMinute=false; WatchTime.NewMinute=false;
IDidIt=false; IDidIt=false;
@ -572,12 +588,14 @@ void WatchyGSR::init(){
processWiFiRequest(); // Process any WiFi requests. processWiFiRequest(); // Process any WiFi requests.
if (UpdateDisp) showWatchFace(); //partial updates on tick if (UpdateDisp) showWatchFace(); //partial updates on tick
AlarmsOn =(Alarms_Times[0] > 0 || Alarms_Times[1] > 0 || Alarms_Times[2] > 0 || Alarms_Times[3] > 0 || TimerDown.ToneLeft > 0); AlarmsOn =(Alarms_Times[0] > 0 || Alarms_Times[1] > 0 || Alarms_Times[2] > 0 || Alarms_Times[3] > 0 || TimerDown.ToneLeft > 0);
ActiveMode = (InTurbo() || DarkWait() || NTPData.State > 0 || AlarmsOn || WatchyAPOn || OTAUpdate || NTPData.TimeTest); ActiveMode = (InTurbo() || DarkWait() || NTPData.State > 0 || AlarmsOn || WatchyAPOn || OTAUpdate || NTPData.TimeTest || WatchTime.DeadRTC);
} }
deepSleep(); deepSleep();
} }
void WatchyGSR::showWatchFace(){ void WatchyGSR::showWatchFace(){
RefreshCPU(CPUMID);
if (Darkness.Went) display.init(0,false); // Force it here so it fixes the border.
display.epd2.setDarkBorder(Options.Border); display.epd2.setDarkBorder(Options.Border);
drawWatchFace(); drawWatchFace();
@ -589,6 +607,7 @@ void WatchyGSR::showWatchFace(){
DoHaptic=false; DoHaptic=false;
UpdateDisp=false; UpdateDisp=false;
ScreenRefresh(); ScreenRefresh();
RefreshCPU();
} }
void WatchyGSR::drawWatchFace(){ void WatchyGSR::drawWatchFace(){
@ -810,7 +829,7 @@ void WatchyGSR::drawMenu(){
O = "Watchy Reboot"; O = "Watchy Reboot";
break; break;
case MENU_TOFF: case MENU_TOFF:
O = "Detect Travel"; if (WatchTime.DeadRTC) O = "Return to RTC"; else O = "Detect Travel";
} }
display.getTextBounds(O, 0, HeaderY, &x1, &y1, &w, &h); display.getTextBounds(O, 0, HeaderY, &x1, &y1, &w, &h);
w = (196 - w) /2; w = (196 - w) /2;
@ -973,10 +992,10 @@ void WatchyGSR::drawMenu(){
if (Options.Feedback){ if (Options.Feedback){
O = "Enabled"; O = "Enabled";
}else { }else {
O = "Disabled"; O = (WatchTime.DeadRTC ? "Locked" : "Disabled");
} }
}else if (Menu.Item == MENU_TRBO){ // Turbo! }else if (Menu.Item == MENU_TRBO){ // Turbo!
if (Options.Turbo > 0) O=String(Options.Turbo) + " " + MakeSeconds(Options.Turbo); else O = "Off"; if (Options.Turbo > 0 && !WatchTime.DeadRTC) O=String(Options.Turbo) + " " + MakeSeconds(Options.Turbo); else O = "Off";
}else if (Menu.Item == MENU_DARK){ // Dark Running. }else if (Menu.Item == MENU_DARK){ // Dark Running.
switch(Menu.SubItem){ switch(Menu.SubItem){
case 0: case 0:
@ -1048,7 +1067,7 @@ void WatchyGSR::drawMenu(){
}else if (Menu.Item == MENU_TOFF){ // Time Travel detect. }else if (Menu.Item == MENU_TOFF){ // Time Travel detect.
switch (Menu.SubItem){ switch (Menu.SubItem){
case 0: case 0:
O = "MENU to Start"; if (WatchTime.DeadRTC) O = "MENU to Change"; else O = "MENU to Start";
break; break;
case 1: case 1:
O = "Time Sync"; O = "Time Sync";
@ -1057,7 +1076,7 @@ void WatchyGSR::drawMenu(){
O = "Calculating"; O = "Calculating";
break; break;
case 3: case 3:
if (Options.UsingDrift){ if (Options.Drift< 0) O = "+" + String(0 - Options.Drift) + " " + MakeSeconds(0 - Options.Drift); else O = "-" + String(Options.Drift) + " " + MakeSeconds(Options.Drift); } else O = "No Drift"; if (WatchTime.DeadRTC) O = "Bad RTC"; else { if (Options.UsingDrift){ if (Options.Drift< 0) O = "+" + String(0 - Options.Drift) + " " + MakeSeconds(0 - Options.Drift); else O = "-" + String(Options.Drift) + " " + MakeSeconds(Options.Drift); } else O = "No Drift"; }
} }
} }
if (O > ""){ if (O > ""){
@ -1074,24 +1093,38 @@ void WatchyGSR::deepSleep(){
GoDark(); GoDark();
display.hibernate(); display.hibernate();
if (Options.NeedsSaving) RecordSettings(); if (Options.NeedsSaving) RecordSettings();
esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press ... |ACC_INT_MASK esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press ... |ACC_INT_MASK
esp_deep_sleep_start(); esp_deep_sleep_start();
} }
void WatchyGSR::GoDark(){ void WatchyGSR::GoDark(){
if ((Updates.Drawn || Battery.Direction != Battery.DarkDirection) && Showing() == false) if ((Updates.Drawn || Battery.Direction != Battery.DarkDirection || !Darkness.Went) && !Showing())
{ {
Darkness=true; Darkness.Went=true;
display.epd2.setDarkBorder(true);
display.init(0,false); // Force it here so it fixes the border. display.init(0,false); // Force it here so it fixes the border.
display.epd2.setDarkBorder(true);
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
if (getBatteryVoltage() < MinBattery) display.drawBitmap(155, 178, ChargeMe, 40, 17, GxEPD_WHITE); else if (Battery.Direction == 1) display.drawBitmap(155, 178, Charging, 40, 17, GxEPD_WHITE); if (getBatteryVoltage() < MinBattery) display.drawBitmap(155, 178, ChargeMe, 40, 17, GxEPD_WHITE); else if (Battery.Direction == 1) display.drawBitmap(155, 178, Charging, 40, 17, GxEPD_WHITE);
Battery.DarkDirection = Battery.Direction; Battery.DarkDirection = Battery.Direction;
display.setFullWindow(); display.setFullWindow();
display.display(true); display.display(true);
Updates.Drawn = false; WatchTime.LastTime="";
WatchTime.LastDay="";
WatchTime.LastDate="";
WatchTime.LastYear="";
Menu.LastHeader="";
Menu.LastItem="";
Updates.Time=true;
Updates.Day=true;
Updates.Date=true;
Updates.Header=true;
Updates.Item=true;
Updates.Status=true;
Updates.Year=true;
Updates.Charge=true;
Updates.Drawn=false;
if (WatchTime.DeadRTC) display.hibernate();
} }
} }
@ -1125,7 +1158,6 @@ void WatchyGSR::detectBattery(){
} }
void WatchyGSR::ProcessNTP(){ void WatchyGSR::ProcessNTP(){
tmElements_t TM;
bool B; bool B;
// Do ProgressNTP here. // Do ProgressNTP here.
@ -1245,11 +1277,11 @@ void WatchyGSR::ProcessNTP(){
break; break;
} }
WatchTime.UTC_RAW = time(nullptr); WatchTime.UTC_RAW = time(nullptr);
breakTime(WatchTime.UTC_RAW,TM); breakTime(WatchTime.UTC_RAW,WatchTime.UTC);
RTC.write(TM); RTC.write(WatchTime.UTC);
WatchTime.Drifting = 0; WatchTime.Drifting = 0;
WatchTime.EPSMS = (millis() + (60000 - (1000 * WatchTime.UTC.Second))); WatchTime.EPSMS = (millis() + (1000 * (60 - WatchTime.UTC.Second)));
WatchTime.UTC = TM; WatchTime.WatchyRTC = esp_timer_get_time() + ((60 - WatchTime.UTC.Second) * 1000000);
NTPData.NTPDone = true; NTPData.NTPDone = true;
NTPData.Pause = 0; NTPData.Pause = 0;
NTPData.State = 99; NTPData.State = 99;
@ -1291,17 +1323,20 @@ void WatchyGSR::drawStatus(){
if (WatchyStatus > ""){ if (WatchyStatus > ""){
display.fillRect(NTPX, NTPY - 19, 60, 20, Options.LightMode ? GxEPD_WHITE : GxEPD_BLACK); display.fillRect(NTPX, NTPY - 19, 60, 20, Options.LightMode ? GxEPD_WHITE : GxEPD_BLACK);
display.setFont(&Bronova_Regular13pt7b); display.setFont(&Bronova_Regular13pt7b);
display.setCursor(NTPX + 17, NTPY);
// display.setTextColor(Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
// display.print(WatchyStatus);
if (WatchyStatus.startsWith("WiFi")){ if (WatchyStatus.startsWith("WiFi")){
display.drawBitmap(NTPX, NTPY - 18, iWiFi, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE); display.drawBitmap(NTPX, NTPY - 18, iWiFi, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
display.print(WatchyStatus.substring(4)); if (WatchyStatus.length() > 4){
display.setCursor(NTPX + 17, NTPY);
display.setTextColor(Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
display.print(WatchyStatus.substring(4));
}
} }
else if (WatchyStatus == "TZ") display.drawBitmap(NTPX, NTPY - 18, iTZ, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE); else if (WatchyStatus == "TZ") display.drawBitmap(NTPX, NTPY - 18, iTZ, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
else if (WatchyStatus == "NTP") display.drawBitmap(NTPX, NTPY - 18, iSync, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE); else if (WatchyStatus == "NTP") display.drawBitmap(NTPX, NTPY - 18, iSync, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
else if (WatchyStatus == "ESP") display.drawBitmap(NTPX, NTPY - 18, iSync, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE); else if (WatchyStatus == "ESP") display.drawBitmap(NTPX, NTPY - 18, iSync, 19, 19, Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
else{ else{
display.setCursor(NTPX + 17, NTPY);
display.setTextColor(Options.LightMode ? GxEPD_BLACK : GxEPD_WHITE);
display.setCursor(NTPX, NTPY); display.setCursor(NTPX, NTPY);
display.print(WatchyStatus); display.print(WatchyStatus);
} }
@ -1363,8 +1398,9 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
*/ */
if (Options.Orientated) { if (Direction != DIRECTION_DISP_UP && Direction != DIRECTION_TOP_EDGE) return; } // Don't accept it. if (Options.Orientated) { if (Direction != DIRECTION_DISP_UP && Direction != DIRECTION_TOP_EDGE) return; } // Don't accept it.
LastButton=millis(); if (LastButton > 0 && (millis() - LastButton) < KEYPAUSE) return;
if (Darkness) { Button = 0; SetTurbo(); UpdateDisp=true; return; } // Don't do the button, just exit. LastButton=millis(); Darkness.Last=LastButton;
if (Darkness.Went) { UpdateDisp=true; return; } // Don't do the button, just exit.
switch (Pressed){ switch (Pressed){
case 1: case 1:
@ -1437,7 +1473,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
SetTurbo(); SetTurbo();
} }
}else if (Menu.Item == MENU_TONES){ // Tones. }else if (Menu.Item == MENU_TONES){ // Tones.
Options.MasterRepeats = clamp(Options.MasterRepeats + 1, 0, 4); Options.MasterRepeats = clamp(Options.MasterRepeats + 1, (WatchTime.DeadRTC ? 4 : 0), 4);
Alarms_Repeats[0] = Options.MasterRepeats; Alarms_Repeats[0] = Options.MasterRepeats;
Alarms_Repeats[1] = Options.MasterRepeats; Alarms_Repeats[1] = Options.MasterRepeats;
Alarms_Repeats[2] = Options.MasterRepeats; Alarms_Repeats[2] = Options.MasterRepeats;
@ -1571,14 +1607,14 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
DoHaptic = true; DoHaptic = true;
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
SetTurbo(); SetTurbo();
}else if (Menu.Item == MENU_FEED){ // Feedback. }else if (Menu.Item == MENU_FEED && !WatchTime.DeadRTC){ // Feedback.
Options.Feedback = !Options.Feedback; Options.Feedback = !Options.Feedback;
Menu.LastItem=""; // Forces a redraw. Menu.LastItem=""; // Forces a redraw.
Options.NeedsSaving = true; Options.NeedsSaving = true;
DoHaptic = true; DoHaptic = true;
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
SetTurbo(); SetTurbo();
}else if (Menu.Item == MENU_TRBO){ // Turbo }else if (Menu.Item == MENU_TRBO && !WatchTime.DeadRTC){ // Turbo
Options.Turbo = roller(Options.Turbo + 1, 0, 10); Options.Turbo = roller(Options.Turbo + 1, 0, 10);
Options.NeedsSaving = true; Options.NeedsSaving = true;
DoHaptic = true; DoHaptic = true;
@ -1621,14 +1657,19 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
}else if (Menu.Item == MENU_TOFF && NTPData.State == 0 && Menu.SubItem == 0){ // Detect Drift }else if (Menu.Item == MENU_TOFF && NTPData.State == 0 && Menu.SubItem == 0){ // Detect Drift
WatchTime.LastDay=""; WatchTime.LastDay="";
WatchTime.LastDate=""; WatchTime.LastDate="";
NTPData.TimeTest = true; if (WatchTime.DeadRTC){
NTPData.State = 1; Options.NeedsSaving = true;
Menu.SubItem = 1; WatchTime.DeadRTC = false;
NTPData.UpdateUTC = true; }else{
NTPData.TimeTest = true;
NTPData.State = 1;
Menu.SubItem = 1;
NTPData.UpdateUTC = true;
AskForWiFi();
}
DoHaptic = true; DoHaptic = true;
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
SetTurbo(); SetTurbo();
AskForWiFi();
} }
} }
break; break;
@ -1791,7 +1832,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
SetTurbo(); SetTurbo();
}else if (Menu.SubItem == 4){ // Repeats. }else if (Menu.SubItem == 4){ // Repeats.
Alarms_Repeats[Menu.Item - MENU_ALARM1] = roller(Alarms_Repeats[Menu.Item - MENU_ALARM1] - 1, 0, 4); Alarms_Repeats[Menu.Item - MENU_ALARM1] = roller(Alarms_Repeats[Menu.Item - MENU_ALARM1] - 1, (WatchTime.DeadRTC ? 4 : 0), 4);
Options.NeedsSaving = true; Options.NeedsSaving = true;
DoHaptic = true; DoHaptic = true;
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
@ -1836,7 +1877,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
SetTurbo(); SetTurbo();
break; break;
case 4: //Repeats case 4: //Repeats
TimerDown.MaxTones = roller(TimerDown.MaxTones - 1, 0, 4); TimerDown.MaxTones = roller(TimerDown.MaxTones - 1, (WatchTime.DeadRTC ? 4 : 0), 4);
StopCD(); StopCD();
Options.NeedsSaving = true; Options.NeedsSaving = true;
DoHaptic = true; DoHaptic = true;
@ -1846,7 +1887,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
}else if (Menu.Item == MENU_DARK && Menu.SubItem > 0){ // Sleep Mode. }else if (Menu.Item == MENU_DARK && Menu.SubItem > 0){ // Sleep Mode.
switch (Menu.SubItem){ switch (Menu.SubItem){
case 1: // Style. case 1: // Style.
Options.SleepStyle = roller(Options.SleepStyle + 1, 0, 2); Options.SleepStyle = roller(Options.SleepStyle + 1, (WatchTime.DeadRTC ? 1 : 0), 2);
Options.NeedsSaving = true; Options.NeedsSaving = true;
break; break;
case 2: // SleepMode (0=off, 10 seconds) case 2: // SleepMode (0=off, 10 seconds)
@ -1956,7 +1997,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
SetTurbo(); SetTurbo();
}else if (Menu.SubItem == 4){ // Repeats. }else if (Menu.SubItem == 4){ // Repeats.
Alarms_Repeats[Menu.Item - MENU_ALARM1] = roller(Alarms_Repeats[Menu.Item - MENU_ALARM1] + 1, 0, 4); Alarms_Repeats[Menu.Item - MENU_ALARM1] = roller(Alarms_Repeats[Menu.Item - MENU_ALARM1] + 1, (WatchTime.DeadRTC ? 4 : 0), 4);
Options.NeedsSaving = true; Options.NeedsSaving = true;
DoHaptic = true; DoHaptic = true;
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
@ -2001,7 +2042,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
SetTurbo(); SetTurbo();
break; break;
case 4: //Repeats case 4: //Repeats
TimerDown.MaxTones = roller(TimerDown.MaxTones + 1, 0, 4); TimerDown.MaxTones = roller(TimerDown.MaxTones + 1, (WatchTime.DeadRTC ? 4 : 0), 4);
StopCD(); StopCD();
Options.NeedsSaving = true; Options.NeedsSaving = true;
DoHaptic = true; DoHaptic = true;
@ -2011,7 +2052,7 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
}else if (Menu.Item == MENU_DARK && Menu.SubItem > 0){ // Sleep Mode. }else if (Menu.Item == MENU_DARK && Menu.SubItem > 0){ // Sleep Mode.
switch (Menu.SubItem){ switch (Menu.SubItem){
case 1: // Style. case 1: // Style.
Options.SleepStyle = roller(Options.SleepStyle - 1, 0, 2); Options.SleepStyle = roller(Options.SleepStyle - 1, (WatchTime.DeadRTC ? 1 : 0), 2);
Options.NeedsSaving = true; Options.NeedsSaving = true;
break; break;
case 2: // SleepMode (0=off, 10 seconds) case 2: // SleepMode (0=off, 10 seconds)
@ -2062,8 +2103,10 @@ void WatchyGSR::handleButtonPress(uint8_t Pressed){
void WatchyGSR::UpdateUTC(){ void WatchyGSR::UpdateUTC(){
tmElements_t TM; // struct tm * tm; tmElements_t TM; // struct tm * tm;
RTC.read(TM); if (!WatchTime.DeadRTC){
WatchTime.UTC_RAW = makeTime(TM) + (NTPData.TimeTest ? 0 : WatchTime.Drifting); RTC.read(TM);
WatchTime.UTC_RAW = makeTime(TM) + (NTPData.TimeTest ? 0 : WatchTime.Drifting);
}
breakTime(WatchTime.UTC_RAW,WatchTime.UTC); breakTime(WatchTime.UTC_RAW,WatchTime.UTC);
} }
@ -2085,7 +2128,10 @@ void WatchyGSR::UpdateClock(){
void WatchyGSR::ManageTime(){ void WatchyGSR::ManageTime(){
tmElements_t TM; // struct tm * tm; tmElements_t TM; // struct tm * tm;
int I; int I;
if (WatchTime.EPSMS < millis()){ bool B;
if (WatchTime.DeadRTC) B = (WatchTime.WatchyRTC < esp_timer_get_time()); else B = (WatchTime.EPSMS < millis());
if (B){
// Deal with NTPData.TimeTest. // Deal with NTPData.TimeTest.
if (NTPData.TimeTest){ if (NTPData.TimeTest){
NTPData.TestCount++; NTPData.TestCount++;
@ -2097,7 +2143,10 @@ void WatchyGSR::ManageTime(){
if (WatchTime.TravelTest > WatchTime.UTC_RAW) Options.Drift = 0 - (WatchTime.TravelTest - WatchTime.UTC_RAW); if (WatchTime.TravelTest > WatchTime.UTC_RAW) Options.Drift = 0 - (WatchTime.TravelTest - WatchTime.UTC_RAW);
else if (WatchTime.UTC_RAW > WatchTime.TravelTest) Options.Drift = WatchTime.UTC_RAW - WatchTime.TravelTest; else if (WatchTime.UTC_RAW > WatchTime.TravelTest) Options.Drift = WatchTime.UTC_RAW - WatchTime.TravelTest;
else if (WatchTime.UTC_RAW == WatchTime.TravelTest) Options.Drift = 0; else if (WatchTime.UTC_RAW == WatchTime.TravelTest) Options.Drift = 0;
Options.UsingDrift = (Options.Drift != 0); if (Options.Drift < -29 || Options.Drift > 29){
WatchTime.DeadRTC = true; Options.NeedsSaving = true; Options.UsingDrift = false; Options.Feedback = false; Options.MasterRepeats = 4; Alarms_Repeats[0] = 4; Alarms_Repeats[1] = 4; Alarms_Repeats[2] = 4; Alarms_Repeats[3] = 4; TimerDown.MaxTones = 4;
if (Options.SleepStyle == 0) Options.SleepStyle = 1;
}else Options.UsingDrift = (Options.Drift != 0);
if (Menu.Item == MENU_TOFF) Menu.SubItem = 3; if (Menu.Item == MENU_TOFF) Menu.SubItem = 3;
NTPData.TimeTest = false; NTPData.TimeTest = false;
if (Options.UsingDrift) WatchTime.Drifting = Options.Drift; if (Options.UsingDrift) WatchTime.Drifting = Options.Drift;
@ -2109,17 +2158,25 @@ void WatchyGSR::ManageTime(){
UpdateClock(); UpdateClock();
} }
} }
WatchTime.EPSMS += 60000; if (WatchTime.DeadRTC) WatchTime.WatchyRTC += 60000000; else WatchTime.EPSMS += 60000;
WatchTime.NewMinute=true; WatchTime.NewMinute=true;
} }
if (WatchTime.NewMinute && !NTPData.TimeTest && !IDidIt){ if (WatchTime.NewMinute && !NTPData.TimeTest && !IDidIt){
WatchTime.EPSMS += ((Options.UsingDrift ? Options.Drift : 0) * 1000); if (WatchTime.DeadRTC){
if (Options.UsingDrift){ WatchTime.UTC_RAW += 60;
WatchTime.Drifting += Options.Drift;
IDidIt = true; IDidIt = true;
UpdateDisp=Showing(); UpdateDisp=Showing();
UpdateUTC(); UpdateUTC();
UpdateClock(); UpdateClock();
}else{
WatchTime.EPSMS += ((Options.UsingDrift ? Options.Drift : 0) * 1000);
if (Options.UsingDrift){
WatchTime.Drifting += Options.Drift;
IDidIt = true;
UpdateDisp=Showing();
UpdateUTC();
UpdateClock();
}
} }
} }
} }
@ -2334,7 +2391,7 @@ void WatchyGSR::CheckAlarm(int I){
if (bA && Alarms_Times[I] == 0 && (Alarms_Active[I] & ALARM_TRIGGERED) == 0){ if (bA && Alarms_Times[I] == 0 && (Alarms_Active[I] & ALARM_TRIGGERED) == 0){
Alarms_Times[I] = 255; Alarms_Times[I] = 255;
Alarms_Playing[I] = 30; Alarms_Playing[I] = 30;
LastUse=millis(); LastButton=LastUse; Darkness.Last=millis();
UpdateDisp=true; // Force it on, if it is in Dark Running. UpdateDisp=true; // Force it on, if it is in Dark Running.
Alarms_Active[I] |= ALARM_TRIGGERED; Alarms_Active[I] |= ALARM_TRIGGERED;
if ((Alarms_Active[I] & ALARM_REPEAT) == 0){ if ((Alarms_Active[I] & ALARM_REPEAT) == 0){
@ -2361,7 +2418,7 @@ void WatchyGSR::CheckCD(){
TimerDown.Tone = 24; TimerDown.Tone = 24;
TimerDown.ToneLeft = 255; TimerDown.ToneLeft = 255;
TimerDown.Active = false; TimerDown.Active = false;
LastUse=millis(); LastButton=LastUse; Darkness.Last=millis();
UpdateDisp = true; // Quick Update. UpdateDisp = true; // Quick Update.
} }
} }
@ -2471,7 +2528,7 @@ IRAM_ATTR uint8_t WatchyGSR::getSwapped(uint8_t pIn){
void WatchyGSR::ScreenRefresh(){ void WatchyGSR::ScreenRefresh(){
uint16_t XL, YL, XH, YH; uint16_t XL, YL, XH, YH;
bool DoIt; bool DoIt = false;
XL = 200; YL = 200; XH = 0; YH = 0; XL = 200; YL = 200; XH = 0; YH = 0;
@ -2488,19 +2545,19 @@ void WatchyGSR::ScreenRefresh(){
}else{ XL = 0; YL = 0; XH = 200; YH = 200; DoIt = true; } }else{ XL = 0; YL = 0; XH = 200; YH = 200; DoIt = true; }
if (DoIt){ if (DoIt){
if(Updates.Full) display.setFullWindow(); else display.setFullWindow(); //init moved, can't do this: display.setPartialWindow(XL, YL, XH - XL, YH - YL); if(Updates.Full) display.setFullWindow(); else display.setFullWindow(); //init moved, can't do this: display.setPartialWindow(XL, YL, XH - XL, YH - YL);
Darkness=false; Darkness.Went=false; Darkness.Last = millis();
display.display(!Updates.Full); //partial refresh display.display(!Updates.Full); //partial refresh
Updates.Drawn=Updates.Time || Updates.Day || Updates.Date || Updates.Header || Updates.Item || Updates.Status || Updates.Year || Updates.Charge || Updates.Full;
Updates.Time=false;
Updates.Day=false;
Updates.Date=false;
Updates.Header=false;
Updates.Item=false;
Updates.Status=false;
Updates.Year=false;
Updates.Charge=false;
Updates.Full=false;
} }
Updates.Drawn=Updates.Time || Updates.Day || Updates.Date || Updates.Header || Updates.Item || Updates.Status || Updates.Year || Updates.Charge || Updates.Full;
Updates.Time=false;
Updates.Day=false;
Updates.Date=false;
Updates.Header=false;
Updates.Item=false;
Updates.Status=false;
Updates.Year=false;
Updates.Charge=false;
Updates.Full=false;
} }
void WatchyGSR::AskForWiFi(){ if (!GSRWiFi.Requested && !GSRWiFi.Working) GSRWiFi.Requested = true; } void WatchyGSR::AskForWiFi(){ if (!GSRWiFi.Requested && !GSRWiFi.Working) GSRWiFi.Requested = true; }
@ -2525,6 +2582,9 @@ void WatchyGSR::processWiFiRequest(){
if (GSRWiFi.Requested){ if (GSRWiFi.Requested){
GSRWiFi.Requested = false; GSRWiFi.Requested = false;
if (GSRWiFi.Requests == 0){ if (GSRWiFi.Requests == 0){
RefreshCPU(CPUMAX);
OTATimer = millis();
OTAFail = OTATimer;
WiFi.onEvent(WatchyGSR::WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED); WiFi.onEvent(WatchyGSR::WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);
WiFi.disconnect(); WiFi.disconnect();
WiFi.setHostname(WiFi_AP_SSID); WiFi.setHostname(WiFi_AP_SSID);
@ -2552,7 +2612,7 @@ void WatchyGSR::processWiFiRequest(){
setStatus(WiFiIndicator(24)); setStatus(WiFiIndicator(24));
GSRWiFi.Tried = true; GSRWiFi.Tried = true;
if (WiFi_DEF_SSID > "") WiFiE = WiFi.begin(WiFi_DEF_SSID,WiFi_DEF_PASS); else WiFiE = WiFi.begin(); if (WiFi_DEF_SSID > "") WiFiE = WiFi.begin(WiFi_DEF_SSID,WiFi_DEF_PASS); else WiFiE = WiFi.begin();
GSRWiFi.Last = millis() + 6000; GSRWiFi.Last = millis() + 9000;
//if (WiFiE == WL_CONNECT_FAILED || WiFiE == WL_NO_SSID_AVAIL) { GSRWiFi.Last = millis() + 53000; GSRWiFi.Index++; } // Try the next one instantly. //if (WiFiE == WL_CONNECT_FAILED || WiFiE == WL_NO_SSID_AVAIL) { GSRWiFi.Last = millis() + 53000; GSRWiFi.Index++; } // Try the next one instantly.
} }
if (GSRWiFi.Index > 0){ if (GSRWiFi.Index > 0){
@ -2562,7 +2622,7 @@ void WatchyGSR::processWiFiRequest(){
setStatus(O); setStatus(O);
GSRWiFi.Tried = true; GSRWiFi.Tried = true;
WiFiE = WiFi.begin(AP.c_str(),PA.c_str()); WiFiE = WiFi.begin(AP.c_str(),PA.c_str());
GSRWiFi.Last = millis() + 6000; GSRWiFi.Last = millis() + 9000;
}else GSRWiFi.Index++; }else GSRWiFi.Index++;
//if (WiFiE == WL_CONNECT_FAILED || WiFiE == WL_NO_SSID_AVAIL || AP == "") { GSRWiFi.Last = millis() + 53000; GSRWiFi.Index++; } // Try the next one instantly. //if (WiFiE == WL_CONNECT_FAILED || WiFiE == WL_NO_SSID_AVAIL || AP == "") { GSRWiFi.Last = millis() + 53000; GSRWiFi.Index++; } // Try the next one instantly.
} }
@ -2688,6 +2748,16 @@ void WatchyGSR::initZeros(){
GSRWiFi.Working=false; GSRWiFi.Working=false;
GSRWiFi.Results=false; GSRWiFi.Results=false;
GSRWiFi.Index=0; GSRWiFi.Index=0;
Updates.Time=true;
Updates.Day=true;
Updates.Date=true;
Updates.Header=true;
Updates.Item=true;
Updates.Status=true;
Updates.Year=true;
Updates.Charge=true;
Updates.Full=true;
Updates.Drawn=true;
strcpy(GSRWiFi.AP[0].APID,S.c_str()); strcpy(GSRWiFi.AP[0].APID,S.c_str());
strcpy(GSRWiFi.AP[0].PASS,S.c_str()); strcpy(GSRWiFi.AP[0].PASS,S.c_str());
strcpy(GSRWiFi.AP[1].APID,S.c_str()); strcpy(GSRWiFi.AP[1].APID,S.c_str());
@ -2830,20 +2900,25 @@ void WatchyGSR::StoreSettings(String FromUser){
if (NewV > 128){ if (NewV > 128){
J++; if (L > J + 1){ J++; if (L > J + 1){
Options.Drift = (((O[J + 1] & 255) << 8) | O[J]); J++; Options.Drift = (((O[J + 1] & 255) << 8) | O[J]); J++;
if (Options.Drift < -29 || Options.Drift > 29){
Options.UsingDrift = false;
WatchTime.DeadRTC = true;
}else WatchTime.DeadRTC = false;
} }
J++; if (L > J) Options.SleepStyle = clamp(O[J],0,2); J++; if (L > J) Options.SleepStyle = clamp(O[J],(WatchTime.DeadRTC ? 1 : 0),2);
J++; if (L > J) Options.SleepMode = clamp(O[J],1,10); J++; if (L > J) Options.SleepMode = clamp(O[J],1,10);
J++; if (L > J) Options.SleepStart = clamp(O[J],0,23); J++; if (L > J) Options.SleepStart = clamp(O[J],0,23);
J++; if (L > J) Options.SleepEnd = clamp(O[J],0,23); J++; if (L > J) Options.SleepEnd = clamp(O[J],0,23);
} }
if (WatchTime.DeadRTC) Options.Feedback = false;
J++; if (L > J){ J++; if (L > J){
V = ((O[J] & 224) >> 5); V = ((O[J] & 224) >> 5);
Options.MasterRepeats = V; Options.MasterRepeats = clamp(V,(WatchTime.DeadRTC ? 4 : 0),4);
Options.Turbo = clamp((O[J] & 31),0,10); Options.Turbo = clamp((O[J] & 31),0,10);
} }
J++; if (L > J){ J++; if (L > J){
V = ((O[J] & 224) >> 5); V = ((O[J] & 224) >> 5);
TimerDown.MaxTones = V; TimerDown.MaxTones = clamp(V,(WatchTime.DeadRTC ? 4 : 0),4);
TimerDown.MaxHours = clamp((O[J] & 31),0,23); TimerDown.MaxHours = clamp((O[J] & 31),0,23);
} }
J++; if (L > J) TimerDown.MaxMins = clamp(O[J],0,59); J++; if (L > J) TimerDown.MaxMins = clamp(O[J],0,59);
@ -2851,7 +2926,7 @@ void WatchyGSR::StoreSettings(String FromUser){
for (K = 0; K < 4; K++){ for (K = 0; K < 4; K++){
J++; if (L > J){ J++; if (L > J){
V = ((O[J] & 224) >> 5); V = ((O[J] & 224) >> 5);
Alarms_Repeats[K] = V; Alarms_Repeats[K] = clamp(V,(WatchTime.DeadRTC ? 4 : 0),4);
Alarms_Hour[K] = clamp((O[J] & 31),0,23); Alarms_Hour[K] = clamp((O[J] & 31),0,23);
} }
J++; if (L > J) Alarms_Minutes[K] = clamp(O[J],0,59); J++; if (L > J) Alarms_Minutes[K] = clamp(O[J],0,59);
@ -2905,21 +2980,33 @@ void WatchyGSR::RecordSettings(){
// Turbo Mode! // Turbo Mode!
void WatchyGSR::SetTurbo(){ void WatchyGSR::SetTurbo(){
Turbo.On=true; TurboTime=millis();
Turbo.Last=millis(); LastButton=TurboTime; // Here for speed.
LastButton=Turbo.Last; // Here for speed. Darkness.Last=LastButton; // Keeps track of SleepMode.
LastUse=LastButton; // Keeps track of SleepMode.
} }
bool WatchyGSR::InTurbo() { return (Turbo.On && millis() - Turbo.Last < (Options.Turbo * 1000)); } bool WatchyGSR::InTurbo() { return (Options.Turbo > 0 && millis() - TurboTime < (Options.Turbo * 1000)); }
bool WatchyGSR::DarkWait() { return (Options.SleepStyle > 0 && LastButton > 0 && (millis() - LastUse) < (Options.SleepMode * 1000)); } bool WatchyGSR::DarkWait(){
bool B = (Darkness.Last > 0 && (millis() - Darkness.Last) < (Options.SleepMode * 1000));
if (Options.SleepStyle == 2){
if (B) return B;
if (Options.SleepEnd > Options.SleepStart) { if (WatchTime.Local.Hour >= Options.SleepStart && WatchTime.Local.Hour < Options.SleepEnd) return false; }
else if (WatchTime.Local.Hour >= Options.SleepStart || WatchTime.Local.Hour < Options.SleepEnd) return false;
}else if (Options.SleepStyle > 0) return B;
return false;
}
bool WatchyGSR::Showing() { bool WatchyGSR::Showing() {
bool B = Updates.Full;
if (Options.SleepStyle > 0){ if (Options.SleepStyle > 0){
if (LastButton > 0 && (millis() - LastUse) < (Options.SleepMode * 1000)) return true; B |= (Darkness.Last > 0 && (millis() - Darkness.Last) < (Options.SleepMode * 1000));
if (Options.SleepStyle == 1) return (GuiMode != WATCHON); // Hide because it isn't checking the rest. if (Options.SleepStyle == 1){
if (WatchTime.DeadRTC) return B;
else return (B | (GuiMode != WATCHON)); // Hide because it isn't checking the rest.
}
if (Options.SleepStyle == 2){ if (Options.SleepStyle == 2){
if (B) return B;
if (Options.SleepEnd > Options.SleepStart) { if (WatchTime.Local.Hour >= Options.SleepStart && WatchTime.Local.Hour < Options.SleepEnd) return false; } if (Options.SleepEnd > Options.SleepStart) { if (WatchTime.Local.Hour >= Options.SleepStart && WatchTime.Local.Hour < Options.SleepEnd) return false; }
else if (WatchTime.Local.Hour >= Options.SleepStart || WatchTime.Local.Hour < Options.SleepEnd) return false; else if (WatchTime.Local.Hour >= Options.SleepStart || WatchTime.Local.Hour < Options.SleepEnd) return false;
} }
@ -2927,6 +3014,18 @@ bool WatchyGSR::Showing() {
return true; return true;
} }
void WatchyGSR::RefreshCPU(){ RefreshCPU(0); }
void WatchyGSR::RefreshCPU(int Value){
uint32_t C;
bool B;
CPUSet.Freq=getCpuFrequencyMhz();
C = (InTurbo() || Value == CPUMID) ? 160 : 80;
if (Value == CPUMAX) CPUSet.Locked = true;
if (Value == CPUDEF) CPUSet.Locked = false;
if (WatchyAPOn || OTAUpdate || GSRWiFi.Requests > 0 || CPUSet.Locked) C = 240;
if (C != CPUSet.Freq) B = setCpuFrequencyMhz(C);
}
// Debugging here. // Debugging here.
void WatchyGSR::DBug(String Value){ void WatchyGSR::DBug(String Value){

View File

@ -103,6 +103,8 @@ class WatchyGSR{
bool InTurbo(); bool InTurbo();
bool DarkWait(); bool DarkWait();
bool Showing(); bool Showing();
void RefreshCPU();
void RefreshCPU(int Value);
void DBug(String Value); void DBug(String Value);
String ToHex(uint64_t Value); String ToHex(uint64_t Value);
}; };