diff --git a/src/Afterburner/src/Utility/BTC_JSON.cpp b/src/Afterburner/src/Utility/BTC_JSON.cpp index 5a6ed56..cdc51af 100644 --- a/src/Afterburner/src/Utility/BTC_JSON.cpp +++ b/src/Afterburner/src/Utility/BTC_JSON.cpp @@ -32,6 +32,7 @@ #include "../cfg/BTCConfig.h" #include "macros.h" #include "../Protocol/Protocol.h" +#include char defaultJSONstr[64]; CModerator JSONmoderator; @@ -289,17 +290,15 @@ void interpretJsonCommand(char* pLine) } else if(strcmp("LowVoltCutout", it->key) == 0) { float fCal = it->value.as(); - if(fCal != 0) { - bool bOK = false; - if(NVstore.getHeaterTuning().sysVoltage == 120) - bOK = INBOUNDS(fCal, 10.0, 12.5); - else - bOK = INBOUNDS(fCal, 20.0, 25.0); - if(bOK) { - sHeaterTuning ht = NVstore.getHeaterTuning(); - ht.lowVolts = uint8_t(fCal * 10); - NVstore.setHeaterTuning(ht); - } + bool bOK = false; + if(NVstore.getHeaterTuning().sysVoltage == 120) + bOK |= (fCal == 0) || INBOUNDS(fCal, 10.0, 12.5); + else + bOK |= (fCal == 0) || INBOUNDS(fCal, 20.0, 25.0); + if(bOK) { + sHeaterTuning ht = NVstore.getHeaterTuning(); + ht.lowVolts = uint8_t(fCal * 10); + NVstore.setHeaterTuning(ht); } } } diff --git a/src/Afterburner/src/Utility/NVCore.cpp b/src/Afterburner/src/Utility/NVCore.cpp index d91cf76..c1df88c 100644 --- a/src/Afterburner/src/Utility/NVCore.cpp +++ b/src/Afterburner/src/Utility/NVCore.cpp @@ -23,6 +23,7 @@ #include "NVCore.h" #include "DebugPort.h" #include +#include #define INBOUNDS(TST, MIN, MAX) (((TST) >= (MIN)) && ((TST) <= (MAX))) @@ -45,7 +46,7 @@ CESP32_NVStorage::validatedLoad(const char* key, char* val, int maxlen, const ch } bool -CESP32_NVStorage::validatedLoad(const char* key, uint8_t& val, int defVal, std::function validator, int min, int max, uint8_t mask) +CESP32_NVStorage::validatedLoad(const char* key, uint8_t& val, uint8_t defVal, std::function validator, uint8_t min, uint8_t max, uint8_t mask) { val = preferences.getUChar(key, defVal); if(!validator(val & mask, min, max)) { @@ -61,7 +62,7 @@ CESP32_NVStorage::validatedLoad(const char* key, uint8_t& val, int defVal, std:: } bool -CESP32_NVStorage::validatedLoad(const char* key, int8_t& val, int defVal, std::function validator, int min, int max) +CESP32_NVStorage::validatedLoad(const char* key, int8_t& val, int8_t defVal, std::function validator, int8_t min, int8_t max) { val = preferences.getChar(key, defVal); if(!validator(val, min, max)) { @@ -77,7 +78,7 @@ CESP32_NVStorage::validatedLoad(const char* key, int8_t& val, int defVal, std::f } bool -CESP32_NVStorage::validatedLoad(const char* key, uint16_t& val, int defVal, std::function validator, int min, int max) +CESP32_NVStorage::validatedLoad(const char* key, uint16_t& val, uint16_t defVal, std::function validator, uint16_t min, uint16_t max) { val = preferences.getUShort(key, defVal); if(!validator(val, min, max)) { @@ -134,6 +135,12 @@ bool u8inBounds(uint8_t test, uint8_t minLim, uint8_t maxLim) return INBOUNDS(test, minLim, maxLim); } +bool u8inBoundsOrZero(uint8_t test, uint8_t minLim, uint8_t maxLim) +{ + return INBOUNDS(test, minLim, maxLim) || (test == 0); +} + + bool s8inBounds(int8_t test, int8_t minLim, int8_t maxLim) { return INBOUNDS(test, minLim, maxLim); diff --git a/src/Afterburner/src/Utility/NVCore.h b/src/Afterburner/src/Utility/NVCore.h index 396cc69..46c1bd9 100644 --- a/src/Afterburner/src/Utility/NVCore.h +++ b/src/Afterburner/src/Utility/NVCore.h @@ -28,6 +28,7 @@ bool finBounds(float tets, float min, float max); bool u8inBounds(uint8_t test, uint8_t minLim, uint8_t maxLim); +bool u8inBoundsOrZero(uint8_t test, uint8_t minLim, uint8_t maxLim); bool s8inBounds(int8_t test, int8_t minLim, int8_t maxLim); bool u8Match2(uint8_t test, uint8_t test1, uint8_t test2); bool u16inBounds(uint16_t test, uint16_t minLim, uint16_t maxLim); @@ -47,9 +48,9 @@ class CESP32_NVStorage { protected: Preferences preferences; protected: - bool validatedLoad(const char* key, int8_t& val, int defVal, std::function validator, int min, int max); - bool validatedLoad(const char* key, uint8_t& val, int defVal, std::function validator, int min, int max, uint8_t mask=0xff); - bool validatedLoad(const char* key, uint16_t& val, int defVal, std::function validator, int min, int max); + bool validatedLoad(const char* key, int8_t& val, int8_t defVal, std::function validator, int8_t min, int8_t max); + bool validatedLoad(const char* key, uint8_t& val, uint8_t defVal, std::function validator, uint8_t min, uint8_t max, uint8_t mask=0xff); + bool validatedLoad(const char* key, uint16_t& val, uint16_t defVal, std::function validator, uint16_t min, uint16_t max); bool validatedLoad(const char* key, long& val, long defVal, long min, long max); bool validatedLoad(const char* key, char* val, int maxlen, const char* defVal); bool validatedLoad(const char* key, float& val, float defVal, float min, float max); diff --git a/src/Afterburner/src/Utility/NVStorage.cpp b/src/Afterburner/src/Utility/NVStorage.cpp index c3f6925..85fb434 100644 --- a/src/Afterburner/src/Utility/NVStorage.cpp +++ b/src/Afterburner/src/Utility/NVStorage.cpp @@ -241,9 +241,9 @@ sHeaterTuning::load() validatedLoad("fanSensor", fanSensor, 1, u8inBounds, 1, 2); validatedLoad("glowDrive", glowDrive, 5, u8inBounds, 1, 6); if(sysVoltage == 120) - validatedLoad("lowVolts", lowVolts, 115, u8inBounds, 100, 125); + validatedLoad("lowVolts", lowVolts, 115, u8inBoundsOrZero, 100, 125); else - validatedLoad("lowVolts", lowVolts, 230, u8inBounds, 200, 250); + validatedLoad("lowVolts", lowVolts, 230, u8inBoundsOrZero, 200, 250); validatedLoad("pumpCal", pumpCal, 0.02, 0.001, 1); validatedLoad("tempOfs", tempOfs, 0.0, -10.0, +10.0); preferences.end();