In: Computer Science
write a general example of polling in C language with comments
#undef __cplusplus
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
#include "LeapC.h"
#include "ExampleConnection.h"
int64_t lastFrameID = 0; //The last frame received
int main(int argc, char** argv) {
OpenConnection();
while(!IsConnected)
millisleep(100); //wait a bit to let the connection complete
printf("Connected.");
LEAP_DEVICE_INFO* deviceProps = GetDeviceProperties(); // leap device information
if(deviceProps)
printf("Using device %s.\n", deviceProps->serial);
for(;;){ //using loop
LEAP_TRACKING_EVENT *frame = GetFrame();
if(frame && (frame->tracking_frame_id > lastFrameID)){
lastFrameID = frame->tracking_frame_id;
printf("Frame %lli with %i hands.\n", (long long int)frame->tracking_frame_id, frame->nHands);
for(uint32_t h = 0; h < frame->nHands; h++){
LEAP_HAND* hand = &frame->pHands[h];
printf(" Hand id %i is a %s hand with position (%f, %f, %f).\n",
hand->id,
(hand->type == eLeapHandType_Left ? "left" : "right"),
hand->palm.position.x,
hand->palm.position.y,
hand->palm.position.z);
}
}
}
return 0;
}