Cubic Hand project for EECS 249A course.

Dependencies:   MMA8451Q TSI cc3000_hostdriver_mbedsocket NVIC_set_all_priorities mbed Multi_WS2811

Revision:
32:bf5f545621aa
Parent:
28:3261015fdd17
Child:
35:b6fb5dd65a98
diff -r 3261015fdd17 -r bf5f545621aa DataGlove.cpp
--- a/DataGlove.cpp	Thu Dec 11 05:57:54 2014 +0000
+++ b/DataGlove.cpp	Thu Dec 11 06:08:13 2014 +0000
@@ -58,14 +58,7 @@
     GloveSocket.SendDataToGlove(SendBuf, 6);
 }
 
-
-Glove DataGlove::ReceiveBlocking()
-{
-	while(Receive() == false);
-	return *gl;
-}
-
-bool DataGlove::Receive()
+void DataGlove::Receive()
 {
     raw = false;
     numReceived += GloveSocket.GetDataFromBuffer(Buf, 1);
@@ -83,7 +76,7 @@
             if ((numReceived  - 3 )< pkglen) 
             {
                 if(numReceived == 0) notConnectedCount++;
-                return false;
+                return;
             }
             for (u = 3; u <= pkglen; u++)
             {
@@ -98,12 +91,11 @@
                 timeOfArrival = (Buf[6] << 24) + (Buf[7] << 16) + (Buf[8] << 8) + Buf[9];
                 id = (Buf[4] << 8) + Buf[5];
                 pkgtype = Buf[3];
-                ReceiveCount++;
-                /*if(ReceiveCount > 501 && ReceiveCount%25 == 0) {//printf("%d %c\r\n", ReceiveCount, Buf[0]);
+                if(ReceiveCount > 501 && ReceiveCount++%25 == 0) {//printf("%d %c\r\n", ReceiveCount, Buf[0]);
                 	printf("%f %f %f %f %f %f %f %f\r\n", corrected->roll, corrected->pitch, corrected->yaw, 
                 	corrected->fingers[0], corrected->fingers[1], corrected->fingers[2], 
                 	corrected->fingers[3], corrected->fingers[4]);
-                }*/
+                }
                 switch (pkgtype){
                     case STREAM_FINGERS_QUATERNION:
                     {
@@ -136,7 +128,6 @@
                 Buf[0] = 0; //Clear Token so no repeats.
                 notConnectedCount = 0;
                 numReceived = 0;
-                return true;
             }
             else
             {
@@ -145,7 +136,7 @@
             }
         }
         // Normalize the data for the first 1000 samples
-        /*if (ReceiveCount < 500) {
+        if (ReceiveCount < 500) {
         	correction->roll = (correction->roll*ReceiveCount + gl->roll)/(ReceiveCount+1);
         	correction->pitch = (correction->pitch*ReceiveCount + gl->pitch)/(ReceiveCount+1);
         	correction->yaw = (correction->yaw*ReceiveCount + gl->yaw)/(ReceiveCount+1);
@@ -158,21 +149,21 @@
         	corrected->yaw = gl->yaw - correction->yaw;
         	for (int iter = 0; iter < 5; iter++)
         		corrected->fingers[iter] = gl->fingers[iter] - correction->fingers[iter];
-        }*/
+        }
     }
-   else {
+    else {
         //printf("couldn't get data %d\r\n", notConnectedCount);
         // Re-establishing communication in case no data is received for 1s (20 frames per second*1 = 20)
-        /*if (notConnectedCount > 200) {
+        if (notConnectedCount > 200) {
             printf("Connection broke! Trying to re-establish... %d %c\r\n",numReceived,Buf[0]);
             //GloveSocket.Reconnect();
             //StreamData(STREAM_QUATERNION);
             notConnectedCount = 0;
-        }*/
+        }
         numReceived = 0;
-        //notConnectedCount++;
+        notConnectedCount++;
     }
-    return false;
+    
 }
 
 void DataGlove::ExtractFingersQuat()
@@ -328,7 +319,6 @@
 {
 	return *gl;
 }
-
 bool DataGlove::CheckForNewValues()
 {
 	if(NewData == true)