Example of single tap and double tap detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of SingleDoubleTap_IKS01A2 by ST Expansion SW Team

Single and Double Tap Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to detect the single and double tap events using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to tap the board and then view the notification using an hyper terminal. When the single tap is detected, the LED is switched on for a while.
- the user can press the user button to pass from the single tap detection to the double tap detection feature. The user can try to double tap the board and then view the notification using an hyper terminal. When the double tap is detected, the LED is switched on twice for a while.
- the user can press again the user button to disable the single and double tap detection feature.
- the user can press the user button to enable again the single tap detection feature and so on.

Revision:
19:ada8d403238b
Parent:
14:1556d5cb2e9c
--- a/main.cpp	Fri Dec 16 09:53:24 2016 +0000
+++ b/main.cpp	Tue Mar 14 13:43:42 2017 +0100
@@ -38,10 +38,10 @@
 
 /* Includes */
 #include "mbed.h"
-#include "x_nucleo_iks01a2.h"
+#include "XNucleoIKS01A2.h"
 
 /* Instantiate the expansion board */
-static X_NUCLEO_IKS01A2 *mems_expansion_board = X_NUCLEO_IKS01A2::Instance(D14, D15, D4, D5);
+static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
 
 /* Retrieve the composing elements of the expansion board */
 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
@@ -53,20 +53,27 @@
 volatile int change_mode = 0;
 static int mode = 1; /* 0 means No tap, 1 means Single Tap enabled, 2 means Double Tap enabled*/
 
-void pressed_cb();
-void INT1_cb();
+/* User button callback. */
+void pressed_cb() {
+  change_mode = 1;
+}
+
+/* Interrupt 1 callback. */
+void int1_cb() {
+  mems_event = 1;
+}
 
 /* Simple main function */
 int main() {
   /* Attach callback to User button press */
   mybutton.fall(&pressed_cb);
   /* Attach callback to LSM6DSL INT1 */
-  acc_gyro->AttachINT1IRQ(&INT1_cb);
+  acc_gyro->attach_int1_irq(&int1_cb);
   
   /* Enable LSM6DSL accelerometer */
-  acc_gyro->Enable_X();
+  acc_gyro->enable_x();
   /* Enable Single Tap Detection. */
-  acc_gyro->Enable_Single_Tap_Detection();
+  acc_gyro->enable_single_tap_detection();
   
   printf("\r\n--- Starting new run ---\r\n");
  
@@ -77,16 +84,16 @@
       switch(mode) {
         case 0:
           /* Disable Double Tap */
-          acc_gyro->Disable_Double_Tap_Detection();
+          acc_gyro->disable_double_tap_detection();
           break;
         case 1:
           /* Enable Single Tap */
-          acc_gyro->Enable_Single_Tap_Detection();
+          acc_gyro->enable_single_tap_detection();
           break;
         case 2:
           /* Disable Single Tap and Enable Double Tap */
-          acc_gyro->Disable_Single_Tap_Detection();
-          acc_gyro->Enable_Double_Tap_Detection();
+          acc_gyro->disable_single_tap_detection();
+          acc_gyro->enable_double_tap_detection();
           break;
       }
     }
@@ -99,7 +106,7 @@
           break;
         case 1: {
           LSM6DSL_Event_Status_t status;
-          acc_gyro->Get_Event_Status(&status);
+          acc_gyro->get_event_status(&status);
           if (status.TapStatus) {
             /* Led blinking. */
             myled = 1;
@@ -109,10 +116,11 @@
             /* Output data. */
             printf("Single Tap Detected!\r\n");
           }
+          break;
         }
         case 2: {
           LSM6DSL_Event_Status_t status;
-          acc_gyro->Get_Event_Status(&status);
+          acc_gyro->get_event_status(&status);
           if (status.DoubleTapStatus) {
             /* Double Led blinking */
             myled = 1;
@@ -126,16 +134,9 @@
             /* Output data. */
             printf("Double Tap Detected!\r\n");
           }
+          break;
         }
       }
     }
   }
 }
-
-void pressed_cb() {
-  change_mode = 1;
-}
-
-void INT1_cb() {
-  mems_event = 1;
-}