Format debug output by field
This commit is contained in:
+87
-40
@@ -515,7 +515,7 @@ void updateDebugOutput(unsigned long currentTime) {
|
||||
|
||||
if (lastDebugPrintTime == 0 || currentTime - lastDebugPrintTime >= DEBUG_INTERVAL_MS) {
|
||||
lastDebugPrintTime = currentTime;
|
||||
printStatus(F("DEBUG"));
|
||||
printDebugLine();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,50 +625,65 @@ void printStatus(const __FlashStringHelper *tag) {
|
||||
printAutoCalibrationDelayStatus();
|
||||
}
|
||||
|
||||
void printUptime() {
|
||||
unsigned long totalMs = millis();
|
||||
unsigned long hours = totalMs / 3600000UL;
|
||||
totalMs %= 3600000UL;
|
||||
unsigned long minutes = totalMs / 60000UL;
|
||||
totalMs %= 60000UL;
|
||||
unsigned long seconds = totalMs / 1000UL;
|
||||
unsigned long milliseconds = totalMs % 1000UL;
|
||||
|
||||
Serial.print(F("uptime="));
|
||||
Serial.print(hours);
|
||||
Serial.print(F("h "));
|
||||
Serial.print(minutes);
|
||||
Serial.print(F("m "));
|
||||
Serial.print(seconds);
|
||||
Serial.print(F("s "));
|
||||
Serial.print(milliseconds);
|
||||
Serial.println(F("ms"));
|
||||
void printDebugLine() {
|
||||
Serial.println();
|
||||
Serial.println(F("[DEBUG]"));
|
||||
printUptime();
|
||||
printNamedInt(F("raw"), parkingRawValue);
|
||||
printNamedBool(F("ig"), ignitionState == HIGH);
|
||||
printNamedBool(F("p"), parkingState == HIGH);
|
||||
printNamedBool(F("rawDrive"), getRawDriveMode() == HIGH);
|
||||
printNamedBool(F("confirmedDrive"), confirmedDriveMode == HIGH);
|
||||
printNamedLong(F("currentMs"), currentPosMs);
|
||||
printNamedLong(F("targetMs"), targetPosMs);
|
||||
printNamedInt(F("savedMs"), storedSeatPositionMs);
|
||||
printNamedInt(F("hardLimitMs"), SEAT_HARD_LIMIT_UP_MS);
|
||||
printNamedInt(F("requestedRelay"), requestedSeatAction);
|
||||
printNamedInt(F("actualRelay"), currentSeatAction);
|
||||
printNamedBool(F("manual"), manualMode);
|
||||
printNamedBool(F("stabilizing"), isStabilizing);
|
||||
Serial.print(F("useCount="));
|
||||
Serial.print(useCount);
|
||||
Serial.print(F("/"));
|
||||
Serial.println(USES_BEFORE_AUTO_CALIBRATION);
|
||||
printNamedBool(F("autoPending"), autoCalibrationPending);
|
||||
printNamedBool(F("forceCal"), forceCalibration);
|
||||
printNamedInt(F("autoCalState"), autoCalibrationState);
|
||||
printAutoCalibrationDelayStatus();
|
||||
}
|
||||
|
||||
void printAutoCalibrationDelayStatus() {
|
||||
if (useCount < USES_BEFORE_AUTO_CALIBRATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print(F("autoCalOffTimer="));
|
||||
if (ignitionState == HIGH) {
|
||||
Serial.println(F("waiting_for_ig_off"));
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long elapsedMs = millis() - ignitionOffStartTime;
|
||||
unsigned long remainingMs = 0;
|
||||
if (elapsedMs < AUTO_CALIBRATION_DELAY_MS) {
|
||||
remainingMs = AUTO_CALIBRATION_DELAY_MS - elapsedMs;
|
||||
}
|
||||
|
||||
Serial.print(F("elapsed "));
|
||||
printDuration(elapsedMs);
|
||||
Serial.print(F(" remaining "));
|
||||
printDuration(remainingMs);
|
||||
void printUptime() {
|
||||
Serial.print(F("uptime="));
|
||||
printDuration(millis());
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printUptimeInline() {
|
||||
Serial.print(F("uptime="));
|
||||
printDuration(millis());
|
||||
}
|
||||
|
||||
void printBool(bool value) {
|
||||
Serial.print(value ? F("true") : F("false"));
|
||||
}
|
||||
|
||||
void printNamedBool(const __FlashStringHelper *name, bool value) {
|
||||
Serial.print(name);
|
||||
Serial.print(F("="));
|
||||
printBool(value);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printNamedInt(const __FlashStringHelper *name, long value) {
|
||||
Serial.print(name);
|
||||
Serial.print(F("="));
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void printNamedLong(const __FlashStringHelper *name, long value) {
|
||||
printNamedInt(name, value);
|
||||
}
|
||||
|
||||
void printDuration(unsigned long totalMs) {
|
||||
unsigned long hours = totalMs / 3600000UL;
|
||||
totalMs %= 3600000UL;
|
||||
@@ -687,6 +702,38 @@ void printDuration(unsigned long totalMs) {
|
||||
Serial.print(F("ms"));
|
||||
}
|
||||
|
||||
void printAutoCalibrationDelayStatusInline() {
|
||||
if (useCount < USES_BEFORE_AUTO_CALIBRATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print(F(" autoCalOffTimer="));
|
||||
if (ignitionState == HIGH) {
|
||||
Serial.print(F("waiting_for_ig_off"));
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long elapsedMs = millis() - ignitionOffStartTime;
|
||||
unsigned long remainingMs = 0;
|
||||
if (elapsedMs < AUTO_CALIBRATION_DELAY_MS) {
|
||||
remainingMs = AUTO_CALIBRATION_DELAY_MS - elapsedMs;
|
||||
}
|
||||
|
||||
Serial.print(F("elapsed "));
|
||||
printDuration(elapsedMs);
|
||||
Serial.print(F(" remaining "));
|
||||
printDuration(remainingMs);
|
||||
}
|
||||
|
||||
void printAutoCalibrationDelayStatus() {
|
||||
if (useCount < USES_BEFORE_AUTO_CALIBRATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
printAutoCalibrationDelayStatusInline();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setRelay(int relayPin, boolean state) {
|
||||
digitalWrite(relayPin, state ? LOW : HIGH);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user