Reordered boot sequence to load settings in time.

This commit is contained in:
Jonas Diemer 2025-12-18 16:04:34 +01:00
parent 44e2d0e319
commit a9de80d24b

View File

@ -75,20 +75,16 @@ void enterNewActivity(Activity* activity) {
// Verify long press on wake-up from deep sleep // Verify long press on wake-up from deep sleep
void verifyWakeupLongPress() { void verifyWakeupLongPress() {
// Give the user up to 1000ms to start holding the power button, and must hold for SETTINGS.getPowerButtonDuration() // Give the user up to 1000ms to start holding the power button, and must hold for SETTINGS.getPowerButtonDuration()
const auto start = millis(); const auto start = millis();
bool abort = false; bool abort = false;
Serial.printf("[%lu] [ ] Verifying power button press\n", millis());
inputManager.update(); inputManager.update();
// Verify the user has actually pressed
while (!inputManager.isPressed(InputManager::BTN_POWER) && millis() - start < 1000) { while (!inputManager.isPressed(InputManager::BTN_POWER) && millis() - start < 1000) {
delay(50); delay(10); // only wait 10ms each iteration to not delay too much in case of short configured duration.
inputManager.update(); inputManager.update();
} }
// Return immediately if power button duration is less than 100ms
if (SETTINGS.getPowerButtonDuration() < 100) return;
if (inputManager.isPressed(InputManager::BTN_POWER)) { if (inputManager.isPressed(InputManager::BTN_POWER)) {
do { do {
delay(10); delay(10);
@ -156,14 +152,20 @@ void setup() {
Serial.printf("[%lu] [ ] Starting CrossPoint version " CROSSPOINT_VERSION "\n", millis()); Serial.printf("[%lu] [ ] Starting CrossPoint version " CROSSPOINT_VERSION "\n", millis());
inputManager.begin(); inputManager.begin();
// verifyWakeupLongPress();
// Initialize pins // Initialize pins
pinMode(BAT_GPIO0, INPUT); pinMode(BAT_GPIO0, INPUT);
// Initialize SPI with custom pins // Initialize SPI with custom pins
SPI.begin(EPD_SCLK, SD_SPI_MISO, EPD_MOSI, EPD_CS); SPI.begin(EPD_SCLK, SD_SPI_MISO, EPD_MOSI, EPD_CS);
// SD Card Initialization
SD.begin(SD_SPI_CS, SPI, SPI_FQ);
SETTINGS.loadFromFile();
// verify power button press duration after we've read settings.
verifyWakeupLongPress();
// Initialize display // Initialize display
einkDisplay.begin(); einkDisplay.begin();
Serial.printf("[%lu] [ ] Display initialized\n", millis()); Serial.printf("[%lu] [ ] Display initialized\n", millis());
@ -176,10 +178,6 @@ void setup() {
exitActivity(); exitActivity();
enterNewActivity(new BootActivity(renderer, inputManager)); enterNewActivity(new BootActivity(renderer, inputManager));
// SD Card Initialization
SD.begin(SD_SPI_CS, SPI, SPI_FQ);
SETTINGS.loadFromFile();
APP_STATE.loadFromFile(); APP_STATE.loadFromFile();
if (APP_STATE.openEpubPath.empty()) { if (APP_STATE.openEpubPath.empty()) {
onGoHome(); onGoHome();