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); bool validateFrame(const CProtocol& frame, const char* name);
void checkDisplayUpdate(); void checkDisplayUpdate();
void checkTimer(); void checkTimer();
void checkTimer(const DateTime& now, sTimer timerInfo); void checkTimer(int timer, const DateTime& now);
void checkDebugCommands(); void checkDebugCommands();
// DS18B20 temperature sensor support // DS18B20 temperature sensor support
@ -950,32 +950,44 @@ void checkTimer()
{ {
const DateTime& now = getCurrentTime(); const DateTime& now = getCurrentTime();
sTimer timerInfo; checkTimer(0, now); // test timer 1
// test timer 1 checkTimer(1, now); // test timer 2
NVstore.getTimerInfo(0, timerInfo);
checkTimer(now, timerInfo);
// test timer 2
NVstore.getTimerInfo(1, timerInfo);
checkTimer(now, timerInfo);
} }
void checkTimer(const DateTime& now, sTimer timerInfo) void checkTimer(int timer, const DateTime& now)
{ {
int maskDOW = 0x01 << now.dayOfTheWeek(); sTimer Info;
if(timerInfo.enabled & (maskDOW | 0x80) ) { // specific day, or next day NVstore.getTimerInfo(timer, Info);
// check start int DOW = now.dayOfTheWeek();
if(now.hour() == timerInfo.start.hour && now.minute() == timerInfo.start.min) { 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(); requestOn();
} }
// check stop
if(now.hour() == timerInfo.stop.hour && now.minute() == timerInfo.stop.min) { if(timeNow == timeStop) { // check stop
requestOff(); requestOff();
if(!timerInfo.repeat) { // cancel timer if non repeating if(!Info.repeat) { // cancel timer if non repeating
if(timerInfo.enabled & 0x80) // next day start flag? if(Info.enabled & 0x80) // next day start flag set?
timerInfo.enabled = 0; // outright cancel Info.enabled = 0; // outright cancel
else else {
timerInfo.enabled &= ~maskDOW; // otherwise clear particular day Info.enabled &= ~maskDOW; // otherwise clear specific day
NVstore.setTimerInfo(0, timerInfo); }
NVstore.setTimerInfo(timer, Info);
NVstore.save(); NVstore.save();
} }
} }

View file

@ -29,6 +29,11 @@ CScreen::show()
{ {
} }
void
CScreen::onSelect()
{
}
void void
CScreen::_printMenuText(int x, int y, const char* str, bool selected, eJUSTIFY justify, int border, int radius) 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: public:
CScreen(C128x64_OLED& disp, CScreenManager& mgr); CScreen(C128x64_OLED& disp, CScreenManager& mgr);
virtual ~CScreen(); virtual ~CScreen();
virtual void onSelect();
virtual bool animate(); virtual bool animate();
virtual void show(); virtual void show();
virtual void keyHandler(uint8_t event) {}; virtual void keyHandler(uint8_t event) {};

View file

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

View file

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

View file

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