Skip to content

Instantly share code, notes, and snippets.

@breuderink
Created December 6, 2012 15:12
Show Gist options
  • Save breuderink/4225173 to your computer and use it in GitHub Desktop.
Save breuderink/4225173 to your computer and use it in GitHub Desktop.
MindPlay C example
#include "mindplay.h"
#define FPS 30
int main(void)
{
mp_api_t mp;
mp_response_t *response = NULL;
float p;
/* To start using MindPlay, we setup an API with with a server address, a
* user and a stream to analyze: */
mp_init(&mp, "http://localhost:5000", "test_user", "1");
for(int frame=0;; ++frame) {
if (frame % (FPS / 8) == 0) {
/* Eight times a second, we request a detection from the server: */
response = mp_request_detection(&mp);
}
/* We hate interrupting your game. So we quickly poll for a response: */
mp_update(&mp);
if (response->status == MP_RESP_READY) {
/* There is a complete response from the server. Let's extract a
* probability from the "left hand" detector: */
mp_detection(response, "left hand", &p);
mp_response_destroy(response); /* Free slot for new requests. */
printf("Detected imagined left hand movement with a probability of %.2f.\n", p);
}
printf("[Insert your game code for frame %d.]\n", frame);
usleep(1e6/FPS);
}
mp_destroy(&mp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment