2018-11-26 11:58:15 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-07 11:16:04 +00:00
|
|
|
#ifndef __BTC_NV_STORAGE_H__
|
|
|
|
#define __BTC_NV_STORAGE_H__
|
|
|
|
|
2018-12-07 04:18:24 +00:00
|
|
|
struct sHeater {
|
|
|
|
uint8_t Pmin;
|
|
|
|
uint8_t Pmax;
|
|
|
|
uint16_t Fmin;
|
|
|
|
uint16_t Fmax;
|
|
|
|
uint8_t ThermostatMode;
|
|
|
|
uint8_t setTemperature;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sHourMin {
|
2018-12-07 11:16:04 +00:00
|
|
|
int8_t hour;
|
|
|
|
int8_t min;
|
2018-12-07 04:18:24 +00:00
|
|
|
sHourMin() {
|
|
|
|
hour = 0;
|
|
|
|
min = 0;
|
|
|
|
};
|
2018-12-07 11:16:04 +00:00
|
|
|
sHourMin& operator=(const sHourMin& rhs) {
|
|
|
|
hour = rhs.hour;
|
|
|
|
min = rhs.min;
|
|
|
|
};
|
2018-12-07 04:18:24 +00:00
|
|
|
};
|
2018-10-20 07:11:23 +00:00
|
|
|
|
2018-12-07 04:18:24 +00:00
|
|
|
struct sTimer {
|
|
|
|
sHourMin start; // start time
|
|
|
|
sHourMin stop; // stop time
|
2018-12-07 22:30:55 +00:00
|
|
|
uint8_t enabled; // timer enabled - each bit is a day of week flag
|
2018-12-07 04:18:24 +00:00
|
|
|
uint8_t repeat; // repeating timer
|
|
|
|
sTimer() {
|
2018-12-07 22:30:55 +00:00
|
|
|
enabled = 0;
|
2018-12-07 04:18:24 +00:00
|
|
|
repeat = false;
|
|
|
|
};
|
2018-12-07 11:16:04 +00:00
|
|
|
sTimer& operator=(const sTimer& rhs) {
|
|
|
|
start = rhs.start;
|
|
|
|
stop = rhs.stop;
|
|
|
|
enabled = rhs.enabled;
|
|
|
|
repeat = rhs.repeat;
|
|
|
|
};
|
2018-12-07 04:18:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// the actual data stored to NV memory
|
2018-10-20 07:11:23 +00:00
|
|
|
struct sNVStore {
|
2018-12-07 04:18:24 +00:00
|
|
|
sHeater Heater;
|
|
|
|
sTimer timer[2];
|
2018-12-07 11:16:04 +00:00
|
|
|
bool valid();
|
|
|
|
void init();
|
2018-10-20 07:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CNVStorage {
|
|
|
|
public:
|
|
|
|
CNVStorage() {};
|
|
|
|
virtual ~CNVStorage() {};
|
|
|
|
virtual void init() = 0;
|
|
|
|
virtual void load() = 0;
|
|
|
|
virtual void save() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CHeaterStorage : public CNVStorage {
|
|
|
|
protected:
|
2018-12-07 11:16:04 +00:00
|
|
|
sNVStore _calValues;
|
2018-10-20 07:11:23 +00:00
|
|
|
public:
|
|
|
|
CHeaterStorage();
|
|
|
|
virtual ~CHeaterStorage() {};
|
|
|
|
|
|
|
|
// TODO: These are only here to allow building without fully
|
|
|
|
// fleshing out NV storage for Due, Mega etc
|
|
|
|
// these should be removed once complete (pure virtual)
|
|
|
|
void init() {};
|
|
|
|
void load() {};
|
|
|
|
void save() {};
|
|
|
|
|
|
|
|
|
2018-11-28 11:15:23 +00:00
|
|
|
float getPmin();
|
|
|
|
float getPmax();
|
2018-10-20 07:11:23 +00:00
|
|
|
unsigned short getFmin();
|
|
|
|
unsigned short getFmax();
|
|
|
|
unsigned char getTemperature();
|
|
|
|
unsigned char getThermostatMode();
|
|
|
|
|
2018-11-28 11:15:23 +00:00
|
|
|
void setPmin(float);
|
|
|
|
void setPmax(float);
|
2018-10-20 07:11:23 +00:00
|
|
|
void setFmin(unsigned short val);
|
|
|
|
void setFmax(unsigned short val);
|
|
|
|
void setTemperature(unsigned char val);
|
|
|
|
void setThermostatMode(unsigned char val);
|
2018-12-07 04:18:24 +00:00
|
|
|
|
|
|
|
void getTimerInfo(int idx, sTimer& timerInfo);
|
|
|
|
void setTimerInfo(int idx, const sTimer& timerInfo);
|
2018-10-20 07:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
|
|
|
|
#include <Preferences.h>
|
|
|
|
|
|
|
|
class CESP32HeaterStorage : public CHeaterStorage {
|
|
|
|
Preferences preferences;
|
|
|
|
public:
|
|
|
|
CESP32HeaterStorage();
|
|
|
|
virtual ~CESP32HeaterStorage();
|
|
|
|
void init();
|
|
|
|
void load();
|
|
|
|
void save();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-11-28 11:15:23 +00:00
|
|
|
extern CHeaterStorage& NVstore;
|
|
|
|
|
2018-12-07 11:16:04 +00:00
|
|
|
#endif // __BTC_NV_STORAGE_H__
|
2018-10-20 07:11:23 +00:00
|
|
|
|