Compare commits

..

5 Commits

10 changed files with 69 additions and 23 deletions

View File

@ -1,8 +1,8 @@
{
"pid": {
"p": 5,
"i": 0,
"p": 20,
"i": 1e-6,
"d": 0,
"target": 0
"target": 28
}
}

View File

@ -16,7 +16,7 @@ void patrixSetup() {
heater.setup();
rotary.setup();
pid.setup();
pidSetup();
httpSetup2();
}
@ -25,7 +25,7 @@ void patrixLoop() {
ds18b20.loop();
temperature.loop();
pid.loop();
pidLoop();
rotary.loop();
program.loop();

View File

@ -11,9 +11,9 @@ inline String durationString(const unsigned long millis) {
const unsigned long days = hours / 24;
char buffer[15];
if (days > 0) {
snprintf(buffer, sizeof buffer, "%d. %2d:%02d:%02d", days, hours % 24, minutes % 60, seconds % 60);
snprintf(buffer, sizeof buffer, "%lu. %2lu:%02lu:%02lu", days, hours % 24, minutes % 60, seconds % 60);
} else {
snprintf(buffer, sizeof buffer, "%d:%02d:%02d", hours % 24, minutes % 60, seconds % 60);
snprintf(buffer, sizeof buffer, "%lu:%02lu:%02lu", hours % 24, minutes % 60, seconds % 60);
}
return {buffer};
}

View File

@ -5,6 +5,17 @@
#include "pid.h"
#include "Program.h"
void httpHistory(AsyncWebServerRequest* request) {
AsyncResponseStream* stream = request->beginResponseStream("text/plain");
constexpr int size = std::size(history);
const History* h = history;
for (int i = 0; i < size; i++) {
stream->printf("%d/%d/%d\n", h->target, h->temperature, h->heater);
h = (h - history + size - 1) % size + history;
}
request->send(stream);
}
void httpStatus(AsyncWebServerRequest* request) {
JsonDocument json;
json["pid"]["p"] = pid.p;
@ -130,22 +141,15 @@ void httpProgramResume(AsyncWebServerRequest* request) {
}
void httpSetup2() {
server.on("/history", httpHistory);
server.on("/status", httpStatus);
server.on("/status/", httpStatus);
server.on("/target/add", httpTargetAdd);
server.on("/target/add/", httpTargetAdd);
server.on("/config/set", httpConfigSet);
server.on("/config/set/", httpConfigSet);
server.on("/program/load", httpProgramLoad);
server.on("/program/load/", httpProgramLoad);
server.on("/program/start", httpProgramStart);
server.on("/program/start/", httpProgramStart);
server.on("/program/stop", httpProgramStop);
server.on("/program/stop/", httpProgramStop);
server.on("/program/pause", httpProgramPause);
server.on("/program/pause/", httpProgramPause);
server.on("/program/resume", httpProgramResume);
server.on("/program/resume/", httpProgramResume);
}
#endif

View File

@ -3,6 +3,12 @@
#include "pid.h"
#include "config.h"
History history[3 * 60];
History* historyPtr = history;
unsigned long historyLastMinute = 0;
DS18B20 ds18b20(
"DS18B20",
D4
@ -39,4 +45,20 @@ void addTarget(const double delta) {
config.markDirty();
}
void pidSetup() {
pid.setup();
}
void pidLoop() {
pid.loop();
const auto currentMinute = millis() / 60000;
if (historyLastMinute != currentMinute) {
historyLastMinute = currentMinute;
historyPtr = (historyPtr - history + 1) % std::size(history) + history;
}
historyPtr->heater = static_cast<uint8_t>(heater.getPercent());
historyPtr->target = static_cast<int16_t>(pid.getTarget() * 10);
historyPtr->temperature = static_cast<int16_t>(temperature.getValue() * 10);
}
#endif

View File

@ -7,6 +7,20 @@
#define HEATER_POWER_W 30
struct History {
int16_t target;
int16_t temperature;
uint8_t heater;
};
extern History history[3 * 60];
extern History* historyPtr;
extern DS18B20 ds18b20;
extern DS18B20Sensor temperature;
@ -17,4 +31,8 @@ extern PIDController pid;
void addTarget(double delta);
void pidSetup();
void pidLoop();
#endif

View File

@ -1,6 +1,8 @@
#include <LittleFS.h>
#include "Patrix.h"
#include "http.h"
#include "mqtt.h"
#include "system.h"
void setup() {

View File

@ -1,9 +1,6 @@
#ifndef PATRIX_H
#define PATRIX_H
#include "wifi.h"
#include "mqtt.h"
void patrixSetup();
void patrixLoop();

View File

@ -5,15 +5,18 @@
AsyncWebServer server(80);
void httpNotFound(AsyncWebServerRequest *request) {
if (request->method() == HTTP_OPTIONS) {
void httpNotFound(AsyncWebServerRequest* request) {
const String path = request->url();
if (path.endsWith("/") && path.length() > 1) {
request->redirect(path.substring(0, path.length() - 1));
} else if (request->method() == HTTP_OPTIONS) {
request->send(200);
} else {
request->send(404, "text/plain", "not found");
}
}
void httpRestart([[maybe_unused]] AsyncWebServerRequest *request) {
void httpRestart([[maybe_unused]] AsyncWebServerRequest* request) {
systemRequestRestart();
request->send(200, "application/json", "true");
}

View File

@ -7,7 +7,7 @@
#define WIFI_SSID "HappyNet"
#define WIFI_PASSWORD "1Grausame!Sackratte7"
#define NTP_SERVER "107.189.12.98" /* pool.ntp.org */
#define BOOT_DELAY_SEC 1
#define BOOT_DELAY_SEC 5
auto wifiConnected = false;