Added exponential mean to heater data.

Replaced char with int8_t - damn thing was unsigned!
Likewise uint8_t for unsigned char
Rework of webserver inbuilt management functions cross linked, work well
This commit is contained in:
Ray Jones 2019-07-06 23:46:20 +10:00
parent c20b309184
commit 1b4b6699c5
26 changed files with 881 additions and 596 deletions

View file

@ -15,5 +15,8 @@ board = esp32dev
framework = arduino
board_build.partitions = min_spiffs.csv
upload_speed = 921600
upload_port = COM14
upload_port = 192.168.20.40
upload_protocol = espota
upload_flags =
--port=3232
monitor_speed = 115200

View file

@ -105,6 +105,7 @@
#include "src/OLED/ScreenManager.h"
#include "src/OLED/KeyPad.h"
#include "src/Utility/TempSense.h"
#include "src/Utility/DataFilter.h"
#include <rom/rtc.h>
#include <esp_spiffs.h>
#include <SPIFFS.h>
@ -144,19 +145,19 @@ void manageCyclicMode();
void doStreaming();
void heaterOn();
void heaterOff();
void updateFilteredData();
// DS18B20 temperature sensor support
// Uses the RMT timeslot driver to operate as a one-wire bus
CTempSense TempSensor;
long lastTemperatureTime; // used to moderate DS18B20 access
float fFilteredTemperature = -100; // -100: force direct update uopn first pass
const float fAlpha = 0.95; // exponential mean alpha
int DS18B20holdoff = 2;
int BoardRevision = 0;
unsigned long lastAnimationTime; // used to sequence updates to LCD for animation
sFilteredData FilteredSamples;
CommStates CommState;
CTxManage TxManage(TxEnbPin, BlueWireSerial);
CModeratedFrame OEMCtrlFrame; // data packet received from heater in response to OEM controller packet
@ -396,6 +397,13 @@ void setup() {
timerAlarmEnable(watchdogTimer); //enable interrupt
#endif
FilteredSamples.ipVolts.setRounding(0.1);
FilteredSamples.GlowAmps.setRounding(0.01);
FilteredSamples.GlowVolts.setRounding(0.1);
FilteredSamples.Fan.setRounding(10);
FilteredSamples.Fan.setAlpha(0.7);
FilteredSamples.AmbientTemp.reset(-100.0);
delay(1000); // just to hold the splash screeen for while
}
@ -724,25 +732,22 @@ void loop()
DebugPort.printf("Skipped initial DS18B20 reading: %f\r\n", fTemperature);
} // first value upon sensor connect is bad
else {
// initialise filtered temperature upon very first pass
if(fFilteredTemperature < -90) { // avoid FP exactness issues - starts as -100 on boot
fFilteredTemperature = fTemperature; // prime with first *valid* reading
}
// exponential mean to stabilse readings
fFilteredTemperature = fFilteredTemperature * fAlpha + (1-fAlpha) * fTemperature;
FilteredSamples.AmbientTemp.update(fTemperature);
manageCyclicMode();
}
}
else {
DS18B20holdoff = 3;
fFilteredTemperature = -100;
}
FilteredSamples.AmbientTemp.reset(-100.0);
}
TempSensor.startConvert(); // request a new conversion, will be ready by the time we loop back around
ScreenManager.reqUpdate();
}
updateFilteredData();
updateJSONclients(bReportJSONData);
CommState.set(CommStates::Idle);
NVstore.doSave(); // now is a good time to store to the NV storage, well away from any blue wire activity
@ -769,7 +774,7 @@ void manageCyclicMode()
const sCyclicThermostat& cyclic = NVstore.getUserSettings().cyclic;
if(cyclic.Stop && bUserON) { // cyclic mode enabled, and user has started heater
int stopDeltaT = cyclic.Stop + 1; // bump up by 1 degree - no point invoking at 1 deg over!
float deltaT = fFilteredTemperature - getDemandDegC();
float deltaT = FilteredSamples.AmbientTemp.getValue() - getDemandDegC();
// DebugPort.printf("Cyclic=%d bUserOn=%d deltaT=%d\r\n", cyclic, bUserON, deltaT);
// ensure we cancel user ON mode if heater throws an error
@ -853,13 +858,13 @@ void heaterOff()
}
bool reqTemp(unsigned char newTemp, bool save)
bool reqTemp(uint8_t newTemp, bool save)
{
if(bHasOEMController)
return false;
unsigned char max = DefaultBTCParams.getTemperature_Max();
unsigned char min = DefaultBTCParams.getTemperature_Min();
uint8_t max = DefaultBTCParams.getTemperature_Max();
uint8_t min = DefaultBTCParams.getTemperature_Min();
if(newTemp >= max)
newTemp = max;
if(newTemp <= min)
@ -878,7 +883,7 @@ bool reqTemp(unsigned char newTemp, bool save)
bool reqTempDelta(int delta)
{
unsigned char newTemp;
uint8_t newTemp;
if(getThermostatModeActive())
newTemp = demandDegC + delta;
else
@ -892,7 +897,7 @@ bool reqThermoToggle()
return setThermostatMode(getThermostatModeActive() ? 0 : 1);
}
bool setThermostatMode(unsigned char val)
bool setThermostatMode(uint8_t val)
{
if(bHasOEMController)
return false;
@ -957,8 +962,8 @@ uint8_t getDemandDegC()
void setDemandDegC(uint8_t val)
{
unsigned char max = DefaultBTCParams.getTemperature_Max();
unsigned char min = DefaultBTCParams.getTemperature_Min();
uint8_t max = DefaultBTCParams.getTemperature_Max();
uint8_t min = DefaultBTCParams.getTemperature_Min();
BOUNDSLIMIT(val, min, max);
demandDegC = val;
}
@ -984,7 +989,7 @@ float getTemperatureDesired()
float getTemperatureSensor()
{
return fFilteredTemperature;
return FilteredSamples.AmbientTemp.getValue();
}
void setPumpMin(float val)
@ -1001,7 +1006,7 @@ void setPumpMax(float val)
NVstore.setHeaterTuning(tuning);
}
void setFanMin(short cVal)
void setFanMin(uint16_t cVal)
{
sHeaterTuning tuning = NVstore.getHeaterTuning();
if(INBOUNDS(cVal, 500, 5000))
@ -1009,7 +1014,7 @@ void setFanMin(short cVal)
NVstore.setHeaterTuning(tuning);
}
void setFanMax(short cVal)
void setFanMax(uint16_t cVal)
{
sHeaterTuning tuning = NVstore.getHeaterTuning();
if(INBOUNDS(cVal, 500, 5000))
@ -1017,7 +1022,7 @@ void setFanMax(short cVal)
NVstore.setHeaterTuning(tuning);
}
void setFanSensor(unsigned char cVal)
void setFanSensor(uint8_t cVal)
{
sHeaterTuning tuning = NVstore.getHeaterTuning();
if(INBOUNDS(cVal, 1, 2))
@ -1031,7 +1036,7 @@ void setSystemVoltage(float val) {
NVstore.setHeaterTuning(tuning);
}
void setGlowDrive(unsigned char val) {
void setGlowDrive(uint8_t val) {
sHeaterTuning tuning = NVstore.getHeaterTuning();
if(INBOUNDS(val, 1, 6))
tuning.glowDrive = val;
@ -1319,7 +1324,6 @@ int getBoardRevision()
void ShowOTAScreen(int percent, eOTAmodes updateType)
{
ScreenManager.showOTAMessage(percent, updateType);
feedWatchdog();
}
void feedWatchdog()
@ -1391,4 +1395,48 @@ void getGPIOinfo(sGPIO& info)
void simulateGPIOin(uint8_t newKey)
{
GPIOin.simulateKey(newKey);
}
float getBatteryVoltage()
{
#ifdef RAW_SAMPLES
return getHeaterInfo().getBattVoltage();
#else
return FilteredSamples.ipVolts.getValue();
#endif
}
float getGlowVolts()
{
#ifdef RAW_SAMPLES
return getHeaterInfo().getGlow_Voltage();
#else
return FilteredSamples.GlowVolts.getValue();
#endif
}
float getGlowCurrent()
{
#ifdef RAW_SAMPLES
return getHeaterInfo().getGlow_Current();
#else
return FilteredSamples.GlowAmps.getValue();
#endif
}
float getFanSpeed()
{
#ifdef RAW_SAMPLES
return getHeaterInfo().getFan_Actual();
#else
return FilteredSamples.Fan.getValue();
#endif
}
void updateFilteredData()
{
FilteredSamples.ipVolts.update(HeaterFrame2.getVoltage_Supply());
FilteredSamples.GlowVolts.update(HeaterFrame2.getGlowPlug_Voltage());
FilteredSamples.GlowAmps.update(HeaterFrame2.getGlowPlug_Current());
FilteredSamples.Fan.update(HeaterFrame2.getFan_Actual());
}

View file

@ -102,7 +102,7 @@ void C128x64_OLED::getTextExtents(const char* str, CRect& rect)
rect.height = 0;
if(m_pFontInfo) {
while(*str) {
unsigned char c = (unsigned char)*str++;
uint8_t c = (uint8_t)*str++;
if(c >= m_pFontInfo->StartChar && c <= m_pFontInfo->EndChar) {
const FONT_CHAR_INFO* pCharInfo = &m_pFontInfo->pCharInfo[c - m_pFontInfo->StartChar];
// and extract info from flash (program) storage
@ -123,7 +123,7 @@ void C128x64_OLED::getTextExtents(const char* str, CRect& rect)
}
void
C128x64_OLED::drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize)
C128x64_OLED::drawDotFactoryChar(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize)
{
#ifdef DEBUG_FONT
char pr = c;
@ -140,7 +140,7 @@ C128x64_OLED::drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t
// point to info for selected character
const FONT_CHAR_INFO* pCharInfo = &pFontDescriptor->pCharInfo[c - pFontDescriptor->StartChar];
// and extract info from flash (program) storage
unsigned char* addr = (unsigned char*)&pCharInfo->Offset;
uint8_t* addr = (uint8_t*)&pCharInfo->Offset;
// uint8_t LSB = pgm_read_byte(&pCharInfo->Offset);
uint8_t LSB = pgm_read_byte(addr++);
uint8_t MSB = pgm_read_byte(addr);

View file

@ -42,7 +42,7 @@ public:
C128x64_OLED(int8_t DC, int8_t CS, int8_t RST); // Hardware SPI constructor
C128x64_OLED(int8_t SDA, int8_t SCL); // I2C constructor
void drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize);
void drawDotFactoryChar(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize);
void setFontInfo(const FONT_INFO* pFontInfo) { m_pFontInfo = pFontInfo; };
void offsetCursor(int16_t x, int16_t y) {
cursor_x += x;

View file

@ -29,9 +29,9 @@ class CProtocolPackage;
class CBasicScreen : public CScreenHeader
{
unsigned long _showSetModeTime;
unsigned char _feedbackType;
uint8_t _feedbackType;
unsigned long _showModeTime;
unsigned char _nModeSel;
uint8_t _nModeSel;
void showRunState();
public:
CBasicScreen(C128x64_OLED& display, CScreenManager& mgr);

View file

@ -30,7 +30,7 @@ class CScreenManager;
class CFontDumpScreen : public CScreen
{
unsigned char _startChar;
uint8_t _startChar;
void _initUI();
public:
CFontDumpScreen(C128x64_OLED& display, CScreenManager& mgr);

View file

@ -30,7 +30,7 @@ class CScreenManager;
class CFuelMixtureScreen : public CPasswordScreen {
float adjPump[2];
short adjFan[2];
uint16_t adjFan[2];
int _rowSel;
int _colSel;
void _adjustSetting(int dir);

View file

@ -76,7 +76,7 @@ CScreenHeader::show()
// WiFi icon is updated in animate()
// battery
showBatteryIcon(getHeaterInfo().getBattVoltage());
showBatteryIcon(getBatteryVoltage());
// clock
showTime();

View file

@ -58,7 +58,7 @@
// Identifier: DieselSplash
// Draw Mode: Horizontal
//
/*const unsigned char DieselSplash [] PROGMEM = {
/*const uint8_t DieselSplash [] PROGMEM = {
// 'Splash3, 128x64px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -128,7 +128,7 @@
*/
const unsigned char DieselSplash [] PROGMEM =
const uint8_t DieselSplash [] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
@ -571,7 +571,11 @@ void
CScreenManager::showOTAMessage(int percent, eOTAmodes updateType)
{
static int prevPercent = -1;
if(percent != prevPercent) {
static long prevTime = millis();
long tDelta = millis() - prevTime;
if(percent != prevPercent && tDelta > 500) {
prevTime = millis();
_pDisplay->clearDisplay();
_pDisplay->setCursor(64,22);
switch(updateType) {

View file

@ -44,7 +44,7 @@ typedef struct {
uint8_t EndChar; // End character
uint8_t SpaceWidth;
const FONT_CHAR_INFO* pCharInfo; // Character descriptor array
const unsigned char* pBitmaps; // Character bitmap array
const uint8_t* pBitmaps; // Character bitmap array
} FONT_INFO;
#endif

View file

@ -24,7 +24,7 @@
#include "../Screen.h"
// 'Thermometer', 8x50px
const unsigned char bodyThermometerIcon [] PROGMEM = {
const uint8_t bodyThermometerIcon [] PROGMEM = {
0x00, //
0x18, // ##
0x24, // # #
@ -78,7 +78,7 @@ const unsigned char bodyThermometerIcon [] PROGMEM = {
const BITMAP_INFO BodyThermometerIconInfo(8, 50, bodyThermometerIcon);
// 'ThermometerActual', 8x50px
const unsigned char ambientThermometerIcon [] PROGMEM = {
const uint8_t ambientThermometerIcon [] PROGMEM = {
0x00, //
0x18, // ##
0x24, // # #
@ -133,7 +133,7 @@ const BITMAP_INFO AmbientThermometerIconInfo(8, 50, ambientThermometerIcon);
// 'ThermoPtr', 3x5px
const unsigned char thermoPtr [] PROGMEM = {
const uint8_t thermoPtr [] PROGMEM = {
0x80, // #
0xc0, // ##
0xe0, // ###
@ -143,7 +143,7 @@ const unsigned char thermoPtr [] PROGMEM = {
const BITMAP_INFO ThermoPtrIconInfo(3, 5, thermoPtr);
// 'ThermoPtr', 3x5px
const unsigned char thermoOpenPtr [] PROGMEM = {
const uint8_t thermoOpenPtr [] PROGMEM = {
0x80, // #
0x40, // #
0x20, // #
@ -153,7 +153,7 @@ const unsigned char thermoOpenPtr [] PROGMEM = {
const BITMAP_INFO ThermoOpenPtrIconInfo(3, 5, thermoOpenPtr);
// 'ThermoPtrHigh', 3x3px
const unsigned char thermoPtrLow [] PROGMEM = {
const uint8_t thermoPtrLow [] PROGMEM = {
0xe0, // ####
0x60, // ##
0x20, // #
@ -161,7 +161,7 @@ const unsigned char thermoPtrLow [] PROGMEM = {
const BITMAP_INFO ThermoPtrLowIconInfo(3, 3, thermoPtrLow);
// 'ThermoPtrLow', 3x3px
const unsigned char thermoPtrHigh [] PROGMEM = {
const uint8_t thermoPtrHigh [] PROGMEM = {
0x20, // #
0x60, // ##
0xe0 // ###
@ -169,7 +169,7 @@ const unsigned char thermoPtrHigh [] PROGMEM = {
const BITMAP_INFO ThermoPtrHighIconInfo(3, 3, thermoPtrHigh);
// 'Bluetooth icon', 6x11px
const unsigned char BTicon [] PROGMEM = {
const uint8_t BTicon [] PROGMEM = {
0x20, // #
0x30, // ##
0x28, // # #
@ -185,7 +185,7 @@ const unsigned char BTicon [] PROGMEM = {
const BITMAP_INFO BluetoothIconInfo(6, 11, BTicon);
// 'wifiIcon', 13x10px
const unsigned char wifiIcon [] PROGMEM = {
const uint8_t wifiIcon [] PROGMEM = {
0x1f, 0xc0, // #######
0x20, 0x20, // # #
0x40, 0x10, // # #
@ -200,7 +200,7 @@ const unsigned char wifiIcon [] PROGMEM = {
const BITMAP_INFO WifiIconInfo(13, 10, wifiIcon);
// 'wifiIconWide', 13x10px
const unsigned char wifiwideIcon [] PROGMEM = {
const uint8_t wifiwideIcon [] PROGMEM = {
0x1f, 0xc0, 0x00, 0x00, // #######
0x20, 0x20, 0x00, 0x00, // # #
0x40, 0x10, 0x00, 0x00, // # #
@ -217,7 +217,7 @@ const BITMAP_INFO WifiWideIconInfo(25, 11, wifiwideIcon);
// 'wifiInIcon, 5x5px
const unsigned char wifiInIcon [] PROGMEM = {
const uint8_t wifiInIcon [] PROGMEM = {
0x70, // ###
0x70, // ###
0xf8, // #####
@ -227,7 +227,7 @@ const unsigned char wifiInIcon [] PROGMEM = {
const BITMAP_INFO WifiInIconInfo(5, 5, wifiInIcon);
// 'wifiOutIcon, 5x5px
const unsigned char wifiOutIcon [] PROGMEM = {
const uint8_t wifiOutIcon [] PROGMEM = {
0x20, // #
0x70, // ###
0xf8, // #####
@ -239,7 +239,7 @@ const unsigned char wifiOutIcon [] PROGMEM = {
const BITMAP_INFO WifiOutIconInfo(5, 5, wifiOutIcon);
// 'BatteryIcon', 15x10px
const unsigned char BatteryIcon [] PROGMEM = {
const uint8_t BatteryIcon [] PROGMEM = {
0x30, 0x18, // ## ##
0xff, 0xfe, // ###############
0x80, 0x02, // # #
@ -255,7 +255,7 @@ const BITMAP_INFO BatteryIconInfo(15, 10, BatteryIcon);
// 'GlowPlugIcon', 16x9px
const unsigned char GlowPlugIcon [] PROGMEM = {
const uint8_t GlowPlugIcon [] PROGMEM = {
0x71, 0xc7, // ### ### ###
0x0e, 0x38, // ### ###
0x14, 0x14, // # # # #
@ -270,14 +270,14 @@ const BITMAP_INFO GlowPlugIconInfo(16, 9, GlowPlugIcon);
// 'HeatRise', 17x2px
const unsigned char GlowHeatIcon [] PROGMEM = {
const uint8_t GlowHeatIcon [] PROGMEM = {
0x80, 0x00, 0x80, // # #
0x40, 0x01, 0x00 // # #
};
const BITMAP_INFO GlowHeatIconInfo(17, 2, GlowHeatIcon);
// 'Fan3_1a', 16x16px
const unsigned char FanIcon1 [] PROGMEM = {
const uint8_t FanIcon1 [] PROGMEM = {
0x03, 0xc0, // ####
0x04, 0x20, // # #
0x04, 0x20, // # #
@ -296,7 +296,7 @@ const unsigned char FanIcon1 [] PROGMEM = {
0x00, 0x00
};
// 'Fan3_2a', 16x16px
const unsigned char FanIcon2 [] PROGMEM = {
const uint8_t FanIcon2 [] PROGMEM = {
0x00, 0x78, // ####
0x00, 0x84, // # #
0x00, 0x84, // # #
@ -315,7 +315,7 @@ const unsigned char FanIcon2 [] PROGMEM = {
0x00, 0x78, // ####
};
// 'Fan3_3a', 16x16px
const unsigned char FanIcon3 [] PROGMEM = {
const uint8_t FanIcon3 [] PROGMEM = {
0x00, 0x00,
0x00, 0x00,
0x78, 0x1e, // #### ####
@ -334,7 +334,7 @@ const unsigned char FanIcon3 [] PROGMEM = {
0x03, 0xc0 // ####
};
// 'Fan3_4a', 16x16px
const unsigned char FanIcon4 [] PROGMEM = {
const uint8_t FanIcon4 [] PROGMEM = {
0x1e, 0x00, // ####
0x21, 0x00, // # #
0x21, 0x00, // # #
@ -359,7 +359,7 @@ const BITMAP_INFO FanIcon4Info(16, 16, FanIcon4);
// 'FuelIcon', 7x12px
const unsigned char FuelIcon [] PROGMEM = {
const uint8_t FuelIcon [] PROGMEM = {
0x10, // #
0x10, // #
0x38, // ###
@ -376,7 +376,7 @@ const unsigned char FuelIcon [] PROGMEM = {
const BITMAP_INFO FuelIconInfo(7, 12, FuelIcon);
// 'Target', 13x13px
const unsigned char TargetIcon [] PROGMEM = {
const uint8_t TargetIcon [] PROGMEM = {
0x0f, 0x80, // #####
0x10, 0x40, // # #
0x20, 0x20, // # #
@ -394,7 +394,7 @@ const unsigned char TargetIcon [] PROGMEM = {
const BITMAP_INFO TargetIconInfo(13, 13, TargetIcon);
// 'repeat', 15x15px
const unsigned char repeatIcon [] PROGMEM = {
const uint8_t repeatIcon [] PROGMEM = {
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
@ -414,7 +414,7 @@ const unsigned char repeatIcon [] PROGMEM = {
const BITMAP_INFO RepeatIconInfo(15, 15, repeatIcon);
// 'timerID1', 15x15px
const unsigned char timerID1Icon [] PROGMEM = {
const uint8_t timerID1Icon [] PROGMEM = {
0x00, 0x00, //
0x00, 0x00, //
0x07, 0xc0, // #####
@ -434,7 +434,7 @@ const unsigned char timerID1Icon [] PROGMEM = {
const BITMAP_INFO TimerId1IconInfo(15, 15, timerID1Icon);
// 'timerID2', 15x15px
const unsigned char timerID2Icon [] PROGMEM = {
const uint8_t timerID2Icon [] PROGMEM = {
0x00, 0x00, //
0x00, 0x00, //
0x07, 0xc0, // #####
@ -454,7 +454,7 @@ const unsigned char timerID2Icon [] PROGMEM = {
const BITMAP_INFO TimerId2IconInfo(15, 15, timerID2Icon);
// 'timer', 15x15px
const unsigned char timerIcon [] PROGMEM = {
const uint8_t timerIcon [] PROGMEM = {
0x00, 0x00, //
0x00, 0x00, //
0x07, 0xc0, // #####
@ -474,7 +474,7 @@ const unsigned char timerIcon [] PROGMEM = {
const BITMAP_INFO TimerIconInfo(15, 15, timerIcon);
// 'large timer', 15x15px
const unsigned char largeTimerIcon[] PROGMEM =
const uint8_t largeTimerIcon[] PROGMEM =
{
0x07, 0xC0, // #####
0x19, 0x30, // ## # ##

View file

@ -27,17 +27,17 @@
#include "../Utility/macros.h"
unsigned short
uint16_t
CProtocol::CalcCRC(int len) const
{
// calculate a CRC-16/MODBUS checksum using the first 22 bytes of the data array
unsigned short wCRCWord = 0xFFFF;
uint16_t wCRCWord = 0xFFFF;
int wLength = len;
const unsigned char* pData = Data;
const uint8_t* pData = Data;
while (wLength--)
{
unsigned char nTemp = *pData++ ^ wCRCWord;
uint8_t nTemp = *pData++ ^ wCRCWord;
wCRCWord >>= 8;
wCRCWord ^= wCRCTable[nTemp];
}
@ -52,17 +52,17 @@ CProtocol::setCRC()
}
void
CProtocol::setCRC(unsigned short CRC)
CProtocol::setCRC(uint16_t CRC)
{
Data[22] = (CRC >> 8) & 0xff; // MSB of CRC in Data[22]
Data[23] = (CRC >> 0) & 0xff; // LSB of CRC in Data[23]
}
unsigned short
uint16_t
CProtocol::getCRC() const
{
unsigned short CRC;
uint16_t CRC;
CRC = Data[22]; // MSB of CRC in Data[22]
CRC <<= 8;
CRC |= Data[23]; // LSB of CRC in Data[23]
@ -73,8 +73,8 @@ CProtocol::getCRC() const
bool
CProtocol::verifyCRC(bool bSilent) const
{
unsigned short CRC = CalcCRC(22); // calculate CRC based on first 22 bytes
unsigned short FrameCRC = getCRC();
uint16_t CRC = CalcCRC(22); // calculate CRC based on first 22 bytes
uint16_t FrameCRC = getCRC();
bool bOK = (FrameCRC == CRC);
if(!bOK && !bSilent) {
DebugPort.printf("verifyCRC FAILED: calc: %04X data: %04X\r\n", CRC, FrameCRC);
@ -91,7 +91,7 @@ CProtocol::operator=(const CProtocol& rhs)
void
CProtocol::setFan_Min(short Speed)
CProtocol::setFan_Min(uint16_t Speed)
{
// Minimum speed set
Controller.MinFanRPM_MSB = (Speed >> 8) & 0xff;
@ -99,17 +99,17 @@ CProtocol::setFan_Min(short Speed)
}
void
CProtocol::setFan_Max(short Speed)
CProtocol::setFan_Max(uint16_t Speed)
{
// Minimum speed set
Controller.MaxFanRPM_MSB = (Speed >> 8) & 0xff;
Controller.MaxFanRPM_LSB = (Speed >> 0) & 0xff;
}
short
uint16_t
CProtocol::getFan_Min() const
{
short retval;
uint16_t retval;
// Minimum speed get
retval = Controller.MinFanRPM_MSB;
retval <<= 8;
@ -117,10 +117,10 @@ CProtocol::getFan_Min() const
return retval;
}
short
uint16_t
CProtocol::getFan_Max() const
{
short retval;
uint16_t retval;
// Maximum speed get
retval = Controller.MaxFanRPM_MSB;
retval <<= 8;
@ -128,11 +128,11 @@ CProtocol::getFan_Max() const
return retval;
}
short
uint16_t
CProtocol::getFan_Actual() const
{
// Rx side, actual
short retval;
uint16_t retval;
retval = Heater.FanRPM_MSB;
retval <<= 8;
retval |= Heater.FanRPM_LSB;
@ -140,7 +140,7 @@ CProtocol::getFan_Actual() const
}
void
CProtocol::setFan_Actual(short Speed) // Heater side, actual
CProtocol::setFan_Actual(uint16_t Speed) // Heater side, actual
{
// actual speed set
Heater.FanRPM_MSB = (Speed >> 8) & 0xff;
@ -150,7 +150,7 @@ CProtocol::setFan_Actual(short Speed) // Heater side, actual
float
CProtocol::getGlowPlug_Current() const // glow plug current
{
short val;
uint16_t val;
val = Heater.GlowPlugCurrent_MSB;
val <<= 8;
val |= Heater.GlowPlugCurrent_LSB;
@ -158,7 +158,7 @@ CProtocol::getGlowPlug_Current() const // glow plug current
}
void
CProtocol::setGlowPlug_Current(short ampsx100) // glow plug current
CProtocol::setGlowPlug_Current(uint16_t ampsx100) // glow plug current
{
Heater.GlowPlugCurrent_MSB = (ampsx100 >> 8) & 0xff;
Heater.GlowPlugCurrent_LSB = (ampsx100 >> 0) & 0xff;
@ -167,7 +167,7 @@ CProtocol::setGlowPlug_Current(short ampsx100) // glow plug current
float
CProtocol::getGlowPlug_Voltage() const // glow plug voltage
{
short val;
uint16_t val;
val = Heater.GlowPlugVoltage_MSB;
val <<= 8;
val |= Heater.GlowPlugVoltage_LSB;
@ -176,16 +176,16 @@ CProtocol::getGlowPlug_Voltage() const // glow plug voltage
void
CProtocol::setGlowPlug_Voltage(short voltsx10) // glow plug voltage
CProtocol::setGlowPlug_Voltage(uint16_t voltsx10) // glow plug voltage
{
Heater.GlowPlugVoltage_MSB = (voltsx10 >> 8) & 0xff;
Heater.GlowPlugVoltage_LSB = (voltsx10 >> 0) & 0xff;
}
short
uint16_t
CProtocol::getTemperature_HeatExchg() const // temperature of heat exchanger
{
short retval;
uint16_t retval;
retval = Heater.HeatExchgTemp_MSB;
retval <<= 8;
retval |= Heater.HeatExchgTemp_LSB;
@ -193,7 +193,7 @@ CProtocol::getTemperature_HeatExchg() const // temperature of heat exchanger
}
void
CProtocol::setTemperature_HeatExchg(short degC) // temperature of heat exchanger
CProtocol::setTemperature_HeatExchg(uint16_t degC) // temperature of heat exchanger
{
Heater.HeatExchgTemp_MSB = (degC >> 8) & 0xff;
Heater.HeatExchgTemp_LSB = (degC >> 0) & 0xff;
@ -203,7 +203,7 @@ float
CProtocol::getFan_Voltage() const // fan voltage
{
if(getRunState()) { // fan volatge sensing goes stupid when main heater relay turns off!
short val;
uint16_t val;
val = Heater.FanVoltage_MSB;
val <<= 8;
val |= Heater.FanVoltage_LSB;
@ -215,7 +215,7 @@ CProtocol::getFan_Voltage() const // fan voltage
void
CProtocol::setFan_Voltage(float volts) // fan voltage
{
short val = short(volts * 10);
uint16_t val = uint16_t(volts * 10);
Heater.FanVoltage_MSB = (val >> 8) & 0xff;
Heater.FanVoltage_LSB = (val >> 0) & 0xff;
}
@ -223,7 +223,7 @@ CProtocol::setFan_Voltage(float volts) // fan voltage
void
CProtocol::setVoltage_Supply(float volts)
{
short val = short(volts * 10);
uint16_t val = uint16_t(volts * 10);
Heater.SupplyV_MSB = (val >> 8) & 0xff;
Heater.SupplyV_LSB = (val >> 0) & 0xff;
}
@ -231,7 +231,7 @@ CProtocol::setVoltage_Supply(float volts)
float
CProtocol::getVoltage_SupplyRaw() const
{
short val = 0;
uint16_t val = 0;
val = Heater.SupplyV_MSB & 0xff;
val <<= 8;
val |= Heater.SupplyV_LSB & 0xff;

View file

@ -28,63 +28,63 @@
class CProtocol {
public:
union {
unsigned char Data[24];
uint8_t Data[24];
struct {
unsigned char Byte0; // [0] always 0x76
unsigned char Len; // [1] always 0x16 == 22
unsigned char Command; // [2] transient commands: 00: NOP, 0xa0 START, 0x05: STOP
unsigned char ActualTemperature; // [3] 1degC / digit
unsigned char DesiredDemand; // [4] typ. 1degC / digit, but also gets used for Fixed Hx demand too!
unsigned char MinPumpFreq; // [5] 0.1Hz/digit
unsigned char MaxPumpFreq; // [6] 0.1Hz/digit
unsigned char MinFanRPM_MSB; // [7] 16 bit - big endian MSB
unsigned char MinFanRPM_LSB; // [8] 16 bit - big endian LSB : 1 RPM / digit
unsigned char MaxFanRPM_MSB; // [9] 16 bit - big endian MSB
unsigned char MaxFanRPM_LSB; // [10] 16 bit - big endian LSB : 1 RPM / digit
unsigned char OperatingVoltage; // [11] 120, 240 : 0.1V/digit
unsigned char FanSensor; // [12] SN-1 or SN-2
unsigned char OperatingMode; // [13] 0x32:Thermostat, 0xCD:Fixed
unsigned char MinTemperature; // [14] Minimum settable temperature
unsigned char MaxTemperature; // [15] Maximum settable temperature
unsigned char GlowDrive; // [16] power to supply to glow plug
unsigned char Prime; // [17] 00: normal, 0x5A: fuel prime
unsigned char Unknown1_MSB; // [18] always 0x01
unsigned char Unknown1_LSB; // [19] always 0x2c "300 secs = max run without burn detected"?
unsigned char Unknown2_MSB; // [20] always 0x0d
unsigned char Unknown2_LSB; // [21] always 0xac "3500 ?"
unsigned char CRC_MSB; // [22]
unsigned char CRC_LSB; // [23]
uint8_t Byte0; // [0] always 0x76
uint8_t Len; // [1] always 0x16 == 22
uint8_t Command; // [2] transient commands: 00: NOP, 0xa0 START, 0x05: STOP
uint8_t ActualTemperature; // [3] 1degC / digit
uint8_t DesiredDemand; // [4] typ. 1degC / digit, but also gets used for Fixed Hx demand too!
uint8_t MinPumpFreq; // [5] 0.1Hz/digit
uint8_t MaxPumpFreq; // [6] 0.1Hz/digit
uint8_t MinFanRPM_MSB; // [7] 16 bit - big endian MSB
uint8_t MinFanRPM_LSB; // [8] 16 bit - big endian LSB : 1 RPM / digit
uint8_t MaxFanRPM_MSB; // [9] 16 bit - big endian MSB
uint8_t MaxFanRPM_LSB; // [10] 16 bit - big endian LSB : 1 RPM / digit
uint8_t OperatingVoltage; // [11] 120, 240 : 0.1V/digit
uint8_t FanSensor; // [12] SN-1 or SN-2
uint8_t OperatingMode; // [13] 0x32:Thermostat, 0xCD:Fixed
uint8_t MinTemperature; // [14] Minimum settable temperature
uint8_t MaxTemperature; // [15] Maximum settable temperature
uint8_t GlowDrive; // [16] power to supply to glow plug
uint8_t Prime; // [17] 00: normal, 0x5A: fuel prime
uint8_t Unknown1_MSB; // [18] always 0x01
uint8_t Unknown1_LSB; // [19] always 0x2c "300 secs = max run without burn detected"?
uint8_t Unknown2_MSB; // [20] always 0x0d
uint8_t Unknown2_LSB; // [21] always 0xac "3500 ?"
uint8_t CRC_MSB; // [22]
uint8_t CRC_LSB; // [23]
} Controller;
struct {
unsigned char Byte0; // always 0x76
unsigned char Len; // always 0x16 == 22 bytes
unsigned char RunState; // operating state
unsigned char ErrState; // 0: OFF, 1: ON, 2+ (E-0n + 1)
unsigned char SupplyV_MSB; // 16 bit - big endian MSB
unsigned char SupplyV_LSB; // 16 bit - big endian MSB : 0.1V / digit
unsigned char FanRPM_MSB; // 16 bit - big endian MSB
unsigned char FanRPM_LSB; // 16 bit - big endian LSB : 1 RPM / digit
unsigned char FanVoltage_MSB; // 16 bit - big endian MSB
unsigned char FanVoltage_LSB; // 16 bit - big endian LSB : 0.1V / digit
unsigned char HeatExchgTemp_MSB; // 16 bit - big endian MSB
unsigned char HeatExchgTemp_LSB; // 16 bit - big endian LSB : 1 degC / digit
unsigned char GlowPlugVoltage_MSB; // 16 bit - big endian MSB
unsigned char GlowPlugVoltage_LSB; // 16 bit - big endian LSB : 0.1V / digit
unsigned char GlowPlugCurrent_MSB; // 16 bit - big endian MSB
unsigned char GlowPlugCurrent_LSB; // 16 bit - big endian LSB : 10mA / digit
unsigned char ActualPumpFreq; // fuel pump freq.: 0.1Hz / digit
unsigned char StoredErrorCode; //
unsigned char Unknown1; // always 0x00
unsigned char FixedPumpFreq; // fixed mode frequency set point: 0.1Hz / digit
unsigned char Unknown2; // always 0x64 "100 ?"
unsigned char Unknown3; // always 0x00
unsigned char CRC_MSB;
unsigned char CRC_LSB;
uint8_t Byte0; // always 0x76
uint8_t Len; // always 0x16 == 22 bytes
uint8_t RunState; // operating state
uint8_t ErrState; // 0: OFF, 1: ON, 2+ (E-0n + 1)
uint8_t SupplyV_MSB; // 16 bit - big endian MSB
uint8_t SupplyV_LSB; // 16 bit - big endian MSB : 0.1V / digit
uint8_t FanRPM_MSB; // 16 bit - big endian MSB
uint8_t FanRPM_LSB; // 16 bit - big endian LSB : 1 RPM / digit
uint8_t FanVoltage_MSB; // 16 bit - big endian MSB
uint8_t FanVoltage_LSB; // 16 bit - big endian LSB : 0.1V / digit
uint8_t HeatExchgTemp_MSB; // 16 bit - big endian MSB
uint8_t HeatExchgTemp_LSB; // 16 bit - big endian LSB : 1 degC / digit
uint8_t GlowPlugVoltage_MSB; // 16 bit - big endian MSB
uint8_t GlowPlugVoltage_LSB; // 16 bit - big endian LSB : 0.1V / digit
uint8_t GlowPlugCurrent_MSB; // 16 bit - big endian MSB
uint8_t GlowPlugCurrent_LSB; // 16 bit - big endian LSB : 10mA / digit
uint8_t ActualPumpFreq; // fuel pump freq.: 0.1Hz / digit
uint8_t StoredErrorCode; //
uint8_t Unknown1; // always 0x00
uint8_t FixedPumpFreq; // fixed mode frequency set point: 0.1Hz / digit
uint8_t Unknown2; // always 0x64 "100 ?"
uint8_t Unknown3; // always 0x00
uint8_t CRC_MSB;
uint8_t CRC_LSB;
} Heater;
};
static const int CtrlMode = 1;
static const int HeatMode = 2;
const unsigned short wCRCTable[256] = {
const uint16_t wCRCTable[256] = {
0X0000, 0XC0C1, 0XC181, 0X0140, 0XC301, 0X03C0, 0X0280, 0XC241,
0XC601, 0X06C0, 0X0780, 0XC741, 0X0500, 0XC5C1, 0XC481, 0X0440,
0XCC01, 0X0CC0, 0X0D80, 0XCD41, 0X0F00, 0XCFC1, 0XCE81, 0X0E40,
@ -125,10 +125,10 @@ public:
void Init(int Txmode);
// CRC handlers
unsigned short CalcCRC(int len) const; // calculate the CRC upon len bytes
uint16_t CalcCRC(int len) const; // calculate the CRC upon len bytes
void setCRC(); // calculate and set the CRC in the buffer
void setCRC(unsigned short CRC); // set the CRC in the buffer
unsigned short getCRC() const; // extract CRC value from buffer
void setCRC(uint16_t CRC); // set the CRC in the buffer
uint16_t getCRC() const; // extract CRC value from buffer
bool verifyCRC(bool silent=false) const; // return true for CRC match
void setActiveMode() { Controller.Byte0 = 0x76; }; // this allows heater to save tuning params to EEPROM
@ -141,12 +141,12 @@ public:
int getRawCommand() const { return Controller.Command; };
void setRawCommand(int mode) { Controller.Command = mode; };
// Run state
unsigned char getRunState() const { return Heater.RunState; };
void setRunState(unsigned char state) { Heater.RunState = state; };
unsigned char getErrState() const { return Heater.ErrState; };
void setErrState(unsigned char state) { Heater.ErrState = state; };
unsigned char getStoredErrCode() const { return Heater.StoredErrorCode; };
void setStoredErrCode(unsigned char state) { Heater.StoredErrorCode = state; };
uint8_t getRunState() const { return Heater.RunState; };
void setRunState(uint8_t state) { Heater.RunState = state; };
uint8_t getErrState() const { return Heater.ErrState; };
void setErrState(uint8_t state) { Heater.ErrState = state; };
uint8_t getStoredErrCode() const { return Heater.StoredErrorCode; };
void setStoredErrCode(uint8_t state) { Heater.StoredErrorCode = state; };
//
float getVoltage_Supply() const;
float getVoltage_SupplyRaw() const;
@ -155,12 +155,12 @@ public:
void setSystemVoltage(float val);
// fan set/get
short getFan_Actual() const; // Heater side, actual
short getFan_Min() const; // Controller side, define min fan speed
short getFan_Max() const; // Controller side, define max fan speed
void setFan_Actual(short speed); // Heater side, actual
void setFan_Min(short speed); // Controller side, define min fan speed
void setFan_Max(short speed); // Controller side, define max fan speed
uint16_t getFan_Actual() const; // Heater side, actual
uint16_t getFan_Min() const; // Controller side, define min fan speed
uint16_t getFan_Max() const; // Controller side, define max fan speed
void setFan_Actual(uint16_t speed); // Heater side, actual
void setFan_Min(uint16_t speed); // Controller side, define min fan speed
void setFan_Max(uint16_t speed); // Controller side, define max fan speed
float getFan_Voltage() const; // fan voltage
void setFan_Voltage(float volts); // fan voltage
@ -175,26 +175,26 @@ public:
float getPump_Fixed() const { return float(Heater.FixedPumpFreq) * 0.1f; }; // Fixed mode pump frequency
void setPump_Prime(bool on) { Controller.Prime = on ? 0x5A : 0; };
// temperature set/get
void setHeaterDemand(unsigned char degC) { Controller.DesiredDemand = degC; };
void setTemperature_Min(unsigned char degC) { Controller.MinTemperature = degC; };
void setTemperature_Max(unsigned char degC) { Controller.MaxTemperature = degC; };
void setTemperature_Actual(unsigned char degC) { Controller.ActualTemperature = degC; };
unsigned char getHeaterDemand() const { return Controller.DesiredDemand; };
unsigned char getTemperature_Min() const { return Controller.MinTemperature; };
unsigned char getTemperature_Max() const { return Controller.MaxTemperature; };
unsigned char getTemperature_Actual() const { return Controller.ActualTemperature; };
void setHeaterDemand(uint8_t degC) { Controller.DesiredDemand = degC; };
void setTemperature_Min(uint8_t degC) { Controller.MinTemperature = degC; };
void setTemperature_Max(uint8_t degC) { Controller.MaxTemperature = degC; };
void setTemperature_Actual(uint8_t degC) { Controller.ActualTemperature = degC; };
uint8_t getHeaterDemand() const { return Controller.DesiredDemand; };
uint8_t getTemperature_Min() const { return Controller.MinTemperature; };
uint8_t getTemperature_Max() const { return Controller.MaxTemperature; };
uint8_t getTemperature_Actual() const { return Controller.ActualTemperature; };
void setThermostatModeProtocol(unsigned on);
bool isThermostat() const { return Controller.OperatingMode == 0x32; };
// glow plug
float getGlowPlug_Current() const; // glow plug current
float getGlowPlug_Voltage() const; // glow plug voltage
void setGlowPlug_Current(short ampsx100); // glow plug current
void setGlowPlug_Voltage(short voltsx10); // glow plug voltage
void setGlowDrive(unsigned char val) { Controller.GlowDrive = val; };
unsigned char getGlowDrive() const { return Controller.GlowDrive; };
void setGlowPlug_Current(uint16_t ampsx100); // glow plug current
void setGlowPlug_Voltage(uint16_t voltsx10); // glow plug voltage
void setGlowDrive(uint8_t val) { Controller.GlowDrive = val; };
uint8_t getGlowDrive() const { return Controller.GlowDrive; };
// heat exchanger
short getTemperature_HeatExchg() const; // temperature of heat exchanger
void setTemperature_HeatExchg(short degC); // temperature of heat exchanger
uint16_t getTemperature_HeatExchg() const; // temperature of heat exchanger
void setTemperature_HeatExchg(uint16_t degC); // temperature of heat exchanger
void DebugReport(const char* hdr, const char* ftr);
@ -233,8 +233,8 @@ public:
float getPump_Min() const { return Controller.getPump_Min(); };
float getPump_Max() const { return Controller.getPump_Max(); };
float getFan_Actual() const { return Heater.getFan_Actual(); };
short getFan_Min() const { return Controller.getFan_Min(); };
short getFan_Max() const { return Controller.getFan_Max(); };
uint16_t getFan_Min() const { return Controller.getFan_Min(); };
uint16_t getFan_Max() const { return Controller.getFan_Max(); };
float getFan_Voltage() const { return Heater.getFan_Voltage(); };
int getFan_Sensor() const { return Controller.Controller.FanSensor; };
float getGlowPlug_Power() const { return Heater.getGlowPlug_Current() * Heater.getGlowPlug_Voltage(); };

View file

@ -63,7 +63,7 @@ CSmartError::monitor(const CProtocol& heaterFrame)
// test the new run state value, comparing to previous
// detect abnormal transitions
void
CSmartError::monitor(unsigned char newRunState)
CSmartError::monitor(uint8_t newRunState)
{
// check if moving away from heater Idle state (S0)
// especially useful if an OEM controller exists
@ -110,7 +110,7 @@ CSmartError::monitor(unsigned char newRunState)
}
// return our smart error, if it exists, as the registered code
unsigned char
uint8_t
CSmartError::getError()
{
if(m_Error) {

View file

@ -22,16 +22,16 @@
#include "Protocol.h"
class CSmartError {
unsigned char m_prevRunState;
unsigned char m_Error;
uint8_t m_prevRunState;
uint8_t m_Error;
bool m_bInhibit;
public:
CSmartError();
void reset();
void inhibit();
void monitor(const CProtocol& heaterFrame);
void monitor(unsigned char runstate);
unsigned char getError();
void monitor(uint8_t runstate);
uint8_t getError();
};
extern CSmartError SmartError;

View file

@ -81,7 +81,7 @@ CTxManage::queueOffRequest(bool set)
}
void
CTxManage::queueRawCommand(unsigned char val)
CTxManage::queueRawCommand(uint8_t val)
{
_rawCommand = val;
}

View file

@ -32,7 +32,7 @@ public:
CTxManage(int TxGatePin, HardwareSerial& serial);
void queueOnRequest(bool set = true); // use false to remove repeating command
void queueOffRequest(bool set = true); // use false to remove repeating command
void queueRawCommand(unsigned char val);
void queueRawCommand(uint8_t val);
void PrepareFrame(const CProtocol& Frame, bool isBTCmaster);
void Start(unsigned long timenow);
bool CheckTx(unsigned long timenow);
@ -46,7 +46,7 @@ private:
bool m_bOffReq;
bool m_bTxPending;
int m_nTxGatePin;
unsigned char _rawCommand;
uint8_t _rawCommand;
unsigned long m_nStartTime;
};

View file

@ -36,7 +36,7 @@ void decodeJSONTimerDays(const char* ipStr)
if(INBOUNDS(timerIdx, 0, 13)) {
sTimer timer;
NVstore.getTimerInfo(timerIdx, timer);
unsigned char days = 0;
uint8_t days = 0;
if(strstr(dayInfo, "Next")) {
days = 0x80;
}

View file

@ -61,12 +61,12 @@ void interpretJsonCommand(char* pLine)
for(it = obj.begin(); it != obj.end(); ++it) {
if(strcmp("TempDesired", it->key) == 0) {
if( !reqTemp(it->value.as<unsigned char>(), false) ) { // this request is blocked if OEM controller active
if( !reqTemp(it->value.as<uint8_t>(), false) ) { // this request is blocked if OEM controller active
JSONmoderator.reset("TempDesired");
}
}
else if(strcmp("RunState", it->key) == 0) {
if(it->value.as<unsigned char>()) {
if(it->value.as<uint8_t>()) {
requestOn();
}
else {
@ -80,27 +80,29 @@ void interpretJsonCommand(char* pLine)
setPumpMax(it->value.as<float>());
}
else if(strcmp("FanMin", it->key) == 0) {
setFanMin(it->value.as<short>());
setFanMin(it->value.as<uint16_t>());
}
else if(strcmp("FanMax", it->key) == 0) {
setFanMax(it->value.as<short>());
setFanMax(it->value.as<uint16_t>());
}
else if(strcmp("CyclicTemp", it->key) == 0) {
setDemandDegC(it->value.as<unsigned char>()); // directly set demandDegC
setDemandDegC(it->value.as<uint8_t>()); // directly set demandDegC
}
else if((strcmp("CyclicOff", it->key) == 0) || (strcmp("ThermostatOvertemp", it->key) == 0)) {
sUserSettings us = NVstore.getUserSettings();
char val = it->value.as<char>();
if(val > 1) val--; // internal uses a 1 offset
if(INBOUNDS(val, 0, 10))
int8_t val = it->value.as<int8_t>();
if(INBOUNDS(val, 0, 10)) {
if(val > 1) val--; // internal uses a 1 offset
us.cyclic.Stop = val;
}
NVstore.setUserSettings(us);
}
else if((strcmp("CyclicOn", it->key) == 0) || (strcmp("ThermostatUndertemp", it->key) == 0)) {
sUserSettings us = NVstore.getUserSettings();
char val = it->value.as<char>();
if(INBOUNDS(val, -20, 0))
us.cyclic.Start = val;
int8_t val = it->value.as<int8_t>();
if(INBOUNDS(val, -20, 0)) {
us.cyclic.Start = val;
}
NVstore.setUserSettings(us);
}
else if(strcmp("ThermostatMethod", it->key) == 0) {
@ -118,7 +120,7 @@ void interpretJsonCommand(char* pLine)
NVstore.setUserSettings(settings);
}
else if(strcmp("Thermostat", it->key) == 0) {
if(!setThermostatMode(it->value.as<unsigned char>())) { // this request is blocked if OEM controller active
if(!setThermostatMode(it->value.as<uint8_t>())) { // this request is blocked if OEM controller active
JSONmoderator.reset("ThermoStat");
}
}
@ -136,7 +138,7 @@ void interpretJsonCommand(char* pLine)
setTime(it->value.as<const char*>());
}
else if(strcmp("PumpPrime", it->key) == 0) {
reqPumpPrime(it->value.as<unsigned char>());
reqPumpPrime(it->value.as<uint8_t>());
}
else if(strcmp("Refresh", it->key) == 0) {
resetJSONmoderator();
@ -175,7 +177,7 @@ void interpretJsonCommand(char* pLine)
TimerModerator.reset();
}
else if(strcmp("FanSensor", it->key) == 0) {
setFanSensor(it->value.as<unsigned char>());
setFanSensor(it->value.as<uint8_t>());
}
// MQTT parameters
else if(strcmp("MQuery", it->key) == 0) {
@ -183,12 +185,12 @@ void interpretJsonCommand(char* pLine)
}
else if(strcmp("MEn", it->key) == 0) {
sMQTTparams info = NVstore.getMQTTinfo();
info.enabled = it->value.as<unsigned char>();
info.enabled = it->value.as<uint8_t>();
NVstore.setMQTTinfo(info);
}
else if(strcmp("MPort", it->key) == 0) {
sMQTTparams info = NVstore.getMQTTinfo();
info.port = it->value.as<unsigned short>();
info.port = it->value.as<uint16_t>();
NVstore.setMQTTinfo(info);
}
else if(strcmp("MHost", it->key) == 0) {
@ -213,20 +215,20 @@ void interpretJsonCommand(char* pLine)
setUploadSize(it->value.as<long>());
}
else if(strcmp("GPout1", it->key) == 0) {
setGPIOout(0, it->value.as<unsigned char>() ? true : false);
setGPIOout(0, it->value.as<uint8_t>() ? true : false);
}
else if(strcmp("GPout2", it->key) == 0) {
setGPIOout(1, it->value.as<unsigned char>() ? true : false);
setGPIOout(1, it->value.as<uint8_t>() ? true : false);
}
else if(strcmp("GPin1", it->key) == 0) {
simulateGPIOin(it->value.as<unsigned char>() ? 0x01 : 0x00); // simulate key 1 press
simulateGPIOin(it->value.as<uint8_t>() ? 0x01 : 0x00); // simulate key 1 press
}
else if(strcmp("GPin2", it->key) == 0) {
simulateGPIOin(it->value.as<unsigned char>() ? 0x02 : 0x00); // simulate key 2 press
simulateGPIOin(it->value.as<uint8_t>() ? 0x02 : 0x00); // simulate key 2 press
}
else if(strcmp("JSONpack", it->key) == 0) {
sUserSettings us = NVstore.getUserSettings();
uint8_t packed = it->value.as<unsigned char>() ? 0x00 : 0x01;
uint8_t packed = it->value.as<uint8_t>() ? 0x00 : 0x01;
us.JSON.LF = packed;
us.JSON.padding = packed;
us.JSON.singleElement = packed;
@ -236,7 +238,7 @@ void interpretJsonCommand(char* pLine)
}
else if(strcmp("TempMode", it->key) == 0) {
sUserSettings us = NVstore.getUserSettings();
us.degF = it->value.as<unsigned char>() ? 0x01 : 0x00;
us.degF = it->value.as<uint8_t>() ? 0x01 : 0x00;
NVstore.setUserSettings(us);
NVstore.save();
}
@ -282,13 +284,13 @@ bool makeJSONString(CModerator& moderator, char* opStr, int len)
bSend |= moderator.addJson("PumpActual", getHeaterInfo().getPump_Actual(), root );
bSend |= moderator.addJson("FanMin", getHeaterInfo().getFan_Min(), root );
bSend |= moderator.addJson("FanMax", getHeaterInfo().getFan_Max(), root );
bSend |= moderator.addJson("FanRPM", getHeaterInfo().getFan_Actual(), root );
bSend |= moderator.addJson("FanRPM", getFanSpeed(), root );
bSend |= moderator.addJson("FanVoltage", getHeaterInfo().getFan_Voltage(), root );
bSend |= moderator.addJson("FanSensor", getHeaterInfo().getFan_Sensor(), root );
bSend |= moderator.addJson("InputVoltage", getHeaterInfo().getBattVoltage(), root );
bSend |= moderator.addJson("InputVoltage", getBatteryVoltage(), root );
bSend |= moderator.addJson("SystemVoltage", getHeaterInfo().getSystemVoltage(), root );
bSend |= moderator.addJson("GlowVoltage", getHeaterInfo().getGlow_Voltage(), root );
bSend |= moderator.addJson("GlowCurrent", getHeaterInfo().getGlow_Current(), root );
bSend |= moderator.addJson("GlowVoltage", getGlowVolts(), root );
bSend |= moderator.addJson("GlowCurrent", getGlowCurrent(), root );
bSend |= moderator.addJson("BluewireStat", getBlueWireStatStr(), root );
bSend |= moderator.addJson("TempMode", NVstore.getUserSettings().degF, root);

View file

@ -108,7 +108,7 @@ void TModerator<T>::reset(const char* name)
class CModerator {
TModerator<int> iModerator;
TModerator<float> fModerator;
TModerator<unsigned char> ucModerator;
TModerator<uint8_t> ucModerator;
CStringModerator szModerator;
public:
// integer values
@ -119,8 +119,8 @@ public:
bool addJson(const char* name, float value, JsonObject& root) {
return fModerator.addJson(name, value, root);
};
// unsigned char values
bool addJson(const char* name, unsigned char value, JsonObject& root) {
// uint8_t values
bool addJson(const char* name, uint8_t value, JsonObject& root) {
return ucModerator.addJson(name, value, root);
};
// const char* values

View file

@ -43,13 +43,13 @@ CommStates::set(eCS eState)
}
bool
CommStates::collectData(CProtocol& Frame, unsigned char val, int limit) { // returns true when buffer filled
CommStates::collectData(CProtocol& Frame, uint8_t val, int limit) { // returns true when buffer filled
Frame.Data[_Count++] = val;
return _Count >= limit;
}
bool
CommStates::collectDataEx(CProtocol& Frame, unsigned char val, int limit) { // returns true when buffer filled
CommStates::collectDataEx(CProtocol& Frame, uint8_t val, int limit) { // returns true when buffer filled
// guarding against rogue rx kernel buffer stutters....
if((_Count == 0) && (val != 0x76)) {
DebugPort.println("First heater byte not 0x76 - SKIPPING");
@ -60,7 +60,7 @@ CommStates::collectDataEx(CProtocol& Frame, unsigned char val, int limit) { //
}
bool
CommStates::checkValidStart(unsigned char val)
CommStates::checkValidStart(uint8_t val)
{
if(_Count)
return true;

View file

@ -56,9 +56,9 @@ public:
bool is(eCS eState) {
return _State == eState;
}
bool collectData(CProtocol& Frame, unsigned char val, int limit = 24);
bool collectDataEx(CProtocol& Frame, unsigned char val, int limit = 24);
bool checkValidStart(unsigned char val);
bool collectData(CProtocol& Frame, uint8_t val, int limit = 24);
bool collectDataEx(CProtocol& Frame, uint8_t val, int limit = 24);
bool checkValidStart(uint8_t val);
void setDelay(int ms);
bool delayExpired();
bool toggleReporting() {

View file

@ -32,9 +32,9 @@ extern void forceBootInit();
extern void requestOn();
extern void requestOff();
extern bool reqTempDelta(int delta);
extern bool reqTemp(unsigned char newTemp, bool save=true);
extern bool reqTemp(uint8_t newTemp, bool save=true);
extern bool reqThermoToggle();
extern bool setThermostatMode(unsigned char);
extern bool setThermostatMode(uint8_t);
extern bool getThermostatModeActive(); // OEM: actual mode from blue wire, BTC: or our NV
extern void reqPumpPrime(bool on);
extern float getTemperatureDesired(); // OEM: the advertised value, BTC our setpoint
@ -45,13 +45,13 @@ extern uint8_t getDemandPump();
extern float getTemperatureSensor();
extern void setPumpMin(float);
extern void setPumpMax(float);
extern void setFanMin(short);
extern void setFanMax(short);
extern void setFanSensor(unsigned char cVal);
extern void setFanMin(uint16_t);
extern void setFanMax(uint16_t);
extern void setFanSensor(uint8_t cVal);
extern void setDateTime(const char* newTime);
extern void setDate(const char* newTime);
extern void setTime(const char* newTime);
extern void setGlowDrive(unsigned char val);
extern void setGlowDrive(uint8_t val);
extern void saveNV();
extern void setSystemVoltage(float val);
extern void interpretJsonCommand(char* pLine);
@ -78,6 +78,10 @@ extern void setUploadSize(long val);
extern void getGPIOinfo(sGPIO& info);
extern void simulateGPIOin(uint8_t newKey);
extern void setDegFMode(bool state);
extern float getBatteryVoltage();
extern float getGlowVolts();
extern float getGlowCurrent();
extern float getFanSpeed();
extern void ShowOTAScreen(int percent=0, eOTAmodes updateType=eOTAnormal);

File diff suppressed because it is too large Load diff

View file

@ -55,4 +55,4 @@ void webturnOff();
bool sendWebServerString(const char* Str);
bool isWebServerClientChange();
void listDir(fs::FS &fs, const char * dirname, uint8_t levels, String& HTMLreport, bool withHTMLanchors=false);
void listDir(fs::FS &fs, const char * dirname, uint8_t levels, String& HTMLreport, int withHTMLanchors=0);

View file

@ -66,10 +66,15 @@ void initOTA(){
// DebugPort.end(); // force graceful close of telnetspy - ensures a client will reconnect cleanly
})
.onProgress([](unsigned int progress, unsigned int total) {
feedWatchdog();
int percent = (progress / (total / 100));
DebugPort.printf("Progress: %u%%\r", percent);
DebugPort.handle(); // keep telnet spy alive
ShowOTAScreen(percent);
static int prevPC = 0;
if(percent != prevPC) {
prevPC = percent;
DebugPort.printf("Progress: %u%%\r", percent);
DebugPort.handle(); // keep telnet spy alive
ShowOTAScreen(percent);
}
})
.onError([](ota_error_t error) {
DebugPort.printf("Error[%u]: ", error);