diff --git a/data/Fermenter/config.json b/data/Fermenter/config.json index 9da52bb..4dd4998 100644 --- a/data/Fermenter/config.json +++ b/data/Fermenter/config.json @@ -1,6 +1,6 @@ { "pid": { - "p": 5, + "p": 1, "i": 0, "d": 0, "target": 0 diff --git a/src/node/Fermenter/Fermenter.cpp b/src/node/Fermenter/Fermenter.cpp index 81721d6..f63a1a1 100644 --- a/src/node/Fermenter/Fermenter.cpp +++ b/src/node/Fermenter/Fermenter.cpp @@ -16,7 +16,7 @@ void patrixSetup() { heater.setup(); rotary.setup(); - pid.setup(); + pidSetup(); httpSetup2(); } @@ -25,7 +25,7 @@ void patrixLoop() { ds18b20.loop(); temperature.loop(); - pid.loop(); + pidLoop(); rotary.loop(); program.loop(); diff --git a/src/node/Fermenter/pid.cpp b/src/node/Fermenter/pid.cpp index 3a01c6f..b8ae192 100644 --- a/src/node/Fermenter/pid.cpp +++ b/src/node/Fermenter/pid.cpp @@ -1,8 +1,25 @@ +#include #ifdef NODE_FERMENTER #include "pid.h" #include "config.h" +struct History { + + int16_t target; + + int16_t temperature; + + uint8_t heater; + +}; + +History history[3 * 60]; + +History* historyPtr = history; + +unsigned long historyLastMinute = 0; + DS18B20 ds18b20( "DS18B20", D4 @@ -39,4 +56,20 @@ void addTarget(const double delta) { config.markDirty(); } +void pidSetup() { + pid.setup(); +} + +void pidLoop() { + pid.loop(); + const auto currentMinute = millis() / 60000; + if (historyLastMinute != currentMinute) { + historyLastMinute = currentMinute; + historyPtr = (historyPtr - history + 1) % std::size(history) + history; + } + historyPtr->heater = static_cast(heater.getPercent()); + historyPtr->target = static_cast(pid.getTarget() * 10); + historyPtr->temperature = static_cast(temperature.getValue() * 10); +} + #endif diff --git a/src/node/Fermenter/pid.h b/src/node/Fermenter/pid.h index 64e5f6a..99ad453 100644 --- a/src/node/Fermenter/pid.h +++ b/src/node/Fermenter/pid.h @@ -17,4 +17,8 @@ extern PIDController pid; void addTarget(double delta); +void pidSetup(); + +void pidLoop(); + #endif diff --git a/src/patrix/Patrix.cpp b/src/patrix/Patrix.cpp index 8382aaf..c896a2d 100644 --- a/src/patrix/Patrix.cpp +++ b/src/patrix/Patrix.cpp @@ -1,6 +1,8 @@ #include + #include "Patrix.h" #include "http.h" +#include "mqtt.h" #include "system.h" void setup() { diff --git a/src/patrix/Patrix.h b/src/patrix/Patrix.h index 1601aab..00ba7f2 100644 --- a/src/patrix/Patrix.h +++ b/src/patrix/Patrix.h @@ -1,9 +1,6 @@ #ifndef PATRIX_H #define PATRIX_H -#include "wifi.h" -#include "mqtt.h" - void patrixSetup(); void patrixLoop();