diff --git a/lib/EpdFont/SdCardFontRegistry.cpp b/lib/EpdFont/SdCardFontRegistry.cpp index f3eaca3974a..897b03b7d70 100644 --- a/lib/EpdFont/SdCardFontRegistry.cpp +++ b/lib/EpdFont/SdCardFontRegistry.cpp @@ -19,6 +19,26 @@ const SdCardFontFileInfo* SdCardFontFamilyInfo::findClosestReaderSize(const uint const uint8_t style) const { if (files.empty()) return nullptr; + // Collect sizes matching the requested style, sorted ascending. + std::vector sizes; + for (const auto& f : files) { + if (f.style != style) continue; + sizes.push_back(f.pointSize); + } + if (sizes.empty()) return nullptr; + std::sort(sizes.begin(), sizes.end()); + + // When the family provides at least 4 sizes, use ordinal (index-based) + // selection so custom-built font sets (e.g. 10/12/14/16) map SMALL to + // the smallest file, not to a hardcoded 12pt target. + if (sizes.size() >= 4) { + uint8_t idx = fontSizeEnum; + if (idx >= sizes.size()) idx = sizes.size() - 1; + return findFile(sizes[idx], style); + } + + // Fewer sizes than enum slots (e.g. CJK packs with only 2-3 sizes): + // fall back to closest-match against the built-in reader targets. uint8_t target = 14; switch (fontSizeEnum) { case 0: diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index 42009b79920..2a0f8a50ac1 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -1616,6 +1616,30 @@ size_t GfxRenderer::getBufferSize() const { return frameBufferSize; } // unused // void GfxRenderer::grayscaleRevert() const { display.grayscaleRevert(); } +void GfxRenderer::displayGrayscaleBase(HalDisplay::RefreshMode fallback) const { + display.displayGrayscaleBase(fallback, fadingFix); +} + +void GfxRenderer::preconditionGrayscale() const { display.preconditionGrayscale(); } + +void GfxRenderer::preconditionGrayscale(int x, int y, int w, int h) const { + if (w <= 0 || h <= 0) return; + // Rotate the logical rect's opposite corners to physical panel coords; the + // physical bbox stays axis-aligned for all four orientations. + int ax, ay, bx, by; + rotateCoordinates(orientation, x, y, &ax, &ay, panelWidth, panelHeight); + rotateCoordinates(orientation, x + w - 1, y + h - 1, &bx, &by, panelWidth, panelHeight); + int x0 = ax < bx ? ax : bx, x1 = ax > bx ? ax : bx; + int y0 = ay < by ? ay : by, y1 = ay > by ? ay : by; + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 >= panelWidth) x1 = panelWidth - 1; + if (y1 >= panelHeight) y1 = panelHeight - 1; + if (x1 < x0 || y1 < y0) return; + display.preconditionGrayscale(static_cast(x0), static_cast(y0), + static_cast(x1 - x0 + 1), static_cast(y1 - y0 + 1)); +} + void GfxRenderer::copyGrayscaleLsbBuffers() const { display.copyGrayscaleLsbBuffers(frameBuffer); } void GfxRenderer::copyGrayscaleMsbBuffers() const { display.copyGrayscaleMsbBuffers(frameBuffer); } diff --git a/lib/GfxRenderer/GfxRenderer.h b/lib/GfxRenderer/GfxRenderer.h index 9d2b6677d48..c788ac99a54 100644 --- a/lib/GfxRenderer/GfxRenderer.h +++ b/lib/GfxRenderer/GfxRenderer.h @@ -239,6 +239,16 @@ class GfxRenderer { // Grayscale functions void setRenderMode(const RenderMode mode) { this->renderMode = mode; } RenderMode getRenderMode() const { return renderMode; } + // Grayscale preconditioning settle pass (no-op on X4). The rect overload + // takes the gray region in LOGICAL screen coordinates and rotates it to the + // panel; the no-arg overload settles the full frame. Call after the BW base + // frame is displayed and before the grayscale planes are written. + void preconditionGrayscale() const; + void preconditionGrayscale(int x, int y, int w, int h) const; + // Display the framebuffer as the base frame for a grayscale overlay that + // follows (X3: OEM differential base waveform; others: plain display with + // `fallback`). + void displayGrayscaleBase(HalDisplay::RefreshMode fallback = HalDisplay::HALF_REFRESH) const; void copyGrayscaleLsbBuffers() const; void copyGrayscaleMsbBuffers() const; void displayGrayBuffer() const; diff --git a/lib/hal/HalDisplay.cpp b/lib/hal/HalDisplay.cpp index decf378f593..fd1d4063912 100644 --- a/lib/hal/HalDisplay.cpp +++ b/lib/hal/HalDisplay.cpp @@ -80,6 +80,16 @@ void HalDisplay::copyGrayscaleBuffers(const uint8_t* lsbBuffer, const uint8_t* m einkDisplay.copyGrayscaleBuffers(lsbBuffer, msbBuffer); } +void HalDisplay::displayGrayscaleBase(RefreshMode fallback, bool turnOffScreen) { + einkDisplay.displayGrayscaleBase(convertRefreshMode(fallback), turnOffScreen); +} + +void HalDisplay::preconditionGrayscale() { einkDisplay.preconditionGrayscale(); } + +void HalDisplay::preconditionGrayscale(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { + einkDisplay.preconditionGrayscale(x, y, w, h); +} + void HalDisplay::copyGrayscaleLsbBuffers(const uint8_t* lsbBuffer) { einkDisplay.copyGrayscaleLsbBuffers(lsbBuffer); } void HalDisplay::copyGrayscaleMsbBuffers(const uint8_t* msbBuffer) { einkDisplay.copyGrayscaleMsbBuffers(msbBuffer); } diff --git a/lib/hal/HalDisplay.h b/lib/hal/HalDisplay.h index df01360ae67..c0d2c985c5b 100644 --- a/lib/hal/HalDisplay.h +++ b/lib/hal/HalDisplay.h @@ -53,6 +53,19 @@ class HalDisplay { // Access to frame buffer uint8_t* getFrameBuffer() const; + // X3 grayscale preconditioning (OEM "AA-pre-BW(mid)" settle pass), windowed + // to the gray region in physical panel coordinates (no-arg = full frame). + // Call after the BW base frame is displayed and before the grayscale planes + // are written; no-op on X4. See EInkDisplay::preconditionGrayscale. + void preconditionGrayscale(); + void preconditionGrayscale(uint16_t x, uint16_t y, uint16_t w, uint16_t h); + + // Display the framebuffer as the base frame for a grayscale overlay that + // follows. X3 uses the OEM differential base waveform ("AA-pre-BW(mid)"); + // other panels display normally with `fallback` mode (previous behavior). + // Deliberately does NOT force the X3 resync that displayBuffer(HALF) does. + void displayGrayscaleBase(RefreshMode fallback = HALF_REFRESH, bool turnOffScreen = false); + void copyGrayscaleBuffers(const uint8_t* lsbBuffer, const uint8_t* msbBuffer); void copyGrayscaleLsbBuffers(const uint8_t* lsbBuffer); void copyGrayscaleMsbBuffers(const uint8_t* msbBuffer); diff --git a/open-x4-sdk b/open-x4-sdk index 7e0258db3ae..75b892b2cbe 160000 --- a/open-x4-sdk +++ b/open-x4-sdk @@ -1 +1 @@ -Subproject commit 7e0258db3ae929b006748cb8918dd56c3b1dde7e +Subproject commit 75b892b2cbeac6e54d13d5ac5f243f5e7a26a32d diff --git a/src/CrossPointSettings.h b/src/CrossPointSettings.h index 828086a1844..baddadf7786 100644 --- a/src/CrossPointSettings.h +++ b/src/CrossPointSettings.h @@ -57,6 +57,8 @@ class CrossPointSettings { XTC_STATUS_BAR_MODE_COUNT }; + enum STATUS_BAR_CLOCK_MODE { STATUS_BAR_CLOCK_HIDE = 0, STATUS_BAR_CLOCK_RIGHT = 1, STATUS_BAR_CLOCK_LEFT = 2 }; + enum ORIENTATION { PORTRAIT = 0, // 480x800 logical coordinates (current default) LANDSCAPE_CW = 1, // 800x480 logical coordinates, rotated 180° (swap top/bottom) @@ -145,7 +147,7 @@ class CrossPointSettings { uint8_t statusBarBattery = 1; uint8_t xtcStatusBarMode = XTC_STATUS_BAR_HIDE; // Clock display in status bar (X3 only, requires DS3231 RTC) - uint8_t statusBarClock = 0; + uint8_t statusBarClock = STATUS_BAR_CLOCK_HIDE; // Clock UTC offset in quarter-hour steps, biased by 48 so it fits in uint8_t. // Value 48 = UTC+0, 0 = UTC-12:00, 104 = UTC+14:00. // Quarter-hour granularity supports oddball zones like Nepal (+5:45) and Chatham (+12:45). diff --git a/src/SettingsList.h b/src/SettingsList.h index a8696b7ef14..6e9193036f2 100644 --- a/src/SettingsList.h +++ b/src/SettingsList.h @@ -211,8 +211,9 @@ inline std::vector getSettingsList(const SdCardFontRegistry* regist StrId::STR_CUSTOMISE_STATUS_BAR), // Clock entries (web settings only; device UI uses ClockOffsetActivity for the offset). // Range 0..104 = quarter-hour steps from UTC-12:00 to UTC+14:00, biased by 48. - SettingInfo::Toggle(StrId::STR_CLOCK, &CrossPointSettings::statusBarClock, "statusBarClock", - StrId::STR_CUSTOMISE_STATUS_BAR), + SettingInfo::Enum(StrId::STR_CLOCK, &CrossPointSettings::statusBarClock, + {StrId::STR_HIDE, StrId::STR_DIR_LEFT, StrId::STR_DIR_RIGHT}, "statusBarClock", + StrId::STR_CUSTOMISE_STATUS_BAR), SettingInfo::Value(StrId::STR_CLOCK_UTC_OFFSET, &CrossPointSettings::clockUtcOffsetQ, {0, 104, 1}, "clockUtcOffsetQ", StrId::STR_CUSTOMISE_STATUS_BAR), SettingInfo::Enum(StrId::STR_CLOCK_FORMAT, &CrossPointSettings::clockFormat, diff --git a/src/activities/boot_sleep/SleepActivity.cpp b/src/activities/boot_sleep/SleepActivity.cpp index f1ac29b6f8f..ddf7f26f781 100644 --- a/src/activities/boot_sleep/SleepActivity.cpp +++ b/src/activities/boot_sleep/SleepActivity.cpp @@ -253,7 +253,15 @@ void SleepActivity::renderBitmapSleepScreen(Bitmap& bitmap) const { renderer.invertScreen(); } - renderer.displayBuffer(HalDisplay::HALF_REFRESH); + if (hasGreyscale) { + // OEM grayscale pipeline base: on X3 this displays the frame with the + // dedicated "AA-pre-BW(mid)" differential waveform, leaving every pixel + // in the calibrated state the gray nudge refresh expects; on X4 it is a + // plain HALF refresh (previous behavior). + renderer.displayGrayscaleBase(HalDisplay::HALF_REFRESH); + } else { + renderer.displayBuffer(HalDisplay::HALF_REFRESH); + } if (hasGreyscale) { bitmap.rewindToData(); diff --git a/src/activities/reader/XtcReaderActivity.cpp b/src/activities/reader/XtcReaderActivity.cpp index 17c8fcb8727..240bdc58f62 100644 --- a/src/activities/reader/XtcReaderActivity.cpp +++ b/src/activities/reader/XtcReaderActivity.cpp @@ -293,7 +293,19 @@ void XtcReaderActivity::renderPage() { } } - ReaderUtils::displayWithRefreshCycle(renderer, pagesUntilFullRefresh); + if (pagesUntilFullRefresh <= 1) { + // Periodic ghost cleanup: scrub via the normal path, then run the + // settle flavor of the grayscale base pass (DTM planes are equal after + // the display sync, so only the gentle reinforcement cells fire). + renderer.displayBuffer(HalDisplay::HALF_REFRESH); + renderer.preconditionGrayscale(); + pagesUntilFullRefresh = SETTINGS.getRefreshFrequency(); + } else { + // OEM grayscale pipeline base: differential "AA-pre-BW(mid)" update as + // the page turn on X3; plain FAST refresh on X4 (previous behavior). + renderer.displayGrayscaleBase(HalDisplay::FAST_REFRESH); + pagesUntilFullRefresh--; + } // Pass 2: LSB buffer - mark DARK gray only (XTH value 1) // In LUT: 0 bit = apply gray effect, 1 bit = untouched diff --git a/src/activities/settings/StatusBarSettingsActivity.cpp b/src/activities/settings/StatusBarSettingsActivity.cpp index ccfef74e8bf..6f741bbe417 100644 --- a/src/activities/settings/StatusBarSettingsActivity.cpp +++ b/src/activities/settings/StatusBarSettingsActivity.cpp @@ -77,6 +77,9 @@ const StrId titleNames[TITLE_ITEMS] = {StrId::STR_BOOK, StrId::STR_CHAPTER, StrI constexpr int XTC_STATUS_BAR_ITEMS = 3; const StrId xtcStatusBarNames[XTC_STATUS_BAR_ITEMS] = {StrId::STR_HIDE, StrId::STR_BOTTOM, StrId::STR_TOP}; +constexpr int STATUS_BAR_CLOCK_ITEMS = 3; +const StrId statusBarClockNames[STATUS_BAR_CLOCK_ITEMS] = {StrId::STR_HIDE, StrId::STR_DIR_RIGHT, StrId::STR_DIR_LEFT}; + const int verticalPreviewPadding = 50; const int verticalPreviewTextPadding = 40; } // namespace @@ -112,6 +115,10 @@ void StatusBarSettingsActivity::onEnter() { SETTINGS.clockFormat = 0; } + if (SETTINGS.statusBarClock >= STATUS_BAR_CLOCK_ITEMS) { + SETTINGS.statusBarClock = CrossPointSettings::STATUS_BAR_CLOCK_MODE::STATUS_BAR_CLOCK_HIDE; + } + requestUpdate(); } @@ -176,7 +183,7 @@ void StatusBarSettingsActivity::handleSelection() { SETTINGS.xtcStatusBarMode = (SETTINGS.xtcStatusBarMode + 1) % XTC_STATUS_BAR_ITEMS; break; case ITEM_CLOCK: - SETTINGS.statusBarClock = (SETTINGS.statusBarClock + 1) % 2; + SETTINGS.statusBarClock = (SETTINGS.statusBarClock + 1) % STATUS_BAR_CLOCK_ITEMS; break; case ITEM_CLOCK_FORMAT: SETTINGS.clockFormat = (SETTINGS.clockFormat + 1) % CLOCK_FORMAT_ITEMS; @@ -225,7 +232,7 @@ void StatusBarSettingsActivity::render(RenderLock&&) { case ITEM_XTC_STATUS_BAR: return I18N.get(xtcStatusBarNames[SETTINGS.xtcStatusBarMode]); case ITEM_CLOCK: - return SETTINGS.statusBarClock ? tr(STR_SHOW) : tr(STR_HIDE); + return I18N.get(statusBarClockNames[SETTINGS.statusBarClock]); case ITEM_CLOCK_FORMAT: { const uint8_t fmt = SETTINGS.clockFormat < CLOCK_FORMAT_ITEMS ? SETTINGS.clockFormat : 0; return std::string(I18N.get(clockFormatNames[fmt])); diff --git a/src/components/UITheme.cpp b/src/components/UITheme.cpp index 979602caf4e..59cb23857c9 100644 --- a/src/components/UITheme.cpp +++ b/src/components/UITheme.cpp @@ -131,9 +131,10 @@ int UITheme::getStatusBarHeight() { const ThemeMetrics& metrics = UITheme::getInstance().getMetrics(); // Add status bar margin - const bool showStatusBar = SETTINGS.statusBarChapterPageCount || SETTINGS.statusBarBookProgressPercentage || - SETTINGS.statusBarTitle != CrossPointSettings::STATUS_BAR_TITLE::HIDE_TITLE || - SETTINGS.statusBarBattery; + const bool showStatusBar = + SETTINGS.statusBarChapterPageCount || SETTINGS.statusBarBookProgressPercentage || + SETTINGS.statusBarTitle != CrossPointSettings::STATUS_BAR_TITLE::HIDE_TITLE || SETTINGS.statusBarBattery || + SETTINGS.statusBarClock != CrossPointSettings::STATUS_BAR_CLOCK_MODE::STATUS_BAR_CLOCK_HIDE; const bool showProgressBar = SETTINGS.statusBarProgressBar != CrossPointSettings::STATUS_BAR_PROGRESS_BAR::HIDE_PROGRESS; return (showStatusBar ? (metrics.statusBarVerticalMargin) : 0) + diff --git a/src/components/themes/BaseTheme.cpp b/src/components/themes/BaseTheme.cpp index e2908d61aa7..6343252a45d 100644 --- a/src/components/themes/BaseTheme.cpp +++ b/src/components/themes/BaseTheme.cpp @@ -756,7 +756,11 @@ void BaseTheme::drawStatusBar(GfxRenderer& renderer, const float bookProgress, c // Draw Progress Text const auto screenHeight = renderer.getScreenHeight(); auto textY = screenHeight - UITheme::getInstance().getStatusBarHeight() - margins.bottom - paddingBottom - 4; - int progressTextWidth = 0; + + const int leftClusterX = metrics.statusBarHorizontalMargin + margins.left + 1; + const int rightClusterX = renderer.getScreenWidth() - metrics.statusBarHorizontalMargin - margins.right; + int leftClusterWidth = 0; + int rightClusterWidth = 0; if (SETTINGS.statusBarBookProgressPercentage || SETTINGS.statusBarChapterPageCount) { // Right aligned text for progress counter @@ -770,10 +774,10 @@ void BaseTheme::drawStatusBar(GfxRenderer& renderer, const float bookProgress, c snprintf(progressStr, sizeof(progressStr), "%d/%d", currentPage, pageCount); } - progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progressStr); - renderer.drawText(SMALL_FONT_ID, - renderer.getScreenWidth() - metrics.statusBarHorizontalMargin - margins.right - progressTextWidth, - textY, progressStr); + int progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progressStr); + renderer.drawText(SMALL_FONT_ID, rightClusterX - progressTextWidth, textY, progressStr); + + rightClusterWidth += progressTextWidth; } // Draw Progress Bar @@ -796,34 +800,46 @@ void BaseTheme::drawStatusBar(GfxRenderer& renderer, const float bookProgress, c } // Draw Bookmark - const int leftClusterX = metrics.statusBarHorizontalMargin + margins.left + 1; - const bool showBookmarkIcon = showStatusBarTextLane && isPageBookmarked; - const int bookmarkReserveWidth = showBookmarkIcon ? (bookmarkStatusIconWidth + bookmarkStatusIconGap) : 0; - if (showBookmarkIcon) { + if (showStatusBarTextLane && isPageBookmarked) { const int bookmarkY = textY + 5; drawBookmarkStatusIcon(renderer, leftClusterX, bookmarkY); + leftClusterWidth += bookmarkStatusIconWidth + bookmarkStatusIconGap; } // Draw Battery const bool showBatteryPercentage = SETTINGS.hideBatteryPercentage == CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_NEVER; - int leftClusterWidth = bookmarkReserveWidth; + if (SETTINGS.statusBarBattery) { GUI.drawBatteryLeft(renderer, - Rect{leftClusterX + bookmarkReserveWidth, textY, metrics.batteryWidth, metrics.batteryHeight}, + Rect{leftClusterX + leftClusterWidth, textY, metrics.batteryWidth, metrics.batteryHeight}, showBatteryPercentage); - leftClusterWidth += showBatteryPercentage ? 50 : 20; + int batteryWidth = metrics.batteryWidth; + + if (showBatteryPercentage) { + const uint16_t percentage = halPowerManager.getBatteryPercentage(); + // width of icon + spacing + text for layout purposes + batteryWidth += + batteryPercentSpacing + renderer.getTextWidth(SMALL_FONT_ID, (std::to_string(percentage) + "%").c_str()); + } + + leftClusterWidth += batteryWidth; } // Draw Clock (X3 only — DS3231 RTC) - int clockTextWidth = 0; if (SETTINGS.statusBarClock && halClock.isAvailable()) { char timeBuf[9]; if (halClock.formatTime(timeBuf, sizeof(timeBuf), SETTINGS.clockUtcOffsetQ, SETTINGS.clockFormat == 1)) { - clockTextWidth = renderer.getTextWidth(SMALL_FONT_ID, timeBuf); - // Position to the left of the progress text (with a small gap) - const int clockX = renderer.getScreenWidth() - metrics.statusBarHorizontalMargin - margins.right - - progressTextWidth - (progressTextWidth > 0 ? 10 : 0) - clockTextWidth; + int clockTextWidth = renderer.getTextWidth(SMALL_FONT_ID, timeBuf); + int clockX = 0; + // Position to the left or right of the progress text (with a small gap) + if (SETTINGS.statusBarClock == CrossPointSettings::STATUS_BAR_CLOCK_LEFT) { + clockX = leftClusterX + leftClusterWidth + (leftClusterWidth > 0 ? 10 : 0); + leftClusterWidth += clockTextWidth + 10; + } else if (SETTINGS.statusBarClock == CrossPointSettings::STATUS_BAR_CLOCK_RIGHT) { + clockX = rightClusterX - rightClusterWidth - (rightClusterWidth > 0 ? 10 : 0) - clockTextWidth; + rightClusterWidth += clockTextWidth + 10; + } renderer.drawText(SMALL_FONT_ID, clockX, textY, timeBuf); } } @@ -837,8 +853,7 @@ void BaseTheme::drawStatusBar(GfxRenderer& renderer, const float bookProgress, c renderer.getScreenWidth() - (metrics.statusBarHorizontalMargin * 2) - margins.left - margins.right; const int titleMarginLeft = leftClusterWidth + 30; - const int clockReserve = clockTextWidth > 0 ? (clockTextWidth + 10) : 0; - const int titleMarginRight = progressTextWidth + clockReserve + 30; + const int titleMarginRight = rightClusterWidth + 30; // Attempt to center title on the screen, but if title is too wide then later we will center it within the // available space.