safety commit
This commit is contained in:
67
src/main.cpp
67
src/main.cpp
@@ -146,6 +146,8 @@ void printStatus(float avgTemp, float minTemp, float maxTemp) {
|
||||
Serial.print(F("(off)"));
|
||||
} else if (thermal.isIdleCooling()) {
|
||||
Serial.print(F("(cooldown)"));
|
||||
} else if (thermal.fanPwm() == 0) {
|
||||
Serial.print(F("(cmd-off)"));
|
||||
}
|
||||
Serial.print(F(" cutoff="));
|
||||
Serial.print(thermal.isCutoffActive() ? F("YES") : F("no"));
|
||||
@@ -164,6 +166,18 @@ void printStatus(float avgTemp, float minTemp, float maxTemp) {
|
||||
Serial.print(F("cyc pre>="));
|
||||
Serial.print(thermal.autotunePreheatTargetC(), 0);
|
||||
Serial.print(F("C"));
|
||||
} else if (thermal.isStepResponseActive()) {
|
||||
Serial.print(F("stepresp/"));
|
||||
Serial.print(thermal.stepResponsePhaseName());
|
||||
Serial.print(F(" "));
|
||||
Serial.print(thermal.stepResponseElapsedMs(millis()) / 1000UL);
|
||||
Serial.print(F("s step "));
|
||||
Serial.print(thermal.stepResponseStepIndex() + 1);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(thermal.stepResponseStepCount());
|
||||
Serial.print(F(" heat="));
|
||||
Serial.print(thermal.stepResponseHeaterPct(), 0);
|
||||
Serial.print(F("%"));
|
||||
} else if (thermal.isAdaptive()) {
|
||||
Serial.print(F("learned"));
|
||||
} else {
|
||||
@@ -199,6 +213,8 @@ void printHelp() {
|
||||
Serial.println(F(" fan test N set fan PWM 0-255 for 15s (verify wiring)"));
|
||||
Serial.println(F(" autotune [C] learn PID (default: 40C when idle)"));
|
||||
Serial.println(F(" autotune stop"));
|
||||
Serial.println(F(" stepresp [C] [heater%] fan step response (default: 45C 35%)"));
|
||||
Serial.println(F(" stepresp stop"));
|
||||
Serial.println(F(" pid show PID / adaptive status"));
|
||||
Serial.println(F(" pid default reset to factory PID"));
|
||||
Serial.println(F(" status print current readings"));
|
||||
@@ -328,6 +344,45 @@ void processSerialLine(const char *line) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "stepresp", 8) == 0) {
|
||||
if (strcmp(line, "stepresp stop") == 0) {
|
||||
thermal.stopStepResponse();
|
||||
Serial.println(F("OK stepresp cancelled"));
|
||||
return;
|
||||
}
|
||||
|
||||
float tempC = STEPRESP_DEFAULT_TEMP_C;
|
||||
float heaterPct = STEPRESP_DEFAULT_HEATER_PCT;
|
||||
if (line[8] == ' ') {
|
||||
const char *args = line + 9;
|
||||
tempC = atof(args);
|
||||
const char *space = strchr(args, ' ');
|
||||
if (space != nullptr) {
|
||||
heaterPct = atof(space + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (tempC < 25.0f || tempC > TARGET_MAX_C) {
|
||||
Serial.println(F("ERR stepresp temperature must be 25-80 C"));
|
||||
return;
|
||||
}
|
||||
if (heaterPct < STEPRESP_MIN_HEATER_PCT || heaterPct > STEPRESP_MAX_HEATER_PCT) {
|
||||
Serial.print(F("ERR stepresp heater must be "));
|
||||
Serial.print(STEPRESP_MIN_HEATER_PCT, 0);
|
||||
Serial.print(F("-"));
|
||||
Serial.print(STEPRESP_MAX_HEATER_PCT, 0);
|
||||
Serial.println(F("%"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!thermal.startStepResponse(tempC, heaterPct)) {
|
||||
Serial.println(F("ERR stepresp already running or autotune active"));
|
||||
return;
|
||||
}
|
||||
Serial.println(F("OK stepresp started — open-loop heater, fan steps, ~25-35 min"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(line, "pid") == 0 || strcmp(line, "pid show") == 0) {
|
||||
thermal.printTuning();
|
||||
return;
|
||||
@@ -428,6 +483,18 @@ void loop() {
|
||||
|
||||
if (!isnan(avgTemp) && !isnan(maxTemp) && !isnan(spread)) {
|
||||
thermal.update(avgTemp, maxTemp, spread, now);
|
||||
|
||||
float sensorTemps[SENSOR_COUNT];
|
||||
bool sensorValid[SENSOR_COUNT];
|
||||
for (uint8_t i = 0; i < SENSOR_COUNT; ++i) {
|
||||
sensorTemps[i] = sensors[i].temperatureC;
|
||||
sensorValid[i] = sensors[i].valid;
|
||||
}
|
||||
const float minTemp = minValidTemperature();
|
||||
if (thermal.isStepResponseActive() && !isnan(minTemp)) {
|
||||
thermal.logStepResponseIfDue(sensorTemps, sensorValid, SENSOR_COUNT, avgTemp, minTemp,
|
||||
maxTemp, spread, now);
|
||||
}
|
||||
} else {
|
||||
thermal.enterFailSafe();
|
||||
Serial.println(F("WARN: no valid sensor readings — heater off"));
|
||||
|
||||
Reference in New Issue
Block a user