Created
August 26, 2012 19:59
-
-
Save eduardolundgren/3483166 to your computer and use it in GitHub Desktop.
tracking.js PSMoveAPI Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* tracking.js PS Move API | |
* Copyright (c) 2012 Eduardo Lundgren <[email protected]> | |
* All rights reserved. | |
**/ | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "psmove.h" | |
int ui_set_controller(PSMove *move) { | |
int buttons, | |
data = psmove_poll(move); | |
if (data) { | |
buttons = psmove_get_buttons(move); | |
if (buttons) { | |
if (buttons & Btn_TRIANGLE) { | |
psmove_set_leds(move, 0, 255, 255); | |
} | |
else if (buttons & Btn_CIRCLE) { | |
psmove_set_leds(move, 0, 0, 0); | |
} | |
else if (buttons & Btn_CROSS) { | |
psmove_set_leds(move, 0, 0, 255); | |
} | |
else if (buttons & Btn_SQUARE) { | |
psmove_set_leds(move, 255, 0, 255); | |
} | |
psmove_update_leds(move); | |
// printf("Controller buttons: %x\n", buttons); | |
} | |
} | |
return 1; | |
} | |
int main(int argc, char* argv[]) { | |
PSMove *move1, *move2; | |
printf("=> tracking.js PSMove Controller (Eduardo Lundgren)"); | |
printf("\n\thelp:\n\t\tBtn_TRIANGLE: Cyan\n\t\tBtn_CIRCLE: Off\n\t\tBtn_CROSS: Blue\n\t\tBtn_SQUARE: Magenta"); | |
printf("\n\n=> Connected controllers: %d\n", psmove_count_connected()); | |
move1 = psmove_connect_by_id(0); | |
move2 = psmove_connect_by_id(1); | |
while (1) { | |
ui_set_controller(move1); | |
ui_set_controller(move2); | |
} | |
psmove_disconnect(move1); | |
psmove_disconnect(move2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment