mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 15:17:37 +03:00
Merge a87cd9ed72 into 87d6c032a5
This commit is contained in:
commit
239d310079
29
src/main.cpp
29
src/main.cpp
@ -45,6 +45,8 @@ MappedInputManager mappedInputManager(inputManager);
|
|||||||
GfxRenderer renderer(einkDisplay);
|
GfxRenderer renderer(einkDisplay);
|
||||||
Activity* currentActivity;
|
Activity* currentActivity;
|
||||||
|
|
||||||
|
RTC_DATA_ATTR uint16_t rtcPowerButtonDurationMs = 400;
|
||||||
|
|
||||||
// Fonts
|
// Fonts
|
||||||
EpdFont bookerly14RegularFont(&bookerly_14_regular);
|
EpdFont bookerly14RegularFont(&bookerly_14_regular);
|
||||||
EpdFont bookerly14BoldFont(&bookerly_14_bold);
|
EpdFont bookerly14BoldFont(&bookerly_14_bold);
|
||||||
@ -153,15 +155,10 @@ 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 the configured duration
|
||||||
const auto start = millis();
|
const auto start = millis();
|
||||||
bool abort = false;
|
bool abort = false;
|
||||||
// Subtract the current time, because inputManager only starts counting the HeldTime from the first update()
|
const uint16_t requiredPressDuration = rtcPowerButtonDurationMs;
|
||||||
// This way, we remove the time we already took to reach here from the duration,
|
|
||||||
// assuming the button was held until now from millis()==0 (i.e. device start time).
|
|
||||||
const uint16_t calibration = start;
|
|
||||||
const uint16_t calibratedPressDuration =
|
|
||||||
(calibration < SETTINGS.getPowerButtonDuration()) ? SETTINGS.getPowerButtonDuration() - calibration : 1;
|
|
||||||
|
|
||||||
inputManager.update();
|
inputManager.update();
|
||||||
// Verify the user has actually pressed
|
// Verify the user has actually pressed
|
||||||
@ -175,8 +172,8 @@ void verifyWakeupLongPress() {
|
|||||||
do {
|
do {
|
||||||
delay(10);
|
delay(10);
|
||||||
inputManager.update();
|
inputManager.update();
|
||||||
} while (inputManager.isPressed(InputManager::BTN_POWER) && inputManager.getHeldTime() < calibratedPressDuration);
|
} while (inputManager.isPressed(InputManager::BTN_POWER) && inputManager.getHeldTime() <= requiredPressDuration);
|
||||||
abort = inputManager.getHeldTime() < calibratedPressDuration;
|
abort = inputManager.getHeldTime() <= requiredPressDuration;
|
||||||
} else {
|
} else {
|
||||||
abort = true;
|
abort = true;
|
||||||
}
|
}
|
||||||
@ -202,6 +199,8 @@ void enterDeepSleep() {
|
|||||||
exitActivity();
|
exitActivity();
|
||||||
enterNewActivity(new SleepActivity(renderer, mappedInputManager));
|
enterNewActivity(new SleepActivity(renderer, mappedInputManager));
|
||||||
|
|
||||||
|
rtcPowerButtonDurationMs = SETTINGS.getPowerButtonDuration();
|
||||||
|
|
||||||
einkDisplay.deepSleep();
|
einkDisplay.deepSleep();
|
||||||
Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1);
|
Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1);
|
||||||
Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis());
|
Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis());
|
||||||
@ -286,6 +285,10 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inputManager.begin();
|
inputManager.begin();
|
||||||
|
verifyWakeupLongPress();
|
||||||
|
|
||||||
|
Serial.printf("[%lu] [ ] Starting CrossPoint version " CROSSPOINT_VERSION "\n", millis());
|
||||||
|
|
||||||
// Initialize pins
|
// Initialize pins
|
||||||
pinMode(BAT_GPIO0, INPUT);
|
pinMode(BAT_GPIO0, INPUT);
|
||||||
|
|
||||||
@ -303,14 +306,10 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SETTINGS.loadFromFile();
|
SETTINGS.loadFromFile();
|
||||||
|
rtcPowerButtonDurationMs = SETTINGS.getPowerButtonDuration();
|
||||||
|
|
||||||
KOREADER_STORE.loadFromFile();
|
KOREADER_STORE.loadFromFile();
|
||||||
|
|
||||||
// verify power button press duration after we've read settings.
|
|
||||||
verifyWakeupLongPress();
|
|
||||||
|
|
||||||
// First serial output only here to avoid timing inconsistencies for power button press duration verification
|
|
||||||
Serial.printf("[%lu] [ ] Starting CrossPoint version " CROSSPOINT_VERSION "\n", millis());
|
|
||||||
|
|
||||||
setupDisplayAndFonts();
|
setupDisplayAndFonts();
|
||||||
|
|
||||||
exitActivity();
|
exitActivity();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user