Cubic Hand project for EECS 249A course.
Dependencies: MMA8451Q TSI cc3000_hostdriver_mbedsocket NVIC_set_all_priorities mbed Multi_WS2811
Diff: DataGlove.cpp
- Revision:
- 26:42ae7eed0b68
- Parent:
- 23:a8de4f87cada
- Child:
- 28:3261015fdd17
- Child:
- 36:4a58639da6cf
--- a/DataGlove.cpp Thu Dec 11 04:17:46 2014 +0000 +++ b/DataGlove.cpp Thu Dec 11 05:25:03 2014 +0000 @@ -58,7 +58,14 @@ GloveSocket.SendDataToGlove(SendBuf, 6); } -void DataGlove::Receive() + +Glove DataGlove::ReceiveBlocking() +{ + while(Receive() == false); + return *gl; +} + +bool DataGlove::Receive() { raw = false; numReceived += GloveSocket.GetDataFromBuffer(Buf, 1); @@ -76,7 +83,7 @@ if ((numReceived - 3 )< pkglen) { if(numReceived == 0) notConnectedCount++; - return; + return false; } for (u = 3; u <= pkglen; u++) { @@ -91,7 +98,8 @@ timeOfArrival = (Buf[6] << 24) + (Buf[7] << 16) + (Buf[8] << 8) + Buf[9]; id = (Buf[4] << 8) + Buf[5]; pkgtype = Buf[3]; - if(ReceiveCount > 501 && ReceiveCount++%25 == 0) {//printf("%d %c\r\n", ReceiveCount, Buf[0]); + ReceiveCount++; + 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]); @@ -128,6 +136,7 @@ Buf[0] = 0; //Clear Token so no repeats. notConnectedCount = 0; numReceived = 0; + return true; } else { @@ -136,7 +145,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); @@ -149,7 +158,7 @@ corrected->yaw = gl->yaw - correction->yaw; for (int iter = 0; iter < 5; iter++) corrected->fingers[iter] = gl->fingers[iter] - correction->fingers[iter]; - } + }*/ } else { //printf("couldn't get data %d\r\n", notConnectedCount); @@ -163,7 +172,7 @@ numReceived = 0; notConnectedCount++; } - + return false; } void DataGlove::ExtractFingersQuat() @@ -319,6 +328,7 @@ { return *gl; } + bool DataGlove::CheckForNewValues() { if(NewData == true)