From f4e5de741d99a035af3ca7a3bb3f723679a2ad85 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Wed, 13 May 2026 21:23:32 +0200 Subject: [PATCH] Review comments --- lib/hal/HalTiltSensor.cpp | 11 +++++++---- lib/hal/HalTiltSensor.h | 7 ++++--- src/main.cpp | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/hal/HalTiltSensor.cpp b/lib/hal/HalTiltSensor.cpp index 211fde9e..b469c462 100644 --- a/lib/hal/HalTiltSensor.cpp +++ b/lib/hal/HalTiltSensor.cpp @@ -78,6 +78,7 @@ void HalTiltSensor::begin() { _available = true; _initMs = millis(); + _sleepMs = millis(); _lastPollMs = millis(); LOG_INF("GYR", "QMI8658 gyro initialized and put to sleep"); } @@ -87,7 +88,7 @@ bool HalTiltSensor::wake() { return false; } - if ((millis() - _initMs) < SLEEP_STABILIZE_MS) { + if ((millis() - _sleepMs) < SLEEP_STABILIZE_MS) { return false; } @@ -115,6 +116,7 @@ bool HalTiltSensor::deepSleep() { if (writeReg(REG_CTRL7, CTRL7_DISABLE_ALL) && writeReg(REG_CTRL1, CTRL1_BASE | CTRL1_SENSOR_DISABLE)) { clearPendingEvents(); _inTilt = false; + _sleepMs = millis(); LOG_INF("GYR", "QMI8658 entered sleep mode"); return true; } 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) { return; } - if ((mode != CrossPointTiltPageTurn::TILT_OFF) && !_isAwake) { + if ((mode != CrossPointTiltPageTurn::TILT_OFF && inReader) && !_isAwake) { _isAwake = wake(); return; - } else if ((mode == CrossPointTiltPageTurn::TILT_OFF) && _isAwake) { + } else if ((mode == CrossPointTiltPageTurn::TILT_OFF || !inReader) && _isAwake) { _isAwake = !deepSleep(); return; } diff --git a/lib/hal/HalTiltSensor.h b/lib/hal/HalTiltSensor.h index d0e69c02..f070d723 100644 --- a/lib/hal/HalTiltSensor.h +++ b/lib/hal/HalTiltSensor.h @@ -26,6 +26,7 @@ class HalTiltSensor { bool _inTilt = false; bool _isAwake = false; unsigned long _initMs = 0; + unsigned long _sleepMs = 0; unsigned long _lastTiltMs = 0; unsigned long _wakeMs = 0; @@ -43,10 +44,10 @@ class HalTiltSensor { static constexpr uint8_t REG_CTRL7 = 0x08; 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_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_ODR_28HZ = 0b1000; @@ -65,7 +66,7 @@ class HalTiltSensor { 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 wasTiltedBack(); diff --git a/src/main.cpp b/src/main.cpp index d1be51cb..2aa112e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -335,7 +335,9 @@ void loop() { gpio.update(); buttonEventManager.update(); HalClock::updatePeriodic(); - halTiltSensor.update(SETTINGS.tiltPageTurn, SETTINGS.orientation, activityManager.isReaderActivity()); + halTiltSensor.update(static_cast(SETTINGS.tiltPageTurn), + static_cast(SETTINGS.orientation), + activityManager.isReaderActivity()); renderer.setFadingFix(SETTINGS.fadingFix); renderer.setTextDarkness(SETTINGS.textDarkness);