heaterPercent in Data

This commit is contained in:
Patrick Haßel 2024-04-15 14:46:09 +02:00
parent 110f454e01
commit 0c77595ae5
2 changed files with 35 additions and 16 deletions

View File

@ -43,7 +43,9 @@ double temperatureCurrent = NAN;
double heaterPWM = 0;
Cache<FermenterData, 500> cache;
uint8_t heaterPercent = 0;
Cache<FermenterData, 800> cache;
void writeDecimal(int *digit, double value);
@ -64,13 +66,14 @@ void patrixSetup() {
void patrixLoop() {
dallas.loop();
if (sensor.loop()) {
const FermenterData data = {sensor.getLastValue(), temperatureTarget, proportional, integral, derivative};
bool doPublish = sensor.loop();
displayLoop();
pidLoop();
if (doPublish) {
const FermenterData data = {(float) sensor.getLastValue(), (float) temperatureTarget, heaterPercent, (float) proportional, (float) integral, (float) derivative};
cache.add(sensor.getLastTimestamp(), data);
}
cache.loop();
displayLoop();
pidLoop();
}
void pidLoop() {
@ -88,12 +91,12 @@ void pidLoop() {
}
analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
static unsigned long lastDebug = 0;
unsigned long now = millis();
if (now - lastDebug >= 1000) {
lastDebug = now;
int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
debug(
"cache: %3d/%d | p: %f | i: %f | d: %f | target: %4.1f | heater: %3d%% | temperature: %5.2f %s",
cache.getUsage(),

View File

@ -4,27 +4,43 @@
#include "data.h"
struct FermenterData : IData {
double temperature;
double target;
double p;
double i;
double d;
float currentCelsius;
float targetCelsius;
uint8_t heaterPercent;
float p;
float i;
float d;
FermenterData() {
temperature = NAN;
target = NAN;
currentCelsius = NAN;
targetCelsius = NAN;
heaterPercent = 0;
p = NAN;
i = NAN;
d = NAN;
}
FermenterData(double temperature, double target, double p, double i, double d) : temperature(temperature), target(target), p(p), i(i), d(d) {
FermenterData(
float currentCelsius,
float targetCelsius,
uint8_t heaterPercent,
float p,
float i,
float d
) :
currentCelsius(currentCelsius),
targetCelsius(targetCelsius),
heaterPercent(heaterPercent),
p(p),
i(i),
d(d) {
// -
}
void toJson(JsonObject &json) const override {
json["temperature"] = temperature;
json["target"] = target;
json["currentCelsius"] = currentCelsius;
json["targetCelsius"] = targetCelsius;
json["heaterPercent"] = heaterPercent;
json["p"] = p;
json["i"] = i;
json["d"] = d;