serial print dot on no output

This commit is contained in:
devdesk
2026-02-06 14:15:09 +02:00
parent c8d990b1cd
commit c7e28c5116

View File

@@ -70,6 +70,10 @@ void MotorController::stop() {
void MotorController::update() {
#if CURRENT_SENSING_ENABLED
static unsigned long lastPrintTime = 0;
static bool lastWasIdle = false;
static int idleDotCount = 0;
const int dotsPerLine = 50; // Print newline after this many dots
const int dotInterval = 5; // Print dot every N idle readings
// Read current sensors
_currentRight = readCurrentSense(R_IS_PIN);
@@ -79,8 +83,37 @@ void MotorController::update() {
unsigned long now = millis();
if (now - lastPrintTime >= CURRENT_LOG_INTERVAL_MS) {
lastPrintTime = now;
Serial.printf("CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d\n",
_currentRight, _currentLeft, _direction, _speed);
// Check if this is an idle reading (all zeros)
bool isIdle = (_currentRight < 0.01f && _currentLeft < 0.01f && _direction == 0);
if (isIdle) {
if (!lastWasIdle) {
// First idle after non-idle: print full line once
Serial.printf("CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d\n",
_currentRight, _currentLeft, _direction, _speed);
idleDotCount = 0;
} else {
// Subsequent idle: print dot every N readings
idleDotCount++;
if (idleDotCount % dotInterval == 0) {
Serial.print(".");
if ((idleDotCount / dotInterval) % dotsPerLine == 0) {
Serial.println(); // Newline after dotsPerLine dots
}
}
}
lastWasIdle = true;
} else {
// Non-idle reading: always print full line
if (lastWasIdle && idleDotCount > 0) {
Serial.println(); // Newline after dots before full reading
}
Serial.printf("CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d\n",
_currentRight, _currentLeft, _direction, _speed);
lastWasIdle = false;
idleDotCount = 0;
}
}
// Check for stall condition