Add user-toggleable setting to turn off display between refreshes, which helps mitigate the sunlight fading issue on e-ink displays. Changes: - Add turnOffScreen parameter to HalDisplay methods - Add fadingFix member and setFadingFix() to GfxRenderer - Add fadingFix setting to CrossPointSettings with persistence - Add "Sunlight Fading Fix" toggle in Display settings - Update SDK submodule with turnOffScreen support
256 lines
10 KiB
C++
256 lines
10 KiB
C++
#include "SettingsActivity.h"
|
|
|
|
#include <GfxRenderer.h>
|
|
#include <HardwareSerial.h>
|
|
#include <builtinFonts/custom/customFonts.h>
|
|
|
|
#include "CategorySettingsActivity.h"
|
|
#include "CrossPointSettings.h"
|
|
#include "MappedInputManager.h"
|
|
#include "fontIds.h"
|
|
|
|
const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "System"};
|
|
|
|
namespace {
|
|
// Visibility condition for bezel edge setting (only show when compensation > 0)
|
|
bool isBezelCompensationEnabled() { return SETTINGS.bezelCompensation > 0; }
|
|
|
|
constexpr int displaySettingsCount = 10;
|
|
const SettingInfo displaySettings[displaySettingsCount] = {
|
|
// Should match with SLEEP_SCREEN_MODE
|
|
SettingInfo::Enum("Sleep Screen", &CrossPointSettings::sleepScreen, {"Dark", "Light", "Custom", "Cover", "None"}),
|
|
SettingInfo::Enum("Sleep Screen Cover Mode", &CrossPointSettings::sleepScreenCoverMode, {"Fit", "Crop", "Actual"}),
|
|
SettingInfo::Enum("Sleep Screen Cover Filter", &CrossPointSettings::sleepScreenCoverFilter,
|
|
{"None", "Contrast", "Inverted"}),
|
|
SettingInfo::Toggle("High Contrast", &CrossPointSettings::displayContrast),
|
|
SettingInfo::Enum("Status Bar", &CrossPointSettings::statusBar,
|
|
{"None", "No Progress", "Full w/ Percentage", "Full w/ Progress Bar", "Progress Bar"}),
|
|
SettingInfo::Enum("Hide Battery %", &CrossPointSettings::hideBatteryPercentage, {"Never", "In Reader", "Always"}),
|
|
SettingInfo::Enum("Refresh Frequency", &CrossPointSettings::refreshFrequency,
|
|
{"1 page", "5 pages", "10 pages", "15 pages", "30 pages"}),
|
|
SettingInfo::Enum("Sunlight Fading Fix", &CrossPointSettings::fadingFix, {"OFF", "ON"}),
|
|
SettingInfo::Value("Bezel Compensation", &CrossPointSettings::bezelCompensation, {0, 10, 1}),
|
|
SettingInfo::Enum("Bezel Edge", &CrossPointSettings::bezelCompensationEdge, {"Bottom", "Top", "Left", "Right"},
|
|
isBezelCompensationEnabled)};
|
|
|
|
// Helper to get custom font names as a vector
|
|
std::vector<std::string> getCustomFontNamesVector() {
|
|
std::vector<std::string> names;
|
|
#if CUSTOM_FONT_COUNT > 0
|
|
for (int i = 0; i < CUSTOM_FONT_COUNT; i++) {
|
|
names.push_back(CUSTOM_FONT_NAMES[i]);
|
|
}
|
|
#else
|
|
names.push_back("(none)"); // Placeholder when no custom fonts
|
|
#endif
|
|
return names;
|
|
}
|
|
|
|
// Visibility condition for custom font settings
|
|
bool isCustomFontSelected() { return SETTINGS.fontFamily == CrossPointSettings::CUSTOM_FONT; }
|
|
|
|
// Font family options - includes "Custom" only if custom fonts are available
|
|
std::vector<std::string> getFontFamilyOptions() {
|
|
std::vector<std::string> options = {"Bookerly", "Noto Sans"};
|
|
#if CUSTOM_FONT_COUNT > 0
|
|
options.push_back("Custom");
|
|
#endif
|
|
return options;
|
|
}
|
|
|
|
constexpr int readerSettingsCount = 11;
|
|
const SettingInfo readerSettings[readerSettingsCount] = {
|
|
SettingInfo::Enum("Font Family", &CrossPointSettings::fontFamily, getFontFamilyOptions()),
|
|
SettingInfo::Enum("Custom Font", &CrossPointSettings::customFontIndex, getCustomFontNamesVector(),
|
|
isCustomFontSelected),
|
|
SettingInfo::Enum("Fallback Font", &CrossPointSettings::fallbackFontFamily, {"Bookerly", "Noto Sans"},
|
|
isCustomFontSelected),
|
|
SettingInfo::Enum("Font Size", &CrossPointSettings::fontSize, {"Small", "Medium", "Large", "X Large"}),
|
|
SettingInfo::Enum("Line Spacing", &CrossPointSettings::lineSpacing, {"Tight", "Normal", "Wide"}),
|
|
SettingInfo::Value("Screen Margin", &CrossPointSettings::screenMargin, {5, 40, 5}),
|
|
SettingInfo::Enum("Paragraph Alignment", &CrossPointSettings::paragraphAlignment,
|
|
{"Justify", "Left", "Center", "Right"}),
|
|
SettingInfo::Toggle("Hyphenation", &CrossPointSettings::hyphenationEnabled),
|
|
SettingInfo::Enum("Reading Orientation", &CrossPointSettings::orientation,
|
|
{"Portrait", "Landscape CW", "Inverted", "Landscape CCW"}),
|
|
SettingInfo::Toggle("Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing),
|
|
SettingInfo::Toggle("Text Anti-Aliasing", &CrossPointSettings::textAntiAliasing)};
|
|
|
|
constexpr int controlsSettingsCount = 4;
|
|
const SettingInfo controlsSettings[controlsSettingsCount] = {
|
|
SettingInfo::Enum(
|
|
"Front Button Layout", &CrossPointSettings::frontButtonLayout,
|
|
{"Bck, Cnfrm, Lft, Rght", "Lft, Rght, Bck, Cnfrm", "Lft, Bck, Cnfrm, Rght", "Bck, Cnfrm, Rght, Lft"}),
|
|
SettingInfo::Enum("Side Button Layout (reader)", &CrossPointSettings::sideButtonLayout,
|
|
{"Prev, Next", "Next, Prev"}),
|
|
SettingInfo::Toggle("Long-press Chapter Skip", &CrossPointSettings::longPressChapterSkip),
|
|
SettingInfo::Enum("Short Power Button Click", &CrossPointSettings::shortPwrBtn,
|
|
{"Ignore", "Sleep", "Page Turn", "Dictionary", "Quick Menu"})};
|
|
|
|
constexpr int systemSettingsCount = 4;
|
|
const SettingInfo systemSettings[systemSettingsCount] = {
|
|
SettingInfo::Enum("Time to Sleep", &CrossPointSettings::sleepTimeout,
|
|
{"1 min", "5 min", "10 min", "15 min", "30 min"}),
|
|
SettingInfo::Action("Calibre Settings"), SettingInfo::Action("Clear Cache"),
|
|
SettingInfo::Action("Check for updates")};
|
|
} // namespace
|
|
|
|
void SettingsActivity::taskTrampoline(void* param) {
|
|
auto* self = static_cast<SettingsActivity*>(param);
|
|
self->displayTaskLoop();
|
|
}
|
|
|
|
void SettingsActivity::onEnter() {
|
|
Activity::onEnter();
|
|
renderingMutex = xSemaphoreCreateMutex();
|
|
|
|
// Reset selection to first category
|
|
selectedCategoryIndex = 0;
|
|
|
|
// Trigger first update
|
|
updateRequired = true;
|
|
|
|
xTaskCreate(&SettingsActivity::taskTrampoline, "SettingsActivityTask",
|
|
4096, // Stack size
|
|
this, // Parameters
|
|
1, // Priority
|
|
&displayTaskHandle // Task handle
|
|
);
|
|
}
|
|
|
|
void SettingsActivity::onExit() {
|
|
ActivityWithSubactivity::onExit();
|
|
|
|
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
|
if (displayTaskHandle) {
|
|
vTaskDelete(displayTaskHandle);
|
|
displayTaskHandle = nullptr;
|
|
vTaskDelay(10 / portTICK_PERIOD_MS); // Let idle task free stack
|
|
}
|
|
vSemaphoreDelete(renderingMutex);
|
|
renderingMutex = nullptr;
|
|
}
|
|
|
|
void SettingsActivity::loop() {
|
|
if (subActivity) {
|
|
subActivity->loop();
|
|
return;
|
|
}
|
|
|
|
// Handle category selection
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
|
enterCategory(selectedCategoryIndex);
|
|
return;
|
|
}
|
|
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
|
|
SETTINGS.saveToFile();
|
|
onGoHome();
|
|
return;
|
|
}
|
|
|
|
// Handle navigation
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Up) ||
|
|
mappedInput.wasPressed(MappedInputManager::Button::Left)) {
|
|
// Move selection up (with wrap-around)
|
|
selectedCategoryIndex = (selectedCategoryIndex > 0) ? (selectedCategoryIndex - 1) : (categoryCount - 1);
|
|
updateRequired = true;
|
|
} else if (mappedInput.wasPressed(MappedInputManager::Button::Down) ||
|
|
mappedInput.wasPressed(MappedInputManager::Button::Right)) {
|
|
// Move selection down (with wrap around)
|
|
selectedCategoryIndex = (selectedCategoryIndex < categoryCount - 1) ? (selectedCategoryIndex + 1) : 0;
|
|
updateRequired = true;
|
|
}
|
|
}
|
|
|
|
void SettingsActivity::enterCategory(int categoryIndex) {
|
|
if (categoryIndex < 0 || categoryIndex >= categoryCount) {
|
|
return;
|
|
}
|
|
|
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
|
exitActivity();
|
|
|
|
const SettingInfo* settingsList = nullptr;
|
|
int settingsCount = 0;
|
|
|
|
switch (categoryIndex) {
|
|
case 0: // Display
|
|
settingsList = displaySettings;
|
|
settingsCount = displaySettingsCount;
|
|
break;
|
|
case 1: // Reader
|
|
settingsList = readerSettings;
|
|
settingsCount = readerSettingsCount;
|
|
break;
|
|
case 2: // Controls
|
|
settingsList = controlsSettings;
|
|
settingsCount = controlsSettingsCount;
|
|
break;
|
|
case 3: // System
|
|
settingsList = systemSettings;
|
|
settingsCount = systemSettingsCount;
|
|
break;
|
|
}
|
|
|
|
enterNewActivity(new CategorySettingsActivity(renderer, mappedInput, categoryNames[categoryIndex], settingsList,
|
|
settingsCount, [this] {
|
|
exitActivity();
|
|
updateRequired = true;
|
|
}));
|
|
xSemaphoreGive(renderingMutex);
|
|
}
|
|
|
|
void SettingsActivity::displayTaskLoop() {
|
|
while (true) {
|
|
if (updateRequired && !subActivity) {
|
|
updateRequired = false;
|
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
|
render();
|
|
xSemaphoreGive(renderingMutex);
|
|
}
|
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
|
}
|
|
}
|
|
|
|
void SettingsActivity::render() const {
|
|
renderer.clearScreen();
|
|
|
|
const auto pageWidth = renderer.getScreenWidth();
|
|
const auto pageHeight = renderer.getScreenHeight();
|
|
|
|
// Bezel compensation offsets
|
|
const int bezelTop = renderer.getBezelOffsetTop();
|
|
const int bezelLeft = renderer.getBezelOffsetLeft();
|
|
const int bezelRight = renderer.getBezelOffsetRight();
|
|
const int bezelBottom = renderer.getBezelOffsetBottom();
|
|
|
|
// Draw header
|
|
renderer.drawCenteredText(UI_12_FONT_ID, 15 + bezelTop, "Settings", true, EpdFontFamily::BOLD);
|
|
|
|
// Draw selection
|
|
renderer.fillRect(bezelLeft, 60 + bezelTop + selectedCategoryIndex * 30 - 2, pageWidth - 1 - bezelLeft - bezelRight,
|
|
30);
|
|
|
|
// Draw all categories
|
|
for (int i = 0; i < categoryCount; i++) {
|
|
const int categoryY = 60 + bezelTop + i * 30; // 30 pixels between categories
|
|
|
|
// Draw category name
|
|
renderer.drawText(UI_10_FONT_ID, 20 + bezelLeft, categoryY, categoryNames[i], i != selectedCategoryIndex);
|
|
}
|
|
|
|
// Draw version text above button hints
|
|
renderer.drawText(SMALL_FONT_ID,
|
|
pageWidth - 20 - bezelRight - renderer.getTextWidth(SMALL_FONT_ID, CROSSPOINT_VERSION),
|
|
pageHeight - 60 - bezelBottom, CROSSPOINT_VERSION);
|
|
|
|
// Draw help text
|
|
const auto labels = mappedInput.mapLabels("« Back", "Select", "", "");
|
|
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
|
|
|
// Always use standard refresh for settings screen
|
|
renderer.displayBuffer();
|
|
}
|