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

Dependents:   Hexi_BLE_Example_Modified Hexi_BLE_Example_ModifiedPOTATO

Fork of Hexi_KW40Z by Hexiwear

Revision:
14:241c491f985f
Parent:
13:84ead63f7353
--- a/Hexi_KW40Z.cpp	Thu Aug 09 22:45:01 2018 +0000
+++ b/Hexi_KW40Z.cpp	Mon Aug 27 16:15:26 2018 -0700
@@ -35,7 +35,7 @@
  
 #include "Hexi_KW40Z.h"
  
-KW40Z::KW40Z(PinName txPin,PinName rxPin) : 
+KW40Z::KW40Z(PinName txPin,PinName rxPin) :
 #if defined (LIB_DEBUG) || defined (RAW_DEBUG) || defined (RX_DEBUG)
 pc(USBTX, USBRX),
 #endif
@@ -70,6 +70,9 @@
     advertisementMode = 0;
     linkState = 0;
     bondPassKey = 0;
+
+    allocated = 0;
+    freed = 0;
     
     /* intialization finalized, signal to start the threads */
     rxThread.start(this, &KW40Z::rxTask);
@@ -109,7 +112,10 @@
             hostInterface_packet_t *packet = (hostInterface_packet_t*)evt.value.p;
             ProcessPacket(packet);
             mpool.free(packet);
+            // freed += 1;
+            // printf("%s%lu\r\n", "non-freed buffer slots: ", allocated - freed);
         }
+        
     }
 }
 
@@ -139,6 +145,13 @@
 {
     /* copy txPacket to the mem pool */
     hostInterface_packet_t *packet = mpool.alloc();
+    
+
+    if (packet == NULL) {
+        return;
+    }
+    allocated += 1;
+
     memcpy(packet, txPacket, sizeof(hostInterface_packet_t));
     
     /* Set the TX bit in the Start 2 byte */
@@ -154,6 +167,8 @@
     printf("SendPacket: ");
     DebugPrintPacket(packet);
 #endif
+    // printf("SendPacket: ");
+    // DebugPrintPacket(packet);
 
     /* send message to main task */
     queue.put(packet);
@@ -255,6 +270,7 @@
                     
                     /* send message to main task */
                     hostInterface_packet_t *rxPacket = mpool.alloc();
+                    allocated += 1;
                     memcpy(rxPacket, &hostInterface_rxPacket, sizeof(hostInterface_packet_t));
                     queue.put(rxPacket);
 
@@ -265,6 +281,9 @@
 #if defined (RAW_DEBUG)
                     printf("\r\n");
 #endif
+                    // printf("RX: ");
+                    // DebugPrintPacket(&hostInterface_rxPacket);
+                    // printf("\r\n");
                     /* reset buffer position */
                     rxBuff = (uint8_t*)&hostInterface_rxPacket;
                 } 
@@ -775,3 +794,20 @@
     printf("\r\n");
 }
 #endif
+// void KW40Z::DebugPrintPacket(hostInterface_packet_t * packet)
+// {
+//     char * idx = (char *)packet;
+//     uint8_t length = packet->length + gHostInterface_headerSize + 1;
+    
+//     if(length > sizeof(hostInterface_packet_t))
+//     {
+//         length = sizeof(hostInterface_packet_t);
+//     }
+
+//     for(uint8_t i = 0; i < length; i++)
+//     {
+//         printf("%02X ",*idx);
+//         idx++;
+//     }
+//     printf("\r\n");
+// }