mirror of https://github.com/sqfmi/Watchy.git
Setup AbstractRTC, cleanup init(), and add some declarations
parent
715bbaf85d
commit
bac7b4eb51
|
@ -46,12 +46,14 @@ void Watchy::init(String datetime){
|
|||
}
|
||||
|
||||
void Watchy::displayBusyCallback(const void*){
|
||||
gpio_wakeup_enable((gpio_num_t)BUSY, GPIO_INTR_LOW_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup();
|
||||
esp_light_sleep_start();
|
||||
gpio_wakeup_enable((gpio_num_t)BUSY, GPIO_INTR_LOW_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup();
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
|
||||
void Watchy::deepSleep(){
|
||||
display.hibernate();
|
||||
displayFullInit = false; // Notify not to init it again
|
||||
RTC.clearAlarm(); //resets the alarm flag in the RTC
|
||||
// Set pins 0-39 to input to avoid power leaking out
|
||||
for(int i=0; i<40; i++) {
|
||||
|
@ -588,7 +590,7 @@ weatherData Watchy::getWeatherData(){
|
|||
}
|
||||
|
||||
float Watchy::getBatteryVoltage(){
|
||||
if(RTC.rtcType == DS3231){
|
||||
if(RTC.rtcType == DS3232_RTC_TYPE){
|
||||
return analogReadMilliVolts(V10_ADC_PIN) / 1000.0f * 2.0f; // Battery voltage goes through a 1/2 divider.
|
||||
}else{
|
||||
return analogReadMilliVolts(V15_ADC_PIN) / 1000.0f * 2.0f;
|
||||
|
|
|
@ -7,29 +7,34 @@ void WatchyRTC::init(){
|
|||
byte error;
|
||||
Wire.beginTransmission(RTC_DS_ADDR);
|
||||
error = Wire.endTransmission();
|
||||
if(error == 0){
|
||||
rtcType = DS3231_RTC_TYPE;
|
||||
}else{
|
||||
Wire.beginTransmission(RTC_PCF_ADDR);
|
||||
error = Wire.endTransmission();
|
||||
if(error == 0){
|
||||
rtcType = PCF8563_RTC_TYPE;
|
||||
}else{
|
||||
//RTC Error
|
||||
}
|
||||
if (error == 0) {
|
||||
rtcType = DS3232_RTC_TYPE;
|
||||
_rtc = DS3232();
|
||||
return;
|
||||
}
|
||||
|
||||
Wire.beginTransmission(RTC_PCF_ADDR);
|
||||
error = Wire.endTransmission();
|
||||
if (error == 0) {
|
||||
rtcType = PCF8563_RTC_TYPE;
|
||||
_rtc = PCF8563();
|
||||
return;
|
||||
}
|
||||
|
||||
rtcType = NO_RTC_TYPE;
|
||||
_rtc = AbstractRTC();
|
||||
}
|
||||
|
||||
void WatchyRTC::config(String datetime){
|
||||
if(rtcType == DS3231_RTC_TYPE){
|
||||
if (rtcType == DS3232_RTC_TYPE) {
|
||||
_DSConfig(datetime);
|
||||
}else{
|
||||
} else {
|
||||
_PCFConfig(datetime);
|
||||
}
|
||||
}
|
||||
|
||||
void WatchyRTC::clearAlarm(){
|
||||
if(rtcType == DS3231_RTC_TYPE){
|
||||
if(rtcType == DS3232_RTC_TYPE){
|
||||
rtc_ds.alarm(ALARM_2);
|
||||
}else{
|
||||
int nextAlarmMinute = 0;
|
||||
|
@ -41,7 +46,7 @@ void WatchyRTC::clearAlarm(){
|
|||
}
|
||||
|
||||
void WatchyRTC::read(tmElements_t &tm){
|
||||
if(rtcType == DS3231_RTC_TYPE){
|
||||
if(rtcType == DS3232_RTC_TYPE){
|
||||
rtc_ds.read(tm);
|
||||
tm.Year = tm.Year - 30; //reset to offset from 2000
|
||||
}else{
|
||||
|
@ -61,7 +66,7 @@ void WatchyRTC::read(tmElements_t &tm){
|
|||
}
|
||||
|
||||
void WatchyRTC::set(tmElements_t tm){
|
||||
if(rtcType == DS3231_RTC_TYPE){
|
||||
if(rtcType == DS3232_RTC_TYPE){
|
||||
tm.Year = tm.Year + 2000 - YEAR_OFFSET_DS;
|
||||
time_t t = makeTime(tm);
|
||||
rtc_ds.set(t);
|
||||
|
@ -73,7 +78,7 @@ void WatchyRTC::set(tmElements_t tm){
|
|||
}
|
||||
|
||||
uint8_t WatchyRTC::temperature(){
|
||||
if(rtcType == DS3231_RTC_TYPE){
|
||||
if(rtcType == DS3232_RTC_TYPE){
|
||||
return rtc_ds.temperature();
|
||||
}else{
|
||||
return 255; //error
|
||||
|
|
|
@ -4,13 +4,17 @@
|
|||
#include <DS3232RTC.h>
|
||||
#include <Rtc_Pcf8563.h>
|
||||
|
||||
#define DS3231_RTC_TYPE 0
|
||||
#define DS3232_RTC_TYPE 0
|
||||
#define PCF8563_RTC_TYPE 1
|
||||
#define NO_RTC_TYPE 255
|
||||
|
||||
#define RTC_DS_ADDR 0x68
|
||||
#define RTC_PCF_ADDR 0x51
|
||||
#define YEAR_OFFSET_DS 1970
|
||||
#define YEAR_OFFSET_PCF 2000
|
||||
|
||||
#define NO_TEMPERATURE_ERR 255
|
||||
|
||||
// TODO: So we're relying on an rtcType as a multiplexer, making our WatchyRTC code a bit
|
||||
// more complex. A way around this is to use a command pattern instead:
|
||||
// https://sourcemaking.com/design_patterns/command
|
||||
|
@ -41,10 +45,9 @@ class WatchyRTC {
|
|||
void set(tmElements_t tm);
|
||||
uint8_t temperature();
|
||||
private:
|
||||
void _DSConfig(String datetime);
|
||||
void _PCFConfig(String datetime);
|
||||
int _getDayOfWeek(int d, int m, int y);
|
||||
String _getValue(String data, char separator, int index);
|
||||
AbstractRTC _rtc;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue