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-16 07:34:39 +00:00
|
|
|
#include <Arduino.h>
|
2018-10-20 07:11:23 +00:00
|
|
|
#include "NVStorage.h"
|
2018-12-12 09:47:20 +00:00
|
|
|
#include "DebugPort.h"
|
2019-04-12 23:18:07 +00:00
|
|
|
#include <driver/adc.h>
|
2018-10-20 07:11:23 +00:00
|
|
|
|
2019-01-12 01:19:55 +00:00
|
|
|
bool u8inBounds(uint8_t test, uint8_t minLim, uint8_t maxLim);
|
2019-01-18 20:15:02 +00:00
|
|
|
bool s8inBounds(int8_t test, int8_t minLim, int8_t maxLim);
|
2019-01-12 01:19:55 +00:00
|
|
|
bool u8Match2(uint8_t test, uint8_t test1, uint8_t test2);
|
|
|
|
bool u16inBounds(uint16_t test, uint16_t minLim, uint16_t maxLim);
|
|
|
|
bool s32inBounds(long test, long minLim, long maxLim);
|
2019-03-14 10:52:59 +00:00
|
|
|
bool thermoMethodinBounds(uint8_t test, uint8_t minLim, uint8_t maxLim);
|
2019-01-11 23:33:45 +00:00
|
|
|
|
2018-12-07 11:16:04 +00:00
|
|
|
bool
|
|
|
|
sNVStore::valid()
|
|
|
|
{
|
|
|
|
bool retval = true;
|
2019-03-24 05:48:03 +00:00
|
|
|
retval &= Options.valid();
|
2018-12-07 11:16:04 +00:00
|
|
|
for(int i=0; i<2; i++) {
|
2019-01-11 23:33:45 +00:00
|
|
|
retval &= timer[i].valid();
|
2018-12-07 11:16:04 +00:00
|
|
|
}
|
2019-01-11 23:33:45 +00:00
|
|
|
retval &= Heater.valid();
|
2018-12-07 11:16:04 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sNVStore::init()
|
|
|
|
{
|
|
|
|
for(int i=0; i<2; i++) {
|
2019-01-11 23:33:45 +00:00
|
|
|
timer[i].init();
|
2018-12-07 11:16:04 +00:00
|
|
|
}
|
2019-03-24 05:48:03 +00:00
|
|
|
Options.init();
|
2019-01-11 23:33:45 +00:00
|
|
|
Heater.init();
|
2018-12-07 11:16:04 +00:00
|
|
|
}
|
2018-10-20 07:11:23 +00:00
|
|
|
|
|
|
|
CHeaterStorage::CHeaterStorage()
|
|
|
|
{
|
2019-01-11 23:33:45 +00:00
|
|
|
_calValues.Heater.init();
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 11:15:23 +00:00
|
|
|
float
|
2018-10-20 07:11:23 +00:00
|
|
|
CHeaterStorage::getPmin()
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
return float(_calValues.Heater.Pmin) * 0.1f;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 11:15:23 +00:00
|
|
|
float
|
2018-10-20 07:11:23 +00:00
|
|
|
CHeaterStorage::getPmax()
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
return float(_calValues.Heater.Pmax) * 0.1f;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short
|
|
|
|
CHeaterStorage::getFmin()
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
return _calValues.Heater.Fmin;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short
|
|
|
|
CHeaterStorage::getFmax()
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
return _calValues.Heater.Fmax;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
2018-12-15 09:34:58 +00:00
|
|
|
CHeaterStorage::getDesiredTemperature()
|
2018-10-20 07:11:23 +00:00
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
return _calValues.Heater.setTemperature;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getThermostatMode()
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
return _calValues.Heater.ThermostatMode;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 10:52:59 +00:00
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getThermostatMethodMode()
|
|
|
|
{
|
2019-03-24 05:48:03 +00:00
|
|
|
return _calValues.Options.ThermostatMethod & 0x03;
|
2019-03-14 10:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2019-03-15 07:19:30 +00:00
|
|
|
CHeaterStorage::getThermostatMethodWindow()
|
2019-03-14 10:52:59 +00:00
|
|
|
{
|
2019-03-24 05:48:03 +00:00
|
|
|
return float((_calValues.Options.ThermostatMethod >> 2) & 0x3f) * 0.1f; // top 5 bits / 10, then / 2
|
2019-03-14 10:52:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-20 07:11:23 +00:00
|
|
|
void
|
2018-11-28 11:15:23 +00:00
|
|
|
CHeaterStorage::setPmin(float val)
|
2018-10-20 07:11:23 +00:00
|
|
|
{
|
2018-11-28 11:15:23 +00:00
|
|
|
uint8_t cVal = (uint8_t)(val * 10.f + 0.5f);
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.Heater.Pmin = cVal;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-11-28 11:15:23 +00:00
|
|
|
CHeaterStorage::setPmax(float val)
|
2018-10-20 07:11:23 +00:00
|
|
|
{
|
2018-11-28 11:15:23 +00:00
|
|
|
uint8_t cVal = (uint8_t)(val * 10.f + 0.5f);
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.Heater.Pmax = cVal;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setFmin(unsigned short val)
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.Heater.Fmin = val;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setFmax(unsigned short val)
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.Heater.Fmax = val;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-12-15 09:34:58 +00:00
|
|
|
CHeaterStorage::setDesiredTemperature(unsigned char val)
|
2018-10-20 07:11:23 +00:00
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.Heater.setTemperature = val;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setThermostatMode(unsigned char val)
|
|
|
|
{
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.Heater.ThermostatMode = val;
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 10:52:59 +00:00
|
|
|
void
|
|
|
|
CHeaterStorage::setThermostatMethodMode(unsigned char val)
|
|
|
|
{
|
2019-03-24 05:48:03 +00:00
|
|
|
_calValues.Options.ThermostatMethod &= ~0x03;
|
|
|
|
_calValues.Options.ThermostatMethod |= (val & 0x03);
|
2019-03-14 10:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-15 07:19:30 +00:00
|
|
|
CHeaterStorage::setThermostatMethodWindow(float val)
|
2019-03-14 10:52:59 +00:00
|
|
|
{
|
2019-03-24 05:48:03 +00:00
|
|
|
_calValues.Options.ThermostatMethod &= 0x03;
|
2019-03-14 10:52:59 +00:00
|
|
|
int nVal = int(val * 10 + 0.5);
|
2019-03-24 05:48:03 +00:00
|
|
|
_calValues.Options.ThermostatMethod |= ((nVal & 0x3F) << 2);
|
2019-03-14 10:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-11 05:40:25 +00:00
|
|
|
void
|
|
|
|
CHeaterStorage::setSystemVoltage(float fVal)
|
|
|
|
{
|
|
|
|
int val = int(fVal * 10.0);
|
|
|
|
if(val == 120 || val == 240) {
|
|
|
|
_calValues.Heater.sysVoltage = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getSysVoltage()
|
|
|
|
{
|
|
|
|
return _calValues.Heater.sysVoltage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setFanSensor(unsigned char val)
|
|
|
|
{
|
|
|
|
if(val == 2)
|
|
|
|
_calValues.Heater.fanSensor = 2;
|
|
|
|
else
|
|
|
|
_calValues.Heater.fanSensor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getFanSensor()
|
|
|
|
{
|
|
|
|
return _calValues.Heater.fanSensor;
|
|
|
|
}
|
|
|
|
|
2019-01-19 11:05:14 +00:00
|
|
|
void
|
|
|
|
CHeaterStorage::setGlowDrive(unsigned char val)
|
|
|
|
{
|
|
|
|
if(val >=1 && val <= 6)
|
|
|
|
_calValues.Heater.glowDrive = val;
|
|
|
|
else
|
|
|
|
_calValues.Heater.glowDrive = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getGlowDrive()
|
|
|
|
{
|
|
|
|
return _calValues.Heater.glowDrive;
|
|
|
|
}
|
|
|
|
|
2018-12-07 04:18:24 +00:00
|
|
|
void
|
|
|
|
CHeaterStorage::getTimerInfo(int idx, sTimer& timerInfo)
|
|
|
|
{
|
2019-02-14 10:20:15 +00:00
|
|
|
if(idx >= 0 && idx < 14) {
|
2018-12-07 11:16:04 +00:00
|
|
|
timerInfo = _calValues.timer[idx];
|
2018-12-07 04:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setTimerInfo(int idx, const sTimer& timerInfo)
|
|
|
|
{
|
2019-02-14 10:20:15 +00:00
|
|
|
if(idx >= 0 && idx < 14) {
|
2018-12-07 11:16:04 +00:00
|
|
|
_calValues.timer[idx] = timerInfo;
|
2018-12-07 04:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 10:41:47 +00:00
|
|
|
long
|
2018-12-22 10:32:13 +00:00
|
|
|
CHeaterStorage::getDimTime()
|
|
|
|
{
|
2019-04-27 10:41:47 +00:00
|
|
|
return _calValues.Options.dimTime;
|
2018-12-22 10:32:13 +00:00
|
|
|
}
|
2018-12-07 04:18:24 +00:00
|
|
|
|
2018-12-22 10:32:13 +00:00
|
|
|
void
|
2019-04-27 10:41:47 +00:00
|
|
|
CHeaterStorage::setDimTime(long val)
|
2018-12-22 10:32:13 +00:00
|
|
|
{
|
2019-04-27 10:41:47 +00:00
|
|
|
_calValues.Options.dimTime = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
CHeaterStorage::getMenuTimeout()
|
|
|
|
{
|
|
|
|
return _calValues.Options.menuTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setMenuTimeout(long val)
|
|
|
|
{
|
|
|
|
_calValues.Options.menuTimeout = val;
|
2018-12-22 10:32:13 +00:00
|
|
|
}
|
2018-10-20 07:11:23 +00:00
|
|
|
|
2019-02-06 20:24:22 +00:00
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getDegFMode()
|
|
|
|
{
|
2019-03-24 05:48:03 +00:00
|
|
|
return _calValues.Options.degF;
|
2019-02-06 20:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setDegFMode(unsigned char val)
|
|
|
|
{
|
2019-03-24 05:48:03 +00:00
|
|
|
_calValues.Options.degF = val;
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getWifiEnabled()
|
|
|
|
{
|
|
|
|
return _calValues.Options.enableWifi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setWifiEnabled(unsigned char val)
|
|
|
|
{
|
|
|
|
_calValues.Options.enableWifi = val;
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
CHeaterStorage::getOTAEnabled()
|
|
|
|
{
|
|
|
|
return _calValues.Options.enableOTA;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setOTAEnabled(unsigned char val)
|
|
|
|
{
|
|
|
|
_calValues.Options.enableOTA = val;
|
2019-02-06 20:24:22 +00:00
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2019-04-27 10:41:47 +00:00
|
|
|
const sCyclicThermostat&
|
|
|
|
CHeaterStorage::getCyclicMode() const
|
2019-04-04 10:48:05 +00:00
|
|
|
{
|
2019-04-27 10:41:47 +00:00
|
|
|
return _calValues.Options.cyclic;
|
2019-04-04 10:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-27 10:41:47 +00:00
|
|
|
CHeaterStorage::setCyclicMode(const sCyclicThermostat& val)
|
2019-04-04 10:48:05 +00:00
|
|
|
{
|
2019-04-27 10:41:47 +00:00
|
|
|
_calValues.Options.cyclic = val;
|
2019-04-04 10:48:05 +00:00
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2019-04-09 23:28:46 +00:00
|
|
|
GPIOinModes
|
|
|
|
CHeaterStorage::getGPIOinMode()
|
|
|
|
{
|
|
|
|
GPIOinModes inMode = GPIOinNone;
|
|
|
|
switch(_calValues.Options.GPIOinMode) {
|
|
|
|
case 0: inMode = GPIOinNone; break;
|
|
|
|
case 1: inMode = GPIOinOn1Off2; break;
|
|
|
|
case 2: inMode = GPIOinOnHold1; break;
|
|
|
|
case 3: inMode = GPIOinOn1Off1; break;
|
|
|
|
}
|
|
|
|
return inMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setGPIOinMode(unsigned char val)
|
|
|
|
{
|
|
|
|
_calValues.Options.GPIOinMode = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPIOoutModes
|
|
|
|
CHeaterStorage::getGPIOoutMode()
|
|
|
|
{
|
|
|
|
GPIOoutModes outMode = GPIOoutNone;
|
|
|
|
switch(_calValues.Options.GPIOoutMode) {
|
|
|
|
case 0: outMode = GPIOoutNone; break;
|
|
|
|
case 1: outMode = GPIOoutStatus; break;
|
|
|
|
case 2: outMode = GPIOoutUser; break;
|
|
|
|
}
|
|
|
|
return outMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setGPIOoutMode(unsigned char val)
|
|
|
|
{
|
|
|
|
_calValues.Options.GPIOoutMode = val;
|
|
|
|
}
|
|
|
|
|
2019-04-12 23:18:07 +00:00
|
|
|
GPIOalgModes
|
2019-04-09 23:28:46 +00:00
|
|
|
CHeaterStorage::getGPIOalgMode()
|
|
|
|
{
|
2019-04-12 23:18:07 +00:00
|
|
|
GPIOalgModes algMode = GPIOalgNone;
|
|
|
|
switch (_calValues.Options.GPIOalgMode) {
|
|
|
|
case 0: algMode = GPIOalgNone; break;
|
|
|
|
case 1: algMode = GPIOalgHeatDemand; break;
|
|
|
|
}
|
|
|
|
return algMode;
|
2019-04-09 23:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setGPIOalgMode(unsigned char val)
|
|
|
|
{
|
|
|
|
_calValues.Options.GPIOalgMode = val;
|
|
|
|
}
|
|
|
|
|
2019-04-19 11:38:39 +00:00
|
|
|
uint16_t
|
|
|
|
CHeaterStorage::getFrameRate()
|
|
|
|
{
|
|
|
|
return _calValues.Options.FrameRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setFrameRate(uint16_t val)
|
|
|
|
{
|
|
|
|
_calValues.Options.FrameRate = val;
|
|
|
|
}
|
|
|
|
|
2019-04-19 23:49:22 +00:00
|
|
|
const sHomeMenuActions&
|
|
|
|
CHeaterStorage::getHomeMenu() const
|
2019-04-19 11:38:39 +00:00
|
|
|
{
|
|
|
|
return _calValues.Options.HomeMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-19 23:49:22 +00:00
|
|
|
CHeaterStorage::setHomeMenu(sHomeMenuActions val)
|
2019-04-19 11:38:39 +00:00
|
|
|
{
|
|
|
|
_calValues.Options.HomeMenu = val;
|
|
|
|
}
|
|
|
|
|
2018-10-20 07:11:23 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ESP32
|
|
|
|
//
|
2019-05-11 02:18:06 +00:00
|
|
|
//#ifdef ESP32
|
2018-10-20 07:11:23 +00:00
|
|
|
|
|
|
|
CESP32HeaterStorage::CESP32HeaterStorage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CESP32HeaterStorage::~CESP32HeaterStorage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CESP32HeaterStorage::init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
|
|
|
CESP32HeaterStorage::load()
|
2018-10-20 07:11:23 +00:00
|
|
|
{
|
2018-12-12 09:47:20 +00:00
|
|
|
DebugPort.println("Reading from NV storage");
|
2019-01-11 23:33:45 +00:00
|
|
|
loadHeater();
|
2019-02-14 10:20:15 +00:00
|
|
|
for(int i=0; i<14; i++) {
|
2019-01-12 01:57:32 +00:00
|
|
|
loadTimer(i);
|
2018-12-07 11:16:04 +00:00
|
|
|
}
|
2019-01-11 23:33:45 +00:00
|
|
|
loadUI();
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
|
|
|
CESP32HeaterStorage::save()
|
2018-10-20 07:11:23 +00:00
|
|
|
{
|
2018-12-12 09:47:20 +00:00
|
|
|
DebugPort.println("Saving to NV storage");
|
2019-01-11 23:33:45 +00:00
|
|
|
saveHeater();
|
2019-02-14 10:20:15 +00:00
|
|
|
for(int i=0; i<14; i++) {
|
2019-01-12 01:57:32 +00:00
|
|
|
saveTimer(i);
|
2019-01-11 23:33:45 +00:00
|
|
|
}
|
|
|
|
saveUI();
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:38:14 +00:00
|
|
|
// **** MAX LENGTH is 15 for name and values ****
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
|
|
|
CESP32HeaterStorage::loadHeater()
|
|
|
|
{
|
|
|
|
// section for heater calibration params
|
|
|
|
preferences.begin("Calibration", false);
|
2019-01-12 01:19:55 +00:00
|
|
|
validatedLoad("minPump", _calValues.Heater.Pmin, 14, u8inBounds, 4, 100);
|
2019-02-10 08:20:47 +00:00
|
|
|
validatedLoad("maxPump", _calValues.Heater.Pmax, 45, u8inBounds, 4, 150);
|
2019-01-12 01:19:55 +00:00
|
|
|
validatedLoad("minFan", _calValues.Heater.Fmin, 1500, u16inBounds, 100, 5000);
|
|
|
|
validatedLoad("maxFan", _calValues.Heater.Fmax, 4500, u16inBounds, 100, 6000);
|
|
|
|
validatedLoad("thermostat", _calValues.Heater.ThermostatMode, 1, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("setTemperature", _calValues.Heater.setTemperature, 22, u8inBounds, 0, 40);
|
2019-01-26 00:58:50 +00:00
|
|
|
validatedLoad("systemVoltage", _calValues.Heater.sysVoltage, 120, u8Match2, 120, 240);
|
2019-01-12 01:19:55 +00:00
|
|
|
validatedLoad("fanSensor", _calValues.Heater.fanSensor, 1, u8inBounds, 1, 2);
|
2019-01-19 11:05:14 +00:00
|
|
|
validatedLoad("glowDrive", _calValues.Heater.glowDrive, 5, u8inBounds, 1, 6);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:38:14 +00:00
|
|
|
// **** MAX LENGTH is 15 for name and values ****
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
|
|
|
CESP32HeaterStorage::saveHeater()
|
|
|
|
{
|
|
|
|
// section for heater calibration params
|
|
|
|
preferences.begin("Calibration", false);
|
|
|
|
preferences.putUChar("minPump", _calValues.Heater.Pmin);
|
|
|
|
preferences.putUChar("maxPump", _calValues.Heater.Pmax);
|
|
|
|
preferences.putUShort("minFan", _calValues.Heater.Fmin);
|
|
|
|
preferences.putUShort("maxFan", _calValues.Heater.Fmax);
|
|
|
|
preferences.putUChar("thermostat", _calValues.Heater.ThermostatMode);
|
|
|
|
preferences.putUChar("setTemperature", _calValues.Heater.setTemperature);
|
|
|
|
preferences.putUChar("systemVoltage", _calValues.Heater.sysVoltage);
|
|
|
|
preferences.putUChar("fanSensor", _calValues.Heater.fanSensor);
|
2019-01-19 11:05:14 +00:00
|
|
|
preferences.putUChar("glowDrive", _calValues.Heater.glowDrive);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:38:14 +00:00
|
|
|
// **** MAX LENGTH is 15 for name and values ****
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
2019-01-12 01:57:32 +00:00
|
|
|
CESP32HeaterStorage::loadTimer(int idx)
|
2019-01-12 01:19:55 +00:00
|
|
|
{
|
2019-01-12 01:57:32 +00:00
|
|
|
sTimer& timer = _calValues.timer[idx];
|
2019-02-14 19:36:13 +00:00
|
|
|
timer.timerID = idx;
|
2019-01-11 23:33:45 +00:00
|
|
|
char SectionName[16];
|
2019-01-12 01:57:32 +00:00
|
|
|
sprintf(SectionName, "timer%d", idx+1);
|
2019-01-12 01:19:55 +00:00
|
|
|
preferences.begin(SectionName, false);
|
2019-01-18 20:15:02 +00:00
|
|
|
validatedLoad("startHour", timer.start.hour, 0, s8inBounds, 0, 23);
|
|
|
|
validatedLoad("startMin", timer.start.min, 0, s8inBounds, 0, 59);
|
|
|
|
validatedLoad("stopHour", timer.stop.hour, 0, s8inBounds, 0, 23);
|
|
|
|
validatedLoad("stopMin", timer.stop.min, 0, s8inBounds, 0, 59);
|
2019-01-12 01:19:55 +00:00
|
|
|
validatedLoad("enabled", timer.enabled, 0, u8inBounds, 0, 255); // all 8 bits used!
|
2019-02-14 10:20:15 +00:00
|
|
|
validatedLoad("repeat", timer.repeat, 0, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("temperature", timer.temperature, 22, u8inBounds, 8, 35);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:38:14 +00:00
|
|
|
// **** MAX LENGTH is 15 for name and values ****
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
2019-01-12 01:57:32 +00:00
|
|
|
CESP32HeaterStorage::saveTimer(int idx)
|
2019-01-11 23:33:45 +00:00
|
|
|
{
|
2019-01-12 01:57:32 +00:00
|
|
|
sTimer& timer = _calValues.timer[idx];
|
2019-01-11 23:33:45 +00:00
|
|
|
char SectionName[16];
|
2019-01-12 01:57:32 +00:00
|
|
|
sprintf(SectionName, "timer%d", idx+1);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.begin(SectionName, false);
|
2019-01-18 20:15:02 +00:00
|
|
|
preferences.putChar("startHour", timer.start.hour);
|
|
|
|
preferences.putChar("startMin", timer.start.min);
|
|
|
|
preferences.putChar("stopHour", timer.stop.hour);
|
|
|
|
preferences.putChar("stopMin", timer.stop.min);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.putUChar("enabled", timer.enabled);
|
|
|
|
preferences.putUChar("repeat", timer.repeat);
|
2019-02-14 10:20:15 +00:00
|
|
|
preferences.putUChar("temperature", timer.temperature);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:38:14 +00:00
|
|
|
// **** MAX LENGTH is 15 for name and values ****
|
2019-01-11 23:33:45 +00:00
|
|
|
void
|
|
|
|
CESP32HeaterStorage::loadUI()
|
|
|
|
{
|
|
|
|
preferences.begin("user", false);
|
2019-04-27 10:41:47 +00:00
|
|
|
validatedLoad("dimTime", _calValues.Options.dimTime, 60000, s32inBounds, -600000, 600000);
|
|
|
|
validatedLoad("menuTimeout", _calValues.Options.menuTimeout, 60000, s32inBounds, 0, 300000);
|
2019-03-24 05:48:03 +00:00
|
|
|
validatedLoad("degF", _calValues.Options.degF, 0, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("thermoMethod", _calValues.Options.ThermostatMethod, (10 << 2), u8inBounds, 0, 2, 0x03);
|
|
|
|
validatedLoad("enableWifi", _calValues.Options.enableWifi, 1, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("enableOTA", _calValues.Options.enableOTA, 1, u8inBounds, 0, 1);
|
2019-04-27 10:41:47 +00:00
|
|
|
validatedLoad("cyclicStop", _calValues.Options.cyclic.Stop, 0, s8inBounds, 0, 10);
|
2019-05-11 23:01:22 +00:00
|
|
|
validatedLoad("cyclicStart", _calValues.Options.cyclic.Start, -1, s8inBounds, -20, 0);
|
2019-04-09 23:28:46 +00:00
|
|
|
validatedLoad("GPIOinMode", _calValues.Options.GPIOinMode, 0, u8inBounds, 0, 3);
|
|
|
|
validatedLoad("GPIOoutMode", _calValues.Options.GPIOoutMode, 0, u8inBounds, 0, 2);
|
|
|
|
validatedLoad("GPIOalgMode", _calValues.Options.GPIOalgMode, 0, u8inBounds, 0, 2);
|
2019-05-07 19:38:14 +00:00
|
|
|
validatedLoad("MenuonTimeout", _calValues.Options.HomeMenu.onTimeout, 0, u8inBounds, 0, 3);
|
|
|
|
validatedLoad("MenuonStart", _calValues.Options.HomeMenu.onStart, 0, u8inBounds, 0, 3);
|
|
|
|
validatedLoad("MenuonStop", _calValues.Options.HomeMenu.onStop, 0, u8inBounds, 0, 3);
|
2019-04-19 11:38:39 +00:00
|
|
|
validatedLoad("FrameRate", _calValues.Options.FrameRate, 1000, u16inBounds, 300, 1500);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CESP32HeaterStorage::saveUI()
|
|
|
|
{
|
|
|
|
preferences.begin("user", false);
|
2019-04-27 10:41:47 +00:00
|
|
|
preferences.putLong("dimTime", _calValues.Options.dimTime);
|
|
|
|
preferences.putLong("menuTimeout", _calValues.Options.menuTimeout);
|
2019-03-24 05:48:03 +00:00
|
|
|
preferences.putUChar("degF", _calValues.Options.degF);
|
|
|
|
preferences.putUChar("thermoMethod", _calValues.Options.ThermostatMethod);
|
|
|
|
preferences.putUChar("enableWifi", _calValues.Options.enableWifi);
|
|
|
|
preferences.putUChar("enableOTA", _calValues.Options.enableOTA);
|
2019-05-11 02:18:06 +00:00
|
|
|
preferences.putChar("cyclicStop", _calValues.Options.cyclic.Stop);
|
|
|
|
preferences.putChar("cyclicStart", _calValues.Options.cyclic.Start);
|
2019-04-09 23:28:46 +00:00
|
|
|
preferences.putUChar("GPIOinMode", _calValues.Options.GPIOinMode);
|
|
|
|
preferences.putUChar("GPIOoutMode", _calValues.Options.GPIOoutMode);
|
|
|
|
preferences.putUChar("GPIOalgMode", _calValues.Options.GPIOalgMode);
|
2019-05-07 19:38:14 +00:00
|
|
|
preferences.putUChar("MenuOnTimeout", _calValues.Options.HomeMenu.onTimeout);
|
|
|
|
preferences.putUChar("MenuonStart", _calValues.Options.HomeMenu.onStart);
|
|
|
|
preferences.putUChar("MenuonStop", _calValues.Options.HomeMenu.onStop);
|
2019-04-19 11:38:39 +00:00
|
|
|
preferences.putUShort("FrameRate", _calValues.Options.FrameRate);
|
2019-01-11 23:33:45 +00:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-01-12 01:19:55 +00:00
|
|
|
bool
|
2019-03-14 10:52:59 +00:00
|
|
|
CESP32HeaterStorage::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)
|
2019-01-12 01:19:55 +00:00
|
|
|
{
|
|
|
|
val = preferences.getUChar(key, defVal);
|
2019-03-14 10:52:59 +00:00
|
|
|
if(!validator(val & mask, min, max)) {
|
2019-01-12 01:19:55 +00:00
|
|
|
|
|
|
|
DebugPort.print("CESP32HeaterStorage::validatedLoad<uint8_t> invalid read ");
|
|
|
|
DebugPort.print(key); DebugPort.print("="); DebugPort.print(val);
|
|
|
|
DebugPort.print(" validator("); DebugPort.print(min); DebugPort.print(","); DebugPort.print(max); DebugPort.print(") reset to ");
|
|
|
|
DebugPort.println(defVal);
|
|
|
|
|
|
|
|
val = defVal;
|
|
|
|
preferences.putUChar(key, val);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-18 20:15:02 +00:00
|
|
|
bool
|
|
|
|
CESP32HeaterStorage::validatedLoad(const char* key, int8_t& val, int defVal, std::function<bool(int8_t, int8_t, int8_t)> validator, int min, int max)
|
|
|
|
{
|
|
|
|
val = preferences.getChar(key, defVal);
|
|
|
|
if(!validator(val, min, max)) {
|
|
|
|
|
|
|
|
DebugPort.print("CESP32HeaterStorage::validatedLoad<uint8_t> invalid read ");
|
|
|
|
DebugPort.print(key); DebugPort.print("="); DebugPort.print(val);
|
|
|
|
DebugPort.print(" validator("); DebugPort.print(min); DebugPort.print(","); DebugPort.print(max); DebugPort.print(") reset to ");
|
|
|
|
DebugPort.println(defVal);
|
|
|
|
|
|
|
|
val = defVal;
|
|
|
|
preferences.putChar(key, val);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-12 01:19:55 +00:00
|
|
|
bool
|
|
|
|
CESP32HeaterStorage::validatedLoad(const char* key, uint16_t& val, int defVal, std::function<bool(uint16_t, uint16_t, uint16_t)> validator, int min, int max)
|
|
|
|
{
|
|
|
|
val = preferences.getUShort(key, defVal);
|
|
|
|
if(!validator(val, min, max)) {
|
|
|
|
|
|
|
|
DebugPort.print("CESP32HeaterStorage::validatedLoad<uint16_t> invalid read ");
|
|
|
|
DebugPort.print(key); DebugPort.print("="); DebugPort.print(val);
|
|
|
|
DebugPort.print(" validator("); DebugPort.print(min); DebugPort.print(","); DebugPort.print(max); DebugPort.print(") reset to ");
|
|
|
|
DebugPort.println(defVal);
|
|
|
|
|
|
|
|
val = defVal;
|
|
|
|
preferences.putUShort(key, val);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CESP32HeaterStorage::validatedLoad(const char* key, long& val, long defVal, std::function<bool(long, long, long)> validator, long min, long max)
|
|
|
|
{
|
|
|
|
val = preferences.getLong(key, defVal);
|
|
|
|
if(!validator(val, min, max)) {
|
|
|
|
|
|
|
|
DebugPort.print("CESP32HeaterStorage::validatedLoad<long> invalid read ");
|
|
|
|
DebugPort.print(key); DebugPort.print("="); DebugPort.print(val);
|
|
|
|
DebugPort.print(" validator("); DebugPort.print(min); DebugPort.print(","); DebugPort.print(max); DebugPort.print(") reset to ");
|
|
|
|
DebugPort.println(defVal);
|
|
|
|
|
|
|
|
val = defVal;
|
|
|
|
preferences.putLong(key, val);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool u8inBounds(uint8_t test, uint8_t minLim, uint8_t maxLim)
|
|
|
|
{
|
|
|
|
return (test >= minLim) && (test <= maxLim);
|
|
|
|
}
|
|
|
|
|
2019-01-18 20:15:02 +00:00
|
|
|
bool s8inBounds(int8_t test, int8_t minLim, int8_t maxLim)
|
|
|
|
{
|
|
|
|
return (test >= minLim) && (test <= maxLim);
|
|
|
|
}
|
|
|
|
|
2019-01-12 01:19:55 +00:00
|
|
|
bool u8Match2(uint8_t test, uint8_t test1, uint8_t test2)
|
|
|
|
{
|
|
|
|
return (test == test1) || (test == test2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool u16inBounds(uint16_t test, uint16_t minLim, uint16_t maxLim)
|
2019-01-11 23:33:45 +00:00
|
|
|
{
|
|
|
|
return (test >= minLim) && (test <= maxLim);
|
|
|
|
}
|
2019-01-12 01:19:55 +00:00
|
|
|
|
|
|
|
bool s32inBounds(long test, long minLim, long maxLim)
|
2019-01-11 23:33:45 +00:00
|
|
|
{
|
|
|
|
return (test >= minLim) && (test <= maxLim);
|
2018-10-20 07:11:23 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 01:19:55 +00:00
|
|
|
|
2019-05-11 02:18:06 +00:00
|
|
|
//#endif // ESP32
|