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__
|
|
|
|
|
2019-03-03 08:48:52 +00:00
|
|
|
#include "../RTC/Timers.h" // for sTimer
|
|
|
|
|
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;
|
2019-01-11 05:40:25 +00:00
|
|
|
uint8_t sysVoltage;
|
|
|
|
uint8_t fanSensor;
|
2019-01-19 11:05:14 +00:00
|
|
|
uint8_t glowDrive;
|
2019-01-11 23:33:45 +00:00
|
|
|
|
|
|
|
bool valid() {
|
|
|
|
bool retval = true;
|
|
|
|
retval &= Pmin < 100;
|
|
|
|
retval &= Pmax < 150;
|
|
|
|
retval &= Fmin < 5000;
|
|
|
|
retval &= Fmax < 6000;
|
|
|
|
retval &= ThermostatMode < 2;
|
|
|
|
retval &= setTemperature < 40;
|
|
|
|
retval &= sysVoltage == 120 || sysVoltage == 240;
|
|
|
|
retval &= fanSensor == 1 || fanSensor == 2;
|
2019-01-19 11:05:14 +00:00
|
|
|
retval &= glowDrive >= 1 && glowDrive <= 6;
|
2019-01-11 23:33:45 +00:00
|
|
|
return retval;
|
|
|
|
};
|
|
|
|
void init() {
|
|
|
|
Pmin = 14;
|
|
|
|
Pmax = 45;
|
|
|
|
Fmin = 1500;
|
|
|
|
Fmax = 4500;
|
|
|
|
ThermostatMode = 1;
|
|
|
|
setTemperature = 23;
|
|
|
|
sysVoltage = 120;
|
|
|
|
fanSensor = 1;
|
2019-01-19 11:05:14 +00:00
|
|
|
glowDrive = 5;
|
2019-01-11 23:33:45 +00:00
|
|
|
};
|
2018-12-07 04:18:24 +00:00
|
|
|
};
|
|
|
|
|
2019-03-24 05:48:03 +00:00
|
|
|
struct sBTCoptions {
|
|
|
|
long DimTime;
|
|
|
|
uint8_t degF;
|
|
|
|
uint8_t ThermostatMethod; // 0: standard heater, 1: Narrow Hysterisis, 2:Managed Hz mode
|
|
|
|
uint8_t enableWifi;
|
|
|
|
uint8_t enableOTA;
|
2019-04-04 10:48:05 +00:00
|
|
|
uint8_t cyclicMode;
|
2019-03-24 05:48:03 +00:00
|
|
|
bool valid() {
|
|
|
|
bool retval = true;
|
|
|
|
retval &= (DimTime >= 0) && (DimTime < 300000); // 5 mins
|
|
|
|
retval &= (degF == 0) || (degF == 1);
|
|
|
|
retval &= (ThermostatMethod & 0x03) < 3; // only modes 0, 1 or 2
|
|
|
|
retval &= (enableWifi == 0) || (enableWifi == 1);
|
|
|
|
retval &= (enableOTA == 0) || (enableOTA == 1);
|
2019-04-04 10:48:05 +00:00
|
|
|
retval &= cyclicMode < 10;
|
2019-03-24 05:48:03 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
void init() {
|
|
|
|
DimTime = 60000;
|
|
|
|
degF = 0;
|
|
|
|
ThermostatMethod = 0;
|
|
|
|
enableWifi = 1;
|
|
|
|
enableOTA = 1;
|
2019-04-04 10:48:05 +00:00
|
|
|
cyclicMode = 0;
|
2019-03-24 05:48:03 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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;
|
2019-03-24 05:48:03 +00:00
|
|
|
sBTCoptions Options;
|
2019-02-14 10:20:15 +00:00
|
|
|
sTimer timer[14];
|
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();
|
2018-12-15 09:34:58 +00:00
|
|
|
unsigned char getDesiredTemperature();
|
2018-10-20 07:11:23 +00:00
|
|
|
unsigned char getThermostatMode();
|
2019-03-14 10:52:59 +00:00
|
|
|
unsigned char getThermostatMethodMode();
|
2019-03-15 07:19:30 +00:00
|
|
|
float getThermostatMethodWindow();
|
2019-01-11 05:40:25 +00:00
|
|
|
unsigned char getSysVoltage();
|
|
|
|
unsigned char getFanSensor();
|
2019-01-19 11:05:14 +00:00
|
|
|
unsigned char getGlowDrive();
|
2018-12-22 10:32:13 +00:00
|
|
|
unsigned long getDimTime();
|
2019-02-06 20:24:22 +00:00
|
|
|
unsigned char getDegFMode();
|
2019-03-24 05:48:03 +00:00
|
|
|
unsigned char getWifiEnabled();
|
|
|
|
unsigned char getOTAEnabled();
|
2019-04-04 10:48:05 +00:00
|
|
|
unsigned char getCyclicMode();
|
2018-10-20 07:11:23 +00:00
|
|
|
|
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);
|
2018-12-15 09:34:58 +00:00
|
|
|
void setDesiredTemperature(unsigned char val);
|
2018-10-20 07:11:23 +00:00
|
|
|
void setThermostatMode(unsigned char val);
|
2019-03-14 10:52:59 +00:00
|
|
|
void setThermostatMethodMode(unsigned char val);
|
2019-03-15 07:19:30 +00:00
|
|
|
void setThermostatMethodWindow(float val);
|
2019-01-11 05:40:25 +00:00
|
|
|
void setSystemVoltage(float fVal);
|
|
|
|
void setFanSensor(unsigned char val);
|
2019-01-19 11:05:14 +00:00
|
|
|
void setGlowDrive(unsigned char val);
|
2018-12-22 10:32:13 +00:00
|
|
|
void setDimTime(unsigned long val);
|
2019-02-06 20:24:22 +00:00
|
|
|
void setDegFMode(unsigned char val);
|
2019-03-24 05:48:03 +00:00
|
|
|
void setWifiEnabled(unsigned char val);
|
|
|
|
void setOTAEnabled(unsigned char val);
|
2019-04-04 10:48:05 +00:00
|
|
|
void setCyclicMode(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>
|
2019-01-12 01:19:55 +00:00
|
|
|
#include <functional>
|
2018-10-20 07:11:23 +00:00
|
|
|
|
|
|
|
class CESP32HeaterStorage : public CHeaterStorage {
|
|
|
|
Preferences preferences;
|
|
|
|
public:
|
|
|
|
CESP32HeaterStorage();
|
|
|
|
virtual ~CESP32HeaterStorage();
|
|
|
|
void init();
|
|
|
|
void load();
|
|
|
|
void save();
|
2019-01-11 23:33:45 +00:00
|
|
|
void loadHeater();
|
|
|
|
void saveHeater();
|
2019-01-12 01:57:32 +00:00
|
|
|
void loadTimer(int idx);
|
|
|
|
void saveTimer(int idx);
|
2019-01-11 23:33:45 +00:00
|
|
|
void loadUI();
|
|
|
|
void saveUI();
|
2019-01-18 20:15:02 +00:00
|
|
|
bool validatedLoad(const char* key, int8_t& val, int defVal, std::function<bool(int8_t, int8_t, int8_t)> validator, int min, int max);
|
2019-03-14 10:52:59 +00:00
|
|
|
bool validatedLoad(const char* key, uint8_t& val, int defVal, std::function<bool(uint8_t, uint8_t, uint8_t)> validator, int min, int max, uint8_t mask=0xff);
|
2019-01-12 01:19:55 +00:00
|
|
|
bool validatedLoad(const char* key, uint16_t& val, int defVal, std::function<bool(uint16_t, uint16_t, uint16_t)> validator, int min, int max);
|
|
|
|
bool validatedLoad(const char* key, long& val, long defVal, std::function<bool(long, long, long)> validator, long min, long max);
|
2018-10-20 07:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#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
|
|
|
|