mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-01-01 13:03:36 +05:00
Compare commits
1 Commits
497dcdd854
...
7ff5c6a838
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ff5c6a838 |
60
lib/Equitherm/Equitherm.h
Normal file
60
lib/Equitherm/Equitherm.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#if defined(EQUITHERM_INTEGER)
|
||||||
|
// расчёты с целыми числами
|
||||||
|
typedef int datatype;
|
||||||
|
#else
|
||||||
|
// расчёты с float числами
|
||||||
|
typedef float datatype;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Equitherm {
|
||||||
|
public:
|
||||||
|
datatype targetTemp = 0;
|
||||||
|
datatype indoorTemp = 0;
|
||||||
|
datatype outdoorTemp = 0;
|
||||||
|
float Kn = 0.0;
|
||||||
|
float Kk = 0.0;
|
||||||
|
float Kt = 0.0;
|
||||||
|
float Ke = 1.3;
|
||||||
|
|
||||||
|
Equitherm() = default;
|
||||||
|
|
||||||
|
// kn, kk, kt, Ke
|
||||||
|
Equitherm(float new_kn, float new_kk, float new_kt, float new_ke) {
|
||||||
|
Kn = new_kn;
|
||||||
|
Kk = new_kk;
|
||||||
|
Kt = new_kt;
|
||||||
|
Ke = new_ke;
|
||||||
|
}
|
||||||
|
|
||||||
|
// лимит выходной величины
|
||||||
|
void setLimits(unsigned short min_output, unsigned short max_output) {
|
||||||
|
_minOut = min_output;
|
||||||
|
_maxOut = max_output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// возвращает новое значение при вызове
|
||||||
|
datatype getResult() {
|
||||||
|
datatype output = getResultN() + Kk + getResultT();
|
||||||
|
output = constrain(output, _minOut, _maxOut); // ограничиваем выход
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned short _minOut = 20, _maxOut = 90;
|
||||||
|
|
||||||
|
datatype getResultN()
|
||||||
|
{
|
||||||
|
float tempDelta = targetTemp - outdoorTemp,
|
||||||
|
maxPoint = targetTemp - (_maxOut - targetTemp) / Kn,
|
||||||
|
sf = (_maxOut - targetTemp) / pow(targetTemp - maxPoint, 1.0 / Ke),
|
||||||
|
T_rad = targetTemp + sf * (tempDelta >= 0 ? pow(tempDelta, 1.0 / Ke) : -pow(-tempDelta, 1.0 / Ke));
|
||||||
|
return T_rad > _maxOut ? _maxOut : T_rad;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реакция на разницу с целевой температурой
|
||||||
|
datatype getResultT() {
|
||||||
|
return constrain((targetTemp - indoorTemp), -3, 3) * Kt;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -496,8 +496,9 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark connected
|
if (!rSensor.connected) {
|
||||||
Sensors::setConnectionStatusById(sensorId, true, true);
|
rSensor.connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->bleLastSetDtTime[sensorId] || millis() - this->bleLastSetDtTime[sensorId] > this->bleSetDtInterval) {
|
if (!this->bleLastSetDtTime[sensorId] || millis() - this->bleLastSetDtTime[sensorId] > this->bleSetDtInterval) {
|
||||||
struct tm ti;
|
struct tm ti;
|
||||||
@@ -520,6 +521,7 @@ protected:
|
|||||||
|
|
||||||
this->bleLastSetDtTime[sensorId] = millis();
|
this->bleLastSetDtTime[sensorId] = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -979,16 +981,16 @@ protected:
|
|||||||
auto& rSensor = Sensors::results[sensorId];
|
auto& rSensor = Sensors::results[sensorId];
|
||||||
|
|
||||||
if (rSensor.connected && !sSensor.enabled) {
|
if (rSensor.connected && !sSensor.enabled) {
|
||||||
Sensors::setConnectionStatusById(sensorId, false, false);
|
rSensor.connected = false;
|
||||||
|
|
||||||
} else if (rSensor.connected && sSensor.type == Sensors::Type::NOT_CONFIGURED) {
|
} else if (rSensor.connected && sSensor.type == Sensors::Type::NOT_CONFIGURED) {
|
||||||
Sensors::setConnectionStatusById(sensorId, false, false);
|
rSensor.connected = false;
|
||||||
|
|
||||||
} else if (rSensor.connected && sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
} else if (rSensor.connected && sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
||||||
Sensors::setConnectionStatusById(sensorId, false, false);
|
rSensor.connected = false;
|
||||||
|
|
||||||
} else if (sSensor.type != Sensors::Type::MANUAL && rSensor.connected && (millis() - rSensor.activityTime) > this->disconnectedTimeout) {
|
} else if (sSensor.type != Sensors::Type::MANUAL && rSensor.connected && (millis() - rSensor.activityTime) > this->disconnectedTimeout) {
|
||||||
Sensors::setConnectionStatusById(sensorId, false, false);
|
rSensor.connected = false;
|
||||||
|
|
||||||
}/* else if (!rSensor.connected) {
|
}/* else if (!rSensor.connected) {
|
||||||
rSensor.connected = true;
|
rSensor.connected = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user