heaterPercent in Data
This commit is contained in:
parent
110f454e01
commit
0c77595ae5
@ -43,7 +43,9 @@ double temperatureCurrent = NAN;
|
|||||||
|
|
||||||
double heaterPWM = 0;
|
double heaterPWM = 0;
|
||||||
|
|
||||||
Cache<FermenterData, 500> cache;
|
uint8_t heaterPercent = 0;
|
||||||
|
|
||||||
|
Cache<FermenterData, 800> cache;
|
||||||
|
|
||||||
void writeDecimal(int *digit, double value);
|
void writeDecimal(int *digit, double value);
|
||||||
|
|
||||||
@ -64,13 +66,14 @@ void patrixSetup() {
|
|||||||
|
|
||||||
void patrixLoop() {
|
void patrixLoop() {
|
||||||
dallas.loop();
|
dallas.loop();
|
||||||
if (sensor.loop()) {
|
bool doPublish = sensor.loop();
|
||||||
const FermenterData data = {sensor.getLastValue(), temperatureTarget, proportional, integral, derivative};
|
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.add(sensor.getLastTimestamp(), data);
|
||||||
}
|
}
|
||||||
cache.loop();
|
cache.loop();
|
||||||
displayLoop();
|
|
||||||
pidLoop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pidLoop() {
|
void pidLoop() {
|
||||||
@ -88,12 +91,12 @@ void pidLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
|
analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
|
||||||
|
heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
|
||||||
|
|
||||||
static unsigned long lastDebug = 0;
|
static unsigned long lastDebug = 0;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
if (now - lastDebug >= 1000) {
|
if (now - lastDebug >= 1000) {
|
||||||
lastDebug = now;
|
lastDebug = now;
|
||||||
int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
|
|
||||||
debug(
|
debug(
|
||||||
"cache: %3d/%d | p: %f | i: %f | d: %f | target: %4.1f | heater: %3d%% | temperature: %5.2f %s",
|
"cache: %3d/%d | p: %f | i: %f | d: %f | target: %4.1f | heater: %3d%% | temperature: %5.2f %s",
|
||||||
cache.getUsage(),
|
cache.getUsage(),
|
||||||
|
|||||||
@ -4,27 +4,43 @@
|
|||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
struct FermenterData : IData {
|
struct FermenterData : IData {
|
||||||
double temperature;
|
float currentCelsius;
|
||||||
double target;
|
float targetCelsius;
|
||||||
double p;
|
uint8_t heaterPercent;
|
||||||
double i;
|
float p;
|
||||||
double d;
|
float i;
|
||||||
|
float d;
|
||||||
|
|
||||||
FermenterData() {
|
FermenterData() {
|
||||||
temperature = NAN;
|
currentCelsius = NAN;
|
||||||
target = NAN;
|
targetCelsius = NAN;
|
||||||
|
heaterPercent = 0;
|
||||||
p = NAN;
|
p = NAN;
|
||||||
i = NAN;
|
i = NAN;
|
||||||
d = 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 {
|
void toJson(JsonObject &json) const override {
|
||||||
json["temperature"] = temperature;
|
json["currentCelsius"] = currentCelsius;
|
||||||
json["target"] = target;
|
json["targetCelsius"] = targetCelsius;
|
||||||
|
json["heaterPercent"] = heaterPercent;
|
||||||
json["p"] = p;
|
json["p"] = p;
|
||||||
json["i"] = i;
|
json["i"] = i;
|
||||||
json["d"] = d;
|
json["d"] = d;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user