Hexiwear library for communicating with the on-board KW40Z BLE device. KW40Z handles also the touch buttons.

Dependents:   Hexi_Buttons_Example Hexi_Click_Relay-v2_Example Hexi_Click_Relay-v3_Example Hexi_Catch-the-dot_Game ... more

Revision:
1:f6f9b24aea57
Parent:
0:c2d52562f36b
Child:
2:bb66c19c3c04
--- a/Hexi_KW40Z.cpp	Mon Sep 19 02:46:28 2016 +0000
+++ b/Hexi_KW40Z.cpp	Mon Sep 19 03:39:36 2016 +0000
@@ -50,8 +50,16 @@
     device.format(8, Serial::None, 2);
     
     rxBuff = (uint8_t*)&hostInterface_rxPacket;
-    kw40z_Cbs = NULL;
-    //memset(&hexiwear_kw40version,0,sizeof(hexiwear_version_t));
+    
+    /* initialize callbacks */
+    buttonUpCb = NULL;
+    buttonDownCb = NULL;
+    buttonLeftCb = NULL;
+    buttonRightCb = NULL;
+    buttonSlideCb = NULL;
+    alertCb = NULL;
+    passkeyCb = NULL;
+    notificationsCb = NULL;
     
     /* intialization finalized, signal to start the threads */
     mainThread.signal_set(START_THREAD);
@@ -62,9 +70,44 @@
 {
 }
 
-void KW40Z::attach(kw40z_callbacks_t * callbacks)
+void KW40Z::attach_buttonUp(button_t btnFct)
+{
+    buttonUpCb = btnFct;
+}
+
+void KW40Z::attach_buttonDown(button_t btnFct)
+{
+    buttonDownCb = btnFct;
+}
+
+void KW40Z::attach_buttonLeft(button_t btnFct)
+{
+    buttonLeftCb = btnFct;
+}
+
+void KW40Z::attach_buttonRight(button_t btnFct)
 {
-    kw40z_Cbs = callbacks;
+    buttonRightCb = btnFct;
+}
+
+void KW40Z::attach_buttonSlide(button_t btnFct)
+{
+    buttonSlideCb = btnFct;
+}
+
+void KW40Z::attach_alert(alert_t alertFct)
+{
+    alertCb = alertFct;
+}
+
+void KW40Z::attach_passkey(passkey_t passkeyFct)
+{
+    passkeyCb = passkeyFct;
+}
+
+void KW40Z::attach_notifications(notifications_t notFct)
+{
+    notificationsCb = notFct;
 }
 
 void KW40Z::rxStarter(void const *p) {
@@ -330,30 +373,33 @@
     {
         /* button presses */
         case packetType_pressUp:
+            if(buttonUpCb != NULL) buttonUpCb();
+            break;
+            
         case packetType_pressDown:
+            if(buttonDownCb != NULL) buttonDownCb();
+            break;
+            
         case packetType_pressLeft:
+            if(buttonLeftCb != NULL) buttonLeftCb();
+            break;
+            
         case packetType_pressRight:
+            if(buttonRightCb != NULL) buttonRightCb();
+            break;
+        
         case packetType_slide:
-            if((kw40z_Cbs != NULL) && (kw40z_Cbs->buttons != NULL))
-            {
-                kw40z_Cbs->buttons((hexi_buttons_t)(rxPacket->type));
-            }
+            if(buttonSlideCb != NULL) buttonSlideCb();
             break;
     
         /* Alert Service */
         case packetType_alertIn:
-            if((kw40z_Cbs != NULL) && (kw40z_Cbs->alert != NULL))
-            {
-                kw40z_Cbs->alert(&rxPacket->data[0], rxPacket->length);
-            }
+            if(alertCb != NULL) alertCb(&rxPacket->data[0], rxPacket->length);
             break;
         
         /* Passkey for pairing received */
         case packetType_passDisplay:
-            if((kw40z_Cbs != NULL) && (kw40z_Cbs->passkey != NULL))
-            {
-                kw40z_Cbs->passkey(&rxPacket->data[0]);
-            }
+            if(passkeyCb != NULL) passkeyCb(&rxPacket->data[0]);
             break;
             
         /* OTAP messages */
@@ -375,10 +421,7 @@
             
         /* ANCS Service Notification Received */
         case packetType_notification:
-            if((kw40z_Cbs != NULL) && (kw40z_Cbs->notifications != NULL))
-            {
-                kw40z_Cbs->notifications(rxPacket->data[0],rxPacket->data[1]);
-            }
+            if(notificationsCb != NULL) notificationsCb(rxPacket->data[0], rxPacket->data[1]);
             break;
             
         /* Build version */