refactor: added SensorType enum

This commit is contained in:
Yurii
2024-03-14 13:07:42 +03:00
parent b07dd46f55
commit a5f6749101
8 changed files with 69 additions and 34 deletions

View File

@@ -174,7 +174,7 @@ public:
Log.serrorln(
FPSTR(L_PORTAL_OTA),
F("File '%s', on writing %d bytes: %s"),
upload.filename.c_str(), upload.totalSize, result->error
upload.filename.c_str(), upload.totalSize, result->error.c_str()
);
} else {

View File

@@ -385,8 +385,8 @@ protected:
bool isStupidMode = !settings.pid.enable && !settings.equitherm.enable;
byte heatingMinTemp = isStupidMode ? settings.heating.minTemp : 10;
byte heatingMaxTemp = isStupidMode ? settings.heating.maxTemp : 30;
bool editableOutdoorTemp = settings.sensors.outdoor.type == 1;
bool editableIndoorTemp = settings.sensors.indoor.type == 1;
bool editableOutdoorTemp = settings.sensors.outdoor.type == SensorType::MANUAL;
bool editableIndoorTemp = settings.sensors.indoor.type == SensorType::MANUAL;
if (force || _dhwPresent != settings.opentherm.dhwPresent) {
_dhwPresent = settings.opentherm.dhwPresent;

View File

@@ -257,7 +257,7 @@ protected:
setMaxHeatingTemp(settings.heating.maxTemp);
// Get outdoor temp (if necessary)
if (settings.sensors.outdoor.type == 0) {
if (settings.sensors.outdoor.type == SensorType::BOILER) {
updateOutsideTemp();
}

View File

@@ -84,7 +84,7 @@ protected:
float newTemp = 0;
// if use equitherm
if (settings.emergency.useEquitherm && settings.sensors.outdoor.type != 1) {
if (settings.emergency.useEquitherm && settings.sensors.outdoor.type != SensorType::MANUAL) {
float etResult = getEquithermTemp(settings.heating.minTemp, settings.heating.maxTemp);
if (fabs(prevEtResult - etResult) + 0.0001 >= 0.5) {
@@ -97,7 +97,7 @@ protected:
newTemp += prevEtResult;
}
} else if(settings.emergency.usePid && settings.sensors.indoor.type != 1) {
} else if(settings.emergency.usePid && settings.sensors.indoor.type != SensorType::MANUAL) {
if (vars.parameters.heatingEnabled) {
float pidResult = getPidTemp(
settings.heating.minTemp,

View File

@@ -63,21 +63,21 @@ protected:
bool indoorTempUpdated = false;
bool outdoorTempUpdated = false;
if (settings.sensors.outdoor.type == 2 && GPIO_IS_VALID(settings.sensors.indoor.gpio)) {
if (settings.sensors.outdoor.type == SensorType::DS18B20 && GPIO_IS_VALID(settings.sensors.indoor.gpio)) {
outdoorTemperatureSensor();
outdoorTempUpdated = true;
}
if (settings.sensors.indoor.type == 2 && GPIO_IS_VALID(settings.sensors.indoor.gpio)) {
if (settings.sensors.indoor.type == SensorType::DS18B20 && GPIO_IS_VALID(settings.sensors.indoor.gpio)) {
indoorTemperatureSensor();
indoorTempUpdated = true;
}
#if USE_BLE
else if (settings.sensors.indoor.type == 3) {
#if USE_BLE
else if (settings.sensors.indoor.type == SensorType::BLUETOOTH) {
indoorTemperatureBluetoothSensor();
indoorTempUpdated = true;
}
#endif
#endif
if (outdoorTempUpdated && fabs(vars.temperatures.outdoor - this->filteredOutdoorTemp) > 0.099) {
vars.temperatures.outdoor = this->filteredOutdoorTemp + settings.sensors.outdoor.offset;

View File

@@ -100,15 +100,13 @@ struct Settings {
struct {
struct {
// 0 - boiler, 1 - manual, 2 - ds18b20
byte type = 0;
SensorType type = SensorType::BOILER;
byte gpio = DEFAULT_SENSOR_OUTDOOR_GPIO;
float offset = 0.0f;
} outdoor;
struct {
// 1 - manual, 2 - ds18b20, 3 - ble
byte type = 1;
SensorType type = SensorType::MANUAL;
byte gpio = DEFAULT_SENSOR_INDOOR_GPIO;
uint8_t bleAddresss[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
float offset = 0.0f;

View File

@@ -111,4 +111,11 @@
#define GPIO_IS_VALID(gpioNum) (gpioNum != GPIO_IS_NOT_CONFIGURED && GPIO_IS_VALID_GPIO(gpioNum))
enum class SensorType : byte {
BOILER,
MANUAL,
DS18B20,
BLUETOOTH
};
char buffer[255];

View File

@@ -323,11 +323,11 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
dst["equitherm"]["k_factor"] = roundd(src.equitherm.k_factor, 3);
dst["equitherm"]["t_factor"] = roundd(src.equitherm.t_factor, 3);
dst["sensors"]["outdoor"]["type"] = src.sensors.outdoor.type;
dst["sensors"]["outdoor"]["type"] = static_cast<byte>(src.sensors.outdoor.type);
dst["sensors"]["outdoor"]["gpio"] = src.sensors.outdoor.gpio;
dst["sensors"]["outdoor"]["offset"] = roundd(src.sensors.outdoor.offset, 2);
dst["sensors"]["indoor"]["type"] = src.sensors.indoor.type;
dst["sensors"]["indoor"]["type"] = static_cast<byte>(src.sensors.indoor.type);
dst["sensors"]["indoor"]["gpio"] = src.sensors.indoor.gpio;
char bleAddress[18];
@@ -574,7 +574,7 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
if (src["emergency"]["useEquitherm"].is<bool>()) {
if (dst.sensors.outdoor.type != 1) {
if (dst.sensors.outdoor.type != SensorType::MANUAL) {
dst.emergency.useEquitherm = src["emergency"]["useEquitherm"].as<bool>();
} else {
@@ -589,7 +589,7 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
if (src["emergency"]["usePid"].is<bool>()) {
if (dst.sensors.indoor.type != 1) {
if (dst.sensors.indoor.type != SensorType::MANUAL) {
dst.emergency.usePid = src["emergency"]["usePid"].as<bool>();
} else {
@@ -792,16 +792,27 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
// sensors
if (!src["sensors"]["outdoor"]["type"].isNull()) {
unsigned char value = src["sensors"]["outdoor"]["type"].as<unsigned char>();
byte value = src["sensors"]["outdoor"]["type"].as<unsigned char>();
if (value >= 0 && value <= 2) {
dst.sensors.outdoor.type = value;
switch (value) {
case static_cast<byte>(SensorType::BOILER):
dst.sensors.outdoor.type = SensorType::BOILER;
changed = true;
break;
if (dst.sensors.outdoor.type == 1) {
case static_cast<byte>(SensorType::MANUAL):
dst.sensors.outdoor.type = SensorType::MANUAL;
dst.emergency.useEquitherm = false;
}
changed = true;
break;
changed = true;
case static_cast<byte>(SensorType::DS18B20):
dst.sensors.outdoor.type = SensorType::DS18B20;
changed = true;
break;
default:
break;
}
}
@@ -832,16 +843,35 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
}
if (!src["sensors"]["indoor"]["type"].isNull()) {
unsigned char value = src["sensors"]["indoor"]["type"].as<unsigned char>();
byte value = src["sensors"]["indoor"]["type"].as<unsigned char>();
if (value >= 1 && value <= 3) {
dst.sensors.indoor.type = value;
if (dst.sensors.indoor.type == 1) {
dst.emergency.usePid = false;
}
switch (value) {
case static_cast<byte>(SensorType::BOILER):
dst.sensors.indoor.type = SensorType::BOILER;
changed = true;
break;
changed = true;
case static_cast<byte>(SensorType::MANUAL):
dst.sensors.indoor.type = SensorType::MANUAL;
dst.emergency.useEquitherm = false;
changed = true;
break;
case static_cast<byte>(SensorType::DS18B20):
dst.sensors.indoor.type = SensorType::DS18B20;
changed = true;
break;
#if USE_BLE
case static_cast<byte>(SensorType::BLUETOOTH):
dst.sensors.indoor.type = SensorType::BLUETOOTH;
changed = true;
break;
#endif
default:
break;
}
}
@@ -1001,7 +1031,7 @@ bool jsonToVars(const JsonVariantConst src, Variables& dst) {
if (!src["temperatures"]["indoor"].isNull()) {
double value = src["temperatures"]["indoor"].as<double>();
if (settings.sensors.indoor.type == 1 && value > -100 && value < 100) {
if (settings.sensors.indoor.type == SensorType::MANUAL && value > -100 && value < 100) {
dst.temperatures.indoor = roundd(value, 2);
changed = true;
}
@@ -1010,7 +1040,7 @@ bool jsonToVars(const JsonVariantConst src, Variables& dst) {
if (!src["temperatures"]["outdoor"].isNull()) {
double value = src["temperatures"]["outdoor"].as<double>();
if (settings.sensors.outdoor.type == 1 && value > -100 && value < 100) {
if (settings.sensors.outdoor.type == SensorType::MANUAL && value > -100 && value < 100) {
dst.temperatures.outdoor = roundd(value, 2);
changed = true;
}