2018-12-16 03:27:08 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-03-03 08:48:52 +00:00
|
|
|
#ifndef __BTC_CLOCK_H__
|
|
|
|
#define __BTC_CLOCK_H__
|
2018-12-08 22:55:55 +00:00
|
|
|
|
2019-07-18 12:28:40 +00:00
|
|
|
#include "../Libraries/RTClib/RTClib.h"
|
2018-12-08 22:55:55 +00:00
|
|
|
#include "BTCDateTime.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "../cfg/BTCConfig.h"
|
2018-12-08 22:55:55 +00:00
|
|
|
|
2019-07-18 12:28:40 +00:00
|
|
|
class RTC_DS3231Ex : public RTC_DS3231 {
|
|
|
|
public:
|
|
|
|
void writeData(uint8_t* pData, int len, int ofs=0);
|
|
|
|
void readData(uint8_t* pData, int len, int ofs=0);
|
|
|
|
};
|
|
|
|
|
2018-12-08 22:55:55 +00:00
|
|
|
|
|
|
|
class CClock {
|
2018-12-09 01:10:56 +00:00
|
|
|
// allow use of ONE of the RTClib supported RTC chips
|
|
|
|
// reference to the selected rtc stored here
|
|
|
|
#if RTC_USE_DS3231 == 1
|
2019-07-18 12:28:40 +00:00
|
|
|
// RTC_DS3231& _rtc;
|
|
|
|
RTC_DS3231Ex& _rtc;
|
2018-12-09 01:10:56 +00:00
|
|
|
#elif RTC_USE_DS1307 == 1
|
|
|
|
RTC_DS1307& _rtc;
|
|
|
|
#elif RTC_USE_PCF8523 == 1
|
|
|
|
RTC_PCF8523& _rtc;
|
|
|
|
#else
|
|
|
|
RTC_Millis& _rtc;
|
|
|
|
#endif
|
2018-12-08 22:55:55 +00:00
|
|
|
unsigned long _nextRTCfetch;
|
|
|
|
BTCDateTime _currentTime;
|
2019-02-20 10:50:28 +00:00
|
|
|
int _prevMinute;
|
2018-12-08 22:55:55 +00:00
|
|
|
|
|
|
|
public:
|
2018-12-09 01:10:56 +00:00
|
|
|
// constructors for ONE of the RTClib supported RTC chips
|
|
|
|
#if RTC_USE_DS3231 == 1
|
2019-07-18 12:28:40 +00:00
|
|
|
// CClock(RTC_DS3231& rtc) : _rtc(rtc) {};
|
|
|
|
CClock(RTC_DS3231Ex& rtc) : _rtc(rtc) {};
|
2018-12-09 01:10:56 +00:00
|
|
|
#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
|
2018-12-08 22:55:55 +00:00
|
|
|
void begin();
|
|
|
|
const BTCDateTime& update();
|
|
|
|
const BTCDateTime& get() const;
|
|
|
|
void set(const DateTime& newTime);
|
2019-07-18 12:28:40 +00:00
|
|
|
void saveData(uint8_t* pData, int len, int ofs);
|
|
|
|
void readData(uint8_t* pData, int len, int ofs);
|
2018-12-08 22:55:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CClock Clock;
|
|
|
|
|
|
|
|
#endif // __BTC_TIMERS_H__
|