Unix line endings and remove trailing spaces
This commit is contained in:
@@ -6,7 +6,7 @@ if(SDL_FOUND AND OPENGL_FOUND AND GLUT_FOUND)
|
||||
include_directories(../src ${SDL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIRS})
|
||||
add_executable(wiiuseexample-sdl sdl.c)
|
||||
target_link_libraries(wiiuseexample-sdl wiiuse ${SDL_LIBRARY} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})
|
||||
|
||||
|
||||
if(INSTALL_EXAMPLES)
|
||||
install(TARGETS wiiuseexample-sdl
|
||||
RUNTIME DESTINATION bin COMPONENT examples)
|
||||
|
||||
@@ -55,14 +55,14 @@ wiimote** wiimotes = NULL;
|
||||
|
||||
int last_dots[4][2] = {{0}};
|
||||
int xcoord = 0;
|
||||
int ycoord = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
int ycoord = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
DWORD last_render;
|
||||
#else
|
||||
struct timeval last_render;
|
||||
int last_sec = 0;
|
||||
int fps = 0;
|
||||
int last_sec = 0;
|
||||
int fps = 0;
|
||||
#endif
|
||||
|
||||
enum render_mode_t {
|
||||
@@ -125,8 +125,8 @@ void handle_event(struct wiimote_t* wm) {
|
||||
wiiuse_set_ir(wm, 1);
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
||||
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);
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||
@@ -161,8 +161,8 @@ int can_render() {
|
||||
/* quick fps limit to ~60fps -- not too fancy, could be better */
|
||||
#ifdef WIN32
|
||||
if (GetTickCount() < (last_render + 16))
|
||||
return 0;
|
||||
last_render = GetTickCount();
|
||||
return 0;
|
||||
last_render = GetTickCount();
|
||||
return 1;
|
||||
#else
|
||||
struct timeval now;
|
||||
@@ -204,23 +204,23 @@ void display() {
|
||||
float size = 5;
|
||||
|
||||
if (!can_render())
|
||||
return;
|
||||
return;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glLoadIdentity();
|
||||
|
||||
if (render_mode == IR) {
|
||||
/* draw the IR stuff */
|
||||
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
/* green center */
|
||||
glColor3f(0.0, 1.0, 0.0);
|
||||
DRAW_TRIANGLE(width/2, height/2, 0, size);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
/* green center */
|
||||
glColor3f(0.0, 1.0, 0.0);
|
||||
DRAW_TRIANGLE(width/2, height/2, 0, size);
|
||||
glEnd();
|
||||
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||
glBegin(GL_TRIANGLES);
|
||||
/* red ir */
|
||||
@@ -258,7 +258,7 @@ void display() {
|
||||
|
||||
|
||||
glutSolidTeapot(1);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
@@ -287,8 +287,8 @@ void set_material(struct material_t* mptr) {
|
||||
}
|
||||
|
||||
|
||||
void resize_window(GLint new_width, GLint new_height) {
|
||||
int wm;
|
||||
void resize_window(GLint new_width, GLint new_height) {
|
||||
int wm;
|
||||
|
||||
width = new_width;
|
||||
height = new_height;
|
||||
@@ -313,8 +313,8 @@ void resize_window(GLint new_width, GLint new_height) {
|
||||
|
||||
width = new_width;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ int main(int argc, char** argv) {
|
||||
#else
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
#endif
|
||||
int found, connected;
|
||||
int found, connected;
|
||||
int wm;
|
||||
|
||||
//printf("wiiuse version = %s\n", wiiuse_version());
|
||||
@@ -340,7 +340,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
return 0;
|
||||
}
|
||||
wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1 | WIIMOTE_LED_4);
|
||||
wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4);
|
||||
wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4);
|
||||
wiiuse_rumble(wiimotes[0], 1);
|
||||
|
||||
#ifndef WIN32
|
||||
@@ -350,29 +350,29 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
#endif
|
||||
|
||||
wiiuse_rumble(wiimotes[0], 0);
|
||||
|
||||
/* enable IR and motion sensing for all wiimotes */
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||
|
||||
/* enable IR and motion sensing for all wiimotes */
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||
wiiuse_motion_sensing(wiimotes[wm], 1);
|
||||
wiiuse_set_ir(wiimotes[wm], 1);
|
||||
}
|
||||
wiiuse_set_ir(wiimotes[wm], 1);
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("Failed to initialize SDL: %s\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption("wiiuse SDL IR Example", "wiiuse SDL IR Example");
|
||||
|
||||
SDL_WM_SetCaption("wiiuse SDL IR Example", "wiiuse SDL IR Example");
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
|
||||
/* set window size */
|
||||
width = wiimotes[0]->ir.vres[0];
|
||||
height = wiimotes[0]->ir.vres[1];
|
||||
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
||||
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm)
|
||||
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
||||
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm)
|
||||
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
||||
|
||||
/* set OpenGL stuff */
|
||||
@@ -388,15 +388,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
/* set the size of the window */
|
||||
resize_window(width, height);
|
||||
|
||||
display();
|
||||
|
||||
#ifdef WIN32
|
||||
display();
|
||||
|
||||
#ifdef WIN32
|
||||
last_render = GetTickCount();
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
SDL_Event event;
|
||||
|
||||
|
||||
if (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_VIDEORESIZE:
|
||||
@@ -437,6 +437,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
}
|
||||
|
||||
display();
|
||||
display();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,450 +1,450 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Example using the wiiuse API.
|
||||
*
|
||||
* This file is an example of how to use the wiiuse library.
|
||||
*/
|
||||
|
||||
#include <stdio.h> // for printf
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h> // for usleep
|
||||
#endif
|
||||
|
||||
#include "wiiuse.h" // for wiimote_t, classic_ctrl_t, etc
|
||||
|
||||
|
||||
#define MAX_WIIMOTES 4
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles an event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* This function is called automatically by the wiiuse library when an
|
||||
* event occurs on the specified wiimote.
|
||||
*/
|
||||
void handle_event(struct wiimote_t* wm) {
|
||||
printf("\n\n--- EVENT [id %i] ---\n", wm->unid);
|
||||
|
||||
/* if a button is pressed, report it */
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) printf("A pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) printf("B 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_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.
|
||||
* This is useful because it saves battery power.
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
|
||||
wiiuse_motion_sensing(wm, 0);
|
||||
|
||||
/*
|
||||
* Pressing plus will tell the wiimote we are interested in movement.
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
|
||||
wiiuse_motion_sensing(wm, 1);
|
||||
|
||||
/*
|
||||
* Pressing B will toggle the rumble
|
||||
*
|
||||
* if B is pressed but is not held, toggle the rumble
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
|
||||
wiiuse_toggle_rumble(wm);
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
|
||||
wiiuse_set_ir(wm, 1);
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
||||
wiiuse_set_ir(wm, 0);
|
||||
|
||||
/* if the accelerometer is turned on then print angles */
|
||||
if (WIIUSE_USING_ACC(wm)) {
|
||||
printf("wiimote roll = %f [%f]\n", wm->orient.roll, wm->orient.a_roll);
|
||||
printf("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch);
|
||||
printf("wiimote yaw = %f\n", wm->orient.yaw);
|
||||
}
|
||||
|
||||
/*
|
||||
* If IR tracking is enabled then print the coordinates
|
||||
* on the virtual screen that the wiimote is pointing to.
|
||||
*
|
||||
* Also make sure that we see at least 1 dot.
|
||||
*/
|
||||
if (WIIUSE_USING_IR(wm)) {
|
||||
int i = 0;
|
||||
|
||||
/* go through each of the 4 possible IR sources */
|
||||
for (; i < 4; ++i) {
|
||||
/* check if the source is 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 cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
|
||||
printf("IR z distance: %f\n", wm->ir.z);
|
||||
}
|
||||
|
||||
/* show events specific to supported expansions */
|
||||
if (wm->exp.type == EXP_NUNCHUK) {
|
||||
/* 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_Z)) printf("Nunchuk: Z pressed\n");
|
||||
|
||||
printf("nunchuk roll = %f\n", nc->orient.roll);
|
||||
printf("nunchuk pitch = %f\n", nc->orient.pitch);
|
||||
printf("nunchuk yaw = %f\n", nc->orient.yaw);
|
||||
|
||||
printf("nunchuk joystick angle: %f\n", nc->js.ang);
|
||||
printf("nunchuk joystick magnitude: %f\n", nc->js.mag);
|
||||
} else if (wm->exp.type == EXP_CLASSIC) {
|
||||
/* classic controller */
|
||||
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_B)) printf("Classic: B 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_X)) printf("Classic: X 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 R button pressed: %f\n", cc->r_shoulder);
|
||||
printf("classic left joystick angle: %f\n", cc->ljs.ang);
|
||||
printf("classic left joystick magnitude: %f\n", cc->ljs.mag);
|
||||
printf("classic right joystick angle: %f\n", cc->rjs.ang);
|
||||
printf("classic right joystick magnitude: %f\n", cc->rjs.mag);
|
||||
} else if (wm->exp.type == EXP_GUITAR_HERO_3) {
|
||||
/* guitar hero 3 guitar */
|
||||
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_DOWN)) printf("Guitar: Strum Down 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_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 joystick angle: %f\n", gh3->js.ang);
|
||||
printf("Guitar joystick magnitude: %f\n", gh3->js.mag);
|
||||
} else if (wm->exp.type == EXP_WII_BOARD) {
|
||||
/* wii balance board */
|
||||
struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb;
|
||||
float total = wb->tl + wb->tr + wb->bl + wb->br;
|
||||
float x = ((wb->tr + wb->br) / total) * 2 - 1;
|
||||
float y = ((wb->tl + wb->tr) / total) * 2 - 1;
|
||||
printf("Weight: %f kg @ (%f, %f)\n", total, x, y);
|
||||
//printf("Interpolated weight: TL:%f TR:%f BL:%f BR:%f\n", wb->tl, wb->tr, wb->bl, wb->br);
|
||||
//printf("Raw: TL:%d TR:%d BL:%d BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Pointer to the filled data block.
|
||||
* @param len Length in bytes of the data block.
|
||||
*
|
||||
* This function is called automatically by the wiiuse library when
|
||||
* the wiimote has returned the full data requested by a previous
|
||||
* call to wiiuse_read_data().
|
||||
*
|
||||
* You can read data on the wiimote, such as Mii data, if
|
||||
* you know the offset address and the length.
|
||||
*
|
||||
* The \a data pointer was specified on the call to wiiuse_read_data().
|
||||
* At the time of this function being called, it is not safe to deallocate
|
||||
* this buffer.
|
||||
*/
|
||||
void handle_read(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
int i = 0;
|
||||
|
||||
printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
|
||||
printf("finished read of size %i\n", len);
|
||||
for (; i < len; ++i) {
|
||||
if (!(i%16))
|
||||
printf("\n");
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a controller status event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param attachment Is there an attachment? (1 for yes, 0 for no)
|
||||
* @param speaker Is the speaker enabled? (1 for yes, 0 for no)
|
||||
* @param ir Is the IR support enabled? (1 for yes, 0 for no)
|
||||
* @param led What LEDs are lit.
|
||||
* @param battery_level Battery level, between 0.0 (0%) and 1.0 (100%).
|
||||
*
|
||||
* This occurs when either the controller status changed
|
||||
* or the controller status was requested explicitly by
|
||||
* wiiuse_status().
|
||||
*
|
||||
* One reason the status can change is if the nunchuk was
|
||||
* inserted or removed from the expansion port.
|
||||
*/
|
||||
void handle_ctrl_status(struct wiimote_t* wm) {
|
||||
printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid);
|
||||
|
||||
printf("attachment: %i\n", wm->exp.type);
|
||||
printf("speaker: %i\n", WIIUSE_USING_SPEAKER(wm));
|
||||
printf("ir: %i\n", WIIUSE_USING_IR(wm));
|
||||
printf("leds: %i %i %i %i\n", WIIUSE_IS_LED_SET(wm, 1), WIIUSE_IS_LED_SET(wm, 2), WIIUSE_IS_LED_SET(wm, 3), WIIUSE_IS_LED_SET(wm, 4));
|
||||
printf("battery: %f %%\n", wm->battery_level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a disconnection event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* This can happen if the POWER button is pressed, or
|
||||
* if the connection is interrupted.
|
||||
*/
|
||||
void handle_disconnect(wiimote* wm) {
|
||||
printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", wm->unid);
|
||||
}
|
||||
|
||||
|
||||
void test(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
printf("test: %i [%x %x %x %x]\n", len, data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief main()
|
||||
*
|
||||
* Connect to up to two wiimotes and print any events
|
||||
* that occur on either device.
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
wiimote** wiimotes;
|
||||
int found, connected;
|
||||
|
||||
/*
|
||||
* Initialize an array of wiimote objects.
|
||||
*
|
||||
* The parameter is the number of wiimotes I want to create.
|
||||
*/
|
||||
wiimotes = wiiuse_init(MAX_WIIMOTES);
|
||||
|
||||
/*
|
||||
* Find wiimote devices
|
||||
*
|
||||
* Now we need to find some wiimotes.
|
||||
* Give the function the wiimote array we created, and tell it there
|
||||
* are MAX_WIIMOTES wiimotes we are interested in.
|
||||
*
|
||||
* Set the timeout to be 5 seconds.
|
||||
*
|
||||
* This will return the number of actual wiimotes that are in discovery mode.
|
||||
*/
|
||||
found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
|
||||
if (!found) {
|
||||
printf ("No wiimotes found.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect to the wiimotes
|
||||
*
|
||||
* Now that we found some wiimotes, connect to them.
|
||||
* Give the function the wiimote array and the number
|
||||
* of wiimote devices we found.
|
||||
*
|
||||
* This will return the number of established connections to the found wiimotes.
|
||||
*/
|
||||
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
||||
if (connected)
|
||||
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
||||
else {
|
||||
printf("Failed to connect to any wiimote.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now set the LEDs and rumble for a second so it's easy
|
||||
* to tell which wiimotes are connected (just like the wii does).
|
||||
*/
|
||||
wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
|
||||
wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2);
|
||||
wiiuse_set_leds(wiimotes[2], WIIMOTE_LED_3);
|
||||
wiiuse_set_leds(wiimotes[3], WIIMOTE_LED_4);
|
||||
wiiuse_rumble(wiimotes[0], 1);
|
||||
wiiuse_rumble(wiimotes[1], 1);
|
||||
|
||||
#ifndef WIN32
|
||||
usleep(200000);
|
||||
#else
|
||||
Sleep(200);
|
||||
#endif
|
||||
|
||||
wiiuse_rumble(wiimotes[0], 0);
|
||||
wiiuse_rumble(wiimotes[1], 0);
|
||||
|
||||
/*
|
||||
* Maybe I'm interested in the battery power of the 0th
|
||||
* wiimote. This should be WIIMOTE_ID_1 but to be sure
|
||||
* you can get the wiimote assoicated with WIIMOTE_ID_1
|
||||
* using the wiiuse_get_by_id() function.
|
||||
*
|
||||
* A status request will return other things too, like
|
||||
* if any expansions are plugged into the wiimote or
|
||||
* what LEDs are lit.
|
||||
*/
|
||||
//wiiuse_status(wiimotes[0]);
|
||||
|
||||
/*
|
||||
* This is the main loop
|
||||
*
|
||||
* wiiuse_poll() needs to be called with the wiimote array
|
||||
* and the number of wiimote structures in that array
|
||||
* (it doesn't matter if some of those wiimotes are not used
|
||||
* or are not connected).
|
||||
*
|
||||
* This function will set the event flag for each wiimote
|
||||
* when the wiimote has things to report.
|
||||
*/
|
||||
while (1) {
|
||||
if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
|
||||
/*
|
||||
* This happens if something happened on any wiimote.
|
||||
* So go through each one and check if anything happened.
|
||||
*/
|
||||
int i = 0;
|
||||
for (; i < MAX_WIIMOTES; ++i) {
|
||||
switch (wiimotes[i]->event) {
|
||||
case WIIUSE_EVENT:
|
||||
/* a generic event occured */
|
||||
handle_event(wiimotes[i]);
|
||||
break;
|
||||
|
||||
case WIIUSE_STATUS:
|
||||
/* a status event occured */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
break;
|
||||
|
||||
case WIIUSE_DISCONNECT:
|
||||
case WIIUSE_UNEXPECTED_DISCONNECT:
|
||||
/* the wiimote disconnected */
|
||||
handle_disconnect(wiimotes[i]);
|
||||
break;
|
||||
|
||||
case WIIUSE_READ_DATA:
|
||||
/*
|
||||
* Data we requested to read was returned.
|
||||
* Take a look at wiimotes[i]->read_req
|
||||
* for the data.
|
||||
*/
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_INSERTED:
|
||||
/*
|
||||
* a nunchuk was inserted
|
||||
* This is a good place to set any nunchuk specific
|
||||
* threshold values. By default they are the same
|
||||
* as the wiimote.
|
||||
*/
|
||||
//wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f);
|
||||
//wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100);
|
||||
printf("Nunchuk inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_CLASSIC_CTRL_INSERTED:
|
||||
printf("Classic controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_WII_BOARD_CTRL_INSERTED:
|
||||
printf("Balance board controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
|
||||
/* some expansion was inserted */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
printf("Guitar Hero 3 controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_REMOVED:
|
||||
case WIIUSE_CLASSIC_CTRL_REMOVED:
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
|
||||
case WIIUSE_WII_BOARD_CTRL_REMOVED:
|
||||
/* some expansion was removed */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
printf("An expansion was removed.\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Disconnect the wiimotes
|
||||
*/
|
||||
wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Example using the wiiuse API.
|
||||
*
|
||||
* This file is an example of how to use the wiiuse library.
|
||||
*/
|
||||
|
||||
#include <stdio.h> // for printf
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h> // for usleep
|
||||
#endif
|
||||
|
||||
#include "wiiuse.h" // for wiimote_t, classic_ctrl_t, etc
|
||||
|
||||
|
||||
#define MAX_WIIMOTES 4
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles an event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* This function is called automatically by the wiiuse library when an
|
||||
* event occurs on the specified wiimote.
|
||||
*/
|
||||
void handle_event(struct wiimote_t* wm) {
|
||||
printf("\n\n--- EVENT [id %i] ---\n", wm->unid);
|
||||
|
||||
/* if a button is pressed, report it */
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) printf("A pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) printf("B 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_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.
|
||||
* This is useful because it saves battery power.
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
|
||||
wiiuse_motion_sensing(wm, 0);
|
||||
|
||||
/*
|
||||
* Pressing plus will tell the wiimote we are interested in movement.
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
|
||||
wiiuse_motion_sensing(wm, 1);
|
||||
|
||||
/*
|
||||
* Pressing B will toggle the rumble
|
||||
*
|
||||
* if B is pressed but is not held, toggle the rumble
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
|
||||
wiiuse_toggle_rumble(wm);
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
|
||||
wiiuse_set_ir(wm, 1);
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
||||
wiiuse_set_ir(wm, 0);
|
||||
|
||||
/* if the accelerometer is turned on then print angles */
|
||||
if (WIIUSE_USING_ACC(wm)) {
|
||||
printf("wiimote roll = %f [%f]\n", wm->orient.roll, wm->orient.a_roll);
|
||||
printf("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch);
|
||||
printf("wiimote yaw = %f\n", wm->orient.yaw);
|
||||
}
|
||||
|
||||
/*
|
||||
* If IR tracking is enabled then print the coordinates
|
||||
* on the virtual screen that the wiimote is pointing to.
|
||||
*
|
||||
* Also make sure that we see at least 1 dot.
|
||||
*/
|
||||
if (WIIUSE_USING_IR(wm)) {
|
||||
int i = 0;
|
||||
|
||||
/* go through each of the 4 possible IR sources */
|
||||
for (; i < 4; ++i) {
|
||||
/* check if the source is 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 cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
|
||||
printf("IR z distance: %f\n", wm->ir.z);
|
||||
}
|
||||
|
||||
/* show events specific to supported expansions */
|
||||
if (wm->exp.type == EXP_NUNCHUK) {
|
||||
/* 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_Z)) printf("Nunchuk: Z pressed\n");
|
||||
|
||||
printf("nunchuk roll = %f\n", nc->orient.roll);
|
||||
printf("nunchuk pitch = %f\n", nc->orient.pitch);
|
||||
printf("nunchuk yaw = %f\n", nc->orient.yaw);
|
||||
|
||||
printf("nunchuk joystick angle: %f\n", nc->js.ang);
|
||||
printf("nunchuk joystick magnitude: %f\n", nc->js.mag);
|
||||
} else if (wm->exp.type == EXP_CLASSIC) {
|
||||
/* classic controller */
|
||||
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_B)) printf("Classic: B 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_X)) printf("Classic: X 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 R button pressed: %f\n", cc->r_shoulder);
|
||||
printf("classic left joystick angle: %f\n", cc->ljs.ang);
|
||||
printf("classic left joystick magnitude: %f\n", cc->ljs.mag);
|
||||
printf("classic right joystick angle: %f\n", cc->rjs.ang);
|
||||
printf("classic right joystick magnitude: %f\n", cc->rjs.mag);
|
||||
} else if (wm->exp.type == EXP_GUITAR_HERO_3) {
|
||||
/* guitar hero 3 guitar */
|
||||
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_DOWN)) printf("Guitar: Strum Down 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_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 joystick angle: %f\n", gh3->js.ang);
|
||||
printf("Guitar joystick magnitude: %f\n", gh3->js.mag);
|
||||
} else if (wm->exp.type == EXP_WII_BOARD) {
|
||||
/* wii balance board */
|
||||
struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb;
|
||||
float total = wb->tl + wb->tr + wb->bl + wb->br;
|
||||
float x = ((wb->tr + wb->br) / total) * 2 - 1;
|
||||
float y = ((wb->tl + wb->tr) / total) * 2 - 1;
|
||||
printf("Weight: %f kg @ (%f, %f)\n", total, x, y);
|
||||
//printf("Interpolated weight: TL:%f TR:%f BL:%f BR:%f\n", wb->tl, wb->tr, wb->bl, wb->br);
|
||||
//printf("Raw: TL:%d TR:%d BL:%d BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Pointer to the filled data block.
|
||||
* @param len Length in bytes of the data block.
|
||||
*
|
||||
* This function is called automatically by the wiiuse library when
|
||||
* the wiimote has returned the full data requested by a previous
|
||||
* call to wiiuse_read_data().
|
||||
*
|
||||
* You can read data on the wiimote, such as Mii data, if
|
||||
* you know the offset address and the length.
|
||||
*
|
||||
* The \a data pointer was specified on the call to wiiuse_read_data().
|
||||
* At the time of this function being called, it is not safe to deallocate
|
||||
* this buffer.
|
||||
*/
|
||||
void handle_read(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
int i = 0;
|
||||
|
||||
printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
|
||||
printf("finished read of size %i\n", len);
|
||||
for (; i < len; ++i) {
|
||||
if (!(i%16))
|
||||
printf("\n");
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a controller status event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param attachment Is there an attachment? (1 for yes, 0 for no)
|
||||
* @param speaker Is the speaker enabled? (1 for yes, 0 for no)
|
||||
* @param ir Is the IR support enabled? (1 for yes, 0 for no)
|
||||
* @param led What LEDs are lit.
|
||||
* @param battery_level Battery level, between 0.0 (0%) and 1.0 (100%).
|
||||
*
|
||||
* This occurs when either the controller status changed
|
||||
* or the controller status was requested explicitly by
|
||||
* wiiuse_status().
|
||||
*
|
||||
* One reason the status can change is if the nunchuk was
|
||||
* inserted or removed from the expansion port.
|
||||
*/
|
||||
void handle_ctrl_status(struct wiimote_t* wm) {
|
||||
printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid);
|
||||
|
||||
printf("attachment: %i\n", wm->exp.type);
|
||||
printf("speaker: %i\n", WIIUSE_USING_SPEAKER(wm));
|
||||
printf("ir: %i\n", WIIUSE_USING_IR(wm));
|
||||
printf("leds: %i %i %i %i\n", WIIUSE_IS_LED_SET(wm, 1), WIIUSE_IS_LED_SET(wm, 2), WIIUSE_IS_LED_SET(wm, 3), WIIUSE_IS_LED_SET(wm, 4));
|
||||
printf("battery: %f %%\n", wm->battery_level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a disconnection event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* This can happen if the POWER button is pressed, or
|
||||
* if the connection is interrupted.
|
||||
*/
|
||||
void handle_disconnect(wiimote* wm) {
|
||||
printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", wm->unid);
|
||||
}
|
||||
|
||||
|
||||
void test(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
printf("test: %i [%x %x %x %x]\n", len, data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief main()
|
||||
*
|
||||
* Connect to up to two wiimotes and print any events
|
||||
* that occur on either device.
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
wiimote** wiimotes;
|
||||
int found, connected;
|
||||
|
||||
/*
|
||||
* Initialize an array of wiimote objects.
|
||||
*
|
||||
* The parameter is the number of wiimotes I want to create.
|
||||
*/
|
||||
wiimotes = wiiuse_init(MAX_WIIMOTES);
|
||||
|
||||
/*
|
||||
* Find wiimote devices
|
||||
*
|
||||
* Now we need to find some wiimotes.
|
||||
* Give the function the wiimote array we created, and tell it there
|
||||
* are MAX_WIIMOTES wiimotes we are interested in.
|
||||
*
|
||||
* Set the timeout to be 5 seconds.
|
||||
*
|
||||
* This will return the number of actual wiimotes that are in discovery mode.
|
||||
*/
|
||||
found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
|
||||
if (!found) {
|
||||
printf ("No wiimotes found.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect to the wiimotes
|
||||
*
|
||||
* Now that we found some wiimotes, connect to them.
|
||||
* Give the function the wiimote array and the number
|
||||
* of wiimote devices we found.
|
||||
*
|
||||
* This will return the number of established connections to the found wiimotes.
|
||||
*/
|
||||
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
||||
if (connected)
|
||||
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
||||
else {
|
||||
printf("Failed to connect to any wiimote.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now set the LEDs and rumble for a second so it's easy
|
||||
* to tell which wiimotes are connected (just like the wii does).
|
||||
*/
|
||||
wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
|
||||
wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2);
|
||||
wiiuse_set_leds(wiimotes[2], WIIMOTE_LED_3);
|
||||
wiiuse_set_leds(wiimotes[3], WIIMOTE_LED_4);
|
||||
wiiuse_rumble(wiimotes[0], 1);
|
||||
wiiuse_rumble(wiimotes[1], 1);
|
||||
|
||||
#ifndef WIN32
|
||||
usleep(200000);
|
||||
#else
|
||||
Sleep(200);
|
||||
#endif
|
||||
|
||||
wiiuse_rumble(wiimotes[0], 0);
|
||||
wiiuse_rumble(wiimotes[1], 0);
|
||||
|
||||
/*
|
||||
* Maybe I'm interested in the battery power of the 0th
|
||||
* wiimote. This should be WIIMOTE_ID_1 but to be sure
|
||||
* you can get the wiimote assoicated with WIIMOTE_ID_1
|
||||
* using the wiiuse_get_by_id() function.
|
||||
*
|
||||
* A status request will return other things too, like
|
||||
* if any expansions are plugged into the wiimote or
|
||||
* what LEDs are lit.
|
||||
*/
|
||||
//wiiuse_status(wiimotes[0]);
|
||||
|
||||
/*
|
||||
* This is the main loop
|
||||
*
|
||||
* wiiuse_poll() needs to be called with the wiimote array
|
||||
* and the number of wiimote structures in that array
|
||||
* (it doesn't matter if some of those wiimotes are not used
|
||||
* or are not connected).
|
||||
*
|
||||
* This function will set the event flag for each wiimote
|
||||
* when the wiimote has things to report.
|
||||
*/
|
||||
while (1) {
|
||||
if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
|
||||
/*
|
||||
* This happens if something happened on any wiimote.
|
||||
* So go through each one and check if anything happened.
|
||||
*/
|
||||
int i = 0;
|
||||
for (; i < MAX_WIIMOTES; ++i) {
|
||||
switch (wiimotes[i]->event) {
|
||||
case WIIUSE_EVENT:
|
||||
/* a generic event occured */
|
||||
handle_event(wiimotes[i]);
|
||||
break;
|
||||
|
||||
case WIIUSE_STATUS:
|
||||
/* a status event occured */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
break;
|
||||
|
||||
case WIIUSE_DISCONNECT:
|
||||
case WIIUSE_UNEXPECTED_DISCONNECT:
|
||||
/* the wiimote disconnected */
|
||||
handle_disconnect(wiimotes[i]);
|
||||
break;
|
||||
|
||||
case WIIUSE_READ_DATA:
|
||||
/*
|
||||
* Data we requested to read was returned.
|
||||
* Take a look at wiimotes[i]->read_req
|
||||
* for the data.
|
||||
*/
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_INSERTED:
|
||||
/*
|
||||
* a nunchuk was inserted
|
||||
* This is a good place to set any nunchuk specific
|
||||
* threshold values. By default they are the same
|
||||
* as the wiimote.
|
||||
*/
|
||||
//wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f);
|
||||
//wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100);
|
||||
printf("Nunchuk inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_CLASSIC_CTRL_INSERTED:
|
||||
printf("Classic controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_WII_BOARD_CTRL_INSERTED:
|
||||
printf("Balance board controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
|
||||
/* some expansion was inserted */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
printf("Guitar Hero 3 controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_REMOVED:
|
||||
case WIIUSE_CLASSIC_CTRL_REMOVED:
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
|
||||
case WIIUSE_WII_BOARD_CTRL_REMOVED:
|
||||
/* some expansion was removed */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
printf("An expansion was removed.\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Disconnect the wiimotes
|
||||
*/
|
||||
wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ set(SOURCES
|
||||
wiiboard.h)
|
||||
set(API
|
||||
wiiuse.h)
|
||||
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND SOURCES io_win.c)
|
||||
set(CMAKE_DEBUG_POSTFIX _debug)
|
||||
|
||||
@@ -1,247 +1,247 @@
|
||||
// ISO C9x compliant stdint.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// Copyright (c) 2006-2008 Alexander Chemeris
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The name of the author may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_STDINT_H_ // [
|
||||
#define _MSC_STDINT_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
|
||||
// or compiler give many errors like this:
|
||||
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// 7.18.1 Integer types
|
||||
|
||||
// 7.18.1.1 Exact-width integer types
|
||||
|
||||
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
|
||||
// 7.18.1.2 Minimum-width integer types
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
// 7.18.1.3 Fastest minimum-width integer types
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
|
||||
// 7.18.2 Limits of specified-width integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
|
||||
|
||||
// 7.18.2.1 Limits of exact-width integer types
|
||||
#define INT8_MIN ((int8_t)_I8_MIN)
|
||||
#define INT8_MAX _I8_MAX
|
||||
#define INT16_MIN ((int16_t)_I16_MIN)
|
||||
#define INT16_MAX _I16_MAX
|
||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
||||
#define INT32_MAX _I32_MAX
|
||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
|
||||
// 7.18.2.2 Limits of minimum-width integer types
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX _UI16_MAX
|
||||
|
||||
#endif // __STDC_LIMIT_MACROS ]
|
||||
|
||||
|
||||
// 7.18.4 Limits of other integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
|
||||
|
||||
// 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
#define INT8_C(val) val##i8
|
||||
#define INT16_C(val) val##i16
|
||||
#define INT32_C(val) val##i32
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
#define UINT8_C(val) val##ui8
|
||||
#define UINT16_C(val) val##ui16
|
||||
#define UINT32_C(val) val##ui32
|
||||
#define UINT64_C(val) val##ui64
|
||||
|
||||
// 7.18.4.2 Macros for greatest-width integer constants
|
||||
#define INTMAX_C INT64_C
|
||||
#define UINTMAX_C UINT64_C
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
||||
|
||||
#endif // _MSC_STDINT_H_ ]
|
||||
// ISO C9x compliant stdint.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// Copyright (c) 2006-2008 Alexander Chemeris
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The name of the author may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_STDINT_H_ // [
|
||||
#define _MSC_STDINT_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
|
||||
// or compiler give many errors like this:
|
||||
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// 7.18.1 Integer types
|
||||
|
||||
// 7.18.1.1 Exact-width integer types
|
||||
|
||||
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
|
||||
// 7.18.1.2 Minimum-width integer types
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
// 7.18.1.3 Fastest minimum-width integer types
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
|
||||
// 7.18.2 Limits of specified-width integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
|
||||
|
||||
// 7.18.2.1 Limits of exact-width integer types
|
||||
#define INT8_MIN ((int8_t)_I8_MIN)
|
||||
#define INT8_MAX _I8_MAX
|
||||
#define INT16_MIN ((int16_t)_I16_MIN)
|
||||
#define INT16_MAX _I16_MAX
|
||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
||||
#define INT32_MAX _I32_MAX
|
||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
|
||||
// 7.18.2.2 Limits of minimum-width integer types
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX _UI16_MAX
|
||||
|
||||
#endif // __STDC_LIMIT_MACROS ]
|
||||
|
||||
|
||||
// 7.18.4 Limits of other integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
|
||||
|
||||
// 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
#define INT8_C(val) val##i8
|
||||
#define INT16_C(val) val##i16
|
||||
#define INT32_C(val) val##i32
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
#define UINT8_C(val) val##ui8
|
||||
#define UINT16_C(val) val##ui16
|
||||
#define UINT32_C(val) val##ui32
|
||||
#define UINT64_C(val) val##ui64
|
||||
|
||||
// 7.18.4.2 Macros for greatest-width integer constants
|
||||
#define INTMAX_C INT64_C
|
||||
#define UINTMAX_C UINT64_C
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
||||
|
||||
#endif // _MSC_STDINT_H_ ]
|
||||
|
||||
Reference in New Issue
Block a user