mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Compare commits
8 Commits
f5508f291e
...
2750238fc4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2750238fc4 | ||
|
|
4dd73a211a | ||
|
|
634f6279cb | ||
|
|
11b2a59233 | ||
|
|
12c20bb09e | ||
|
|
6b7065b986 | ||
|
|
f4df513bf3 | ||
|
|
f935b59a41 |
@ -201,7 +201,7 @@ CrossPoint renders text using the following Unicode character blocks, enabling s
|
||||
* **Latin Script (Basic, Supplement, Extended-A):** Covers English, German, French, Spanish, Portuguese, Italian, Dutch, Swedish, Norwegian, Danish, Finnish, Polish, Czech, Hungarian, Romanian, Slovak, Slovenian, Turkish, and others.
|
||||
* **Cyrillic Script (Standard and Extended):** Covers Russian, Ukrainian, Belarusian, Bulgarian, Serbian, Macedonian, Kazakh, Kyrgyz, Mongolian, and others.
|
||||
|
||||
What is not supported: Chinese, Japanese, Korean, Vietnamese, Hebrew, Arabic and Farsi.
|
||||
What is not supported: Chinese, Japanese, Korean, Vietnamese, Hebrew, Arabic, Greek and Farsi.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -123,9 +123,7 @@ bool Section::clearCache() const {
|
||||
bool Section::createSectionFile(const int fontId, const float lineCompression, const bool extraParagraphSpacing,
|
||||
const uint8_t paragraphAlignment, const uint16_t viewportWidth,
|
||||
const uint16_t viewportHeight, const bool hyphenationEnabled,
|
||||
const std::function<void()>& progressSetupFn,
|
||||
const std::function<void(int)>& progressFn) {
|
||||
constexpr uint32_t MIN_SIZE_FOR_PROGRESS = 50 * 1024; // 50KB
|
||||
const std::function<void()>& popupFn) {
|
||||
const auto localPath = epub->getSpineItem(spineIndex).href;
|
||||
const auto tmpHtmlPath = epub->getCachePath() + "/.tmp_" + std::to_string(spineIndex) + ".html";
|
||||
|
||||
@ -171,11 +169,6 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
|
||||
Serial.printf("[%lu] [SCT] Streamed temp HTML to %s (%d bytes)\n", millis(), tmpHtmlPath.c_str(), fileSize);
|
||||
|
||||
// Only show progress bar for larger chapters where rendering overhead is worth it
|
||||
if (progressSetupFn && fileSize >= MIN_SIZE_FOR_PROGRESS) {
|
||||
progressSetupFn();
|
||||
}
|
||||
|
||||
if (!SdMan.openFileForWrite("SCT", filePath, file)) {
|
||||
return false;
|
||||
}
|
||||
@ -186,8 +179,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
ChapterHtmlSlimParser visitor(
|
||||
tmpHtmlPath, renderer, fontId, lineCompression, extraParagraphSpacing, paragraphAlignment, viewportWidth,
|
||||
viewportHeight, hyphenationEnabled,
|
||||
[this, &lut](std::unique_ptr<Page> page) { lut.emplace_back(this->onPageComplete(std::move(page))); },
|
||||
progressFn);
|
||||
[this, &lut](std::unique_ptr<Page> page) { lut.emplace_back(this->onPageComplete(std::move(page))); }, popupFn);
|
||||
Hyphenator::setPreferredLanguage(epub->getLanguage());
|
||||
success = visitor.parseAndBuildPages();
|
||||
|
||||
|
||||
@ -33,7 +33,6 @@ class Section {
|
||||
bool clearCache() const;
|
||||
bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
||||
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled,
|
||||
const std::function<void()>& progressSetupFn = nullptr,
|
||||
const std::function<void(int)>& progressFn = nullptr);
|
||||
const std::function<void()>& popupFn = nullptr);
|
||||
std::unique_ptr<Page> loadPageFromSectionFile();
|
||||
};
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
const char* HEADER_TAGS[] = {"h1", "h2", "h3", "h4", "h5", "h6"};
|
||||
constexpr int NUM_HEADER_TAGS = sizeof(HEADER_TAGS) / sizeof(HEADER_TAGS[0]);
|
||||
|
||||
// Minimum file size (in bytes) to show progress bar - smaller chapters don't benefit from it
|
||||
constexpr size_t MIN_SIZE_FOR_PROGRESS = 50 * 1024; // 50KB
|
||||
// Minimum file size (in bytes) to show indexing popup - smaller chapters don't benefit from it
|
||||
constexpr size_t MIN_SIZE_FOR_POPUP = 50 * 1024; // 50KB
|
||||
|
||||
const char* BLOCK_TAGS[] = {"p", "li", "div", "br", "blockquote"};
|
||||
constexpr int NUM_BLOCK_TAGS = sizeof(BLOCK_TAGS) / sizeof(BLOCK_TAGS[0]);
|
||||
@ -289,10 +289,10 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get file size for progress calculation
|
||||
const size_t totalSize = file.size();
|
||||
size_t bytesRead = 0;
|
||||
int lastProgress = -1;
|
||||
// Get file size to decide whether to show indexing popup.
|
||||
if (popupFn && file.size() >= MIN_SIZE_FOR_POPUP) {
|
||||
popupFn();
|
||||
}
|
||||
|
||||
XML_SetUserData(parser, this);
|
||||
XML_SetElementHandler(parser, startElement, endElement);
|
||||
@ -322,17 +322,6 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update progress (call every 10% change to avoid too frequent updates)
|
||||
// Only show progress for larger chapters where rendering overhead is worth it
|
||||
bytesRead += len;
|
||||
if (progressFn && totalSize >= MIN_SIZE_FOR_PROGRESS) {
|
||||
const int progress = static_cast<int>((bytesRead * 100) / totalSize);
|
||||
if (lastProgress / 10 != progress / 10) {
|
||||
lastProgress = progress;
|
||||
progressFn(progress);
|
||||
}
|
||||
}
|
||||
|
||||
done = file.available() == 0;
|
||||
|
||||
if (XML_ParseBuffer(parser, static_cast<int>(len), done) == XML_STATUS_ERROR) {
|
||||
|
||||
@ -18,7 +18,7 @@ class ChapterHtmlSlimParser {
|
||||
const std::string& filepath;
|
||||
GfxRenderer& renderer;
|
||||
std::function<void(std::unique_ptr<Page>)> completePageFn;
|
||||
std::function<void(int)> progressFn; // Progress callback (0-100)
|
||||
std::function<void()> popupFn; // Popup callback
|
||||
int depth = 0;
|
||||
int skipUntilDepth = INT_MAX;
|
||||
int boldUntilDepth = INT_MAX;
|
||||
@ -52,7 +52,7 @@ class ChapterHtmlSlimParser {
|
||||
const uint8_t paragraphAlignment, const uint16_t viewportWidth,
|
||||
const uint16_t viewportHeight, const bool hyphenationEnabled,
|
||||
const std::function<void(std::unique_ptr<Page>)>& completePageFn,
|
||||
const std::function<void(int)>& progressFn = nullptr)
|
||||
const std::function<void()>& popupFn = nullptr)
|
||||
: filepath(filepath),
|
||||
renderer(renderer),
|
||||
fontId(fontId),
|
||||
@ -63,7 +63,7 @@ class ChapterHtmlSlimParser {
|
||||
viewportHeight(viewportHeight),
|
||||
hyphenationEnabled(hyphenationEnabled),
|
||||
completePageFn(completePageFn),
|
||||
progressFn(progressFn) {}
|
||||
popupFn(popupFn) {}
|
||||
~ChapterHtmlSlimParser() = default;
|
||||
bool parseAndBuildPages();
|
||||
void addLineToPage(std::shared_ptr<TextBlock> line);
|
||||
|
||||
@ -68,7 +68,7 @@ class GfxRenderer {
|
||||
int getScreenHeight() const;
|
||||
void displayBuffer(HalDisplay::RefreshMode refreshMode = HalDisplay::FAST_REFRESH) const;
|
||||
// EXPERIMENTAL: Windowed update - display only a rectangular region
|
||||
void displayWindow(int x, int y, int width, int height) const;
|
||||
// void displayWindow(int x, int y, int width, int height) const;
|
||||
void invertScreen() const;
|
||||
void clearScreen(uint8_t color = 0xFF) const;
|
||||
|
||||
|
||||
@ -24,12 +24,13 @@ bool HalGPIO::wasAnyReleased() const { return inputMgr.wasAnyReleased(); }
|
||||
unsigned long HalGPIO::getHeldTime() const { return inputMgr.getHeldTime(); }
|
||||
|
||||
void HalGPIO::startDeepSleep() {
|
||||
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);
|
||||
// Ensure that the power button has been released to avoid immediately turning back on if you're holding it
|
||||
while (inputMgr.isPressed(BTN_POWER)) {
|
||||
delay(50);
|
||||
inputMgr.update();
|
||||
}
|
||||
// Arm the wakeup trigger *after* the button is released
|
||||
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);
|
||||
// Enter Deep Sleep
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
@ -44,12 +45,20 @@ bool HalGPIO::isUsbConnected() const {
|
||||
return digitalRead(UART0_RXD) == HIGH;
|
||||
}
|
||||
|
||||
bool HalGPIO::isWakeupByPowerButton() const {
|
||||
HalGPIO::WakeupReason HalGPIO::getWakeupReason() const {
|
||||
const bool usbConnected = isUsbConnected();
|
||||
const auto wakeupCause = esp_sleep_get_wakeup_cause();
|
||||
const auto resetReason = esp_reset_reason();
|
||||
if (isUsbConnected()) {
|
||||
return wakeupCause == ESP_SLEEP_WAKEUP_GPIO;
|
||||
} else {
|
||||
return (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_POWERON);
|
||||
|
||||
if ((wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && !usbConnected) ||
|
||||
(wakeupCause == ESP_SLEEP_WAKEUP_GPIO && resetReason == ESP_RST_DEEPSLEEP && usbConnected)) {
|
||||
return WakeupReason::PowerButton;
|
||||
}
|
||||
if (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_UNKNOWN && usbConnected) {
|
||||
return WakeupReason::AfterFlash;
|
||||
}
|
||||
if (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED && resetReason == ESP_RST_POWERON && usbConnected) {
|
||||
return WakeupReason::AfterUSBPower;
|
||||
}
|
||||
return WakeupReason::Other;
|
||||
}
|
||||
@ -47,8 +47,9 @@ class HalGPIO {
|
||||
// Check if USB is connected
|
||||
bool isUsbConnected() const;
|
||||
|
||||
// Check if wakeup was caused by power button press
|
||||
bool isWakeupByPowerButton() const;
|
||||
enum class WakeupReason { PowerButton, AfterFlash, AfterUSBPower, Other };
|
||||
|
||||
WakeupReason getWakeupReason() const;
|
||||
|
||||
// Button indices
|
||||
static constexpr uint8_t BTN_BACK = 0;
|
||||
|
||||
@ -34,7 +34,7 @@ int HomeActivity::getMenuItemCount() const {
|
||||
return count;
|
||||
}
|
||||
|
||||
void HomeActivity::loadRecentBooks(int maxBooks, int coverHeight, PopupCallbacks& popupCallbacks) {
|
||||
void HomeActivity::loadRecentBooks(int maxBooks, int coverHeight, Rect& popupRect) {
|
||||
recentsLoading = true;
|
||||
|
||||
recentBooks.clear();
|
||||
@ -42,7 +42,6 @@ void HomeActivity::loadRecentBooks(int maxBooks, int coverHeight, PopupCallbacks
|
||||
recentBooks.reserve(std::min(static_cast<int>(books.size()), maxBooks));
|
||||
|
||||
int progress = 0;
|
||||
bool loadingPopupDisplayed = false;
|
||||
for (const RecentBook& book : books) {
|
||||
const std::string& path = book.path;
|
||||
|
||||
@ -73,12 +72,7 @@ void HomeActivity::loadRecentBooks(int maxBooks, int coverHeight, PopupCallbacks
|
||||
// Try to generate thumbnail image for Continue Reading card
|
||||
coverBmpPath = epub.getThumbBmpPath(coverHeight);
|
||||
if (!SdMan.exists(coverBmpPath.c_str())) {
|
||||
if (loadingPopupDisplayed) {
|
||||
popupCallbacks.update(progress * 30);
|
||||
} else {
|
||||
popupCallbacks.setup();
|
||||
loadingPopupDisplayed = true;
|
||||
}
|
||||
UITheme::fillPopupProgress(renderer, popupRect, progress * 30);
|
||||
if (!epub.generateThumbBmp(coverHeight)) {
|
||||
coverBmpPath = "";
|
||||
}
|
||||
@ -91,12 +85,7 @@ void HomeActivity::loadRecentBooks(int maxBooks, int coverHeight, PopupCallbacks
|
||||
// Try to generate thumbnail image for Continue Reading card
|
||||
coverBmpPath = xtc.getThumbBmpPath(coverHeight);
|
||||
if (!SdMan.exists(coverBmpPath.c_str())) {
|
||||
if (loadingPopupDisplayed) {
|
||||
popupCallbacks.update(progress * 30);
|
||||
} else {
|
||||
popupCallbacks.setup();
|
||||
loadingPopupDisplayed = true;
|
||||
}
|
||||
UITheme::fillPopupProgress(renderer, popupRect, progress * 30);
|
||||
if (!xtc.generateThumbBmp(coverHeight)) {
|
||||
coverBmpPath = "";
|
||||
}
|
||||
@ -268,8 +257,8 @@ void HomeActivity::render() {
|
||||
std::bind(&HomeActivity::storeCoverBuffer, this));
|
||||
} else if (!recentsLoading && firstRenderDone) {
|
||||
recentsLoading = true;
|
||||
PopupCallbacks popupCallbacks = UITheme::drawPopupWithProgress(renderer, "Loading...");
|
||||
loadRecentBooks(metrics.homeRecentBooksCount, metrics.homeCoverHeight, popupCallbacks);
|
||||
Rect popupRect = UITheme::drawPopup(renderer, "Loading...");
|
||||
loadRecentBooks(metrics.homeRecentBooksCount, metrics.homeCoverHeight, popupRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "./MyLibraryActivity.h"
|
||||
|
||||
struct RecentBookWithCover;
|
||||
struct PopupCallbacks;
|
||||
struct Rect;
|
||||
|
||||
class HomeActivity final : public Activity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
@ -41,7 +41,7 @@ class HomeActivity final : public Activity {
|
||||
bool storeCoverBuffer(); // Store frame buffer for cover image
|
||||
bool restoreCoverBuffer(); // Restore frame buffer from stored cover
|
||||
void freeCoverBuffer(); // Free the stored cover buffer
|
||||
void loadRecentBooks(int maxBooks, int coverHeight, PopupCallbacks& popupCallbacks);
|
||||
void loadRecentBooks(int maxBooks, int coverHeight, Rect& popupRect);
|
||||
|
||||
public:
|
||||
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||||
|
||||
@ -267,9 +267,9 @@ void WifiSelectionActivity::checkConnectionStatus() {
|
||||
}
|
||||
|
||||
if (status == WL_CONNECT_FAILED || status == WL_NO_SSID_AVAIL) {
|
||||
connectionError = "Connection failed";
|
||||
connectionError = "Error: General failure";
|
||||
if (status == WL_NO_SSID_AVAIL) {
|
||||
connectionError = "Network not found";
|
||||
connectionError = "Error: Network not found";
|
||||
}
|
||||
state = WifiSelectionState::CONNECTION_FAILED;
|
||||
updateRequired = true;
|
||||
@ -279,7 +279,7 @@ void WifiSelectionActivity::checkConnectionStatus() {
|
||||
// Check for timeout
|
||||
if (millis() - connectionStartTime > CONNECTION_TIMEOUT_MS) {
|
||||
WiFi.disconnect();
|
||||
connectionError = "Connection timeout";
|
||||
connectionError = "Error: Connection timeout";
|
||||
state = WifiSelectionState::CONNECTION_FAILED;
|
||||
updateRequired = true;
|
||||
return;
|
||||
@ -690,7 +690,7 @@ void WifiSelectionActivity::renderForgetPrompt() const {
|
||||
const auto height = renderer.getLineHeight(UI_10_FONT_ID);
|
||||
const auto top = (pageHeight - height * 3) / 2;
|
||||
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Forget Network?", true, EpdFontFamily::BOLD);
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Connection Failed", true, EpdFontFamily::BOLD);
|
||||
|
||||
std::string ssidInfo = "Network: " + selectedSSID;
|
||||
if (ssidInfo.length() > 28) {
|
||||
@ -698,7 +698,7 @@ void WifiSelectionActivity::renderForgetPrompt() const {
|
||||
}
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, top, ssidInfo.c_str());
|
||||
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, top + 40, "Remove saved password?");
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, top + 40, "Forget network and remove saved password?");
|
||||
|
||||
// Draw Cancel/Forget network buttons
|
||||
const int buttonY = top + 80;
|
||||
|
||||
@ -130,31 +130,9 @@ void EpubReaderActivity::loop() {
|
||||
const int currentPage = section ? section->currentPage : 0;
|
||||
const int totalPages = section ? section->pageCount : 0;
|
||||
exitActivity();
|
||||
enterNewActivity(new EpubReaderChapterSelectionActivity(
|
||||
this->renderer, this->mappedInput, epub, epub->getPath(), currentSpineIndex, currentPage, totalPages,
|
||||
[this] {
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
},
|
||||
[this](const int newSpineIndex) {
|
||||
if (currentSpineIndex != newSpineIndex) {
|
||||
currentSpineIndex = newSpineIndex;
|
||||
nextPageNumber = 0;
|
||||
section.reset();
|
||||
}
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
},
|
||||
[this](const int newSpineIndex, const int newPage) {
|
||||
// Handle sync position
|
||||
if (currentSpineIndex != newSpineIndex || (section && section->currentPage != newPage)) {
|
||||
currentSpineIndex = newSpineIndex;
|
||||
nextPageNumber = newPage;
|
||||
section.reset();
|
||||
}
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
}));
|
||||
enterNewActivity(new EpubReaderMenuActivity(
|
||||
this->renderer, this->mappedInput, epub->getTitle(), [this]() { onReaderMenuBack(); },
|
||||
[this](EpubReaderMenuActivity::MenuAction action) { onReaderMenuConfirm(action); }));
|
||||
xSemaphoreGive(renderingMutex);
|
||||
}
|
||||
|
||||
@ -242,6 +220,89 @@ void EpubReaderActivity::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderActivity::onReaderMenuBack() {
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
}
|
||||
|
||||
void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action) {
|
||||
switch (action) {
|
||||
case EpubReaderMenuActivity::MenuAction::SELECT_CHAPTER: {
|
||||
// Calculate values BEFORE we start destroying things
|
||||
const int currentP = section ? section->currentPage : 0;
|
||||
const int totalP = section ? section->pageCount : 0;
|
||||
const int spineIdx = currentSpineIndex;
|
||||
const std::string path = epub->getPath();
|
||||
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
|
||||
// 1. Close the menu
|
||||
exitActivity();
|
||||
|
||||
// 2. Open the Chapter Selector
|
||||
enterNewActivity(new EpubReaderChapterSelectionActivity(
|
||||
this->renderer, this->mappedInput, epub, path, spineIdx, currentP, totalP,
|
||||
[this] {
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
},
|
||||
[this](const int newSpineIndex) {
|
||||
if (currentSpineIndex != newSpineIndex) {
|
||||
currentSpineIndex = newSpineIndex;
|
||||
nextPageNumber = 0;
|
||||
section.reset();
|
||||
}
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
},
|
||||
[this](const int newSpineIndex, const int newPage) {
|
||||
if (currentSpineIndex != newSpineIndex || (section && section->currentPage != newPage)) {
|
||||
currentSpineIndex = newSpineIndex;
|
||||
nextPageNumber = newPage;
|
||||
section.reset();
|
||||
}
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
}));
|
||||
|
||||
xSemaphoreGive(renderingMutex);
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::GO_HOME: {
|
||||
// 2. Trigger the reader's "Go Home" callback
|
||||
if (onGoHome) {
|
||||
onGoHome();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::DELETE_CACHE: {
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (epub) {
|
||||
// 2. BACKUP: Read current progress
|
||||
// We use the current variables that track our position
|
||||
uint16_t backupSpine = currentSpineIndex;
|
||||
uint16_t backupPage = section->currentPage;
|
||||
uint16_t backupPageCount = section->pageCount;
|
||||
|
||||
section.reset();
|
||||
// 3. WIPE: Clear the cache directory
|
||||
epub->clearCache();
|
||||
|
||||
// 4. RESTORE: Re-setup the directory and rewrite the progress file
|
||||
epub->setupCacheDir();
|
||||
|
||||
saveProgress(backupSpine, backupPage, backupPageCount);
|
||||
}
|
||||
exitActivity();
|
||||
updateRequired = true;
|
||||
xSemaphoreGive(renderingMutex);
|
||||
if (onGoHome) onGoHome();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
@ -310,12 +371,11 @@ void EpubReaderActivity::renderScreen() {
|
||||
viewportHeight, SETTINGS.hyphenationEnabled)) {
|
||||
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
||||
|
||||
auto popupCallbacks = UITheme::drawPopupWithProgress(renderer, "Indexing...");
|
||||
const auto popupFn = [this]() { UITheme::drawPopup(renderer, "Indexing..."); };
|
||||
|
||||
if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(),
|
||||
SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth,
|
||||
viewportHeight, SETTINGS.hyphenationEnabled, popupCallbacks.setup,
|
||||
popupCallbacks.update)) {
|
||||
viewportHeight, SETTINGS.hyphenationEnabled, popupFn)) {
|
||||
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
|
||||
section.reset();
|
||||
return;
|
||||
@ -372,21 +432,26 @@ void EpubReaderActivity::renderScreen() {
|
||||
renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
|
||||
Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);
|
||||
}
|
||||
saveProgress(currentSpineIndex, section->currentPage, section->pageCount);
|
||||
}
|
||||
|
||||
void EpubReaderActivity::saveProgress(int spineIndex, int currentPage, int pageCount) {
|
||||
FsFile f;
|
||||
if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[6];
|
||||
data[0] = currentSpineIndex & 0xFF;
|
||||
data[1] = (currentSpineIndex >> 8) & 0xFF;
|
||||
data[2] = section->currentPage & 0xFF;
|
||||
data[3] = (section->currentPage >> 8) & 0xFF;
|
||||
data[4] = section->pageCount & 0xFF;
|
||||
data[5] = (section->pageCount >> 8) & 0xFF;
|
||||
data[2] = currentPage & 0xFF;
|
||||
data[3] = (currentPage >> 8) & 0xFF;
|
||||
data[4] = pageCount & 0xFF;
|
||||
data[5] = (pageCount >> 8) & 0xFF;
|
||||
f.write(data, 6);
|
||||
f.close();
|
||||
Serial.printf("[ERS] Progress saved: Chapter %d, Page %d\n", spineIndex, currentPage);
|
||||
} else {
|
||||
Serial.printf("[ERS] Could not save progress!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int orientedMarginTop,
|
||||
const int orientedMarginRight, const int orientedMarginBottom,
|
||||
const int orientedMarginLeft) {
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "EpubReaderMenuActivity.h"
|
||||
#include "activities/ActivityWithSubactivity.h"
|
||||
|
||||
class EpubReaderActivity final : public ActivityWithSubactivity {
|
||||
@ -27,6 +28,9 @@ class EpubReaderActivity final : public ActivityWithSubactivity {
|
||||
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
|
||||
int orientedMarginBottom, int orientedMarginLeft);
|
||||
void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const;
|
||||
void saveProgress(int spineIndex, int currentPage, int pageCount);
|
||||
void onReaderMenuBack();
|
||||
void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action);
|
||||
|
||||
public:
|
||||
explicit EpubReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr<Epub> epub,
|
||||
|
||||
@ -182,9 +182,7 @@ void EpubReaderChapterSelectionActivity::renderScreen() {
|
||||
const int pageItems = getPageItems();
|
||||
const int totalItems = getTotalItems();
|
||||
|
||||
const std::string title =
|
||||
renderer.truncatedText(UI_12_FONT_ID, epub->getTitle().c_str(), pageWidth - 40, EpdFontFamily::BOLD);
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 15, title.c_str(), true, EpdFontFamily::BOLD);
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 15, "Go to Chapter", true, EpdFontFamily::BOLD);
|
||||
|
||||
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
||||
renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30);
|
||||
@ -209,8 +207,11 @@ void EpubReaderChapterSelectionActivity::renderScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
// Skip button hints in landscape CW mode (they overlap content)
|
||||
if (renderer.getOrientation() != GfxRenderer::LandscapeClockwise) {
|
||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");
|
||||
UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
}
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
|
||||
104
src/activities/reader/EpubReaderMenuActivity.cpp
Normal file
104
src/activities/reader/EpubReaderMenuActivity.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "EpubReaderMenuActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
void EpubReaderMenuActivity::onEnter() {
|
||||
ActivityWithSubactivity::onEnter();
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
updateRequired = true;
|
||||
|
||||
xTaskCreate(&EpubReaderMenuActivity::taskTrampoline, "EpubMenuTask", 4096, this, 1, &displayTaskHandle);
|
||||
}
|
||||
|
||||
void EpubReaderMenuActivity::onExit() {
|
||||
ActivityWithSubactivity::onExit();
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
vTaskDelete(displayTaskHandle);
|
||||
displayTaskHandle = nullptr;
|
||||
}
|
||||
vSemaphoreDelete(renderingMutex);
|
||||
renderingMutex = nullptr;
|
||||
}
|
||||
|
||||
void EpubReaderMenuActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<EpubReaderMenuActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void EpubReaderMenuActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired && !subActivity) {
|
||||
updateRequired = false;
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
renderScreen();
|
||||
xSemaphoreGive(renderingMutex);
|
||||
}
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderMenuActivity::loop() {
|
||||
if (subActivity) {
|
||||
subActivity->loop();
|
||||
return;
|
||||
}
|
||||
|
||||
// Use local variables for items we need to check after potential deletion
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Up) ||
|
||||
mappedInput.wasReleased(MappedInputManager::Button::Left)) {
|
||||
selectedIndex = (selectedIndex + menuItems.size() - 1) % menuItems.size();
|
||||
updateRequired = true;
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Down) ||
|
||||
mappedInput.wasReleased(MappedInputManager::Button::Right)) {
|
||||
selectedIndex = (selectedIndex + 1) % menuItems.size();
|
||||
updateRequired = true;
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
// 1. Capture the callback and action locally
|
||||
auto actionCallback = onAction;
|
||||
auto selectedAction = menuItems[selectedIndex].action;
|
||||
|
||||
// 2. Execute the callback
|
||||
actionCallback(selectedAction);
|
||||
|
||||
// 3. CRITICAL: Return immediately. 'this' is likely deleted now.
|
||||
return;
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
onBack();
|
||||
return; // Also return here just in case
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderMenuActivity::renderScreen() {
|
||||
renderer.clearScreen();
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
|
||||
// Title
|
||||
const std::string truncTitle =
|
||||
renderer.truncatedText(UI_12_FONT_ID, title.c_str(), pageWidth - 40, EpdFontFamily::BOLD);
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 15, truncTitle.c_str(), true, EpdFontFamily::BOLD);
|
||||
|
||||
// Menu Items
|
||||
constexpr int startY = 60;
|
||||
constexpr int lineHeight = 30;
|
||||
|
||||
for (size_t i = 0; i < menuItems.size(); ++i) {
|
||||
const int displayY = startY + (i * lineHeight);
|
||||
const bool isSelected = (static_cast<int>(i) == selectedIndex);
|
||||
|
||||
if (isSelected) {
|
||||
renderer.fillRect(0, displayY, pageWidth - 1, lineHeight, true);
|
||||
}
|
||||
|
||||
renderer.drawText(UI_10_FONT_ID, 20, displayY, menuItems[i].label.c_str(), !isSelected);
|
||||
}
|
||||
|
||||
// Footer / Hints
|
||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");
|
||||
UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
51
src/activities/reader/EpubReaderMenuActivity.h
Normal file
51
src/activities/reader/EpubReaderMenuActivity.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include <Epub.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../ActivityWithSubactivity.h"
|
||||
#include "MappedInputManager.h"
|
||||
|
||||
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
public:
|
||||
enum class MenuAction { SELECT_CHAPTER, GO_HOME, DELETE_CACHE };
|
||||
|
||||
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
||||
const std::function<void()>& onBack, const std::function<void(MenuAction)>& onAction)
|
||||
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
||||
title(title),
|
||||
onBack(onBack),
|
||||
onAction(onAction) {}
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
|
||||
private:
|
||||
struct MenuItem {
|
||||
MenuAction action;
|
||||
std::string label;
|
||||
};
|
||||
|
||||
const std::vector<MenuItem> menuItems = {{MenuAction::SELECT_CHAPTER, "Go to Chapter"},
|
||||
{MenuAction::GO_HOME, "Go Home"},
|
||||
{MenuAction::DELETE_CACHE, "Delete Book Cache"}};
|
||||
|
||||
int selectedIndex = 0;
|
||||
bool updateRequired = false;
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
std::string title = "Reader Menu";
|
||||
|
||||
const std::function<void()> onBack;
|
||||
const std::function<void(MenuAction)> onAction;
|
||||
|
||||
static void taskTrampoline(void* param);
|
||||
[[noreturn]] void displayTaskLoop();
|
||||
void renderScreen();
|
||||
};
|
||||
@ -209,28 +209,10 @@ void TxtReaderActivity::buildPageIndex() {
|
||||
|
||||
size_t offset = 0;
|
||||
const size_t fileSize = txt->getFileSize();
|
||||
int lastProgressPercent = -1;
|
||||
|
||||
Serial.printf("[%lu] [TRS] Building page index for %zu bytes...\n", millis(), fileSize);
|
||||
|
||||
// Progress bar dimensions (matching EpubReaderActivity style)
|
||||
constexpr int barWidth = 200;
|
||||
constexpr int barHeight = 10;
|
||||
constexpr int boxMargin = 20;
|
||||
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, "Indexing...");
|
||||
const int boxWidth = (barWidth > textWidth ? barWidth : textWidth) + boxMargin * 2;
|
||||
const int boxHeight = renderer.getLineHeight(UI_12_FONT_ID) + barHeight + boxMargin * 3;
|
||||
const int boxX = (renderer.getScreenWidth() - boxWidth) / 2;
|
||||
constexpr int boxY = 50;
|
||||
const int barX = boxX + (boxWidth - barWidth) / 2;
|
||||
const int barY = boxY + renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2;
|
||||
|
||||
// Draw initial progress box
|
||||
renderer.fillRect(boxX, boxY, boxWidth, boxHeight, false);
|
||||
renderer.drawText(UI_12_FONT_ID, boxX + boxMargin, boxY + boxMargin, "Indexing...");
|
||||
renderer.drawRect(boxX + 5, boxY + 5, boxWidth - 10, boxHeight - 10);
|
||||
renderer.drawRect(barX, barY, barWidth, barHeight);
|
||||
renderer.displayBuffer();
|
||||
UITheme::drawPopup(renderer, "Indexing...");
|
||||
|
||||
while (offset < fileSize) {
|
||||
std::vector<std::string> tempLines;
|
||||
@ -250,17 +232,6 @@ void TxtReaderActivity::buildPageIndex() {
|
||||
pageOffsets.push_back(offset);
|
||||
}
|
||||
|
||||
// Update progress bar every 10% (matching EpubReaderActivity logic)
|
||||
int progressPercent = (offset * 100) / fileSize;
|
||||
if (lastProgressPercent / 10 != progressPercent / 10) {
|
||||
lastProgressPercent = progressPercent;
|
||||
|
||||
// Fill progress bar
|
||||
const int fillWidth = (barWidth - 2) * progressPercent / 100;
|
||||
renderer.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, true);
|
||||
renderer.displayBuffer(HalDisplay::FAST_REFRESH);
|
||||
}
|
||||
|
||||
// Yield to other tasks periodically
|
||||
if (pageOffsets.size() % 20 == 0) {
|
||||
vTaskDelay(1);
|
||||
@ -404,9 +375,6 @@ void TxtReaderActivity::renderScreen() {
|
||||
|
||||
// Initialize reader if not done
|
||||
if (!initialized) {
|
||||
renderer.clearScreen();
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 300, "Indexing...", true, EpdFontFamily::BOLD);
|
||||
renderer.displayBuffer();
|
||||
initializeReader();
|
||||
}
|
||||
|
||||
|
||||
@ -150,8 +150,11 @@ void XtcReaderChapterSelectionActivity::renderScreen() {
|
||||
renderer.drawText(UI_10_FONT_ID, 20, 60 + (i % pageItems) * 30, title, i != selectorIndex);
|
||||
}
|
||||
|
||||
// Skip button hints in landscape CW mode (they overlap content)
|
||||
if (renderer.getOrientation() != GfxRenderer::LandscapeClockwise) {
|
||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");
|
||||
UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
}
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ void UITheme::drawBattery(const GfxRenderer& renderer, Rect rect, bool showPerce
|
||||
}
|
||||
}
|
||||
|
||||
void UITheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
void UITheme::drawButtonHints(GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
const char* btn4) {
|
||||
if (currentTheme != nullptr) {
|
||||
currentTheme->drawButtonHints(renderer, btn1, btn2, btn3, btn4);
|
||||
@ -113,17 +113,17 @@ void UITheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount,
|
||||
}
|
||||
}
|
||||
|
||||
void UITheme::drawPopup(GfxRenderer& renderer, const char* message) {
|
||||
Rect UITheme::drawPopup(const GfxRenderer& renderer, const char* message) {
|
||||
if (currentTheme != nullptr) {
|
||||
currentTheme->drawPopup(renderer, message);
|
||||
return currentTheme->drawPopup(renderer, message);
|
||||
}
|
||||
return Rect{0, 0, 0, 0};
|
||||
}
|
||||
|
||||
PopupCallbacks UITheme::drawPopupWithProgress(GfxRenderer& renderer, const std::string& title) {
|
||||
void UITheme::fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress) {
|
||||
if (currentTheme != nullptr) {
|
||||
return currentTheme->drawPopupWithProgress(renderer, title);
|
||||
currentTheme->fillPopupProgress(renderer, layout, progress);
|
||||
}
|
||||
return PopupCallbacks{};
|
||||
}
|
||||
|
||||
void UITheme::drawBookProgressBar(const GfxRenderer& renderer, const size_t bookProgress) {
|
||||
|
||||
@ -74,7 +74,7 @@ class UITheme {
|
||||
|
||||
static void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total);
|
||||
static void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true);
|
||||
static void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
static void drawButtonHints(GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
const char* btn4);
|
||||
static void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn);
|
||||
static void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
|
||||
@ -89,7 +89,7 @@ class UITheme {
|
||||
static void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
|
||||
const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
|
||||
const std::function<std::string(int index)>& rowIcon);
|
||||
static void drawPopup(GfxRenderer& renderer, const char* message);
|
||||
static PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, const std::string& title);
|
||||
static Rect drawPopup(const GfxRenderer& renderer, const char* message);
|
||||
static void fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress);
|
||||
static void drawBookProgressBar(const GfxRenderer& renderer, const size_t bookProgress);
|
||||
};
|
||||
@ -75,11 +75,10 @@ void BaseTheme::drawProgressBar(const GfxRenderer& renderer, Rect rect, const si
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, rect.y + rect.height + 15, percentText.c_str());
|
||||
}
|
||||
|
||||
void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
void BaseTheme::drawButtonHints(GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
const char* btn4) {
|
||||
// TODO: Fix rotated hints
|
||||
// const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
|
||||
// renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
||||
const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
|
||||
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
||||
|
||||
const int pageHeight = renderer.getScreenHeight();
|
||||
constexpr int buttonWidth = 106;
|
||||
@ -101,7 +100,7 @@ void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
|
||||
}
|
||||
}
|
||||
|
||||
// renderer.setOrientation(orig_orientation);
|
||||
renderer.setOrientation(orig_orientation);
|
||||
}
|
||||
|
||||
void BaseTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) {
|
||||
@ -584,60 +583,36 @@ void BaseTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTheme::drawPopup(GfxRenderer& renderer, const char* message) {
|
||||
Rect BaseTheme::drawPopup(const GfxRenderer& renderer, const char* message) {
|
||||
constexpr int margin = 15;
|
||||
constexpr int y = 60;
|
||||
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::BOLD);
|
||||
constexpr int margin = 20;
|
||||
const int x = (renderer.getScreenWidth() - textWidth - margin * 2) / 2;
|
||||
constexpr int y = 117;
|
||||
const int textHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
||||
const int w = textWidth + margin * 2;
|
||||
const int h = renderer.getLineHeight(UI_12_FONT_ID) + margin * 2;
|
||||
// renderer.clearScreen();
|
||||
renderer.fillRect(x - 5, y - 5, w + 10, h + 10, true);
|
||||
renderer.fillRect(x + 5, y + 5, w - 10, h - 10, false);
|
||||
renderer.drawText(UI_12_FONT_ID, x + margin, y + margin, message, true, EpdFontFamily::BOLD);
|
||||
const int h = textHeight + margin * 2;
|
||||
const int x = (renderer.getScreenWidth() - w) / 2;
|
||||
|
||||
renderer.fillRect(x - 2, y - 2, w + 4, h + 4, true); // frame thickness 2
|
||||
renderer.fillRect(x, y, w, h, false);
|
||||
|
||||
const int textX = x + (w - textWidth) / 2;
|
||||
const int textY = y + margin - 2;
|
||||
renderer.drawText(UI_12_FONT_ID, textX, textY, message, true, EpdFontFamily::BOLD);
|
||||
renderer.displayBuffer();
|
||||
return Rect{x, y, w, h};
|
||||
}
|
||||
|
||||
PopupCallbacks BaseTheme::drawPopupWithProgress(GfxRenderer& renderer, const std::string& title) {
|
||||
// Progress bar dimensions
|
||||
constexpr int barWidth = 200;
|
||||
constexpr int barHeight = 10;
|
||||
constexpr int boxMargin = 20;
|
||||
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, title.c_str());
|
||||
const int boxWidthWithBar = (barWidth > textWidth ? barWidth : textWidth) + boxMargin * 2;
|
||||
const int boxWidthNoBar = textWidth + boxMargin * 2;
|
||||
const int boxHeightWithBar = renderer.getLineHeight(UI_12_FONT_ID) + barHeight + boxMargin * 3;
|
||||
const int boxHeightNoBar = renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2;
|
||||
const int boxXWithBar = (renderer.getScreenWidth() - boxWidthWithBar) / 2;
|
||||
const int boxXNoBar = (renderer.getScreenWidth() - boxWidthNoBar) / 2;
|
||||
constexpr int boxY = 50;
|
||||
const int barX = boxXWithBar + (boxWidthWithBar - barWidth) / 2;
|
||||
const int barY = boxY + renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2;
|
||||
void BaseTheme::fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress) {
|
||||
constexpr int barHeight = 4;
|
||||
const int barWidth = layout.width - 30; // twice the margin in drawPopup to match text width
|
||||
const int barX = layout.x + (layout.width - barWidth) / 2;
|
||||
const int barY = layout.y + layout.height - 10;
|
||||
|
||||
// Always show title text first
|
||||
renderer.fillRect(boxXNoBar, boxY, boxWidthNoBar, boxHeightNoBar, false);
|
||||
renderer.drawText(UI_12_FONT_ID, boxXNoBar + boxMargin, boxY + boxMargin, title.c_str());
|
||||
renderer.drawRect(boxXNoBar + 5, boxY + 5, boxWidthNoBar - 10, boxHeightNoBar - 10);
|
||||
renderer.displayBuffer();
|
||||
int fillWidth = barWidth * progress / 100;
|
||||
|
||||
// Setup callback - only called for chapters >= 50KB, redraws with progress bar
|
||||
auto setup = [this, &renderer, boxXWithBar, boxWidthWithBar, boxHeightWithBar, boxMargin, title, barX, barY, barWidth,
|
||||
barHeight, boxY] {
|
||||
renderer.fillRect(boxXWithBar, boxY, boxWidthWithBar, boxHeightWithBar, false);
|
||||
renderer.drawText(UI_12_FONT_ID, boxXWithBar + boxMargin, boxY + boxMargin, title.c_str());
|
||||
renderer.drawRect(boxXWithBar + 5, boxY + 5, boxWidthWithBar - 10, boxHeightWithBar - 10);
|
||||
renderer.drawRect(barX, barY, barWidth, barHeight);
|
||||
renderer.displayBuffer();
|
||||
};
|
||||
renderer.fillRect(barX, barY, fillWidth, barHeight, true);
|
||||
|
||||
// Progress callback to update progress bar
|
||||
auto update = [this, &renderer, barX, barY, barWidth, barHeight](int progress) {
|
||||
const int fillWidth = (barWidth - 2) * progress / 100;
|
||||
renderer.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, true);
|
||||
renderer.displayBuffer(HalDisplay::FAST_REFRESH);
|
||||
};
|
||||
|
||||
return {setup, update};
|
||||
}
|
||||
|
||||
void BaseTheme::drawBookProgressBar(const GfxRenderer& renderer, const size_t bookProgress) {
|
||||
|
||||
@ -45,7 +45,7 @@ class BaseTheme {
|
||||
// Component drawing methods
|
||||
virtual void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total);
|
||||
virtual void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true);
|
||||
virtual void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
virtual void drawButtonHints(GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
const char* btn4);
|
||||
virtual void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn);
|
||||
virtual void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
|
||||
@ -62,7 +62,7 @@ class BaseTheme {
|
||||
virtual void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
|
||||
const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
|
||||
const std::function<std::string(int index)>& rowIcon);
|
||||
virtual void drawPopup(GfxRenderer& renderer, const char* message);
|
||||
virtual PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, const std::string& title);
|
||||
virtual Rect drawPopup(const GfxRenderer& renderer, const char* message);
|
||||
virtual void fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress);
|
||||
virtual void drawBookProgressBar(const GfxRenderer& renderer, const size_t bookProgress);
|
||||
};
|
||||
@ -174,11 +174,10 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
|
||||
}
|
||||
}
|
||||
|
||||
void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
void LyraTheme::drawButtonHints(GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
const char* btn4) {
|
||||
// TODO: Fix rotated hints
|
||||
// const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
|
||||
// renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
||||
const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
|
||||
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
||||
|
||||
const int pageHeight = renderer.getScreenHeight();
|
||||
constexpr int buttonWidth = 80;
|
||||
@ -205,7 +204,7 @@ void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
|
||||
}
|
||||
}
|
||||
|
||||
// renderer.setOrientation(orig_orientation);
|
||||
renderer.setOrientation(orig_orientation);
|
||||
}
|
||||
|
||||
void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) {
|
||||
@ -342,16 +341,21 @@ void LyraTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
|
||||
}
|
||||
}
|
||||
|
||||
void LyraTheme::drawPopup(GfxRenderer& renderer, const char* message) {
|
||||
Rect LyraTheme::drawPopup(const GfxRenderer& renderer, const char* message) {
|
||||
constexpr int margin = 15;
|
||||
constexpr int y = 60;
|
||||
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::REGULAR);
|
||||
constexpr int margin = 20;
|
||||
const int x = (renderer.getScreenWidth() - textWidth - margin * 2) / 2;
|
||||
constexpr int y = 117;
|
||||
const int textHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
||||
const int w = textWidth + margin * 2;
|
||||
const int h = renderer.getLineHeight(UI_12_FONT_ID) + margin * 2;
|
||||
const int h = textHeight + margin * 2;
|
||||
const int x = (renderer.getScreenWidth() - w) / 2;
|
||||
|
||||
renderer.fillRect(x - 5, y - 5, w + 10, h + 10, false);
|
||||
renderer.drawRect(x + 5, y + 5, w - 10, h - 10, true);
|
||||
renderer.drawText(UI_12_FONT_ID, x + margin, y + margin, message, true, EpdFontFamily::REGULAR);
|
||||
renderer.drawRect(x, y, w, h, true);
|
||||
|
||||
const int textX = x + (w - textWidth) / 2;
|
||||
const int textY = y + margin - 2;
|
||||
renderer.drawText(UI_12_FONT_ID, textX, textY, message, true, EpdFontFamily::REGULAR);
|
||||
renderer.displayBuffer();
|
||||
return Rect{x, y, w, h};
|
||||
}
|
||||
@ -22,7 +22,7 @@ constexpr ThemeMetrics values = {.batteryWidth = 16,
|
||||
.scrollBarRightOffset = 5,
|
||||
.homeTopPadding = 56,
|
||||
.homeCoverHeight = 226,
|
||||
.homeCoverTileHeight = 327,
|
||||
.homeCoverTileHeight = 287,
|
||||
.homeRecentBooksCount = 3,
|
||||
.buttonHintsHeight = 40,
|
||||
.sideButtonHintsWidth = 19,
|
||||
@ -42,7 +42,7 @@ class LyraTheme : public BaseTheme {
|
||||
const std::function<std::string(int index)>& rowTitle, bool hasIcon,
|
||||
const std::function<std::string(int index)>& rowIcon, bool hasValue,
|
||||
const std::function<std::string(int index)>& rowValue) override;
|
||||
void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
void drawButtonHints(GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
|
||||
const char* btn4) override;
|
||||
void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) override;
|
||||
void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
|
||||
@ -51,5 +51,5 @@ class LyraTheme : public BaseTheme {
|
||||
void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookWithCover>& recentBooks,
|
||||
const int selectorIndex, bool& coverRendered, bool& coverBufferStored, bool& bufferRestored,
|
||||
std::function<bool()> storeCoverBuffer) override;
|
||||
void drawPopup(GfxRenderer& renderer, const char* message) override;
|
||||
virtual Rect drawPopup(const GfxRenderer& renderer, const char* message) override;
|
||||
};
|
||||
|
||||
15
src/main.cpp
15
src/main.cpp
@ -302,10 +302,22 @@ void setup() {
|
||||
KOREADER_STORE.loadFromFile();
|
||||
UITheme::initialize();
|
||||
|
||||
if (gpio.isWakeupByPowerButton()) {
|
||||
switch (gpio.getWakeupReason()) {
|
||||
case HalGPIO::WakeupReason::PowerButton:
|
||||
// For normal wakeups, verify power button press duration
|
||||
Serial.printf("[%lu] [ ] Verifying power button press duration\n", millis());
|
||||
verifyPowerButtonDuration();
|
||||
break;
|
||||
case HalGPIO::WakeupReason::AfterUSBPower:
|
||||
// If USB power caused a cold boot, go back to sleep
|
||||
Serial.printf("[%lu] [ ] Wakeup reason: After USB Power\n", millis());
|
||||
gpio.startDeepSleep();
|
||||
break;
|
||||
case HalGPIO::WakeupReason::AfterFlash:
|
||||
// After flashing, just proceed to boot
|
||||
case HalGPIO::WakeupReason::Other:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// First serial output only here to avoid timing inconsistencies for power button press duration verification
|
||||
@ -325,7 +337,6 @@ void setup() {
|
||||
// Clear app state to avoid getting into a boot loop if the epub doesn't load
|
||||
const auto path = APP_STATE.openEpubPath;
|
||||
APP_STATE.openEpubPath = "";
|
||||
APP_STATE.lastSleepImage = 0;
|
||||
APP_STATE.saveToFile();
|
||||
onGoToReader(path);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user