Patrix.h cleanup

This commit is contained in:
Patrick Haßel 2024-04-22 11:02:40 +02:00
parent b7b9ea61b5
commit de4bdfa98b
6 changed files with 22 additions and 20 deletions

View File

@ -2,6 +2,9 @@
#define SENSOR3_PATRIX_H #define SENSOR3_PATRIX_H
#include "base.h" #include "base.h"
#include "config.h"
#include "console.h"
#include "log.h"
void patrixSetup(); void patrixSetup();

View File

@ -67,11 +67,11 @@ void consoleLoop() {
void consoleHandle(char *cmd) { void consoleHandle(char *cmd) {
char *first = strtok(cmd, " "); char *first = strtok(cmd, " ");
if (first == nullptr) { if (first == nullptr) {
_usage(); consolePrintUsage();
return; return;
} }
if (strcmp(first, "help") == 0) { if (strcmp(first, "help") == 0) {
_usage(); consolePrintUsage();
} else if (strcmp(first, "wifi") == 0) { } else if (strcmp(first, "wifi") == 0) {
_wifi(); _wifi();
} else if (strcmp(first, "mqtt") == 0) { } else if (strcmp(first, "mqtt") == 0) {
@ -89,7 +89,7 @@ void consoleHandle(char *cmd) {
} }
} }
void _usage() { void consolePrintUsage() {
info(R"(USAGE: info(R"(USAGE:
help help
info info
@ -120,7 +120,7 @@ void _reboot() {
void _mqtt() { void _mqtt() {
char *sub = strtok(nullptr, " "); char *sub = strtok(nullptr, " ");
if (sub == nullptr) { if (sub == nullptr) {
_usage(); consolePrintUsage();
return; return;
} }
if (strcmp(sub, "reconnect") == 0) { if (strcmp(sub, "reconnect") == 0) {
@ -134,7 +134,7 @@ void _mqtt() {
void _wifi() { void _wifi() {
char *sub = strtok(nullptr, " "); char *sub = strtok(nullptr, " ");
if (sub == nullptr) { if (sub == nullptr) {
_usage(); consolePrintUsage();
return; return;
} }
if (strcmp(sub, "reconnect") == 0) { if (strcmp(sub, "reconnect") == 0) {
@ -150,7 +150,7 @@ void _wifi() {
void _setConfigString(const char *name, bool allowEmpty) { void _setConfigString(const char *name, bool allowEmpty) {
char *value = strtok(nullptr, ""); char *value = strtok(nullptr, "");
if (value == nullptr) { if (value == nullptr) {
_usage(); consolePrintUsage();
return; return;
} }
if (!allowEmpty && strcmp(value, "") == 0) { if (!allowEmpty && strcmp(value, "") == 0) {

View File

@ -9,6 +9,6 @@ void consoleHandle(char *cmd);
bool patrix_command(char *cmd); bool patrix_command(char *cmd);
void _usage(); void consolePrintUsage();
#endif #endif

View File

@ -3,6 +3,8 @@
#include "base.h" #include "base.h"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "wifi.h"
#include "mqtt.h"
struct IData { struct IData {

View File

@ -4,9 +4,6 @@
#include "sensors/Dallas.h" #include "sensors/Dallas.h"
#include "sensors/DallasSensor.h" #include "sensors/DallasSensor.h"
#include "ArduPID.h" #include "ArduPID.h"
#include "config.h"
#include "console.h"
#include <Arduino.h>
#include "LedControl.h" #include "LedControl.h"
#include "FermenterData.h" #include "FermenterData.h"
@ -39,7 +36,7 @@ double temperatureTarget = PID_DEFAULT_TARGET;
double temperatureOver = PID_DEFAULT_OVER; double temperatureOver = PID_DEFAULT_OVER;
double temperatureCurrent = NAN; double temperature = NAN;
double heaterPWM = 0; double heaterPWM = 0;
@ -59,7 +56,7 @@ void patrixSetup() {
configLoaded(); configLoaded();
pid.begin(&temperatureCurrent, &heaterPWM, &temperatureTarget, proportional, integral, derivative); pid.begin(&temperature, &heaterPWM, &temperatureTarget, proportional, integral, derivative);
pid.setOutputLimits(0, CONTROL_PWM_MAX); pid.setOutputLimits(0, CONTROL_PWM_MAX);
pid.start(); pid.start();
} }
@ -77,15 +74,15 @@ void patrixLoop() {
} }
void pidLoop() { void pidLoop() {
temperatureCurrent = sensor.getLastValue(); temperature = sensor.getLastValue();
if (!isnan(temperatureCurrent)) { if (!isnan(temperature)) {
pid.compute(); pid.compute();
} else { } else {
heaterPWM = 0; heaterPWM = 0;
} }
const char *emergencyStr = ""; const char *emergencyStr = "";
if (heaterPWM > 0 && temperatureCurrent > temperatureTarget + temperatureOver) { if (heaterPWM > 0 && temperature > temperatureTarget + temperatureOver) {
heaterPWM = 0; heaterPWM = 0;
emergencyStr = "[EMERGENCY CUTOFF]"; emergencyStr = "[EMERGENCY CUTOFF]";
} }
@ -108,7 +105,7 @@ void pidLoop() {
temperatureTarget, temperatureTarget,
heaterPercent, heaterPercent,
temperatureCurrent, temperature,
emergencyStr emergencyStr
); );
@ -125,7 +122,7 @@ void displayLoop() {
lc.clearDisplay(0); lc.clearDisplay(0);
} }
int digit = 0; int digit = 0;
writeDecimal(&digit, temperatureCurrent); writeDecimal(&digit, temperature);
digit++; digit++;
digit++; digit++;
writeDecimal(&digit, temperatureTarget); writeDecimal(&digit, temperatureTarget);
@ -142,7 +139,7 @@ void writeDecimal(int *digit, double value) {
bool setDouble(const char *name, double *destinationPtr, double min, double max) { bool setDouble(const char *name, double *destinationPtr, double min, double max) {
const char *valueStr = strtok(nullptr, ""); const char *valueStr = strtok(nullptr, "");
if (valueStr == nullptr) { if (valueStr == nullptr) {
_usage(); consolePrintUsage();
return false; return false;
} }
double value = strtod(valueStr, nullptr); double value = strtod(valueStr, nullptr);

View File

@ -1,5 +1,5 @@
#ifndef SENSOR3_FERMENTERDATA_H #ifndef SENSOR3_FERMENTER_DATA_H
#define SENSOR3_FERMENTERDATA_H #define SENSOR3_FERMENTER_DATA_H
#include "data.h" #include "data.h"