Cleanup serial output

This commit is contained in:
Dave Allie
2025-12-08 22:39:23 +11:00
parent b743a1ca8e
commit 07cc589e59
10 changed files with 92 additions and 95 deletions

View File

@@ -23,7 +23,7 @@ bool CrossPointState::loadFromFile() {
uint8_t version;
serialization::readPod(inputFile, version);
if (version != STATE_FILE_VERSION) {
Serial.printf("CrossPointState: Unknown version %u\n", version);
Serial.printf("[%lu] [CPS] Deserialization failed: Unknown version %u\n", millis(), version);
inputFile.close();
return false;
}

View File

@@ -64,7 +64,7 @@ constexpr unsigned long POWER_BUTTON_SLEEP_MS = 1000;
Epub* loadEpub(const std::string& path) {
if (!SD.exists(path.c_str())) {
Serial.printf("File does not exist: %s\n", path.c_str());
Serial.printf("[%lu] [ ] File does not exist: %s\n", millis(), path.c_str());
return nullptr;
}
@@ -73,7 +73,7 @@ Epub* loadEpub(const std::string& path) {
return epub;
}
Serial.println("Failed to load epub");
Serial.printf("[%lu] [ ] Failed to load epub\n", millis());
delete epub;
return nullptr;
}
@@ -96,15 +96,13 @@ void verifyWakeupLongPress() {
const auto start = millis();
bool abort = false;
Serial.println("Verifying power button press");
Serial.printf("[%lu] [ ] Verifying power button press\n", millis());
inputManager.update();
while (!inputManager.isPressed(InputManager::BTN_POWER) && millis() - start < 1000) {
delay(50);
inputManager.update();
Serial.println("Waiting...");
}
Serial.printf("Made it? %s\n", inputManager.isPressed(InputManager::BTN_POWER) ? "yes" : "no");
if (inputManager.isPressed(InputManager::BTN_POWER)) {
do {
delay(50);
@@ -115,8 +113,6 @@ void verifyWakeupLongPress() {
abort = true;
}
Serial.printf("held for %lu\n", inputManager.getHeldTime());
if (abort) {
// Button released too early. Returning to sleep.
// IMPORTANT: Re-arm the wakeup trigger before sleeping again
@@ -138,7 +134,7 @@ void enterDeepSleep() {
exitScreen();
enterNewScreen(new SleepScreen(renderer, inputManager));
Serial.println("Power button released after a long press. Entering deep sleep.");
Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis());
delay(1000); // Allow Serial buffer to empty and display to update
// Enable Wakeup on LOW (button press)
@@ -193,12 +189,12 @@ void setup() {
// Initialize display
einkDisplay.begin();
Serial.println("Display initialized");
Serial.printf("[%lu] [ ] Display initialized\n", millis());
renderer.insertFont(READER_FONT_ID, bookerlyFontFamily);
renderer.insertFont(UI_FONT_ID, ubuntuFontFamily);
renderer.insertFont(SMALL_FONT_ID, smallFontFamily);
Serial.println("Fonts loaded");
Serial.printf("[%lu] [ ] Fonts setup\n", millis());
exitScreen();
enterNewScreen(new BootLogoScreen(renderer, inputManager));
@@ -229,8 +225,8 @@ void loop() {
delay(10);
static unsigned long lastMemPrint = 0;
if (Serial && millis() - lastMemPrint >= 5000) {
Serial.printf("[%lu] Memory - Free: %d bytes, Total: %d bytes, Min Free: %d bytes\n", millis(), ESP.getFreeHeap(),
if (Serial && millis() - lastMemPrint >= 10000) {
Serial.printf("[%lu] [MEM] Free: %d bytes, Total: %d bytes, Min Free: %d bytes\n", millis(), ESP.getFreeHeap(),
ESP.getHeapSize(), ESP.getMinFreeHeap());
lastMemPrint = millis();
}

View File

@@ -36,7 +36,7 @@ void EpubReaderScreen::onEnter() {
f.read(data, 4);
currentSpineIndex = data[0] + (data[1] << 8);
nextPageNumber = data[2] + (data[3] << 8);
Serial.printf("Loaded cache: %d, %d\n", currentSpineIndex, nextPageNumber);
Serial.printf("[%lu] [ERS] Loaded cache: %d, %d\n", millis(), currentSpineIndex, nextPageNumber);
f.close();
}
@@ -154,11 +154,11 @@ void EpubReaderScreen::renderScreen() {
if (!section) {
const auto filepath = epub->getSpineItem(currentSpineIndex);
Serial.printf("Loading file: %s, index: %d\n", filepath.c_str(), currentSpineIndex);
Serial.printf("[%lu] [ERS] Loading file: %s, index: %d\n", millis(), filepath.c_str(), currentSpineIndex);
section = new Section(epub, currentSpineIndex, renderer);
if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
marginLeft)) {
Serial.println("Cache not found, building...");
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
{
const int textWidth = renderer.getTextWidth(READER_FONT_ID, "Indexing...");
@@ -171,20 +171,20 @@ void EpubReaderScreen::renderScreen() {
renderer.fillRect(x, y, w, h, 0);
renderer.drawText(READER_FONT_ID, x + margin, y + margin, "Indexing...");
renderer.drawRect(x + 5, y + 5, w - 10, h - 10);
renderer.displayBuffer(EInkDisplay::HALF_REFRESH);
renderer.displayBuffer();
pagesUntilFullRefresh = 0;
}
section->setupCacheDir();
if (!section->persistPageDataToSD(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
marginLeft)) {
Serial.println("Failed to persist page data to SD");
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
delete section;
section = nullptr;
return;
}
} else {
Serial.println("Cache found, skipping build...");
Serial.printf("[%lu] [ERS] Cache found, skipping build...\n", millis());
}
if (nextPageNumber == UINT16_MAX) {
@@ -197,7 +197,7 @@ void EpubReaderScreen::renderScreen() {
renderer.clearScreen();
if (section->pageCount == 0) {
Serial.println("No pages to render");
Serial.printf("[%lu] [ERS] No pages to render\n", millis());
const int width = renderer.getTextWidth(READER_FONT_ID, "Empty chapter", BOLD);
renderer.drawText(READER_FONT_ID, (GfxRenderer::getScreenWidth() - width) / 2, 300, "Empty chapter", true, BOLD);
renderStatusBar();
@@ -206,7 +206,7 @@ void EpubReaderScreen::renderScreen() {
}
if (section->currentPage < 0 || section->currentPage >= section->pageCount) {
Serial.printf("Page out of bounds: %d (max %d)\n", section->currentPage, section->pageCount);
Serial.printf("[%lu] [ERS] Page out of bounds: %d (max %d)\n", millis(), section->currentPage, section->pageCount);
const int width = renderer.getTextWidth(READER_FONT_ID, "Out of bounds", BOLD);
renderer.drawText(READER_FONT_ID, (GfxRenderer::getScreenWidth() - width) / 2, 300, "Out of bounds", true, BOLD);
renderStatusBar();
@@ -215,7 +215,9 @@ void EpubReaderScreen::renderScreen() {
}
const Page* p = section->loadPageFromSD();
const auto start = millis();
renderContents(p);
Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);
delete p;
File f = SD.open((epub->getCachePath() + "/progress.bin").c_str(), FILE_WRITE);