Some checks failed
CI / build (push) Failing after 2m16s
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.
62 lines
2.1 KiB
C++
62 lines
2.1 KiB
C++
#pragma once
|
|
#include <Epub/blocks/TextBlock.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../Activity.h"
|
|
|
|
/**
|
|
* DictionaryResultActivity displays a word definition with pagination.
|
|
* Supports multi-page definitions with navigation and rich text formatting.
|
|
*/
|
|
class DictionaryResultActivity final : public Activity {
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
|
bool updateRequired = false;
|
|
|
|
const std::string lookupWord; // Named to avoid Arduino's 'word' macro
|
|
const std::string rawDefinition;
|
|
const std::function<void()> onBack;
|
|
const std::function<void()> onSearchAnother;
|
|
|
|
// Pagination - each page contains TextBlocks with styled text
|
|
std::vector<std::vector<std::shared_ptr<TextBlock>>> pages;
|
|
int currentPage = 0;
|
|
bool notFound = false;
|
|
|
|
static void taskTrampoline(void* param);
|
|
[[noreturn]] void displayTaskLoop();
|
|
void render() const;
|
|
void paginateDefinition();
|
|
|
|
public:
|
|
/**
|
|
* Constructor
|
|
* @param renderer Graphics renderer
|
|
* @param mappedInput Input manager
|
|
* @param wordToLookup The word that was looked up
|
|
* @param definition The definition text (HTML will be stripped). Empty = not found.
|
|
* @param onBack Callback when user wants to go back to book
|
|
* @param onSearchAnother Callback when user wants to search another word
|
|
*/
|
|
explicit DictionaryResultActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
const std::string& wordToLookup, const std::string& definition,
|
|
const std::function<void()>& onBack, const std::function<void()>& onSearchAnother)
|
|
: Activity("DictionaryResult", renderer, mappedInput),
|
|
lookupWord(wordToLookup),
|
|
rawDefinition(definition),
|
|
onBack(onBack),
|
|
onSearchAnother(onSearchAnother),
|
|
notFound(definition.empty()) {}
|
|
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
};
|