Encapsulated RTC and timer functionality inside CClock class.
This commit is contained in:
parent
2a7e3fce1b
commit
90569c319c
4 changed files with 12 additions and 89 deletions
|
@ -102,10 +102,8 @@
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include "keypad.h"
|
#include "keypad.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include <time.h>
|
|
||||||
#include "RTClib.h"
|
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
#include "BTCDateTime.h"
|
#include "Clock.h"
|
||||||
|
|
||||||
#define FAILEDSSID "BTCESP32"
|
#define FAILEDSSID "BTCESP32"
|
||||||
#define FAILEDPASSWORD "thereisnospoon"
|
#define FAILEDPASSWORD "thereisnospoon"
|
||||||
|
@ -140,7 +138,6 @@ static HardwareSerial& BlueWireSerial(Serial1);
|
||||||
void initBlueWireSerial();
|
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 checkDebugCommands();
|
void checkDebugCommands();
|
||||||
|
|
||||||
// DS18B20 temperature sensor support
|
// DS18B20 temperature sensor support
|
||||||
|
@ -151,7 +148,6 @@ float fFilteredTemperature = -100; // -100: force direct update uopn first pas
|
||||||
const float fAlpha = 0.95; // exponential mean alpha
|
const float fAlpha = 0.95; // exponential mean alpha
|
||||||
|
|
||||||
unsigned long lastAnimationTime; // used to sequence updates to LCD for animation
|
unsigned long lastAnimationTime; // used to sequence updates to LCD for animation
|
||||||
unsigned long nextRTCfetch;
|
|
||||||
|
|
||||||
CommStates CommState;
|
CommStates CommState;
|
||||||
CTxManage TxManage(TxEnbPin, BlueWireSerial);
|
CTxManage TxManage(TxEnbPin, BlueWireSerial);
|
||||||
|
@ -163,15 +159,13 @@ CSmartError SmartError;
|
||||||
CKeyPad KeyPad;
|
CKeyPad KeyPad;
|
||||||
CScreenManager ScreenManager;
|
CScreenManager ScreenManager;
|
||||||
RTC_DS3231 rtc;
|
RTC_DS3231 rtc;
|
||||||
|
CClock Clock(rtc);
|
||||||
|
|
||||||
sRxLine PCline;
|
sRxLine PCline;
|
||||||
long lastRxTime; // used to observe inter character delays
|
long lastRxTime; // used to observe inter character delays
|
||||||
bool hasOEMController = false;
|
bool hasOEMController = false;
|
||||||
|
|
||||||
//const CProtocol* pRxFrame = NULL;
|
|
||||||
//const CProtocol* pTxFrame = NULL;
|
|
||||||
CProtocolPackage HeaterData;
|
CProtocolPackage HeaterData;
|
||||||
BTCDateTime currentTime;
|
|
||||||
|
|
||||||
unsigned long moderator;
|
unsigned long moderator;
|
||||||
bool bUpdateDisplay = false;
|
bool bUpdateDisplay = false;
|
||||||
|
@ -253,7 +247,7 @@ void setup() {
|
||||||
KeyPad.setCallback(parentKeyHandler);
|
KeyPad.setCallback(parentKeyHandler);
|
||||||
|
|
||||||
// Initialize the rtc object
|
// Initialize the rtc object
|
||||||
rtc.begin();
|
Clock.begin();
|
||||||
|
|
||||||
// initialise DS18B20 temperature sensor(s)
|
// initialise DS18B20 temperature sensor(s)
|
||||||
TempSensor.begin();
|
TempSensor.begin();
|
||||||
|
@ -261,7 +255,6 @@ void setup() {
|
||||||
TempSensor.requestTemperatures();
|
TempSensor.requestTemperatures();
|
||||||
lastTemperatureTime = millis();
|
lastTemperatureTime = millis();
|
||||||
lastAnimationTime = millis();
|
lastAnimationTime = millis();
|
||||||
nextRTCfetch = millis();
|
|
||||||
|
|
||||||
ScreenManager.init();
|
ScreenManager.init();
|
||||||
|
|
||||||
|
@ -424,13 +417,13 @@ void loop()
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Clock.update();
|
||||||
checkDisplayUpdate();
|
checkDisplayUpdate();
|
||||||
checkRTC();
|
|
||||||
break; // only break if we fail all Idle state tests
|
break; // only break if we fail all Idle state tests
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Clock.update();
|
||||||
checkDisplayUpdate();
|
checkDisplayUpdate();
|
||||||
checkRTC();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -946,69 +939,3 @@ void checkDebugCommands()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkTimer()
|
|
||||||
{
|
|
||||||
const DateTime& now = getCurrentTime();
|
|
||||||
|
|
||||||
checkTimer(0, now); // test timer 1
|
|
||||||
checkTimer(1, now); // test timer 2
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkTimer(int timer, const DateTime& now)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(timeNow == timeStop) { // check stop
|
|
||||||
requestOff();
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkRTC()
|
|
||||||
{
|
|
||||||
long deltaT = millis() - nextRTCfetch;
|
|
||||||
if(deltaT >= 0) {
|
|
||||||
uint32_t origClock = Wire.getClock();
|
|
||||||
Wire.setClock(400000);
|
|
||||||
currentTime = rtc.now(); // moderate I2C accesses
|
|
||||||
Wire.setClock(origClock);
|
|
||||||
nextRTCfetch = millis() + 500;
|
|
||||||
checkTimer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const BTCDateTime& getCurrentTime()
|
|
||||||
{
|
|
||||||
return currentTime;
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
//
|
//
|
||||||
// CScreen5
|
// CScreen5
|
||||||
//
|
//
|
||||||
// This screen allows the fuel mixture endpoints to be adjusted
|
// This screen allows the real time clock to be adjusted
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -32,9 +32,8 @@
|
||||||
#include "KeyPad.h"
|
#include "KeyPad.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "Screen6.h"
|
#include "Screen6.h"
|
||||||
#include "RTClib.h"
|
|
||||||
#include "Arial.h"
|
#include "Arial.h"
|
||||||
#include "BTCDateTime.h"
|
#include "Clock.h"
|
||||||
|
|
||||||
extern RTC_DS3231 rtc;
|
extern RTC_DS3231 rtc;
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ CScreen6::show()
|
||||||
|
|
||||||
_printInverted(0, 16, " Clock ", true);
|
_printInverted(0, 16, " Clock ", true);
|
||||||
|
|
||||||
const BTCDateTime& now = getCurrentTime();
|
const BTCDateTime& now = Clock.get();
|
||||||
switch(_rowSel) {
|
switch(_rowSel) {
|
||||||
case 0:
|
case 0:
|
||||||
// update printable values
|
// update printable values
|
||||||
|
@ -130,7 +129,7 @@ CScreen6::keyHandler(uint8_t event)
|
||||||
case 1:
|
case 1:
|
||||||
_rowSel = 0;
|
_rowSel = 0;
|
||||||
if(_colSel == 6) { // set the RTC!
|
if(_colSel == 6) { // set the RTC!
|
||||||
rtc.adjust(working);
|
Clock.set(working);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,8 @@
|
||||||
#include "MiniFont.h"
|
#include "MiniFont.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "NVStorage.h"
|
#include "NVStorage.h"
|
||||||
#include "RTClib.h"
|
#include "Clock.h"
|
||||||
#include "Arial.h"
|
#include "Arial.h"
|
||||||
#include "BTCDateTime.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define MINIFONT miniFontInfo
|
#define MINIFONT miniFontInfo
|
||||||
|
@ -192,7 +191,7 @@ CScreenHeader::showTimers()
|
||||||
void
|
void
|
||||||
CScreenHeader::showTime(int numTimers)
|
CScreenHeader::showTime(int numTimers)
|
||||||
{
|
{
|
||||||
const BTCDateTime& now = getCurrentTime();
|
const BTCDateTime& now = Clock.get();
|
||||||
|
|
||||||
char msg[16];
|
char msg[16];
|
||||||
if(now.second() & 0x01)
|
if(now.second() & 0x01)
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CProtocolPackage;
|
class CProtocolPackage;
|
||||||
class BTCDateTime;
|
|
||||||
|
|
||||||
|
|
||||||
extern void ToggleOnOff();
|
extern void ToggleOnOff();
|
||||||
|
@ -38,7 +37,6 @@ extern void setFanMin(short);
|
||||||
extern void setFanMax(short);
|
extern void setFanMax(short);
|
||||||
extern void saveNV();
|
extern void saveNV();
|
||||||
extern const CProtocolPackage& getHeaterInfo();
|
extern const CProtocolPackage& getHeaterInfo();
|
||||||
extern const BTCDateTime& getCurrentTime();
|
|
||||||
|
|
||||||
#define LOWERLIMIT(A, B) if(A < B) A = B
|
#define LOWERLIMIT(A, B) if(A < B) A = B
|
||||||
#define UPPERLIMIT(A, B) if(A > B) A = B
|
#define UPPERLIMIT(A, B) if(A > B) A = B
|
||||||
|
|
Loading…
Reference in a new issue