Review comments

This commit is contained in:
jpirnay
2026-05-13 21:23:32 +02:00
parent 7f395ceb0f
commit f4e5de741d
3 changed files with 14 additions and 8 deletions
+7 -4
View File
@@ -78,6 +78,7 @@ void HalTiltSensor::begin() {
_available = true; _available = true;
_initMs = millis(); _initMs = millis();
_sleepMs = millis();
_lastPollMs = millis(); _lastPollMs = millis();
LOG_INF("GYR", "QMI8658 gyro initialized and put to sleep"); LOG_INF("GYR", "QMI8658 gyro initialized and put to sleep");
} }
@@ -87,7 +88,7 @@ bool HalTiltSensor::wake() {
return false; return false;
} }
if ((millis() - _initMs) < SLEEP_STABILIZE_MS) { if ((millis() - _sleepMs) < SLEEP_STABILIZE_MS) {
return false; return false;
} }
@@ -115,6 +116,7 @@ bool HalTiltSensor::deepSleep() {
if (writeReg(REG_CTRL7, CTRL7_DISABLE_ALL) && writeReg(REG_CTRL1, CTRL1_BASE | CTRL1_SENSOR_DISABLE)) { if (writeReg(REG_CTRL7, CTRL7_DISABLE_ALL) && writeReg(REG_CTRL1, CTRL1_BASE | CTRL1_SENSOR_DISABLE)) {
clearPendingEvents(); clearPendingEvents();
_inTilt = false; _inTilt = false;
_sleepMs = millis();
LOG_INF("GYR", "QMI8658 entered sleep mode"); LOG_INF("GYR", "QMI8658 entered sleep mode");
return true; return true;
} else { } else {
@@ -123,15 +125,16 @@ bool HalTiltSensor::deepSleep() {
} }
} }
void HalTiltSensor::update(const uint8_t mode, const uint8_t orientation, const bool inReader) { void HalTiltSensor::update(CrossPointTiltPageTurn::Value mode, CrossPointOrientation::Value orientation,
bool inReader) {
if (!_available) { if (!_available) {
return; return;
} }
if ((mode != CrossPointTiltPageTurn::TILT_OFF) && !_isAwake) { if ((mode != CrossPointTiltPageTurn::TILT_OFF && inReader) && !_isAwake) {
_isAwake = wake(); _isAwake = wake();
return; return;
} else if ((mode == CrossPointTiltPageTurn::TILT_OFF) && _isAwake) { } else if ((mode == CrossPointTiltPageTurn::TILT_OFF || !inReader) && _isAwake) {
_isAwake = !deepSleep(); _isAwake = !deepSleep();
return; return;
} }
+4 -3
View File
@@ -26,6 +26,7 @@ class HalTiltSensor {
bool _inTilt = false; bool _inTilt = false;
bool _isAwake = false; bool _isAwake = false;
unsigned long _initMs = 0; unsigned long _initMs = 0;
unsigned long _sleepMs = 0;
unsigned long _lastTiltMs = 0; unsigned long _lastTiltMs = 0;
unsigned long _wakeMs = 0; unsigned long _wakeMs = 0;
@@ -43,10 +44,10 @@ class HalTiltSensor {
static constexpr uint8_t REG_CTRL7 = 0x08; static constexpr uint8_t REG_CTRL7 = 0x08;
static constexpr uint8_t REG_GX_L = 0x3B; static constexpr uint8_t REG_GX_L = 0x3B;
static constexpr uint8_t CTRL1_BIG_ENDIAN = (1 << 5); static constexpr uint8_t CTRL1_SPI_BE = (1 << 5); // SPI byte-order bit; no-op on I2C (QMI8658C)
static constexpr uint8_t CTRL1_AUTO_INC = (1 << 6); static constexpr uint8_t CTRL1_AUTO_INC = (1 << 6);
static constexpr uint8_t CTRL1_SENSOR_DISABLE = (1 << 0); static constexpr uint8_t CTRL1_SENSOR_DISABLE = (1 << 0);
static constexpr uint8_t CTRL1_BASE = CTRL1_AUTO_INC | CTRL1_BIG_ENDIAN; static constexpr uint8_t CTRL1_BASE = CTRL1_AUTO_INC | CTRL1_SPI_BE;
static constexpr uint8_t CTRL3_FS_512DPS = (0b101 << 4); static constexpr uint8_t CTRL3_FS_512DPS = (0b101 << 4);
static constexpr uint8_t CTRL3_ODR_28HZ = 0b1000; static constexpr uint8_t CTRL3_ODR_28HZ = 0b1000;
@@ -65,7 +66,7 @@ class HalTiltSensor {
bool isAvailable() const { return _available; } bool isAvailable() const { return _available; }
void update(const uint8_t mode, const uint8_t orientation, const bool inReader); void update(CrossPointTiltPageTurn::Value mode, CrossPointOrientation::Value orientation, bool inReader);
bool wasTiltedForward(); bool wasTiltedForward();
bool wasTiltedBack(); bool wasTiltedBack();
+3 -1
View File
@@ -335,7 +335,9 @@ void loop() {
gpio.update(); gpio.update();
buttonEventManager.update(); buttonEventManager.update();
HalClock::updatePeriodic(); HalClock::updatePeriodic();
halTiltSensor.update(SETTINGS.tiltPageTurn, SETTINGS.orientation, activityManager.isReaderActivity()); halTiltSensor.update(static_cast<CrossPointTiltPageTurn::Value>(SETTINGS.tiltPageTurn),
static_cast<CrossPointOrientation::Value>(SETTINGS.orientation),
activityManager.isReaderActivity());
renderer.setFadingFix(SETTINGS.fadingFix); renderer.setFadingFix(SETTINGS.fadingFix);
renderer.setTextDarkness(SETTINGS.textDarkness); renderer.setTextDarkness(SETTINGS.textDarkness);