2024-09-25 21:25:31 +10:00
|
|
|
#include "BMA423Sensor.h"
|
|
|
|
|
|
2025-04-28 18:35:13 -05:00
|
|
|
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && defined(HAS_BMA423) && __has_include(<SensorBMA423.hpp>)
|
2024-09-25 21:25:31 +10:00
|
|
|
|
|
|
|
|
BMA423Sensor::BMA423Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {}
|
|
|
|
|
|
|
|
|
|
bool BMA423Sensor::init()
|
|
|
|
|
{
|
2025-12-21 02:10:21 +01:00
|
|
|
if (sensor.begin(Wire, deviceAddress())) {
|
2024-09-25 21:25:31 +10:00
|
|
|
sensor.configAccelerometer(sensor.RANGE_2G, sensor.ODR_100HZ, sensor.BW_NORMAL_AVG4, sensor.PERF_CONTINUOUS_MODE);
|
|
|
|
|
sensor.enableAccelerometer();
|
2025-12-21 02:10:21 +01:00
|
|
|
sensor.configInterrupt();
|
2024-09-25 21:25:31 +10:00
|
|
|
|
|
|
|
|
#ifdef BMA423_INT
|
|
|
|
|
pinMode(BMA4XX_INT, INPUT);
|
|
|
|
|
attachInterrupt(
|
|
|
|
|
BMA4XX_INT,
|
|
|
|
|
[] {
|
|
|
|
|
// Set interrupt to set irq value to true
|
|
|
|
|
BMA_IRQ = true;
|
|
|
|
|
},
|
|
|
|
|
RISING); // Select the interrupt mode according to the actual circuit
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef T_WATCH_S3
|
|
|
|
|
// Need to raise the wrist function, need to set the correct axis
|
2025-12-21 02:10:21 +01:00
|
|
|
sensor.setRemapAxes(sensor.REMAP_TOP_LAYER_RIGHT_CORNER);
|
2024-09-25 21:25:31 +10:00
|
|
|
#else
|
2025-12-21 02:10:21 +01:00
|
|
|
sensor.setRemapAxes(sensor.REMAP_BOTTOM_LAYER_BOTTOM_LEFT_CORNER);
|
2024-09-25 21:25:31 +10:00
|
|
|
#endif
|
|
|
|
|
// sensor.enableFeature(sensor.FEATURE_STEP_CNTR, true);
|
|
|
|
|
sensor.enableFeature(sensor.FEATURE_TILT, true);
|
|
|
|
|
sensor.enableFeature(sensor.FEATURE_WAKEUP, true);
|
|
|
|
|
// sensor.resetPedometer();
|
|
|
|
|
|
|
|
|
|
// Turn on feature interrupt
|
|
|
|
|
sensor.enablePedometerIRQ();
|
|
|
|
|
sensor.enableTiltIRQ();
|
|
|
|
|
|
|
|
|
|
// It corresponds to isDoubleClick interrupt
|
|
|
|
|
sensor.enableWakeupIRQ();
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("BMA423 init ok");
|
2024-09-25 21:25:31 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_DEBUG("BMA423 init failed");
|
2024-09-25 21:25:31 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t BMA423Sensor::runOnce()
|
|
|
|
|
{
|
2025-12-21 02:10:21 +01:00
|
|
|
if (sensor.readIrqStatus()) {
|
2024-09-25 21:25:31 +10:00
|
|
|
if (sensor.isTilt() || sensor.isDoubleTap()) {
|
|
|
|
|
wakeScreen();
|
|
|
|
|
return 500;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MOTION_SENSOR_CHECK_INTERVAL_MS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|