// 20260413 ChatGPT
// Exercise 19: SD Card Diagnostics

#include <Arduino.h>

#include "SdCardDiag.h"

#ifndef NODE_LABEL
#define NODE_LABEL "SDDIAG"
#endif

static const uint32_t kSerialDelayMs = 1500;
static const uint32_t kLoopDelayMs = 25;
static const uint32_t kReportEveryMs = 10000;

static SdCardDiag g_diag(Serial);
static uint32_t g_lastReportMs = 0;

void setup() {
  Serial.begin(115200);
  delay(kSerialDelayMs);

  Serial.println();
  Serial.println("============================================================");
  Serial.printf("Exercise 19 SD Card Diagnostics [%s]\r\n", NODE_LABEL);
  Serial.println("============================================================");

  g_diag.begin();
  g_diag.printReport();
  g_lastReportMs = millis();
}

void loop() {
  const uint32_t now = millis();
  if ((uint32_t)(now - g_lastReportMs) >= kReportEveryMs) {
    g_lastReportMs = now;
    g_diag.printReport();
  }

  delay(kLoopDelayMs);
}
