fix: prevent Serial.printf from blocking when USB disconnected
All checks were successful
CI / build (push) Successful in 2m23s
All checks were successful
CI / build (push) Successful in 2m23s
On ESP32-C3 with USB CDC, Serial.printf() blocks indefinitely when USB is not connected. This caused device freezes when booted without USB. Solution: Call Serial.setTxTimeoutMs(0) after Serial.begin() to make all Serial output non-blocking. Also added if (Serial) guards to high-traffic logging paths in EpubReaderActivity as belt-and-suspenders protection. Includes documentation of the debugging process and Serial call inventory. Also applies clang-format to fix pre-existing formatting issues.
This commit is contained in:
@@ -150,8 +150,7 @@ std::string DictHtmlParser::extractTagName(const std::string& html, size_t start
|
||||
|
||||
std::string tagName = html.substr(nameStart, pos - nameStart);
|
||||
// Convert to lowercase
|
||||
std::transform(tagName.begin(), tagName.end(), tagName.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
std::transform(tagName.begin(), tagName.end(), tagName.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
return tagName;
|
||||
}
|
||||
|
||||
@@ -160,17 +159,11 @@ bool DictHtmlParser::isBlockTag(const std::string& tagName) {
|
||||
tagName == "ol" || tagName == "ul" || tagName == "dt" || tagName == "dd" || tagName == "html";
|
||||
}
|
||||
|
||||
bool DictHtmlParser::isBoldTag(const std::string& tagName) {
|
||||
return tagName == "b" || tagName == "strong";
|
||||
}
|
||||
bool DictHtmlParser::isBoldTag(const std::string& tagName) { return tagName == "b" || tagName == "strong"; }
|
||||
|
||||
bool DictHtmlParser::isItalicTag(const std::string& tagName) {
|
||||
return tagName == "i" || tagName == "em";
|
||||
}
|
||||
bool DictHtmlParser::isItalicTag(const std::string& tagName) { return tagName == "i" || tagName == "em"; }
|
||||
|
||||
bool DictHtmlParser::isUnderlineTag(const std::string& tagName) {
|
||||
return tagName == "u" || tagName == "ins";
|
||||
}
|
||||
bool DictHtmlParser::isUnderlineTag(const std::string& tagName) { return tagName == "u" || tagName == "ins"; }
|
||||
|
||||
bool DictHtmlParser::isSuperscriptTag(const std::string& tagName) { return tagName == "sup"; }
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class GfxRenderer;
|
||||
|
||||
/**
|
||||
* DictHtmlParser parses HTML dictionary definitions into ParsedText.
|
||||
*
|
||||
*
|
||||
* Supports:
|
||||
* - Bold: <b>, <strong>
|
||||
* - Italic: <i>, <em>
|
||||
@@ -25,7 +25,7 @@ class DictHtmlParser {
|
||||
/**
|
||||
* Parse HTML definition and populate ParsedText with styled words.
|
||||
* Each paragraph/block creates a separate ParsedText via the callback.
|
||||
*
|
||||
*
|
||||
* @param html The HTML definition text
|
||||
* @param fontId Font ID for text width calculations
|
||||
* @param renderer Reference to renderer for layout
|
||||
|
||||
@@ -588,8 +588,12 @@ static std::string decodeHtmlEntity(const std::string& html, size_t& i) {
|
||||
const char* replacement;
|
||||
};
|
||||
static const EntityMapping entities[] = {
|
||||
{" ", " "}, {"<", "<"}, {">", ">"},
|
||||
{"&", "&"}, {""", "\""}, {"'", "'"},
|
||||
{" ", " "},
|
||||
{"<", "<"},
|
||||
{">", ">"},
|
||||
{"&", "&"},
|
||||
{""", "\""},
|
||||
{"'", "'"},
|
||||
{"—", "\xe2\x80\x94"}, // —
|
||||
{"–", "\xe2\x80\x93"}, // –
|
||||
{"…", "\xe2\x80\xa6"}, // …
|
||||
@@ -688,8 +692,8 @@ std::string StarDict::stripHtml(const std::string& html) {
|
||||
|
||||
// Extract tag name
|
||||
size_t tagEnd = tagStart;
|
||||
while (tagEnd < html.length() && !std::isspace(static_cast<unsigned char>(html[tagEnd])) &&
|
||||
html[tagEnd] != '>' && html[tagEnd] != '/') {
|
||||
while (tagEnd < html.length() && !std::isspace(static_cast<unsigned char>(html[tagEnd])) && html[tagEnd] != '>' &&
|
||||
html[tagEnd] != '/') {
|
||||
tagEnd++;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class StarDict {
|
||||
struct DictzipInfo {
|
||||
uint32_t chunkLength = 0; // Uncompressed chunk size (usually 58315)
|
||||
uint16_t chunkCount = 0;
|
||||
uint32_t headerSize = 0; // Total header size to skip
|
||||
uint32_t headerSize = 0; // Total header size to skip
|
||||
uint16_t* chunkSizes = nullptr; // Array of compressed chunk sizes
|
||||
bool loaded = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user