2024-09-25 21:25:31 +10:00
|
|
|
#include "LIS3DHSensor.h"
|
2024-10-24 21:58:24 +02:00
|
|
|
#include "NodeDB.h"
|
2024-09-25 21:25:31 +10:00
|
|
|
|
|
|
|
|
#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);
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("LIS3DH init ok");
|
2024-09-25 21:25:31 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("LIS3DH init failed");
|
2024-09-25 21:25:31 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t LIS3DHSensor::runOnce()
|
|
|
|
|
{
|
|
|
|
|
if (sensor.getClick() > 0) {
|
|
|
|
|
uint8_t click = sensor.getClick();
|
2024-12-24 10:47:27 +11:00
|
|
|
if (!config.device.double_tap_as_button_press && config.display.wake_on_tap_or_motion) {
|
2024-09-25 21:25:31 +10:00
|
|
|
wakeScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.device.double_tap_as_button_press && (click & 0x20)) {
|
|
|
|
|
buttonPress();
|
|
|
|
|
return 500;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MOTION_SENSOR_CHECK_INTERVAL_MS;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 10:47:27 +11:00
|
|
|
#endif
|