Compare commits

..

No commits in common. "19e81885a97da9b438bcf286d0eb7e8fa89be577" and "1e1a1c8a5bd906a2ad32e4fcb4e92a01b8aaf6be" have entirely different histories.

10 changed files with 23 additions and 69 deletions

View File

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

View File

@ -16,7 +16,7 @@ void patrixSetup() {
heater.setup();
rotary.setup();
pidSetup();
pid.setup();
httpSetup2();
}
@ -25,7 +25,7 @@ void patrixLoop() {
ds18b20.loop();
temperature.loop();
pidLoop();
pid.loop();
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, "%lu. %2lu:%02lu:%02lu", days, hours % 24, minutes % 60, seconds % 60);
snprintf(buffer, sizeof buffer, "%d. %2d:%02d:%02d", days, hours % 24, minutes % 60, seconds % 60);
} else {
snprintf(buffer, sizeof buffer, "%lu:%02lu:%02lu", hours % 24, minutes % 60, seconds % 60);
snprintf(buffer, sizeof buffer, "%d:%02d:%02d", hours % 24, minutes % 60, seconds % 60);
}
return {buffer};
}

View File

@ -5,17 +5,6 @@
#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;
@ -141,15 +130,22 @@ 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,12 +3,6 @@
#include "pid.h"
#include "config.h"
History history[3 * 60];
History* historyPtr = history;
unsigned long historyLastMinute = 0;
DS18B20 ds18b20(
"DS18B20",
D4
@ -45,20 +39,4 @@ 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,20 +7,6 @@
#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;
@ -31,8 +17,4 @@ extern PIDController pid;
void addTarget(double delta);
void pidSetup();
void pidLoop();
#endif

View File

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

View File

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

View File

@ -5,18 +5,15 @@
AsyncWebServer server(80);
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) {
void httpNotFound(AsyncWebServerRequest *request) {
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 5
#define BOOT_DELAY_SEC 1
auto wifiConnected = false;