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;
_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;
}
+4 -3
View File
@@ -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();
+3 -1
View File
@@ -335,7 +335,9 @@ void loop() {
gpio.update();
buttonEventManager.update();
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.setTextDarkness(SETTINGS.textDarkness);