motion data on button press

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z

Fork of Hexi_Buttons_Example by Hexiwear

Files at this revision

API Documentation at this revision

Comitter:
cotigac
Date:
Mon Sep 19 03:40:21 2016 +0000
Parent:
0:f7ef26f17610
Child:
2:5b025ef2835a
Commit message:
Updated example for simpler callbacks

Changed in this revision

Hexi_KW40Z.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Hexi_KW40Z.lib	Mon Sep 19 02:51:26 2016 +0000
+++ b/Hexi_KW40Z.lib	Mon Sep 19 03:40:21 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#c2d52562f36b
+https://developer.mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#f6f9b24aea57
--- a/main.cpp	Mon Sep 19 02:51:26 2016 +0000
+++ b/main.cpp	Mon Sep 19 03:40:21 2016 +0000
@@ -6,15 +6,6 @@
    
 void StartHaptic(void);
 void StopHaptic(void const *n);
-void HandleButtons(hexi_buttons_t button);
-
-kw40z_callbacks_t callbacks = 
-{
-    .buttons = HandleButtons,
-    .alert = NULL,
-    .passkey = NULL,
-    .notifications = NULL,
-};
 
 DigitalOut redLed(LED1);
 DigitalOut greenLed(LED2);
@@ -26,57 +17,65 @@
 
 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ 
 KW40Z kw40z_device(PTE24, PTE25);
+
+void ButtonUp(void)
+{
+    StartHaptic();
     
+    redLed      = LED_ON;
+    greenLed    = LED_OFF;
+    blueLed     = LED_OFF;
+}
+
+void ButtonDown(void)
+{
+    StartHaptic();
+    
+    redLed      = LED_OFF;
+    greenLed    = LED_ON;
+    blueLed     = LED_OFF;
+}
+
+void ButtonRight(void)
+{
+    StartHaptic();
+    
+    redLed      = LED_OFF;
+    greenLed    = LED_OFF;
+    blueLed     = LED_ON;
+}
+
+void ButtonLeft(void)
+{
+    StartHaptic();
+    
+    redLed      = LED_ON;
+    greenLed    = LED_OFF;
+    blueLed     = LED_OFF;
+}
+
+void ButtonSlide(void)
+{
+    StartHaptic();
+    
+    redLed      = LED_ON;
+    greenLed    = LED_ON;
+    blueLed     = LED_OFF;
+}
+   
 int main()
 {
     /* Register callbacks to application functions */
-    kw40z_device.attach(&callbacks);
+    kw40z_device.attach_buttonUp(&ButtonUp);
+    kw40z_device.attach_buttonDown(&ButtonDown);
+    kw40z_device.attach_buttonLeft(&ButtonLeft);
+    kw40z_device.attach_buttonRight(&ButtonRight);
+    kw40z_device.attach_buttonSlide(&ButtonSlide);
     
     while (true) {
         Thread::wait(500);
     }
 }
-   
-void HandleButtons(hexi_buttons_t button)
-{   
-    StartHaptic();
-
-    switch(button)
-    {
-        case pressUp:
-            redLed      = LED_ON;
-            greenLed    = LED_OFF;
-            blueLed     = LED_OFF;
-            break;
-            
-        case pressDown:
-            redLed      = LED_OFF;
-            greenLed    = LED_ON;
-            blueLed     = LED_OFF;
-            break;
-            
-        case pressLeft:
-            redLed      = LED_OFF;
-            greenLed    = LED_OFF;
-            blueLed     = LED_ON;
-            break;
-            
-        case pressRight:
-            redLed      = LED_ON;
-            greenLed    = LED_ON;
-            blueLed     = LED_OFF;
-            break;
-            
-        case slide:
-            redLed      = LED_ON;
-            greenLed    = LED_ON;
-            blueLed     = LED_ON;
-            break;
-        
-        default:
-            break;
-    }
-}
 
 void StartHaptic(void)
 {