Bug fixes: timer that spans midnight, stale info in timer setup screens

This commit is contained in:
rljonesau 2018-12-08 15:18:37 +11:00
parent ec1631b84b
commit fbe39980ce
6 changed files with 48 additions and 22 deletions

View file

@ -139,7 +139,7 @@ void initBlueWireSerial();
bool validateFrame(const CProtocol& frame, const char* name);
void checkDisplayUpdate();
void checkTimer();
void checkTimer(const DateTime& now, sTimer timerInfo);
void checkTimer(int timer, const DateTime& now);
void checkDebugCommands();
// DS18B20 temperature sensor support
@ -950,32 +950,44 @@ void checkTimer()
{
const DateTime& now = getCurrentTime();
sTimer timerInfo;
// test timer 1
NVstore.getTimerInfo(0, timerInfo);
checkTimer(now, timerInfo);
// test timer 2
NVstore.getTimerInfo(1, timerInfo);
checkTimer(now, timerInfo);
checkTimer(0, now); // test timer 1
checkTimer(1, now); // test timer 2
}
void checkTimer(const DateTime& now, sTimer timerInfo)
void checkTimer(int timer, const DateTime& now)
{
int maskDOW = 0x01 << now.dayOfTheWeek();
if(timerInfo.enabled & (maskDOW | 0x80) ) { // specific day, or next day
// check start
if(now.hour() == timerInfo.start.hour && now.minute() == timerInfo.start.min) {
sTimer Info;
NVstore.getTimerInfo(timer, Info);
int DOW = now.dayOfTheWeek();
int timeNow = now.hour() * 60 + now.minute();
int timeStart = Info.start.hour * 60 + Info.start.min;
int timeStop = Info.stop.hour * 60 + Info.stop.min;
// ensure DOW tracks expected start day should timer straddle midnight
if(timeStop < timeStart) { // true if stop is next morning
if(timeNow <= timeStop) { // current time has passed midnight - enable flag is based upon prior day
DOW--;
ROLLLOWERLIMIT(DOW, 0, 6); // fixup for saturday night!
}
}
// DOW of week is now correct for the day this timer started
int maskDOW = 0x01 << DOW;
if(Info.enabled & (maskDOW | 0x80) ) { // specific day of week, or next day
if(timeNow == timeStart && now.second() < 3) { // check start, within 2 seconds of the minute rollover
requestOn();
}
// check stop
if(now.hour() == timerInfo.stop.hour && now.minute() == timerInfo.stop.min) {
if(timeNow == timeStop) { // check stop
requestOff();
if(!timerInfo.repeat) { // cancel timer if non repeating
if(timerInfo.enabled & 0x80) // next day start flag?
timerInfo.enabled = 0; // outright cancel
else
timerInfo.enabled &= ~maskDOW; // otherwise clear particular day
NVstore.setTimerInfo(0, timerInfo);
if(!Info.repeat) { // cancel timer if non repeating
if(Info.enabled & 0x80) // next day start flag set?
Info.enabled = 0; // outright cancel
else {
Info.enabled &= ~maskDOW; // otherwise clear specific day
}
NVstore.setTimerInfo(timer, Info);
NVstore.save();
}
}

View file

@ -29,6 +29,11 @@ CScreen::show()
{
}
void
CScreen::onSelect()
{
}
void
CScreen::_printMenuText(int x, int y, const char* str, bool selected, eJUSTIFY justify, int border, int radius)

View file

@ -48,6 +48,7 @@ protected:
public:
CScreen(C128x64_OLED& disp, CScreenManager& mgr);
virtual ~CScreen();
virtual void onSelect();
virtual bool animate();
virtual void show();
virtual void keyHandler(uint8_t event) {};

View file

@ -42,9 +42,13 @@ CScreen7::CScreen7(C128x64_OLED& display, CScreenManager& mgr, int instance) : C
_rowSel = 0;
_colSel = 0;
_instance = instance;
NVstore.getTimerInfo(_instance, _timer);
}
void
CScreen7::onSelect()
{
NVstore.getTimerInfo(_instance, _timer);
}
void
CScreen7::show()

View file

@ -37,6 +37,7 @@ class CScreen7 : public CScreenHeader {
public:
CScreen7(C128x64_OLED& display, CScreenManager& mgr, int instance);
void onSelect();
void show();
void keyHandler(uint8_t event);
};

View file

@ -193,6 +193,9 @@ CScreenManager::refresh()
void
CScreenManager::_switchScreen()
{
if(_currentScreen >= 0)
_Screens[_currentScreen]->onSelect();
reqUpdate();
}