From de4bdfa98b508c953f209a148a029b3e64105281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Mon, 22 Apr 2024 11:02:40 +0200 Subject: [PATCH] Patrix.h cleanup --- lib/patrix/Patrix.h | 3 +++ lib/patrix/console.cpp | 12 ++++++------ lib/patrix/console.h | 2 +- lib/patrix/data.h | 2 ++ src/Fermenter/Fermenter.cpp | 19 ++++++++----------- src/Fermenter/FermenterData.h | 4 ++-- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/patrix/Patrix.h b/lib/patrix/Patrix.h index a5a3931..3701161 100644 --- a/lib/patrix/Patrix.h +++ b/lib/patrix/Patrix.h @@ -2,6 +2,9 @@ #define SENSOR3_PATRIX_H #include "base.h" +#include "config.h" +#include "console.h" +#include "log.h" void patrixSetup(); diff --git a/lib/patrix/console.cpp b/lib/patrix/console.cpp index da70292..a25f5d8 100644 --- a/lib/patrix/console.cpp +++ b/lib/patrix/console.cpp @@ -67,11 +67,11 @@ void consoleLoop() { void consoleHandle(char *cmd) { char *first = strtok(cmd, " "); if (first == nullptr) { - _usage(); + consolePrintUsage(); return; } if (strcmp(first, "help") == 0) { - _usage(); + consolePrintUsage(); } else if (strcmp(first, "wifi") == 0) { _wifi(); } else if (strcmp(first, "mqtt") == 0) { @@ -89,7 +89,7 @@ void consoleHandle(char *cmd) { } } -void _usage() { +void consolePrintUsage() { info(R"(USAGE: help info @@ -120,7 +120,7 @@ void _reboot() { void _mqtt() { char *sub = strtok(nullptr, " "); if (sub == nullptr) { - _usage(); + consolePrintUsage(); return; } if (strcmp(sub, "reconnect") == 0) { @@ -134,7 +134,7 @@ void _mqtt() { void _wifi() { char *sub = strtok(nullptr, " "); if (sub == nullptr) { - _usage(); + consolePrintUsage(); return; } if (strcmp(sub, "reconnect") == 0) { @@ -150,7 +150,7 @@ void _wifi() { void _setConfigString(const char *name, bool allowEmpty) { char *value = strtok(nullptr, ""); if (value == nullptr) { - _usage(); + consolePrintUsage(); return; } if (!allowEmpty && strcmp(value, "") == 0) { diff --git a/lib/patrix/console.h b/lib/patrix/console.h index c8307bb..d412363 100644 --- a/lib/patrix/console.h +++ b/lib/patrix/console.h @@ -9,6 +9,6 @@ void consoleHandle(char *cmd); bool patrix_command(char *cmd); -void _usage(); +void consolePrintUsage(); #endif diff --git a/lib/patrix/data.h b/lib/patrix/data.h index 799180a..3d72705 100644 --- a/lib/patrix/data.h +++ b/lib/patrix/data.h @@ -3,6 +3,8 @@ #include "base.h" #include +#include "wifi.h" +#include "mqtt.h" struct IData { diff --git a/src/Fermenter/Fermenter.cpp b/src/Fermenter/Fermenter.cpp index e08930f..b0b8e8f 100644 --- a/src/Fermenter/Fermenter.cpp +++ b/src/Fermenter/Fermenter.cpp @@ -4,9 +4,6 @@ #include "sensors/Dallas.h" #include "sensors/DallasSensor.h" #include "ArduPID.h" -#include "config.h" -#include "console.h" -#include #include "LedControl.h" #include "FermenterData.h" @@ -39,7 +36,7 @@ double temperatureTarget = PID_DEFAULT_TARGET; double temperatureOver = PID_DEFAULT_OVER; -double temperatureCurrent = NAN; +double temperature = NAN; double heaterPWM = 0; @@ -59,7 +56,7 @@ void patrixSetup() { configLoaded(); - pid.begin(&temperatureCurrent, &heaterPWM, &temperatureTarget, proportional, integral, derivative); + pid.begin(&temperature, &heaterPWM, &temperatureTarget, proportional, integral, derivative); pid.setOutputLimits(0, CONTROL_PWM_MAX); pid.start(); } @@ -77,15 +74,15 @@ void patrixLoop() { } void pidLoop() { - temperatureCurrent = sensor.getLastValue(); - if (!isnan(temperatureCurrent)) { + temperature = sensor.getLastValue(); + if (!isnan(temperature)) { pid.compute(); } else { heaterPWM = 0; } const char *emergencyStr = ""; - if (heaterPWM > 0 && temperatureCurrent > temperatureTarget + temperatureOver) { + if (heaterPWM > 0 && temperature > temperatureTarget + temperatureOver) { heaterPWM = 0; emergencyStr = "[EMERGENCY CUTOFF]"; } @@ -108,7 +105,7 @@ void pidLoop() { temperatureTarget, heaterPercent, - temperatureCurrent, + temperature, emergencyStr ); @@ -125,7 +122,7 @@ void displayLoop() { lc.clearDisplay(0); } int digit = 0; - writeDecimal(&digit, temperatureCurrent); + writeDecimal(&digit, temperature); digit++; digit++; writeDecimal(&digit, temperatureTarget); @@ -142,7 +139,7 @@ void writeDecimal(int *digit, double value) { bool setDouble(const char *name, double *destinationPtr, double min, double max) { const char *valueStr = strtok(nullptr, ""); if (valueStr == nullptr) { - _usage(); + consolePrintUsage(); return false; } double value = strtod(valueStr, nullptr); diff --git a/src/Fermenter/FermenterData.h b/src/Fermenter/FermenterData.h index 676e2a9..6a26cc5 100644 --- a/src/Fermenter/FermenterData.h +++ b/src/Fermenter/FermenterData.h @@ -1,5 +1,5 @@ -#ifndef SENSOR3_FERMENTERDATA_H -#define SENSOR3_FERMENTERDATA_H +#ifndef SENSOR3_FERMENTER_DATA_H +#define SENSOR3_FERMENTER_DATA_H #include "data.h"