mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-29 22:20:37 +00:00
Refactor AccelerometerThread.h (#4831)
* Initial upload * Tidy up * Update ICM20948Sensor.cpp * Update AccelerometerThread.h * Initial upload * Tidy up * Update ICM20948Sensor.cpp * Update AccelerometerThread.h --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
36
src/motion/LIS3DHSensor.cpp
Executable file
36
src/motion/LIS3DHSensor.cpp
Executable file
@@ -0,0 +1,36 @@
|
||||
#include "LIS3DHSensor.h"
|
||||
|
||||
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C
|
||||
|
||||
LIS3DHSensor::LIS3DHSensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {}
|
||||
|
||||
bool LIS3DHSensor::init()
|
||||
{
|
||||
if (sensor.begin(deviceAddress())) {
|
||||
sensor.setRange(LIS3DH_RANGE_2_G);
|
||||
// Adjust threshold, higher numbers are less sensitive
|
||||
sensor.setClick(config.device.double_tap_as_button_press ? 2 : 1, MOTION_SENSOR_CHECK_INTERVAL_MS);
|
||||
LOG_DEBUG("LIS3DHSensor::init ok\n");
|
||||
return true;
|
||||
}
|
||||
LOG_DEBUG("LIS3DHSensor::init failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t LIS3DHSensor::runOnce()
|
||||
{
|
||||
if (sensor.getClick() > 0) {
|
||||
uint8_t click = sensor.getClick();
|
||||
if (!config.device.double_tap_as_button_press) {
|
||||
wakeScreen();
|
||||
}
|
||||
|
||||
if (config.device.double_tap_as_button_press && (click & 0x20)) {
|
||||
buttonPress();
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
return MOTION_SENSOR_CHECK_INTERVAL_MS;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user