Files
crosspoint-reader-mod/chat-summaries/2026-02-15_20-30-summary.md

40 lines
2.4 KiB
Markdown
Raw Normal View History

# Adjust Low Power Mode: Fix Processing Bug and Sync with PR #852
**Date:** 2026-02-15
**Branch:** mod/adjust-low-power-mode
## Task
Fix a bug where the device enters low-power mode (10MHz CPU) during first-time book opening and chapter indexing, causing significant slowdown. Also sync minor logging differences with upstream PR #852.
## Root Causes (three issues combined)
1. **Missing delegation in ActivityWithSubactivity**: `main.cpp` calls `preventAutoSleep()` on `ReaderActivity` (the top-level activity). `ReaderActivity` creates `EpubReaderActivity` as a subactivity, but `ActivityWithSubactivity` never delegated `preventAutoSleep()` or `skipLoopDelay()` to the active subactivity.
2. **Stale check across activity transitions**: The `preventAutoSleep()` check at the top of the main loop runs before `loop()`. When an activity transitions mid-loop (HomeActivity -> ReaderActivity), the pre-loop check is stale but the post-loop power-saving decision fires.
3. **Section object vs section file**: `!section` alone was insufficient as a condition. The Section object is created early in the `!section` block, making `section` non-null, but `createSectionFile()` (the slow operation) runs afterward. A separate `loadingSection` flag is needed to cover the full duration.
## Changes Made
1. **ActivityWithSubactivity** (`src/activities/ActivityWithSubactivity.h`)
- Added `preventAutoSleep()` override that delegates to `subActivity->preventAutoSleep()`
- Added `skipLoopDelay()` override with same delegation pattern
2. **main.cpp** (`src/main.cpp`)
- Added a second `preventAutoSleep()` re-check after `currentActivity->loop()` returns, before the power-saving block
3. **EpubReaderActivity** (`src/activities/reader/EpubReaderActivity.h`, `.cpp`)
- Added `volatile bool loadingSection` flag
- `preventAutoSleep()` returns `!section || loadingSection`
- `!section` covers the pre-Section-object period (including cover prerendering in onEnter)
- `loadingSection` covers the full `!section` block in `renderScreen()` where `createSectionFile()` runs
- Flag is also cleared on the error path
4. **TxtReaderActivity** (`src/activities/reader/TxtReaderActivity.h`)
- `preventAutoSleep()` returns `!initialized`
- Covers cover prerendering and page index building
5. **HalPowerManager.cpp** (`lib/hal/HalPowerManager.cpp`)
- Synced log messages with upstream PR: `LOG_ERR` -> `LOG_DBG` with frequency values (matching commit `ff89fb1`)