Support for DS3231, DS1307, PCF8523 or millis() based RTCs - Use BTCConfig.h to select

This commit is contained in:
rljonesau 2018-12-09 12:10:56 +11:00
parent 55c33af996
commit 85ff28d347
10 changed files with 90 additions and 44 deletions

View file

@ -75,7 +75,20 @@
// DS18B20 temperature sensing
//
#define TEMPERATURE_INTERVAL 1000
///////////////////////////////////////////////////////////////////////////////
// Real Time Clock support
//
// only select one option to use the indicated hardware
// if none are selected, RTC_Millis will be used, which is volatile (based upon millis())
//
#define RTC_USE_DS3231 1
#define RTC_USE_DS1307 0
#define RTC_USE_PCF8523 0
///////////////////////////////////////////////////////////////////////////////
// Blue wire handling
//
#define SUPPORT_OEM_CONTROLLER 1

View file

@ -112,7 +112,7 @@ BTCDateTime::adjustSecond(int dir)
}
int
BTCDateTime::daysInMonth(int month, int year)
BTCDateTime::daysInMonth(int month, int year) const
{
if(month >= 1 && month <= 12) {
int days = monthDays[month-1];

View file

@ -10,8 +10,7 @@ class BTCDateTime : public DateTime {
public:
const char* monthStr() const;
const char* dowStr() const;
const char* briefDowStr() const;
int daysInMonth(int month, int year);
int daysInMonth(int month, int year) const;
void adjustDay(int val);
void adjustMonth(int val);
void adjustYear(int dir);

View file

@ -158,8 +158,6 @@ CProtocol DefaultBTCParams(CProtocol::CtrlMode); // defines the default paramet
CSmartError SmartError;
CKeyPad KeyPad;
CScreenManager ScreenManager;
RTC_DS3231 rtc;
CClock Clock(rtc);
sRxLine PCline;
long lastRxTime; // used to observe inter character delays

View file

@ -5,15 +5,45 @@
#include "RTClib.h"
#include "helpers.h"
#include "NVStorage.h"
#include "DebugPort.h"
// create ONE of the RTClib supported real time clock classes
#if RTC_USE_DS3231 == 1
RTC_DS3231 rtc;
#elif RTC_USE_DS1307 == 1
RTC_DS1307 rtc;
#elif RTC_USE_PCF8523 == 1
RTC_PCF8523 rtc;
#else
RTC_Millis rtc;
#endif
CClock Clock(rtc);
CClock::CClock(RTC_DS3231& rtc) : _rtc(rtc)
{
}
void
CClock::begin()
{
// announce which sort of RTC is being used
#if RTC_USE_DS3231 == 1
DebugPort.println("Using DS3231 Real Time Clock");
#elif RTC_USE_DS1307 == 1
DebugPort.println("Using DS1307 Real Time Clock");
#elif RTC_USE_PCF8523 == 1
DebugPort.println("Using PCF8523 Real Time Clock");
#else
#define SW_RTC // enable different begin() call for the millis() based RTC
DebugPort.println("Using millis() based psuedo \"Real Time Clock\"");
#endif
#ifdef SW_RTC
DateTime zero(2019, 1, 1); // can be pushed along as seen fit!
_rtc.begin(zero);
#else
_rtc.begin();
#endif
_nextRTCfetch = millis();
}

View file

@ -2,23 +2,37 @@
#define __BTC_TIMERS_H__
#include "BTCDateTime.h"
#include "BTCConfig.h"
/*const BTCDateTime& getCurrentTime();
void setCurrentTime(const DateTime& newDateTime);
void initClock();
void checkClock();*/
class CClock {
// allow use of ONE of the RTClib supported RTC chips
// reference to the selected rtc stored here
#if RTC_USE_DS3231 == 1
RTC_DS3231& _rtc;
#elif RTC_USE_DS1307 == 1
RTC_DS1307& _rtc;
#elif RTC_USE_PCF8523 == 1
RTC_PCF8523& _rtc;
#else
RTC_Millis& _rtc;
#endif
unsigned long _nextRTCfetch;
BTCDateTime _currentTime;
void _checkTimers();
void _checkTimer(int timer, const DateTime& now);
public:
CClock(RTC_DS3231& rtc);
// constructors for ONE of the RTClib supported RTC chips
#if RTC_USE_DS3231 == 1
CClock(RTC_DS3231& rtc) : _rtc(rtc) {};
#elif RTC_USE_DS1307 == 1
CClock(RTC_1307& rtc) : _rtc(rtc) {};
#elif RTC_USE_PCF8523 == 1
CClock(RTC_PCF8523& rtc) : _rtc(rtc) {};
#else
CClock(RTC_Millis& rtc) : _rtc(rtc) {};
#endif
void begin();
const BTCDateTime& update();
const BTCDateTime& get() const;

View file

@ -35,8 +35,6 @@
#include "Arial.h"
#include "Clock.h"
extern RTC_DS3231 rtc;
CScreen6::CScreen6(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
{

View file

@ -31,6 +31,7 @@ CScreenHeader::CScreenHeader(C128x64_OLED& disp, CScreenManager& mgr) : CScreen(
{
_clearUpAnimation = false;
_clearDnAnimation = false;
_colon = false;
}
void
@ -194,10 +195,12 @@ CScreenHeader::showTime(int numTimers)
const BTCDateTime& now = Clock.get();
char msg[16];
if(now.second() & 0x01)
if(_colon)
sprintf(msg, "%02d:%02d", now.hour(), now.minute());
else
sprintf(msg, "%02d %02d", now.hour(), now.minute());
_colon = !_colon;
{
CTransientFont AF(_display, &arial_8ptFontInfo);
// determine centre position of remaining real estate

View file

@ -31,6 +31,7 @@
class CScreenHeader : public CScreen {
bool _clearUpAnimation;
bool _clearDnAnimation;
bool _colon;
protected:
void showBTicon();
void showWifiIcon();

View file

@ -1,9 +1,7 @@
#include "ScreenManager.h"
#include <SPI.h>
#include <Wire.h>
#include "128x64OLED.h"
#include "pins.h"
#include "BluetoothAbstract.h"
#include "Screen1.h"
#include "Screen2.h"
#include "Screen3.h"
@ -12,21 +10,8 @@
#include "Screen6.h"
#include "Screen7.h"
#include "Screen8.h"
#include "BTCConfig.h"
//
// **** NOTE: If trying use hardware SPI on the ESP32 there are two very lame
// **** libaries conspiring to make life difficult
//
// A/ The ESP32 SPI.cpp library instatiates an instance of SPI, using the VSPI port (and pins)
// B/ The Adfruit_SH1106 library hard codes "SPI" as the SPI port instance
//
// As an ESP32 has a pin multiplexer, this is very bad form.
// The actual design here uses the defacto HSPI pins (and port),
// You **MUST comment out the SPIClass SPI(VSPI);** at the end of the ESP32 SPI library
// then we declare "SPI" here, which will use HSPI!!!!
// 128 x 64 OLED support
//SPIClass SPI; // default constructor opens HSPI on standard pins : MOSI=13,CLK=14,MISO=12(unused)
////////////////////////////////////////////////////////////////////////////////////////////////
// splash creen created using image2cpp http://javl.github.io/image2cpp/
@ -144,16 +129,21 @@ CScreenManager::init()
_pDisplay->display();
DebugPort.println("Creating Screens");
_Screens.push_back(new CScreen1(*_pDisplay, *this)); // detail control
_Screens.push_back(new CScreen2(*_pDisplay, *this)); // basic control
_Screens.push_back(new CScreen8(*_pDisplay, *this)); // clock
_Screens.push_back(new CScreen3(*_pDisplay, *this)); // mode / priming
_Screens.push_back(new CScreen4(*_pDisplay, *this)); // comms info
_Screens.push_back(new CScreen5(*_pDisplay, *this)); // tuning
_Screens.push_back(new CScreen6(*_pDisplay, *this)); // clock set
_Screens.push_back(new CScreen7(*_pDisplay, *this, 0)); // timer 1
_Screens.push_back(new CScreen7(*_pDisplay, *this, 1)); // timer 2
_currentScreen = 1;
_Screens.push_back(new CScreen1(*_pDisplay, *this)); // 0: detail control
_Screens.push_back(new CScreen2(*_pDisplay, *this)); // 1: basic control
_Screens.push_back(new CScreen8(*_pDisplay, *this)); // 2: clock
_Screens.push_back(new CScreen3(*_pDisplay, *this)); // 3: mode / priming
_Screens.push_back(new CScreen4(*_pDisplay, *this)); // 4: comms info
_Screens.push_back(new CScreen5(*_pDisplay, *this)); // 5: tuning
_Screens.push_back(new CScreen6(*_pDisplay, *this)); // 6: clock set
_Screens.push_back(new CScreen7(*_pDisplay, *this, 0)); // 7: set timer 1
_Screens.push_back(new CScreen7(*_pDisplay, *this, 1)); // 8: set timer 2
#if RTC_USE_DS3231==0 && RTC_USE_DS1307==0 && RTC_USE_PCF8523==0
_currentScreen = 6; // bring up clock set screen first if using millis based RTC!
#else
_currentScreen = 1; // basic control screen
#endif
_switchScreen();
}