2026-02-01 08:34:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include <Epub.h>
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
2026-02-13 16:07:38 -05:00
|
|
|
#include "util/BookSettings.h"
|
2026-02-09 15:19:34 +06:00
|
|
|
#include "util/ButtonNavigator.h"
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
|
|
|
|
public:
|
2026-02-05 15:17:51 +03:00
|
|
|
// Menu actions available from the reader menu.
|
2026-02-12 19:36:14 -05:00
|
|
|
enum class MenuAction {
|
|
|
|
|
ADD_BOOKMARK,
|
2026-02-12 20:40:07 -05:00
|
|
|
REMOVE_BOOKMARK,
|
2026-02-12 19:36:14 -05:00
|
|
|
LOOKUP,
|
|
|
|
|
LOOKED_UP_WORDS,
|
|
|
|
|
ROTATE_SCREEN,
|
2026-02-13 16:07:38 -05:00
|
|
|
LETTERBOX_FILL,
|
2026-02-12 19:36:14 -05:00
|
|
|
SELECT_CHAPTER,
|
|
|
|
|
GO_TO_BOOKMARK,
|
|
|
|
|
GO_TO_PERCENT,
|
|
|
|
|
GO_HOME,
|
|
|
|
|
SYNC,
|
|
|
|
|
DELETE_CACHE,
|
|
|
|
|
DELETE_DICT_CACHE
|
|
|
|
|
};
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
2026-02-05 15:17:51 +03:00
|
|
|
const int currentPage, const int totalPages, const int bookProgressPercent,
|
2026-02-12 19:36:14 -05:00
|
|
|
const uint8_t currentOrientation, const bool hasDictionary,
|
2026-02-13 16:07:38 -05:00
|
|
|
const bool isBookmarked, const std::string& bookCachePath,
|
2026-02-12 19:36:14 -05:00
|
|
|
const std::function<void(uint8_t)>& onBack,
|
2026-02-05 14:53:35 +03:00
|
|
|
const std::function<void(MenuAction)>& onAction)
|
2026-02-01 08:34:30 +01:00
|
|
|
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
2026-02-12 20:40:07 -05:00
|
|
|
menuItems(buildMenuItems(hasDictionary, isBookmarked)),
|
2026-02-01 08:34:30 +01:00
|
|
|
title(title),
|
2026-02-05 14:53:35 +03:00
|
|
|
pendingOrientation(currentOrientation),
|
2026-02-13 16:07:38 -05:00
|
|
|
bookCachePath(bookCachePath),
|
2026-02-05 15:17:51 +03:00
|
|
|
currentPage(currentPage),
|
|
|
|
|
totalPages(totalPages),
|
|
|
|
|
bookProgressPercent(bookProgressPercent),
|
2026-02-01 08:34:30 +01:00
|
|
|
onBack(onBack),
|
2026-02-13 16:07:38 -05:00
|
|
|
onAction(onAction) {
|
|
|
|
|
// Load per-book settings to initialize the letterbox fill override
|
|
|
|
|
auto bookSettings = BookSettings::load(bookCachePath);
|
|
|
|
|
pendingLetterboxFill = bookSettings.letterboxFillOverride;
|
|
|
|
|
}
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
|
void onExit() override;
|
|
|
|
|
void loop() override;
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
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**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
void render(Activity::RenderLock&&) override;
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct MenuItem {
|
|
|
|
|
MenuAction action;
|
|
|
|
|
std::string label;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-12 19:36:14 -05:00
|
|
|
std::vector<MenuItem> menuItems;
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
int selectedIndex = 0;
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
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**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
|
2026-02-09 15:19:34 +06:00
|
|
|
ButtonNavigator buttonNavigator;
|
2026-02-01 08:34:30 +01:00
|
|
|
std::string title = "Reader Menu";
|
2026-02-05 14:53:35 +03:00
|
|
|
uint8_t pendingOrientation = 0;
|
|
|
|
|
const std::vector<const char*> orientationLabels = {"Portrait", "Landscape CW", "Inverted", "Landscape CCW"};
|
2026-02-13 16:07:38 -05:00
|
|
|
std::string bookCachePath;
|
|
|
|
|
// Letterbox fill override: 0xFF = Default (use global), 0 = Dithered, 1 = Solid, 2 = None
|
|
|
|
|
uint8_t pendingLetterboxFill = BookSettings::USE_GLOBAL;
|
|
|
|
|
static constexpr int LETTERBOX_FILL_OPTION_COUNT = 4; // Default + 3 modes
|
|
|
|
|
const std::vector<const char*> letterboxFillLabels = {"Default", "Dithered", "Solid", "None"};
|
2026-02-05 15:17:51 +03:00
|
|
|
int currentPage = 0;
|
|
|
|
|
int totalPages = 0;
|
|
|
|
|
int bookProgressPercent = 0;
|
2026-02-01 08:34:30 +01:00
|
|
|
|
2026-02-05 14:53:35 +03:00
|
|
|
const std::function<void(uint8_t)> onBack;
|
2026-02-01 08:34:30 +01:00
|
|
|
const std::function<void(MenuAction)> onAction;
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
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**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
<<<<<<< HEAD
|
2026-02-01 08:34:30 +01:00
|
|
|
|
2026-02-13 16:07:38 -05:00
|
|
|
// Map the internal override value to an index into letterboxFillLabels.
|
|
|
|
|
int letterboxFillToIndex() const {
|
|
|
|
|
if (pendingLetterboxFill == BookSettings::USE_GLOBAL) return 0; // "Default"
|
|
|
|
|
return pendingLetterboxFill + 1; // 0->1 (Dithered), 1->2 (Solid), 2->3 (None)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Map an index from letterboxFillLabels back to an override value.
|
|
|
|
|
static uint8_t indexToLetterboxFill(int index) {
|
|
|
|
|
if (index == 0) return BookSettings::USE_GLOBAL;
|
|
|
|
|
return static_cast<uint8_t>(index - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save the current letterbox fill override to the book's settings file.
|
|
|
|
|
void saveLetterboxFill() const {
|
|
|
|
|
auto bookSettings = BookSettings::load(bookCachePath);
|
|
|
|
|
bookSettings.letterboxFillOverride = pendingLetterboxFill;
|
|
|
|
|
BookSettings::save(bookCachePath, bookSettings);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 20:40:07 -05:00
|
|
|
static std::vector<MenuItem> buildMenuItems(bool hasDictionary, bool isBookmarked) {
|
2026-02-12 19:36:14 -05:00
|
|
|
std::vector<MenuItem> items;
|
2026-02-12 20:40:07 -05:00
|
|
|
if (isBookmarked) {
|
|
|
|
|
items.push_back({MenuAction::REMOVE_BOOKMARK, "Remove Bookmark"});
|
|
|
|
|
} else {
|
|
|
|
|
items.push_back({MenuAction::ADD_BOOKMARK, "Add Bookmark"});
|
|
|
|
|
}
|
2026-02-12 19:36:14 -05:00
|
|
|
if (hasDictionary) {
|
|
|
|
|
items.push_back({MenuAction::LOOKUP, "Lookup Word"});
|
|
|
|
|
items.push_back({MenuAction::LOOKED_UP_WORDS, "Lookup Word History"});
|
|
|
|
|
}
|
|
|
|
|
items.push_back({MenuAction::ROTATE_SCREEN, "Reading Orientation"});
|
2026-02-13 16:07:38 -05:00
|
|
|
items.push_back({MenuAction::LETTERBOX_FILL, "Letterbox Fill"});
|
2026-02-12 19:36:14 -05:00
|
|
|
items.push_back({MenuAction::SELECT_CHAPTER, "Table of Contents"});
|
|
|
|
|
items.push_back({MenuAction::GO_TO_BOOKMARK, "Go to Bookmark"});
|
|
|
|
|
items.push_back({MenuAction::GO_TO_PERCENT, "Go to %"});
|
|
|
|
|
items.push_back({MenuAction::GO_HOME, "Close Book"});
|
|
|
|
|
items.push_back({MenuAction::SYNC, "Sync Progress"});
|
|
|
|
|
items.push_back({MenuAction::DELETE_CACHE, "Delete Book Cache"});
|
|
|
|
|
if (hasDictionary) {
|
|
|
|
|
items.push_back({MenuAction::DELETE_DICT_CACHE, "Delete Dictionary Cache"});
|
|
|
|
|
}
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 08:34:30 +01:00
|
|
|
};
|