feat: Add central logging pragma (#843)
## Summary
* Definition and use of a central LOG function, that can later be
extended or completely be removed (for public use where debugging
information may not be required) to save flash by suppressing the
-DENABLE_SERIAL_LOG like in the slim branch
* **What changes are included?**
## Additional Context
* By using the central logger the usual:
```
#include <HardwareSerial.h>
...
Serial.printf("[%lu] [WCS] Obfuscating/deobfuscating %zu bytes\n", millis(), data.size());
```
would then become
```
#include <Logging.h>
...
LOG_DBG("WCS", "Obfuscating/deobfuscating %zu bytes", data.size());
```
You do have ``LOG_DBG`` for debug messages, ``LOG_ERR`` for error
messages and ``LOG_INF`` for informational messages. Depending on the
verbosity level defined (see below) soe of these message types will be
suppressed/not-compiled.
* The normal compilation (default) will create a firmware.elf file of
42.194.356 bytes, the same code via slim will create 42.024.048 bytes -
170.308 bytes less
* Firmware.bin : 6.469.984 bytes for default, 6.418.672 bytes for slim -
51.312 bytes less
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _NO_
---------
Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
This commit is contained in:
@@ -191,8 +191,7 @@ void TxtReaderActivity::initializeReader() {
|
||||
linesPerPage = viewportHeight / lineHeight;
|
||||
if (linesPerPage < 1) linesPerPage = 1;
|
||||
|
||||
Serial.printf("[%lu] [TRS] Viewport: %dx%d, lines per page: %d\n", millis(), viewportWidth, viewportHeight,
|
||||
linesPerPage);
|
||||
LOG_DBG("TRS", "Viewport: %dx%d, lines per page: %d", viewportWidth, viewportHeight, linesPerPage);
|
||||
|
||||
// Try to load cached page index first
|
||||
if (!loadPageIndexCache()) {
|
||||
@@ -215,7 +214,7 @@ void TxtReaderActivity::buildPageIndex() {
|
||||
size_t offset = 0;
|
||||
const size_t fileSize = txt->getFileSize();
|
||||
|
||||
Serial.printf("[%lu] [TRS] Building page index for %zu bytes...\n", millis(), fileSize);
|
||||
LOG_DBG("TRS", "Building page index for %zu bytes...", fileSize);
|
||||
|
||||
GUI.drawPopup(renderer, "Indexing...");
|
||||
|
||||
@@ -244,7 +243,7 @@ void TxtReaderActivity::buildPageIndex() {
|
||||
}
|
||||
|
||||
totalPages = pageOffsets.size();
|
||||
Serial.printf("[%lu] [TRS] Built page index: %d pages\n", millis(), totalPages);
|
||||
LOG_DBG("TRS", "Built page index: %d pages", totalPages);
|
||||
}
|
||||
|
||||
bool TxtReaderActivity::loadPageAtOffset(size_t offset, std::vector<std::string>& outLines, size_t& nextOffset) {
|
||||
@@ -259,7 +258,7 @@ bool TxtReaderActivity::loadPageAtOffset(size_t offset, std::vector<std::string>
|
||||
size_t chunkSize = std::min(CHUNK_SIZE, fileSize - offset);
|
||||
auto* buffer = static_cast<uint8_t*>(malloc(chunkSize + 1));
|
||||
if (!buffer) {
|
||||
Serial.printf("[%lu] [TRS] Failed to allocate %zu bytes\n", millis(), chunkSize);
|
||||
LOG_ERR("TRS", "Failed to allocate %zu bytes", chunkSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -588,7 +587,7 @@ void TxtReaderActivity::loadProgress() {
|
||||
if (currentPage < 0) {
|
||||
currentPage = 0;
|
||||
}
|
||||
Serial.printf("[%lu] [TRS] Loaded progress: page %d/%d\n", millis(), currentPage, totalPages);
|
||||
LOG_DBG("TRS", "Loaded progress: page %d/%d", currentPage, totalPages);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
@@ -610,7 +609,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
std::string cachePath = txt->getCachePath() + "/index.bin";
|
||||
FsFile f;
|
||||
if (!Storage.openFileForRead("TRS", cachePath, f)) {
|
||||
Serial.printf("[%lu] [TRS] No page index cache found\n", millis());
|
||||
LOG_DBG("TRS", "No page index cache found");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -618,7 +617,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
uint32_t magic;
|
||||
serialization::readPod(f, magic);
|
||||
if (magic != CACHE_MAGIC) {
|
||||
Serial.printf("[%lu] [TRS] Cache magic mismatch, rebuilding\n", millis());
|
||||
LOG_DBG("TRS", "Cache magic mismatch, rebuilding");
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -626,7 +625,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
uint8_t version;
|
||||
serialization::readPod(f, version);
|
||||
if (version != CACHE_VERSION) {
|
||||
Serial.printf("[%lu] [TRS] Cache version mismatch (%d != %d), rebuilding\n", millis(), version, CACHE_VERSION);
|
||||
LOG_DBG("TRS", "Cache version mismatch (%d != %d), rebuilding", version, CACHE_VERSION);
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -634,7 +633,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
uint32_t fileSize;
|
||||
serialization::readPod(f, fileSize);
|
||||
if (fileSize != txt->getFileSize()) {
|
||||
Serial.printf("[%lu] [TRS] Cache file size mismatch, rebuilding\n", millis());
|
||||
LOG_DBG("TRS", "Cache file size mismatch, rebuilding");
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -642,7 +641,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
int32_t cachedWidth;
|
||||
serialization::readPod(f, cachedWidth);
|
||||
if (cachedWidth != viewportWidth) {
|
||||
Serial.printf("[%lu] [TRS] Cache viewport width mismatch, rebuilding\n", millis());
|
||||
LOG_DBG("TRS", "Cache viewport width mismatch, rebuilding");
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -650,7 +649,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
int32_t cachedLines;
|
||||
serialization::readPod(f, cachedLines);
|
||||
if (cachedLines != linesPerPage) {
|
||||
Serial.printf("[%lu] [TRS] Cache lines per page mismatch, rebuilding\n", millis());
|
||||
LOG_DBG("TRS", "Cache lines per page mismatch, rebuilding");
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -658,7 +657,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
int32_t fontId;
|
||||
serialization::readPod(f, fontId);
|
||||
if (fontId != cachedFontId) {
|
||||
Serial.printf("[%lu] [TRS] Cache font ID mismatch (%d != %d), rebuilding\n", millis(), fontId, cachedFontId);
|
||||
LOG_DBG("TRS", "Cache font ID mismatch (%d != %d), rebuilding", fontId, cachedFontId);
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -666,7 +665,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
int32_t margin;
|
||||
serialization::readPod(f, margin);
|
||||
if (margin != cachedScreenMargin) {
|
||||
Serial.printf("[%lu] [TRS] Cache screen margin mismatch, rebuilding\n", millis());
|
||||
LOG_DBG("TRS", "Cache screen margin mismatch, rebuilding");
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -674,7 +673,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
uint8_t alignment;
|
||||
serialization::readPod(f, alignment);
|
||||
if (alignment != cachedParagraphAlignment) {
|
||||
Serial.printf("[%lu] [TRS] Cache paragraph alignment mismatch, rebuilding\n", millis());
|
||||
LOG_DBG("TRS", "Cache paragraph alignment mismatch, rebuilding");
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
@@ -694,7 +693,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
|
||||
|
||||
f.close();
|
||||
totalPages = pageOffsets.size();
|
||||
Serial.printf("[%lu] [TRS] Loaded page index cache: %d pages\n", millis(), totalPages);
|
||||
LOG_DBG("TRS", "Loaded page index cache: %d pages", totalPages);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -702,7 +701,7 @@ void TxtReaderActivity::savePageIndexCache() const {
|
||||
std::string cachePath = txt->getCachePath() + "/index.bin";
|
||||
FsFile f;
|
||||
if (!Storage.openFileForWrite("TRS", cachePath, f)) {
|
||||
Serial.printf("[%lu] [TRS] Failed to save page index cache\n", millis());
|
||||
LOG_ERR("TRS", "Failed to save page index cache");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -723,5 +722,5 @@ void TxtReaderActivity::savePageIndexCache() const {
|
||||
}
|
||||
|
||||
f.close();
|
||||
Serial.printf("[%lu] [TRS] Saved page index cache: %d pages\n", millis(), totalPages);
|
||||
LOG_DBG("TRS", "Saved page index cache: %d pages", totalPages);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user