From 0c77595ae59c0603e3440479d761600ecffb05de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Mon, 15 Apr 2024 14:46:09 +0200 Subject: [PATCH] heaterPercent in Data --- src/Fermenter/Fermenter.cpp | 15 +++++++++------ src/Fermenter/FermenterData.h | 36 +++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/Fermenter/Fermenter.cpp b/src/Fermenter/Fermenter.cpp index b61573a..f3dd2b5 100644 --- a/src/Fermenter/Fermenter.cpp +++ b/src/Fermenter/Fermenter.cpp @@ -43,7 +43,9 @@ double temperatureCurrent = NAN; double heaterPWM = 0; -Cache cache; +uint8_t heaterPercent = 0; + +Cache 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(), diff --git a/src/Fermenter/FermenterData.h b/src/Fermenter/FermenterData.h index e2a5b3d..676e2a9 100644 --- a/src/Fermenter/FermenterData.h +++ b/src/Fermenter/FermenterData.h @@ -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;