Astyle the examples.
This commit is contained in:
@@ -123,18 +123,23 @@ void set_material(struct material_t* mptr);
|
|||||||
void resize_window(GLint new_width, GLint new_height);
|
void resize_window(GLint new_width, GLint new_height);
|
||||||
|
|
||||||
void handle_event(struct wiimote_t* wm) {
|
void handle_event(struct wiimote_t* wm) {
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
|
||||||
wiiuse_motion_sensing(wm, 1);
|
wiiuse_motion_sensing(wm, 1);
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
|
}
|
||||||
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
|
||||||
wiiuse_motion_sensing(wm, 0);
|
wiiuse_motion_sensing(wm, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
|
||||||
wiiuse_set_ir(wm, 1);
|
wiiuse_set_ir(wm, 1);
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
}
|
||||||
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
|
||||||
wiiuse_set_ir(wm, 0);
|
wiiuse_set_ir(wm, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {
|
||||||
wiiuse_toggle_rumble(wm);
|
wiiuse_toggle_rumble(wm);
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||||
int level;
|
int level;
|
||||||
@@ -149,10 +154,11 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) {
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) {
|
||||||
if (render_mode == IR)
|
if (render_mode == IR) {
|
||||||
render_mode = TEAPOT;
|
render_mode = TEAPOT;
|
||||||
else
|
} else {
|
||||||
render_mode = IR;
|
render_mode = IR;
|
||||||
|
}
|
||||||
resize_window(width, height);
|
resize_window(width, height);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -167,8 +173,9 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
int can_render() {
|
int can_render() {
|
||||||
/* quick fps limit to ~60fps -- not too fancy, could be better */
|
/* quick fps limit to ~60fps -- not too fancy, could be better */
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (GetTickCount() < (last_render + 16))
|
if (GetTickCount() < (last_render + 16)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
last_render = GetTickCount();
|
last_render = GetTickCount();
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
@@ -182,13 +189,15 @@ int can_render() {
|
|||||||
++now.tv_sec;
|
++now.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now.tv_sec > last_render.tv_sec)
|
if (now.tv_sec > last_render.tv_sec) {
|
||||||
elapsed_usec = ((now.tv_sec - last_render.tv_sec) * 1000000);
|
elapsed_usec = ((now.tv_sec - last_render.tv_sec) * 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
if (now.tv_usec > last_render.tv_usec)
|
if (now.tv_usec > last_render.tv_usec) {
|
||||||
elapsed_usec += now.tv_usec - last_render.tv_usec;
|
elapsed_usec += now.tv_usec - last_render.tv_usec;
|
||||||
else
|
} else {
|
||||||
elapsed_usec += last_render.tv_usec - now.tv_usec;
|
elapsed_usec += last_render.tv_usec - now.tv_usec;
|
||||||
|
}
|
||||||
|
|
||||||
if (time(NULL) > last_sec) {
|
if (time(NULL) > last_sec) {
|
||||||
printf("fps: %i\n", fps);
|
printf("fps: %i\n", fps);
|
||||||
@@ -196,8 +205,9 @@ int can_render() {
|
|||||||
last_sec = time(NULL);
|
last_sec = time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elapsed_usec < 16000)
|
if (elapsed_usec < 16000) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
last_render = now;
|
last_render = now;
|
||||||
++fps;
|
++fps;
|
||||||
@@ -210,8 +220,9 @@ void display() {
|
|||||||
int i, wm;
|
int i, wm;
|
||||||
float size = 5;
|
float size = 5;
|
||||||
|
|
||||||
if (!can_render())
|
if (!can_render()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@@ -233,16 +244,18 @@ void display() {
|
|||||||
/* red ir */
|
/* red ir */
|
||||||
glColor3f(1.0, 0.0, 0.0);
|
glColor3f(1.0, 0.0, 0.0);
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
if (wiimotes[wm]->ir.dot[i].visible)
|
if (wiimotes[wm]->ir.dot[i].visible) {
|
||||||
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size);
|
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* yellow corrected ir */
|
/* yellow corrected ir */
|
||||||
glColor3f(1.0, 1.0, 0.0);
|
glColor3f(1.0, 1.0, 0.0);
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
if (wiimotes[wm]->ir.dot[i].visible)
|
if (wiimotes[wm]->ir.dot[i].visible) {
|
||||||
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size);
|
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* blue cursor */
|
/* blue cursor */
|
||||||
glColor3f(0.0, 0.0, 1.0);
|
glColor3f(0.0, 0.0, 1.0);
|
||||||
@@ -300,8 +313,9 @@ void resize_window(GLint new_width, GLint new_height) {
|
|||||||
width = new_width;
|
width = new_width;
|
||||||
height = new_height;
|
height = new_height;
|
||||||
|
|
||||||
if (new_height == 0)
|
if (new_height == 0) {
|
||||||
new_height = 1;
|
new_height = 1;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
||||||
|
|
||||||
@@ -310,10 +324,11 @@ void resize_window(GLint new_width, GLint new_height) {
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
if (render_mode == IR)
|
if (render_mode == IR) {
|
||||||
gluOrtho2D(0, width, height, 0);
|
gluOrtho2D(0, width, height, 0);
|
||||||
else
|
} else {
|
||||||
gluPerspective(60.0f, (float)new_width / (float)new_height, 0.1f, 100.0f);
|
gluPerspective(60.0f, (float)new_width / (float)new_height, 0.1f, 100.0f);
|
||||||
|
}
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@@ -321,9 +336,10 @@ void resize_window(GLint new_width, GLint new_height) {
|
|||||||
width = new_width;
|
width = new_width;
|
||||||
height = new_height;
|
height = new_height;
|
||||||
|
|
||||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm)
|
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||||
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
@@ -337,12 +353,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
|
|
||||||
wiimotes = wiiuse_init(MAX_WIIMOTES);
|
wiimotes = wiiuse_init(MAX_WIIMOTES);
|
||||||
found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
|
found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
|
||||||
if (!found)
|
if (!found) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
||||||
if (connected)
|
if (connected) {
|
||||||
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
||||||
else {
|
} else {
|
||||||
printf("Failed to connect to any wiimote.\n");
|
printf("Failed to connect to any wiimote.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -379,8 +396,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
height = wiimotes[0]->ir.vres[1];
|
height = wiimotes[0]->ir.vres[1];
|
||||||
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
||||||
|
|
||||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm)
|
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||||
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
||||||
|
}
|
||||||
|
|
||||||
/* set OpenGL stuff */
|
/* set OpenGL stuff */
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@@ -406,21 +424,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
|
|
||||||
if (SDL_PollEvent(&event)) {
|
if (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_VIDEORESIZE:
|
case SDL_VIDEORESIZE: {
|
||||||
{
|
|
||||||
/* resize the window */
|
/* resize the window */
|
||||||
resize_window(event.resize.w, event.resize.h);
|
resize_window(event.resize.w, event.resize.h);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_QUIT:
|
case SDL_QUIT: {
|
||||||
{
|
|
||||||
/* shutdown */
|
/* shutdown */
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
|
wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,57 +58,83 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
printf("\n\n--- EVENT [id %i] ---\n", wm->unid);
|
printf("\n\n--- EVENT [id %i] ---\n", wm->unid);
|
||||||
|
|
||||||
/* if a button is pressed, report it */
|
/* if a button is pressed, report it */
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) printf("A pressed\n");
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) {
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) printf("B pressed\n");
|
printf("A pressed\n");
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) printf("UP pressed\n");
|
}
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) printf("DOWN pressed\n");
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) {
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) printf("LEFT pressed\n");
|
printf("B pressed\n");
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) printf("RIGHT pressed\n");
|
}
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) printf("MINUS pressed\n");
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) printf("PLUS pressed\n");
|
printf("UP pressed\n");
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) printf("ONE pressed\n");
|
}
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) printf("TWO pressed\n");
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
|
||||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) printf("HOME pressed\n");
|
printf("DOWN pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) {
|
||||||
|
printf("LEFT pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) {
|
||||||
|
printf("RIGHT pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
|
||||||
|
printf("MINUS pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
|
||||||
|
printf("PLUS pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||||
|
printf("ONE pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
|
||||||
|
printf("TWO pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) {
|
||||||
|
printf("HOME pressed\n");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pressing minus will tell the wiimote we are no longer interested in movement.
|
* Pressing minus will tell the wiimote we are no longer interested in movement.
|
||||||
* This is useful because it saves battery power.
|
* This is useful because it saves battery power.
|
||||||
*/
|
*/
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
|
||||||
wiiuse_motion_sensing(wm, 0);
|
wiiuse_motion_sensing(wm, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pressing plus will tell the wiimote we are interested in movement.
|
* Pressing plus will tell the wiimote we are interested in movement.
|
||||||
*/
|
*/
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
|
||||||
wiiuse_motion_sensing(wm, 1);
|
wiiuse_motion_sensing(wm, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pressing B will toggle the rumble
|
* Pressing B will toggle the rumble
|
||||||
*
|
*
|
||||||
* if B is pressed but is not held, toggle the rumble
|
* if B is pressed but is not held, toggle the rumble
|
||||||
*/
|
*/
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {
|
||||||
wiiuse_toggle_rumble(wm);
|
wiiuse_toggle_rumble(wm);
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
|
||||||
wiiuse_set_ir(wm, 1);
|
wiiuse_set_ir(wm, 1);
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
}
|
||||||
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
|
||||||
wiiuse_set_ir(wm, 0);
|
wiiuse_set_ir(wm, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Motion+ support
|
* Motion+ support
|
||||||
*/
|
*/
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||||
{
|
if (WIIUSE_USING_EXP(wm)) {
|
||||||
if(WIIUSE_USING_EXP(wm))
|
|
||||||
wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through
|
wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through
|
||||||
else
|
} else {
|
||||||
wiiuse_set_motion_plus(wm, 1); // standalone
|
wiiuse_set_motion_plus(wm, 1); // standalone
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO))
|
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
|
||||||
{
|
|
||||||
wiiuse_set_motion_plus(wm, 0); // off
|
wiiuse_set_motion_plus(wm, 0); // off
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,9 +157,10 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
/* go through each of the 4 possible IR sources */
|
/* go through each of the 4 possible IR sources */
|
||||||
for (; i < 4; ++i) {
|
for (; i < 4; ++i) {
|
||||||
/* check if the source is visible */
|
/* check if the source is visible */
|
||||||
if (wm->ir.dot[i].visible)
|
if (wm->ir.dot[i].visible) {
|
||||||
printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
|
printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
|
printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
|
||||||
printf("IR z distance: %f\n", wm->ir.z);
|
printf("IR z distance: %f\n", wm->ir.z);
|
||||||
@@ -144,8 +171,12 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
/* nunchuk */
|
/* nunchuk */
|
||||||
struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;
|
struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;
|
||||||
|
|
||||||
if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) printf("Nunchuk: C pressed\n");
|
if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) {
|
||||||
if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) printf("Nunchuk: Z pressed\n");
|
printf("Nunchuk: C pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) {
|
||||||
|
printf("Nunchuk: Z pressed\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("nunchuk roll = %f\n", nc->orient.roll);
|
printf("nunchuk roll = %f\n", nc->orient.roll);
|
||||||
printf("nunchuk pitch = %f\n", nc->orient.pitch);
|
printf("nunchuk pitch = %f\n", nc->orient.pitch);
|
||||||
@@ -157,21 +188,51 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
/* classic controller */
|
/* classic controller */
|
||||||
struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic;
|
struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic;
|
||||||
|
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) printf("Classic: ZL pressed\n");
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) {
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) printf("Classic: B pressed\n");
|
printf("Classic: ZL pressed\n");
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) printf("Classic: Y pressed\n");
|
}
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) printf("Classic: A pressed\n");
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) {
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) printf("Classic: X pressed\n");
|
printf("Classic: B pressed\n");
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) printf("Classic: ZR pressed\n");
|
}
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) printf("Classic: LEFT pressed\n");
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) {
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) printf("Classic: UP pressed\n");
|
printf("Classic: Y pressed\n");
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) printf("Classic: RIGHT pressed\n");
|
}
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) printf("Classic: DOWN pressed\n");
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) {
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) printf("Classic: FULL L pressed\n");
|
printf("Classic: A pressed\n");
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) printf("Classic: MINUS pressed\n");
|
}
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) printf("Classic: HOME pressed\n");
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) {
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) printf("Classic: PLUS pressed\n");
|
printf("Classic: X pressed\n");
|
||||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) printf("Classic: FULL R pressed\n");
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) {
|
||||||
|
printf("Classic: ZR pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) {
|
||||||
|
printf("Classic: LEFT pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) {
|
||||||
|
printf("Classic: UP pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) {
|
||||||
|
printf("Classic: RIGHT pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) {
|
||||||
|
printf("Classic: DOWN pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) {
|
||||||
|
printf("Classic: FULL L pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) {
|
||||||
|
printf("Classic: MINUS pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) {
|
||||||
|
printf("Classic: HOME pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) {
|
||||||
|
printf("Classic: PLUS pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) {
|
||||||
|
printf("Classic: FULL R pressed\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("classic L button pressed: %f\n", cc->l_shoulder);
|
printf("classic L button pressed: %f\n", cc->l_shoulder);
|
||||||
printf("classic R button pressed: %f\n", cc->r_shoulder);
|
printf("classic R button pressed: %f\n", cc->r_shoulder);
|
||||||
@@ -183,15 +244,33 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
/* guitar hero 3 guitar */
|
/* guitar hero 3 guitar */
|
||||||
struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;
|
struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;
|
||||||
|
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) printf("Guitar: Strum Up pressed\n");
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) {
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN)) printf("Guitar: Strum Down pressed\n");
|
printf("Guitar: Strum Up pressed\n");
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) printf("Guitar: Yellow pressed\n");
|
}
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) printf("Guitar: Green pressed\n");
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN)) {
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) printf("Guitar: Blue pressed\n");
|
printf("Guitar: Strum Down pressed\n");
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) printf("Guitar: Red pressed\n");
|
}
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) printf("Guitar: Orange pressed\n");
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) {
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) printf("Guitar: Plus pressed\n");
|
printf("Guitar: Yellow pressed\n");
|
||||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) printf("Guitar: Minus pressed\n");
|
}
|
||||||
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) {
|
||||||
|
printf("Guitar: Green pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) {
|
||||||
|
printf("Guitar: Blue pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) {
|
||||||
|
printf("Guitar: Red pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) {
|
||||||
|
printf("Guitar: Orange pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) {
|
||||||
|
printf("Guitar: Plus pressed\n");
|
||||||
|
}
|
||||||
|
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) {
|
||||||
|
printf("Guitar: Minus pressed\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("Guitar whammy bar: %f\n", gh3->whammy_bar);
|
printf("Guitar whammy bar: %f\n", gh3->whammy_bar);
|
||||||
printf("Guitar joystick angle: %f\n", gh3->js.ang);
|
printf("Guitar joystick angle: %f\n", gh3->js.ang);
|
||||||
@@ -208,8 +287,7 @@ void handle_event(struct wiimote_t* wm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wm->exp.type == EXP_MOTION_PLUS ||
|
if (wm->exp.type == EXP_MOTION_PLUS ||
|
||||||
wm->exp.type == EXP_MOTION_PLUS_NUNCHUK)
|
wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) {
|
||||||
{
|
|
||||||
printf("Motion+ angular rates (deg/sec): pitch:%03.2f roll:%03.2f yaw:%03.2f\n",
|
printf("Motion+ angular rates (deg/sec): pitch:%03.2f roll:%03.2f yaw:%03.2f\n",
|
||||||
wm->exp.mp.angle_rate_gyro.pitch,
|
wm->exp.mp.angle_rate_gyro.pitch,
|
||||||
wm->exp.mp.angle_rate_gyro.roll,
|
wm->exp.mp.angle_rate_gyro.roll,
|
||||||
@@ -241,8 +319,9 @@ void handle_read(struct wiimote_t* wm, byte* data, unsigned short len) {
|
|||||||
printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
|
printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
|
||||||
printf("finished read of size %i\n", len);
|
printf("finished read of size %i\n", len);
|
||||||
for (; i < len; ++i) {
|
for (; i < len; ++i) {
|
||||||
if (!(i%16))
|
if (!(i % 16)) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
}
|
||||||
printf("%x ", data[i]);
|
printf("%x ", data[i]);
|
||||||
}
|
}
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
@@ -296,12 +375,15 @@ void test(struct wiimote_t* wm, byte* data, unsigned short len) {
|
|||||||
|
|
||||||
short any_wiimote_connected(wiimote** wm, int wiimotes) {
|
short any_wiimote_connected(wiimote** wm, int wiimotes) {
|
||||||
int i;
|
int i;
|
||||||
if(!wm) return 0;
|
if (!wm) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < wiimotes; i++) {
|
for (i = 0; i < wiimotes; i++) {
|
||||||
if(wm[i] && WIIMOTE_IS_CONNECTED(wm[i]))
|
if (wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -351,9 +433,9 @@ int main(int argc, char** argv) {
|
|||||||
* This will return the number of established connections to the found wiimotes.
|
* This will return the number of established connections to the found wiimotes.
|
||||||
*/
|
*/
|
||||||
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
||||||
if (connected)
|
if (connected) {
|
||||||
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
||||||
else {
|
} else {
|
||||||
printf("Failed to connect to any wiimote.\n");
|
printf("Failed to connect to any wiimote.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user