2018-11-26 12:58:15 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
2019-09-08 02:14:36 +02:00
|
|
|
* Copyright (C) 2019 Ray Jones <ray@mrjones.id.au>
|
2018-11-26 12:58:15 +01:00
|
|
|
*
|
|
|
|
* 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 08:34:39 +01:00
|
|
|
#include <Arduino.h>
|
2018-10-20 09:11:23 +02:00
|
|
|
#include "NVStorage.h"
|
2018-12-12 10:47:20 +01:00
|
|
|
#include "DebugPort.h"
|
2019-04-13 01:18:07 +02:00
|
|
|
#include <driver/adc.h>
|
2020-03-23 06:54:15 +01:00
|
|
|
#include <string.h>
|
2019-01-12 00:33:45 +01:00
|
|
|
|
2018-12-07 12:16:04 +01:00
|
|
|
bool
|
|
|
|
sNVStore::valid()
|
|
|
|
{
|
|
|
|
bool retval = true;
|
2019-06-06 03:32:43 +02:00
|
|
|
retval &= heaterTuning.valid();
|
|
|
|
retval &= userSettings.valid();
|
2018-12-07 12:16:04 +01:00
|
|
|
for(int i=0; i<2; i++) {
|
2019-01-12 00:33:45 +01:00
|
|
|
retval &= timer[i].valid();
|
2018-12-07 12:16:04 +01:00
|
|
|
}
|
2019-05-16 13:12:29 +02:00
|
|
|
retval &= MQTT.valid();
|
|
|
|
retval &= Credentials.valid();
|
2018-12-07 12:16:04 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sNVStore::init()
|
|
|
|
{
|
2019-06-06 03:32:43 +02:00
|
|
|
heaterTuning.init();
|
|
|
|
userSettings.init();
|
2019-06-16 12:37:25 +02:00
|
|
|
|
|
|
|
for(int i=0; i<14; i++) {
|
|
|
|
timer[i].init(i);
|
2018-12-07 12:16:04 +01:00
|
|
|
}
|
2019-06-16 12:37:25 +02:00
|
|
|
|
2019-05-16 13:12:29 +02:00
|
|
|
MQTT.init();
|
|
|
|
Credentials.init();
|
2019-07-24 22:06:47 +02:00
|
|
|
hourMeter.init();
|
2018-12-07 12:16:04 +01:00
|
|
|
}
|
2018-10-20 09:11:23 +02:00
|
|
|
|
|
|
|
CHeaterStorage::CHeaterStorage()
|
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
_calValues.init();
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 12:15:23 +01:00
|
|
|
float
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::getPmin() const
|
2018-10-20 09:11:23 +02:00
|
|
|
{
|
2019-06-06 03:32:43 +02:00
|
|
|
return float(Pmin) * 0.1f;
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 12:15:23 +01:00
|
|
|
float
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::getPmax() const
|
2018-10-20 09:11:23 +02:00
|
|
|
{
|
2019-06-06 03:32:43 +02:00
|
|
|
return float(Pmax) * 0.1f;
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
2019-03-14 11:52:59 +01:00
|
|
|
|
2018-10-20 09:11:23 +02:00
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::setPmin(float val)
|
2018-10-20 09:11:23 +02:00
|
|
|
{
|
2019-07-03 15:01:36 +02:00
|
|
|
BOUNDSLIMIT(val, 0.4, 5.0);
|
2018-11-28 12:15:23 +01:00
|
|
|
uint8_t cVal = (uint8_t)(val * 10.f + 0.5f);
|
2019-06-06 03:32:43 +02:00
|
|
|
Pmin = cVal;
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::setPmax(float val)
|
2018-10-20 09:11:23 +02:00
|
|
|
{
|
2019-07-03 15:01:36 +02:00
|
|
|
BOUNDSLIMIT(val, 1.0, 10.0);
|
2018-11-28 12:15:23 +01:00
|
|
|
uint8_t cVal = (uint8_t)(val * 10.f + 0.5f);
|
2019-06-06 03:32:43 +02:00
|
|
|
Pmax = cVal;
|
2019-03-14 11:52:59 +01:00
|
|
|
}
|
|
|
|
|
2020-04-11 10:49:52 +02:00
|
|
|
void
|
|
|
|
sHeaterTuning::setFanSensor(int val)
|
|
|
|
{
|
|
|
|
if(INBOUNDS(val, 1, 2))
|
|
|
|
fanSensor = val;
|
|
|
|
}
|
2019-03-14 11:52:59 +01:00
|
|
|
|
2019-01-11 06:40:25 +01:00
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::setSysVoltage(float fVal)
|
2019-01-11 06:40:25 +01:00
|
|
|
{
|
|
|
|
int val = int(fVal * 10.0);
|
|
|
|
if(val == 120 || val == 240) {
|
2019-06-06 03:32:43 +02:00
|
|
|
sysVoltage = val;
|
2019-01-11 06:40:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-11 10:49:52 +02:00
|
|
|
void
|
|
|
|
sHeaterTuning::setGlowDrive(uint8_t val) {
|
|
|
|
if(INBOUNDS(val, 1, 6))
|
|
|
|
glowDrive = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-21 13:17:54 +02:00
|
|
|
float
|
|
|
|
sHeaterTuning::getLVC() const
|
|
|
|
{
|
|
|
|
return lowVolts * 0.1;
|
|
|
|
}
|
2019-01-19 12:05:14 +01:00
|
|
|
|
2018-12-07 05:18:24 +01:00
|
|
|
void
|
|
|
|
CHeaterStorage::getTimerInfo(int idx, sTimer& timerInfo)
|
|
|
|
{
|
2019-06-16 01:09:29 +02:00
|
|
|
if(INBOUNDS(idx, 0, 13)) {
|
2018-12-07 12:16:04 +01:00
|
|
|
timerInfo = _calValues.timer[idx];
|
2018-12-07 05:18:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setTimerInfo(int idx, const sTimer& timerInfo)
|
|
|
|
{
|
2019-06-16 01:09:29 +02:00
|
|
|
if(INBOUNDS(idx, 0, 13)) {
|
2018-12-07 12:16:04 +01:00
|
|
|
_calValues.timer[idx] = timerInfo;
|
2018-12-07 05:18:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 13:38:39 +02:00
|
|
|
|
2019-05-12 12:15:18 +02:00
|
|
|
// MQTT parameter read/save
|
|
|
|
const sMQTTparams&
|
|
|
|
CHeaterStorage::getMQTTinfo() const
|
|
|
|
{
|
|
|
|
return _calValues.MQTT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setMQTTinfo(const sMQTTparams& info)
|
|
|
|
{
|
2020-03-23 06:54:15 +01:00
|
|
|
if(_calValues.MQTT != info) {
|
|
|
|
requestMQTTrestart();
|
|
|
|
}
|
|
|
|
|
2019-05-12 12:15:18 +02:00
|
|
|
_calValues.MQTT = info;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:12:29 +02:00
|
|
|
// credentials read/save
|
|
|
|
const sCredentials&
|
|
|
|
CHeaterStorage::getCredentials() const
|
|
|
|
{
|
|
|
|
return _calValues.Credentials;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setCredentials(const sCredentials& info)
|
|
|
|
{
|
|
|
|
_calValues.Credentials = info;
|
|
|
|
}
|
|
|
|
|
2019-06-06 03:32:43 +02:00
|
|
|
const sUserSettings&
|
|
|
|
CHeaterStorage::getUserSettings() const
|
|
|
|
{
|
|
|
|
return _calValues.userSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setUserSettings(const sUserSettings& info) {
|
|
|
|
_calValues.userSettings = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sHeaterTuning&
|
|
|
|
CHeaterStorage::getHeaterTuning() const
|
|
|
|
{
|
|
|
|
return _calValues.heaterTuning;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CHeaterStorage::setHeaterTuning(const sHeaterTuning& info)
|
|
|
|
{
|
|
|
|
_calValues.heaterTuning = info;
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:06:47 +02:00
|
|
|
const sHourMeter&
|
|
|
|
CHeaterStorage::getHourMeter() const
|
|
|
|
{
|
|
|
|
return _calValues.hourMeter;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CHeaterStorage::setHourMeter(const sHourMeter& newVals)
|
|
|
|
{
|
|
|
|
// if(_calValues.hourMeter != newVals) {
|
|
|
|
if(newVals != _calValues.hourMeter) {
|
2019-07-25 22:39:56 +02:00
|
|
|
_calValues.hourMeter = newVals; // stage changes
|
|
|
|
save(); // request save to NV
|
2019-07-25 13:27:57 +02:00
|
|
|
return true;
|
2019-07-24 22:06:47 +02:00
|
|
|
};
|
2019-07-25 13:27:57 +02:00
|
|
|
return false;
|
2019-07-24 22:06:47 +02:00
|
|
|
}
|
2019-06-06 03:32:43 +02:00
|
|
|
|
2019-05-12 12:15:18 +02:00
|
|
|
|
2018-10-20 09:11:23 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ESP32
|
|
|
|
//
|
2019-05-11 04:18:06 +02:00
|
|
|
//#ifdef ESP32
|
2018-10-20 09:11:23 +02:00
|
|
|
|
|
|
|
CESP32HeaterStorage::CESP32HeaterStorage()
|
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
init();
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CESP32HeaterStorage::~CESP32HeaterStorage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CESP32HeaterStorage::init()
|
|
|
|
{
|
2019-06-29 10:08:37 +02:00
|
|
|
_bShouldSave = false;
|
2019-06-16 12:37:25 +02:00
|
|
|
_calValues.init();
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
2019-01-12 00:33:45 +01:00
|
|
|
void
|
|
|
|
CESP32HeaterStorage::load()
|
2018-10-20 09:11:23 +02:00
|
|
|
{
|
2018-12-12 10:47:20 +01:00
|
|
|
DebugPort.println("Reading from NV storage");
|
2019-06-06 03:32:43 +02:00
|
|
|
_calValues.heaterTuning.load();
|
2019-02-14 11:20:15 +01:00
|
|
|
for(int i=0; i<14; i++) {
|
2019-05-16 13:12:29 +02:00
|
|
|
_calValues.timer[i].load();
|
2018-12-07 12:16:04 +01:00
|
|
|
}
|
2019-06-06 03:32:43 +02:00
|
|
|
_calValues.userSettings.load();
|
2019-05-16 13:12:29 +02:00
|
|
|
_calValues.MQTT.load();
|
|
|
|
_calValues.Credentials.load();
|
2019-07-25 22:39:56 +02:00
|
|
|
_calValues.hourMeter.load();
|
2018-10-20 09:11:23 +02:00
|
|
|
}
|
|
|
|
|
2019-01-12 00:33:45 +01:00
|
|
|
void
|
2019-06-29 10:08:37 +02:00
|
|
|
CESP32HeaterStorage::doSave()
|
2018-10-20 09:11:23 +02:00
|
|
|
{
|
2019-06-29 10:08:37 +02:00
|
|
|
if(_bShouldSave) {
|
|
|
|
_bShouldSave = false;
|
2019-07-25 22:39:56 +02:00
|
|
|
DebugPort.println("Saving to NV storage");
|
|
|
|
_calValues.heaterTuning.save();
|
|
|
|
for(int i=0; i<14; i++) {
|
|
|
|
_calValues.timer[i].save();
|
|
|
|
}
|
|
|
|
_calValues.userSettings.save();
|
|
|
|
_calValues.MQTT.save();
|
|
|
|
_calValues.Credentials.save();
|
|
|
|
_calValues.hourMeter.save();
|
2019-01-12 00:33:45 +01:00
|
|
|
}
|
2019-06-29 10:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CESP32HeaterStorage::save()
|
|
|
|
{
|
|
|
|
_bShouldSave = true; // queue request to save to NV
|
|
|
|
}
|
2019-01-12 00:33:45 +01:00
|
|
|
|
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::load()
|
2019-01-12 00:33:45 +01:00
|
|
|
{
|
|
|
|
// section for heater calibration params
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.begin("Calibration", false);
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("minPump", Pmin, 14, u8inBounds, 4, 100);
|
|
|
|
validatedLoad("maxPump", Pmax, 45, u8inBounds, 4, 150);
|
|
|
|
validatedLoad("minFan", Fmin, 1500, u16inBounds, 100, 5000);
|
|
|
|
validatedLoad("maxFan", Fmax, 4500, u16inBounds, 100, 6000);
|
|
|
|
validatedLoad("systemVoltage", sysVoltage, 120, u8Match2, 120, 240);
|
|
|
|
validatedLoad("fanSensor", fanSensor, 1, u8inBounds, 1, 2);
|
|
|
|
validatedLoad("glowDrive", glowDrive, 5, u8inBounds, 1, 6);
|
2019-07-21 13:17:54 +02:00
|
|
|
if(sysVoltage == 120)
|
2019-07-22 22:15:18 +02:00
|
|
|
validatedLoad("lowVolts", lowVolts, 115, u8inBoundsOrZero, 100, 125);
|
2019-07-21 13:17:54 +02:00
|
|
|
else
|
2019-07-22 22:15:18 +02:00
|
|
|
validatedLoad("lowVolts", lowVolts, 230, u8inBoundsOrZero, 200, 250);
|
2019-07-18 14:28:40 +02:00
|
|
|
validatedLoad("pumpCal", pumpCal, 0.02, 0.001, 1);
|
2020-03-30 07:17:54 +02:00
|
|
|
validatedLoad("maxFuelUsage", maxFuelUsage, 0, u16inBounds, 0, 10000);
|
|
|
|
validatedLoad("warnFuelUsage", warnFuelUsage, 5, u16inBounds, 0, 100);
|
2019-10-18 03:55:16 +02:00
|
|
|
validatedLoad("tempOffset0", DS18B20probe[0].offset, 0.0, -10.0, +10.0);
|
|
|
|
validatedLoad("tempOffset1", DS18B20probe[1].offset, 0.0, -10.0, +10.0);
|
|
|
|
validatedLoad("tempOffset2", DS18B20probe[2].offset, 0.0, -10.0, +10.0);
|
2020-03-23 06:54:15 +01:00
|
|
|
memset(DS18B20probe[0].romCode.bytes, 0, 8);
|
|
|
|
memset(DS18B20probe[1].romCode.bytes, 0, 8);
|
|
|
|
memset(DS18B20probe[2].romCode.bytes, 0, 8);
|
|
|
|
validatedLoad("probeSerial0", DS18B20probe[0].romCode.bytes, 8);
|
|
|
|
validatedLoad("probeSerial1", DS18B20probe[1].romCode.bytes, 8);
|
|
|
|
validatedLoad("probeSerial2", DS18B20probe[2].romCode.bytes, 8);
|
2019-10-18 03:55:16 +02:00
|
|
|
validatedLoad("tempOffsetBME", BME280probe.offset, 0.0, -10.0, +10.0);
|
|
|
|
validatedLoad("probeBMEPrmy", BME280probe.bPrimary, 0, u8inBounds, 0, 1);
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.end();
|
2019-09-22 01:03:42 +02:00
|
|
|
|
2020-03-23 06:54:15 +01:00
|
|
|
// save();
|
|
|
|
|
2019-09-25 09:27:43 +02:00
|
|
|
// for(int i=0; i<3; i++) {
|
|
|
|
// DebugPort.printf("Rd Probe[%d] %02X:%02X:%02X:%02X:%02X:%02X\r\n",
|
|
|
|
// i,
|
2019-10-18 03:55:16 +02:00
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[5],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[4],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[3],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[2],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[1],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[0]
|
2019-09-25 09:27:43 +02:00
|
|
|
// );
|
|
|
|
// }
|
2019-01-12 00:33:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sHeaterTuning::save()
|
2019-01-12 00:33:45 +01:00
|
|
|
{
|
2020-03-23 06:54:15 +01:00
|
|
|
sHeaterTuning currentSettings;
|
|
|
|
currentSettings.load();
|
|
|
|
|
|
|
|
bool requestHeaterUpdate = false;
|
|
|
|
requestHeaterUpdate |= currentSettings.sysVoltage != this->sysVoltage;
|
|
|
|
requestHeaterUpdate |= currentSettings.fanSensor != this->fanSensor;
|
|
|
|
requestHeaterUpdate |= currentSettings.glowDrive != this->glowDrive;
|
|
|
|
requestHeaterUpdate |= currentSettings.Pmin != this->Pmin;
|
|
|
|
requestHeaterUpdate |= currentSettings.Pmax != this->Pmax;
|
|
|
|
requestHeaterUpdate |= currentSettings.Fmin != this->Fmin;
|
|
|
|
requestHeaterUpdate |= currentSettings.Fmax != this->Fmax;
|
|
|
|
if(requestHeaterUpdate) {
|
|
|
|
reqHeaterCalUpdate();
|
|
|
|
}
|
2019-01-12 00:33:45 +01:00
|
|
|
// section for heater calibration params
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.begin("Calibration", false);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putUChar("minPump", Pmin);
|
|
|
|
preferences.putUChar("maxPump", Pmax);
|
|
|
|
preferences.putUShort("minFan", Fmin);
|
|
|
|
preferences.putUShort("maxFan", Fmax);
|
|
|
|
preferences.putUChar("systemVoltage", sysVoltage);
|
|
|
|
preferences.putUChar("fanSensor", fanSensor);
|
|
|
|
preferences.putUChar("glowDrive", glowDrive);
|
2019-07-21 13:17:54 +02:00
|
|
|
preferences.putUChar("lowVolts", lowVolts);
|
2020-03-23 06:54:15 +01:00
|
|
|
saveFloat("pumpCal", pumpCal);
|
2020-03-30 07:17:54 +02:00
|
|
|
preferences.putUShort("maxFuelUsage", maxFuelUsage);
|
|
|
|
preferences.putUShort("warnFuelUsage", warnFuelUsage);
|
2020-03-23 06:54:15 +01:00
|
|
|
saveFloat("tempOffset0", DS18B20probe[0].offset);
|
|
|
|
saveFloat("tempOffset1", DS18B20probe[1].offset);
|
|
|
|
saveFloat("tempOffset2", DS18B20probe[2].offset);
|
|
|
|
// preferences.putFloat("pumpCal", pumpCal);
|
|
|
|
// preferences.putFloat("tempOffset0", DS18B20probe[0].offset);
|
|
|
|
// preferences.putFloat("tempOffset1", DS18B20probe[1].offset);
|
|
|
|
// preferences.putFloat("tempOffset2", DS18B20probe[2].offset);
|
|
|
|
|
|
|
|
/*// START TESTO
|
|
|
|
for(int i=0; i<8; i++)
|
|
|
|
DS18B20probe[0].romCode.bytes[i] = i;
|
|
|
|
// END TESTO*/
|
|
|
|
|
2019-10-18 03:55:16 +02:00
|
|
|
preferences.putBytes("probeSerial0", DS18B20probe[0].romCode.bytes, 8);
|
|
|
|
preferences.putBytes("probeSerial1", DS18B20probe[1].romCode.bytes, 8);
|
|
|
|
preferences.putBytes("probeSerial2", DS18B20probe[2].romCode.bytes, 8);
|
2020-03-23 06:54:15 +01:00
|
|
|
// preferences.putFloat("tempOffsetBME", BME280probe.offset);
|
|
|
|
saveFloat("tempOffsetBME", BME280probe.offset);
|
2019-10-18 03:55:16 +02:00
|
|
|
preferences.putUChar("probeBMEPrmy", BME280probe.bPrimary);
|
2020-03-23 06:54:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*// START TESTO
|
|
|
|
preferences.getBytes("probeSerial0", DS18B20probe[0].romCode.bytes, 8);
|
|
|
|
DebugPort.printf("getBytes %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
|
DS18B20probe[0].romCode.bytes[0],
|
|
|
|
DS18B20probe[0].romCode.bytes[1],
|
|
|
|
DS18B20probe[0].romCode.bytes[2],
|
|
|
|
DS18B20probe[0].romCode.bytes[3],
|
|
|
|
DS18B20probe[0].romCode.bytes[4],
|
|
|
|
DS18B20probe[0].romCode.bytes[5],
|
|
|
|
DS18B20probe[0].romCode.bytes[6],
|
|
|
|
DS18B20probe[0].romCode.bytes[7]
|
|
|
|
);
|
|
|
|
|
|
|
|
uint64_t tVal = preferences.getULong64("probeSerial0", 0xffffffffffffffff);
|
|
|
|
unsigned char* pTst = (unsigned char*)&tVal;
|
|
|
|
DebugPort.printf("getULong %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
|
pTst[0],
|
|
|
|
pTst[1],
|
|
|
|
pTst[2],
|
|
|
|
pTst[3],
|
|
|
|
pTst[4],
|
|
|
|
pTst[5],
|
|
|
|
pTst[6],
|
|
|
|
pTst[7]
|
|
|
|
);
|
|
|
|
// END TESTO*/
|
|
|
|
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.end();
|
2019-09-22 01:03:42 +02:00
|
|
|
|
2019-09-25 09:27:43 +02:00
|
|
|
// for(int i=0; i<3; i++) {
|
|
|
|
// DebugPort.printf("Wr Probe[%d] %02X:%02X:%02X:%02X:%02X:%02X\r\n",
|
|
|
|
// i,
|
2019-10-18 03:55:16 +02:00
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[5],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[4],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[3],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[2],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[1],
|
|
|
|
// DS18B20probe[i].romCode.fields.serial_number[0]
|
2019-09-25 09:27:43 +02:00
|
|
|
// );
|
|
|
|
// }
|
2019-01-12 00:33:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-16 13:12:29 +02:00
|
|
|
sTimer::load()
|
2019-01-12 02:19:55 +01:00
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-01-12 00:33:45 +01:00
|
|
|
char SectionName[16];
|
2019-05-16 13:12:29 +02:00
|
|
|
sprintf(SectionName, "timer%d", timerID+1);
|
2019-01-12 02:19:55 +01:00
|
|
|
preferences.begin(SectionName, false);
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("startHour", start.hour, 0, s8inBounds, 0, 23);
|
|
|
|
validatedLoad("startMin", start.min, 0, s8inBounds, 0, 59);
|
|
|
|
validatedLoad("stopHour", stop.hour, 0, s8inBounds, 0, 23);
|
|
|
|
validatedLoad("stopMin", stop.min, 0, s8inBounds, 0, 59);
|
|
|
|
validatedLoad("enabled", enabled, 0, u8inBounds, 0, 255); // all 8 bits used!
|
|
|
|
validatedLoad("repeat", repeat, 0, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("temperature", temperature, 22, u8inBounds, 8, 35);
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-16 13:12:29 +02:00
|
|
|
sTimer::save()
|
2019-01-12 00:33:45 +01:00
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-01-12 00:33:45 +01:00
|
|
|
char SectionName[16];
|
2019-05-16 13:12:29 +02:00
|
|
|
sprintf(SectionName, "timer%d", timerID+1);
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.begin(SectionName, false);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putChar("startHour", start.hour);
|
|
|
|
preferences.putChar("startMin", start.min);
|
|
|
|
preferences.putChar("stopHour", stop.hour);
|
|
|
|
preferences.putChar("stopMin", stop.min);
|
|
|
|
preferences.putUChar("enabled", enabled);
|
|
|
|
preferences.putUChar("repeat", repeat);
|
|
|
|
preferences.putUChar("temperature", temperature);
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sUserSettings::load()
|
2019-01-12 00:33:45 +01:00
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.begin("user", false);
|
2019-06-06 03:32:43 +02:00
|
|
|
validatedLoad("dimTime", dimTime, 60000, -600000, 600000);
|
|
|
|
validatedLoad("menuTimeout", menuTimeout, 60000, 0, 300000);
|
2019-08-25 22:37:41 +02:00
|
|
|
validatedLoad("thermoTimeout", ExtThermoTimeout, 0, 0, 3600000);
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("degF", degF, 0, u8inBounds, 0, 1);
|
2019-06-06 03:32:43 +02:00
|
|
|
validatedLoad("thermostat", useThermostat, 1, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("thermoMethod", ThermostatMethod, 0, u8inBounds, 0, 255);
|
|
|
|
// catch and migrate old combined method & window
|
|
|
|
if(ThermostatMethod & 0xFC) {
|
|
|
|
float defVal = float(ThermostatMethod>>2) * 0.1f;
|
|
|
|
validatedLoad("thermoWindow", ThermostatWindow, defVal, 0.2f, 10.0f);
|
|
|
|
preferences.putUChar("thermoMethod", ThermostatMethod & 0x03); // strip old window
|
|
|
|
}
|
|
|
|
validatedLoad("thermoWindow", ThermostatWindow, 1.0f, 0.2f, 10.f);
|
|
|
|
DebugPort.printf("2) Window = %f\r\n", ThermostatWindow);
|
2019-10-31 23:24:58 +01:00
|
|
|
validatedLoad("frostOn", FrostOn, 0, u8inBounds, 0, 10);
|
|
|
|
validatedLoad("frostRise", FrostRise, 5, u8inBounds, 0, 20);
|
2019-12-15 07:58:11 +01:00
|
|
|
validatedLoad("enableWifi", wifiMode, 1, u8inBounds, 0, 3);
|
2019-09-07 15:48:46 +02:00
|
|
|
validatedLoad("enableOTA", enableOTA, 0, u8inBounds, 0, 1);
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("cyclicStop", cyclic.Stop, 0, s8inBounds, 0, 10);
|
|
|
|
validatedLoad("cyclicStart", cyclic.Start, -1, s8inBounds, -20, 0);
|
2019-06-02 14:47:35 +02:00
|
|
|
uint8_t tVal;
|
2019-08-07 14:04:20 +02:00
|
|
|
validatedLoad("GPIOinMode", tVal, 0, u8inBounds, 0, 255);
|
|
|
|
if(tVal <= 4) {
|
|
|
|
// migrate old GPIO input mode
|
2019-08-08 22:13:02 +02:00
|
|
|
GPIO.in1Mode = CGPIOin1::Disabled;
|
|
|
|
GPIO.in2Mode = CGPIOin2::Disabled;
|
2019-08-07 14:04:20 +02:00
|
|
|
switch(tVal) {
|
2019-08-10 07:57:46 +02:00
|
|
|
case 1: GPIO.in1Mode = CGPIOin1::Start; GPIO.in2Mode = CGPIOin2::Stop; break;
|
|
|
|
case 2: GPIO.in1Mode = CGPIOin1::Run; GPIO.in2Mode = CGPIOin2::Thermostat; break;
|
|
|
|
case 3: GPIO.in1Mode = CGPIOin1::StartStop; break;
|
2019-08-08 22:13:02 +02:00
|
|
|
case 4: GPIO.in2Mode = CGPIOin2::Thermostat; break;
|
2019-08-07 14:04:20 +02:00
|
|
|
}
|
|
|
|
preferences.putUChar("GPIOinMode", 0xff); // cancel old
|
|
|
|
preferences.putUChar("GPIOin1Mode", GPIO.in1Mode); // set new
|
|
|
|
preferences.putUChar("GPIOin2Mode", GPIO.in2Mode); // set new
|
|
|
|
}
|
2020-03-31 10:46:25 +02:00
|
|
|
validatedLoad("GPIOin1Mode", tVal, 0, u8inBounds, 0, 4); GPIO.in1Mode = (CGPIOin1::Modes)tVal;
|
|
|
|
validatedLoad("GPIOin2Mode", tVal, 0, u8inBounds, 0, 3); GPIO.in2Mode = (CGPIOin2::Modes)tVal;
|
2019-08-07 14:04:20 +02:00
|
|
|
validatedLoad("GPIOoutMode", tVal, 0, u8inBounds, 0, 255);
|
|
|
|
if(tVal <= 2) {
|
|
|
|
// migrate old GPIO output mode
|
2019-08-08 22:13:02 +02:00
|
|
|
GPIO.out1Mode = CGPIOout1::Disabled;
|
|
|
|
GPIO.out2Mode = CGPIOout2::Disabled;
|
2019-08-07 14:04:20 +02:00
|
|
|
switch(tVal) {
|
2019-08-08 22:13:02 +02:00
|
|
|
case 1: GPIO.out1Mode = CGPIOout1::Status; break;
|
|
|
|
case 2: GPIO.out1Mode = CGPIOout1::User; GPIO.out2Mode = CGPIOout2::User; break;
|
2019-08-07 14:04:20 +02:00
|
|
|
}
|
|
|
|
preferences.putUChar("GPIOoutMode", 0xff); // cancel old
|
|
|
|
preferences.putUChar("GPIOout1Mode", GPIO.out1Mode); // set new
|
|
|
|
preferences.putUChar("GPIOout2Mode", GPIO.out2Mode); // set new
|
|
|
|
}
|
2020-03-23 06:54:15 +01:00
|
|
|
validatedLoad("GPIOout1Mode", tVal, 0, u8inBounds, 0, 4); GPIO.out1Mode = (CGPIOout1::Modes)tVal;
|
|
|
|
validatedLoad("GPIOout2Mode", tVal, 0, u8inBounds, 0, 3); GPIO.out2Mode = (CGPIOout2::Modes)tVal;
|
2019-10-30 11:48:25 +01:00
|
|
|
validatedLoad("GPIOout1Thresh", GPIO.thresh[0], 0, s8inBounds, -50, 50);
|
|
|
|
validatedLoad("GPIOout2Thresh", GPIO.thresh[1], 0, s8inBounds, -50, 50);
|
2019-08-08 22:13:02 +02:00
|
|
|
validatedLoad("GPIOalgMode", tVal, 0, u8inBounds, 0, 2); GPIO.algMode = (CGPIOalg::Modes)tVal;
|
2019-06-06 03:32:43 +02:00
|
|
|
validatedLoad("MenuOnTimeout", HomeMenu.onTimeout, 0, u8inBounds, 0, 3);
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("MenuonStart", HomeMenu.onStart, 0, u8inBounds, 0, 3);
|
|
|
|
validatedLoad("MenuonStop", HomeMenu.onStop, 0, u8inBounds, 0, 3);
|
|
|
|
validatedLoad("FrameRate", FrameRate, 1000, u16inBounds, 300, 1500);
|
2019-06-16 01:09:29 +02:00
|
|
|
validatedLoad("JSONsingle", JSON.singleElement, 0, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("JSONLF", JSON.LF, 0, u8inBounds, 0, 1);
|
|
|
|
validatedLoad("JSONpad", JSON.padding, 0, u8inBounds, 0, 1);
|
2019-09-15 04:51:51 +02:00
|
|
|
validatedLoad("menuMode", menuMode, 0, u8inBounds, 0, 2);
|
2019-09-07 15:48:46 +02:00
|
|
|
validatedLoad("Clock12hr", clock12hr, 0, u8inBounds, 0, 1);
|
2019-09-17 12:07:57 +02:00
|
|
|
validatedLoad("holdPassword", holdPassword, 0, u8inBounds, 0, 1);
|
2020-01-13 09:48:32 +01:00
|
|
|
validatedLoad("humidityStart", humidityStart, 0, u8inBounds, 0, 100);
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-06 03:32:43 +02:00
|
|
|
sUserSettings::save()
|
2019-01-12 00:33:45 +01:00
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.begin("user", false);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putLong("dimTime", dimTime);
|
|
|
|
preferences.putLong("menuTimeout", menuTimeout);
|
2019-08-25 22:37:41 +02:00
|
|
|
preferences.putLong("thermoTimeout", ExtThermoTimeout);
|
2019-06-06 03:32:43 +02:00
|
|
|
preferences.putUChar("thermostat", useThermostat);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putUChar("degF", degF);
|
|
|
|
preferences.putUChar("thermoMethod", ThermostatMethod);
|
2020-03-23 06:54:15 +01:00
|
|
|
// preferences.putFloat("thermoWindow", ThermostatWindow);
|
|
|
|
saveFloat("thermoWindow", ThermostatWindow);
|
2019-10-31 23:24:58 +01:00
|
|
|
preferences.putUChar("frostOn", FrostOn);
|
|
|
|
preferences.putUChar("frostRise", FrostRise);
|
2019-12-15 07:58:11 +01:00
|
|
|
preferences.putUChar("enableWifi", wifiMode);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putUChar("enableOTA", enableOTA);
|
|
|
|
preferences.putChar("cyclicStop", cyclic.Stop);
|
|
|
|
preferences.putChar("cyclicStart",cyclic.Start);
|
2019-08-07 14:04:20 +02:00
|
|
|
preferences.putUChar("GPIOin1Mode", GPIO.in1Mode);
|
|
|
|
preferences.putUChar("GPIOin2Mode", GPIO.in2Mode);
|
|
|
|
preferences.putUChar("GPIOout1Mode", GPIO.out1Mode);
|
|
|
|
preferences.putUChar("GPIOout2Mode", GPIO.out2Mode);
|
2019-10-30 11:48:25 +01:00
|
|
|
preferences.putChar("GPIOout1Thresh", GPIO.thresh[0]);
|
|
|
|
preferences.putChar("GPIOout2Thresh", GPIO.thresh[1]);
|
2019-06-02 14:47:35 +02:00
|
|
|
preferences.putUChar("GPIOalgMode", GPIO.algMode);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putUChar("MenuOnTimeout", HomeMenu.onTimeout);
|
|
|
|
preferences.putUChar("MenuonStart", HomeMenu.onStart);
|
|
|
|
preferences.putUChar("MenuonStop", HomeMenu.onStop);
|
|
|
|
preferences.putUShort("FrameRate", FrameRate);
|
2019-06-16 01:09:29 +02:00
|
|
|
preferences.putUChar("JSONsingle", JSON.singleElement);
|
|
|
|
preferences.putUChar("JSONLF", JSON.LF);
|
|
|
|
preferences.putUChar("JSONpad", JSON.padding);
|
2019-09-15 04:51:51 +02:00
|
|
|
preferences.putUChar("menuMode", menuMode);
|
2019-09-07 15:48:46 +02:00
|
|
|
preferences.putUChar("Clock12hr", clock12hr);
|
2019-09-17 12:07:57 +02:00
|
|
|
preferences.putUChar("holdPassword", holdPassword);
|
2020-01-13 09:48:32 +01:00
|
|
|
preferences.putUChar("humidityStart", humidityStart);
|
2019-01-12 00:33:45 +01:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-05-12 12:15:18 +02:00
|
|
|
void
|
2019-05-16 13:12:29 +02:00
|
|
|
sMQTTparams::load()
|
2019-05-12 12:15:18 +02:00
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-05-12 12:15:18 +02:00
|
|
|
preferences.begin("mqtt", false);
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("enabled", enabled, 0, u8inBounds, 0, 1);
|
2019-09-01 09:35:12 +02:00
|
|
|
validatedLoad("port", port, 1883, u16inBounds, 0, 0xffff);
|
2019-08-31 09:34:56 +02:00
|
|
|
validatedLoad("qos", qos, 0, u8inBounds, 0, 2);
|
2020-03-23 06:54:15 +01:00
|
|
|
validatedLoad("host", host, 127, "broker");
|
|
|
|
validatedLoad("username", username, 31, "username");
|
|
|
|
validatedLoad("password", password, 31, "password");
|
2019-10-18 03:55:16 +02:00
|
|
|
validatedLoad("topic", topicPrefix, 31, "Afterburner");
|
2019-05-12 12:15:18 +02:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-16 13:12:29 +02:00
|
|
|
sMQTTparams::save()
|
2019-05-12 12:15:18 +02:00
|
|
|
{
|
2019-05-16 13:12:29 +02:00
|
|
|
// **** MAX LENGTH is 15 for names ****
|
2019-05-12 12:15:18 +02:00
|
|
|
preferences.begin("mqtt", false);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putUChar("enabled", enabled);
|
|
|
|
preferences.putUShort("port", port);
|
2019-08-31 09:34:56 +02:00
|
|
|
preferences.putUChar("qos", qos);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putString("host", host);
|
|
|
|
preferences.putString("username", username);
|
|
|
|
preferences.putString("password", password);
|
2019-10-18 03:55:16 +02:00
|
|
|
preferences.putString("topic", topicPrefix);
|
2019-05-12 12:15:18 +02:00
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:12:29 +02:00
|
|
|
bool
|
|
|
|
sMQTTparams::valid()
|
2019-01-12 02:19:55 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:12:29 +02:00
|
|
|
void
|
|
|
|
sCredentials::load()
|
|
|
|
{
|
|
|
|
// **** MAX LENGTH is 15 for names ****
|
|
|
|
preferences.begin("credentials", false);
|
2020-04-07 23:51:52 +02:00
|
|
|
validatedLoad("SSID", APSSID, 31, "Afterburner");
|
2019-05-16 13:12:29 +02:00
|
|
|
validatedLoad("APpassword", APpassword, 31, "thereisnospoon");
|
|
|
|
validatedLoad("webUpdateUser", webUpdateUsername, 31, "Afterburner");
|
|
|
|
validatedLoad("webUpdatePass", webUpdatePassword, 31, "BurnBabyBurn");
|
2020-05-09 11:17:21 +02:00
|
|
|
validatedLoad("webUser", webUsername, 31, "");
|
|
|
|
validatedLoad("webPass", webPassword, 31, "");
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.end();
|
2019-01-18 21:15:02 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:12:29 +02:00
|
|
|
void
|
|
|
|
sCredentials::save()
|
|
|
|
{
|
|
|
|
// **** MAX LENGTH is 15 for names ****
|
|
|
|
preferences.begin("credentials", false);
|
2020-04-07 23:51:52 +02:00
|
|
|
preferences.putString("SSID", APSSID);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.putString("APpassword", APpassword);
|
|
|
|
preferences.putString("webUpdateUser", webUpdateUsername);
|
|
|
|
preferences.putString("webUpdatePass", webUpdatePassword);
|
2020-04-22 08:21:24 +02:00
|
|
|
preferences.putString("webUser", webUsername);
|
|
|
|
preferences.putString("webPass", webPassword);
|
2019-05-16 13:12:29 +02:00
|
|
|
preferences.end();
|
2019-01-12 02:19:55 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:12:29 +02:00
|
|
|
bool
|
|
|
|
sCredentials::valid()
|
2019-01-12 02:19:55 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-06 03:32:43 +02:00
|
|
|
void toggle(bool& ref)
|
|
|
|
{
|
|
|
|
ref = !ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggle(uint8_t& ref)
|
|
|
|
{
|
|
|
|
ref = ref ? 0 : 1;
|
|
|
|
}
|
2019-07-24 22:06:47 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
sHourMeter::save()
|
|
|
|
{
|
|
|
|
// **** MAX LENGTH is 15 for names ****
|
|
|
|
preferences.begin("hourmeter", false);
|
|
|
|
preferences.putULong("RunTime", RunTime);
|
|
|
|
preferences.putULong("GlowTime", GlowTime);
|
|
|
|
preferences.end();
|
2019-07-25 14:31:31 +02:00
|
|
|
DebugPort.printf("Hourmeter NV save: Run=%d, Glow=%d\r\n", RunTime, GlowTime);
|
2019-07-24 22:06:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sHourMeter::load()
|
|
|
|
{
|
|
|
|
// **** MAX LENGTH is 15 for names ****
|
|
|
|
preferences.begin("hourmeter", false);
|
|
|
|
validatedLoad("RunTime", RunTime, 0, 0, 0xffffffffL);
|
|
|
|
validatedLoad("GlowTime", GlowTime, 0, 0, 0xffffffffL);
|
|
|
|
preferences.end();
|
2019-07-25 14:31:31 +02:00
|
|
|
DebugPort.printf("Hourmeter NV read: Run=%d, Glow=%d\r\n", RunTime, GlowTime);
|
2020-03-23 06:54:15 +01:00
|
|
|
}
|