Format debug output by field

This commit is contained in:
2026-06-07 13:25:13 +09:00
parent 4a68bd39c6
commit 9ebe8656fb
3 changed files with 111 additions and 40 deletions
+87 -40
View File
@@ -515,7 +515,7 @@ void updateDebugOutput(unsigned long currentTime) {
if (lastDebugPrintTime == 0 || currentTime - lastDebugPrintTime >= DEBUG_INTERVAL_MS) { if (lastDebugPrintTime == 0 || currentTime - lastDebugPrintTime >= DEBUG_INTERVAL_MS) {
lastDebugPrintTime = currentTime; lastDebugPrintTime = currentTime;
printStatus(F("DEBUG")); printDebugLine();
} }
} }
@@ -625,50 +625,65 @@ void printStatus(const __FlashStringHelper *tag) {
printAutoCalibrationDelayStatus(); printAutoCalibrationDelayStatus();
} }
void printUptime() { void printDebugLine() {
unsigned long totalMs = millis(); Serial.println();
unsigned long hours = totalMs / 3600000UL; Serial.println(F("[DEBUG]"));
totalMs %= 3600000UL; printUptime();
unsigned long minutes = totalMs / 60000UL; printNamedInt(F("raw"), parkingRawValue);
totalMs %= 60000UL; printNamedBool(F("ig"), ignitionState == HIGH);
unsigned long seconds = totalMs / 1000UL; printNamedBool(F("p"), parkingState == HIGH);
unsigned long milliseconds = totalMs % 1000UL; printNamedBool(F("rawDrive"), getRawDriveMode() == HIGH);
printNamedBool(F("confirmedDrive"), confirmedDriveMode == HIGH);
Serial.print(F("uptime=")); printNamedLong(F("currentMs"), currentPosMs);
Serial.print(hours); printNamedLong(F("targetMs"), targetPosMs);
Serial.print(F("h ")); printNamedInt(F("savedMs"), storedSeatPositionMs);
Serial.print(minutes); printNamedInt(F("hardLimitMs"), SEAT_HARD_LIMIT_UP_MS);
Serial.print(F("m ")); printNamedInt(F("requestedRelay"), requestedSeatAction);
Serial.print(seconds); printNamedInt(F("actualRelay"), currentSeatAction);
Serial.print(F("s ")); printNamedBool(F("manual"), manualMode);
Serial.print(milliseconds); printNamedBool(F("stabilizing"), isStabilizing);
Serial.println(F("ms")); 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() { void printUptime() {
if (useCount < USES_BEFORE_AUTO_CALIBRATION) { Serial.print(F("uptime="));
return; printDuration(millis());
}
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);
Serial.println(); 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) { void printDuration(unsigned long totalMs) {
unsigned long hours = totalMs / 3600000UL; unsigned long hours = totalMs / 3600000UL;
totalMs %= 3600000UL; totalMs %= 3600000UL;
@@ -687,6 +702,38 @@ void printDuration(unsigned long totalMs) {
Serial.print(F("ms")); 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) { void setRelay(int relayPin, boolean state) {
digitalWrite(relayPin, state ? LOW : HIGH); digitalWrite(relayPin, state ? LOW : HIGH);
} }
+23
View File
@@ -98,6 +98,29 @@ If IG1 is still ON:
autoCalOffTimer=waiting_for_ig_off autoCalOffTimer=waiting_for_ig_off
``` ```
Debug mode prints a readable block every second, one item per line. Boolean values are printed as `true` or `false`:
```text
[DEBUG]
uptime=0h 0m 5s 123ms
raw=1023
ig=true
p=true
rawDrive=false
confirmedDrive=false
currentMs=0
targetMs=0
savedMs=6000
requestedRelay=0
actualRelay=0
manual=false
stabilizing=false
useCount=0/10
autoPending=false
forceCal=false
autoCalState=0
```
## Automatic Calibration ## Automatic Calibration
- Each `IG1 HIGH -> LOW` transition increments the EEPROM use counter. - Each `IG1 HIGH -> LOW` transition increments the EEPROM use counter.
+1
View File
@@ -226,6 +226,7 @@ when currentPosMs <= 0:
<p><span class="warn">주의:</span> 명령은 한 글자만 받습니다. <code>debug</code>, <code>down</code>, <code>position 2000</code>처럼 긴 문자열은 실행하지 않습니다.</p> <p><span class="warn">주의:</span> 명령은 한 글자만 받습니다. <code>debug</code>, <code>down</code>, <code>position 2000</code>처럼 긴 문자열은 실행하지 않습니다.</p>
<p>모든 상태 출력에는 부팅 후 경과 시간이 <code>uptime=0h 2m 13s 457ms</code> 형식으로 포함됩니다. debug 출력에서도 1초마다 같은 형식으로 확인할 수 있습니다.</p> <p>모든 상태 출력에는 부팅 후 경과 시간이 <code>uptime=0h 2m 13s 457ms</code> 형식으로 포함됩니다. debug 출력에서도 1초마다 같은 형식으로 확인할 수 있습니다.</p>
<p>사용 횟수가 10회에 도달한 경우에만 보정 대기 타이머가 <code>autoCalOffTimer=elapsed 0h 1m 20s 123ms remaining 0h 3m 39s 877ms</code> 형식으로 추가 출력됩니다. IG1 ON 상태에서는 <code>autoCalOffTimer=waiting_for_ig_off</code>로 표시됩니다.</p> <p>사용 횟수가 10회에 도달한 경우에만 보정 대기 타이머가 <code>autoCalOffTimer=elapsed 0h 1m 20s 123ms remaining 0h 3m 39s 877ms</code> 형식으로 추가 출력됩니다. IG1 ON 상태에서는 <code>autoCalOffTimer=waiting_for_ig_off</code>로 표시됩니다.</p>
<p>debug 출력은 1초마다 항목별 한 줄 형식으로 표시되며, <code>ig=true</code>, <code>p=false</code>, <code>autoPending=false</code>처럼 bool 값은 <code>true</code>/<code>false</code>로 출력됩니다.</p>
<h2>5. 수동 위치 세팅 시뮬레이션</h2> <h2>5. 수동 위치 세팅 시뮬레이션</h2>
<table> <table>