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

View File

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

View File

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

View File

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

View File

@ -12,14 +12,14 @@
constexpr uint8_t SECTION_FILE_VERSION = 3; constexpr uint8_t SECTION_FILE_VERSION = 3;
void Section::onPageComplete(const Page* page) { 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"; const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin";
std::ofstream outputFile("/sd" + filePath); std::ofstream outputFile("/sd" + filePath);
page->serialize(outputFile); page->serialize(outputFile);
outputFile.close(); outputFile.close();
Serial.printf("[%lu] [SCT] Page %d processed\n", millis(), pageCount);
pageCount++; pageCount++;
delete page; delete page;
} }
@ -58,7 +58,7 @@ bool Section::loadCacheMetadata(const int fontId, const float lineCompression, c
if (version != SECTION_FILE_VERSION) { if (version != SECTION_FILE_VERSION) {
inputFile.close(); inputFile.close();
clearCache(); 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; return false;
} }
@ -75,14 +75,14 @@ bool Section::loadCacheMetadata(const int fontId, const float lineCompression, c
marginRight != fileMarginRight || marginBottom != fileMarginBottom || marginLeft != fileMarginLeft) { marginRight != fileMarginRight || marginBottom != fileMarginBottom || marginLeft != fileMarginLeft) {
inputFile.close(); inputFile.close();
clearCache(); 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; return false;
} }
} }
serialization::readPod(inputFile, pageCount); serialization::readPod(inputFile, pageCount);
inputFile.close(); inputFile.close();
Serial.printf("Loaded cache: %d pages\n", pageCount); Serial.printf("[%lu] [SCT] Deserialization succeeded: %d pages\n", millis(), pageCount);
return true; return true;
} }
@ -106,11 +106,11 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
f.close(); f.close();
if (!success) { 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; 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; const auto sdTmpHtmlPath = "/sd" + tmpHtmlPath;
@ -120,7 +120,7 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
SD.remove(tmpHtmlPath.c_str()); SD.remove(tmpHtmlPath.c_str());
if (!success) { 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; return false;
} }
@ -132,7 +132,7 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
Page* Section::loadPageFromSD() const { Page* Section::loadPageFromSD() const {
const auto filePath = "/sd" + cachePath + "/page_" + std::to_string(currentPage) + ".bin"; const auto filePath = "/sd" + cachePath + "/page_" + std::to_string(currentPage) + ".bin";
if (!SD.exists(filePath.c_str() + 3)) { 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; 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 // Early return if no framebuffer is set
if (!frameBuffer) { if (!frameBuffer) {
Serial.printf("!!No framebuffer\n"); Serial.printf("[%lu] [GFX] !! No framebuffer\n", millis());
return; return;
} }
@ -21,7 +21,7 @@ void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
// Bounds checking (portrait: 480x800) // Bounds checking (portrait: 480x800)
if (rotatedX < 0 || rotatedX >= EInkDisplay::DISPLAY_WIDTH || rotatedY < 0 || if (rotatedX < 0 || rotatedX >= EInkDisplay::DISPLAY_WIDTH || rotatedY < 0 ||
rotatedY >= EInkDisplay::DISPLAY_HEIGHT) { 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; 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 { int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontStyle style) const {
if (fontMap.count(fontId) == 0) { 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; 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) { 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; return;
} }
const auto font = fontMap.at(fontId); 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 { } else {
// TODO: Implement // 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 { int GfxRenderer::getSpaceWidth(const int fontId) const {
if (fontMap.count(fontId) == 0) { 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; return 0;
} }
@ -148,7 +148,7 @@ int GfxRenderer::getSpaceWidth(const int fontId) const {
int GfxRenderer::getLineHeight(const int fontId) const { int GfxRenderer::getLineHeight(const int fontId) const {
if (fontMap.count(fontId) == 0) { 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; return 0;
} }
@ -173,7 +173,7 @@ void GfxRenderer::renderChar(const EpdFontFamily& fontFamily, const uint32_t cp,
// no glyph? // no glyph?
if (!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; return;
} }

View File

@ -7,7 +7,7 @@ bool inflateOneShot(const uint8_t* inputBuf, const size_t deflatedSize, uint8_t*
// Setup inflator // Setup inflator
const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor))); const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor)));
if (!inflator) { if (!inflator) {
Serial.println("Failed to allocate memory for inflator"); Serial.printf("[%lu] [ZIP] Failed to allocate memory for inflator\n", millis());
return false; return false;
} }
memset(inflator, 0, sizeof(tinfl_decompressor)); memset(inflator, 0, sizeof(tinfl_decompressor));
@ -20,7 +20,7 @@ bool inflateOneShot(const uint8_t* inputBuf, const size_t deflatedSize, uint8_t*
free(inflator); free(inflator);
if (status != TINFL_STATUS_DONE) { 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; 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); const bool status = mz_zip_reader_init_file(&zipArchive, filePath.c_str(), 0);
if (!status) { 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; return false;
} }
// find the file // find the file
mz_uint32 fileIndex = 0; mz_uint32 fileIndex = 0;
if (!mz_zip_reader_locate_file_v2(&zipArchive, filename, nullptr, 0, &fileIndex)) { 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); mz_zip_reader_end(&zipArchive);
return false; return false;
} }
if (!mz_zip_reader_file_stat(&zipArchive, fileIndex, fileStat)) { 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); mz_zip_reader_end(&zipArchive);
return false; return false;
} }
@ -65,13 +67,13 @@ long ZipFile::getDataOffset(const mz_zip_archive_file_stat& fileStat) const {
fclose(file); fclose(file);
if (read != localHeaderSize) { 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; return -1;
} }
if (pLocalHeader[0] + (pLocalHeader[1] << 8) + (pLocalHeader[2] << 16) + (pLocalHeader[3] << 24) != if (pLocalHeader[0] + (pLocalHeader[1] << 8) + (pLocalHeader[2] << 16) + (pLocalHeader[3] << 24) !=
0x04034b50 /* MZ_ZIP_LOCAL_DIR_HEADER_SIG */) { 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; return -1;
} }
@ -105,7 +107,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
fclose(file); fclose(file);
if (dataRead != inflatedDataSize) { if (dataRead != inflatedDataSize) {
Serial.println("Failed to read data"); Serial.printf("[%lu] [ZIP] Failed to read data\n", millis());
free(data); free(data);
return nullptr; return nullptr;
} }
@ -115,7 +117,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
// Read out deflated content from file // Read out deflated content from file
const auto deflatedData = static_cast<uint8_t*>(malloc(deflatedDataSize)); const auto deflatedData = static_cast<uint8_t*>(malloc(deflatedDataSize));
if (deflatedData == nullptr) { 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); fclose(file);
return nullptr; return nullptr;
} }
@ -124,7 +126,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
fclose(file); fclose(file);
if (dataRead != deflatedDataSize) { 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(deflatedData);
free(data); free(data);
return nullptr; return nullptr;
@ -134,14 +136,14 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
free(deflatedData); free(deflatedData);
if (!success) { if (!success) {
Serial.println("Failed to inflate file"); Serial.printf("[%lu] [ZIP] Failed to inflate file\n", millis());
free(data); free(data);
return nullptr; return nullptr;
} }
// Continue out of block with data set // Continue out of block with data set
} else { } else {
Serial.println("Unsupported compression method"); Serial.printf("[%lu] [ZIP] Unsupported compression method\n", millis());
fclose(file); fclose(file);
return nullptr; return nullptr;
} }
@ -172,7 +174,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
// no deflation, just read content // no deflation, just read content
const auto buffer = static_cast<uint8_t*>(malloc(chunkSize)); const auto buffer = static_cast<uint8_t*>(malloc(chunkSize));
if (!buffer) { if (!buffer) {
Serial.println("Failed to allocate memory for buffer"); Serial.printf("[%lu] [ZIP] Failed to allocate memory for buffer\n", millis());
fclose(file); fclose(file);
return false; return false;
} }
@ -181,7 +183,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
while (remaining > 0) { while (remaining > 0) {
const size_t dataRead = fread(buffer, 1, remaining < chunkSize ? remaining : chunkSize, file); const size_t dataRead = fread(buffer, 1, remaining < chunkSize ? remaining : chunkSize, file);
if (dataRead == 0) { if (dataRead == 0) {
Serial.println("Could not read more bytes"); Serial.printf("[%lu] [ZIP] Could not read more bytes\n", millis());
free(buffer); free(buffer);
fclose(file); fclose(file);
return false; return false;
@ -200,7 +202,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
// Setup inflator // Setup inflator
const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor))); const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor)));
if (!inflator) { if (!inflator) {
Serial.println("Failed to allocate memory for inflator"); Serial.printf("[%lu] [ZIP] Failed to allocate memory for inflator\n", millis());
fclose(file); fclose(file);
return false; return false;
} }
@ -210,7 +212,7 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
// Setup file read buffer // Setup file read buffer
const auto fileReadBuffer = static_cast<uint8_t*>(malloc(chunkSize)); const auto fileReadBuffer = static_cast<uint8_t*>(malloc(chunkSize));
if (!fileReadBuffer) { 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); free(inflator);
fclose(file); fclose(file);
return false; 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)); const auto outputBuffer = static_cast<uint8_t*>(malloc(TINFL_LZ_DICT_SIZE));
if (!outputBuffer) { 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(inflator);
free(fileReadBuffer); free(fileReadBuffer);
fclose(file); 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); 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) { 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); fclose(file);
free(outputBuffer); free(outputBuffer);
free(fileReadBuffer); free(fileReadBuffer);
@ -284,7 +283,8 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
} }
if (status == TINFL_STATUS_DONE) { 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); fclose(file);
free(inflator); free(inflator);
free(fileReadBuffer); 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 // If we get here, EOF reached without TINFL_STATUS_DONE
Serial.println("Unexpected EOF"); Serial.printf("[%lu] [ZIP] Unexpected EOF\n", millis());
fclose(file); fclose(file);
free(outputBuffer); free(outputBuffer);
free(fileReadBuffer); free(fileReadBuffer);
@ -302,6 +302,6 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
return false; return false;
} }
Serial.println("Unsupported compression method"); Serial.printf("[%lu] [ZIP] Unsupported compression method\n", millis());
return false; return false;
} }

View File

@ -23,7 +23,7 @@ bool CrossPointState::loadFromFile() {
uint8_t version; uint8_t version;
serialization::readPod(inputFile, version); serialization::readPod(inputFile, version);
if (version != STATE_FILE_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(); inputFile.close();
return false; return false;
} }

View File

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

View File

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