Cleanup serial output

This commit is contained in:
Dave Allie 2025-12-08 22:39:23 +11:00
parent b743a1ca8e
commit 07cc589e59
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F
10 changed files with 92 additions and 95 deletions

View File

@ -11,7 +11,7 @@ bool Epub::findContentOpfFile(const ZipFile& zip, std::string& contentOpfFile) {
size_t s;
const auto metaInfo = reinterpret_cast<char*>(zip.readFileToMemory("META-INF/container.xml", &s, true));
if (!metaInfo) {
Serial.println("Could not find META-INF/container.xml");
Serial.printf("[%lu] [EBP] Could not find META-INF/container.xml\n", millis());
return false;
}
@ -21,19 +21,19 @@ bool Epub::findContentOpfFile(const ZipFile& zip, std::string& contentOpfFile) {
free(metaInfo);
if (result != tinyxml2::XML_SUCCESS) {
Serial.printf("Could not parse META-INF/container.xml. Error: %d\n", result);
Serial.printf("[%lu] [EBP] Could not parse META-INF/container.xml. Error: %d\n", millis(), result);
return false;
}
const auto container = metaDataDoc.FirstChildElement("container");
if (!container) {
Serial.println("Could not find container element in META-INF/container.xml");
Serial.printf("[%lu] [EBP] Could not find container element in META-INF/container.xml\n", millis());
return false;
}
const auto rootfiles = container->FirstChildElement("rootfiles");
if (!rootfiles) {
Serial.println("Could not find rootfiles element in META-INF/container.xml");
Serial.printf("[%lu] [EBP] Could not find rootfiles element in META-INF/container.xml\n", millis());
return false;
}
@ -51,7 +51,7 @@ bool Epub::findContentOpfFile(const ZipFile& zip, std::string& contentOpfFile) {
rootfile = rootfile->NextSiblingElement("rootfile");
}
Serial.println("Could not get path to content.opf file");
Serial.printf("[%lu] [EBP] Could not get path to content.opf file\n", millis());
return false;
}
@ -65,7 +65,8 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
free(contents);
if (result != tinyxml2::XML_SUCCESS) {
Serial.printf("Error parsing content.opf - %s\n", tinyxml2::XMLDocument::ErrorIDToName(result));
Serial.printf("[%lu] [EBP] Error parsing content.opf - %s\n", millis(),
tinyxml2::XMLDocument::ErrorIDToName(result));
return false;
}
@ -73,7 +74,7 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
if (!package) package = doc.FirstChildElement("opf:package");
if (!package) {
Serial.println("Could not find package element in content.opf");
Serial.printf("[%lu] [EBP] Could not find package element in content.opf\n", millis());
return false;
}
@ -81,13 +82,13 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
auto metadata = package->FirstChildElement("metadata");
if (!metadata) metadata = package->FirstChildElement("opf:metadata");
if (!metadata) {
Serial.println("Missing metadata");
Serial.printf("[%lu] [EBP] Missing metadata\n", millis());
return false;
}
auto titleEl = metadata->FirstChildElement("dc:title");
if (!titleEl) {
Serial.println("Missing title");
Serial.printf("[%lu] [EBP] Missing title\n", millis());
return false;
}
this->title = titleEl->GetText();
@ -98,7 +99,7 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
cover = cover->NextSiblingElement("meta");
}
if (!cover) {
Serial.println("Missing cover");
Serial.printf("[%lu] [EBP] Missing cover\n", millis());
}
auto coverItem = cover ? cover->Attribute("content") : nullptr;
@ -109,7 +110,7 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
auto manifest = package->FirstChildElement("manifest");
if (!manifest) manifest = package->FirstChildElement("opf:manifest");
if (!manifest) {
Serial.println("Missing manifest");
Serial.printf("[%lu] [EBP] Missing manifest\n", millis());
return false;
}
@ -142,7 +143,7 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
auto spineEl = package->FirstChildElement("spine");
if (!spineEl) spineEl = package->FirstChildElement("opf:spine");
if (!spineEl) {
Serial.println("Missing spine");
Serial.printf("[%lu] [EBP] Missing spine\n", millis());
return false;
}
@ -164,13 +165,13 @@ bool Epub::parseContentOpf(ZipFile& zip, std::string& content_opf_file) {
bool Epub::parseTocNcxFile(const ZipFile& zip) {
// the ncx file should have been specified in the content.opf file
if (tocNcxItem.empty()) {
Serial.println("No ncx file specified");
Serial.printf("[%lu] [EBP] No ncx file specified\n", millis());
return false;
}
const auto ncxData = reinterpret_cast<char*>(zip.readFileToMemory(tocNcxItem.c_str(), nullptr, true));
if (!ncxData) {
Serial.printf("Could not find %s\n", tocNcxItem.c_str());
Serial.printf("[%lu] [EBP] Could not find %s\n", millis(), tocNcxItem.c_str());
return false;
}
@ -180,19 +181,19 @@ bool Epub::parseTocNcxFile(const ZipFile& zip) {
free(ncxData);
if (result != tinyxml2::XML_SUCCESS) {
Serial.printf("Error parsing toc %s\n", tinyxml2::XMLDocument::ErrorIDToName(result));
Serial.printf("[%lu] [EBP] Error parsing toc %s\n", millis(), tinyxml2::XMLDocument::ErrorIDToName(result));
return false;
}
const auto ncx = doc.FirstChildElement("ncx");
if (!ncx) {
Serial.println("Could not find first child ncx in toc");
Serial.printf("[%lu] [EBP] Could not find first child ncx in toc\n", millis());
return false;
}
const auto navMap = ncx->FirstChildElement("navMap");
if (!navMap) {
Serial.println("Could not find navMap child in ncx");
Serial.printf("[%lu] [EBP] Could not find navMap child in ncx\n", millis());
return false;
}
@ -231,7 +232,7 @@ bool Epub::load() {
std::string contentOpfFile;
if (!findContentOpfFile(zip, contentOpfFile)) {
Serial.println("Could not open ePub");
Serial.printf("[%lu] [EBP] Could not open ePub\n", millis());
return false;
}
@ -314,7 +315,7 @@ uint8_t* Epub::readItemContentsToBytes(const std::string& itemHref, size_t* size
const auto content = zip.readFileToMemory(path.c_str(), size, trailingNullByte);
if (!content) {
Serial.printf("Failed to read item %s\n", path.c_str());
Serial.printf("[%lu] [EBP] Failed to read item %s\n", millis(), path.c_str());
return nullptr;
}
@ -332,7 +333,7 @@ int Epub::getSpineItemsCount() const { return spine.size(); }
std::string& Epub::getSpineItem(const int spineIndex) {
if (spineIndex < 0 || spineIndex >= spine.size()) {
Serial.printf("getSpineItem index:%d is out of range\n", spineIndex);
Serial.printf("[%lu] [EBP] getSpineItem index:%d is out of range\n", millis(), spineIndex);
return spine.at(0).second;
}
@ -341,7 +342,7 @@ std::string& Epub::getSpineItem(const int spineIndex) {
EpubTocEntry& Epub::getTocItem(const int tocTndex) {
if (tocTndex < 0 || tocTndex >= toc.size()) {
Serial.printf("getTocItem index:%d is out of range\n", tocTndex);
Serial.printf("[%lu] [EBP] getTocItem index:%d is out of range\n", millis(), tocTndex);
return toc.at(0);
}
@ -360,7 +361,7 @@ int Epub::getSpineIndexForTocIndex(const int tocIndex) const {
}
}
Serial.println("Section not found");
Serial.printf("[%lu] [EBP] Section not found\n", millis());
// not found - default to the start of the book
return 0;
}
@ -374,7 +375,7 @@ int Epub::getTocIndexForSpineIndex(const int spineIndex) const {
}
}
Serial.println("TOC item not found");
Serial.printf("[%lu] [EBP] TOC item not found\n", millis());
// not found - default to first item
return 0;
}

View File

@ -1,5 +1,5 @@
#pragma once
#include <HardwareSerial.h>
#include <Print.h>
#include <tinyxml2.h>
#include <string>

View File

@ -190,7 +190,7 @@ bool EpubHtmlParserSlim::parseAndBuildPages() {
int done;
if (!parser) {
Serial.println("Couldn't allocate memory for parser");
Serial.printf("[%lu] [EHP] Couldn't allocate memory for parser\n", millis());
return false;
}
@ -200,7 +200,7 @@ bool EpubHtmlParserSlim::parseAndBuildPages() {
FILE* file = fopen(filepath, "r");
if (!file) {
Serial.printf("Couldn't open file %s\n", filepath);
Serial.printf("[%lu] [EHP] Couldn't open file %s\n", millis(), filepath);
XML_ParserFree(parser);
return false;
}
@ -208,7 +208,7 @@ bool EpubHtmlParserSlim::parseAndBuildPages() {
do {
void* const buf = XML_GetBuffer(parser, 1024);
if (!buf) {
Serial.println("Couldn't allocate memory for buffer");
Serial.printf("[%lu] [EHP] Couldn't allocate memory for buffer\n", millis());
XML_ParserFree(parser);
fclose(file);
return false;
@ -217,7 +217,7 @@ bool EpubHtmlParserSlim::parseAndBuildPages() {
const size_t len = fread(buf, 1, 1024, file);
if (ferror(file)) {
Serial.println("Read error");
Serial.printf("[%lu] [EHP] File read error\n", millis());
XML_ParserFree(parser);
fclose(file);
return false;
@ -226,7 +226,7 @@ bool EpubHtmlParserSlim::parseAndBuildPages() {
done = feof(file);
if (XML_ParseBuffer(parser, static_cast<int>(len), done) == XML_STATUS_ERROR) {
Serial.printf("Parse error at line %lu:\n%s\n", XML_GetCurrentLineNumber(parser),
Serial.printf("[%lu] [EHP] Parse error at line %lu:\n%s\n", millis(), XML_GetCurrentLineNumber(parser),
XML_ErrorString(XML_GetErrorCode(parser)));
XML_ParserFree(parser);
fclose(file);
@ -251,7 +251,7 @@ bool EpubHtmlParserSlim::parseAndBuildPages() {
void EpubHtmlParserSlim::makePages() {
if (!currentTextBlock) {
Serial.println("!! No text block to make pages for !!");
Serial.printf("[%lu] [EHP] !! No text block to make pages for !!\n", millis());
return;
}

View File

@ -26,11 +26,9 @@ PageLine* PageLine::deserialize(std::istream& is) {
}
void Page::render(GfxRenderer& renderer, const int fontId) const {
const auto start = millis();
for (const auto element : elements) {
element->render(renderer, fontId);
}
Serial.printf("Rendered page elements (%u) in %dms\n", elements.size(), millis() - start);
}
void Page::serialize(std::ostream& os) const {
@ -50,7 +48,7 @@ Page* Page::deserialize(std::istream& is) {
uint8_t version;
serialization::readPod(is, version);
if (version != PAGE_FILE_VERSION) {
Serial.printf("Page: Unknown version %u\n", version);
Serial.printf("[%lu] [PGE] Deserialization failed: Unknown version %u\n", millis(), version);
return nullptr;
}

View File

@ -12,14 +12,14 @@
constexpr uint8_t SECTION_FILE_VERSION = 3;
void Section::onPageComplete(const Page* page) {
Serial.printf("Page %d complete - free mem: %lu\n", pageCount, ESP.getFreeHeap());
const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin";
std::ofstream outputFile("/sd" + filePath);
page->serialize(outputFile);
outputFile.close();
Serial.printf("[%lu] [SCT] Page %d processed\n", millis(), pageCount);
pageCount++;
delete page;
}
@ -58,7 +58,7 @@ bool Section::loadCacheMetadata(const int fontId, const float lineCompression, c
if (version != SECTION_FILE_VERSION) {
inputFile.close();
clearCache();
Serial.printf("Section state file: Unknown version %u\n", version);
Serial.printf("[%lu] [SCT] Deserialization failed: Unknown version %u\n", millis(), version);
return false;
}
@ -75,14 +75,14 @@ bool Section::loadCacheMetadata(const int fontId, const float lineCompression, c
marginRight != fileMarginRight || marginBottom != fileMarginBottom || marginLeft != fileMarginLeft) {
inputFile.close();
clearCache();
Serial.println("Section state file: Parameters do not match, ignoring");
Serial.printf("[%lu] [SCT] Deserialization failed: Parameters do not match\n", millis());
return false;
}
}
serialization::readPod(inputFile, pageCount);
inputFile.close();
Serial.printf("Loaded cache: %d pages\n", pageCount);
Serial.printf("[%lu] [SCT] Deserialization succeeded: %d pages\n", millis(), pageCount);
return true;
}
@ -106,11 +106,11 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
f.close();
if (!success) {
Serial.println("Failed to stream item contents");
Serial.printf("[%lu] [SCT] Failed to stream item contents to temp file\n", millis());
return false;
}
Serial.printf("Streamed HTML to %s\n", tmpHtmlPath.c_str());
Serial.printf("[%lu] [SCT] Streamed temp HTML to %s\n", millis(), tmpHtmlPath.c_str());
const auto sdTmpHtmlPath = "/sd" + tmpHtmlPath;
@ -120,7 +120,7 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
SD.remove(tmpHtmlPath.c_str());
if (!success) {
Serial.println("Failed to parse and build pages");
Serial.printf("[%lu] [SCT] Failed to parse XML and build pages\n", millis());
return false;
}
@ -132,7 +132,7 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
Page* Section::loadPageFromSD() const {
const auto filePath = "/sd" + cachePath + "/page_" + std::to_string(currentPage) + ".bin";
if (!SD.exists(filePath.c_str() + 3)) {
Serial.printf("Page file does not exist: %s\n", filePath.c_str());
Serial.printf("[%lu] [SCT] Page file does not exist: %s\n", millis(), filePath.c_str());
return nullptr;
}

View File

@ -9,7 +9,7 @@ void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
// Early return if no framebuffer is set
if (!frameBuffer) {
Serial.printf("!!No framebuffer\n");
Serial.printf("[%lu] [GFX] !! No framebuffer\n", millis());
return;
}
@ -21,7 +21,7 @@ void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
// Bounds checking (portrait: 480x800)
if (rotatedX < 0 || rotatedX >= EInkDisplay::DISPLAY_WIDTH || rotatedY < 0 ||
rotatedY >= EInkDisplay::DISPLAY_HEIGHT) {
Serial.printf("!! Outside range (%d, %d)\n", x, y);
Serial.printf("[%lu] [GFX] !! Outside range (%d, %d)\n", millis(), x, y);
return;
}
@ -38,7 +38,7 @@ void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontStyle style) const {
if (fontMap.count(fontId) == 0) {
Serial.printf("Font %d not found\n", fontId);
Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId);
return 0;
}
@ -58,7 +58,7 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha
}
if (fontMap.count(fontId) == 0) {
Serial.printf("Font %d not found\n", fontId);
Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId);
return;
}
const auto font = fontMap.at(fontId);
@ -91,7 +91,7 @@ void GfxRenderer::drawLine(int x1, int y1, int x2, int y2, const bool state) con
}
} else {
// TODO: Implement
Serial.println("Line drawing not supported");
Serial.printf("[%lu] [GFX] Line drawing not supported\n", millis());
}
}
@ -139,7 +139,7 @@ int GfxRenderer::getScreenHeight() { return EInkDisplay::DISPLAY_WIDTH; }
int GfxRenderer::getSpaceWidth(const int fontId) const {
if (fontMap.count(fontId) == 0) {
Serial.printf("Font %d not found\n", fontId);
Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId);
return 0;
}
@ -148,7 +148,7 @@ int GfxRenderer::getSpaceWidth(const int fontId) const {
int GfxRenderer::getLineHeight(const int fontId) const {
if (fontMap.count(fontId) == 0) {
Serial.printf("Font %d not found\n", fontId);
Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId);
return 0;
}
@ -173,7 +173,7 @@ void GfxRenderer::renderChar(const EpdFontFamily& fontFamily, const uint32_t cp,
// no glyph?
if (!glyph) {
Serial.printf("No glyph for codepoint %d\n", cp);
Serial.printf("[%lu] [GFX] No glyph for codepoint %d\n", millis(), cp);
return;
}

View File

@ -7,7 +7,7 @@ bool inflateOneShot(const uint8_t* inputBuf, const size_t deflatedSize, uint8_t*
// Setup inflator
const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor)));
if (!inflator) {
Serial.println("Failed to allocate memory for inflator");
Serial.printf("[%lu] [ZIP] Failed to allocate memory for inflator\n", millis());
return false;
}
memset(inflator, 0, sizeof(tinfl_decompressor));
@ -20,7 +20,7 @@ bool inflateOneShot(const uint8_t* inputBuf, const size_t deflatedSize, uint8_t*
free(inflator);
if (status != TINFL_STATUS_DONE) {
Serial.printf("tinfl_decompress() failed with status %d\n", status);
Serial.printf("[%lu] [ZIP] tinfl_decompress() failed with status %d\n", millis(), status);
return false;
}
@ -32,20 +32,22 @@ bool ZipFile::loadFileStat(const char* filename, mz_zip_archive_file_stat* fileS
const bool status = mz_zip_reader_init_file(&zipArchive, filePath.c_str(), 0);
if (!status) {
Serial.printf("mz_zip_reader_init_file() failed!\nError %s\n", mz_zip_get_error_string(zipArchive.m_last_error));
Serial.printf("[%lu] [ZIP] mz_zip_reader_init_file() failed! Error: %s\n", millis(),
mz_zip_get_error_string(zipArchive.m_last_error));
return false;
}
// find the file
mz_uint32 fileIndex = 0;
if (!mz_zip_reader_locate_file_v2(&zipArchive, filename, nullptr, 0, &fileIndex)) {
Serial.printf("Could not find file %s\n", filename);
Serial.printf("[%lu] [ZIP] Could not find file %s\n", millis, filename);
mz_zip_reader_end(&zipArchive);
return false;
}
if (!mz_zip_reader_file_stat(&zipArchive, fileIndex, fileStat)) {
Serial.printf("mz_zip_reader_file_stat() failed!\nError %s\n", mz_zip_get_error_string(zipArchive.m_last_error));
Serial.printf("[%lu] [ZIP] mz_zip_reader_file_stat() failed! Error: %s\n", millis(),
mz_zip_get_error_string(zipArchive.m_last_error));
mz_zip_reader_end(&zipArchive);
return false;
}
@ -65,13 +67,13 @@ long ZipFile::getDataOffset(const mz_zip_archive_file_stat& fileStat) const {
fclose(file);
if (read != localHeaderSize) {
Serial.println("Something went wrong reading the local header");
Serial.printf("[%lu] [ZIP] Something went wrong reading the local header\n", millis());
return -1;
}
if (pLocalHeader[0] + (pLocalHeader[1] << 8) + (pLocalHeader[2] << 16) + (pLocalHeader[3] << 24) !=
0x04034b50 /* MZ_ZIP_LOCAL_DIR_HEADER_SIG */) {
Serial.println("Not a valid zip file header");
Serial.printf("[%lu] [ZIP] Not a valid zip file header\n", millis());
return -1;
}
@ -105,7 +107,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
fclose(file);
if (dataRead != inflatedDataSize) {
Serial.println("Failed to read data");
Serial.printf("[%lu] [ZIP] Failed to read data\n", millis());
free(data);
return nullptr;
}
@ -115,7 +117,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
// Read out deflated content from file
const auto deflatedData = static_cast<uint8_t*>(malloc(deflatedDataSize));
if (deflatedData == nullptr) {
Serial.println("Failed to allocate memory for decompression buffer");
Serial.printf("[%lu] [ZIP] Failed to allocate memory for decompression buffer\n", millis());
fclose(file);
return nullptr;
}
@ -124,7 +126,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
fclose(file);
if (dataRead != deflatedDataSize) {
Serial.printf("Failed to read data, expected %d got %d\n", deflatedDataSize, dataRead);
Serial.printf("[%lu] [ZIP] Failed to read data, expected %d got %d\n", millis(), deflatedDataSize, dataRead);
free(deflatedData);
free(data);
return nullptr;
@ -134,14 +136,14 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
free(deflatedData);
if (!success) {
Serial.println("Failed to inflate file");
Serial.printf("[%lu] [ZIP] Failed to inflate file\n", millis());
free(data);
return nullptr;
}
// Continue out of block with data set
} else {
Serial.println("Unsupported compression method");
Serial.printf("[%lu] [ZIP] Unsupported compression method\n", millis());
fclose(file);
return nullptr;
}
@ -172,7 +174,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
// no deflation, just read content
const auto buffer = static_cast<uint8_t*>(malloc(chunkSize));
if (!buffer) {
Serial.println("Failed to allocate memory for buffer");
Serial.printf("[%lu] [ZIP] Failed to allocate memory for buffer\n", millis());
fclose(file);
return false;
}
@ -181,7 +183,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
while (remaining > 0) {
const size_t dataRead = fread(buffer, 1, remaining < chunkSize ? remaining : chunkSize, file);
if (dataRead == 0) {
Serial.println("Could not read more bytes");
Serial.printf("[%lu] [ZIP] Could not read more bytes\n", millis());
free(buffer);
fclose(file);
return false;
@ -200,7 +202,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
// Setup inflator
const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor)));
if (!inflator) {
Serial.println("Failed to allocate memory for inflator");
Serial.printf("[%lu] [ZIP] Failed to allocate memory for inflator\n", millis());
fclose(file);
return false;
}
@ -210,7 +212,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
// Setup file read buffer
const auto fileReadBuffer = static_cast<uint8_t*>(malloc(chunkSize));
if (!fileReadBuffer) {
Serial.println("Failed to allocate memory for zip file read buffer");
Serial.printf("[%lu] [ZIP] Failed to allocate memory for zip file read buffer\n", millis());
free(inflator);
fclose(file);
return false;
@ -218,7 +220,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
const auto outputBuffer = static_cast<uint8_t*>(malloc(TINFL_LZ_DICT_SIZE));
if (!outputBuffer) {
Serial.println("Failed to allocate memory for dictionary");
Serial.printf("[%lu] [ZIP] Failed to allocate memory for dictionary\n", millis());
free(inflator);
free(fileReadBuffer);
fclose(file);
@ -271,11 +273,8 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
outputCursor = (outputCursor + outBytes) & (TINFL_LZ_DICT_SIZE - 1);
}
Serial.printf("Decompressing - %d/%d deflated into %d/%d inflated\n", deflatedDataSize - fileRemainingBytes,
deflatedDataSize, processedOutputBytes, inflatedDataSize);
if (status < 0) {
Serial.printf("tinfl_decompress() failed with status %d\n", status);
Serial.printf("[%lu] [ZIP] tinfl_decompress() failed with status %d\n", millis(), status);
fclose(file);
free(outputBuffer);
free(fileReadBuffer);
@ -284,7 +283,8 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
}
if (status == TINFL_STATUS_DONE) {
Serial.println("Decompression finished");
Serial.printf("[%lu] [ZIP] Decompressed %d bytes into %d bytes\n", millis(), deflatedDataSize,
inflatedDataSize);
fclose(file);
free(inflator);
free(fileReadBuffer);
@ -294,7 +294,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
}
// If we get here, EOF reached without TINFL_STATUS_DONE
Serial.println("Unexpected EOF");
Serial.printf("[%lu] [ZIP] Unexpected EOF\n", millis());
fclose(file);
free(outputBuffer);
free(fileReadBuffer);
@ -302,6 +302,6 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
return false;
}
Serial.println("Unsupported compression method");
Serial.printf("[%lu] [ZIP] Unsupported compression method\n", millis());
return false;
}

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);