Add motion tracking and calibration features

This commit is contained in:
Nik Rozman committed 2026-10-14 09:37:41 +02:00
1 parent 4aa369ca73
commit aab61a2b7b
13 files changed
+735 -169

No files matched your search

+4 -3
View File
@@ -7,7 +7,7 @@
extern BLEHidAdafruit blehid;
// Tap detection setup
// REG_TAP_THS_6D bits[4:0] = tapThreshold (1–31); 1 LSB = FS/32 = 62.5 mg at ±2g.
// REG_TAP_THS_6D bits[4:0] = tapThreshold (1–31); 1 LSB = FS/32 = 125 mg at ±4g.
// REG_INT_DUR2 at ODR=416 Hz:
// SHOCK[7:6] = 2 → 38 ms max tap duration
// QUIET[5:4] = 2 → 19 ms refractory after tap
@@ -20,14 +20,15 @@ void applyTapThreshold() {
}
void setupTapDetection() {
imuWriteReg(REG_CTRL1_XL, 0x60); // ODR=416 Hz, FS=±2g
// ODR=416 Hz; keep the ±4 g full scale the tracking pipeline expects
imuWriteReg(REG_CTRL1_XL, (imuReadReg(REG_CTRL1_XL) & 0x0F) | 0x60);
imuWriteReg(REG_TAP_CFG, 0x8E); // TIMER_EN + LIR + TAP_Z/Y/X enabled
applyTapThreshold();
imuWriteReg(REG_INT_DUR2, 0x62); // SHOCK=2(38ms), QUIET=2(19ms), DUR=6(115ms)
imuWriteReg(REG_WAKE_UP_THS, 0x80); // bit7=1 → single + double tap both enabled
imuWriteReg(REG_MD1_CFG, 0x48); // route single-tap(0x08) + double-tap(0x40) → INT1
Serial.print("[TAP] threshold="); Serial.print(cfg.tapThreshold);
Serial.print(" (~"); Serial.print(cfg.tapThreshold * 62.5f, 0); Serial.println(" mg)");
Serial.print(" (~"); Serial.print(cfg.tapThreshold * 125.0f, 0); Serial.println(" mg)");
}
// Tap processing