56#if !defined(USE_I2C_INTERFACE) && !defined(USE_SPI_INTERFACE)
57#define USE_I2C_INTERFACE
60#if defined(USE_SPI_INTERFACE)
94#ifdef ARDUINO_T_BEAM_S3_SUPREME
95#include <XPowersAXP2101.tpp>
98static void serialPrintFmt(
const char *fmt, ...)
103 vsnprintf(
buf,
sizeof(
buf), fmt, args);
110#if defined(ARDUINO_T_BEAM_S3_SUPREME)
111 XPowersAXP2101 power;
112 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
113 power.disableALDO1();
114 power.disableALDO2();
116 power.setALDO1Voltage(3300);
118 power.setALDO2Voltage(3300);
136 case SensorQMI8658::TapEvent::SINGLE:
137 Serial.println(
"[TAP] Single tap detected!");
139 case SensorQMI8658::TapEvent::DOUBLE:
140 Serial.println(
"[TAP] Double tap detected!");
143 Serial.println(
"[TAP] Invalid tap");
162 serialPrintFmt(
"[TAP CFG] peak=%.3f quiet=%.3f peakWin=%u tapWin=%u dblWin=%u\n",
168 Serial.println(
"\nTap debug commands:");
169 Serial.println(
" p+ / p- : peak threshold +/- 0.05 g^2");
170 Serial.println(
" q+ / q- : quiet threshold +/- 0.02 g^2");
171 Serial.println(
" w+ / w- : tap window +/- 5 samples");
172 Serial.println(
" d+ / d- : double tap window +/- 10 samples");
173 Serial.println(
" s : show current tap config");
174 Serial.println(
" h : show this help");
175 Serial.println(
"Single-key shortcuts (no Enter needed):");
176 Serial.println(
" 1:p- 2:p+ 3:q- 4:q+ 5:w- 6:w+ 7:d- 8:d+");
181 bool changed =
false;
186 }
else if (
cmd ==
"p-") {
190 }
else if (
cmd ==
"q+") {
193 }
else if (
cmd ==
"q-") {
197 }
else if (
cmd ==
"w+") {
200 }
else if (
cmd ==
"w-") {
203 }
else if (
cmd ==
"d+") {
206 }
else if (
cmd ==
"d-") {
209 }
else if (
cmd ==
"s") {
211 }
else if (
cmd ==
"h") {
226 static String lineBuf;
227 while (Serial.available()) {
228 char c = (char)Serial.read();
230 if (c ==
'\r' || c ==
'\n') {
232 if (lineBuf.length() > 0) {
234 Serial.println(
"Unknown command, input 'h' for help.");
242 if (c ==
'h' || c ==
's') {
243 String
cmd = String(c);
247 if (c >=
'1' && c <=
'8') {
261 if (isPrintable(c)) {
269 Serial.begin(115200);
274 Serial.println(
"QMI8658 Tap Detection Example");
276#ifdef USE_I2C_INTERFACE
278 Serial.println(
"Failed to initialize QMI8658!");
285#ifdef USE_SPI_INTERFACE
288 Serial.println(
"Failed to initialize QMI8658!");
305 Serial.println(
"\n=== Simple Usage ===");
306 Serial.println(
"Using configTapDefault() with sensible defaults:");
307 Serial.println(
"- peak_window: 30 samples");
308 Serial.println(
"- tap_window: 100 samples");
309 Serial.println(
"- double_tap_window: 500 samples");
310 Serial.println(
"- peak_mag_threshold: 1.5 g^2");
311 Serial.println(
"- quiet_threshold: 0.5 g^2");
314 Serial.println(
"\n=== Advanced Usage ===");
315 Serial.println(
"Using configTap() with runtime tuning support");
316 Serial.println(
"(Tuned to reduce single-tap reported as double)");
321 Serial.println(
"\nTap detection configured. Tap the sensor!");
322 Serial.println(
"Expected: Single tap = 1 event, Double tap = 2 events");
bool begin(CommInterface interface, SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr=0)
Initialize the sensor using custom callback interface.
QMI8658 IMU sensor driver class.
bool disableTap()
Disable tap detection.
bool enableAccel() override
Enable the accelerometer.
void setTapCallback(TapCallback callback)
Set callback for tap event.
bool configTap(TapPriority priority, uint8_t peak_window, uint16_t tap_window, uint16_t double_tap_window, float peak_mag_threshold, float quiet_threshold)
Configure tap detection parameters.
bool enableTap(IntPin pin=IntPin::PIN1)
Enable tap detection.
@ OFF
Disable low-pass filter.
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
uint16_t update()
Update sensor status and process events.
bool configTapDefault(TapPriority priority=TapPriority::X_GT_Y_GT_Z)
Configure tap detection with default parameters.
void setPins(int pin)
Set interrupt pin.
bool applyCommand(const String &cmd)
void tapCallback(SensorQMI8658::TapEvent event)
void handleSerialCommands()