Hi everyone Got a problem with understanding how this works. I am trying to read in the data values of a P5 GAME glove, And i want to create a Windows form to display the data that i have retrieved from my P5 GAME GLOVE. But the problem that i am facing is that i do not know how to read the data from my glove to the form application in real time.
So temporary i created a button, and when i want to see the data values i would have to click on the button and it would release the data values.
this is my code for it :
private: System::Void btnGet_Click(System::Objec
t^ sender, System::EventArgs^ e) {
int finger1bent = 1100;
int finger2bent = 1100;
int finger3bent = 1100;
int finger4bent = 1400;
int tumbbent = 0;
P5_Init();
P5_SetUnits(P5_CM);
P5State *state = P5_GetStatePointer(0);
P5Info *info = P5_GetInfoPointer(0);
lblValue1->Text = state->FingerAbsolute[1].T
oString();
lblValue2->Text = state->FingerAbsolute[2].T
oString();
lblValue3->Text = state->FingerAbsolute[3].T
oString();
lblValue4->Text = state->FingerAbsolute[4].T
oString();
lblValue5->Text = state->FingerAbsolute[5].T
oString();
lblFP0->Text = state->FilterPos[0].ToStri
ng();
lblFP1->Text = state->FilterPos[1].ToStri
ng();
lblFP2->Text = state->FilterPos[2].ToStri
ng();
lblFP3->Text = state->FilterPos[3].ToStri
ng();
lblFP4->Text = state->FilterPos[4].ToStri
ng();
lblDeviceId->Text = info->DeviceID.ToString();
if (state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
lblHandStatus->Text = "SISSORS";
}
if ( state->FingerAbsolute[1] < finger1bent && state->FingerAbsolute[2] < finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
lblHandStatus->Text = "STONE";
}
if ( state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] > finger3bent && state->FingerAbsolute[4] > finger4bent ){
lblHandStatus->Text = "PAPER";
}
P5_Close();
}
When i try to put it into a while loop at the Form_Load part to try to get the values dynamically, the program with just hang:
The attempted codes are:
private: System::Void Form1_Load(System::Object^
sender, System::EventArgs^ e) {
/*
int finger1bent = 1100;
int finger2bent = 1100;
int finger3bent = 1100;
int finger4bent = 1400;
int tumbbent = 0;
P5_Init();
P5_SetUnits(P5_CM);
P5State *state = P5_GetStatePointer(0);
P5Info *info = P5_GetInfoPointer(0);
int counter = 0;
while (counter =0) {
lblValue1->Text = state->FingerAbsolute[1].T
oString();
lblValue2->Text = state->FingerAbsolute[2].T
oString();
lblValue3->Text = state->FingerAbsolute[3].T
oString();
lblValue4->Text = state->FingerAbsolute[4].T
oString();
lblValue5->Text = state->FingerAbsolute[5].T
oString();
lblFP0->Text = state->FilterPos[0].ToStri
ng();
lblFP1->Text = state->FilterPos[1].ToStri
ng();
lblFP2->Text = state->FilterPos[2].ToStri
ng();
lblFP3->Text = state->FilterPos[3].ToStri
ng();
lblFP4->Text = state->FilterPos[4].ToStri
ng();
lblDeviceId->Text = info->DeviceID.ToString();
if (state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
lblHandStatus->Text = "SISSORS";
}
if ( state->FingerAbsolute[1] < finger1bent && state->FingerAbsolute[2] < finger2bent && state->FingerAbsolute[3] < finger3bent && state->FingerAbsolute[4] < finger4bent ){
lblHandStatus->Text = "STONE";
}
if ( state->FingerAbsolute[1] > finger1bent && state->FingerAbsolute[2] > finger2bent && state->FingerAbsolute[3] > finger3bent && state->FingerAbsolute[4] > finger4bent ){
lblHandStatus->Text = "PAPER";
}
}//end of while loop
*/
}
After searching around the net, i found out that i should use a thread to solve this problem. But i am not sure how. Could any one point me in the right direction? or could someone advice me on what should i do, to be able to view the datas from my glove on the windows form, dynamically.
Thanks a million.
Start Free Trial