Patrix.h cleanup
This commit is contained in:
parent
b7b9ea61b5
commit
de4bdfa98b
@ -2,6 +2,9 @@
|
||||
#define SENSOR3_PATRIX_H
|
||||
|
||||
#include "base.h"
|
||||
#include "config.h"
|
||||
#include "console.h"
|
||||
#include "log.h"
|
||||
|
||||
void patrixSetup();
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -9,6 +9,6 @@ void consoleHandle(char *cmd);
|
||||
|
||||
bool patrix_command(char *cmd);
|
||||
|
||||
void _usage();
|
||||
void consolePrintUsage();
|
||||
|
||||
#endif
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
|
||||
#include "base.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include "wifi.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
struct IData {
|
||||
|
||||
|
||||
@ -4,9 +4,6 @@
|
||||
#include "sensors/Dallas.h"
|
||||
#include "sensors/DallasSensor.h"
|
||||
#include "ArduPID.h"
|
||||
#include "config.h"
|
||||
#include "console.h"
|
||||
#include <Arduino.h>
|
||||
#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);
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user