@@ -43,6 +43,11 @@ bool drvLis3dh::begin() {
4343 // Note: some Adafruit_LIS3DH variants offer setDataRate; if present this
4444 // keeps defaults. Keep configuration minimal to avoid API mismatches.
4545
46+ // setup interrupt for click detection (boolean event)
47+ _lis->setClick (1 , LIS3DH_CLICKTHRESHHOLD); // 0-2 clicks, threshold 50
48+ delay (100 ); // ignore any spurious interrupts right after setup
49+ _lis->readAndClearInterrupt ();
50+
4651 return true ;
4752}
4853
@@ -58,7 +63,7 @@ bool drvLis3dh::begin() {
5863bool drvLis3dh::getEventRaw (sensors_event_t *rawEvent) {
5964 if (!_lis)
6065 return false ;
61-
66+ WS_DEBUG_PRINTLN ( " [drvLis3dh] Getting raw event... " );
6267 // Read an Adafruit_Sensor compatible event from the device
6368 sensors_event_t event;
6469 _lis->getEvent (&event);
@@ -69,6 +74,43 @@ bool drvLis3dh::getEventRaw(sensors_event_t *rawEvent) {
6974 event.acceleration .y * event.acceleration .y +
7075 event.acceleration .z * event.acceleration .z );
7176 rawEvent->data [0 ] = mag;
77+ WS_DEBUG_PRINT (" [drvLis3dh] Raw magnitude: " );
78+ WS_DEBUG_PRINTLN (mag);
79+ return true ;
80+ }
81+
82+ /* *****************************************************************************/
83+ /* !
84+ @brief Gets the LIS3DH's boolean sensor event.
85+ @param booleanEvent
86+ Pointer to the sensor event.
87+ @returns True if the sensor event was obtained successfully, False
88+ otherwise.
89+ */
90+ /* *****************************************************************************/
91+ bool drvLis3dh::getEventBoolean (sensors_event_t *booleanEvent) {
92+ if (!_lis) {
93+ return false ;
94+ }
95+ WS_DEBUG_PRINTLN (" [drvLis3dh] Checking for click event..." );
96+ uint8_t result = _lis->getClick ();
97+ WS_DEBUG_PRINT (" Click result: " );
98+ WS_DEBUG_PRINTHEX (result);
99+ WS_DEBUG_PRINTLN (" " );
100+ // does it & 0x30, then 0x20 is double click, 0x10 is single click
101+ WS_DEBUG_PRINTLN (" [drvLis3dh] Click result & 0x30: " );
102+ WS_DEBUG_PRINTHEX (result & 0x30 );
103+ WS_DEBUG_PRINTLN (" " );
104+ uint8_t interruptReason = _lis->readAndClearInterrupt ();
105+ WS_DEBUG_PRINTLN (" [drvLis3dh] Interrupt reason: " );
106+ WS_DEBUG_PRINTHEX (interruptReason);
107+ WS_DEBUG_PRINTLN (" " );
108+
109+ // todo: switch on interrupt type - needs driver library expanding
110+ if (interruptReason == 1 && result == 1 ) {
111+ WS_DEBUG_PRINTLN (" [drvLis3dh] Click event detected!" );
112+ }
113+ booleanEvent->data [0 ] = result ? 1 .0f : 0 .0f ;
72114 return true ;
73115}
74116
@@ -82,9 +124,10 @@ bool drvLis3dh::getEventRaw(sensors_event_t *rawEvent) {
82124*/
83125/* *****************************************************************************/
84126bool drvLis3dh::getEventAccelerometer (sensors_event_t *accelEvent) {
85- if (!_lis)
127+ if (!_lis) {
86128 return false ;
87-
129+ }
130+ WS_DEBUG_PRINTLN (" [drvLis3dh] Getting accelerometer event..." );
88131 // Fill the provided event with sensor data
89132 _lis->getEvent (accelEvent);
90133 return true ;
0 commit comments