A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Cleanup serial output

+92 -95
+24 -23
lib/Epub/Epub.cpp
··· 11 11 size_t s; 12 12 const auto metaInfo = reinterpret_cast<char*>(zip.readFileToMemory("META-INF/container.xml", &s, true)); 13 13 if (!metaInfo) { 14 - Serial.println("Could not find META-INF/container.xml"); 14 + Serial.printf("[%lu] [EBP] Could not find META-INF/container.xml\n", millis()); 15 15 return false; 16 16 } 17 17 ··· 21 21 free(metaInfo); 22 22 23 23 if (result != tinyxml2::XML_SUCCESS) { 24 - Serial.printf("Could not parse META-INF/container.xml. Error: %d\n", result); 24 + Serial.printf("[%lu] [EBP] Could not parse META-INF/container.xml. Error: %d\n", millis(), result); 25 25 return false; 26 26 } 27 27 28 28 const auto container = metaDataDoc.FirstChildElement("container"); 29 29 if (!container) { 30 - Serial.println("Could not find container element in META-INF/container.xml"); 30 + Serial.printf("[%lu] [EBP] Could not find container element in META-INF/container.xml\n", millis()); 31 31 return false; 32 32 } 33 33 34 34 const auto rootfiles = container->FirstChildElement("rootfiles"); 35 35 if (!rootfiles) { 36 - Serial.println("Could not find rootfiles element in META-INF/container.xml"); 36 + Serial.printf("[%lu] [EBP] Could not find rootfiles element in META-INF/container.xml\n", millis()); 37 37 return false; 38 38 } 39 39 ··· 51 51 rootfile = rootfile->NextSiblingElement("rootfile"); 52 52 } 53 53 54 - Serial.println("Could not get path to content.opf file"); 54 + Serial.printf("[%lu] [EBP] Could not get path to content.opf file\n", millis()); 55 55 return false; 56 56 } 57 57 ··· 65 65 free(contents); 66 66 67 67 if (result != tinyxml2::XML_SUCCESS) { 68 - Serial.printf("Error parsing content.opf - %s\n", tinyxml2::XMLDocument::ErrorIDToName(result)); 68 + Serial.printf("[%lu] [EBP] Error parsing content.opf - %s\n", millis(), 69 + tinyxml2::XMLDocument::ErrorIDToName(result)); 69 70 return false; 70 71 } 71 72 ··· 73 74 if (!package) package = doc.FirstChildElement("opf:package"); 74 75 75 76 if (!package) { 76 - Serial.println("Could not find package element in content.opf"); 77 + Serial.printf("[%lu] [EBP] Could not find package element in content.opf\n", millis()); 77 78 return false; 78 79 } 79 80 ··· 81 82 auto metadata = package->FirstChildElement("metadata"); 82 83 if (!metadata) metadata = package->FirstChildElement("opf:metadata"); 83 84 if (!metadata) { 84 - Serial.println("Missing metadata"); 85 + Serial.printf("[%lu] [EBP] Missing metadata\n", millis()); 85 86 return false; 86 87 } 87 88 88 89 auto titleEl = metadata->FirstChildElement("dc:title"); 89 90 if (!titleEl) { 90 - Serial.println("Missing title"); 91 + Serial.printf("[%lu] [EBP] Missing title\n", millis()); 91 92 return false; 92 93 } 93 94 this->title = titleEl->GetText(); ··· 98 99 cover = cover->NextSiblingElement("meta"); 99 100 } 100 101 if (!cover) { 101 - Serial.println("Missing cover"); 102 + Serial.printf("[%lu] [EBP] Missing cover\n", millis()); 102 103 } 103 104 auto coverItem = cover ? cover->Attribute("content") : nullptr; 104 105 ··· 109 110 auto manifest = package->FirstChildElement("manifest"); 110 111 if (!manifest) manifest = package->FirstChildElement("opf:manifest"); 111 112 if (!manifest) { 112 - Serial.println("Missing manifest"); 113 + Serial.printf("[%lu] [EBP] Missing manifest\n", millis()); 113 114 return false; 114 115 } 115 116 ··· 142 143 auto spineEl = package->FirstChildElement("spine"); 143 144 if (!spineEl) spineEl = package->FirstChildElement("opf:spine"); 144 145 if (!spineEl) { 145 - Serial.println("Missing spine"); 146 + Serial.printf("[%lu] [EBP] Missing spine\n", millis()); 146 147 return false; 147 148 } 148 149 ··· 164 165 bool Epub::parseTocNcxFile(const ZipFile& zip) { 165 166 // the ncx file should have been specified in the content.opf file 166 167 if (tocNcxItem.empty()) { 167 - Serial.println("No ncx file specified"); 168 + Serial.printf("[%lu] [EBP] No ncx file specified\n", millis()); 168 169 return false; 169 170 } 170 171 171 172 const auto ncxData = reinterpret_cast<char*>(zip.readFileToMemory(tocNcxItem.c_str(), nullptr, true)); 172 173 if (!ncxData) { 173 - Serial.printf("Could not find %s\n", tocNcxItem.c_str()); 174 + Serial.printf("[%lu] [EBP] Could not find %s\n", millis(), tocNcxItem.c_str()); 174 175 return false; 175 176 } 176 177 ··· 180 181 free(ncxData); 181 182 182 183 if (result != tinyxml2::XML_SUCCESS) { 183 - Serial.printf("Error parsing toc %s\n", tinyxml2::XMLDocument::ErrorIDToName(result)); 184 + Serial.printf("[%lu] [EBP] Error parsing toc %s\n", millis(), tinyxml2::XMLDocument::ErrorIDToName(result)); 184 185 return false; 185 186 } 186 187 187 188 const auto ncx = doc.FirstChildElement("ncx"); 188 189 if (!ncx) { 189 - Serial.println("Could not find first child ncx in toc"); 190 + Serial.printf("[%lu] [EBP] Could not find first child ncx in toc\n", millis()); 190 191 return false; 191 192 } 192 193 193 194 const auto navMap = ncx->FirstChildElement("navMap"); 194 195 if (!navMap) { 195 - Serial.println("Could not find navMap child in ncx"); 196 + Serial.printf("[%lu] [EBP] Could not find navMap child in ncx\n", millis()); 196 197 return false; 197 198 } 198 199 ··· 231 232 232 233 std::string contentOpfFile; 233 234 if (!findContentOpfFile(zip, contentOpfFile)) { 234 - Serial.println("Could not open ePub"); 235 + Serial.printf("[%lu] [EBP] Could not open ePub\n", millis()); 235 236 return false; 236 237 } 237 238 ··· 314 315 315 316 const auto content = zip.readFileToMemory(path.c_str(), size, trailingNullByte); 316 317 if (!content) { 317 - Serial.printf("Failed to read item %s\n", path.c_str()); 318 + Serial.printf("[%lu] [EBP] Failed to read item %s\n", millis(), path.c_str()); 318 319 return nullptr; 319 320 } 320 321 ··· 332 333 333 334 std::string& Epub::getSpineItem(const int spineIndex) { 334 335 if (spineIndex < 0 || spineIndex >= spine.size()) { 335 - Serial.printf("getSpineItem index:%d is out of range\n", spineIndex); 336 + Serial.printf("[%lu] [EBP] getSpineItem index:%d is out of range\n", millis(), spineIndex); 336 337 return spine.at(0).second; 337 338 } 338 339 ··· 341 342 342 343 EpubTocEntry& Epub::getTocItem(const int tocTndex) { 343 344 if (tocTndex < 0 || tocTndex >= toc.size()) { 344 - Serial.printf("getTocItem index:%d is out of range\n", tocTndex); 345 + Serial.printf("[%lu] [EBP] getTocItem index:%d is out of range\n", millis(), tocTndex); 345 346 return toc.at(0); 346 347 } 347 348 ··· 360 361 } 361 362 } 362 363 363 - Serial.println("Section not found"); 364 + Serial.printf("[%lu] [EBP] Section not found\n", millis()); 364 365 // not found - default to the start of the book 365 366 return 0; 366 367 } ··· 374 375 } 375 376 } 376 377 377 - Serial.println("TOC item not found"); 378 + Serial.printf("[%lu] [EBP] TOC item not found\n", millis()); 378 379 // not found - default to first item 379 380 return 0; 380 381 }
+1 -1
lib/Epub/Epub.h
··· 1 1 #pragma once 2 - #include <HardwareSerial.h> 2 + #include <Print.h> 3 3 #include <tinyxml2.h> 4 4 5 5 #include <string>
+6 -6
lib/Epub/Epub/EpubHtmlParserSlim.cpp
··· 190 190 int done; 191 191 192 192 if (!parser) { 193 - Serial.println("Couldn't allocate memory for parser"); 193 + Serial.printf("[%lu] [EHP] Couldn't allocate memory for parser\n", millis()); 194 194 return false; 195 195 } 196 196 ··· 200 200 201 201 FILE* file = fopen(filepath, "r"); 202 202 if (!file) { 203 - Serial.printf("Couldn't open file %s\n", filepath); 203 + Serial.printf("[%lu] [EHP] Couldn't open file %s\n", millis(), filepath); 204 204 XML_ParserFree(parser); 205 205 return false; 206 206 } ··· 208 208 do { 209 209 void* const buf = XML_GetBuffer(parser, 1024); 210 210 if (!buf) { 211 - Serial.println("Couldn't allocate memory for buffer"); 211 + Serial.printf("[%lu] [EHP] Couldn't allocate memory for buffer\n", millis()); 212 212 XML_ParserFree(parser); 213 213 fclose(file); 214 214 return false; ··· 217 217 const size_t len = fread(buf, 1, 1024, file); 218 218 219 219 if (ferror(file)) { 220 - Serial.println("Read error"); 220 + Serial.printf("[%lu] [EHP] File read error\n", millis()); 221 221 XML_ParserFree(parser); 222 222 fclose(file); 223 223 return false; ··· 226 226 done = feof(file); 227 227 228 228 if (XML_ParseBuffer(parser, static_cast<int>(len), done) == XML_STATUS_ERROR) { 229 - Serial.printf("Parse error at line %lu:\n%s\n", XML_GetCurrentLineNumber(parser), 229 + Serial.printf("[%lu] [EHP] Parse error at line %lu:\n%s\n", millis(), XML_GetCurrentLineNumber(parser), 230 230 XML_ErrorString(XML_GetErrorCode(parser))); 231 231 XML_ParserFree(parser); 232 232 fclose(file); ··· 251 251 252 252 void EpubHtmlParserSlim::makePages() { 253 253 if (!currentTextBlock) { 254 - Serial.println("!! No text block to make pages for !!"); 254 + Serial.printf("[%lu] [EHP] !! No text block to make pages for !!\n", millis()); 255 255 return; 256 256 } 257 257
+1 -3
lib/Epub/Epub/Page.cpp
··· 26 26 } 27 27 28 28 void Page::render(GfxRenderer& renderer, const int fontId) const { 29 - const auto start = millis(); 30 29 for (const auto element : elements) { 31 30 element->render(renderer, fontId); 32 31 } 33 - Serial.printf("Rendered page elements (%u) in %dms\n", elements.size(), millis() - start); 34 32 } 35 33 36 34 void Page::serialize(std::ostream& os) const { ··· 50 48 uint8_t version; 51 49 serialization::readPod(is, version); 52 50 if (version != PAGE_FILE_VERSION) { 53 - Serial.printf("Page: Unknown version %u\n", version); 51 + Serial.printf("[%lu] [PGE] Deserialization failed: Unknown version %u\n", millis(), version); 54 52 return nullptr; 55 53 } 56 54
+9 -9
lib/Epub/Epub/Section.cpp
··· 12 12 constexpr uint8_t SECTION_FILE_VERSION = 3; 13 13 14 14 void Section::onPageComplete(const Page* page) { 15 - Serial.printf("Page %d complete - free mem: %lu\n", pageCount, ESP.getFreeHeap()); 16 - 17 15 const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin"; 18 16 19 17 std::ofstream outputFile("/sd" + filePath); 20 18 page->serialize(outputFile); 21 19 outputFile.close(); 20 + 21 + Serial.printf("[%lu] [SCT] Page %d processed\n", millis(), pageCount); 22 22 23 23 pageCount++; 24 24 delete page; ··· 58 58 if (version != SECTION_FILE_VERSION) { 59 59 inputFile.close(); 60 60 clearCache(); 61 - Serial.printf("Section state file: Unknown version %u\n", version); 61 + Serial.printf("[%lu] [SCT] Deserialization failed: Unknown version %u\n", millis(), version); 62 62 return false; 63 63 } 64 64 ··· 75 75 marginRight != fileMarginRight || marginBottom != fileMarginBottom || marginLeft != fileMarginLeft) { 76 76 inputFile.close(); 77 77 clearCache(); 78 - Serial.println("Section state file: Parameters do not match, ignoring"); 78 + Serial.printf("[%lu] [SCT] Deserialization failed: Parameters do not match\n", millis()); 79 79 return false; 80 80 } 81 81 } 82 82 83 83 serialization::readPod(inputFile, pageCount); 84 84 inputFile.close(); 85 - Serial.printf("Loaded cache: %d pages\n", pageCount); 85 + Serial.printf("[%lu] [SCT] Deserialization succeeded: %d pages\n", millis(), pageCount); 86 86 return true; 87 87 } 88 88 ··· 106 106 f.close(); 107 107 108 108 if (!success) { 109 - Serial.println("Failed to stream item contents"); 109 + Serial.printf("[%lu] [SCT] Failed to stream item contents to temp file\n", millis()); 110 110 return false; 111 111 } 112 112 113 - Serial.printf("Streamed HTML to %s\n", tmpHtmlPath.c_str()); 113 + Serial.printf("[%lu] [SCT] Streamed temp HTML to %s\n", millis(), tmpHtmlPath.c_str()); 114 114 115 115 const auto sdTmpHtmlPath = "/sd" + tmpHtmlPath; 116 116 ··· 120 120 121 121 SD.remove(tmpHtmlPath.c_str()); 122 122 if (!success) { 123 - Serial.println("Failed to parse and build pages"); 123 + Serial.printf("[%lu] [SCT] Failed to parse XML and build pages\n", millis()); 124 124 return false; 125 125 } 126 126 ··· 132 132 Page* Section::loadPageFromSD() const { 133 133 const auto filePath = "/sd" + cachePath + "/page_" + std::to_string(currentPage) + ".bin"; 134 134 if (!SD.exists(filePath.c_str() + 3)) { 135 - Serial.printf("Page file does not exist: %s\n", filePath.c_str()); 135 + Serial.printf("[%lu] [SCT] Page file does not exist: %s\n", millis(), filePath.c_str()); 136 136 return nullptr; 137 137 } 138 138
+8 -8
lib/GfxRenderer/GfxRenderer.cpp
··· 9 9 10 10 // Early return if no framebuffer is set 11 11 if (!frameBuffer) { 12 - Serial.printf("!!No framebuffer\n"); 12 + Serial.printf("[%lu] [GFX] !! No framebuffer\n", millis()); 13 13 return; 14 14 } 15 15 ··· 21 21 // Bounds checking (portrait: 480x800) 22 22 if (rotatedX < 0 || rotatedX >= EInkDisplay::DISPLAY_WIDTH || rotatedY < 0 || 23 23 rotatedY >= EInkDisplay::DISPLAY_HEIGHT) { 24 - Serial.printf("!! Outside range (%d, %d)\n", x, y); 24 + Serial.printf("[%lu] [GFX] !! Outside range (%d, %d)\n", millis(), x, y); 25 25 return; 26 26 } 27 27 ··· 38 38 39 39 int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontStyle style) const { 40 40 if (fontMap.count(fontId) == 0) { 41 - Serial.printf("Font %d not found\n", fontId); 41 + Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); 42 42 return 0; 43 43 } 44 44 ··· 58 58 } 59 59 60 60 if (fontMap.count(fontId) == 0) { 61 - Serial.printf("Font %d not found\n", fontId); 61 + Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); 62 62 return; 63 63 } 64 64 const auto font = fontMap.at(fontId); ··· 91 91 } 92 92 } else { 93 93 // TODO: Implement 94 - Serial.println("Line drawing not supported"); 94 + Serial.printf("[%lu] [GFX] Line drawing not supported\n", millis()); 95 95 } 96 96 } 97 97 ··· 139 139 140 140 int GfxRenderer::getSpaceWidth(const int fontId) const { 141 141 if (fontMap.count(fontId) == 0) { 142 - Serial.printf("Font %d not found\n", fontId); 142 + Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); 143 143 return 0; 144 144 } 145 145 ··· 148 148 149 149 int GfxRenderer::getLineHeight(const int fontId) const { 150 150 if (fontMap.count(fontId) == 0) { 151 - Serial.printf("Font %d not found\n", fontId); 151 + Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); 152 152 return 0; 153 153 } 154 154 ··· 173 173 174 174 // no glyph? 175 175 if (!glyph) { 176 - Serial.printf("No glyph for codepoint %d\n", cp); 176 + Serial.printf("[%lu] [GFX] No glyph for codepoint %d\n", millis(), cp); 177 177 return; 178 178 } 179 179
+24 -24
lib/ZipFile/ZipFile.cpp
··· 7 7 // Setup inflator 8 8 const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor))); 9 9 if (!inflator) { 10 - Serial.println("Failed to allocate memory for inflator"); 10 + Serial.printf("[%lu] [ZIP] Failed to allocate memory for inflator\n", millis()); 11 11 return false; 12 12 } 13 13 memset(inflator, 0, sizeof(tinfl_decompressor)); ··· 20 20 free(inflator); 21 21 22 22 if (status != TINFL_STATUS_DONE) { 23 - Serial.printf("tinfl_decompress() failed with status %d\n", status); 23 + Serial.printf("[%lu] [ZIP] tinfl_decompress() failed with status %d\n", millis(), status); 24 24 return false; 25 25 } 26 26 ··· 32 32 const bool status = mz_zip_reader_init_file(&zipArchive, filePath.c_str(), 0); 33 33 34 34 if (!status) { 35 - Serial.printf("mz_zip_reader_init_file() failed!\nError %s\n", mz_zip_get_error_string(zipArchive.m_last_error)); 35 + Serial.printf("[%lu] [ZIP] mz_zip_reader_init_file() failed! Error: %s\n", millis(), 36 + mz_zip_get_error_string(zipArchive.m_last_error)); 36 37 return false; 37 38 } 38 39 39 40 // find the file 40 41 mz_uint32 fileIndex = 0; 41 42 if (!mz_zip_reader_locate_file_v2(&zipArchive, filename, nullptr, 0, &fileIndex)) { 42 - Serial.printf("Could not find file %s\n", filename); 43 + Serial.printf("[%lu] [ZIP] Could not find file %s\n", millis, filename); 43 44 mz_zip_reader_end(&zipArchive); 44 45 return false; 45 46 } 46 47 47 48 if (!mz_zip_reader_file_stat(&zipArchive, fileIndex, fileStat)) { 48 - Serial.printf("mz_zip_reader_file_stat() failed!\nError %s\n", mz_zip_get_error_string(zipArchive.m_last_error)); 49 + Serial.printf("[%lu] [ZIP] mz_zip_reader_file_stat() failed! Error: %s\n", millis(), 50 + mz_zip_get_error_string(zipArchive.m_last_error)); 49 51 mz_zip_reader_end(&zipArchive); 50 52 return false; 51 53 } ··· 65 67 fclose(file); 66 68 67 69 if (read != localHeaderSize) { 68 - Serial.println("Something went wrong reading the local header"); 70 + Serial.printf("[%lu] [ZIP] Something went wrong reading the local header\n", millis()); 69 71 return -1; 70 72 } 71 73 72 74 if (pLocalHeader[0] + (pLocalHeader[1] << 8) + (pLocalHeader[2] << 16) + (pLocalHeader[3] << 24) != 73 75 0x04034b50 /* MZ_ZIP_LOCAL_DIR_HEADER_SIG */) { 74 - Serial.println("Not a valid zip file header"); 76 + Serial.printf("[%lu] [ZIP] Not a valid zip file header\n", millis()); 75 77 return -1; 76 78 } 77 79 ··· 105 107 fclose(file); 106 108 107 109 if (dataRead != inflatedDataSize) { 108 - Serial.println("Failed to read data"); 110 + Serial.printf("[%lu] [ZIP] Failed to read data\n", millis()); 109 111 free(data); 110 112 return nullptr; 111 113 } ··· 115 117 // Read out deflated content from file 116 118 const auto deflatedData = static_cast<uint8_t*>(malloc(deflatedDataSize)); 117 119 if (deflatedData == nullptr) { 118 - Serial.println("Failed to allocate memory for decompression buffer"); 120 + Serial.printf("[%lu] [ZIP] Failed to allocate memory for decompression buffer\n", millis()); 119 121 fclose(file); 120 122 return nullptr; 121 123 } ··· 124 126 fclose(file); 125 127 126 128 if (dataRead != deflatedDataSize) { 127 - Serial.printf("Failed to read data, expected %d got %d\n", deflatedDataSize, dataRead); 129 + Serial.printf("[%lu] [ZIP] Failed to read data, expected %d got %d\n", millis(), deflatedDataSize, dataRead); 128 130 free(deflatedData); 129 131 free(data); 130 132 return nullptr; ··· 134 136 free(deflatedData); 135 137 136 138 if (!success) { 137 - Serial.println("Failed to inflate file"); 139 + Serial.printf("[%lu] [ZIP] Failed to inflate file\n", millis()); 138 140 free(data); 139 141 return nullptr; 140 142 } 141 143 142 144 // Continue out of block with data set 143 145 } else { 144 - Serial.println("Unsupported compression method"); 146 + Serial.printf("[%lu] [ZIP] Unsupported compression method\n", millis()); 145 147 fclose(file); 146 148 return nullptr; 147 149 } ··· 172 174 // no deflation, just read content 173 175 const auto buffer = static_cast<uint8_t*>(malloc(chunkSize)); 174 176 if (!buffer) { 175 - Serial.println("Failed to allocate memory for buffer"); 177 + Serial.printf("[%lu] [ZIP] Failed to allocate memory for buffer\n", millis()); 176 178 fclose(file); 177 179 return false; 178 180 } ··· 181 183 while (remaining > 0) { 182 184 const size_t dataRead = fread(buffer, 1, remaining < chunkSize ? remaining : chunkSize, file); 183 185 if (dataRead == 0) { 184 - Serial.println("Could not read more bytes"); 186 + Serial.printf("[%lu] [ZIP] Could not read more bytes\n", millis()); 185 187 free(buffer); 186 188 fclose(file); 187 189 return false; ··· 200 202 // Setup inflator 201 203 const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor))); 202 204 if (!inflator) { 203 - Serial.println("Failed to allocate memory for inflator"); 205 + Serial.printf("[%lu] [ZIP] Failed to allocate memory for inflator\n", millis()); 204 206 fclose(file); 205 207 return false; 206 208 } ··· 210 212 // Setup file read buffer 211 213 const auto fileReadBuffer = static_cast<uint8_t*>(malloc(chunkSize)); 212 214 if (!fileReadBuffer) { 213 - Serial.println("Failed to allocate memory for zip file read buffer"); 215 + Serial.printf("[%lu] [ZIP] Failed to allocate memory for zip file read buffer\n", millis()); 214 216 free(inflator); 215 217 fclose(file); 216 218 return false; ··· 218 220 219 221 const auto outputBuffer = static_cast<uint8_t*>(malloc(TINFL_LZ_DICT_SIZE)); 220 222 if (!outputBuffer) { 221 - Serial.println("Failed to allocate memory for dictionary"); 223 + Serial.printf("[%lu] [ZIP] Failed to allocate memory for dictionary\n", millis()); 222 224 free(inflator); 223 225 free(fileReadBuffer); 224 226 fclose(file); ··· 271 273 outputCursor = (outputCursor + outBytes) & (TINFL_LZ_DICT_SIZE - 1); 272 274 } 273 275 274 - Serial.printf("Decompressing - %d/%d deflated into %d/%d inflated\n", deflatedDataSize - fileRemainingBytes, 275 - deflatedDataSize, processedOutputBytes, inflatedDataSize); 276 - 277 276 if (status < 0) { 278 - Serial.printf("tinfl_decompress() failed with status %d\n", status); 277 + Serial.printf("[%lu] [ZIP] tinfl_decompress() failed with status %d\n", millis(), status); 279 278 fclose(file); 280 279 free(outputBuffer); 281 280 free(fileReadBuffer); ··· 284 283 } 285 284 286 285 if (status == TINFL_STATUS_DONE) { 287 - Serial.println("Decompression finished"); 286 + Serial.printf("[%lu] [ZIP] Decompressed %d bytes into %d bytes\n", millis(), deflatedDataSize, 287 + inflatedDataSize); 288 288 fclose(file); 289 289 free(inflator); 290 290 free(fileReadBuffer); ··· 294 294 } 295 295 296 296 // If we get here, EOF reached without TINFL_STATUS_DONE 297 - Serial.println("Unexpected EOF"); 297 + Serial.printf("[%lu] [ZIP] Unexpected EOF\n", millis()); 298 298 fclose(file); 299 299 free(outputBuffer); 300 300 free(fileReadBuffer); ··· 302 302 return false; 303 303 } 304 304 305 - Serial.println("Unsupported compression method"); 305 + Serial.printf("[%lu] [ZIP] Unsupported compression method\n", millis()); 306 306 return false; 307 307 }
+1 -1
src/CrossPointState.cpp
··· 23 23 uint8_t version; 24 24 serialization::readPod(inputFile, version); 25 25 if (version != STATE_FILE_VERSION) { 26 - Serial.printf("CrossPointState: Unknown version %u\n", version); 26 + Serial.printf("[%lu] [CPS] Deserialization failed: Unknown version %u\n", millis(), version); 27 27 inputFile.close(); 28 28 return false; 29 29 }
+8 -12
src/main.cpp
··· 64 64 65 65 Epub* loadEpub(const std::string& path) { 66 66 if (!SD.exists(path.c_str())) { 67 - Serial.printf("File does not exist: %s\n", path.c_str()); 67 + Serial.printf("[%lu] [ ] File does not exist: %s\n", millis(), path.c_str()); 68 68 return nullptr; 69 69 } 70 70 ··· 73 73 return epub; 74 74 } 75 75 76 - Serial.println("Failed to load epub"); 76 + Serial.printf("[%lu] [ ] Failed to load epub\n", millis()); 77 77 delete epub; 78 78 return nullptr; 79 79 } ··· 96 96 const auto start = millis(); 97 97 bool abort = false; 98 98 99 - Serial.println("Verifying power button press"); 99 + Serial.printf("[%lu] [ ] Verifying power button press\n", millis()); 100 100 inputManager.update(); 101 101 while (!inputManager.isPressed(InputManager::BTN_POWER) && millis() - start < 1000) { 102 102 delay(50); 103 103 inputManager.update(); 104 - Serial.println("Waiting..."); 105 104 } 106 105 107 - Serial.printf("Made it? %s\n", inputManager.isPressed(InputManager::BTN_POWER) ? "yes" : "no"); 108 106 if (inputManager.isPressed(InputManager::BTN_POWER)) { 109 107 do { 110 108 delay(50); ··· 114 112 } else { 115 113 abort = true; 116 114 } 117 - 118 - Serial.printf("held for %lu\n", inputManager.getHeldTime()); 119 115 120 116 if (abort) { 121 117 // Button released too early. Returning to sleep. ··· 138 134 exitScreen(); 139 135 enterNewScreen(new SleepScreen(renderer, inputManager)); 140 136 141 - Serial.println("Power button released after a long press. Entering deep sleep."); 137 + Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis()); 142 138 delay(1000); // Allow Serial buffer to empty and display to update 143 139 144 140 // Enable Wakeup on LOW (button press) ··· 193 189 194 190 // Initialize display 195 191 einkDisplay.begin(); 196 - Serial.println("Display initialized"); 192 + Serial.printf("[%lu] [ ] Display initialized\n", millis()); 197 193 198 194 renderer.insertFont(READER_FONT_ID, bookerlyFontFamily); 199 195 renderer.insertFont(UI_FONT_ID, ubuntuFontFamily); 200 196 renderer.insertFont(SMALL_FONT_ID, smallFontFamily); 201 - Serial.println("Fonts loaded"); 197 + Serial.printf("[%lu] [ ] Fonts setup\n", millis()); 202 198 203 199 exitScreen(); 204 200 enterNewScreen(new BootLogoScreen(renderer, inputManager)); ··· 229 225 delay(10); 230 226 231 227 static unsigned long lastMemPrint = 0; 232 - if (Serial && millis() - lastMemPrint >= 5000) { 233 - Serial.printf("[%lu] Memory - Free: %d bytes, Total: %d bytes, Min Free: %d bytes\n", millis(), ESP.getFreeHeap(), 228 + if (Serial && millis() - lastMemPrint >= 10000) { 229 + Serial.printf("[%lu] [MEM] Free: %d bytes, Total: %d bytes, Min Free: %d bytes\n", millis(), ESP.getFreeHeap(), 234 230 ESP.getHeapSize(), ESP.getMinFreeHeap()); 235 231 lastMemPrint = millis(); 236 232 }
+10 -8
src/screens/EpubReaderScreen.cpp
··· 36 36 f.read(data, 4); 37 37 currentSpineIndex = data[0] + (data[1] << 8); 38 38 nextPageNumber = data[2] + (data[3] << 8); 39 - Serial.printf("Loaded cache: %d, %d\n", currentSpineIndex, nextPageNumber); 39 + Serial.printf("[%lu] [ERS] Loaded cache: %d, %d\n", millis(), currentSpineIndex, nextPageNumber); 40 40 f.close(); 41 41 } 42 42 ··· 154 154 155 155 if (!section) { 156 156 const auto filepath = epub->getSpineItem(currentSpineIndex); 157 - Serial.printf("Loading file: %s, index: %d\n", filepath.c_str(), currentSpineIndex); 157 + Serial.printf("[%lu] [ERS] Loading file: %s, index: %d\n", millis(), filepath.c_str(), currentSpineIndex); 158 158 section = new Section(epub, currentSpineIndex, renderer); 159 159 if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom, 160 160 marginLeft)) { 161 - Serial.println("Cache not found, building..."); 161 + Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis()); 162 162 163 163 { 164 164 const int textWidth = renderer.getTextWidth(READER_FONT_ID, "Indexing..."); ··· 171 171 renderer.fillRect(x, y, w, h, 0); 172 172 renderer.drawText(READER_FONT_ID, x + margin, y + margin, "Indexing..."); 173 173 renderer.drawRect(x + 5, y + 5, w - 10, h - 10); 174 - renderer.displayBuffer(EInkDisplay::HALF_REFRESH); 174 + renderer.displayBuffer(); 175 175 pagesUntilFullRefresh = 0; 176 176 } 177 177 178 178 section->setupCacheDir(); 179 179 if (!section->persistPageDataToSD(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom, 180 180 marginLeft)) { 181 - Serial.println("Failed to persist page data to SD"); 181 + Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis()); 182 182 delete section; 183 183 section = nullptr; 184 184 return; 185 185 } 186 186 } else { 187 - Serial.println("Cache found, skipping build..."); 187 + Serial.printf("[%lu] [ERS] Cache found, skipping build...\n", millis()); 188 188 } 189 189 190 190 if (nextPageNumber == UINT16_MAX) { ··· 197 197 renderer.clearScreen(); 198 198 199 199 if (section->pageCount == 0) { 200 - Serial.println("No pages to render"); 200 + Serial.printf("[%lu] [ERS] No pages to render\n", millis()); 201 201 const int width = renderer.getTextWidth(READER_FONT_ID, "Empty chapter", BOLD); 202 202 renderer.drawText(READER_FONT_ID, (GfxRenderer::getScreenWidth() - width) / 2, 300, "Empty chapter", true, BOLD); 203 203 renderStatusBar(); ··· 206 206 } 207 207 208 208 if (section->currentPage < 0 || section->currentPage >= section->pageCount) { 209 - Serial.printf("Page out of bounds: %d (max %d)\n", section->currentPage, section->pageCount); 209 + Serial.printf("[%lu] [ERS] Page out of bounds: %d (max %d)\n", millis(), section->currentPage, section->pageCount); 210 210 const int width = renderer.getTextWidth(READER_FONT_ID, "Out of bounds", BOLD); 211 211 renderer.drawText(READER_FONT_ID, (GfxRenderer::getScreenWidth() - width) / 2, 300, "Out of bounds", true, BOLD); 212 212 renderStatusBar(); ··· 215 215 } 216 216 217 217 const Page* p = section->loadPageFromSD(); 218 + const auto start = millis(); 218 219 renderContents(p); 220 + Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start); 219 221 delete p; 220 222 221 223 File f = SD.open((epub->getCachePath() + "/progress.bin").c_str(), FILE_WRITE);