mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-19 15:47:40 +03:00
Option to short-press power button.
This commit is contained in:
parent
57fdb1c0fb
commit
44e2d0e319
@ -12,7 +12,7 @@ CrossPointSettings CrossPointSettings::instance;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
||||||
constexpr uint8_t SETTINGS_COUNT = 2;
|
constexpr uint8_t SETTINGS_COUNT = 3;
|
||||||
constexpr char SETTINGS_FILE[] = "/sd/.crosspoint/settings.bin";
|
constexpr char SETTINGS_FILE[] = "/sd/.crosspoint/settings.bin";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -25,6 +25,7 @@ bool CrossPointSettings::saveToFile() const {
|
|||||||
serialization::writePod(outputFile, SETTINGS_COUNT);
|
serialization::writePod(outputFile, SETTINGS_COUNT);
|
||||||
serialization::writePod(outputFile, whiteSleepScreen);
|
serialization::writePod(outputFile, whiteSleepScreen);
|
||||||
serialization::writePod(outputFile, extraParagraphSpacing);
|
serialization::writePod(outputFile, extraParagraphSpacing);
|
||||||
|
serialization::writePod(outputFile, shortPwrBtn);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
||||||
@ -51,15 +52,15 @@ bool CrossPointSettings::loadFromFile() {
|
|||||||
serialization::readPod(inputFile, fileSettingsCount);
|
serialization::readPod(inputFile, fileSettingsCount);
|
||||||
|
|
||||||
// load settings that exist
|
// load settings that exist
|
||||||
switch (fileSettingsCount) {
|
uint8_t settingsRead = 0;
|
||||||
case 1:
|
do {
|
||||||
serialization::readPod(inputFile, whiteSleepScreen);
|
serialization::readPod(inputFile, whiteSleepScreen);
|
||||||
break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
case 2:
|
serialization::readPod(inputFile, extraParagraphSpacing);
|
||||||
serialization::readPod(inputFile, whiteSleepScreen);
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readPod(inputFile, extraParagraphSpacing);
|
serialization::readPod(inputFile, shortPwrBtn);
|
||||||
break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
}
|
} while (false);
|
||||||
|
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis());
|
Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis());
|
||||||
|
|||||||
@ -17,15 +17,18 @@ class CrossPointSettings {
|
|||||||
|
|
||||||
// Sleep screen settings
|
// Sleep screen settings
|
||||||
uint8_t whiteSleepScreen = 0;
|
uint8_t whiteSleepScreen = 0;
|
||||||
|
|
||||||
// Text rendering settings
|
// Text rendering settings
|
||||||
uint8_t extraParagraphSpacing = 1;
|
uint8_t extraParagraphSpacing = 1;
|
||||||
|
// Duration of the power button press
|
||||||
|
uint8_t shortPwrBtn = 0;
|
||||||
|
|
||||||
~CrossPointSettings() = default;
|
~CrossPointSettings() = default;
|
||||||
|
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
static CrossPointSettings& getInstance() { return instance; }
|
static CrossPointSettings& getInstance() { return instance; }
|
||||||
|
|
||||||
|
uint16_t getPowerButtonDuration() const { return shortPwrBtn ? 10 : 500; }
|
||||||
|
|
||||||
bool saveToFile() const;
|
bool saveToFile() const;
|
||||||
bool loadFromFile();
|
bool loadFromFile();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
const SettingInfo SettingsActivity::settingsList[settingsCount] = {
|
const SettingInfo SettingsActivity::settingsList[settingsCount] = {
|
||||||
{"White Sleep Screen", &CrossPointSettings::whiteSleepScreen},
|
{"White Sleep Screen", &CrossPointSettings::whiteSleepScreen},
|
||||||
{"Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing}};
|
{"Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing},
|
||||||
|
{"Short Power Button Click", &CrossPointSettings::shortPwrBtn}};
|
||||||
|
|
||||||
void SettingsActivity::taskTrampoline(void* param) {
|
void SettingsActivity::taskTrampoline(void* param) {
|
||||||
auto* self = static_cast<SettingsActivity*>(param);
|
auto* self = static_cast<SettingsActivity*>(param);
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class SettingsActivity final : public Activity {
|
|||||||
const std::function<void()> onGoHome;
|
const std::function<void()> onGoHome;
|
||||||
|
|
||||||
// Static settings list
|
// Static settings list
|
||||||
static constexpr int settingsCount = 2; // Number of settings
|
static constexpr int settingsCount = 3; // Number of settings
|
||||||
static const SettingInfo settingsList[settingsCount];
|
static const SettingInfo settingsList[settingsCount];
|
||||||
|
|
||||||
static void taskTrampoline(void* param);
|
static void taskTrampoline(void* param);
|
||||||
|
|||||||
25
src/main.cpp
25
src/main.cpp
@ -57,11 +57,6 @@ EpdFont ubuntu10Font(&ubuntu_10);
|
|||||||
EpdFont ubuntuBold10Font(&ubuntu_bold_10);
|
EpdFont ubuntuBold10Font(&ubuntu_bold_10);
|
||||||
EpdFontFamily ubuntuFontFamily(&ubuntu10Font, &ubuntuBold10Font);
|
EpdFontFamily ubuntuFontFamily(&ubuntu10Font, &ubuntuBold10Font);
|
||||||
|
|
||||||
// Power button timing
|
|
||||||
// Time required to confirm boot from sleep
|
|
||||||
constexpr unsigned long POWER_BUTTON_WAKEUP_MS = 500;
|
|
||||||
// Time required to enter sleep mode
|
|
||||||
constexpr unsigned long POWER_BUTTON_SLEEP_MS = 500;
|
|
||||||
// Auto-sleep timeout (10 minutes of inactivity)
|
// Auto-sleep timeout (10 minutes of inactivity)
|
||||||
constexpr unsigned long AUTO_SLEEP_TIMEOUT_MS = 10 * 60 * 1000;
|
constexpr unsigned long AUTO_SLEEP_TIMEOUT_MS = 10 * 60 * 1000;
|
||||||
|
|
||||||
@ -79,7 +74,8 @@ 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 POWER_BUTTON_WAKEUP_MS
|
// 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;
|
||||||
|
|
||||||
@ -90,12 +86,16 @@ void verifyWakeupLongPress() {
|
|||||||
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(50);
|
delay(10);
|
||||||
inputManager.update();
|
inputManager.update();
|
||||||
} while (inputManager.isPressed(InputManager::BTN_POWER) && inputManager.getHeldTime() < POWER_BUTTON_WAKEUP_MS);
|
} while (inputManager.isPressed(InputManager::BTN_POWER) &&
|
||||||
abort = inputManager.getHeldTime() < POWER_BUTTON_WAKEUP_MS;
|
inputManager.getHeldTime() < SETTINGS.getPowerButtonDuration());
|
||||||
|
abort = inputManager.getHeldTime() < SETTINGS.getPowerButtonDuration();
|
||||||
} else {
|
} else {
|
||||||
abort = true;
|
abort = true;
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ void enterDeepSleep() {
|
|||||||
exitActivity();
|
exitActivity();
|
||||||
enterNewActivity(new SleepActivity(renderer, inputManager));
|
enterNewActivity(new SleepActivity(renderer, inputManager));
|
||||||
|
|
||||||
Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis());
|
Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis());
|
||||||
delay(1000); // Allow Serial buffer to empty and display to update
|
delay(1000); // Allow Serial buffer to empty and display to update
|
||||||
|
|
||||||
// Enable Wakeup on LOW (button press)
|
// Enable Wakeup on LOW (button press)
|
||||||
@ -156,7 +156,7 @@ 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();
|
// verifyWakeupLongPress();
|
||||||
|
|
||||||
// Initialize pins
|
// Initialize pins
|
||||||
pinMode(BAT_GPIO0, INPUT);
|
pinMode(BAT_GPIO0, INPUT);
|
||||||
@ -216,7 +216,8 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputManager.wasReleased(InputManager::BTN_POWER) && inputManager.getHeldTime() > POWER_BUTTON_WAKEUP_MS) {
|
if (inputManager.wasReleased(InputManager::BTN_POWER) &&
|
||||||
|
inputManager.getHeldTime() > SETTINGS.getPowerButtonDuration()) {
|
||||||
enterDeepSleep();
|
enterDeepSleep();
|
||||||
// This should never be hit as `enterDeepSleep` calls esp_deep_sleep_start
|
// This should never be hit as `enterDeepSleep` calls esp_deep_sleep_start
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user