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-04-09 23:28:46 +00:00
|
|
|
#include "GPIO.h"
|
2019-05-16 11:12:29 +00:00
|
|
|
#include "NVCore.h"
|
|
|
|
|
|
|
|
#include "../RTC/Timers.h" // for sTimer
|
2019-03-03 08:48:52 +00:00
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
|
|
|
|
struct sHeater : public CESP32_NVStorage {
|
2018-12-07 04:18:24 +00:00
|
|
|
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
|
|
|
};
|
2019-05-16 11:12:29 +00:00
|
|
|
void load();
|
|
|
|
void save();
|
2018-12-07 04:18:24 +00:00
|
|
|
};
|
|
|
|
|
2019-04-19 23:49:22 +00:00
|
|
|
struct sHomeMenuActions {
|
|
|
|
uint8_t onTimeout;
|
|
|
|
uint8_t onStart;
|
|
|
|
uint8_t onStop;
|
|
|
|
bool valid() {
|
|
|
|
bool retval = true;
|
|
|
|
retval &= onTimeout < 4;
|
|
|
|
retval &= onStart < 4;
|
|
|
|
retval &= onStop < 4;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
void init() {
|
|
|
|
onTimeout = 0;
|
|
|
|
onStart = 0;
|
|
|
|
onStop = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-27 10:41:47 +00:00
|
|
|
struct sCyclicThermostat {
|
|
|
|
int8_t Stop;
|
|
|
|
int8_t Start;
|
|
|
|
bool valid() {
|
|
|
|
bool retval = true;
|
|
|
|
retval &= Start >= -10 && Start <= 0;
|
|
|
|
retval &= Stop >= 0 && Stop <= 10;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
void init() {
|
|
|
|
Start = -1;
|
|
|
|
Stop = 0;
|
|
|
|
}
|
|
|
|
bool isEnabled() const {
|
|
|
|
return Stop != 0;
|
|
|
|
}
|
2019-05-11 02:18:06 +00:00
|
|
|
sCyclicThermostat& operator=(const sCyclicThermostat& rhs) {
|
|
|
|
Stop = rhs.Stop;
|
|
|
|
Start = rhs.Start;
|
|
|
|
return *this;
|
|
|
|
}
|
2019-04-27 10:41:47 +00:00
|
|
|
};
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
struct sCredentials : public CESP32_NVStorage {
|
|
|
|
char SSID[32];
|
|
|
|
char APpassword[32];
|
|
|
|
char webUpdateUsername[32];
|
|
|
|
char webUpdatePassword[32];
|
|
|
|
void init() {
|
|
|
|
strcpy(SSID, "Afterburner");
|
|
|
|
strcpy(APpassword, "thereisnospoon");
|
|
|
|
strcpy(webUpdateUsername, "Afterburner");
|
|
|
|
strcpy(webUpdatePassword, "BurnBabyBurn");
|
|
|
|
};
|
|
|
|
void load();
|
|
|
|
void save();
|
|
|
|
bool valid();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sMQTTparams : public CESP32_NVStorage {
|
2019-05-12 10:15:18 +00:00
|
|
|
uint8_t enabled;
|
|
|
|
uint16_t port;
|
|
|
|
char host[128];
|
|
|
|
char username[32];
|
|
|
|
char password[32];
|
|
|
|
void init() {
|
|
|
|
enabled = false;
|
|
|
|
port = 1234;
|
|
|
|
memset(host, 0, 128);
|
|
|
|
memset(username, 0, 32);
|
|
|
|
memset(password, 0, 32);
|
|
|
|
}
|
|
|
|
sMQTTparams& operator=(const sMQTTparams& rhs) {
|
|
|
|
enabled = rhs.enabled;
|
|
|
|
port = rhs.port;
|
|
|
|
memcpy(host, rhs.host, 128);
|
|
|
|
memcpy(username, rhs.username, 32);
|
|
|
|
memcpy(password, rhs.password, 32);
|
|
|
|
host[127] = 0;
|
|
|
|
username[31] = 0;
|
|
|
|
password[31] = 0;
|
|
|
|
}
|
2019-05-16 11:12:29 +00:00
|
|
|
void load();
|
|
|
|
void save();
|
|
|
|
bool valid();
|
2019-05-12 10:15:18 +00:00
|
|
|
};
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
struct sBTCoptions : public CESP32_NVStorage {
|
2019-04-27 10:41:47 +00:00
|
|
|
long dimTime;
|
|
|
|
long menuTimeout;
|
2019-03-24 05:48:03 +00:00
|
|
|
uint8_t degF;
|
|
|
|
uint8_t ThermostatMethod; // 0: standard heater, 1: Narrow Hysterisis, 2:Managed Hz mode
|
|
|
|
uint8_t enableWifi;
|
|
|
|
uint8_t enableOTA;
|
2019-04-09 23:28:46 +00:00
|
|
|
uint8_t GPIOinMode;
|
|
|
|
uint8_t GPIOoutMode;
|
|
|
|
uint8_t GPIOalgMode;
|
2019-04-19 11:38:39 +00:00
|
|
|
uint16_t FrameRate;
|
2019-04-27 10:41:47 +00:00
|
|
|
sCyclicThermostat cyclic;
|
2019-04-19 23:49:22 +00:00
|
|
|
sHomeMenuActions HomeMenu;
|
2019-04-09 23:28:46 +00:00
|
|
|
|
2019-03-24 05:48:03 +00:00
|
|
|
bool valid() {
|
|
|
|
bool retval = true;
|
2019-04-27 10:41:47 +00:00
|
|
|
retval &= (dimTime >= -600000) && (dimTime < 600000); // +/- 10 mins
|
|
|
|
retval &= (menuTimeout >= 0) && (menuTimeout < 300000); // 5 mins
|
2019-03-24 05:48:03 +00:00
|
|
|
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-09 23:28:46 +00:00
|
|
|
retval &= GPIOinMode < 4;
|
|
|
|
retval &= GPIOoutMode < 3;
|
2019-04-19 11:38:39 +00:00
|
|
|
retval &= (FrameRate >= 300) && (FrameRate <= 1500);
|
2019-04-27 10:41:47 +00:00
|
|
|
retval &= cyclic.valid();
|
2019-04-19 23:49:22 +00:00
|
|
|
retval &= HomeMenu.valid();
|
2019-03-24 05:48:03 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
void init() {
|
2019-04-27 10:41:47 +00:00
|
|
|
dimTime = 60000;
|
|
|
|
menuTimeout = 60000;
|
2019-03-24 05:48:03 +00:00
|
|
|
degF = 0;
|
|
|
|
ThermostatMethod = 0;
|
|
|
|
enableWifi = 1;
|
|
|
|
enableOTA = 1;
|
2019-04-09 23:28:46 +00:00
|
|
|
GPIOinMode = 0;
|
|
|
|
GPIOoutMode = 0;
|
|
|
|
GPIOalgMode = 0;
|
2019-04-19 11:38:39 +00:00
|
|
|
FrameRate = 1000;
|
2019-04-27 10:41:47 +00:00
|
|
|
cyclic.init();
|
2019-04-19 23:49:22 +00:00
|
|
|
HomeMenu.init();
|
2019-03-24 05:48:03 +00:00
|
|
|
};
|
2019-05-16 11:12:29 +00:00
|
|
|
void load();
|
|
|
|
void save();
|
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];
|
2019-05-12 10:15:18 +00:00
|
|
|
sMQTTparams MQTT;
|
2019-05-16 11:12:29 +00:00
|
|
|
sCredentials Credentials;
|
2018-12-07 11:16:04 +00:00
|
|
|
bool valid();
|
|
|
|
void init();
|
2018-10-20 07:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
class CHeaterStorage /*: public CESP32_NVStorage*/ {
|
2018-10-20 07:11:23 +00:00
|
|
|
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)
|
2019-06-01 08:03:38 +00:00
|
|
|
virtual void init() {};
|
|
|
|
virtual void load() {};
|
|
|
|
virtual void save() {};
|
2018-10-20 07:11:23 +00:00
|
|
|
|
|
|
|
|
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();
|
2019-04-27 10:41:47 +00:00
|
|
|
long getDimTime();
|
|
|
|
long getMenuTimeout();
|
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-27 10:41:47 +00:00
|
|
|
const sCyclicThermostat& getCyclicMode() const;
|
2019-05-12 10:15:18 +00:00
|
|
|
const sMQTTparams& getMQTTinfo() const;
|
2019-04-09 23:28:46 +00:00
|
|
|
GPIOinModes getGPIOinMode();
|
|
|
|
GPIOoutModes getGPIOoutMode();
|
2019-04-12 23:18:07 +00:00
|
|
|
GPIOalgModes getGPIOalgMode();
|
2019-04-19 11:38:39 +00:00
|
|
|
uint16_t getFrameRate();
|
2019-04-19 23:49:22 +00:00
|
|
|
const sHomeMenuActions& getHomeMenu() const;
|
2019-05-16 11:12:29 +00:00
|
|
|
const sCredentials& getCredentials() const;
|
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);
|
2019-04-27 10:41:47 +00:00
|
|
|
void setDimTime(long val);
|
|
|
|
void setMenuTimeout(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-27 10:41:47 +00:00
|
|
|
void setCyclicMode(const sCyclicThermostat& val);
|
2019-04-09 23:28:46 +00:00
|
|
|
void setGPIOinMode(unsigned char val);
|
|
|
|
void setGPIOoutMode(unsigned char val);
|
|
|
|
void setGPIOalgMode(unsigned char val);
|
2019-04-19 11:38:39 +00:00
|
|
|
void setFrameRate(uint16_t val);
|
2019-04-19 23:49:22 +00:00
|
|
|
void setHomeMenu(sHomeMenuActions val);
|
2018-12-07 04:18:24 +00:00
|
|
|
|
|
|
|
void getTimerInfo(int idx, sTimer& timerInfo);
|
|
|
|
void setTimerInfo(int idx, const sTimer& timerInfo);
|
2019-05-12 10:15:18 +00:00
|
|
|
void setMQTTinfo(const sMQTTparams& info);
|
2019-05-16 11:12:29 +00:00
|
|
|
void setCredentials(const sCredentials& info);
|
2018-10-20 07:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-04-09 23:28:46 +00:00
|
|
|
|
2018-10-20 07:11:23 +00:00
|
|
|
class CESP32HeaterStorage : public CHeaterStorage {
|
|
|
|
public:
|
|
|
|
CESP32HeaterStorage();
|
|
|
|
virtual ~CESP32HeaterStorage();
|
|
|
|
void init();
|
|
|
|
void load();
|
|
|
|
void save();
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|