From 2e347bc523b7a7052bd18e0650d0e4e8df709d55 Mon Sep 17 00:00:00 2001 From: Jan Ciger Date: Sun, 15 Jan 2012 04:43:09 +0100 Subject: [PATCH 01/55] Changed the initial handshake to be synchronous Made the Motion+ init a lot more robust Code cleanup --- src/events.c | 14 +++- src/io.c | 159 +++++++++++++++++++++++++++++++++++++++++- src/io.h | 5 +- src/io_nix.c | 20 ++++-- src/motion_plus.c | 69 +++++++++++++++++- src/wiiuse_internal.h | 10 ++- 6 files changed, 268 insertions(+), 9 deletions(-) diff --git a/src/events.c b/src/events.c index 5e1f803..4ef796a 100644 --- a/src/events.c +++ b/src/events.c @@ -164,6 +164,9 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); evnt += (wm[i]->event != WIIUSE_NONE); } else { + /* send out any waiting writes */ + wiiuse_send_next_pending_write_request(wm[i]); + idle_cycle(wm[i]); } } @@ -186,6 +189,9 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { /* clear out the event buffer */ memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); } else { + /* send out any waiting writes */ + wiiuse_send_next_pending_write_request(wm[i]); + idle_cycle(wm[i]); } } @@ -650,9 +656,16 @@ static void event_status(struct wiimote_t* wm, byte* msg) { if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1; if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1; + /* probe for Motion+ */ + if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT)) + wiiuse_probe_motion_plus(wm); + /* is an attachment connected to the expansion port? */ if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) + { + WIIUSE_DEBUG("Attachment detected!"); attachment = 1; + } /* is the speaker enabled? */ if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) @@ -708,7 +721,6 @@ static void event_status(struct wiimote_t* wm, byte* msg) { req->state = REQ_DONE; /* if(req->cb!=NULL) req->cb(wm,msg,6); */ free(req); - wiiuse_send_next_pending_write_request(wm); } diff --git a/src/io.c b/src/io.c index 168ff9f..25f62d4 100644 --- a/src/io.c +++ b/src/io.c @@ -32,9 +32,11 @@ */ #include "io.h" #include "ir.h" /* for wiiuse_set_ir_mode */ +#include "wiiuse_internal.h" #include /* for free, malloc */ +extern void propagate_event(struct wiimote_t* wm, byte event, byte* msg); static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len) { @@ -53,6 +55,85 @@ static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2); } + /** +* @brief Wait until specified report arrives and return it +* +* @param wm Pointer to a wiimote_t structure. +* @param data Pre-allocated memory to store the received data +* +* Synchronous/blocking, this function will not return until it receives the specified +* report from the Wiimote. +* +*/ +void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *data) +{ + for(;;) + { + if(wiiuse_io_read(wm, data, 32) > 0) + if(data[1] == report) + break; + } +} + +/** +* @brief Read memory/register data synchronously +* +* @param wm Pointer to a wiimote_t structure. +* @param memory If set to non-zero, reads EEPROM, otherwise registers +* @param addr Address offset to read from +* @param size How many bytes to read +* @param data Pre-allocated memory to store the received data +* +* Synchronous/blocking read, this function will not return until it receives the specified +* amount of data from the Wiimote. +* +*/ +void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) +{ + byte pkt[8]; + byte buf[32]; + unsigned n_full_reports; + unsigned last_report; + byte *output; + int i; + + /* + * address in big endian first, the leading byte will + * be overwritten (only 3 bytes are sent) + */ + to_big_endian_uint32_t(pkt + 2, addr); + + pkt[0] = 0x52; /* HID read command */ + pkt[1] = 0x17; /* report 17 - read */ + pkt[2] = (memory != 0) ? 0x00 : 0x04; /* read from registers or memory*/ + + /* + * length in big endian + */ + to_big_endian_uint16_t(pkt + 6, size); + + /* calculate how many 16B packets we have to get back */ + n_full_reports = size / 16; + last_report = size % 16; + output = data; + + wiiuse_io_write(wm, pkt, 8); + + for(i = 0; i < n_full_reports; ++i) + { + wiiuse_wait_report(wm, 0x21, buf); + memmove(output, buf + 7, 16); + output += 16; + } + + /* read the last incomplete packet */ + if(last_report) + { + wiiuse_wait_report(wm, 0x21, buf); + memmove(output, buf + 7, last_report); + } +} + /** * @brief Get initialization data from the wiimote. * @@ -66,18 +147,93 @@ static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned * The handshake will be concluded when the wiimote responds * with this data. */ + +#define SYNC_HANDSHAKE 1 +#ifdef SYNC_HANDSHAKE + +void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) +{ + /* send request to wiimote for accelerometer calibration */ + byte buf[32]; + byte report_type; + + /* step 0 - Reset wiimote */ + { + //wiiuse_set_leds(wm, WIIMOTE_LED_NONE); + + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); + WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS); + + wiiuse_set_report_type(wm); + wiiuse_millisleep(500); + + WIIUSE_DEBUG("Wiimote reset!\n"); + } + + /* step 1 - calibration of accelerometers */ + { + struct accel_t* accel = &wm->accel_calib; + byte val; + + wiiuse_read(wm, 1, WM_MEM_OFFSET_CALIBRATION, 8, buf); + + /* received read data */ + accel->cal_zero.x = buf[0]; + accel->cal_zero.y = buf[1]; + accel->cal_zero.z = buf[2]; + + accel->cal_g.x = buf[4] - accel->cal_zero.x; + accel->cal_g.y = buf[5] - accel->cal_zero.y; + accel->cal_g.z = buf[6] - accel->cal_zero.z; + + WIIUSE_DEBUG("Calibrated wiimote acc\n"); + } + + /* step 2 - re-enable IR and ask for status */ + { + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); + + /* now enable IR if it was set before the handshake completed */ + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) + { + WIIUSE_DEBUG("Handshake finished, enabling IR."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); + wiiuse_set_ir(wm, 1); + } + + WIIUSE_DEBUG("Asking for status ...\n"); + wm->event = WIIUSE_CONNECT; + wiiuse_status(wm); + } +} + +#else void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { if (!wm) return; switch (wm->handshake_state) { case 0: { - /* send request to wiimote for accelerometer calibration */ byte* buf; + /* continous reporting off, report to buttons only */ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); wiiuse_set_leds(wm, WIIMOTE_LED_NONE); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE); + WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS); + + wiiuse_set_report_type(wm); + + /* send request to wiimote for accelerometer calibration */ buf = (byte*)malloc(sizeof(byte) * 8); wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7); wm->handshake_state++; @@ -143,3 +299,4 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { } } } +#endif diff --git a/src/io.h b/src/io.h index 246774f..20da950 100644 --- a/src/io.h +++ b/src/io.h @@ -52,7 +52,10 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len); void wiiuse_init_platform_fields(struct wiimote_t* wm); void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); -int wiiuse_io_read(struct wiimote_t* wm); +void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *data); +void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data); + +int wiiuse_io_read(struct wiimote_t* wm, byte* buf, int len); int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len); /** @} */ diff --git a/src/io_nix.c b/src/io_nix.c index fb14735..703e065 100644 --- a/src/io_nix.c +++ b/src/io_nix.c @@ -267,14 +267,26 @@ void wiiuse_disconnect(struct wiimote_t* wm) { } -int wiiuse_io_read(struct wiimote_t* wm) { - /* not used */ - return 0; +int wiiuse_io_read(struct wiimote_t* wm, byte* buf, int len) { + int rc; + + rc = read(wm->in_sock, buf, len); + + if(rc <= 0) + wiiuse_disconnected(wm); + + return rc; } int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { - return write(wm->out_sock, buf, len); + int rc; + rc = write(wm->out_sock, buf, len); + + if(rc < 0) + wiiuse_disconnected(wm); + + return rc; } void wiiuse_init_platform_fields(struct wiimote_t* wm) { diff --git a/src/motion_plus.c b/src/motion_plus.c index 27d0d0e..c69f3b2 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -30,6 +30,7 @@ #include "motion_plus.h" +#include "wiiuse_internal.h" /* for endian conversions */ #include "events.h" /* for disable_expansion */ #include "ir.h" /* for wiiuse_set_ir_mode */ #include "nunchuk.h" /* for nunchuk_pressed_buttons */ @@ -42,6 +43,68 @@ static void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp); static void calculate_gyro_rates(struct motion_plus_t* mp); +void wiiuse_probe_motion_plus(struct wiimote_t *wm) +{ + byte buf[32]; + unsigned id; + + wiiuse_read(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); + + /* check error code */ + if(buf[4] & 0x0f) + { + WIIUSE_DEBUG("No Motion+ available, stopping probe."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); + return; + } + + /* decode the id*/ + id = from_big_endian_uint32_t(buf + 2); + + if(id != EXP_ID_CODE_INACTIVE_MOTION_PLUS && + id != EXP_ID_CODE_NLA_MOTION_PLUS && + id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK && + id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC) + { + /* we have read something weird */ + WIIUSE_DEBUG("Motion+ ID doesn't match, probably not connected."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); + return; + } + + WIIUSE_DEBUG("Detected inactive Motion+!"); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); + + /* init M+ */ + buf[0] = 0x55; + wiiuse_write_data(wm, WM_EXP_MOTION_PLUS_INIT, buf, 1); + + /* Init whatever is hanging on the pass-through port */ + buf[0] = 0x55; + wiiuse_write_data(wm, WM_EXP_MEM_ENABLE1, buf, 1); + + buf[0] = 0x00; + wiiuse_write_data(wm, WM_EXP_MEM_ENABLE2, buf, 1); + + /* Init gyroscope data */ + wm->exp.mp.cal_gyro.roll = 0; + wm->exp.mp.cal_gyro.pitch = 0; + wm->exp.mp.cal_gyro.yaw = 0; + wm->exp.mp.orient.roll = 0.0; + wm->exp.mp.orient.pitch = 0.0; + wm->exp.mp.orient.yaw = 0.0; + wm->exp.mp.raw_gyro_threshold = 10; + + wm->exp.mp.nc = &(wm->exp.nunchuk); + wm->exp.mp.classic = &(wm->exp.classic); + wm->exp.nunchuk.flags = &wm->flags; + + wm->exp.mp.ext = 0; + + wiiuse_set_ir_mode(wm); + wiiuse_set_report_type(wm); +} + void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short len) { uint32_t val; @@ -133,7 +196,11 @@ void wiiuse_set_motion_plus(struct wiimote_t *wm, int status) { byte val; - if(status && !WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP_HANDSHAKE)) + if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT) || + WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) + return; + + if(status) { WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); val = (status == 1) ? 0x04 : 0x05; diff --git a/src/wiiuse_internal.h b/src/wiiuse_internal.h index 6aed90c..1403d52 100644 --- a/src/wiiuse_internal.h +++ b/src/wiiuse_internal.h @@ -172,6 +172,7 @@ #define WM_EXP_MEM_ENABLE1 0x04A400F0 #define WM_EXP_MEM_ENABLE2 0x04A400FB #define WM_EXP_MEM_CALIBR 0x04A40020 +#define WM_EXP_MOTION_PLUS_IDENT 0x04A600FA #define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE #define WM_EXP_MOTION_PLUS_INIT 0x04A600F0 #define WM_REG_IR 0x04B00030 @@ -209,10 +210,16 @@ #define EXP_ID_CODE_WII_BOARD 0xA4200402 #define EXP_ID_CODE_CLASSIC_CONTROLLER 0xA4200101 #define EXP_ID_CODE_GUITAR 0xA4200103 -#define EXP_ID_CODE_MOTION_PLUS 0xa4200405 +#define EXP_ID_CODE_MOTION_PLUS 0xA4200405 #define EXP_ID_CODE_MOTION_PLUS_NUNCHUK 0xA4200505 /** Motion Plus ID in Nunchuck passthrough mode */ #define EXP_ID_CODE_MOTION_PLUS_CLASSIC 0xA4200705 /** Motion Plus ID in Classic control. passthrough */ +/* decrypted M+ codes at 0x04A600FA */ +#define EXP_ID_CODE_INACTIVE_MOTION_PLUS 0xA6200005 /** Inactive Motion Plus ID */ +#define EXP_ID_CODE_NLA_MOTION_PLUS 0xA6200405 /** No longer active Motion Plus ID */ +#define EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK 0xA6200505 /** No longer active Motion Plus ID in Nunchuck passthrough mode */ +#define EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC 0xA6200705 /** No longer active Motion Plus ID in Classic control. passthrough */ + #define EXP_HANDSHAKE_LEN 224 /******************** @@ -239,6 +246,7 @@ #define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */ #define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */ #define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */ +#define WIIMOTE_STATE_MPLUS_PRESENT 0x80000 /* Motion+ is connected */ From 1b25cd6289962730a680cc2e623aa149c8f005a6 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Casallas Date: Mon, 16 Jan 2012 18:34:38 -0600 Subject: [PATCH 02/55] Replace explicit 32 lengths for MAX_PAYLOAD --- src/io.c | 6 +++--- src/motion_plus.c | 2 +- src/wiiuse.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/io.c b/src/io.c index 25f62d4..16d382a 100644 --- a/src/io.c +++ b/src/io.c @@ -69,7 +69,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *data) { for(;;) { - if(wiiuse_io_read(wm, data, 32) > 0) + if(wiiuse_io_read(wm, data, MAX_PAYLOAD) > 0) if(data[1] == report) break; } @@ -91,7 +91,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *data) void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) { byte pkt[8]; - byte buf[32]; + byte buf[MAX_PAYLOAD]; unsigned n_full_reports; unsigned last_report; byte *output; @@ -154,7 +154,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { /* send request to wiimote for accelerometer calibration */ - byte buf[32]; + byte buf[MAX_PAYLOAD]; byte report_type; /* step 0 - Reset wiimote */ diff --git a/src/motion_plus.c b/src/motion_plus.c index c69f3b2..c0bfe0c 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -45,7 +45,7 @@ static void calculate_gyro_rates(struct motion_plus_t* mp); void wiiuse_probe_motion_plus(struct wiimote_t *wm) { - byte buf[32]; + byte buf[MAX_PAYLOAD]; unsigned id; wiiuse_read(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); diff --git a/src/wiiuse.c b/src/wiiuse.c index 0711cad..406b1bc 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -657,7 +657,7 @@ void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) { * This function should replace any write()s directly to the wiimote device. */ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { - byte buf[32]; /* no payload is better than this */ + byte buf[MAX_PAYLOAD]; /* no payload is better than this */ int rumble = 0; #ifdef WIIUSE_WIN32 From ddc645e1256393e219d9f125e368592ba3ca5906 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Casallas Date: Mon, 16 Jan 2012 19:21:41 -0600 Subject: [PATCH 03/55] pre-declare wiiuse_motion_plus on motion_plus.h -This ensures the function can be called outside of motion_plus.c -Also eliminates an explicit declaration warning on events.c --- src/motion_plus.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/motion_plus.h b/src/motion_plus.h index 88cdba7..b0c0401 100644 --- a/src/motion_plus.h +++ b/src/motion_plus.h @@ -49,6 +49,8 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg); void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data,unsigned short len); +void wiiuse_probe_motion_plus(struct wiimote_t *wm); + /** @} */ #ifdef __cplusplus From aef7ec45f80e1e7756f206e40a0eee44024b594b Mon Sep 17 00:00:00 2001 From: Juan Sebastian Casallas Date: Mon, 16 Jan 2012 19:24:15 -0600 Subject: [PATCH 04/55] motion_plus.c: Revise some includes -wiiuse_internal.h was already included via motion_plus.h -io.h is needed for wiiuse_read --- src/motion_plus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/motion_plus.c b/src/motion_plus.c index c0bfe0c..1d3cac2 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -30,7 +30,7 @@ #include "motion_plus.h" -#include "wiiuse_internal.h" /* for endian conversions */ +#include "io.h" /* for wiiuse_read */ #include "events.h" /* for disable_expansion */ #include "ir.h" /* for wiiuse_set_ir_mode */ #include "nunchuk.h" /* for nunchuk_pressed_buttons */ From 5ed42458f340a2d857374c80887758e8447a08cc Mon Sep 17 00:00:00 2001 From: Juan Sebastian Casallas Date: Mon, 16 Jan 2012 21:31:54 -0600 Subject: [PATCH 05/55] [mac]wiiuse_io_read: Add buffer and length parameters -According to the new signature for wiiuse_io_read --- src/events.c | 7 +++++-- src/io_mac.m | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/events.c b/src/events.c index 4ef796a..fc63a50 100644 --- a/src/events.c +++ b/src/events.c @@ -205,8 +205,8 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - - if (wiiuse_io_read(wm[i])) { + + if (wiiuse_io_read(wm[i],wm[i]->event_buf,sizeof(wm[i]->event_buf))) { /* propagate the event, messages should be read as in linux, starting from the second element */ propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); evnt += (wm[i]->event != WIIUSE_NONE); @@ -214,6 +214,9 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { /* clear out the event buffer */ memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); } else { + /* send out any waiting writes */ + wiiuse_send_next_pending_write_request(wm[i]); + idle_cycle(wm[i]); } } diff --git a/src/io_mac.m b/src/io_mac.m index a586417..3846ae6 100755 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -663,7 +663,7 @@ int wiiuse_load(struct wiimote_t** wm) } // Defined in io.h -int wiiuse_io_read(struct wiimote_t* wm) +int wiiuse_io_read(struct wiimote_t* wm, byte* buf, int len) { if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) return 0; @@ -723,12 +723,12 @@ int wiiuse_io_read(struct wiimote_t* wm) return 0; } - // Forward to WiiC - if(length < sizeof(wm->event_buf)) - memcpy(wm->event_buf,buffer,length); + // Forward to the parameter buffer + if(length <= len) + memcpy(buf,buffer,length); else { WIIUSE_DEBUG("Received data are more than the buffer.... strange! (id %i)", wm->unid); - memcpy(wm->event_buf,buffer,sizeof(wm->event_buf)); + memcpy(buf,buffer,len); } // Release the consumed message From be1f23ff7040c146ca2e40123e5ccbd2917211eb Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Thu, 8 Nov 2012 20:19:58 +0100 Subject: [PATCH 06/55] getting rid of osx 10.7+ deprecation warnings --- src/CMakeLists.txt | 3 +++ src/io_mac.m | 56 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95caf5d..2a0b4ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,9 @@ if(WIN32) elseif(APPLE) list(APPEND SOURCES io_mac.h) list(APPEND SOURCES io_mac.m) + # make sure we use the gcc for Objective-C files as well so that the + # sysroot and deployment target arguments are correctly passed to the compiler + SET_SOURCE_FILES_PROPERTIES(io_mac.m PROPERTIES LANGUAGE C) else() list(APPEND SOURCES io_nix.c) endif() diff --git a/src/io_mac.m b/src/io_mac.m index 80ab33d..7ad62d9 100755 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -35,12 +35,19 @@ #import "io_mac.h" #import "events.h" +#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 +#else +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 +#endif + @implementation WiiSearch #pragma mark - #pragma mark WiiSearch - (id) init { + self = [super init]; foundWiimotes = 0; isDiscovering = NO; @@ -149,8 +156,12 @@ - (void) retrieveWiimoteInfo:(IOBluetoothDevice*) device { // We set the device reference (we must retain it to use it after the search) +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + wiimotes[foundWiimotes]->device = (IOBluetoothDeviceRef) [device retain]; +#else wiimotes[foundWiimotes]->device = [[device retain] getDeviceRef]; - wiimotes[foundWiimotes]->address = (CFStringRef)[[device getAddressString] retain]; +#endif + wiimotes[foundWiimotes]->address = (CFStringRef) [IOBluetoothNSStringFromDeviceAddress([device getAddress]) retain]; // C String (common for Mac and Linux) CFStringGetCString(wiimotes[foundWiimotes]->address,wiimotes[foundWiimotes]->bdaddr_str,18,kCFStringEncodingMacRoman); @@ -287,7 +298,11 @@ - (IOReturn) connectToWiimote:(wiimote*) wm { +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothDevice* device = (IOBluetoothDevice*) wm->device; +#else IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; +#endif IOBluetoothL2CAPChannel* outCh = nil; IOBluetoothL2CAPChannel* inCh = nil; @@ -302,7 +317,11 @@ [device closeConnection]; return kIOReturnNotOpen; } +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + wm->outputCh = (IOBluetoothL2CAPChannelRef) [outCh retain]; +#else wm->outputCh = [[outCh retain] getL2CAPChannelRef]; +#endif usleep(20000); inCh = [self openL2CAPChannelWithPSM:WM_INPUT_CHANNEL device:device delegate:self]; @@ -311,7 +330,11 @@ [device closeConnection]; return kIOReturnNotOpen; } +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + wm->inputCh = (IOBluetoothL2CAPChannelRef) [inCh retain]; +#else wm->inputCh = [[inCh retain] getL2CAPChannelRef]; +#endif usleep(20000); IOBluetoothUserNotification* disconnectNotification = [device registerForDisconnectNotification:self selector:@selector(disconnected:fromDevice:)]; @@ -471,7 +494,11 @@ void wiiuse_disconnect(struct wiimote_t* wm) // Input Channel if(wm->inputCh) { +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothL2CAPChannel* inCh = (IOBluetoothL2CAPChannel*) wm->inputCh; +#else IOBluetoothL2CAPChannel* inCh = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->inputCh]; +#endif error = [inCh closeChannel]; [inCh setDelegate:nil]; if(error != kIOReturnSuccess) @@ -484,7 +511,11 @@ void wiiuse_disconnect(struct wiimote_t* wm) // Output Channel if(wm->outputCh) { +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothL2CAPChannel* outCh = (IOBluetoothL2CAPChannel*) wm->outputCh; +#else IOBluetoothL2CAPChannel* outCh = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh]; +#endif error = [outCh closeChannel]; [outCh setDelegate:nil]; if(error != kIOReturnSuccess) @@ -497,7 +528,11 @@ void wiiuse_disconnect(struct wiimote_t* wm) // Device if(wm->device) { +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothDevice* device = (IOBluetoothDevice*) wm->device; +#else IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; +#endif error = [device closeConnection]; if(error != kIOReturnSuccess) @@ -651,9 +686,14 @@ int wiiuse_load(struct wiimote_t** wm) NSString* string = [NSString stringWithCString:str encoding:[NSString defaultCStringEncoding]]; BluetoothDeviceAddress deviceAddr; IOBluetoothNSStringToDeviceAddress(string, &deviceAddr); +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothDevice* device = [IOBluetoothDevice deviceWithAddress:&deviceAddr]; + wm[i]->device = (IOBluetoothDeviceRef) [device retain]; +#else IOBluetoothDevice* device = [IOBluetoothDevice withAddress:&deviceAddr]; wm[i]->device = [[device retain] getDeviceRef]; - wm[i]->address = (CFStringRef)[[device getAddressString] retain]; +#endif + wm[i]->address = (CFStringRef) [IOBluetoothNSStringFromDeviceAddress([device getAddress]) retain]; WIIMOTE_ENABLE_STATE(wm[i], WIIMOTE_STATE_DEV_FOUND); WIIUSE_INFO("Loaded Wiimote (%s) [id %i].",CFStringGetCStringPtr(wm[i]->address, kCFStringEncodingMacRoman),wm[i]->unid); } @@ -753,7 +793,11 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothL2CAPChannel* channel = (IOBluetoothL2CAPChannel*) wm->outputCh; +#else IOBluetoothL2CAPChannel* channel = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh]; +#endif IOReturn error = [channel writeSync:buf length:length]; if (error != kIOReturnSuccess) @@ -771,14 +815,22 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) WiiConnect* connect = (WiiConnect*)(wm->connectionHandler); +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothDevice* device = (IOBluetoothDevice*) wm->device; +#else IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; +#endif channel = [connect openL2CAPChannelWithPSM:WM_OUTPUT_CHANNEL device:device delegate:connect]; if (!channel) { WIIUSE_ERROR("Unable to open L2CAP output channel (id %i).", wm->unid); [device closeConnection]; return kIOReturnNotOpen; } +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + wm->outputCh = (IOBluetoothL2CAPChannelRef) [channel retain]; +#else wm->outputCh = [[channel retain] getL2CAPChannelRef]; +#endif usleep(20000); WIIUSE_INFO("Attempting to write again through the output channel (id %i).", wm->unid); From f7b4fd44a072cfb34519d33fdb74ccf6d8af566f Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 00:52:05 +0100 Subject: [PATCH 07/55] fix mac expansion handshake by propagating the event on receive --- src/events.c | 1 + src/io_mac.m | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/events.c b/src/events.c index ba6cc3a..a6e82ec 100644 --- a/src/events.c +++ b/src/events.c @@ -801,6 +801,7 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { WIIUSE_DEBUG("no handshake data received from expansion"); return; } + wm->expansion_state = 0; id = from_big_endian_uint32_t(data + 220); switch(id) { case EXP_ID_CODE_NUNCHUK: diff --git a/src/io_mac.m b/src/io_mac.m index 7ad62d9..652cc4a 100755 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -366,24 +366,38 @@ - (void) l2capChannelData:(IOBluetoothL2CAPChannel*) channel data:(byte *) data length:(NSUInteger) length { // This is done in case the output channel woke up this handler - if(!data) { - [self setReading:NO]; - length = 0; + if(!data || ([channel PSM] == WM_OUTPUT_CHANNEL)) { return; } + + // log the received data + #ifdef WITH_WIIUSE_DEBUG + { + printf("[DEBUG] (id %i) RECV: (%x) ", _wm->unid, data[0]); + int x; + for (x = 1; x < length; ++x) + printf("%.2x ", data[x]); + printf("\n"); + } + #endif /* * This is called if we are receiving data before completing * the handshaking, hence before calling wiiuse_poll */ + // wiimote handshake if(WIIMOTE_IS_SET(_wm, WIIMOTE_STATE_HANDSHAKE)) propagate_event(_wm, data[1], data+2); + + // expansion handshake + if(_wm->expansion_state != 0) + propagate_event(_wm, data[1], data+2); receivedMsg = [[NSData dataWithBytes:data length:length] retain]; msgLength = length; - // This is done when a message is successfully received. Stop the main loop after reading - [self setReading:NO]; + // This is done when a message is successfully received. Stop the main loop after reading + [self setReading:NO]; } - (unsigned int) getMsgLength From f1c7a7712b68cc2bd433f36d7757ed550791b486 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 13:03:51 +0100 Subject: [PATCH 08/55] delete mac implementation, replace by stub; reorganize platform-specific code --- src/CMakeLists.txt | 2 +- src/events.c | 13 +- src/io.c | 71 ++++ src/io.h | 21 +- src/io_mac.h | 107 ------ src/io_mac.m | 885 ++------------------------------------------- src/io_nix.c | 52 +-- src/io_platform.h | 62 ++++ src/io_win.c | 6 +- src/wiiuse.h | 12 +- 10 files changed, 188 insertions(+), 1043 deletions(-) delete mode 100755 src/io_mac.h mode change 100755 => 100644 src/io_mac.m create mode 100644 src/io_platform.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a0b4ad..aaa9e17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ set(SOURCES motion_plus.h motion_plus.c io.h + io_platform.h ir.h nunchuk.h os.h @@ -29,7 +30,6 @@ if(WIN32) list(APPEND SOURCES io_win.c) set(CMAKE_DEBUG_POSTFIX _debug) elseif(APPLE) - list(APPEND SOURCES io_mac.h) list(APPEND SOURCES io_mac.m) # make sure we use the gcc for Objective-C files as well so that the # sysroot and deployment target arguments are correctly passed to the compiler diff --git a/src/events.c b/src/events.c index a6e82ec..434b453 100644 --- a/src/events.c +++ b/src/events.c @@ -199,19 +199,8 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - - if (wiiuse_io_read(wm[i])) { - /* propagate the event, messages should be read as in linux, starting from the second element */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - evnt += (wm[i]->event != WIIUSE_NONE); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - } else { - idle_cycle(wm[i]); - } + idle_cycle(wm[i]); } - #endif return evnt; diff --git a/src/io.c b/src/io.c index 168ff9f..9871c8f 100644 --- a/src/io.c +++ b/src/io.c @@ -30,11 +30,82 @@ * @file * @brief Handles device I/O (non-OS specific). */ + #include "io.h" #include "ir.h" /* for wiiuse_set_ir_mode */ #include /* for free, malloc */ +/** + * @brief Find a wiimote or wiimotes. + * + * @param wm An array of wiimote_t structures. + * @param max_wiimotes The number of wiimote structures in \a wm. + * @param timeout The number of seconds before the search times out. + * + * @return The number of wiimotes found. + * + * @see wiiuse_connect() + * @see wiiuse_io_find() + * + * This function will only look for wiimote devices. \n + * When a device is found the address in the structures will be set. \n + * You can then call wiiuse_connect() to connect to the found \n + * devices. + * + * This function only delegates to the platform-specific implementation + * wiiuse_io_find. + * + * This function is declared in wiiuse.h + */ +int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { + return wiiuse_io_find(wm, max_wiimotes, timeout); +} + +/** + * @brief Connect to a wiimote or wiimotes once an address is known. + * + * @param wm An array of wiimote_t structures. + * @param wiimotes The number of wiimote structures in \a wm. + * + * @return The number of wiimotes that successfully connected. + * + * @see wiiuse_find() + * @see wiiuse_disconnect() + * @see wiiuse_io_connect() + * + * Connect to a number of wiimotes when the address is already set + * in the wiimote_t structures. These addresses are normally set + * by the wiiuse_find() function, but can also be set manually. + * + * This function only delegates to the platform-specific implementation + * wiiuse_io_connect. + * + * This function is declared in wiiuse.h + */ +int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { + return wiiuse_io_connect(wm, wiimotes); +} + +/** + * @brief Disconnect a wiimote. + * + * @param wm Pointer to a wiimote_t structure. + * + * @see wiiuse_connect() + * @see wiiuse_io_disconnect() + * + * Note that this will not free the wiimote structure. + * + * This function only delegates to the platform-specific implementation + * wiiuse_io_disconnect. + * + * This function is declared in wiiuse.h + */ +void wiiuse_disconnect(struct wiimote_t* wm) { + wiiuse_io_disconnect(wm); +} + static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len) { diff --git a/src/io.h b/src/io.h index 246774f..ddf634c 100644 --- a/src/io.h +++ b/src/io.h @@ -31,33 +31,24 @@ * @brief Handles device I/O. */ -#ifndef CONNECT_H_INCLUDED -#define CONNECT_H_INCLUDED - -#ifdef WIIUSE_BLUEZ - #include -#endif +#ifndef IO_H_INCLUDED +#define IO_H_INCLUDED #include "wiiuse_internal.h" +#include "io_platform.h" // declare functions implemented per platform + #ifdef __cplusplus extern "C" { #endif - -/** @defgroup internal_io Internal: Device IO */ +/** @defgroup internal_io Internal: Device I/O */ /** @{ */ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len); - -void wiiuse_init_platform_fields(struct wiimote_t* wm); -void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); - -int wiiuse_io_read(struct wiimote_t* wm); -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len); /** @} */ #ifdef __cplusplus } #endif -#endif /* CONNECT_H_INCLUDED */ +#endif /* IO_H_INCLUDED */ diff --git a/src/io_mac.h b/src/io_mac.h deleted file mode 100755 index d5e2c6b..0000000 --- a/src/io_mac.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * io_mac.h - * - * This file is based on io_mac.h from WiiC, written By: - * Gabriele Randelli - * Email: < randelli (--AT--) dis [--DOT--] uniroma1 [--DOT--] it > - * - * Copyright 2010 - * - * 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 . - * - * $Header$ - * - */ - -/** - * @file - * @brief I/O header file for MacOS. - */ -#ifndef IO_MAC_H -#define IO_MAC_H - -#import -#import -#import - -#define BLUETOOTH_VERSION_USE_CURRENT - -#import /* htons() */ -#import -#import -#import -#import -#import - -#import "wiiuse_internal.h" -#import "io.h" - -@interface WiiSearch : NSObject -{ - IOBluetoothDeviceInquiry* inquiry; - BOOL isDiscovering; - // Number of found wiimotes - int foundWiimotes; - // Maximum number of wiimotes to be searched - int maxWiimotes; - // The Wiimotes structure - wiimote** wiimotes; -} - -- (BOOL) isDiscovering; -- (void) setDiscovering:(BOOL) flag; -- (void) setWiimoteStruct:(wiimote**) wiimote_struct; -- (int) getFoundWiimotes; -- (IOReturn) start:(unsigned int) timeout maxWiimotes:(unsigned int) wiimotesNum; -- (IOReturn) stop; -- (IOReturn) close; -- (void) retrieveWiimoteInfo:(IOBluetoothDevice*) device; -- (void) deviceInquiryStarted:(IOBluetoothDeviceInquiry*) sender; -- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) sender device:(IOBluetoothDevice *) device; -- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) sender error:(IOReturn) error aborted:(BOOL) aborted; - -@end - -@interface WiiConnect : NSObject -{ - // Buffer to store incoming data from the Wiimote - NSData* receivedMsg; - unsigned int msgLength; - - // Reference to the relative wiimote struct (used only to complete handshaking) - wiimote* _wm; - BOOL isReading; - BOOL timeout; - BOOL disconnecting; -} - -- (IOBluetoothL2CAPChannel *) openL2CAPChannelWithPSM:(BluetoothL2CAPPSM) psm device:(IOBluetoothDevice*) device delegate:(id) delegate; -- (IOReturn) connectToWiimote:(wiimote*) wm; -- (void) l2capChannelData:(IOBluetoothL2CAPChannel*) channel data:(byte *) data length:(NSUInteger) length; -- (byte*) getNextMsg; -- (unsigned int) getMsgLength; -- (void) deleteMsg; -- (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device; -- (BOOL) isReading; -- (void) setReading:(BOOL) flag; -- (BOOL) isTimeout; -- (void) setTimeout:(BOOL) flag; -- (void) startTimerThread; -- (void) wakeUpMainThreadRunloop:(id)arg; -- (BOOL) isDisconnecting; -@end - -#endif /* IO_MAC_H */ diff --git a/src/io_mac.m b/src/io_mac.m old mode 100755 new mode 100644 index 652cc4a..50d6517 --- a/src/io_mac.m +++ b/src/io_mac.m @@ -1,39 +1,39 @@ /* - * io_mac.m + * wiiuse * - * This file is based on io_mac.m from WiiC, written By: - * Gabriele Randelli - * Email: < randelli (--AT--) dis [--DOT--] uniroma1 [--DOT--] it > + * Written By: + * Michael Laforest < para > + * Email: < thepara (--AT--) g m a i l [--DOT--] com > * - * Copyright 2010 + * Copyright 2006-2007 * - * This file is part of wiiuse. + * 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 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. + * 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 . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * - * $Header$ + * $Header$ * */ /** - * @file - * @brief Handles device I/O for Mac. + * @file + * @brief Handles device I/O for Mac OS X. */ + #ifdef __APPLE__ -#import "io_mac.h" -#import "events.h" +#include "io.h" #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 #define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 @@ -41,848 +41,33 @@ #define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 #endif -@implementation WiiSearch -#pragma mark - -#pragma mark WiiSearch -- (id) init -{ +void wiiuse_init_platform_fields(struct wiimote_t* wm) { - self = [super init]; - foundWiimotes = 0; - isDiscovering = NO; - if (self != nil) { - /* - * Calling IOBluetoothLocalDeviceAvailable has two advantages: - * 1. it sets up a event source in the run loop (bug for C version of the bluetooth api) - * 2. it checks for the availability of the BT hardware - */ - if (![IOBluetoothHostController defaultController]) - { - [self release]; - self = nil; - } - } - - return self; } -- (void) dealloc -{ - inquiry = 0; - WIIUSE_DEBUG("Wiimote Discovery released"); - [super dealloc]; +void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { + } -- (BOOL) isDiscovering -{ - return isDiscovering; +int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { + return 0; } -- (void) setDiscovering:(BOOL) flag -{ - isDiscovering = flag; +int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { + return 0; } -- (void) setWiimoteStruct:(wiimote**) wiimote_struct -{ - wiimotes = wiimote_struct; +void wiiuse_io_disconnect(struct wiimote_t* wm) { + } -- (int) getFoundWiimotes -{ - return foundWiimotes; +int wiiuse_io_read(struct wiimote_t* wm) { + return 0; } -- (IOReturn) start:(unsigned int) timeout maxWiimotes:(unsigned int) wiimotesNum -{ - if (![IOBluetoothHostController defaultController]) { - WIIUSE_ERROR("Unable to find any bluetooth receiver on your host."); - return kIOReturnNotAttached; - } - - // If we are currently discovering, we can't start a new discovery right now. - if ([self isDiscovering]) { - WIIUSE_INFO("Wiimote search is already in progress..."); - return kIOReturnSuccess; - } - - [self close]; - maxWiimotes = wiimotesNum; - foundWiimotes = 0; - - inquiry = [IOBluetoothDeviceInquiry inquiryWithDelegate:self]; - // We set the search timeout - if(timeout == 0) - [inquiry setInquiryLength:5]; - else if(timeout < 20) - [inquiry setInquiryLength:timeout]; - else - [inquiry setInquiryLength:20]; - [inquiry setSearchCriteria:kBluetoothServiceClassMajorAny majorDeviceClass:WM_DEV_MAJOR_CLASS minorDeviceClass:WM_DEV_MINOR_CLASS]; - [inquiry setUpdateNewDeviceNames:NO]; - - IOReturn status = [inquiry start]; - if (status == kIOReturnSuccess) { - [inquiry retain]; - } else { - [self close]; - WIIUSE_ERROR("Unable to search for bluetooth devices."); - } - - return status; +int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { + return 0; } -- (IOReturn) stop -{ - return [inquiry stop]; -} - -- (IOReturn) close -{ - IOReturn ret = kIOReturnSuccess; - - ret = [inquiry stop]; - [inquiry release]; - inquiry = nil; - - WIIUSE_DEBUG("Discovery closed"); - return ret; -} - -#pragma mark - -#pragma mark IOBluetoothDeviceInquiry delegates -//*************** HANDLERS FOR WIIUSE_FIND FOR MACOSX *******************/ -- (void) retrieveWiimoteInfo:(IOBluetoothDevice*) device -{ - // We set the device reference (we must retain it to use it after the search) -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - wiimotes[foundWiimotes]->device = (IOBluetoothDeviceRef) [device retain]; -#else - wiimotes[foundWiimotes]->device = [[device retain] getDeviceRef]; -#endif - wiimotes[foundWiimotes]->address = (CFStringRef) [IOBluetoothNSStringFromDeviceAddress([device getAddress]) retain]; - - // C String (common for Mac and Linux) - CFStringGetCString(wiimotes[foundWiimotes]->address,wiimotes[foundWiimotes]->bdaddr_str,18,kCFStringEncodingMacRoman); - - WIIMOTE_ENABLE_STATE(wiimotes[foundWiimotes], WIIMOTE_STATE_DEV_FOUND); - WIIUSE_INFO("Found Wiimote (%s) [id %i].",CFStringGetCStringPtr(wiimotes[foundWiimotes]->address, kCFStringEncodingMacRoman),wiimotes[foundWiimotes]->unid); - ++foundWiimotes; -} - -- (void) deviceInquiryStarted:(IOBluetoothDeviceInquiry*) sender -{ - [self setDiscovering:YES]; -} - -- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) sender device:(IOBluetoothDevice *) device -{ - if(foundWiimotes < maxWiimotes) - [self retrieveWiimoteInfo:device]; - else - [inquiry stop]; -} - -- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) sender error:(IOReturn) error aborted:(BOOL) aborted -{ - // The inquiry has completed, we can now process what we have found - [self setDiscovering:NO]; - - // We stop the search because of errors - if ((error != kIOReturnSuccess) && !aborted) { - foundWiimotes = 0; - [self close]; - WIIUSE_ERROR("Search not completed, because of unexpected errors. This error can be due to a short search timeout."); - return; - } - - foundWiimotes = [[inquiry foundDevices] count]; -} - -@end - -@implementation WiiConnect -#pragma mark - -#pragma mark WiiConnect -- (id) init -{ - self = [super init]; - receivedMsg = [[NSData alloc] init]; - msgLength = 0; - _wm = 0; - isReading = NO; - timeout = NO; - disconnecting = NO; - return self; -} - -- (void) dealloc -{ - WIIUSE_DEBUG("Wiimote released"); - if(receivedMsg) - [receivedMsg release]; - receivedMsg = 0; - _wm = 0; - [super dealloc]; -} - -- (byte*) getNextMsg -{ - if(!receivedMsg) - return 0; - - return (byte*)[receivedMsg bytes]; -} - -- (void) deleteMsg -{ - if(receivedMsg) { - [receivedMsg release]; - msgLength = 0; - } -} - -- (BOOL) isDisconnecting -{ - return disconnecting; -} - -- (BOOL) isReading -{ - return isReading; -} - -- (void) setReading:(BOOL) flag -{ - isReading = flag; -} - -- (BOOL) isTimeout -{ - return timeout; -} - -- (void) setTimeout:(BOOL) flag -{ - timeout = flag; -} - -- (void) startTimerThread -{ - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - // Timer - sleep(1); - - [pool drain]; -} - -- (void) wakeUpMainThreadRunloop:(id)arg -{ - // This method is executed on main thread! - // It doesn't need to do anything actually, just having it run will - // make sure the main thread stops running the runloop -} - - -- (IOBluetoothL2CAPChannel*) openL2CAPChannelWithPSM:(BluetoothL2CAPPSM) psm device:(IOBluetoothDevice*) device delegate:(id) delegate -{ - IOBluetoothL2CAPChannel* channel = nil; - - if ([device openL2CAPChannelSync:&channel withPSM:psm delegate:delegate] != kIOReturnSuccess) - channel = nil; - - return channel; -} - -- (IOReturn) connectToWiimote:(wiimote*) wm -{ -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothDevice* device = (IOBluetoothDevice*) wm->device; -#else - IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; -#endif - IOBluetoothL2CAPChannel* outCh = nil; - IOBluetoothL2CAPChannel* inCh = nil; - - if(!device) { - WIIUSE_ERROR("Non existent device or already connected."); - return kIOReturnBadArgument; - } - - outCh = [self openL2CAPChannelWithPSM:WM_OUTPUT_CHANNEL device:device delegate:self]; - if (!outCh) { - WIIUSE_ERROR("Unable to open L2CAP output channel (id %i).", wm->unid); - [device closeConnection]; - return kIOReturnNotOpen; - } -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - wm->outputCh = (IOBluetoothL2CAPChannelRef) [outCh retain]; -#else - wm->outputCh = [[outCh retain] getL2CAPChannelRef]; -#endif - usleep(20000); - - inCh = [self openL2CAPChannelWithPSM:WM_INPUT_CHANNEL device:device delegate:self]; - if (!inCh) { - WIIUSE_ERROR("Unable to open L2CAP input channel (id %i).", wm->unid); - [device closeConnection]; - return kIOReturnNotOpen; - } -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - wm->inputCh = (IOBluetoothL2CAPChannelRef) [inCh retain]; -#else - wm->inputCh = [[inCh retain] getL2CAPChannelRef]; -#endif - usleep(20000); - - IOBluetoothUserNotification* disconnectNotification = [device registerForDisconnectNotification:self selector:@selector(disconnected:fromDevice:)]; - if(!disconnectNotification) { - WIIUSE_ERROR("Unable to register disconnection handler (id %i).", wm->unid); - [device closeConnection]; - return kIOReturnNotOpen; - } - - // We store the reference to its relative structure (Used for completing the handshake step) - _wm = wm; - - return kIOReturnSuccess; -} - -#pragma mark - -#pragma mark IOBluetoothL2CAPChannel delegates -- (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device -{ - [self deleteMsg]; - [self setReading:NO]; - disconnecting = YES; - - // The wiimote_t struct must be re-initialized due to the disconnection - wiiuse_disconnected(_wm) ; -} - -//*************** HANDLERS FOR WIIUSE_IO_READ FOR MACOSX *******************/ -- (void) l2capChannelData:(IOBluetoothL2CAPChannel*) channel data:(byte *) data length:(NSUInteger) length -{ - // This is done in case the output channel woke up this handler - if(!data || ([channel PSM] == WM_OUTPUT_CHANNEL)) { - return; - } - - // log the received data - #ifdef WITH_WIIUSE_DEBUG - { - printf("[DEBUG] (id %i) RECV: (%x) ", _wm->unid, data[0]); - int x; - for (x = 1; x < length; ++x) - printf("%.2x ", data[x]); - printf("\n"); - } - #endif - - /* - * This is called if we are receiving data before completing - * the handshaking, hence before calling wiiuse_poll - */ - // wiimote handshake - if(WIIMOTE_IS_SET(_wm, WIIMOTE_STATE_HANDSHAKE)) - propagate_event(_wm, data[1], data+2); - - // expansion handshake - if(_wm->expansion_state != 0) - propagate_event(_wm, data[1], data+2); - - receivedMsg = [[NSData dataWithBytes:data length:length] retain]; - msgLength = length; - - // This is done when a message is successfully received. Stop the main loop after reading - [self setReading:NO]; -} - -- (unsigned int) getMsgLength -{ - return msgLength; -} - -- (void) l2capChannelReconfigured:(IOBluetoothL2CAPChannel*) l2capChannel -{ - //NSLog(@"l2capChannelReconfigured"); -} - -- (void) l2capChannelWriteComplete:(IOBluetoothL2CAPChannel*) l2capChannel refcon:(void*) refcon status:(IOReturn) error -{ - //NSLog(@"l2capChannelWriteComplete"); -} - -- (void) l2capChannelQueueSpaceAvailable:(IOBluetoothL2CAPChannel*) l2capChannel -{ - //NSLog(@"l2capChannelQueueSpaceAvailable"); -} - -- (void) l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*) l2capChannel status:(IOReturn) error -{ - //NSLog(@"l2capChannelOpenComplete (PSM:0x%x)", [l2capChannel getPSM]); -} - - -@end - -#pragma mark - -#pragma mark Wiiuse -/** - * @brief Find a wiimote or wiimotes. - * - * @param wm An array of wiimote_t structures. - * @param max_wiimotes The number of wiimote structures in \a wm. - * @param timeout The number of seconds before the search times out. - * - * @return The number of wiimotes found. - * - * @see wiimote_connect() - * - * This function will only look for wiimote devices. \n - * When a device is found the address in the structures will be set. \n - * You can then call wiimote_connect() to connect to the found \n - * devices. - * - * This function is defined in wiiuse.h - */ -int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) -{ - int found_wiimotes = 0; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - WiiSearch* search = [[WiiSearch alloc] init]; - [search setWiimoteStruct:wm]; - - if(timeout) { // Single search - [search start:timeout maxWiimotes:max_wiimotes]; - - NSRunLoop *theRL = [NSRunLoop currentRunLoop]; - while ([search isDiscovering] && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]); - - found_wiimotes = [search getFoundWiimotes]; - } - else { // Unlimited search - found_wiimotes = 0; - while(!found_wiimotes) { - [search start:timeout maxWiimotes:max_wiimotes]; - - NSRunLoop *theRL = [NSRunLoop currentRunLoop]; - while ([search isDiscovering] && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]); - - found_wiimotes = [search getFoundWiimotes]; - } - } - - WIIUSE_INFO("Found %i Wiimote device(s).", found_wiimotes); - - [search release]; - [pool drain]; - - return found_wiimotes; -} - - -//*************** HANDLERS FOR WIIUSE_DISCONNECT FOR MACOSX *******************/ -/** - * @brief Disconnect a wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * - * @see wiic_connect() - * - * Note that this will not free the wiimote structure. - * - * This function is defined in wiiuse.h - */ -void wiiuse_disconnect(struct wiimote_t* wm) -{ - IOReturn error; - - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - // Input Channel - if(wm->inputCh) { -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothL2CAPChannel* inCh = (IOBluetoothL2CAPChannel*) wm->inputCh; -#else - IOBluetoothL2CAPChannel* inCh = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->inputCh]; -#endif - error = [inCh closeChannel]; - [inCh setDelegate:nil]; - if(error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to close input channel (id %i).", wm->unid); - usleep(10000); - [inCh release]; - inCh = nil; - wm->inputCh = 0; - } - - // Output Channel - if(wm->outputCh) { -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothL2CAPChannel* outCh = (IOBluetoothL2CAPChannel*) wm->outputCh; -#else - IOBluetoothL2CAPChannel* outCh = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh]; -#endif - error = [outCh closeChannel]; - [outCh setDelegate:nil]; - if(error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to close output channel (id %i).", wm->unid); - usleep(10000); - [outCh release]; - outCh = nil; - wm->outputCh = 0; - } - - // Device - if(wm->device) { -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothDevice* device = (IOBluetoothDevice*) wm->device; -#else - IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; -#endif - error = [device closeConnection]; - - if(error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to close the device connection (id %i).", wm->unid); - usleep(10000); - [device release]; - device = nil; - wm->device = 0; - } - - [pool drain]; - - wm->event = WIIUSE_NONE; - - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); -} - -/** - * @brief Connect to a wiimote with a known address. - * - * @param wm Pointer to a wiimote_t structure. - * @param address The address of the device to connect to. - * If NULL, use the address in the struct set by wiic_find(). - * - * @return 1 on success, 0 on failure - * This function is defined in io_mac.h - */ -static int wiiuse_connect_single(struct wiimote_t* wm, char* address) -{ - // Skip if already connected or device not found - if(!wm || WIIMOTE_IS_CONNECTED(wm) || wm->device == 0) { - WIIUSE_ERROR("Non existent device or already connected."); - return 0; - } - - // Convert the IP address - // FIXME - see if it is possible - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - WiiConnect* connect = [[[WiiConnect alloc] init] autorelease]; - if([connect connectToWiimote:wm] == kIOReturnSuccess) { - WIIUSE_INFO("Connected to wiimote [id %i].", wm->unid); - // This is stored to retrieve incoming data - wm->connectionHandler = (void*)([connect retain]); - - // Do the handshake - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - wiiuse_handshake(wm, NULL, 0); - wiiuse_set_report_type(wm); - - [pool drain]; - } - else { - [pool drain]; - return 0; - } - - return 1; -} - -/** - * @brief Connect to a wiimote or wiimotes once an address is known. - * - * @param wm An array of wiimote_t structures. - * @param wiimotes The number of wiimote structures in \a wm. - * - * @return The number of wiimotes that successfully connected. - * - * @see wiic_find() - * @see wiic_connect_single() - * @see wiic_disconnect() - * - * Connect to a number of wiimotes when the address is already set - * in the wiimote_t structures. These addresses are normally set - * by the wiic_find() function, but can also be set manually. - * This function is defined in wiiuse.h - */ -int wiiuse_connect(struct wiimote_t** wm, int wiimotes) -{ - int connected = 0; - int i = 0; - - for (; i < wiimotes; ++i) { - if(!(wm[i])) { - WIIUSE_ERROR("Trying to connect more Wiimotes than initialized"); - return 0; - } - - if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND)) - // If the device address is not set, skip it - continue; - - if (wiiuse_connect_single(wm[i], NULL)) - ++connected; - } - - return connected; -} - -/** - * @brief Load Wii devices registered in the wiimotes.config file. - * - * @param wm An array of wiimote_t structures. - * - * @return The number of wiimotes successfully loaded. - * - * @see wiic_find() - * @see wiic_connect() - * @see wiic_connect_single() - * @see wiic_disconnect() - * - * From version 0.53, it is possible to register the MAC address of your - * Wii devices. This allows to automatically load them, without waiting for any - * search timeout. To register a new device, go to: /.wiic/ and - * edit the file wiimotes.config, by adding the MAC address of the device - * you want to register (one line per MAC address). - * This function seems useful but it's not implemented in wiiuse - * TODO: Erase or implement elsewhere - */ -int wiiuse_load(struct wiimote_t** wm) -{ - int loaded = 0; - int i = 0; - char str[200]; - char configPath[100]; - char* tmp = 0; - - // Retrieve the HOME environment variable - tmp = getenv("HOME"); - strcpy(configPath,tmp); - strncat(configPath,"/.wiic/wiimotes.config",22); - - // Open the config file - FILE* fd = 0; - fd = fopen(configPath,"r"); - if(!fd) - return loaded; - - // Read line by line - while(fgets(str,sizeof(str),fd) != NULL && loaded < 1) { - int len = strlen(str)-1; - if(str[len] == '\n') - str[len] = 0; - loaded++; - } - - // We initialize the device structure - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - for (; i < loaded; ++i) { - NSString* string = [NSString stringWithCString:str encoding:[NSString defaultCStringEncoding]]; - BluetoothDeviceAddress deviceAddr; - IOBluetoothNSStringToDeviceAddress(string, &deviceAddr); -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothDevice* device = [IOBluetoothDevice deviceWithAddress:&deviceAddr]; - wm[i]->device = (IOBluetoothDeviceRef) [device retain]; -#else - IOBluetoothDevice* device = [IOBluetoothDevice withAddress:&deviceAddr]; - wm[i]->device = [[device retain] getDeviceRef]; -#endif - wm[i]->address = (CFStringRef) [IOBluetoothNSStringFromDeviceAddress([device getAddress]) retain]; - WIIMOTE_ENABLE_STATE(wm[i], WIIMOTE_STATE_DEV_FOUND); - WIIUSE_INFO("Loaded Wiimote (%s) [id %i].",CFStringGetCStringPtr(wm[i]->address, kCFStringEncodingMacRoman),wm[i]->unid); - } - [pool drain]; - - return loaded; -} - -// Defined in io.h -int wiiuse_io_read(struct wiimote_t* wm) -{ - if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) - return 0; - - /* If this wiimote is not connected, skip it */ - if (!WIIMOTE_IS_CONNECTED(wm)) - return 0; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - WiiConnect* deviceHandler = 0; - deviceHandler = (WiiConnect*)(wm->connectionHandler); - - /* If this wiimote is disconnecting, skip it */ - if (!deviceHandler || [deviceHandler isDisconnecting]) { - [pool drain]; - return 0; - } - - // Run the main loop to get bt data - [deviceHandler setReading:YES]; - [deviceHandler setTimeout:NO]; - - // We start the thread which manages the timeout to implement a non-blocking read - [NSThread detachNewThreadSelector:@selector(startTimerThread) toTarget:deviceHandler withObject:nil]; - - NSRunLoop *theRL = [NSRunLoop currentRunLoop]; - // Two possible events: we receive and incoming message or there is a timeout - while([deviceHandler isReading] && ![deviceHandler isTimeout]) { - NSAutoreleasePool *pool_loop = [[NSAutoreleasePool alloc] init]; // This is used for fast release of NSDate, otherwise it leaks - [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; - [pool_loop drain]; - } - - // In this case we have no incoming data (TIMEOUT) - if([deviceHandler isTimeout]) { - [pool drain]; - return 0; - } - - if(!(wm->connectionHandler)) { - WIIUSE_ERROR("Unable to find the connection handler (id %i).", wm->unid); - [pool drain]; - return 0; - } - - // Read next message - byte* buffer = 0; - unsigned int length = 0; - if(![deviceHandler isDisconnecting]) { - buffer = [deviceHandler getNextMsg]; - length = [deviceHandler getMsgLength]; - } - - if(!buffer || !length) { - [pool drain]; - return 0; - } - - // Forward to WiiC - if(length < sizeof(wm->event_buf)) - memcpy(wm->event_buf,buffer,length); - else { - WIIUSE_DEBUG("Received data are more than the buffer.... strange! (id %i)", wm->unid); - memcpy(wm->event_buf,buffer,sizeof(wm->event_buf)); - } - - // Release the consumed message - [deviceHandler deleteMsg]; - - [pool drain]; - - return 1; -} - -// Defined in io.h -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) -{ - unsigned int length = (unsigned int)len; - - // Small check before writing - if(!wm || !(wm->outputCh)) { - WIIUSE_ERROR("Attempt to write over non-existent channel (id %i).", wm->unid); - perror("Error Details"); - return 0; - } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothL2CAPChannel* channel = (IOBluetoothL2CAPChannel*) wm->outputCh; -#else - IOBluetoothL2CAPChannel* channel = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh]; -#endif - IOReturn error = [channel writeSync:buf length:length]; - - if (error != kIOReturnSuccess) - { - WIIUSE_ERROR("Unable to write over the output channel (id %i).", wm->unid); - WIIUSE_INFO("Attempting to reopen the output channel (id %i).", wm->unid); - - IOReturn error = [channel closeChannel]; - if (error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to close the output channel (id %i).", wm->unid); - [channel setDelegate:nil]; - usleep(10000); - [channel release]; - wm->outputCh = 0; - - WiiConnect* connect = (WiiConnect*)(wm->connectionHandler); - -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothDevice* device = (IOBluetoothDevice*) wm->device; -#else - IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device]; -#endif - channel = [connect openL2CAPChannelWithPSM:WM_OUTPUT_CHANNEL device:device delegate:connect]; - if (!channel) { - WIIUSE_ERROR("Unable to open L2CAP output channel (id %i).", wm->unid); - [device closeConnection]; - return kIOReturnNotOpen; - } -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - wm->outputCh = (IOBluetoothL2CAPChannelRef) [channel retain]; -#else - wm->outputCh = [[channel retain] getL2CAPChannelRef]; -#endif - usleep(20000); - - WIIUSE_INFO("Attempting to write again through the output channel (id %i).", wm->unid); - error = [channel writeSync:buf length:length]; - if (error != kIOReturnSuccess) - { - WIIUSE_ERROR("Unable to write again over the output channel (id %i).", wm->unid); - } - } - - usleep(10000); - - [pool drain]; - - return (error == kIOReturnSuccess ? len : 0); -} - -void wiiuse_init_platform_fields(struct wiimote_t* wm) -{ - wm->device = nil; - wm->address = nil; - wm->inputCh = nil; - wm->outputCh = 0; - wm->disconnectionRef = nil; - wm->connectionHandler = NULL; - memset (wm->bdaddr_str,'\0',18); -} - -void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) -{ - /* TODO isn't this already done in wiiuse_disconnect ? */ - wm->device = nil; - wm->address = nil; - wm->inputCh = nil; - wm->outputCh = 0; - wm->disconnectionRef = nil; - wm->connectionHandler = NULL; - memset (wm->bdaddr_str,'\0',18); -} - -#endif +#endif // __APPLE__ diff --git a/src/io_nix.c b/src/io_nix.c index fb14735..e10602a 100644 --- a/src/io_nix.c +++ b/src/io_nix.c @@ -47,25 +47,9 @@ #include /* for close, write */ #include -static int wiiuse_connect_single(struct wiimote_t* wm, char* address); +static int wiiuse_io_connect_single(struct wiimote_t* wm, char* address); -/** - * @brief Find a wiimote or wiimotes. - * - * @param wm An array of wiimote_t structures. - * @param max_wiimotes The number of wiimote structures in \a wm. - * @param timeout The number of seconds before the search times out. - * - * @return The number of wiimotes found. - * - * @see wiimote_connect() - * - * This function will only look for wiimote devices. \n - * When a device is found the address in the structures will be set. \n - * You can then call wiimote_connect() to connect to the found \n - * devices. - */ -int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { +int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { int device_id; int device_sock; inquiry_info scan_info_arr[128]; @@ -133,22 +117,10 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { /** - * @brief Connect to a wiimote or wiimotes once an address is known. - * - * @param wm An array of wiimote_t structures. - * @param wiimotes The number of wiimote structures in \a wm. - * - * @return The number of wiimotes that successfully connected. - * - * @see wiiuse_find() - * @see wiiuse_connect_single() - * @see wiiuse_disconnect() - * - * Connect to a number of wiimotes when the address is already set - * in the wiimote_t structures. These addresses are normally set - * by the wiiuse_find() function, but can also be set manually. + * @see wiiuse_connect() + * @see wiiuse_io_connect_single() */ -int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { +int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { int connected = 0; int i = 0; @@ -174,7 +146,7 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { * * @return 1 on success, 0 on failure */ -static int wiiuse_connect_single(struct wiimote_t* wm, char* address) { +static int wiiuse_io_connect_single(struct wiimote_t* wm, char* address) { struct sockaddr_l2 addr; memset(&addr, 0, sizeof (addr)); @@ -241,17 +213,7 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address) { return 1; } - -/** - * @brief Disconnect a wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * - * @see wiiuse_connect() - * - * Note that this will not free the wiimote structure. - */ -void wiiuse_disconnect(struct wiimote_t* wm) { +void wiiuse_io_disconnect(struct wiimote_t* wm) { if (!wm || WIIMOTE_IS_CONNECTED(wm)) return; diff --git a/src/io_platform.h b/src/io_platform.h new file mode 100644 index 0000000..167a64c --- /dev/null +++ b/src/io_platform.h @@ -0,0 +1,62 @@ +/* + * 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 . + * + * $Header$ + * + */ + +/** + * @file + * @brief Handles device I/O. + */ + +#ifndef IO_PLATFORM_H_INCLUDED +#define IO_PLATFORM_H_INCLUDED + +#include "wiiuse_internal.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup internal_io Internal: Platform-specific Device I/O */ +/** @{ */ +void wiiuse_init_platform_fields(struct wiimote_t* wm); +void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); + +int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout); + +int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes); +void wiiuse_io_disconnect(struct wiimote_t* wm); + +int wiiuse_io_read(struct wiimote_t* wm); +int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len); +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* IO_PLATFORM_H_INCLUDED */ diff --git a/src/io_win.c b/src/io_win.c index 0ad88e3..1892b29 100644 --- a/src/io_win.c +++ b/src/io_win.c @@ -52,7 +52,7 @@ extern "C" { # endif #endif -int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { +int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { GUID device_id; HANDLE dev; HDEVINFO device_info; @@ -146,7 +146,7 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { } -int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { +int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { int connected = 0; int i = 0; @@ -161,7 +161,7 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { } -void wiiuse_disconnect(struct wiimote_t* wm) { +void wiiuse_io_disconnect(struct wiimote_t* wm) { if (!wm || WIIMOTE_IS_CONNECTED(wm)) return; diff --git a/src/wiiuse.h b/src/wiiuse.h index 0c5e79f..85af147 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -101,8 +101,6 @@ #endif #ifdef WIIUSE_MAC /* mac */ - #include /*CFRunLoops and CFNumberRef in Bluetooth classes*/ - #include /*IOBluetoothDeviceRef and IOBluetoothL2CAPChannelRef*/ #endif #ifndef WCONST @@ -722,13 +720,7 @@ typedef struct wiimote_t { #ifdef WIIUSE_MAC /** @name Mac OS X-specific members */ - /** @{ */ - WCONST IOBluetoothDeviceRef device; /** Device reference object */ - WCONST CFStringRef address; /** MacOS-like device address string */ - WCONST IOBluetoothL2CAPChannelRef inputCh; /** Input L2CAP channel */ - WCONST IOBluetoothL2CAPChannelRef outputCh; /** Output L2CAP channel */ - WCONST IOBluetoothUserNotificationRef disconnectionRef; /** Disconnection Notification Reference **/ - WCONST void* connectionHandler; /** Wiimote connection handler for MACOSX **/ + /** @{ */ /** @} */ #endif @@ -896,7 +888,7 @@ WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout); WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold); -/* connect.c */ +/* io.c */ WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); From 6f6ba68ed6d558b64c6db4723d0fa3647d0078e0 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 13:28:44 +0100 Subject: [PATCH 09/55] rename wiiuse_io_* to wiiuse_os_* --- src/CMakeLists.txt | 10 +++--- src/definitions.h | 2 +- src/{io_platform.h => definitions_os.h} | 43 +++++++++---------------- src/events.c | 4 +-- src/io.c | 20 ++++++------ src/io.h | 2 -- src/os.h | 43 ++++++++++++++++--------- src/{io_mac.m => os_mac.m} | 10 +++--- src/{io_nix.c => os_nix.c} | 16 ++++----- src/{io_win.c => os_win.c} | 10 +++--- src/wiiuse.c | 5 +-- 11 files changed, 83 insertions(+), 82 deletions(-) rename src/{io_platform.h => definitions_os.h} (55%) rename src/{io_mac.m => os_mac.m} (83%) rename src/{io_nix.c => os_nix.c} (93%) rename src/{io_win.c => os_win.c} (95%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aaa9e17..0231444 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,13 +10,13 @@ set(SOURCES wiiboard.c classic.h definitions.h + definitions_os.h dynamics.h events.h guitar_hero_3.h motion_plus.h motion_plus.c io.h - io_platform.h ir.h nunchuk.h os.h @@ -27,15 +27,15 @@ set(API wiiuse.h) if(WIN32) - list(APPEND SOURCES io_win.c) + list(APPEND SOURCES os_win.c) set(CMAKE_DEBUG_POSTFIX _debug) elseif(APPLE) - list(APPEND SOURCES io_mac.m) + list(APPEND SOURCES os_mac.m) # make sure we use the gcc for Objective-C files as well so that the # sysroot and deployment target arguments are correctly passed to the compiler - SET_SOURCE_FILES_PROPERTIES(io_mac.m PROPERTIES LANGUAGE C) + SET_SOURCE_FILES_PROPERTIES(os_mac.m PROPERTIES LANGUAGE C) else() - list(APPEND SOURCES io_nix.c) + list(APPEND SOURCES os_nix.c) endif() if(MSVC) diff --git a/src/definitions.h b/src/definitions.h index f97e81d..527ea00 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -36,7 +36,7 @@ /* this is wiiuse - used to distinguish from third party programs using wiiuse.h */ #include -#include "os.h" +#include "definitions_os.h" /** @addtogroup internal_general */ /** @{ */ diff --git a/src/io_platform.h b/src/definitions_os.h similarity index 55% rename from src/io_platform.h rename to src/definitions_os.h index 167a64c..4ba6e3e 100644 --- a/src/io_platform.h +++ b/src/definitions_os.h @@ -26,37 +26,26 @@ * */ + /** * @file - * @brief Handles device I/O. + * @brief Operating system related definitions. + * + * This file is an attempt to separate operating system + * dependent functions and choose what should be used + * at compile time. */ -#ifndef IO_PLATFORM_H_INCLUDED -#define IO_PLATFORM_H_INCLUDED +#ifndef DEFINITIONS_OS_H_INCLUDED +#define DEFINITIONS_OS_H_INCLUDED -#include "wiiuse_internal.h" - -#ifdef __cplusplus -extern "C" { +#ifdef _MSC_VER + #include + /* windows with visual c */ + #define isnan(x) (_isnan(x)) + #define isinf(x) (!_finite(x)) + /* disable warnings I don't care about */ + /*#pragma warning(disable:4273) */ /* inconsistent dll linkage */ #endif - -/** @defgroup internal_io Internal: Platform-specific Device I/O */ -/** @{ */ -void wiiuse_init_platform_fields(struct wiimote_t* wm); -void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); - -int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout); - -int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes); -void wiiuse_io_disconnect(struct wiimote_t* wm); - -int wiiuse_io_read(struct wiimote_t* wm); -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len); -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* IO_PLATFORM_H_INCLUDED */ +#endif /* DEFINITIONS_OS_H_INCLUDED */ diff --git a/src/events.c b/src/events.c index 434b453..6378351 100644 --- a/src/events.c +++ b/src/events.c @@ -44,7 +44,7 @@ #include "nunchuk.h" /* for nunchuk_disconnected, etc */ #include "wiiboard.h" /* for wii_board_disconnected, etc */ #include "motion_plus.h" /* for motion_plus_disconnected, etc */ -#include "io.h" /* for wiiuse_io_read on Windows, etc */ +#include "io.h" /* for wiiuse_os_read, etc */ #ifndef WIIUSE_WIN32 #include /* for timeval */ @@ -178,7 +178,7 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - if (wiiuse_io_read(wm[i])) { + if (wiiuse_os_read(wm[i])) { /* propagate the event */ propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1); evnt += (wm[i]->event != WIIUSE_NONE); diff --git a/src/io.c b/src/io.c index 9871c8f..f43b9d3 100644 --- a/src/io.c +++ b/src/io.c @@ -34,6 +34,8 @@ #include "io.h" #include "ir.h" /* for wiiuse_set_ir_mode */ +#include "os.h" /* for wiiuse_os_* */ + #include /* for free, malloc */ /** @@ -46,7 +48,7 @@ * @return The number of wiimotes found. * * @see wiiuse_connect() - * @see wiiuse_io_find() + * @see wiiuse_os_find() * * This function will only look for wiimote devices. \n * When a device is found the address in the structures will be set. \n @@ -54,12 +56,12 @@ * devices. * * This function only delegates to the platform-specific implementation - * wiiuse_io_find. + * wiiuse_os_find. * * This function is declared in wiiuse.h */ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - return wiiuse_io_find(wm, max_wiimotes, timeout); + return wiiuse_os_find(wm, max_wiimotes, timeout); } /** @@ -72,19 +74,19 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { * * @see wiiuse_find() * @see wiiuse_disconnect() - * @see wiiuse_io_connect() + * @see wiiuse_os_connect() * * Connect to a number of wiimotes when the address is already set * in the wiimote_t structures. These addresses are normally set * by the wiiuse_find() function, but can also be set manually. * * This function only delegates to the platform-specific implementation - * wiiuse_io_connect. + * wiiuse_os_connect. * * This function is declared in wiiuse.h */ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { - return wiiuse_io_connect(wm, wiimotes); + return wiiuse_os_connect(wm, wiimotes); } /** @@ -93,17 +95,17 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { * @param wm Pointer to a wiimote_t structure. * * @see wiiuse_connect() - * @see wiiuse_io_disconnect() + * @see wiiuse_os_disconnect() * * Note that this will not free the wiimote structure. * * This function only delegates to the platform-specific implementation - * wiiuse_io_disconnect. + * wiiuse_os_disconnect. * * This function is declared in wiiuse.h */ void wiiuse_disconnect(struct wiimote_t* wm) { - wiiuse_io_disconnect(wm); + wiiuse_os_disconnect(wm); } diff --git a/src/io.h b/src/io.h index ddf634c..3e8b4ba 100644 --- a/src/io.h +++ b/src/io.h @@ -36,8 +36,6 @@ #include "wiiuse_internal.h" -#include "io_platform.h" // declare functions implemented per platform - #ifdef __cplusplus extern "C" { #endif diff --git a/src/os.h b/src/os.h index 21d9c16..8b0d814 100644 --- a/src/os.h +++ b/src/os.h @@ -26,26 +26,37 @@ * */ - /** * @file - * @brief Operating system related definitions. - * - * This file is an attempt to separate operating system - * dependent functions and choose what should be used - * at compile time. + * @brief Handles device I/O. */ -#ifndef OS_H_INCLUDED -#define OS_H_INCLUDED +#ifndef PLATFORM_H_INCLUDED +#define PLATFORM_H_INCLUDED -#ifdef _MSC_VER - #include - /* windows with visual c */ - #define isnan(x) (_isnan(x)) - #define isinf(x) (!_finite(x)) - /* disable warnings I don't care about */ - /*#pragma warning(disable:4273) */ /* inconsistent dll linkage */ +#include "wiiuse_internal.h" + +#ifdef __cplusplus +extern "C" { #endif -#endif /* OS_H_INCLUDED */ + +/** @defgroup internal_io Internal: Platform-specific Device I/O */ +/** @{ */ +void wiiuse_init_platform_fields(struct wiimote_t* wm); +void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); + +int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout); + +int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes); +void wiiuse_os_disconnect(struct wiimote_t* wm); + +int wiiuse_os_read(struct wiimote_t* wm); +int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len); +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PLATFORM_H_INCLUDED */ diff --git a/src/io_mac.m b/src/os_mac.m similarity index 83% rename from src/io_mac.m rename to src/os_mac.m index 50d6517..c75740a 100644 --- a/src/io_mac.m +++ b/src/os_mac.m @@ -50,23 +50,23 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { } -int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { +int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { return 0; } -int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { +int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { return 0; } -void wiiuse_io_disconnect(struct wiimote_t* wm) { +void wiiuse_os_disconnect(struct wiimote_t* wm) { } -int wiiuse_io_read(struct wiimote_t* wm) { +int wiiuse_os_read(struct wiimote_t* wm) { return 0; } -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { return 0; } diff --git a/src/io_nix.c b/src/os_nix.c similarity index 93% rename from src/io_nix.c rename to src/os_nix.c index e10602a..c70bb4d 100644 --- a/src/io_nix.c +++ b/src/os_nix.c @@ -47,9 +47,9 @@ #include /* for close, write */ #include -static int wiiuse_io_connect_single(struct wiimote_t* wm, char* address); +static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address); -int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { +int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { int device_id; int device_sock; inquiry_info scan_info_arr[128]; @@ -118,9 +118,9 @@ int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { /** * @see wiiuse_connect() - * @see wiiuse_io_connect_single() + * @see wiiuse_os_connect_single() */ -int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { +int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { int connected = 0; int i = 0; @@ -146,7 +146,7 @@ int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { * * @return 1 on success, 0 on failure */ -static int wiiuse_io_connect_single(struct wiimote_t* wm, char* address) { +static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) { struct sockaddr_l2 addr; memset(&addr, 0, sizeof (addr)); @@ -213,7 +213,7 @@ static int wiiuse_io_connect_single(struct wiimote_t* wm, char* address) { return 1; } -void wiiuse_io_disconnect(struct wiimote_t* wm) { +void wiiuse_os_disconnect(struct wiimote_t* wm) { if (!wm || WIIMOTE_IS_CONNECTED(wm)) return; @@ -229,13 +229,13 @@ void wiiuse_io_disconnect(struct wiimote_t* wm) { } -int wiiuse_io_read(struct wiimote_t* wm) { +int wiiuse_os_read(struct wiimote_t* wm) { /* not used */ return 0; } -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { return write(wm->out_sock, buf, len); } diff --git a/src/io_win.c b/src/os_win.c similarity index 95% rename from src/io_win.c rename to src/os_win.c index 1892b29..ca1cea6 100644 --- a/src/io_win.c +++ b/src/os_win.c @@ -52,7 +52,7 @@ extern "C" { # endif #endif -int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { +int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { GUID device_id; HANDLE dev; HDEVINFO device_info; @@ -146,7 +146,7 @@ int wiiuse_io_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { } -int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { +int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { int connected = 0; int i = 0; @@ -161,7 +161,7 @@ int wiiuse_io_connect(struct wiimote_t** wm, int wiimotes) { } -void wiiuse_io_disconnect(struct wiimote_t* wm) { +void wiiuse_os_disconnect(struct wiimote_t* wm) { if (!wm || WIIMOTE_IS_CONNECTED(wm)) return; @@ -177,7 +177,7 @@ void wiiuse_io_disconnect(struct wiimote_t* wm) { } -int wiiuse_io_read(struct wiimote_t* wm) { +int wiiuse_os_read(struct wiimote_t* wm) { DWORD b, r; if (!wm || !WIIMOTE_IS_CONNECTED(wm)) @@ -217,7 +217,7 @@ int wiiuse_io_read(struct wiimote_t* wm) { } -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { DWORD bytes; int i; diff --git a/src/wiiuse.c b/src/wiiuse.c index 2b13d29..80dbf10 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -37,6 +37,7 @@ #include "wiiuse_internal.h" #include "io.h" /* for wiiuse_handshake, etc */ +#include "os.h" /* for wiiuse_os_* */ #include /* for printf, FILE */ #include /* for malloc, free */ @@ -706,9 +707,9 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { #endif #ifndef WIIUSE_WIN32 - return wiiuse_io_write(wm, buf, len+2); + return wiiuse_os_write(wm, buf, len+2); #else - return wiiuse_io_write(wm, buf, len+1); + return wiiuse_os_write(wm, buf, len+1); #endif } From 71569818e5bf4c3f7a826f138b4c0f50950a4d5b Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 13:56:06 +0100 Subject: [PATCH 10/55] make wiimote_poll a platform-specific function, move implementations to os_*.c/os_mac.m --- src/events.c | 136 ++------------------------------------------------- src/events.h | 2 + src/os.h | 1 + src/os_mac.m | 25 ++++++++-- src/os_nix.c | 90 ++++++++++++++++++++++++++++++++++ src/os_win.c | 26 ++++++++++ 6 files changed, 142 insertions(+), 138 deletions(-) diff --git a/src/events.c b/src/events.c index 6378351..70d3404 100644 --- a/src/events.c +++ b/src/events.c @@ -44,20 +44,13 @@ #include "nunchuk.h" /* for nunchuk_disconnected, etc */ #include "wiiboard.h" /* for wii_board_disconnected, etc */ #include "motion_plus.h" /* for motion_plus_disconnected, etc */ -#include "io.h" /* for wiiuse_os_read, etc */ -#ifndef WIIUSE_WIN32 - #include /* for timeval */ - #include /* for select, fd_set */ - #include /* for read */ -#endif +#include "os.h" /* for wiiuse_os_poll */ -#include /* for errno */ #include /* for printf, perror */ #include /* for free, malloc */ #include /* for memcpy, memset */ -static void idle_cycle(struct wiimote_t* wm); static void clear_dirty_reads(struct wiimote_t* wm); static void event_data_read(struct wiimote_t* wm, byte* msg); static void event_data_write(struct wiimote_t *wm, byte *msg); @@ -80,130 +73,7 @@ static int state_changed(struct wiimote_t* wm); * the event variable will be set. */ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) { - int evnt = 0; - - #ifdef WIIUSE_BLUEZ - /* - * *nix - */ - struct timeval tv; - fd_set fds; - int r; - int i; - int highest_fd = -1; - - if (!wm) return 0; - - /* block select() for 1/2000th of a second */ - tv.tv_sec = 0; - tv.tv_usec = 500; - - FD_ZERO(&fds); - - for (i = 0; i < wiimotes; ++i) { - /* only poll it if it is connected */ - if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) { - FD_SET(wm[i]->in_sock, &fds); - - /* find the highest fd of the connected wiimotes */ - if (wm[i]->in_sock > highest_fd) - highest_fd = wm[i]->in_sock; - } - - wm[i]->event = WIIUSE_NONE; - } - - if (highest_fd == -1) - /* nothing to poll */ - return 0; - - if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) { - WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s)."); - perror("Error Details"); - return 0; - } - - /* check each socket for an event */ - for (i = 0; i < wiimotes; ++i) { - /* if this wiimote is not connected, skip it */ - if (!WIIMOTE_IS_CONNECTED(wm[i])) - continue; - - if (FD_ISSET(wm[i]->in_sock, &fds)) { - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - - /* clear out any old read requests */ - clear_dirty_reads(wm[i]); - - /* read the pending message into the buffer */ - r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf)); - if (r == -1) { - /* error reading data */ - WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid); - perror("Error Details"); - - if (errno == ENOTCONN) { - /* this can happen if the bluetooth dongle is disconnected */ - WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid); - wiiuse_disconnect(wm[i]); - wiiuse_disconnected(wm[i]); - wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT; - } - - continue; - } - if (!r) { - /* remote disconnect */ - wiiuse_disconnected(wm[i]); - evnt = 1; - continue; - } - - /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - evnt += (wm[i]->event != WIIUSE_NONE); - } else { - idle_cycle(wm[i]); - } - } - #elif defined(WIIUSE_WIN32) - /* - * Windows - */ - int i; - - if (!wm) return 0; - - for (i = 0; i < wiimotes; ++i) { - wm[i]->event = WIIUSE_NONE; - - if (wiiuse_os_read(wm[i])) { - /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1); - evnt += (wm[i]->event != WIIUSE_NONE); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - } else { - idle_cycle(wm[i]); - } - } - #elif defined(WIIUSE_MAC) - /* - * Mac - */ - int i; - - if (!wm) return 0; - - for (i = 0; i < wiimotes; ++i) { - wm[i]->event = WIIUSE_NONE; - idle_cycle(wm[i]); - } - #endif - - return evnt; + return wiiuse_os_poll(wm, wiimotes); } int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb callback) { @@ -244,7 +114,7 @@ int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb c * * @param wm Pointer to a wiimote_t structure. */ -static void idle_cycle(struct wiimote_t* wm) { +void idle_cycle(struct wiimote_t* wm) { /* * Smooth the angles. * diff --git a/src/events.h b/src/events.h index e9809e5..fde16a3 100644 --- a/src/events.h +++ b/src/events.h @@ -56,6 +56,8 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len); void disable_expansion(struct wiimote_t* wm); void propagate_event(struct wiimote_t* wm, byte event, byte* msg); + +void idle_cycle(struct wiimote_t* wm); /** @} */ #endif /* EVENTS_H_INCLUDED */ diff --git a/src/os.h b/src/os.h index 8b0d814..3d8d68b 100644 --- a/src/os.h +++ b/src/os.h @@ -51,6 +51,7 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout); int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes); void wiiuse_os_disconnect(struct wiimote_t* wm); +int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes); int wiiuse_os_read(struct wiimote_t* wm); int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len); /** @} */ diff --git a/src/os_mac.m b/src/os_mac.m index c75740a..68e9c78 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -33,7 +33,9 @@ #ifdef __APPLE__ -#include "io.h" +#import "io.h" +#import "events.h" +#import "os.h" #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 #define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 @@ -51,23 +53,36 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { } int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - return 0; + return 0; } int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { - return 0; + return 0; } void wiiuse_os_disconnect(struct wiimote_t* wm) { } +int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { + int i; + + if (!wm) return 0; + + for (i = 0; i < wiimotes; ++i) { + wm[i]->event = WIIUSE_NONE; + idle_cycle(wm[i]); + } + + return 0; +} + int wiiuse_os_read(struct wiimote_t* wm) { - return 0; + return 0; } int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { - return 0; + return 0; } #endif // __APPLE__ diff --git a/src/os_nix.c b/src/os_nix.c index c70bb4d..838c84b 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -32,6 +32,8 @@ */ #include "io.h" +#include "events.h" +#include "os.h" #ifdef WIIUSE_BLUEZ @@ -229,6 +231,94 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { } +int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { + int evnt; + struct timeval tv; + fd_set fds; + int r; + int i; + int highest_fd = -1; + + evnt = 0; + if (!wm) return 0; + + /* block select() for 1/2000th of a second */ + tv.tv_sec = 0; + tv.tv_usec = 500; + + FD_ZERO(&fds); + + for (i = 0; i < wiimotes; ++i) { + /* only poll it if it is connected */ + if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) { + FD_SET(wm[i]->in_sock, &fds); + + /* find the highest fd of the connected wiimotes */ + if (wm[i]->in_sock > highest_fd) + highest_fd = wm[i]->in_sock; + } + + wm[i]->event = WIIUSE_NONE; + } + + if (highest_fd == -1) + /* nothing to poll */ + return 0; + + if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) { + WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s)."); + perror("Error Details"); + return 0; + } + + /* check each socket for an event */ + for (i = 0; i < wiimotes; ++i) { + /* if this wiimote is not connected, skip it */ + if (!WIIMOTE_IS_CONNECTED(wm[i])) + continue; + + if (FD_ISSET(wm[i]->in_sock, &fds)) { + /* clear out the event buffer */ + memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + + /* clear out any old read requests */ + clear_dirty_reads(wm[i]); + + /* read the pending message into the buffer */ + r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf)); + if (r == -1) { + /* error reading data */ + WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid); + perror("Error Details"); + + if (errno == ENOTCONN) { + /* this can happen if the bluetooth dongle is disconnected */ + WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid); + wiiuse_disconnect(wm[i]); + wiiuse_disconnected(wm[i]); + wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT; + } + + continue; + } + if (!r) { + /* remote disconnect */ + wiiuse_disconnected(wm[i]); + evnt = 1; + continue; + } + + /* propagate the event */ + propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); + evnt += (wm[i]->event != WIIUSE_NONE); + } else { + idle_cycle(wm[i]); + } + } + + return evnt; +} + int wiiuse_os_read(struct wiimote_t* wm) { /* not used */ return 0; diff --git a/src/os_win.c b/src/os_win.c index ca1cea6..fec5f50 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -33,6 +33,8 @@ #include "io.h" +#include "events.h" +#include "os.h" #ifdef WIIUSE_WIN32 #include @@ -177,6 +179,30 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { } +int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { + int i; + int evnt = 0; + + if (!wm) return 0; + + for (i = 0; i < wiimotes; ++i) { + wm[i]->event = WIIUSE_NONE; + + if (wiiuse_os_read(wm[i])) { + /* propagate the event */ + propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1); + evnt += (wm[i]->event != WIIUSE_NONE); + + /* clear out the event buffer */ + memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + } else { + idle_cycle(wm[i]); + } + } + + return evnt; +} + int wiiuse_os_read(struct wiimote_t* wm) { DWORD b, r; From b68c03efd74fea0bc3561ed0538b7a002527f279 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 16:22:00 +0100 Subject: [PATCH 11/55] implement wiiuse_os_find for mac --- src/os_mac.m | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/wiiuse.h | 12 ++-- 2 files changed, 185 insertions(+), 11 deletions(-) diff --git a/src/os_mac.m b/src/os_mac.m index 68e9c78..d4afdd8 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -37,6 +37,15 @@ #import "events.h" #import "os.h" + +#define BLUETOOTH_VERSION_USE_CURRENT +#import +#import +#import +#import +#import + + #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 #define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 #else @@ -44,18 +53,175 @@ #endif -void wiiuse_init_platform_fields(struct wiimote_t* wm) { +#pragma mark - +#pragma mark wiiuse_os_find +@interface WiiuseDeviceInquiry : NSObject { + wiimote** wiimotes; + NSUInteger maxDevices; + int timeout; + + BOOL _running; + NSUInteger _foundDevices; + BOOL _inquiryComplete; } -void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { +- (id) initWithMemory:(wiimote**)wiimotes maxDevices:(int)maxDevices timeout:(int)timeout; +- (int) run; +@end + +@implementation WiiuseDeviceInquiry + +- (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ { + self = [super init]; + if(self) { + wiimotes = wiimotes_; + maxDevices = maxDevices_; + timeout = timeout_; + + _running = NO; + } + return self; } +// creates and starts inquiry. the returned object is in the current autorelease pool. +- (IOBluetoothDeviceInquiry*) start { + + // reset state variables + _foundDevices = 0; + _inquiryComplete = NO; + + // create inquiry + IOBluetoothDeviceInquiry* inquiry = [IOBluetoothDeviceInquiry inquiryWithDelegate: self]; + + // refine search & set timeout + [inquiry setSearchCriteria:kBluetoothServiceClassMajorAny + majorDeviceClass:WM_DEV_MAJOR_CLASS + minorDeviceClass:WM_DEV_MINOR_CLASS]; + [inquiry setUpdateNewDeviceNames: NO]; + if(timeout > 0) + [inquiry setInquiryLength:timeout]; + + // start inquiry + IOReturn status = [inquiry start]; + if (status != kIOReturnSuccess) { + WIIUSE_ERROR("Unable to start bluetooth device inquiry."); + if(![inquiry stop]) { + WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); + } else { + WIIUSE_DEBUG("Bluetooth device inquiry stopped."); + } + return nil; + } + + return inquiry; +} + +- (void) wait { + // wait for the inquiry to complete + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + while(!_inquiryComplete && + [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) { + // no-op + } +} + +- (NSUInteger) collectResultsOf: (IOBluetoothDeviceInquiry*) inquiry { + // read found device information + NSArray* devices = [inquiry foundDevices]; + for(NSUInteger i = 0; i < [devices count]; i++) { + IOBluetoothDevice* device = [devices objectAtIndex:i]; +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + IOBluetoothDeviceRef deviceRef = (IOBluetoothDeviceRef)device; +#else + IOBluetoothDeviceRef deviceRef = [device getDeviceRef]; +#endif + + // save the device in the wiimote structure + wiimotes[i]->device = deviceRef; + [device retain]; // must retain it for later access through its ref + + // mark as found + WIIMOTE_ENABLE_STATE(wiimotes[i], WIIMOTE_STATE_DEV_FOUND); + NSString* address = IOBluetoothNSStringFromDeviceAddress([device getAddress]); + const char* address_str = [address cStringUsingEncoding:NSMacOSRomanStringEncoding]; + WIIUSE_INFO("Found Wiimote (%s) [id %i]", address_str, wiimotes[i]->unid); + } + + return [devices count]; +} + +- (int) run { + int result = -1; + + if(maxDevices == 0) { + result = 0; + } else if(!_running) { + _running = YES; + + if (![IOBluetoothHostController defaultController]) { + WIIUSE_ERROR("Unable to find any bluetooth receiver on your host."); + } else { + IOBluetoothDeviceInquiry* inquiry = [self start]; + if(inquiry) { + [self wait]; + result = [self collectResultsOf: inquiry]; + WIIUSE_INFO("Found %i Wiimote device(s).", result); + } + } + + _running = NO; + } else { // if(_running) + WIIUSE_ERROR("Device inquiry already running - won't start it again."); + } + + return result; +} + +- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) inquiry device:(IOBluetoothDevice *) device { + + WIIUSE_DEBUG("Found a wiimote"); + + _foundDevices++; + if(_foundDevices >= maxDevices) { + // reached maximum number of devices + if(![inquiry stop]) + WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); + _inquiryComplete = YES; + } +} + +- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) inquiry error:(IOReturn) error aborted:(BOOL) aborted +{ + WIIUSE_DEBUG("Inquiry complete, error=%i, aborted=%s", error, aborted ? "YES" : "NO"); + + // mark completion + _inquiryComplete = YES; + + // print error message if we stop due to an error + if ((error != kIOReturnSuccess) && !aborted) { + WIIUSE_ERROR("Bluetooth device inquiry not completed due to unexpected errors. Try increasing the timeout."); + } +} + +@end + int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - return 0; + int result; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + WiiuseDeviceInquiry* inquiry = [[WiiuseDeviceInquiry alloc] initWithMemory:wm maxDevices:max_wiimotes timeout:timeout]; + result = [inquiry run]; + [inquiry release]; + + [pool drain]; + return result; } +#pragma mark - + int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { return 0; } @@ -64,6 +230,8 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { } +#pragma mark - + int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int i; @@ -85,4 +253,14 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { return 0; } +#pragma mark - + +void wiiuse_init_platform_fields(struct wiimote_t* wm) { + +} + +void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { + +} + #endif // __APPLE__ diff --git a/src/wiiuse.h b/src/wiiuse.h index 85af147..48297c3 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -101,6 +101,7 @@ #endif #ifdef WIIUSE_MAC /* mac */ + #include #endif #ifndef WCONST @@ -700,6 +701,7 @@ typedef struct wiimote_t { #ifdef WIIUSE_BLUEZ /** @name Linux-specific (BlueZ) members */ /** @{ */ + WCONST char bdaddr_str[18]; /**< readable bt address */ WCONST bdaddr_t bdaddr; /**< bt address */ WCONST int out_sock; /**< output socket */ WCONST int in_sock; /**< input socket */ @@ -721,13 +723,7 @@ typedef struct wiimote_t { #ifdef WIIUSE_MAC /** @name Mac OS X-specific members */ /** @{ */ - /** @} */ - #endif - - #if defined(WIIUSE_BLUEZ) || defined(WIIUSE_MAC) - /** @name Linux (BlueZ) and Mac OS X shared members */ - /** @{ */ - WCONST char bdaddr_str[18]; /**< readable bt address */ + WCONST IOBluetoothDeviceRef device; /** Device reference object */ /** @} */ #endif @@ -738,7 +734,7 @@ typedef struct wiimote_t { WCONST int flags; /**< options flag */ WCONST byte handshake_state; /**< the state of the connection handshake */ - WCONST byte expansion_state; /**< the state of the expansion handshake */ + WCONST byte expansion_state; /**< the state of the expansion handshake */ WCONST struct data_req_t* data_req; /**< list of data read requests */ WCONST struct read_req_t* read_req; /**< list of data read requests */ From a154eb553610ae5067a84353fb783f160c79084c Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 17:17:37 +0100 Subject: [PATCH 12/55] move find implementation for mac to different file; refactor a bit --- src/CMakeLists.txt | 8 +- src/os_mac.m | 185 ++-------------------------------- src/os_mac/os_mac.h | 66 ++++++++++++ src/os_mac/os_mac_find.m | 212 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 292 insertions(+), 179 deletions(-) create mode 100644 src/os_mac/os_mac.h create mode 100644 src/os_mac/os_mac_find.m diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0231444..7906b76 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,10 +30,14 @@ if(WIN32) list(APPEND SOURCES os_win.c) set(CMAKE_DEBUG_POSTFIX _debug) elseif(APPLE) - list(APPEND SOURCES os_mac.m) + set(MAC_SOURCES + os_mac.m + os_mac/os_mac.h + os_mac/os_mac_find.m) + list(APPEND SOURCES ${MAC_SOURCES}) # make sure we use the gcc for Objective-C files as well so that the # sysroot and deployment target arguments are correctly passed to the compiler - SET_SOURCE_FILES_PROPERTIES(os_mac.m PROPERTIES LANGUAGE C) + SET_SOURCE_FILES_PROPERTIES(${MAC_SOURCES} PROPERTIES LANGUAGE C) else() list(APPEND SOURCES os_nix.c) endif() diff --git a/src/os_mac.m b/src/os_mac.m index d4afdd8..355f125 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -33,6 +33,8 @@ #ifdef __APPLE__ +#import "os_mac/os_mac.h" + #import "io.h" #import "events.h" #import "os.h" @@ -46,181 +48,8 @@ #import -#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 -#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 -#else -#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 -#endif - - -#pragma mark - -#pragma mark wiiuse_os_find - -@interface WiiuseDeviceInquiry : NSObject { - wiimote** wiimotes; - NSUInteger maxDevices; - int timeout; - - BOOL _running; - NSUInteger _foundDevices; - BOOL _inquiryComplete; -} - -- (id) initWithMemory:(wiimote**)wiimotes maxDevices:(int)maxDevices timeout:(int)timeout; -- (int) run; - -@end - -@implementation WiiuseDeviceInquiry - -- (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ { - self = [super init]; - if(self) { - wiimotes = wiimotes_; - maxDevices = maxDevices_; - timeout = timeout_; - - _running = NO; - } - return self; -} - -// creates and starts inquiry. the returned object is in the current autorelease pool. -- (IOBluetoothDeviceInquiry*) start { - - // reset state variables - _foundDevices = 0; - _inquiryComplete = NO; - - // create inquiry - IOBluetoothDeviceInquiry* inquiry = [IOBluetoothDeviceInquiry inquiryWithDelegate: self]; - - // refine search & set timeout - [inquiry setSearchCriteria:kBluetoothServiceClassMajorAny - majorDeviceClass:WM_DEV_MAJOR_CLASS - minorDeviceClass:WM_DEV_MINOR_CLASS]; - [inquiry setUpdateNewDeviceNames: NO]; - if(timeout > 0) - [inquiry setInquiryLength:timeout]; - - // start inquiry - IOReturn status = [inquiry start]; - if (status != kIOReturnSuccess) { - WIIUSE_ERROR("Unable to start bluetooth device inquiry."); - if(![inquiry stop]) { - WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); - } else { - WIIUSE_DEBUG("Bluetooth device inquiry stopped."); - } - return nil; - } - - return inquiry; -} - -- (void) wait { - // wait for the inquiry to complete - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - while(!_inquiryComplete && - [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) { - // no-op - } -} - -- (NSUInteger) collectResultsOf: (IOBluetoothDeviceInquiry*) inquiry { - // read found device information - NSArray* devices = [inquiry foundDevices]; - for(NSUInteger i = 0; i < [devices count]; i++) { - IOBluetoothDevice* device = [devices objectAtIndex:i]; -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE - IOBluetoothDeviceRef deviceRef = (IOBluetoothDeviceRef)device; -#else - IOBluetoothDeviceRef deviceRef = [device getDeviceRef]; -#endif - - // save the device in the wiimote structure - wiimotes[i]->device = deviceRef; - [device retain]; // must retain it for later access through its ref - - // mark as found - WIIMOTE_ENABLE_STATE(wiimotes[i], WIIMOTE_STATE_DEV_FOUND); - NSString* address = IOBluetoothNSStringFromDeviceAddress([device getAddress]); - const char* address_str = [address cStringUsingEncoding:NSMacOSRomanStringEncoding]; - WIIUSE_INFO("Found Wiimote (%s) [id %i]", address_str, wiimotes[i]->unid); - } - - return [devices count]; -} - -- (int) run { - int result = -1; - - if(maxDevices == 0) { - result = 0; - } else if(!_running) { - _running = YES; - - if (![IOBluetoothHostController defaultController]) { - WIIUSE_ERROR("Unable to find any bluetooth receiver on your host."); - } else { - IOBluetoothDeviceInquiry* inquiry = [self start]; - if(inquiry) { - [self wait]; - result = [self collectResultsOf: inquiry]; - WIIUSE_INFO("Found %i Wiimote device(s).", result); - } - } - - _running = NO; - } else { // if(_running) - WIIUSE_ERROR("Device inquiry already running - won't start it again."); - } - - return result; -} - -- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) inquiry device:(IOBluetoothDevice *) device { - - WIIUSE_DEBUG("Found a wiimote"); - - _foundDevices++; - if(_foundDevices >= maxDevices) { - // reached maximum number of devices - if(![inquiry stop]) - WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); - _inquiryComplete = YES; - } -} - -- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) inquiry error:(IOReturn) error aborted:(BOOL) aborted -{ - WIIUSE_DEBUG("Inquiry complete, error=%i, aborted=%s", error, aborted ? "YES" : "NO"); - - // mark completion - _inquiryComplete = YES; - - // print error message if we stop due to an error - if ((error != kIOReturnSuccess) && !aborted) { - WIIUSE_ERROR("Bluetooth device inquiry not completed due to unexpected errors. Try increasing the timeout."); - } -} - -@end - -int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - int result; - - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - WiiuseDeviceInquiry* inquiry = [[WiiuseDeviceInquiry alloc] initWithMemory:wm maxDevices:max_wiimotes timeout:timeout]; - result = [inquiry run]; - [inquiry release]; - - [pool drain]; - return result; -} - #pragma mark - +#pragma mark connect, disconnect int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { return 0; @@ -231,6 +60,7 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { } #pragma mark - +#pragma mark poll, read, write int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int i; @@ -253,14 +83,15 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { return 0; } -#pragma mark - +#pragma mark platform fields void wiiuse_init_platform_fields(struct wiimote_t* wm) { - + wm->device = NULL; } void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { - + [WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(wm->device) release]; + wm->device = NULL; } #endif // __APPLE__ diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h new file mode 100644 index 0000000..abe875c --- /dev/null +++ b/src/os_mac/os_mac.h @@ -0,0 +1,66 @@ +/* + * 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 . + * + * $Header$ + * + */ + +/** + * @file + * @brief Handles device I/O for Mac OS X. + */ + +#ifdef __APPLE__ + + +#import + + +#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 +#else +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 +#endif + + +// WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +#define WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef(device) \ + ((IOBluetoothDeviceRef) (device)) +#else +#define WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef(device) \ + [(device) getDeviceRef] +#endif + +// WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +#define WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(ref) \ + ((IOBluetoothDevice*) (ref)) +#else +#define WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(ref) \ + [IOBluetoothDevice withDeviceRef: (ref)] +#endif + + +#endif // __APPLE__ diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m new file mode 100644 index 0000000..200fb64 --- /dev/null +++ b/src/os_mac/os_mac_find.m @@ -0,0 +1,212 @@ +/* + * 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 . + * + * $Header$ + * + */ + +/** + * @file + * @brief Handles device I/O for Mac OS X. + */ + +#ifdef __APPLE__ + +#import "os_mac.h" + +#import "../io.h" +#import "../events.h" +#import "../os.h" + + +#define BLUETOOTH_VERSION_USE_CURRENT +#import +#import +#import +#import + + +#pragma mark - +#pragma mark find + +@interface WiiuseDeviceInquiry : NSObject { + wiimote** wiimotes; + NSUInteger maxDevices; + int timeout; + + BOOL _running; + NSUInteger _foundDevices; + BOOL _inquiryComplete; +} + +- (id) initWithMemory:(wiimote**)wiimotes maxDevices:(int)maxDevices timeout:(int)timeout; +- (int) run; + +@end + +@implementation WiiuseDeviceInquiry + +- (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ { + self = [super init]; + if(self) { + wiimotes = wiimotes_; + maxDevices = maxDevices_; + timeout = timeout_; + + _running = NO; + } + return self; +} + +// creates and starts inquiry. the returned object is in the current autorelease pool. +- (IOBluetoothDeviceInquiry*) start { + + // reset state variables + _foundDevices = 0; + _inquiryComplete = NO; + + // create inquiry + IOBluetoothDeviceInquiry* inquiry = [IOBluetoothDeviceInquiry inquiryWithDelegate: self]; + + // refine search & set timeout + [inquiry setSearchCriteria:kBluetoothServiceClassMajorAny + majorDeviceClass:WM_DEV_MAJOR_CLASS + minorDeviceClass:WM_DEV_MINOR_CLASS]; + [inquiry setUpdateNewDeviceNames: NO]; + if(timeout > 0) + [inquiry setInquiryLength:timeout]; + + // start inquiry + IOReturn status = [inquiry start]; + if (status != kIOReturnSuccess) { + WIIUSE_ERROR("Unable to start bluetooth device inquiry."); + if(![inquiry stop]) { + WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); + } else { + WIIUSE_DEBUG("Bluetooth device inquiry stopped."); + } + return nil; + } + + return inquiry; +} + +- (void) wait { + // wait for the inquiry to complete + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + while(!_inquiryComplete && + [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) { + // no-op + } +} + +- (NSUInteger) collectResultsOf: (IOBluetoothDeviceInquiry*) inquiry { + // read found device information + NSArray* devices = [inquiry foundDevices]; + for(NSUInteger i = 0; i < [devices count]; i++) { + IOBluetoothDevice* device = [devices objectAtIndex:i]; + + // save the device in the wiimote structure + wiimotes[i]->device = WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef(device); + [device retain]; // must retain it for later access through its ref + + // mark as found + WIIMOTE_ENABLE_STATE(wiimotes[i], WIIMOTE_STATE_DEV_FOUND); + NSString* address = IOBluetoothNSStringFromDeviceAddress([device getAddress]); + const char* address_str = [address cStringUsingEncoding:NSMacOSRomanStringEncoding]; + WIIUSE_INFO("Found Wiimote (%s) [id %i]", address_str, wiimotes[i]->unid); + } + + return [devices count]; +} + +- (int) run { + int result = -1; + + if(maxDevices == 0) { + result = 0; + } else if(!_running) { + _running = YES; + + if (![IOBluetoothHostController defaultController]) { + WIIUSE_ERROR("Unable to find any bluetooth receiver on your host."); + } else { + IOBluetoothDeviceInquiry* inquiry = [self start]; + if(inquiry) { + [self wait]; + result = [self collectResultsOf: inquiry]; + WIIUSE_INFO("Found %i Wiimote device(s).", result); + } + } + + _running = NO; + } else { // if(_running) + WIIUSE_ERROR("Device inquiry already running - won't start it again."); + } + + return result; +} + +- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) inquiry device:(IOBluetoothDevice *) device { + + WIIUSE_DEBUG("Found a wiimote"); + + _foundDevices++; + if(_foundDevices >= maxDevices) { + // reached maximum number of devices + if(![inquiry stop]) + WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); + _inquiryComplete = YES; + } +} + +- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) inquiry error:(IOReturn) error aborted:(BOOL) aborted +{ + WIIUSE_DEBUG("Inquiry complete, error=%i, aborted=%s", error, aborted ? "YES" : "NO"); + + // mark completion + _inquiryComplete = YES; + + // print error message if we stop due to an error + if ((error != kIOReturnSuccess) && !aborted) { + WIIUSE_ERROR("Bluetooth device inquiry not completed due to unexpected errors. Try increasing the timeout."); + } +} + +@end + +int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { + int result; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + WiiuseDeviceInquiry* inquiry = [[WiiuseDeviceInquiry alloc] initWithMemory:wm maxDevices:max_wiimotes timeout:timeout]; + result = [inquiry run]; + [inquiry release]; + + [pool drain]; + return result; +} + +#endif // __APPLE__ From 7d9c82f6042df4bfbc193c28f0b4274621cface9 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 18:31:00 +0100 Subject: [PATCH 13/55] implement wiiuse_os_connect for mac --- src/os_mac.m | 143 ++++++++++++++++++++++++++++++++++++++- src/os_mac/os_mac.h | 34 ++++++++++ src/os_mac/os_mac_find.m | 15 ++-- src/wiiuse.h | 5 +- 4 files changed, 188 insertions(+), 9 deletions(-) diff --git a/src/os_mac.m b/src/os_mac.m index 355f125..17c2662 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -39,8 +39,6 @@ #import "events.h" #import "os.h" - -#define BLUETOOTH_VERSION_USE_CURRENT #import #import #import @@ -51,8 +49,78 @@ #pragma mark - #pragma mark connect, disconnect +/** + * @brief Connect to a wiimote with a known address. + * + * @param wm Pointer to a wiimote_t structure. + * + * @see wiimote_os_connect() + * @see wiimote_os_find() + * + * @return 1 on success, 0 on failure + */ +static short wiiuse_os_connect_single(struct wiimote_t* wm) { + // Skip if already connected or device not found + if(!wm) { + WIIUSE_ERROR("No Wiimote given."); + return 0; + } else if(wm && (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_DEV_FOUND) || wm->device == NULL)) { + WIIUSE_ERROR("Tried to connect Wiimote without an address."); + return 0; + } else if(WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_WARNING("Wiimote [id %i] is already connected.", wm->unid); + return 1; + } + + WIIUSE_DEBUG("Connecting to Wiimote [id %i].", wm->unid); + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + short result = 0; + + // connect + WiiuseWiimote* objc_wm = [[WiiuseWiimote alloc] initWithPtr: wm]; + if([objc_wm connect] == kIOReturnSuccess) { + WIIUSE_INFO("Connected to Wiimote [id %i].", wm->unid); + + // save the connect structure to retrieve data later on + wm->objc_wm = (void*)objc_wm; + + // save the connection status + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); + + // Do the handshake + wiiuse_handshake(wm, NULL, 0); + wiiuse_set_report_type(wm); + + result = 1; + } else { + [objc_wm release]; + } + + [pool drain]; + return result; +} + int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { - return 0; + int connected = 0; + + int i; + for (i = 0; i < wiimotes; ++i) { + if(wm[i] == NULL) { + WIIUSE_ERROR("Trying to connect to non-initialized Wiimote."); + break; + } + + if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND) || !wm[i]->device) { + // If the device is not set, skip it + continue; + } + + if (wiiuse_os_connect_single(wm[i])) + ++connected; + } + + return connected; } void wiiuse_os_disconnect(struct wiimote_t* wm) { @@ -87,11 +155,80 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { void wiiuse_init_platform_fields(struct wiimote_t* wm) { wm->device = NULL; + wm->objc_wm = NULL; + wm->controlChannel = NULL; + wm->interruptChannel = NULL; } void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { [WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(wm->device) release]; wm->device = NULL; + + [((WiiuseWiimote*) wm->objc_wm) release]; + wm->objc_wm = NULL; } +#pragma mark - +#pragma mark WiiuseWiimote + +@implementation WiiuseWiimote + +- (id) initWithPtr: (wiimote*) wm_ { + self = [super init]; + if(self) { + wm = wm_; + disconnectNotification = nil; + } + return self; +} + +- (void) dealloc { + wm = NULL; + + [disconnectNotification release]; + disconnectNotification = nil; + + [super dealloc]; +} + +- (IOReturn) connect { + IOBluetoothDevice* device = WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(wm->device); + if(!device) { + WIIUSE_ERROR("Missing device."); + return kIOReturnBadArgument; + } + + // open channels + IOBluetoothL2CAPChannel* controlChannel = nil, *interruptChannel = nil; + if ([device openL2CAPChannelSync:&controlChannel withPSM:WM_OUTPUT_CHANNEL delegate:self] != kIOReturnSuccess) { + WIIUSE_ERROR("Unable to open L2CAP control channel [id %i].", wm->unid); + [device closeConnection]; + return kIOReturnNotOpen; + } else if([device openL2CAPChannelSync:&interruptChannel withPSM:WM_INPUT_CHANNEL delegate:self] != kIOReturnSuccess) { + WIIUSE_ERROR("Unable to open L2CAP interrupt channel [id %i].", wm->unid); + [controlChannel closeChannel]; + [device closeConnection]; + return kIOReturnNotOpen; + } + + // register for device disconnection + disconnectNotification = [device registerForDisconnectNotification:self selector:@selector(disconnected:fromDevice:)]; + if(!disconnectNotification) { + WIIUSE_ERROR("Unable to register disconnection handler [id %i].", wm->unid); + [interruptChannel closeChannel]; + [controlChannel closeChannel]; + [device closeConnection]; + return kIOReturnNotOpen; + } + + // retain channels, and save them to the C struct + [controlChannel retain]; [interruptChannel retain]; + wm->controlChannel = WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(controlChannel); + wm->interruptChannel = WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(interruptChannel); + + return kIOReturnSuccess; +} + +@end + #endif // __APPLE__ diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index abe875c..667f4ce 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -34,7 +34,12 @@ #ifdef __APPLE__ +#define BLUETOOTH_VERSION_USE_CURRENT + #import +#import + +#import "../wiiuse_internal.h" #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 @@ -62,5 +67,34 @@ [IOBluetoothDevice withDeviceRef: (ref)] #endif +// WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +#define WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(channel) \ + ((IOBluetoothL2CAPChannelRef) (channel)) +#else +#define WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(channel) \ + [(channel) getL2CAPChannelRef] +#endif + +// WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +#define WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel(ref) \ + ((IOBluetoothL2CAPChannel*) (ref)) +#else +#define WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel(ref) \ + [IOBluetoothL2CAPChannel withChanneleRef: (ref)] +#endif + + +@interface WiiuseWiimote : NSObject { + wiimote* wm; // reference to the C wiimote struct + IOBluetoothUserNotification* disconnectNotification; +} + +- (id) initWithPtr: (wiimote*) wm; +- (IOReturn) connect; + +@end + #endif // __APPLE__ diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index 200fb64..032d262 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -39,8 +39,6 @@ #import "../events.h" #import "../os.h" - -#define BLUETOOTH_VERSION_USE_CURRENT #import #import #import @@ -48,7 +46,7 @@ #pragma mark - -#pragma mark find +#pragma mark WiiuseDeviceInquiry @interface WiiuseDeviceInquiry : NSObject { wiimote** wiimotes; @@ -122,6 +120,10 @@ } - (NSUInteger) collectResultsOf: (IOBluetoothDeviceInquiry*) inquiry { + // stop the inquiry + if(![inquiry stop]) + WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); + // read found device information NSArray* devices = [inquiry foundDevices]; for(NSUInteger i = 0; i < [devices count]; i++) { @@ -168,6 +170,8 @@ return result; } +#pragma mark IOBluetoothDeviceInquiryDelegate + - (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) inquiry device:(IOBluetoothDevice *) device { WIIUSE_DEBUG("Found a wiimote"); @@ -175,8 +179,6 @@ _foundDevices++; if(_foundDevices >= maxDevices) { // reached maximum number of devices - if(![inquiry stop]) - WIIUSE_ERROR("Unable to stop bluetooth device inquiry."); _inquiryComplete = YES; } } @@ -196,6 +198,9 @@ @end +#pragma mark - +#pragma mark public interface + int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { int result; diff --git a/src/wiiuse.h b/src/wiiuse.h index 48297c3..f88e793 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -723,7 +723,10 @@ typedef struct wiimote_t { #ifdef WIIUSE_MAC /** @name Mac OS X-specific members */ /** @{ */ - WCONST IOBluetoothDeviceRef device; /** Device reference object */ + WCONST IOBluetoothDeviceRef device; /** Device reference */ + WCONST void* objc_wm; /** WiiuseWiimote* as opaque pointer */ + WCONST IOBluetoothL2CAPChannelRef controlChannel; /** control channel reference */ + WCONST IOBluetoothL2CAPChannelRef interruptChannel; /** interrupt channel reference */ /** @} */ #endif From b295af07771ad84e1c3b94dfe3059d6aef911441 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 19:20:30 +0100 Subject: [PATCH 14/55] implement wiiuse_os_disconnect for mac --- src/os_mac.m | 72 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/src/os_mac.m b/src/os_mac.m index 17c2662..620c77c 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -47,7 +47,7 @@ #pragma mark - -#pragma mark connect, disconnect +#pragma mark connect /** * @brief Connect to a wiimote with a known address. @@ -123,8 +123,56 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { return connected; } -void wiiuse_os_disconnect(struct wiimote_t* wm) { +#pragma mark disconnect +#define WIIUSE_MAC_CLOSE_CHANNEL(wm, channel) \ + { \ + IOBluetoothL2CAPChannel* channel = WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel((wm)->channel##Channel); \ + if([channel closeChannel] != kIOReturnSuccess) \ + WIIUSE_ERROR("Unable to close " #channel " channel [id %i].", (wm)->unid); \ + [channel release]; \ + (wm)->channel##Channel = NULL; \ + } + +#define WIIUSE_MAC_CLOSE_DEVICE_CONNECTION(wm) \ + { \ + IOBluetoothDevice* device = WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice((wm)->device); \ + if([device closeConnection] != kIOReturnSuccess) \ + WIIUSE_ERROR("Unable to close the device connection [id %i].", (wm)->unid); \ + [device release]; \ + (wm)->device = NULL; \ + } + +#define WIIUSE_MAC_DISCONNECT(wm) \ + { \ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + WIIUSE_MAC_CLOSE_CHANNEL(wm, interrupt); \ + WIIUSE_MAC_CLOSE_CHANNEL(wm, control); \ + WIIUSE_MAC_CLOSE_DEVICE_CONNECTION(wm); \ + [pool drain]; \ + } + +void wiiuse_os_disconnect(struct wiimote_t* wm) { + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + return; + + // disconnect + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + { \ + IOBluetoothL2CAPChannel* channel = WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel((wm)->interruptChannel); \ + if([channel closeChannel] != kIOReturnSuccess) \ + WIIUSE_ERROR("Unable to close " "interrupt" " channel [id %i].", (wm)->unid); \ + [channel release]; \ + (wm)->interruptChannel = NULL; \ + } + WIIUSE_MAC_CLOSE_CHANNEL(wm, control); + WIIUSE_MAC_CLOSE_DEVICE_CONNECTION(wm); + [pool drain]; + + // clean up C struct + wm->event = WIIUSE_NONE; + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); } #pragma mark - @@ -151,6 +199,7 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { return 0; } +#pragma mark - #pragma mark platform fields void wiiuse_init_platform_fields(struct wiimote_t* wm) { @@ -161,9 +210,17 @@ void wiiuse_init_platform_fields(struct wiimote_t* wm) { } void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { - [WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(wm->device) release]; - wm->device = NULL; + // disconnect & release device and channels + // Note: this should already have happened, because this function is called + // once the device is disconnected. This is just paranoia. + WIIUSE_MAC_DISCONNECT(wm); + // this is also done on disconnect, so it's even more paranoia. + wm->device = NULL; + wm->controlChannel = NULL; + wm->interruptChannel = NULL; + + // release WiiuseWiimote object [((WiiuseWiimote*) wm->objc_wm) release]; wm->objc_wm = NULL; } @@ -229,6 +286,13 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { return kIOReturnSuccess; } +#pragma mark IOBluetoothL2CAPChannel delegates + +- (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device { + + wiiuse_disconnected(wm); +} + @end #endif // __APPLE__ From a39cfd43748a0bc7b35fb8c07766b2a303df0915 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 20:57:20 +0100 Subject: [PATCH 15/55] move most of the wiiuse mac implementation into WiiuseWiimote* object --- src/os_mac.m | 117 +++++++++++++++------------------------ src/os_mac/os_mac.h | 46 +++------------ src/os_mac/os_mac_find.m | 2 +- src/wiiuse.h | 3 - 4 files changed, 56 insertions(+), 112 deletions(-) diff --git a/src/os_mac.m b/src/os_mac.m index 620c77c..2459d3f 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -47,7 +47,7 @@ #pragma mark - -#pragma mark connect +#pragma mark connect, disconnect /** * @brief Connect to a wiimote with a known address. @@ -64,7 +64,7 @@ static short wiiuse_os_connect_single(struct wiimote_t* wm) { if(!wm) { WIIUSE_ERROR("No Wiimote given."); return 0; - } else if(wm && (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_DEV_FOUND) || wm->device == NULL)) { + } else if(wm && (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_DEV_FOUND) || wm->objc_wm == NULL)) { WIIUSE_ERROR("Tried to connect Wiimote without an address."); return 0; } else if(WIIMOTE_IS_CONNECTED(wm)) { @@ -78,7 +78,7 @@ static short wiiuse_os_connect_single(struct wiimote_t* wm) { short result = 0; // connect - WiiuseWiimote* objc_wm = [[WiiuseWiimote alloc] initWithPtr: wm]; + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; if([objc_wm connect] == kIOReturnSuccess) { WIIUSE_INFO("Connected to Wiimote [id %i].", wm->unid); @@ -93,8 +93,6 @@ static short wiiuse_os_connect_single(struct wiimote_t* wm) { wiiuse_set_report_type(wm); result = 1; - } else { - [objc_wm release]; } [pool drain]; @@ -111,8 +109,8 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { break; } - if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND) || !wm[i]->device) { - // If the device is not set, skip it + if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND) || !wm[i]->objc_wm) { + // If the device is not found, skip it continue; } @@ -123,56 +121,13 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { return connected; } -#pragma mark disconnect - -#define WIIUSE_MAC_CLOSE_CHANNEL(wm, channel) \ - { \ - IOBluetoothL2CAPChannel* channel = WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel((wm)->channel##Channel); \ - if([channel closeChannel] != kIOReturnSuccess) \ - WIIUSE_ERROR("Unable to close " #channel " channel [id %i].", (wm)->unid); \ - [channel release]; \ - (wm)->channel##Channel = NULL; \ - } - -#define WIIUSE_MAC_CLOSE_DEVICE_CONNECTION(wm) \ - { \ - IOBluetoothDevice* device = WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice((wm)->device); \ - if([device closeConnection] != kIOReturnSuccess) \ - WIIUSE_ERROR("Unable to close the device connection [id %i].", (wm)->unid); \ - [device release]; \ - (wm)->device = NULL; \ - } - -#define WIIUSE_MAC_DISCONNECT(wm) \ - { \ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ - WIIUSE_MAC_CLOSE_CHANNEL(wm, interrupt); \ - WIIUSE_MAC_CLOSE_CHANNEL(wm, control); \ - WIIUSE_MAC_CLOSE_DEVICE_CONNECTION(wm); \ - [pool drain]; \ - } - void wiiuse_os_disconnect(struct wiimote_t* wm) { - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !wm->objc_wm) return; - // disconnect NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - { \ - IOBluetoothL2CAPChannel* channel = WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel((wm)->interruptChannel); \ - if([channel closeChannel] != kIOReturnSuccess) \ - WIIUSE_ERROR("Unable to close " "interrupt" " channel [id %i].", (wm)->unid); \ - [channel release]; \ - (wm)->interruptChannel = NULL; \ - } - WIIUSE_MAC_CLOSE_CHANNEL(wm, control); - WIIUSE_MAC_CLOSE_DEVICE_CONNECTION(wm); + [((WiiuseWiimote*)wm->objc_wm) disconnect]; [pool drain]; - - // clean up C struct - wm->event = WIIUSE_NONE; - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); } #pragma mark - @@ -203,25 +158,20 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { #pragma mark platform fields void wiiuse_init_platform_fields(struct wiimote_t* wm) { - wm->device = NULL; wm->objc_wm = NULL; - wm->controlChannel = NULL; - wm->interruptChannel = NULL; } void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { - // disconnect & release device and channels - // Note: this should already have happened, because this function is called - // once the device is disconnected. This is just paranoia. - WIIUSE_MAC_DISCONNECT(wm); + if(!wm) return; + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; - // this is also done on disconnect, so it's even more paranoia. - wm->device = NULL; - wm->controlChannel = NULL; - wm->interruptChannel = NULL; + // disconnect + // Note: this should already have happened, because this function + // is called once the device is disconnected. This is just paranoia. + [objc_wm disconnect]; // release WiiuseWiimote object - [((WiiuseWiimote*) wm->objc_wm) release]; + [objc_wm release]; wm->objc_wm = NULL; } @@ -230,10 +180,13 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { @implementation WiiuseWiimote -- (id) initWithPtr: (wiimote*) wm_ { +- (id) initWithPtr: (wiimote*) wm_ device:(IOBluetoothDevice *)device_ { self = [super init]; if(self) { wm = wm_; + device = device_; + controlChannel = nil; + interruptChannel = nil; disconnectNotification = nil; } return self; @@ -242,6 +195,11 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { - (void) dealloc { wm = NULL; + [interruptChannel release]; + [controlChannel release]; + [device release]; + + [disconnectNotification unregister]; [disconnectNotification release]; disconnectNotification = nil; @@ -249,14 +207,12 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { } - (IOReturn) connect { - IOBluetoothDevice* device = WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(wm->device); if(!device) { WIIUSE_ERROR("Missing device."); return kIOReturnBadArgument; } // open channels - IOBluetoothL2CAPChannel* controlChannel = nil, *interruptChannel = nil; if ([device openL2CAPChannelSync:&controlChannel withPSM:WM_OUTPUT_CHANNEL delegate:self] != kIOReturnSuccess) { WIIUSE_ERROR("Unable to open L2CAP control channel [id %i].", wm->unid); [device closeConnection]; @@ -278,14 +234,33 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { return kIOReturnNotOpen; } - // retain channels, and save them to the C struct - [controlChannel retain]; [interruptChannel retain]; - wm->controlChannel = WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(controlChannel); - wm->interruptChannel = WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(interruptChannel); + // retain channels + [controlChannel retain]; + [interruptChannel retain]; return kIOReturnSuccess; } +- (void) disconnect { + // interrupt channel + if([interruptChannel closeChannel] != kIOReturnSuccess) + WIIUSE_ERROR("Unable to close interrupt channel [id %i].", wm ? wm->unid : -1); + [interruptChannel release]; + interruptChannel = nil; + + // control channel + if([controlChannel closeChannel] != kIOReturnSuccess) + WIIUSE_ERROR("Unable to close control channel [id %i].", wm ? wm->unid : -1); + [controlChannel release]; + controlChannel = nil; + + // device + if([device closeConnection] != kIOReturnSuccess) + WIIUSE_ERROR("Unable to close the device connection [id %i].", wm ? wm->unid : -1); + [device release]; + device = nil; +} + #pragma mark IOBluetoothL2CAPChannel delegates - (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device { diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 667f4ce..41d0c63 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -42,57 +42,29 @@ #import "../wiiuse_internal.h" +#if 0 #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 #define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 #else #define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 #endif - - -// WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE -#define WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef(device) \ - ((IOBluetoothDeviceRef) (device)) -#else -#define WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef(device) \ - [(device) getDeviceRef] -#endif - -// WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE -#define WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(ref) \ - ((IOBluetoothDevice*) (ref)) -#else -#define WIIUSE_IOBluetoothDeviceRef_to_IOBluetoothDevice(ref) \ - [IOBluetoothDevice withDeviceRef: (ref)] -#endif - -// WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE -#define WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(channel) \ - ((IOBluetoothL2CAPChannelRef) (channel)) -#else -#define WIIUSE_IOBluetoothL2CAPChannel_to_IOBluetoothL2CAPChannelRef(channel) \ - [(channel) getL2CAPChannelRef] -#endif - -// WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel -#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE -#define WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel(ref) \ - ((IOBluetoothL2CAPChannel*) (ref)) -#else -#define WIIUSE_IOBluetoothL2CAPChannelRef_to_IOBluetoothL2CAPChannel(ref) \ - [IOBluetoothL2CAPChannel withChanneleRef: (ref)] #endif @interface WiiuseWiimote : NSObject { wiimote* wm; // reference to the C wiimote struct + + IOBluetoothDevice* device; + IOBluetoothL2CAPChannel* controlChannel; + IOBluetoothL2CAPChannel* interruptChannel; + IOBluetoothUserNotification* disconnectNotification; } -- (id) initWithPtr: (wiimote*) wm; +- (id) initWithPtr: (wiimote*) wm device: (IOBluetoothDevice*) device; + - (IOReturn) connect; +- (void) disconnect; @end diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index 032d262..ac51dbc 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -130,7 +130,7 @@ IOBluetoothDevice* device = [devices objectAtIndex:i]; // save the device in the wiimote structure - wiimotes[i]->device = WIIUSE_IOBluetoothDevice_to_IOBluetoothDeviceRef(device); + wiimotes[i]->objc_wm = (void*) [[WiiuseWiimote alloc] initWithPtr:wiimotes[i] device: device]; [device retain]; // must retain it for later access through its ref // mark as found diff --git a/src/wiiuse.h b/src/wiiuse.h index f88e793..4676b27 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -723,10 +723,7 @@ typedef struct wiimote_t { #ifdef WIIUSE_MAC /** @name Mac OS X-specific members */ /** @{ */ - WCONST IOBluetoothDeviceRef device; /** Device reference */ WCONST void* objc_wm; /** WiiuseWiimote* as opaque pointer */ - WCONST IOBluetoothL2CAPChannelRef controlChannel; /** control channel reference */ - WCONST IOBluetoothL2CAPChannelRef interruptChannel; /** interrupt channel reference */ /** @} */ #endif From 8c2f22089a1e1ccf7f0831f585181d415eb9ade6 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 21:26:15 +0100 Subject: [PATCH 16/55] implemented wiiuse_io_write for mac --- src/os_mac.m | 101 ++++++++++++++++++++++++++++++++------------ src/os_mac/os_mac.h | 2 + 2 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/os_mac.m b/src/os_mac.m index 2459d3f..50da0b4 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -151,7 +151,18 @@ int wiiuse_os_read(struct wiimote_t* wm) { } int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { - return 0; + if(!wm) { + WIIUSE_ERROR("Attempting to write to NULL Wiimote"); + return 0; + } + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; + int result = [objc_wm writeBuffer: buf length: (NSUInteger)len]; + + [pool drain]; + return result; } #pragma mark - @@ -180,6 +191,8 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { @implementation WiiuseWiimote +#pragma mark init, dealloc + - (id) initWithPtr: (wiimote*) wm_ device:(IOBluetoothDevice *)device_ { self = [super init]; if(self) { @@ -206,6 +219,19 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { [super dealloc]; } +#pragma mark connect, disconnect + +- (BOOL) connectChannel: (IOBluetoothL2CAPChannel**) pChannel PSM: (BluetoothL2CAPPSM) psm { + if ([device openL2CAPChannelSync:pChannel withPSM:psm delegate:self] != kIOReturnSuccess) { + WIIUSE_ERROR("Unable to open L2CAP channel [id %i].", wm->unid); + *pChannel = nil; + return NO; + } else { + [*pChannel retain]; + return YES; + } +} + - (IOReturn) connect { if(!device) { WIIUSE_ERROR("Missing device."); @@ -213,14 +239,11 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { } // open channels - if ([device openL2CAPChannelSync:&controlChannel withPSM:WM_OUTPUT_CHANNEL delegate:self] != kIOReturnSuccess) { - WIIUSE_ERROR("Unable to open L2CAP control channel [id %i].", wm->unid); - [device closeConnection]; + if(![self connectChannel:&controlChannel PSM:WM_OUTPUT_CHANNEL]) { + [self disconnect]; return kIOReturnNotOpen; - } else if([device openL2CAPChannelSync:&interruptChannel withPSM:WM_INPUT_CHANNEL delegate:self] != kIOReturnSuccess) { - WIIUSE_ERROR("Unable to open L2CAP interrupt channel [id %i].", wm->unid); - [controlChannel closeChannel]; - [device closeConnection]; + } else if(![self connectChannel:&interruptChannel PSM:WM_INPUT_CHANNEL]) { + [self disconnect]; return kIOReturnNotOpen; } @@ -228,31 +251,26 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { disconnectNotification = [device registerForDisconnectNotification:self selector:@selector(disconnected:fromDevice:)]; if(!disconnectNotification) { WIIUSE_ERROR("Unable to register disconnection handler [id %i].", wm->unid); - [interruptChannel closeChannel]; - [controlChannel closeChannel]; - [device closeConnection]; + [self disconnect]; return kIOReturnNotOpen; } - // retain channels - [controlChannel retain]; - [interruptChannel retain]; - return kIOReturnSuccess; } -- (void) disconnect { - // interrupt channel - if([interruptChannel closeChannel] != kIOReturnSuccess) - WIIUSE_ERROR("Unable to close interrupt channel [id %i].", wm ? wm->unid : -1); - [interruptChannel release]; - interruptChannel = nil; +- (void) disconnectChannel: (IOBluetoothL2CAPChannel**) pChannel { + if(!pChannel) return; - // control channel - if([controlChannel closeChannel] != kIOReturnSuccess) - WIIUSE_ERROR("Unable to close control channel [id %i].", wm ? wm->unid : -1); - [controlChannel release]; - controlChannel = nil; + if([*pChannel closeChannel] != kIOReturnSuccess) + WIIUSE_ERROR("Unable to close channel [id %i].", wm ? wm->unid : -1); + [*pChannel release]; + *pChannel = nil; +} + +- (void) disconnect { + // channels + [self disconnectChannel:&interruptChannel]; + [self disconnectChannel:&controlChannel]; // device if([device closeConnection] != kIOReturnSuccess) @@ -261,13 +279,40 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { device = nil; } -#pragma mark IOBluetoothL2CAPChannel delegates - - (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device { wiiuse_disconnected(wm); } +#pragma mark read, write + +- (int) writeBuffer: (byte*) buffer length: (NSUInteger) length { + if(controlChannel == nil) { + WIIUSE_ERROR("Attempted to write to nil control channel [id %i].", wm->unid); + return 0; + } + + IOReturn error = [controlChannel writeSync:buffer length:length]; + if (error != kIOReturnSuccess) { + WIIUSE_ERROR("Error writing to control channel [id %i].", wm->unid); + + WIIUSE_DEBUG("Attempting to reopen the control channel [id %i].", wm->unid); + [self disconnectChannel:&controlChannel]; + [self connectChannel:&controlChannel PSM:WM_OUTPUT_CHANNEL]; + if(!controlChannel) { + WIIUSE_ERROR("Error reopening the control channel [id %i].", wm->unid); + [self disconnect]; + } else { + WIIUSE_DEBUG("Attempting to write again to the control channel [id %i].", wm->unid); + error = [controlChannel writeSync:buffer length:length]; + if (error != kIOReturnSuccess) + WIIUSE_ERROR("Unable to write again to the control channel [id %i].", wm->unid); + } + } + + return (error == kIOReturnSuccess) ? length : 0; +} + @end #endif // __APPLE__ diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 41d0c63..06db9da 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -66,6 +66,8 @@ - (IOReturn) connect; - (void) disconnect; +- (int) writeBuffer: (byte*) buffer length: (NSUInteger) length; + @end From 7e502b66d648f2318ae0b4628fd0e5e02f151932 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 23:26:56 +0100 Subject: [PATCH 17/55] implemented wiiuse_os_read for mac --- src/os_mac.m | 143 +++++++++++++++++++++++++++++++++++++++++--- src/os_mac/os_mac.h | 13 ++-- 2 files changed, 140 insertions(+), 16 deletions(-) diff --git a/src/os_mac.m b/src/os_mac.m index 50da0b4..554a0b6 100644 --- a/src/os_mac.m +++ b/src/os_mac.m @@ -134,25 +134,46 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { #pragma mark poll, read, write int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { - int i; + int i, evnt = 0; if (!wm) return 0; for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - idle_cycle(wm[i]); + + if (wiiuse_os_read(wm[i])) { + /* propagate the event, messages should be read as in linux, starting from the second element */ + propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); + evnt += (wm[i]->event != WIIUSE_NONE); + + /* clear out the event buffer */ + memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + } else { + idle_cycle(wm[i]); + } } - return 0; + return evnt; } int wiiuse_os_read(struct wiimote_t* wm) { - return 0; + if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_ERROR("Attempting to read from NULL or unconnected Wiimote"); + return 0; + } + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; + int result = [objc_wm read]; + + [pool drain]; + return result; } int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { - if(!wm) { - WIIUSE_ERROR("Attempting to write to NULL Wiimote"); + if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_ERROR("Attempting to write to NULL or unconnected Wiimote"); return 0; } @@ -197,10 +218,15 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { self = [super init]; if(self) { wm = wm_; + device = device_; controlChannel = nil; interruptChannel = nil; + disconnectNotification = nil; + + receivedData = [[NSMutableArray alloc] initWithCapacity: 2]; + receivedDataLock = [[NSLock alloc] init]; } return self; } @@ -214,7 +240,8 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { [disconnectNotification unregister]; [disconnectNotification release]; - disconnectNotification = nil; + + [receivedData release]; [super dealloc]; } @@ -286,6 +313,71 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { #pragma mark read, write +- (int) checkForAvailableData { + unsigned int length = 0; + + [receivedDataLock lock]; + if([receivedData count]) { + // pop first item from queue + NSData* firstData = [receivedData objectAtIndex:0]; + [receivedData removeObjectAtIndex:0]; + + byte* data = (byte*) [firstData bytes]; + length = [firstData length]; + + // forward event data to C struct + memcpy(wm->event_buf, data, sizeof(wm->event_buf)); + + // clear local buffer + [firstData release]; + } + [receivedDataLock unlock]; + + return length; +} + +- (void) waitForInclomingData: (NSTimeInterval) duration { + NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow: duration]; + NSRunLoop *theRL = [NSRunLoop currentRunLoop]; + while (true) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // This is used for fast release of NSDate, otherwise it leaks + + if(![theRL runMode:NSDefaultRunLoopMode beforeDate:timeoutDate]) { + WIIUSE_ERROR("Could not start run loop while waiting for read [id %i].", wm->unid); + break; + } + + [receivedDataLock lock]; + NSUInteger count = [receivedData count]; + [receivedDataLock unlock]; + if(count) { + // received some data, stop waiting + break; + } + + if([timeoutDate isLessThanOrEqualTo:[NSDate date]]) { + // timeout + break; + } + + [pool drain]; + } +} + +- (int) read { + // is there already some data to read? + int result = [self checkForAvailableData]; + if(!result) { + // wait a short amount of time, until data becomes available + [self waitForInclomingData:1]; + + // check again + result = [self checkForAvailableData]; + } + + return result; +} + - (int) writeBuffer: (byte*) buffer length: (NSUInteger) length { if(controlChannel == nil) { WIIUSE_ERROR("Attempted to write to nil control channel [id %i].", wm->unid); @@ -313,6 +405,43 @@ void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { return (error == kIOReturnSuccess) ? length : 0; } +#pragma mark IOBluetoothL2CAPChannelDelegate + +- (void) l2capChannelData:(IOBluetoothL2CAPChannel*)channel data:(void*)data_ length:(NSUInteger)length { + + byte* data = (byte*) data_; + + // This is done in case the output channel woke up this handler + if(!data || ([channel PSM] == WM_OUTPUT_CHANNEL)) { + return; + } + + // log the received data +#ifdef WITH_WIIUSE_DEBUG + { + printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, data[0]); + int x; + for (x = 1; x < length; ++x) + printf("%.2x ", data[x]); + printf("\n"); + } +#endif + + /* + * This is called if we are receiving data before completing + * the handshaking, hence before calling wiiuse_poll + */ + if(WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE)) { + propagate_event(wm, data[1], data+2); + return; + } + + // copy the data into the buffer + [receivedDataLock lock]; + [receivedData addObject: [[NSData alloc] initWithBytes:data length:length]]; + [receivedDataLock unlock]; +} + @end #endif // __APPLE__ diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 06db9da..15ceef1 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -42,15 +42,6 @@ #import "../wiiuse_internal.h" -#if 0 -#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 -#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 -#else -#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 -#endif -#endif - - @interface WiiuseWiimote : NSObject { wiimote* wm; // reference to the C wiimote struct @@ -59,6 +50,9 @@ IOBluetoothL2CAPChannel* interruptChannel; IOBluetoothUserNotification* disconnectNotification; + + NSMutableArray* receivedData; // a queue os NSData* + NSLock* receivedDataLock; } - (id) initWithPtr: (wiimote*) wm device: (IOBluetoothDevice*) device; @@ -66,6 +60,7 @@ - (IOReturn) connect; - (void) disconnect; +- (int) read; - (int) writeBuffer: (byte*) buffer length: (NSUInteger) length; @end From f0642ed028dbb26d65bed6b6143538339a23c29a Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 10 Nov 2012 23:52:28 +0100 Subject: [PATCH 18/55] fix os_nix.c stuff that broke during refactorings --- src/os_nix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/os_nix.c b/src/os_nix.c index 838c84b..2c4013b 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -131,7 +131,7 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { /* if the device address is not set, skip it */ continue; - if (wiiuse_connect_single(wm[i], NULL)) + if (wiiuse_os_connect_single(wm[i], NULL)) ++connected; } @@ -144,7 +144,7 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { * * @param wm Pointer to a wiimote_t structure. * @param address The address of the device to connect to. - * If NULL, use the address in the struct set by wiiuse_find(). + * If NULL, use the address in the struct set by wiiuse_os_find(). * * @return 1 on success, 0 on failure */ @@ -294,7 +294,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { if (errno == ENOTCONN) { /* this can happen if the bluetooth dongle is disconnected */ WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid); - wiiuse_disconnect(wm[i]); + wiiuse_os_disconnect(wm[i]); wiiuse_disconnected(wm[i]); wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT; } From 233c496fa0f90492c0f33a46f68495c50c9a295e Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 11 Nov 2012 00:05:04 +0100 Subject: [PATCH 19/55] separate os.h interface from implementation (mac) --- src/CMakeLists.txt | 3 +- src/{ => os_mac}/os_mac.m | 170 +-------------------------- src/os_mac/os_mac_interface.m | 215 ++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 169 deletions(-) rename src/{ => os_mac}/os_mac.m (63%) create mode 100644 src/os_mac/os_mac_interface.m diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7906b76..f428ec3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,8 +31,9 @@ if(WIN32) set(CMAKE_DEBUG_POSTFIX _debug) elseif(APPLE) set(MAC_SOURCES - os_mac.m os_mac/os_mac.h + os_mac/os_mac.m + os_mac/os_mac_interface.m os_mac/os_mac_find.m) list(APPEND SOURCES ${MAC_SOURCES}) # make sure we use the gcc for Objective-C files as well so that the diff --git a/src/os_mac.m b/src/os_mac/os_mac.m similarity index 63% rename from src/os_mac.m rename to src/os_mac/os_mac.m index 554a0b6..6cfb47a 100644 --- a/src/os_mac.m +++ b/src/os_mac/os_mac.m @@ -33,11 +33,9 @@ #ifdef __APPLE__ -#import "os_mac/os_mac.h" +#import "os_mac.h" -#import "io.h" -#import "events.h" -#import "os.h" +#import "../events.h" #import #import @@ -46,170 +44,6 @@ #import -#pragma mark - -#pragma mark connect, disconnect - -/** - * @brief Connect to a wiimote with a known address. - * - * @param wm Pointer to a wiimote_t structure. - * - * @see wiimote_os_connect() - * @see wiimote_os_find() - * - * @return 1 on success, 0 on failure - */ -static short wiiuse_os_connect_single(struct wiimote_t* wm) { - // Skip if already connected or device not found - if(!wm) { - WIIUSE_ERROR("No Wiimote given."); - return 0; - } else if(wm && (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_DEV_FOUND) || wm->objc_wm == NULL)) { - WIIUSE_ERROR("Tried to connect Wiimote without an address."); - return 0; - } else if(WIIMOTE_IS_CONNECTED(wm)) { - WIIUSE_WARNING("Wiimote [id %i] is already connected.", wm->unid); - return 1; - } - - WIIUSE_DEBUG("Connecting to Wiimote [id %i].", wm->unid); - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - short result = 0; - - // connect - WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; - if([objc_wm connect] == kIOReturnSuccess) { - WIIUSE_INFO("Connected to Wiimote [id %i].", wm->unid); - - // save the connect structure to retrieve data later on - wm->objc_wm = (void*)objc_wm; - - // save the connection status - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); - - // Do the handshake - wiiuse_handshake(wm, NULL, 0); - wiiuse_set_report_type(wm); - - result = 1; - } - - [pool drain]; - return result; -} - -int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { - int connected = 0; - - int i; - for (i = 0; i < wiimotes; ++i) { - if(wm[i] == NULL) { - WIIUSE_ERROR("Trying to connect to non-initialized Wiimote."); - break; - } - - if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND) || !wm[i]->objc_wm) { - // If the device is not found, skip it - continue; - } - - if (wiiuse_os_connect_single(wm[i])) - ++connected; - } - - return connected; -} - -void wiiuse_os_disconnect(struct wiimote_t* wm) { - if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !wm->objc_wm) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [((WiiuseWiimote*)wm->objc_wm) disconnect]; - [pool drain]; -} - -#pragma mark - -#pragma mark poll, read, write - -int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { - int i, evnt = 0; - - if (!wm) return 0; - - for (i = 0; i < wiimotes; ++i) { - wm[i]->event = WIIUSE_NONE; - - if (wiiuse_os_read(wm[i])) { - /* propagate the event, messages should be read as in linux, starting from the second element */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - evnt += (wm[i]->event != WIIUSE_NONE); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); - } else { - idle_cycle(wm[i]); - } - } - - return evnt; -} - -int wiiuse_os_read(struct wiimote_t* wm) { - if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { - WIIUSE_ERROR("Attempting to read from NULL or unconnected Wiimote"); - return 0; - } - - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; - int result = [objc_wm read]; - - [pool drain]; - return result; -} - -int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { - if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { - WIIUSE_ERROR("Attempting to write to NULL or unconnected Wiimote"); - return 0; - } - - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; - int result = [objc_wm writeBuffer: buf length: (NSUInteger)len]; - - [pool drain]; - return result; -} - -#pragma mark - -#pragma mark platform fields - -void wiiuse_init_platform_fields(struct wiimote_t* wm) { - wm->objc_wm = NULL; -} - -void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { - if(!wm) return; - WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; - - // disconnect - // Note: this should already have happened, because this function - // is called once the device is disconnected. This is just paranoia. - [objc_wm disconnect]; - - // release WiiuseWiimote object - [objc_wm release]; - wm->objc_wm = NULL; -} - -#pragma mark - -#pragma mark WiiuseWiimote - @implementation WiiuseWiimote #pragma mark init, dealloc diff --git a/src/os_mac/os_mac_interface.m b/src/os_mac/os_mac_interface.m new file mode 100644 index 0000000..c32568d --- /dev/null +++ b/src/os_mac/os_mac_interface.m @@ -0,0 +1,215 @@ +/* + * 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 . + * + * $Header$ + * + */ + +/** + * @file + * @brief C function interface to os_mac. + */ + +#ifdef __APPLE__ + +#import "os_mac.h" + +#import "../io.h" +#import "../events.h" +#import "../os.h" + +#import +#import +#import +#import +#import + + +#pragma mark - +#pragma mark find + +// See os_mac_find.m + +#pragma mark - +#pragma mark connect, disconnect + +/** + * @brief Connect to a wiimote with a known address. + * + * @param wm Pointer to a wiimote_t structure. + * + * @see wiimote_os_connect() + * @see wiimote_os_find() + * + * @return 1 on success, 0 on failure + */ +static short wiiuse_os_connect_single(struct wiimote_t* wm) { + // Skip if already connected or device not found + if(!wm) { + WIIUSE_ERROR("No Wiimote given."); + return 0; + } else if(wm && (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_DEV_FOUND) || wm->objc_wm == NULL)) { + WIIUSE_ERROR("Tried to connect Wiimote without an address."); + return 0; + } else if(WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_WARNING("Wiimote [id %i] is already connected.", wm->unid); + return 1; + } + + WIIUSE_DEBUG("Connecting to Wiimote [id %i].", wm->unid); + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + short result = 0; + + // connect + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; + if([objc_wm connect] == kIOReturnSuccess) { + WIIUSE_INFO("Connected to Wiimote [id %i].", wm->unid); + + // save the connect structure to retrieve data later on + wm->objc_wm = (void*)objc_wm; + + // save the connection status + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); + + // Do the handshake + wiiuse_handshake(wm, NULL, 0); + wiiuse_set_report_type(wm); + + result = 1; + } + + [pool drain]; + return result; +} + +int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { + int connected = 0; + + int i; + for (i = 0; i < wiimotes; ++i) { + if(wm[i] == NULL) { + WIIUSE_ERROR("Trying to connect to non-initialized Wiimote."); + break; + } + + if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND) || !wm[i]->objc_wm) { + // If the device is not found, skip it + continue; + } + + if (wiiuse_os_connect_single(wm[i])) + ++connected; + } + + return connected; +} + +void wiiuse_os_disconnect(struct wiimote_t* wm) { + if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !wm->objc_wm) + return; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [((WiiuseWiimote*)wm->objc_wm) disconnect]; + [pool drain]; +} + +#pragma mark - +#pragma mark poll, read, write + +int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { + int i, evnt = 0; + + if (!wm) return 0; + + for (i = 0; i < wiimotes; ++i) { + wm[i]->event = WIIUSE_NONE; + + if (wiiuse_os_read(wm[i])) { + /* propagate the event, messages should be read as in linux, starting from the second element */ + propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); + evnt += (wm[i]->event != WIIUSE_NONE); + + /* clear out the event buffer */ + memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + } else { + idle_cycle(wm[i]); + } + } + + return evnt; +} + +int wiiuse_os_read(struct wiimote_t* wm) { + if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_ERROR("Attempting to read from NULL or unconnected Wiimote"); + return 0; + } + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; + int result = [objc_wm read]; + + [pool drain]; + return result; +} + +int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { + if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_ERROR("Attempting to write to NULL or unconnected Wiimote"); + return 0; + } + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; + int result = [objc_wm writeBuffer: buf length: (NSUInteger)len]; + + [pool drain]; + return result; +} + +#pragma mark - +#pragma mark platform fields + +void wiiuse_init_platform_fields(struct wiimote_t* wm) { + wm->objc_wm = NULL; +} + +void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) { + if(!wm) return; + WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; + + // disconnect + // Note: this should already have happened, because this function + // is called once the device is disconnected. This is just paranoia. + [objc_wm disconnect]; + + // release WiiuseWiimote object + [objc_wm release]; + wm->objc_wm = NULL; +} + +#endif // __APPLE__ From 9892efab937f7d17e57fd41d5235a832f56c1aa2 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 11 Nov 2012 00:25:47 +0100 Subject: [PATCH 20/55] getting rid of several potential memory leaks and incorrect releases --- src/os_mac/os_mac.m | 13 +++++-------- src/os_mac/os_mac_find.m | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 6cfb47a..337d4c0 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -53,7 +53,7 @@ if(self) { wm = wm_; - device = device_; + device = [device_ retain]; controlChannel = nil; interruptChannel = nil; @@ -161,9 +161,6 @@ // forward event data to C struct memcpy(wm->event_buf, data, sizeof(wm->event_buf)); - - // clear local buffer - [firstData release]; } [receivedDataLock unlock]; @@ -175,11 +172,11 @@ NSRunLoop *theRL = [NSRunLoop currentRunLoop]; while (true) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // This is used for fast release of NSDate, otherwise it leaks - if(![theRL runMode:NSDefaultRunLoopMode beforeDate:timeoutDate]) { WIIUSE_ERROR("Could not start run loop while waiting for read [id %i].", wm->unid); break; } + [pool drain]; [receivedDataLock lock]; NSUInteger count = [receivedData count]; @@ -193,8 +190,6 @@ // timeout break; } - - [pool drain]; } } @@ -271,9 +266,11 @@ } // copy the data into the buffer + NSData* newData = [[NSData alloc] initWithBytes:data length:length]; [receivedDataLock lock]; - [receivedData addObject: [[NSData alloc] initWithBytes:data length:length]]; + [receivedData addObject: newData]; [receivedDataLock unlock]; + [newData release]; } @end diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index ac51dbc..0c686c3 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -131,7 +131,6 @@ // save the device in the wiimote structure wiimotes[i]->objc_wm = (void*) [[WiiuseWiimote alloc] initWithPtr:wiimotes[i] device: device]; - [device retain]; // must retain it for later access through its ref // mark as found WIIMOTE_ENABLE_STATE(wiimotes[i], WIIMOTE_STATE_DEV_FOUND); From 3b1d440f03ef1cced32a98d2d4896394dba3e381 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 11 Nov 2012 18:44:31 +0100 Subject: [PATCH 21/55] fix mac disconnection crash due to asynchronous operations --- src/os_mac/os_mac.h | 18 +++++++- src/os_mac/os_mac.m | 86 +++++++++++++++++++++++++++-------- src/os_mac/os_mac_interface.m | 3 +- src/wiiuse.c | 3 +- 4 files changed, 88 insertions(+), 22 deletions(-) diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 15ceef1..7537f7b 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -51,7 +51,7 @@ IOBluetoothUserNotification* disconnectNotification; - NSMutableArray* receivedData; // a queue os NSData* + NSMutableArray* receivedData; // a queue of NSObject* NSLock* receivedDataLock; } @@ -66,4 +66,20 @@ @end +@protocol WiiuseReceivedMessage +- (int) applyToStruct: (wiimote*) wm; // <0: not copied, 0: copied empty, >0: copied +@end + +@interface WiiuseReceivedData : NSObject { + NSData* data; +} +- (id) initWithBytes: (void*) bytes length: (NSUInteger) length; +- (id) initWithData: (NSData*) data; +@end + +@interface WiiuseDisconnectionMessage : NSObject { +} +@end + + #endif // __APPLE__ diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 337d4c0..c1d235a 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -142,32 +142,33 @@ - (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device { - wiiuse_disconnected(wm); + WiiuseDisconnectionMessage* message = [[WiiuseDisconnectionMessage alloc] init]; + [receivedDataLock lock]; + [receivedData addObject:message]; + [receivedDataLock unlock]; + [message release]; } #pragma mark read, write +// <0: nothing received, else: length of data received (can be 0 in case of disconnection message) - (int) checkForAvailableData { - unsigned int length = 0; + int result = -1; [receivedDataLock lock]; if([receivedData count]) { - // pop first item from queue - NSData* firstData = [receivedData objectAtIndex:0]; - [receivedData removeObjectAtIndex:0]; - - byte* data = (byte*) [firstData bytes]; - length = [firstData length]; - - // forward event data to C struct - memcpy(wm->event_buf, data, sizeof(wm->event_buf)); + // look at first item in queue + NSObject* firstMessage = [receivedData objectAtIndex:0]; + result = [firstMessage applyToStruct:wm]; + if(result >= 0) + [receivedData removeObjectAtIndex:0]; } [receivedDataLock unlock]; - return length; + return result; } -- (void) waitForInclomingData: (NSTimeInterval) duration { +- (void) waitForIncomingData: (NSTimeInterval) duration { NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow: duration]; NSRunLoop *theRL = [NSRunLoop currentRunLoop]; while (true) { @@ -193,18 +194,19 @@ } } +// result = length of data copied to event buffer - (int) read { // is there already some data to read? int result = [self checkForAvailableData]; - if(!result) { - // wait a short amount of time, until data becomes available - [self waitForInclomingData:1]; + if(result < 0) { + // wait a short amount of time, until data becomes available or a timeoutis reached + [self waitForIncomingData:1]; // check again result = [self checkForAvailableData]; } - return result; + return result >= 0 ? result : 0; } - (int) writeBuffer: (byte*) buffer length: (NSUInteger) length { @@ -266,7 +268,7 @@ } // copy the data into the buffer - NSData* newData = [[NSData alloc] initWithBytes:data length:length]; + WiiuseReceivedData* newData = [[WiiuseReceivedData alloc] initWithBytes: data length: length]; [receivedDataLock lock]; [receivedData addObject: newData]; [receivedDataLock unlock]; @@ -275,4 +277,52 @@ @end +#pragma mark - +#pragma mark WiiuseReceivedMessage + +@implementation WiiuseReceivedData + +- (id) initWithData:(NSData *)data_ { + self = [super init]; + if (self) { + data = [data_ retain]; + } + return self; +} +- (id) initWithBytes: (void*) bytes length: (NSUInteger) length { + NSData* data_ = [[NSData alloc] initWithBytes:bytes length:length]; + id result = [self initWithData: data_]; + [data_ release]; + return result; +} + +- (void) dealloc { + [data release]; + [super dealloc]; +} + +- (int) applyToStruct:(wiimote *)wm { + byte* bytes = (byte*) [data bytes]; + NSUInteger length = [data length]; + if(length > sizeof(wm->event_buf)) { + WIIUSE_WARNING("Received data was longer than event buffer. Dropping excess bytes."); + length = sizeof(wm->event_buf); + } + memcpy(wm->event_buf, bytes, length); + + return length; +} + +@end + +@implementation WiiuseDisconnectionMessage + +- (int) applyToStruct:(wiimote *)wm { + wiiuse_disconnected(wm); + return 0; +} + +@end + + #endif // __APPLE__ diff --git a/src/os_mac/os_mac_interface.m b/src/os_mac/os_mac_interface.m index c32568d..c6ce72f 100644 --- a/src/os_mac/os_mac_interface.m +++ b/src/os_mac/os_mac_interface.m @@ -149,13 +149,14 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { if (wiiuse_os_read(wm[i])) { /* propagate the event, messages should be read as in linux, starting from the second element */ propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - evnt += (wm[i]->event != WIIUSE_NONE); /* clear out the event buffer */ memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); } else { idle_cycle(wm[i]); } + + evnt += (wm[i]->event != WIIUSE_NONE); } return evnt; diff --git a/src/wiiuse.c b/src/wiiuse.c index 80dbf10..f947a59 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -85,6 +85,7 @@ void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) { for (; i < wiimotes; ++i) { wiiuse_disconnect(wm[i]); + wiiuse_cleanup_platform_fields(wm[i]); free(wm[i]); } @@ -177,8 +178,6 @@ void wiiuse_disconnected(struct wiimote_t* wm) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); /* reset a bunch of stuff */ - wiiuse_cleanup_platform_fields(wm); - wm->leds = 0; wm->state = WIIMOTE_INIT_STATES; wm->read_req = NULL; From 61d26d509c5d2722d78a06c6b142538322ab8946 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 11 Nov 2012 18:53:37 +0100 Subject: [PATCH 22/55] stop wiiuseexample when all wiimotes are disconnected --- example/example.c | 12 +++++++++++- src/wiiuse.h | 26 ++++++++++++++++++++++++++ src/wiiuse_internal.h | 26 -------------------------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/example/example.c b/example/example.c index 4eaeed6..1db8bc5 100644 --- a/example/example.c +++ b/example/example.c @@ -294,6 +294,16 @@ 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]); } +short any_wiimote_connected(wiimote** wm, int wiimotes) { + if(!wm) return 0; + + for(int i = 0; i < wiimotes; i++) { + if(wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) + return 1; + } + + return 0; +} /** @@ -390,7 +400,7 @@ int main(int argc, char** argv) { * This function will set the event flag for each wiimote * when the wiimote has things to report. */ - while (1) { + while (any_wiimote_connected(wiimotes, MAX_WIIMOTES)) { if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) { /* * This happens if something happened on any wiimote. diff --git a/src/wiiuse.h b/src/wiiuse.h index 4676b27..ec22a24 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -123,6 +123,32 @@ /** @defgroup publicapi External API */ /** @{ */ +/** @name Wiimote state flags and macros */ +/** @{ */ +#define WIIMOTE_STATE_DEV_FOUND 0x0001 +#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */ +#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */ +#define WIIMOTE_STATE_CONNECTED 0x0008 +#define WIIMOTE_STATE_RUMBLE 0x0010 +#define WIIMOTE_STATE_ACC 0x0020 +#define WIIMOTE_STATE_EXP 0x0040 +#define WIIMOTE_STATE_IR 0x0080 +#define WIIMOTE_STATE_SPEAKER 0x0100 +#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200 +#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400 +#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800 +#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000 +#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000 +#define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */ +#define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */ +#define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */ + +#define WIIMOTE_ID(wm) (wm->unid) + +#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) +#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) +/** @} */ + /** @name LED bit masks */ /** @{ */ #define WIIMOTE_LED_NONE 0x00 diff --git a/src/wiiuse_internal.h b/src/wiiuse_internal.h index 6aed90c..7c02113 100644 --- a/src/wiiuse_internal.h +++ b/src/wiiuse_internal.h @@ -221,31 +221,9 @@ * ********************/ -/* wiimote state flags - (some duplicated in wiiuse.h)*/ -#define WIIMOTE_STATE_DEV_FOUND 0x0001 -#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */ -#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */ -#define WIIMOTE_STATE_CONNECTED 0x0008 -#define WIIMOTE_STATE_RUMBLE 0x0010 -#define WIIMOTE_STATE_ACC 0x0020 -#define WIIMOTE_STATE_EXP 0x0040 -#define WIIMOTE_STATE_IR 0x0080 -#define WIIMOTE_STATE_SPEAKER 0x0100 -#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200 -#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400 -#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800 -#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000 -#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000 -#define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */ -#define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */ -#define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */ - - - #define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3) /* macro to manage states */ -#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s)) #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s)) #define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) @@ -257,10 +235,6 @@ #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s)) -/* misc macros */ -#define WIIMOTE_ID(wm) (wm->unid) -#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) - /* * Smooth tilt calculations are computed with the * exponential moving average formula: From 83fc61d7b125875b48674da7c9217f0f4154f365 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 11 Nov 2012 20:27:29 +0100 Subject: [PATCH 23/55] remove debug print when trying to read/write unconnected devices --- src/os_mac/os_mac_interface.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/os_mac/os_mac_interface.m b/src/os_mac/os_mac_interface.m index c6ce72f..b8683d7 100644 --- a/src/os_mac/os_mac_interface.m +++ b/src/os_mac/os_mac_interface.m @@ -163,8 +163,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { } int wiiuse_os_read(struct wiimote_t* wm) { - if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { - WIIUSE_ERROR("Attempting to read from NULL or unconnected Wiimote"); + if(!wm || !wm->objc_wm) return 0; + if(!WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_ERROR("Attempting to read from unconnected Wiimote"); return 0; } @@ -178,8 +179,9 @@ int wiiuse_os_read(struct wiimote_t* wm) { } int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { - if(!wm || !wm->objc_wm || !WIIMOTE_IS_CONNECTED(wm)) { - WIIUSE_ERROR("Attempting to write to NULL or unconnected Wiimote"); + if(!wm || !wm->objc_wm) return 0; + if(!WIIMOTE_IS_CONNECTED(wm)) { + WIIUSE_ERROR("Attempting to write to unconnected Wiimote"); return 0; } From 6aef04f375e029d382d48129f6e8a5ece6c172b6 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 11 Nov 2012 23:12:44 +0100 Subject: [PATCH 24/55] fix mac send/receive debug output --- src/os_mac/os_mac.m | 24 +++++++++++++----------- src/wiiuse.c | 9 +++++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index c1d235a..8a91829 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -247,17 +247,6 @@ return; } - // log the received data -#ifdef WITH_WIIUSE_DEBUG - { - printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, data[0]); - int x; - for (x = 1; x < length; ++x) - printf("%.2x ", data[x]); - printf("\n"); - } -#endif - /* * This is called if we are receiving data before completing * the handshaking, hence before calling wiiuse_poll @@ -308,6 +297,19 @@ WIIUSE_WARNING("Received data was longer than event buffer. Dropping excess bytes."); length = sizeof(wm->event_buf); } + + // log the received data +#ifdef WITH_WIIUSE_DEBUG + { + printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, bytes[1]); + int x; + for (x = 2; x < length; ++x) + printf("%.2x ", bytes[x]); + printf("\n"); + } +#endif + + // copy to struct memcpy(wm->event_buf, bytes, length); return length; diff --git a/src/wiiuse.c b/src/wiiuse.c index f947a59..6d1ff5e 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -693,12 +693,13 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { #ifdef WITH_WIIUSE_DEBUG { - int x = 2; - printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]); + int x; #ifndef WIIUSE_WIN32 - for (; x < len+2; ++x) + printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[1], buf[2]); + for (x = 3; x < len+2; ++x) #else - for (; x < len+1; ++x) + printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]); + for (x = 2; x < len+1; ++x) #endif printf("%.2x ", buf[x]); printf("\n"); From 4bf58ca73a0bb9e43d812e0f4c97613d74aad515 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Mon, 12 Nov 2012 00:37:27 +0100 Subject: [PATCH 25/55] remove obsolete pre-handshake propagate_event on mac --- src/os_mac/os_mac.m | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 8a91829..15c9e3b 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -247,15 +247,6 @@ return; } - /* - * This is called if we are receiving data before completing - * the handshaking, hence before calling wiiuse_poll - */ - if(WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE)) { - propagate_event(wm, data[1], data+2); - return; - } - // copy the data into the buffer WiiuseReceivedData* newData = [[WiiuseReceivedData alloc] initWithBytes: data length: length]; [receivedDataLock lock]; From 7b13623d1295ab2217ce5bd5561bee07dafb9e0a Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Mon, 12 Nov 2012 01:45:32 +0100 Subject: [PATCH 26/55] use the interrupt (data) channel as output channel on mac --- src/os_mac/os_mac.m | 32 ++++++++++++++++---------------- src/wiiuse.c | 6 +++++- src/wiiuse_internal.h | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 15c9e3b..517441a 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -100,10 +100,10 @@ } // open channels - if(![self connectChannel:&controlChannel PSM:WM_OUTPUT_CHANNEL]) { + if(![self connectChannel:&controlChannel PSM:kBluetoothL2CAPPSMHIDControl]) { [self disconnect]; return kIOReturnNotOpen; - } else if(![self connectChannel:&interruptChannel PSM:WM_INPUT_CHANNEL]) { + } else if(![self connectChannel:&interruptChannel PSM:kBluetoothL2CAPPSMHIDInterrupt]) { [self disconnect]; return kIOReturnNotOpen; } @@ -210,26 +210,26 @@ } - (int) writeBuffer: (byte*) buffer length: (NSUInteger) length { - if(controlChannel == nil) { - WIIUSE_ERROR("Attempted to write to nil control channel [id %i].", wm->unid); + if(interruptChannel == nil) { + WIIUSE_ERROR("Attempted to write to nil interrupt channel [id %i].", wm->unid); return 0; } - IOReturn error = [controlChannel writeSync:buffer length:length]; + IOReturn error = [interruptChannel writeSync:buffer length:length]; if (error != kIOReturnSuccess) { - WIIUSE_ERROR("Error writing to control channel [id %i].", wm->unid); + WIIUSE_ERROR("Error writing to interrupt channel [id %i].", wm->unid); - WIIUSE_DEBUG("Attempting to reopen the control channel [id %i].", wm->unid); - [self disconnectChannel:&controlChannel]; - [self connectChannel:&controlChannel PSM:WM_OUTPUT_CHANNEL]; - if(!controlChannel) { - WIIUSE_ERROR("Error reopening the control channel [id %i].", wm->unid); + WIIUSE_DEBUG("Attempting to reopen the interrupt channel [id %i].", wm->unid); + [self disconnectChannel:&interruptChannel]; + [self connectChannel:&interruptChannel PSM:kBluetoothL2CAPPSMHIDInterrupt]; + if(!interruptChannel) { + WIIUSE_ERROR("Error reopening the interrupt channel [id %i].", wm->unid); [self disconnect]; } else { - WIIUSE_DEBUG("Attempting to write again to the control channel [id %i].", wm->unid); - error = [controlChannel writeSync:buffer length:length]; + WIIUSE_DEBUG("Attempting to write again to the interrupt channel [id %i].", wm->unid); + error = [interruptChannel writeSync:buffer length:length]; if (error != kIOReturnSuccess) - WIIUSE_ERROR("Unable to write again to the control channel [id %i].", wm->unid); + WIIUSE_ERROR("Unable to write again to the interrupt channel [id %i].", wm->unid); } } @@ -242,8 +242,8 @@ byte* data = (byte*) data_; - // This is done in case the output channel woke up this handler - if(!data || ([channel PSM] == WM_OUTPUT_CHANNEL)) { + // This is done in case the control channel woke up this handler + if(!data || ([channel PSM] == kBluetoothL2CAPPSMHIDControl)) { return; } diff --git a/src/wiiuse.c b/src/wiiuse.c index 6d1ff5e..a3fd854 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -663,7 +663,11 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { #ifdef WIIUSE_WIN32 buf[0] = report_type; #else - buf[0] = WM_SET_REPORT | WM_BT_OUTPUT; + #ifdef WIIUSE_MAC + buf[0] = WM_SET_DATA | WM_BT_OUTPUT; + #else // *NIX + buf[0] = WM_SET_REPORT | WM_BT_OUTPUT; + #endif buf[1] = report_type; #endif diff --git a/src/wiiuse_internal.h b/src/wiiuse_internal.h index 7c02113..4ec921d 100644 --- a/src/wiiuse_internal.h +++ b/src/wiiuse_internal.h @@ -104,6 +104,7 @@ #define WM_INPUT_CHANNEL 0x13 #define WM_SET_REPORT 0x50 +#define WM_SET_DATA 0xA0 /* commands */ #define WM_CMD_LED 0x11 From ad79a2ff53b4fbd6a5c941421661d667bdfb1174 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Mon, 12 Nov 2012 01:56:34 +0100 Subject: [PATCH 27/55] fix motion plus handshake on mac by disabling expansion handshake while motion plus handshake is being done --- src/events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events.c b/src/events.c index 70d3404..d6d49ec 100644 --- a/src/events.c +++ b/src/events.c @@ -525,7 +525,7 @@ static void event_status(struct wiimote_t* wm, byte* msg) { wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE); /* expansion port */ - if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { + if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP) && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) { /* send the initialization code for the attachment */ handshake_expansion(wm, NULL, 0); exp_changed = 1; From 2e830fa6fa7d54c7d0900f11611ebe3d6171640f Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Mon, 12 Nov 2012 11:27:40 +0100 Subject: [PATCH 28/55] fix Windows compilation --- example/example.c | 3 ++- src/events.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/example/example.c b/example/example.c index 1db8bc5..f35f907 100644 --- a/example/example.c +++ b/example/example.c @@ -295,9 +295,10 @@ void test(struct wiimote_t* wm, byte* data, unsigned short len) { } short any_wiimote_connected(wiimote** wm, int wiimotes) { + int i; if(!wm) return 0; - for(int i = 0; i < wiimotes; i++) { + for(i = 0; i < wiimotes; i++) { if(wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) return 1; } diff --git a/src/events.c b/src/events.c index d6d49ec..1d4d227 100644 --- a/src/events.c +++ b/src/events.c @@ -616,11 +616,11 @@ static void handle_expansion(struct wiimote_t* wm, byte* msg) { * a handshake with the expansion. */ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { - WIIUSE_DEBUG("handshake_expansion with state %d", wm->expansion_state); int id; byte val = 0; byte buf = 0x00; byte* handshake_buf; + WIIUSE_DEBUG("handshake_expansion with state %d", wm->expansion_state); switch(wm->expansion_state) { /* These two initialization writes disable the encryption */ From 156d89ab161be681993edff423c10b91f14cd082 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Thu, 15 Nov 2012 10:54:17 +0100 Subject: [PATCH 29/55] fix *nix compilation --- src/events.c | 3 +-- src/events.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/events.c b/src/events.c index d6d49ec..08f1984 100644 --- a/src/events.c +++ b/src/events.c @@ -51,7 +51,6 @@ #include /* for free, malloc */ #include /* for memcpy, memset */ -static void clear_dirty_reads(struct wiimote_t* wm); static void event_data_read(struct wiimote_t* wm, byte* msg); static void event_data_write(struct wiimote_t *wm, byte *msg); static void event_status(struct wiimote_t* wm, byte* msg); @@ -141,7 +140,7 @@ void idle_cycle(struct wiimote_t* wm) { * * @param wm Pointer to a wiimote_t structure. */ -static void clear_dirty_reads(struct wiimote_t* wm) { +void clear_dirty_reads(struct wiimote_t* wm) { struct read_req_t* req = wm->read_req; while (req && req->dirty) { diff --git a/src/events.h b/src/events.h index fde16a3..9300193 100644 --- a/src/events.h +++ b/src/events.h @@ -56,8 +56,9 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len); void disable_expansion(struct wiimote_t* wm); void propagate_event(struct wiimote_t* wm, byte event, byte* msg); - void idle_cycle(struct wiimote_t* wm); + +void clear_dirty_reads(struct wiimote_t* wm); /** @} */ #endif /* EVENTS_H_INCLUDED */ From 5a2b31afbe42a8a0c8ec4b374d9f5a9670c1b2e8 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Thu, 15 Nov 2012 10:58:48 +0100 Subject: [PATCH 30/55] os_mac.h is not a source file to compile --- src/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f428ec3..975b58d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,15 +30,17 @@ if(WIN32) list(APPEND SOURCES os_win.c) set(CMAKE_DEBUG_POSTFIX _debug) elseif(APPLE) - set(MAC_SOURCES - os_mac/os_mac.h + set(MAC_OBJC_SOURCES os_mac/os_mac.m os_mac/os_mac_interface.m os_mac/os_mac_find.m) + set(MAC_SOURCES + os_mac/os_mac.h + ${MAC_OBJC_SOURCES}) list(APPEND SOURCES ${MAC_SOURCES}) # make sure we use the gcc for Objective-C files as well so that the # sysroot and deployment target arguments are correctly passed to the compiler - SET_SOURCE_FILES_PROPERTIES(${MAC_SOURCES} PROPERTIES LANGUAGE C) + SET_SOURCE_FILES_PROPERTIES(${MAC_OBJC_SOURCES} PROPERTIES LANGUAGE C) else() list(APPEND SOURCES os_nix.c) endif() From 11466cd19d6d8b426e08964b8800dcf0d71be508 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Thu, 15 Nov 2012 10:59:17 +0100 Subject: [PATCH 31/55] fix syntax for non-C99 mode --- example/example.c | 3 ++- src/os_mac/os_mac_find.m | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/example.c b/example/example.c index 1db8bc5..f35f907 100644 --- a/example/example.c +++ b/example/example.c @@ -295,9 +295,10 @@ void test(struct wiimote_t* wm, byte* data, unsigned short len) { } short any_wiimote_connected(wiimote** wm, int wiimotes) { + int i; if(!wm) return 0; - for(int i = 0; i < wiimotes; i++) { + for(i = 0; i < wiimotes; i++) { if(wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) return 1; } diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index 0c686c3..715569d 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -126,7 +126,8 @@ // read found device information NSArray* devices = [inquiry foundDevices]; - for(NSUInteger i = 0; i < [devices count]; i++) { + NSUInteger i; + for(i = 0; i < [devices count]; i++) { IOBluetoothDevice* device = [devices objectAtIndex:i]; // save the device in the wiimote structure From ae001a43b3a016bf90f3705d1d2e088df3610de9 Mon Sep 17 00:00:00 2001 From: Brodie Blackburn Date: Sat, 6 Oct 2012 10:22:45 +1000 Subject: [PATCH 32/55] Check Bluetooth power state Taken from http://cocoadev.com/wiki/FindingBluetoothAvailability Conflicts: src/io_mac.m --- src/os_mac/os_mac_find.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index 715569d..d576a19 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -68,11 +68,18 @@ - (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ { self = [super init]; if(self) { - wiimotes = wiimotes_; - maxDevices = maxDevices_; - timeout = timeout_; - - _running = NO; + if (![IOBluetoothHostController defaultController] || + [IOBluetoothHostController defaultController].powerState == kBluetoothHCIPowerStateOFF) + { + WIIUSE_DEBUG("Bluetooth hardware not available."); + [self release]; + self = nil; + } else { + wiimotes = wiimotes_; + maxDevices = maxDevices_; + timeout = timeout_; + _running = NO; + } } return self; } From 73a47857c99da003448217e53f7c97171ffa9ade Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 10:55:01 +0100 Subject: [PATCH 33/55] lowercase SET_SOURCE_FILES_PROPERTIES cmake command --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 975b58d..9b69837 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,7 +40,7 @@ elseif(APPLE) list(APPEND SOURCES ${MAC_SOURCES}) # make sure we use the gcc for Objective-C files as well so that the # sysroot and deployment target arguments are correctly passed to the compiler - SET_SOURCE_FILES_PROPERTIES(${MAC_OBJC_SOURCES} PROPERTIES LANGUAGE C) + set_source_files_properties(${MAC_OBJC_SOURCES} PROPERTIES LANGUAGE C) else() list(APPEND SOURCES os_nix.c) endif() From 43e8a27fccb9334827788ba68a22c2ab357b32b7 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 11:04:28 +0100 Subject: [PATCH 34/55] no need to include mac IOBluetoothUserLib.h in wiiuse.h --- src/wiiuse.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/wiiuse.h b/src/wiiuse.h index ec22a24..82b42c4 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -99,10 +99,6 @@ /* nix */ #include #endif -#ifdef WIIUSE_MAC - /* mac */ - #include -#endif #ifndef WCONST #define WCONST const From 8a3354d11bbd799b39e3e1677cda0f02ca9cb61e Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 13:11:36 +0100 Subject: [PATCH 35/55] OSX 10.6 compatibility --- src/CMakeLists.txt | 6 ++++-- src/os_mac/os_mac.h | 7 +++++++ src/os_mac/os_mac.m | 26 +++++++++++++++++++++++++- src/os_mac/os_mac_find.m | 18 +++++++++++++++++- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b69837..d3c9f4e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,18 +58,20 @@ if(WIN32) elseif(LINUX) target_link_libraries(wiiuse m ${BLUEZ_LIBRARIES}) elseif(APPLE) + # link libraries find_library(IOBLUETOOTH_FRAMEWORK NAMES IOBluetooth) - find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation) - find_library(FOUNDATION_FRAMEWORK NAMES Foundation) target_link_libraries(wiiuse ${IOBLUETOOTH_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${FOUNDATION_FRAMEWORK}) + + # do not link Objective-C runtime with clang + set_target_properties(wiiuse PROPERTIES XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME "NO") endif() set_property(TARGET diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 7537f7b..11c05a3 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -42,6 +42,13 @@ #import "../wiiuse_internal.h" +#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 +#else +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 +#endif + + @interface WiiuseWiimote : NSObject { wiimote* wm; // reference to the C wiimote struct diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 517441a..f843ab8 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -243,7 +243,12 @@ byte* data = (byte*) data_; // This is done in case the control channel woke up this handler - if(!data || ([channel PSM] == kBluetoothL2CAPPSMHIDControl)) { +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + BluetoothL2CAPPSM psm = channel.PSM; +#else + BluetoothL2CAPPSM psm = [channel getPSM]; +#endif + if(!data || (psm == kBluetoothL2CAPPSMHIDControl)) { return; } @@ -255,6 +260,25 @@ [newData release]; } +#if !WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +// the following delegate methods were required on 10.6. They are here to get rid of 10.6 compiler warnings. +- (void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)l2capChannel status:(IOReturn)error { + /* no-op */ +} +- (void)l2capChannelClosed:(IOBluetoothL2CAPChannel*)l2capChannel { + /* no-op */ +} +- (void)l2capChannelReconfigured:(IOBluetoothL2CAPChannel*)l2capChannel { + /* no-op */ +} +- (void)l2capChannelWriteComplete:(IOBluetoothL2CAPChannel*)l2capChannel refcon:(void*)refcon status:(IOReturn)error { + /* no-op */ +} +- (void)l2capChannelQueueSpaceAvailable:(IOBluetoothL2CAPChannel*)l2capChannel { + /* no-op */ +} +#endif + @end #pragma mark - diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index d576a19..4107a3e 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -43,12 +43,19 @@ #import #import #import +#if !WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +#import // IOBluetoothLocalDeviceGetPowerState +#endif #pragma mark - #pragma mark WiiuseDeviceInquiry +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE @interface WiiuseDeviceInquiry : NSObject { +#else +@interface WiiuseDeviceInquiry : NSObject { +#endif wiimote** wiimotes; NSUInteger maxDevices; int timeout; @@ -68,8 +75,17 @@ - (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ { self = [super init]; if(self) { + + BluetoothHCIPowerState powerState = kBluetoothHCIPowerStateUnintialized; +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + if([IOBluetoothHostController defaultController]) + powerState = [IOBluetoothHostController defaultController].powerState; +#else + // yes it is deprecated. no, there is no alternative (on 10.6). + IOBluetoothLocalDeviceGetPowerState(&powerState); +#endif if (![IOBluetoothHostController defaultController] || - [IOBluetoothHostController defaultController].powerState == kBluetoothHCIPowerStateOFF) + powerState != kBluetoothHCIPowerStateON) { WIIUSE_DEBUG("Bluetooth hardware not available."); [self release]; From f9f896e6054a12c2c074c7ce3b71717503c867d2 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 18:00:31 +0100 Subject: [PATCH 36/55] fix wiiuse_read on mac and windows --- src/io.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/io.c b/src/io.c index aa53c36..1641386 100644 --- a/src/io.c +++ b/src/io.c @@ -149,7 +149,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buff */ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) { - byte pkt[8]; + byte pkt[6]; byte buf[MAX_PAYLOAD]; unsigned n_full_reports; unsigned last_report; @@ -160,27 +160,25 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor * address in big endian first, the leading byte will * be overwritten (only 3 bytes are sent) */ - to_big_endian_uint32_t(pkt + 2, addr); + to_big_endian_uint32_t(pkt, addr); - pkt[0] = 0x52; /* HID read command */ - pkt[1] = 0x17; /* report 17 - read */ - pkt[2] = (memory != 0) ? 0x00 : 0x04; /* read from registers or memory*/ - - /* - * length in big endian - */ - to_big_endian_uint16_t(pkt + 6, size); + /* read from registers or memory */ + pkt[0] = (memory != 0) ? 0x00 : 0x04; + + /* length in big endian */ + to_big_endian_uint16_t(pkt + 4, size); + + /* send */ + wiiuse_send(wm, WM_CMD_READ_DATA, pkt, sizeof(pkt)); /* calculate how many 16B packets we have to get back */ n_full_reports = size / 16; last_report = size % 16; output = data; - wiiuse_os_write(wm, pkt, 8); - for(i = 0; i < n_full_reports; ++i) { - wiiuse_wait_report(wm, 0x21, buf, MAX_PAYLOAD); + wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD); memmove(output, buf + 7, 16); output += 16; } @@ -188,7 +186,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor /* read the last incomplete packet */ if(last_report) { - wiiuse_wait_report(wm, 0x21, buf, MAX_PAYLOAD); + wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD); memmove(output, buf + 7, last_report); } } From 1df24b5c5a58e2086d86d1142d478be706261517 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 18:01:29 +0100 Subject: [PATCH 37/55] conditionally compile handshake_state field --- src/io.c | 3 +-- src/wiiuse.c | 4 ++++ src/wiiuse.h | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/io.c b/src/io.c index 1641386..e7bb83d 100644 --- a/src/io.c +++ b/src/io.c @@ -205,8 +205,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor * with this data. */ -#define SYNC_HANDSHAKE 1 -#ifdef SYNC_HANDSHAKE +#ifndef WIIUSE_SYNC_HANDSHAKE void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { diff --git a/src/wiiuse.c b/src/wiiuse.c index 6dc5347..062e1fd 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -181,7 +181,9 @@ void wiiuse_disconnected(struct wiimote_t* wm) { wm->leds = 0; wm->state = WIIMOTE_INIT_STATES; wm->read_req = NULL; +#ifdef WIIUSE_SYNC_HANDSHAKE wm->handshake_state = 0; +#endif wm->btns = 0; wm->btns_held = 0; wm->btns_released = 0; @@ -795,7 +797,9 @@ void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) { void wiiuse_resync(struct wiimote_t* wm) { if (!wm) return; +#ifdef WIIUSE_SYNC_HANDSHAKE wm->handshake_state = 0; +#endif wiiuse_handshake(wm, NULL, 0); } diff --git a/src/wiiuse.h b/src/wiiuse.h index 71b7537..9822020 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -322,6 +322,9 @@ typedef enum ir_position_t { #define WIIMOTE_EXP_TIMEOUT 10 #endif +#define WIIUSE_SYNC_HANDSHAKE + + typedef unsigned char byte; typedef char sbyte; @@ -756,7 +759,9 @@ typedef struct wiimote_t { WCONST int flags; /**< options flag */ +#ifdef WIIUSE_SYNC_HANDSHAKE WCONST byte handshake_state; /**< the state of the connection handshake */ +#endif WCONST byte expansion_state; /**< the state of the expansion handshake */ WCONST struct data_req_t* data_req; /**< list of data read requests */ From 866b124d3517a36d21bbbc2f16b0839976fe89e2 Mon Sep 17 00:00:00 2001 From: Lysann Kessler Date: Sat, 8 Dec 2012 18:58:30 +0100 Subject: [PATCH 38/55] fix Windows compilation, wiiuse_wait_report and wiiuse_probe_motion_plus --- src/io.c | 12 +++++++++--- src/motion_plus.c | 8 ++++++-- src/os_win.c | 13 ++++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/io.c b/src/io.c index e7bb83d..c3171ce 100644 --- a/src/io.c +++ b/src/io.c @@ -122,13 +122,19 @@ void wiiuse_disconnect(struct wiimote_t* wm) { */ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) { + byte readReport; for(;;) { if(wiiuse_os_read(wm, buffer, bufferLength) > 0) { - if(buffer[1] == report) { +#ifdef WIIUSE_WIN32 + readReport = buffer[0]; +#else + readReport = buffer[1]; +#endif + if(readReport == report) { break; } else { - WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[1], report); + WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, readReport, report); } } } @@ -154,7 +160,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor unsigned n_full_reports; unsigned last_report; byte *output; - int i; + unsigned int i; /* * address in big endian first, the leading byte will diff --git a/src/motion_plus.c b/src/motion_plus.c index 5aed3f4..711f541 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -47,11 +47,15 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm) { byte buf[MAX_PAYLOAD]; unsigned id; + unsigned short offset = 0; +#ifdef WIIUSE_WIN32 + offset = 1; +#endif wiiuse_read(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); /* check error code */ - if(buf[4] & 0x0f) + if(buf[4-offset] & 0x0f) { WIIUSE_DEBUG("No Motion+ available, stopping probe."); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); @@ -59,7 +63,7 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm) } /* decode the id*/ - id = from_big_endian_uint32_t(buf + 2); + id = from_big_endian_uint32_t(buf + 2 - offset); if(id != EXP_ID_CODE_INACTIVE_MOTION_PLUS && id != EXP_ID_CODE_NLA_MOTION_PLUS && diff --git a/src/os_win.c b/src/os_win.c index 08d945b..aede1fb 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -225,7 +225,7 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { if (r == WAIT_TIMEOUT) { /* timeout - cancel and continue */ - if (*wm->event_buf) + if (*buf) WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); CancelIo(wm->dev_handle); @@ -238,6 +238,17 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) return 0; + +#ifdef WITH_WIIUSE_DEBUG + { + int i; + printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, buf[0]); + for(i = 1; i < b; i++) { + printf("%x ", buf[i]); + } + printf("\n"); + } +#endif } ResetEvent(wm->hid_overlap.hEvent); From 72647a56b163c3c62dfe07432f3f9c2db0852478 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 20:34:13 +0100 Subject: [PATCH 39/55] remove the event_buf from the wiimote structure, allocating it on demand instead --- src/os_mac/os_mac_interface.m | 14 ++++++++------ src/os_nix.c | 9 +++++---- src/os_win.c | 11 ++++++----- src/wiiuse.c | 1 - src/wiiuse.h | 1 - 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/os_mac/os_mac_interface.m b/src/os_mac/os_mac_interface.m index f1ab398..c533d55 100644 --- a/src/os_mac/os_mac_interface.m +++ b/src/os_mac/os_mac_interface.m @@ -139,19 +139,21 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { #pragma mark poll, read, write int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { - int i, evnt = 0; + int i; + byte read_buffer[MAX_PAYLOAD]; + int evnt = 0; if (!wm) return 0; for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - if (wiiuse_os_read(wm[i], wm[i]->event_buf, sizeof(wm[i]->event_buf))) { + /* clear out the buffer */ + memset(read_buffer, 0, sizeof(read_buffer)); + /* read */ + if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) { /* propagate the event, messages should be read as in linux, starting from the second element */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + propagate_event(wm[i], read_buffer[1], read_buffer+2); } else { /* send out any waiting writes */ wiiuse_send_next_pending_write_request(wm[i]); diff --git a/src/os_nix.c b/src/os_nix.c index 20e4b1e..3cebe5d 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -237,6 +237,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { fd_set fds; int r; int i; + byte read_buffer[MAX_PAYLOAD]; int highest_fd = -1; evnt = 0; @@ -279,13 +280,13 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { if (FD_ISSET(wm[i]->in_sock, &fds)) { /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); + memset(read_buffer, 0, sizeof(read_buffer)); - /* clear out any old read requests */ + /* clear out any old read data */ clear_dirty_reads(wm[i]); /* read the pending message into the buffer */ - r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf)); + r = read(wm[i]->in_sock, read_buffer, sizeof(read_buffer)); if (r == -1) { /* error reading data */ WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid); @@ -309,7 +310,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { } /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2); + propagate_event(wm[i], read_buffer[1], read_buffer+2); evnt += (wm[i]->event != WIIUSE_NONE); } else { /* send out any waiting writes */ diff --git a/src/os_win.c b/src/os_win.c index aede1fb..0b0c0fb 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -181,6 +181,7 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) { int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int i; + byte read_buffer[MAX_PAYLOAD]; int evnt = 0; if (!wm) return 0; @@ -188,13 +189,13 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; - if (wiiuse_os_read(wm[i], wm[i]->event_buf, sizeof(wm[i]->event_buf))) { + /* clear out the buffer */ + memset(read_buffer, 0, sizeof(read_buffer)); + /* read */ + if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) { /* propagate the event */ - propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1); + propagate_event(wm[i], read_buffer[0], read_buffer+1); evnt += (wm[i]->event != WIIUSE_NONE); - - /* clear out the event buffer */ - memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf)); } else { /* send out any waiting writes */ wiiuse_send_next_pending_write_request(wm[i]); diff --git a/src/wiiuse.c b/src/wiiuse.c index 062e1fd..ee127c9 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -187,7 +187,6 @@ void wiiuse_disconnected(struct wiimote_t* wm) { wm->btns = 0; wm->btns_held = 0; wm->btns_released = 0; - memset(wm->event_buf, 0, sizeof(wm->event_buf)); wm->event = WIIUSE_DISCONNECT; } diff --git a/src/wiiuse.h b/src/wiiuse.h index 9822020..7e1616a 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -785,7 +785,6 @@ typedef struct wiimote_t { WCONST struct wiimote_state_t lstate; /**< last saved state */ WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */ - WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */ WCONST byte motion_plus_id[6]; } wiimote; From 97513647de271a4d0a25c43711a9ddc2a6950e14 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 20:39:12 +0100 Subject: [PATCH 40/55] fix *nix function names for read and write --- src/os_nix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os_nix.c b/src/os_nix.c index 3cebe5d..69349b1 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -322,7 +322,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { return evnt; } -int wiiuse_io_read(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { int rc; rc = read(wm->in_sock, buf, len); @@ -333,7 +333,7 @@ int wiiuse_io_read(struct wiimote_t* wm, byte* buf, int len) { return rc; } -int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { int rc; rc = write(wm->out_sock, buf, len); From f2bf07c18c07214363b6e9c1e25e989d032a9942 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 21:13:15 +0100 Subject: [PATCH 41/55] same interface for all wiiuse_os_read's --- src/io.c | 18 ++++------ src/io.h | 2 +- src/motion_plus.c | 12 +++---- src/os.h | 1 + src/os_mac/os_mac.m | 7 ++-- src/os_mac/os_mac_interface.m | 4 +-- src/os_nix.c | 62 ++++++++++++++++++++--------------- src/os_win.c | 5 +-- src/wiiuse.h | 6 ---- src/wiiuse_internal.h | 6 ++++ 10 files changed, 63 insertions(+), 60 deletions(-) diff --git a/src/io.c b/src/io.c index c3171ce..9e8a749 100644 --- a/src/io.c +++ b/src/io.c @@ -122,19 +122,13 @@ void wiiuse_disconnect(struct wiimote_t* wm) { */ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) { - byte readReport; for(;;) { if(wiiuse_os_read(wm, buffer, bufferLength) > 0) { -#ifdef WIIUSE_WIN32 - readReport = buffer[0]; -#else - readReport = buffer[1]; -#endif - if(readReport == report) { + if(buffer[0] == report) { break; } else { - WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, readReport, report); + WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[0], report); } } } @@ -153,7 +147,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buff * amount of data from the Wiimote. * */ -void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) +void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) { byte pkt[6]; byte buf[MAX_PAYLOAD]; @@ -185,7 +179,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor for(i = 0; i < n_full_reports; ++i) { wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD); - memmove(output, buf + 7, 16); + memmove(output, buf + 6, 16); output += 16; } @@ -193,7 +187,7 @@ void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned shor if(last_report) { wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD); - memmove(output, buf + 7, last_report); + memmove(output, buf + 6, last_report); } } @@ -240,7 +234,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { struct accel_t* accel = &wm->accel_calib; - wiiuse_read(wm, 1, WM_MEM_OFFSET_CALIBRATION, 8, buf); + wiiuse_read_data_sync(wm, 1, WM_MEM_OFFSET_CALIBRATION, 8, buf); /* received read data */ accel->cal_zero.x = buf[0]; diff --git a/src/io.h b/src/io.h index 5f83ac1..9dd1da8 100644 --- a/src/io.h +++ b/src/io.h @@ -45,7 +45,7 @@ extern "C" { void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len); void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength); -void wiiuse_read(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data); +void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data); /** @} */ #ifdef __cplusplus diff --git a/src/motion_plus.c b/src/motion_plus.c index 711f541..84a3699 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -47,23 +47,19 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm) { byte buf[MAX_PAYLOAD]; unsigned id; - unsigned short offset = 0; -#ifdef WIIUSE_WIN32 - offset = 1; -#endif - wiiuse_read(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); + wiiuse_read_data_sync(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); /* check error code */ - if(buf[4-offset] & 0x0f) + if(buf[4] & 0x0f) { WIIUSE_DEBUG("No Motion+ available, stopping probe."); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); return; } - /* decode the id*/ - id = from_big_endian_uint32_t(buf + 2 - offset); + /* decode the id */ + id = from_big_endian_uint32_t(buf + 2); if(id != EXP_ID_CODE_INACTIVE_MOTION_PLUS && id != EXP_ID_CODE_NLA_MOTION_PLUS && diff --git a/src/os.h b/src/os.h index 779fa3f..7b86c44 100644 --- a/src/os.h +++ b/src/os.h @@ -52,6 +52,7 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes); void wiiuse_os_disconnect(struct wiimote_t* wm); int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes); +/* buf[0] will be the report type, buf+1 the rest of the report */ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len); int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len); /** @} */ diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 1f64f45..8e2f57a 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -253,7 +253,8 @@ } // copy the data into the buffer - WiiuseReceivedData* newData = [[WiiuseReceivedData alloc] initWithBytes: data length: length]; + // on Mac, we ignore the first byte + WiiuseReceivedData* newData = [[WiiuseReceivedData alloc] initWithBytes: data+1 length: length-1]; [receivedDataLock lock]; [receivedData addObject: newData]; [receivedDataLock unlock]; @@ -316,9 +317,9 @@ // log the received data #ifdef WITH_WIIUSE_DEBUG { - printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, bytes[1]); + printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, bytes[0]); int x; - for (x = 2; x < length; ++x) + for (x = 1; x < length; ++x) printf("%.2x ", bytes[x]); printf("\n"); } diff --git a/src/os_mac/os_mac_interface.m b/src/os_mac/os_mac_interface.m index c533d55..ed5adfa 100644 --- a/src/os_mac/os_mac_interface.m +++ b/src/os_mac/os_mac_interface.m @@ -152,8 +152,8 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { memset(read_buffer, 0, sizeof(read_buffer)); /* read */ if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) { - /* propagate the event, messages should be read as in linux, starting from the second element */ - propagate_event(wm[i], read_buffer[1], read_buffer+2); + /* propagate the event */ + propagate_event(wm[i], read_buffer[0], read_buffer+1); } else { /* send out any waiting writes */ wiiuse_send_next_pending_write_request(wm[i]); diff --git a/src/os_nix.c b/src/os_nix.c index 69349b1..c454f58 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -286,32 +286,12 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { clear_dirty_reads(wm[i]); /* read the pending message into the buffer */ - r = read(wm[i]->in_sock, read_buffer, sizeof(read_buffer)); - if (r == -1) { - /* error reading data */ - WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid); - perror("Error Details"); - - if (errno == ENOTCONN) { - /* this can happen if the bluetooth dongle is disconnected */ - WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid); - wiiuse_os_disconnect(wm[i]); - wiiuse_disconnected(wm[i]); - wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT; - } - - continue; + r = wiiuse_os_read(wm, read_buffer, sizeof(read_buffer)); + if (r > 0) { + /* propagate the event */ + propagate_event(wm[i], read_buffer[0], read_buffer+1); + evnt += (wm[i]->event != WIIUSE_NONE); } - if (!r) { - /* remote disconnect */ - wiiuse_disconnected(wm[i]); - evnt = 1; - continue; - } - - /* propagate the event */ - propagate_event(wm[i], read_buffer[1], read_buffer+2); - evnt += (wm[i]->event != WIIUSE_NONE); } else { /* send out any waiting writes */ wiiuse_send_next_pending_write_request(wm[i]); @@ -324,11 +304,41 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { int rc; + int i; rc = read(wm->in_sock, buf, len); - if(rc <= 0) + if (r == -1) { + /* error reading data */ + WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid); + perror("Error Details"); + + if (errno == ENOTCONN) { + /* this can happen if the bluetooth dongle is disconnected */ + WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid); + wiiuse_os_disconnect(wm); + wiiuse_disconnected(wm); + } + } else if(rc == 0) { + /* remote disconnect */ wiiuse_disconnected(wm); + } else { + /* read successful */ + /* on *nix we ignore the first byte */ + memmove(buf, buf+1, len-1); + + /* log the received data */ +#ifdef WITH_WIIUSE_DEBUG + { + int i; + printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); + for(i = 1; i < rc; i++) { + printf("%.2x ", buf[i]); + } + printf("\n"); + } +#endif + } return rc; } diff --git a/src/os_win.c b/src/os_win.c index 0b0c0fb..489ff40 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -240,12 +240,13 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) return 0; + /* log the received data */ #ifdef WITH_WIIUSE_DEBUG { int i; - printf("[DEBUG] (id %i) RECV: (%x) ", wm->unid, buf[0]); + printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); for(i = 1; i < b; i++) { - printf("%x ", buf[i]); + printf("%.2x ", buf[i]); } printf("\n"); } diff --git a/src/wiiuse.h b/src/wiiuse.h index 7e1616a..f801e3c 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -307,12 +307,6 @@ typedef enum ir_position_t { #define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num) /** @} */ -/* - * Largest known payload is 21 bytes. - * Add 2 for the prefix and round up to a power of 2. - */ -#define MAX_PAYLOAD 32 - /* * This is left over from an old hack, but it may actually * be a useful feature to keep so it wasn't removed. diff --git a/src/wiiuse_internal.h b/src/wiiuse_internal.h index 39c1f1e..e4830c0 100644 --- a/src/wiiuse_internal.h +++ b/src/wiiuse_internal.h @@ -243,6 +243,12 @@ #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s)) +/* + * Largest known payload is 21 bytes. + * Add 1 (Win32) or 2 (Mac, *nix) for the prefix and round up to a power of 2. + */ +#define MAX_PAYLOAD 32 + /* * Smooth tilt calculations are computed with the * exponential moving average formula: From d7a5d7748955e9ef0fea94739d42aa6d034a5994 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 22:04:07 +0100 Subject: [PATCH 42/55] same interface for all wiiuse_os_write's this also means we moved platform-sepcific write code into the wiiuse_os_write implementation of each platform. --- src/os.h | 2 +- src/os_mac/os_mac.h | 2 +- src/os_mac/os_mac.m | 11 ++++++--- src/os_mac/os_mac_interface.m | 4 ++-- src/os_nix.c | 9 +++++-- src/os_win.c | 14 +++++++---- src/wiiuse.c | 45 +++++------------------------------ 7 files changed, 34 insertions(+), 53 deletions(-) diff --git a/src/os.h b/src/os.h index 7b86c44..a1b6b60 100644 --- a/src/os.h +++ b/src/os.h @@ -54,7 +54,7 @@ void wiiuse_os_disconnect(struct wiimote_t* wm); int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes); /* buf[0] will be the report type, buf+1 the rest of the report */ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len); -int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len); +int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len); /** @} */ #ifdef __cplusplus diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 273d6a0..819d526 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -68,7 +68,7 @@ - (void) disconnect; - (int) readBuffer: (byte*) buffer length: (NSUInteger) bufferLength; -- (int) writeBuffer: (byte*) buffer length: (NSUInteger) length; +- (int) writeReport: (byte) report_type buffer: (byte*) buffer length: (NSUInteger) length; @end diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 8e2f57a..4a9c99b 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -209,13 +209,18 @@ return result >= 0 ? result : 0; } -- (int) writeBuffer: (byte*) buffer length: (NSUInteger) length { +- (int) writeReport: (byte) report_type buffer: (byte*) buffer length: (NSUInteger) length { if(interruptChannel == nil) { WIIUSE_ERROR("Attempted to write to nil interrupt channel [id %i].", wm->unid); return 0; } - IOReturn error = [interruptChannel writeSync:buffer length:length]; + byte write_buffer[MAX_PAYLOAD]; + write_buffer[0] = WM_SET_DATA | WM_BT_OUTPUT; + write_buffer[1] = report_type; + memcpy(write_buffer+2, buffer, length); + + IOReturn error = [interruptChannel writeSync:write_buffer length:length+2]; if (error != kIOReturnSuccess) { WIIUSE_ERROR("Error writing to interrupt channel [id %i].", wm->unid); @@ -227,7 +232,7 @@ [self disconnect]; } else { WIIUSE_DEBUG("Attempting to write again to the interrupt channel [id %i].", wm->unid); - error = [interruptChannel writeSync:buffer length:length]; + error = [interruptChannel writeSync:write_buffer length:length+2]; if (error != kIOReturnSuccess) WIIUSE_ERROR("Unable to write again to the interrupt channel [id %i].", wm->unid); } diff --git a/src/os_mac/os_mac_interface.m b/src/os_mac/os_mac_interface.m index ed5adfa..ca67408 100644 --- a/src/os_mac/os_mac_interface.m +++ b/src/os_mac/os_mac_interface.m @@ -182,7 +182,7 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { return result; } -int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) { if(!wm || !wm->objc_wm) return 0; if(!WIIMOTE_IS_CONNECTED(wm)) { WIIUSE_ERROR("Attempting to write to unconnected Wiimote"); @@ -192,7 +192,7 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm; - int result = [objc_wm writeBuffer: buf length: (NSUInteger)len]; + int result = [objc_wm writeReport: report_type buffer: buf length: (NSUInteger)len]; [pool drain]; return result; diff --git a/src/os_nix.c b/src/os_nix.c index c454f58..88588d5 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -343,9 +343,14 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { return rc; } -int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) { int rc; - rc = write(wm->out_sock, buf, len); + byte write_buffer[MAX_PAYLOAD]; + + write_buffer[0] = WM_SET_REPORT | WM_BT_OUTPUT; + write_buffer[1] = report_type; + memcpy(write_buffer+2, buf, len); + rc = write(wm->out_sock, write_buffer, len+2); if(rc < 0) wiiuse_disconnected(wm); diff --git a/src/os_win.c b/src/os_win.c index 489ff40..0173e04 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -258,24 +258,28 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { } -int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { +int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) { DWORD bytes; int i; + byte write_buffer[MAX_PAYLOAD]; if (!wm || !WIIMOTE_IS_CONNECTED(wm)) return 0; + write_buffer[0] = report_type; + memcpy(write_buffer+1, buf, len); + switch (wm->stack) { case WIIUSE_STACK_UNKNOWN: { /* try to auto-detect the stack type */ - if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) { + if (i = WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap)) { /* bluesoleil will always return 1 here, even if it's not connected */ wm->stack = WIIUSE_STACK_BLUESOLEIL; return i; } - if (i = HidD_SetOutputReport(wm->dev_handle, buf, len)) { + if (i = HidD_SetOutputReport(wm->dev_handle, write_buffer, len+1)) { wm->stack = WIIUSE_STACK_MS; return i; } @@ -285,10 +289,10 @@ int wiiuse_os_write(struct wiimote_t* wm, byte* buf, int len) { } case WIIUSE_STACK_MS: - return HidD_SetOutputReport(wm->dev_handle, buf, len); + return HidD_SetOutputReport(wm->dev_handle, write_buffer, len+1); case WIIUSE_STACK_BLUESOLEIL: - return WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap); + return WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap); } return 0; diff --git a/src/wiiuse.c b/src/wiiuse.c index ee127c9..2b813d3 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -616,26 +616,12 @@ void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) { * * @param wm Pointer to a wiimote_t structure. * @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h - * @param msg The payload. + * @param msg The payload. Might be changed by the callee. * @param len Length of the payload in bytes. * * This function should replace any write()s directly to the wiimote device. */ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { - byte buf[MAX_PAYLOAD]; /* no payload is better than this */ - int rumble = 0; - - #ifdef WIIUSE_WIN32 - buf[0] = report_type; - #else - #ifdef WIIUSE_MAC - buf[0] = WM_SET_DATA | WM_BT_OUTPUT; - #else // *NIX - buf[0] = WM_SET_REPORT | WM_BT_OUTPUT; - #endif - buf[1] = report_type; - #endif - switch (report_type) { case WM_CMD_LED: case WM_CMD_RUMBLE: @@ -643,43 +629,24 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { { /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) - rumble = 1; + msg[1] |= 0x01; break; } default: break; } - #ifndef WIIUSE_WIN32 - memcpy(buf+2, msg, len); - if (rumble) - buf[2] |= 0x01; - #else - memcpy(buf+1, msg, len); - if (rumble) - buf[1] |= 0x01; - #endif - #ifdef WITH_WIIUSE_DEBUG { int x; - #ifndef WIIUSE_WIN32 - printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[1], buf[2]); - for (x = 3; x < len+2; ++x) - #else - printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]); - for (x = 2; x < len+1; ++x) - #endif - printf("%.2x ", buf[x]); + printf("[DEBUG] (id %i) SEND: (%.2x) %.2x ", wm->unid, report_type, msg[0]); + for (x = 1; x < len; ++x) + printf("%.2x ", msg[x]); printf("\n"); } #endif - #ifndef WIIUSE_WIN32 - return wiiuse_os_write(wm, buf, len+2); - #else - return wiiuse_os_write(wm, buf, len+1); - #endif + return wiiuse_os_write(wm, report_type, msg, len); } From cfd8209c23b4ce936acdd10ab11f8690b4c803bf Mon Sep 17 00:00:00 2001 From: Lysann Kessler Date: Sat, 8 Dec 2012 22:44:48 +0100 Subject: [PATCH 43/55] fix rumble flag and windows compiler warning --- src/os_win.c | 2 +- src/wiiuse.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os_win.c b/src/os_win.c index 0173e04..b8d7f90 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -243,7 +243,7 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { /* log the received data */ #ifdef WITH_WIIUSE_DEBUG { - int i; + DWORD i; printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); for(i = 1; i < b; i++) { printf("%.2x ", buf[i]); diff --git a/src/wiiuse.c b/src/wiiuse.c index 2b813d3..b4b95db 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -629,7 +629,7 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { { /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) - msg[1] |= 0x01; + msg[0] |= 0x01; break; } default: From a4e3140274b2e12eba8400b49c74f75f7bd061d3 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 23:01:32 +0100 Subject: [PATCH 44/55] now swap WIIUSE_SYNC_HANDSHAKE usages again --- src/io.c | 2 +- src/wiiuse.c | 4 ++-- src/wiiuse.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/io.c b/src/io.c index 9e8a749..82e9af7 100644 --- a/src/io.c +++ b/src/io.c @@ -205,7 +205,7 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns * with this data. */ -#ifndef WIIUSE_SYNC_HANDSHAKE +#ifdef WIIUSE_SYNC_HANDSHAKE void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { diff --git a/src/wiiuse.c b/src/wiiuse.c index b4b95db..839f0b6 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -181,7 +181,7 @@ void wiiuse_disconnected(struct wiimote_t* wm) { wm->leds = 0; wm->state = WIIMOTE_INIT_STATES; wm->read_req = NULL; -#ifdef WIIUSE_SYNC_HANDSHAKE +#ifndef WIIUSE_SYNC_HANDSHAKE wm->handshake_state = 0; #endif wm->btns = 0; @@ -763,7 +763,7 @@ void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) { void wiiuse_resync(struct wiimote_t* wm) { if (!wm) return; -#ifdef WIIUSE_SYNC_HANDSHAKE +#ifndef WIIUSE_SYNC_HANDSHAKE wm->handshake_state = 0; #endif wiiuse_handshake(wm, NULL, 0); diff --git a/src/wiiuse.h b/src/wiiuse.h index f801e3c..84affea 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -753,7 +753,7 @@ typedef struct wiimote_t { WCONST int flags; /**< options flag */ -#ifdef WIIUSE_SYNC_HANDSHAKE +#ifndef WIIUSE_SYNC_HANDSHAKE WCONST byte handshake_state; /**< the state of the connection handshake */ #endif WCONST byte expansion_state; /**< the state of the expansion handshake */ From ca7c6127aca6f3f4864e26882762b17132372df0 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 9 Dec 2012 00:44:50 +0100 Subject: [PATCH 45/55] fix *nix compilation error --- src/os_nix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os_nix.c b/src/os_nix.c index 88588d5..29cc564 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -308,7 +308,7 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { rc = read(wm->in_sock, buf, len); - if (r == -1) { + if (rc == -1) { /* error reading data */ WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid); perror("Error Details"); From 82080f9f374bf73a01dd29f5f1cb238ad130b766 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sun, 9 Dec 2012 10:31:17 +0100 Subject: [PATCH 46/55] we need to pass a single wiimote structure instead of the array to wiiuse_os_read --- src/os_nix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os_nix.c b/src/os_nix.c index 29cc564..4df8a27 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -286,7 +286,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { clear_dirty_reads(wm[i]); /* read the pending message into the buffer */ - r = wiiuse_os_read(wm, read_buffer, sizeof(read_buffer)); + r = wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer)); if (r > 0) { /* propagate the event */ propagate_event(wm[i], read_buffer[0], read_buffer+1); From a86f33afa58acbe49088699cdbc027c91409bfdb Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 10 Dec 2012 14:13:58 -0600 Subject: [PATCH 47/55] astyle on the library. --- src/classic.c | 7 +- src/classic.h | 12 +- src/dynamics.c | 77 ++++---- src/dynamics.h | 14 +- src/events.c | 439 +++++++++++++++++++++--------------------- src/guitar_hero_3.c | 7 +- src/guitar_hero_3.h | 12 +- src/io.c | 205 ++++++++++---------- src/io.h | 12 +- src/ir.c | 389 ++++++++++++++++++++----------------- src/ir.h | 14 +- src/motion_plus.c | 216 ++++++++++----------- src/motion_plus.h | 22 +-- src/nunchuk.c | 19 +- src/nunchuk.h | 14 +- src/os.h | 24 +-- src/os_nix.c | 52 +++-- src/os_win.c | 83 ++++---- src/wiiboard.c | 22 +-- src/wiiboard.h | 12 +- src/wiiuse.c | 222 +++++++++++++-------- src/wiiuse.h | 156 ++++++++------- src/wiiuse_internal.h | 194 +++++++++---------- 23 files changed, 1168 insertions(+), 1056 deletions(-) diff --git a/src/classic.c b/src/classic.c index a87d1ef..eea8ffc 100644 --- a/src/classic.c +++ b/src/classic.c @@ -77,8 +77,9 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); return 0; - } else + } else { data += 16; + } } @@ -100,9 +101,9 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte /* handshake done */ wm->exp.type = EXP_CLASSIC; - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif +#endif return 1; } diff --git a/src/classic.h b/src/classic.h index 7fe7b30..e54337a 100644 --- a/src/classic.h +++ b/src/classic.h @@ -40,14 +40,14 @@ extern "C" { #endif -/** @defgroup internal_classic Internal: Classic Controller */ -/** @{ */ -int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len); + /** @defgroup internal_classic Internal: Classic Controller */ + /** @{ */ + int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len); -void classic_ctrl_disconnected(struct classic_ctrl_t* cc); + void classic_ctrl_disconnected(struct classic_ctrl_t* cc); -void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg); -/** @} */ + void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg); + /** @} */ #ifdef __cplusplus } diff --git a/src/dynamics.c b/src/dynamics.c index d6ffbf7..76ac202 100644 --- a/src/dynamics.c +++ b/src/dynamics.c @@ -77,12 +77,21 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori z = ((float)accel->z - (float)ac->cal_zero.z) / zg; /* make sure x,y,z are between -1 and 1 for the tan functions */ - if (x < -1.0f) x = -1.0f; - else if (x > 1.0f) x = 1.0f; - if (y < -1.0f) y = -1.0f; - else if (y > 1.0f) y = 1.0f; - if (z < -1.0f) z = -1.0f; - else if (z > 1.0f) z = 1.0f; + if (x < -1.0f) { + x = -1.0f; + } else if (x > 1.0f) { + x = 1.0f; + } + if (y < -1.0f) { + y = -1.0f; + } else if (y > 1.0f) { + y = 1.0f; + } + if (z < -1.0f) { + z = -1.0f; + } else if (z > 1.0f) { + z = 1.0f; + } /* if it is over 1g then it is probably accelerating and not reliable */ if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) { @@ -180,39 +189,39 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) { void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) { switch (type) { - case SMOOTH_ROLL: - { - /* it's possible last iteration was nan or inf, so set it to 0 if that happened */ - if (isnan(ac->st_roll) || isinf(ac->st_roll)) - ac->st_roll = 0.0f; + case SMOOTH_ROLL: { + /* it's possible last iteration was nan or inf, so set it to 0 if that happened */ + if (isnan(ac->st_roll) || isinf(ac->st_roll)) { + ac->st_roll = 0.0f; + } - /* - * If the sign changes (which will happen if going from -180 to 180) - * or from (-1 to 1) then don't smooth, just use the new angle. - */ - if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) { - ac->st_roll = orient->roll; - } else { - orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll)); - ac->st_roll = orient->roll; + /* + * If the sign changes (which will happen if going from -180 to 180) + * or from (-1 to 1) then don't smooth, just use the new angle. + */ + if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) { + ac->st_roll = orient->roll; + } else { + orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll)); + ac->st_roll = orient->roll; + } + + return; } - return; - } + case SMOOTH_PITCH: { + if (isnan(ac->st_pitch) || isinf(ac->st_pitch)) { + ac->st_pitch = 0.0f; + } - case SMOOTH_PITCH: - { - if (isnan(ac->st_pitch) || isinf(ac->st_pitch)) - ac->st_pitch = 0.0f; + if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) { + ac->st_pitch = orient->pitch; + } else { + orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch)); + ac->st_pitch = orient->pitch; + } - if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) { - ac->st_pitch = orient->pitch; - } else { - orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch)); - ac->st_pitch = orient->pitch; + return; } - - return; - } } } diff --git a/src/dynamics.h b/src/dynamics.h index 9722b4d..5ef14e0 100644 --- a/src/dynamics.h +++ b/src/dynamics.h @@ -44,14 +44,14 @@ extern "C" { #endif -/** @defgroup internal_dynamics Internal: Dynamics Functions */ -/** @{ */ + /** @defgroup internal_dynamics Internal: Dynamics Functions */ + /** @{ */ -void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth); -void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce); -void calc_joystick_state(struct joystick_t* js, float x, float y); -void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type); -/** @} */ + void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth); + void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce); + void calc_joystick_state(struct joystick_t* js, float x, float y); + void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type); + /** @} */ #ifdef __cplusplus } diff --git a/src/events.c b/src/events.c index ac398f5..cc7b2c1 100644 --- a/src/events.c +++ b/src/events.c @@ -99,7 +99,7 @@ int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb c s.event = wiimotes[i]->event; s.state = wiimotes[i]->state; s.expansion = wiimotes[i]->exp; - callback( &s ); + callback(&s); evnt++; break; } @@ -184,108 +184,98 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) { save_state(wm); switch (event) { - case WM_RPT_BTN: - { - /* button */ - wiiuse_pressed_buttons(wm, msg); - break; - } - case WM_RPT_BTN_ACC: - { - /* button - motion */ - wiiuse_pressed_buttons(wm, msg); + case WM_RPT_BTN: { + /* button */ + wiiuse_pressed_buttons(wm, msg); + break; + } + case WM_RPT_BTN_ACC: { + /* button - motion */ + wiiuse_pressed_buttons(wm, msg); - handle_wm_accel(wm, msg); + handle_wm_accel(wm, msg); - break; - } - case WM_RPT_READ: - { - /* data read */ - event_data_read(wm, msg); + break; + } + case WM_RPT_READ: { + /* data read */ + event_data_read(wm, msg); - /* yeah buttons may be pressed, but this wasn't an "event" */ - return; - } - case WM_RPT_CTRL_STATUS: - { - /* controller status */ - event_status(wm, msg); + /* yeah buttons may be pressed, but this wasn't an "event" */ + return; + } + case WM_RPT_CTRL_STATUS: { + /* controller status */ + event_status(wm, msg); - /* don't execute the event callback */ - return; - } - case WM_RPT_BTN_EXP: - { - /* button - expansion */ - wiiuse_pressed_buttons(wm, msg); - handle_expansion(wm, msg+2); + /* don't execute the event callback */ + return; + } + case WM_RPT_BTN_EXP: { + /* button - expansion */ + wiiuse_pressed_buttons(wm, msg); + handle_expansion(wm, msg + 2); - break; - } - case WM_RPT_BTN_ACC_EXP: - { - /* button - motion - expansion */ - wiiuse_pressed_buttons(wm, msg); + break; + } + case WM_RPT_BTN_ACC_EXP: { + /* button - motion - expansion */ + wiiuse_pressed_buttons(wm, msg); - handle_wm_accel(wm, msg); + handle_wm_accel(wm, msg); - handle_expansion(wm, msg+5); + handle_expansion(wm, msg + 5); - break; - } - case WM_RPT_BTN_ACC_IR: - { - /* button - motion - ir */ - wiiuse_pressed_buttons(wm, msg); + break; + } + case WM_RPT_BTN_ACC_IR: { + /* button - motion - ir */ + wiiuse_pressed_buttons(wm, msg); - handle_wm_accel(wm, msg); + handle_wm_accel(wm, msg); - /* ir */ - calculate_extended_ir(wm, msg+5); + /* ir */ + calculate_extended_ir(wm, msg + 5); - break; - } - case WM_RPT_BTN_IR_EXP: - { - /* button - ir - expansion */ - wiiuse_pressed_buttons(wm, msg); - handle_expansion(wm, msg+12); + break; + } + case WM_RPT_BTN_IR_EXP: { + /* button - ir - expansion */ + wiiuse_pressed_buttons(wm, msg); + handle_expansion(wm, msg + 12); - /* ir */ - calculate_basic_ir(wm, msg+2); + /* ir */ + calculate_basic_ir(wm, msg + 2); - break; - } - case WM_RPT_BTN_ACC_IR_EXP: - { - /* button - motion - ir - expansion */ - wiiuse_pressed_buttons(wm, msg); + break; + } + case WM_RPT_BTN_ACC_IR_EXP: { + /* button - motion - ir - expansion */ + wiiuse_pressed_buttons(wm, msg); - handle_wm_accel(wm, msg); + handle_wm_accel(wm, msg); - handle_expansion(wm, msg+15); + handle_expansion(wm, msg + 15); - /* ir */ - calculate_basic_ir(wm, msg+5); + /* ir */ + calculate_basic_ir(wm, msg + 5); - break; - } - case WM_RPT_WRITE: - { - event_data_write(wm,msg); - break; - } - default: - { - WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event); - return; - } + break; + } + case WM_RPT_WRITE: { + event_data_write(wm, msg); + break; + } + default: { + WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event); + return; + } } /* was there an event? */ - if (state_changed(wm)) + if (state_changed(wm)) { wm->event = WIIUSE_EVENT; + } } @@ -334,8 +324,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) { wiiuse_pressed_buttons(wm, msg); /* find the next non-dirty request */ - while (req && req->dirty) + while (req && req->dirty) { req = req->next; + } /* if we don't have a request out then we didn't ask for this packet */ if (!req) { @@ -345,12 +336,13 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) { err = msg[2] & 0x0F; - if (err == 0x08) + if (err == 0x08) { WIIUSE_WARNING("Unable to read data - address does not exist."); - else if (err == 0x07) + } else if (err == 0x07) { WIIUSE_WARNING("Unable to read data - address is for write-only registers."); - else if (err) + } else if (err) { WIIUSE_WARNING("Unable to read data - unknown error code %x.", err); + } if (err) { /* this request errored out, so skip it and go to the next one */ @@ -360,8 +352,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) { free(req); /* if another request exists send it to the wiimote */ - if (wm->read_req) + if (wm->read_req) { wiiuse_send_next_pending_read_request(wm); + } return; } @@ -373,7 +366,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) { req->wait -= len; if (req->wait >= req->size) /* this should never happen */ + { req->wait = 0; + } WIIUSE_DEBUG("Received read packet:"); WIIUSE_DEBUG(" Packet read offset: %i bytes", offset); @@ -385,15 +380,16 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) { /* reconstruct this part of the data */ memcpy((req->buf + offset - req->addr), (msg + 5), len); - #ifdef WITH_WIIUSE_DEBUG +#ifdef WITH_WIIUSE_DEBUG { int i = 0; printf("Read: "); - for (; i < req->size - req->wait; ++i) + for (; i < req->size - req->wait; ++i) { printf("%x ", req->buf[i]); + } printf("\n"); } - #endif +#endif /* if all data has been received, execute the read event callback or generate event */ if (!req->wait) { @@ -417,25 +413,25 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) { } /* if another request exists send it to the wiimote */ - if (wm->read_req) + if (wm->read_req) { wiiuse_send_next_pending_read_request(wm); + } } } -static void event_data_write(struct wiimote_t *wm, byte *msg) -{ +static void event_data_write(struct wiimote_t *wm, byte *msg) { struct data_req_t* req = wm->data_req; - wiiuse_pressed_buttons(wm,msg); + wiiuse_pressed_buttons(wm, msg); /* if we don't have a request out then we didn't ask for this packet */ if (!req) { WIIUSE_WARNING("Transmitting data packet when no request was made."); return; } - if(!(req->state==REQ_SENT)) { + if (!(req->state == REQ_SENT)) { WIIUSE_WARNING("Transmission is not necessary"); /* delete this request */ wm->data_req = req->next; @@ -446,23 +442,23 @@ static void event_data_write(struct wiimote_t *wm, byte *msg) req->state = REQ_DONE; - if(req->cb) { + if (req->cb) { /* this was a callback, so invoke it now */ - req->cb(wm,NULL,0); + req->cb(wm, NULL, 0); /* delete this request */ wm->data_req = req->next; free(req); } else { - /* - * This should generate an event. - * We need to leave the event in the array so the client - * can access it still. We'll flag is as being 'REQ_DONE' - * and give the client one cycle to use it. Next event - * we will remove it from the list. - */ - wm->event = WIIUSE_WRITE_DATA; + /* + * This should generate an event. + * We need to leave the event in the array so the client + * can access it still. We'll flag is as being 'REQ_DONE' + * and give the client one cycle to use it. Next event + * we will remove it from the list. + */ + wm->event = WIIUSE_WRITE_DATA; - } + } /* if another request exists send it to the wiimote */ if (wm->data_req) { wiiuse_send_next_pending_write_request(wm); @@ -485,8 +481,9 @@ static void event_status(struct wiimote_t* wm, byte* msg) { struct data_req_t* req = wm->data_req; /* initial handshake is not finished yet, ignore this */ - if(WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE)) { return; + } /* * An event occurred. @@ -498,29 +495,39 @@ static void event_status(struct wiimote_t* wm, byte* msg) { wiiuse_pressed_buttons(wm, msg); /* find what LEDs are lit */ - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1; - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1; - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1; - if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1; + if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) { + led[0] = 1; + } + if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) { + led[1] = 1; + } + if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) { + led[2] = 1; + } + if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) { + led[3] = 1; + } /* probe for Motion+ */ - if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT)) + if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT)) { wiiuse_probe_motion_plus(wm); + } /* is an attachment connected to the expansion port? */ - if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) - { + if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) { WIIUSE_DEBUG("Attachment detected!"); attachment = 1; } /* is the speaker enabled? */ - if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) + if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) { WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER); + } /* is IR sensing enabled? */ - if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED) + if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED) { ir = 1; + } /* find the battery level and normalize between 0 and 1 */ wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE); @@ -536,20 +543,19 @@ static void event_status(struct wiimote_t* wm, byte* msg) { exp_changed = 1; } - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 if (!attachment) { WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout); wm->timeout = wm->normal_timeout; } - #endif +#endif /* * From now on the remote will only send status packets. * We need to send a WIIMOTE_CMD_REPORT_TYPE packet to * reenable other incoming reports. */ - if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) - { + if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { /* * Since the expansion status changed IR needs to * be reset for the new IR report mode. @@ -562,8 +568,12 @@ static void event_status(struct wiimote_t* wm, byte* msg) { } /* handling new Tx for changed exp */ - if(!req) return; - if(!(req->state==REQ_SENT)) return; + if (!req) { + return; + } + if (!(req->state == REQ_SENT)) { + return; + } wm->data_req = req->next; req->state = REQ_DONE; /* if(req->cb!=NULL) req->cb(wm,msg,6); */ @@ -623,8 +633,8 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { int gotIt = 0; WIIUSE_DEBUG("handshake_expansion with state %d", wm->expansion_state); - switch(wm->expansion_state) { - /* These two initialization writes disable the encryption */ + switch (wm->expansion_state) { + /* These two initialization writes disable the encryption */ case 0: wm->expansion_state = 1; /* increase the timeout until the handshake completes */ @@ -648,22 +658,23 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { case 2: wm->expansion_state = 3; /* get the calibration data */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { disable_expansion(wm); + } handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); /* tell the wiimote to send expansion data */ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); break; case 3: - if(!data || !len) { + if (!data || !len) { WIIUSE_DEBUG("no handshake data received from expansion"); disable_expansion(wm); return; } wm->expansion_state = 0; id = from_big_endian_uint32_t(data + 220); - switch(id) { + switch (id) { case EXP_ID_CODE_NUNCHUK: if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len)) { wm->event = WIIUSE_NUNCHUK_INSERTED; @@ -693,12 +704,12 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { gotIt = 1; break; - case EXP_ID_CODE_WII_BOARD: - if(wii_board_handshake(wm, &wm->exp.wb, data, len)) { + case EXP_ID_CODE_WII_BOARD: + if (wii_board_handshake(wm, &wm->exp.wb, data, len)) { wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED; gotIt = 1; } - break; + break; default: WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id); @@ -706,8 +717,8 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { } free(data); if (gotIt) { - WIIMOTE_DISABLE_STATE(wm,WIIMOTE_STATE_EXP_HANDSHAKE); - WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_EXP); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); } else { WIIUSE_WARNING("Could not handshake with expansion id: 0x%x", id); } @@ -731,8 +742,9 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { */ void disable_expansion(struct wiimote_t* wm) { WIIUSE_DEBUG("Disabling expansion"); - if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) + if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { return; + } /* tell the associated module the expansion was removed */ switch (wm->exp.type) { @@ -819,31 +831,29 @@ static void save_state(struct wiimote_t* wm) { case EXP_MOTION_PLUS: case EXP_MOTION_PLUS_CLASSIC: - case EXP_MOTION_PLUS_NUNCHUK: - { - wm->lstate.drx = wm->exp.mp.raw_gyro.pitch; - wm->lstate.dry = wm->exp.mp.raw_gyro.roll; - wm->lstate.drz = wm->exp.mp.raw_gyro.yaw; + case EXP_MOTION_PLUS_NUNCHUK: { + wm->lstate.drx = wm->exp.mp.raw_gyro.pitch; + wm->lstate.dry = wm->exp.mp.raw_gyro.roll; + wm->lstate.drz = wm->exp.mp.raw_gyro.yaw; - if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC) - { - wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang; - wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag; - wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang; - wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag; - wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder; - wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder; - wm->lstate.exp_btns = wm->exp.classic.btns; - } else { - wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang; - wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag; - wm->lstate.exp_btns = wm->exp.nunchuk.btns; - wm->lstate.exp_accel = wm->exp.nunchuk.accel; + if (wm->exp.type == EXP_MOTION_PLUS_CLASSIC) { + wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang; + wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag; + wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang; + wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag; + wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder; + wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder; + wm->lstate.exp_btns = wm->exp.classic.btns; + } else { + wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang; + wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag; + wm->lstate.exp_btns = wm->exp.nunchuk.btns; + wm->lstate.exp_accel = wm->exp.nunchuk.accel; + } + + break; } - break; - } - case EXP_NONE: break; } @@ -856,9 +866,9 @@ static void save_state(struct wiimote_t* wm) { * @return 1 if a significant change occurred, 0 if not. */ static int state_changed(struct wiimote_t* wm) { - #define STATE_CHANGED(a, b) if (a != b) return 1 +#define STATE_CHANGED(a, b) if (a != b) return 1 - #define CROSS_THRESH(last, now, thresh) \ +#define CROSS_THRESH(last, now, thresh) \ do { \ if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \ if ((diff_f(last.roll, now.roll) >= thresh) || \ @@ -875,7 +885,7 @@ static int state_changed(struct wiimote_t* wm) { } \ } while (0) - #define CROSS_THRESH_XYZ(last, now, thresh) \ +#define CROSS_THRESH_XYZ(last, now, thresh) \ do { \ if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \ if ((diff_f(last.x, now.x) >= thresh) || \ @@ -910,54 +920,16 @@ static int state_changed(struct wiimote_t* wm) { /* expansion */ switch (wm->exp.type) { - case EXP_NUNCHUK: - { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns); + case EXP_NUNCHUK: { + STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang); + STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag); + STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns); - CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold); - CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold); - break; - } - case EXP_CLASSIC: - { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag); - STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang); - STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag); - STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder); - STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns); - break; - } - case EXP_GUITAR_HERO_3: - { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag); - STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns); - break; - } - case EXP_WII_BOARD: - { - STATE_CHANGED(wm->lstate.exp_wb_rtr,wm->exp.wb.tr); - STATE_CHANGED(wm->lstate.exp_wb_rtl,wm->exp.wb.tl); - STATE_CHANGED(wm->lstate.exp_wb_rbr,wm->exp.wb.br); - STATE_CHANGED(wm->lstate.exp_wb_rbl,wm->exp.wb.bl); - break; - } - - case EXP_MOTION_PLUS: - case EXP_MOTION_PLUS_CLASSIC: - case EXP_MOTION_PLUS_NUNCHUK: - { - STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.pitch); - STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.roll); - STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw); - - if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC) - { + CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold); + CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold); + break; + } + case EXP_CLASSIC: { STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang); STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag); STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang); @@ -965,21 +937,52 @@ static int state_changed(struct wiimote_t* wm) { STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder); STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder); STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns); - } else { - STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang); - STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag); - STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns); - - CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold); - CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold); + break; + } + case EXP_GUITAR_HERO_3: { + STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang); + STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag); + STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar); + STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns); + break; + } + case EXP_WII_BOARD: { + STATE_CHANGED(wm->lstate.exp_wb_rtr, wm->exp.wb.tr); + STATE_CHANGED(wm->lstate.exp_wb_rtl, wm->exp.wb.tl); + STATE_CHANGED(wm->lstate.exp_wb_rbr, wm->exp.wb.br); + STATE_CHANGED(wm->lstate.exp_wb_rbl, wm->exp.wb.bl); + break; } - break; - } - case EXP_NONE: - { - break; - } + case EXP_MOTION_PLUS: + case EXP_MOTION_PLUS_CLASSIC: + case EXP_MOTION_PLUS_NUNCHUK: { + STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.pitch); + STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.roll); + STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw); + + if (wm->exp.type == EXP_MOTION_PLUS_CLASSIC) { + STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang); + STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag); + STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang); + STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag); + STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder); + STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder); + STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns); + } else { + STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang); + STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag); + STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns); + + CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold); + CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold); + } + + break; + } + case EXP_NONE: { + break; + } } STATE_CHANGED(wm->lstate.btns, wm->btns); diff --git a/src/guitar_hero_3.c b/src/guitar_hero_3.c index 296cb43..5bdc58a 100644 --- a/src/guitar_hero_3.c +++ b/src/guitar_hero_3.c @@ -86,8 +86,9 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); return 0; - } else + } else { data += 16; + } } /* joystick stuff */ @@ -101,9 +102,9 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b /* handshake done */ wm->exp.type = EXP_GUITAR_HERO_3; - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif +#endif return 1; } diff --git a/src/guitar_hero_3.h b/src/guitar_hero_3.h index e9d3e95..b8ffa07 100644 --- a/src/guitar_hero_3.h +++ b/src/guitar_hero_3.h @@ -50,14 +50,14 @@ extern "C" { #endif -/** @defgroup internal_gh3 Internal: Guitar Hero 3 controller */ -/** @{ */ -int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len); + /** @defgroup internal_gh3 Internal: Guitar Hero 3 controller */ + /** @{ */ + int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len); -void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3); + void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3); -void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg); -/** @} */ + void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg); + /** @} */ #ifdef __cplusplus } diff --git a/src/io.c b/src/io.c index 82e9af7..e94064f 100644 --- a/src/io.c +++ b/src/io.c @@ -62,7 +62,7 @@ * This function is declared in wiiuse.h */ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { - return wiiuse_os_find(wm, max_wiimotes, timeout); + return wiiuse_os_find(wm, max_wiimotes, timeout); } /** @@ -87,7 +87,7 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { * This function is declared in wiiuse.h */ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { - return wiiuse_os_connect(wm, wiimotes); + return wiiuse_os_connect(wm, wiimotes); } /** @@ -106,10 +106,10 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) { * This function is declared in wiiuse.h */ void wiiuse_disconnect(struct wiimote_t* wm) { - wiiuse_os_disconnect(wm); + wiiuse_os_disconnect(wm); } - /** +/** * @brief Wait until specified report arrives and return it * * @param wm Pointer to a wiimote_t structure. @@ -120,12 +120,10 @@ void wiiuse_disconnect(struct wiimote_t* wm) { * report from the Wiimote. * */ -void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) -{ - for(;;) - { - if(wiiuse_os_read(wm, buffer, bufferLength) > 0) { - if(buffer[0] == report) { +void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) { + for (;;) { + if (wiiuse_os_read(wm, buffer, bufferLength) > 0) { + if (buffer[0] == report) { break; } else { WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[0], report); @@ -147,8 +145,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buff * amount of data from the Wiimote. * */ -void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) -{ +void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) { byte pkt[6]; byte buf[MAX_PAYLOAD]; unsigned n_full_reports; @@ -164,10 +161,10 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns /* read from registers or memory */ pkt[0] = (memory != 0) ? 0x00 : 0x04; - + /* length in big endian */ to_big_endian_uint16_t(pkt + 4, size); - + /* send */ wiiuse_send(wm, WM_CMD_READ_DATA, pkt, sizeof(pkt)); @@ -176,16 +173,14 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns last_report = size % 16; output = data; - for(i = 0; i < n_full_reports; ++i) - { + for (i = 0; i < n_full_reports; ++i) { wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD); memmove(output, buf + 6, 16); output += 16; } /* read the last incomplete packet */ - if(last_report) - { + if (last_report) { wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD); memmove(output, buf + 6, last_report); } @@ -207,8 +202,7 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns #ifdef WIIUSE_SYNC_HANDSHAKE -void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) -{ +void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { /* send request to wiimote for accelerometer calibration */ byte buf[MAX_PAYLOAD]; @@ -254,118 +248,113 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); /* now enable IR if it was set before the handshake completed */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) - { - WIIUSE_DEBUG("Handshake finished, enabling IR."); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); - wiiuse_set_ir(wm, 1); - } + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { + WIIUSE_DEBUG("Handshake finished, enabling IR."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); + wiiuse_set_ir(wm, 1); + } - WIIUSE_DEBUG("Asking for status ...\n"); - wm->event = WIIUSE_CONNECT; - wiiuse_status(wm); + WIIUSE_DEBUG("Asking for status ...\n"); + wm->event = WIIUSE_CONNECT; + wiiuse_status(wm); } } #else -static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned short len); -static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len); +static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len); +static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len); void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { - if (!wm) return; + if (!wm) { + return; + } switch (wm->handshake_state) { - case 0: - { - byte* buf; + case 0: { + byte* buf; - /* continous reporting off, report to buttons only */ - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); - wiiuse_set_leds(wm, WIIMOTE_LED_NONE); + /* continous reporting off, report to buttons only */ + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); + wiiuse_set_leds(wm, WIIMOTE_LED_NONE); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE); - WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS); - - wiiuse_set_report_type(wm); - - /* send request to wiimote for accelerometer calibration */ - buf = (byte*)malloc(sizeof(byte) * 8); - wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7); - wm->handshake_state++; - - wiiuse_set_leds(wm, WIIMOTE_LED_NONE); - - break; - } - - case 1: - { - struct read_req_t* req = wm->read_req; - struct accel_t* accel = &wm->accel_calib; - byte val; - - /* received read data */ - accel->cal_zero.x = req->buf[0]; - accel->cal_zero.y = req->buf[1]; - accel->cal_zero.z = req->buf[2]; - - accel->cal_g.x = req->buf[4] - accel->cal_zero.x; - accel->cal_g.y = req->buf[5] - accel->cal_zero.y; - accel->cal_g.z = req->buf[6] - accel->cal_zero.z; - - /* done with the buffer */ - free(req->buf); - - /* handshake is done */ - WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x", - accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z, - accel->cal_g.x, accel->cal_g.y, accel->cal_g.z); - - /* M+ off */ - val = 0x55; - wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus1); - - break; - } - - case 2: - { - /* request the status of the wiimote to check for any expansion */ - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); - wm->handshake_state++; - - /* now enable IR if it was set before the handshake completed */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { - WIIUSE_DEBUG("Handshake finished, enabling IR."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); - wiiuse_set_ir(wm, 1); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE); + WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS); + + wiiuse_set_report_type(wm); + + /* send request to wiimote for accelerometer calibration */ + buf = (byte*)malloc(sizeof(byte) * 8); + wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7); + wm->handshake_state++; + + wiiuse_set_leds(wm, WIIMOTE_LED_NONE); + + break; } - wm->event = WIIUSE_CONNECT; - wiiuse_status(wm); + case 1: { + struct read_req_t* req = wm->read_req; + struct accel_t* accel = &wm->accel_calib; + byte val; - break; - } + /* received read data */ + accel->cal_zero.x = req->buf[0]; + accel->cal_zero.y = req->buf[1]; + accel->cal_zero.z = req->buf[2]; - default: - { - break; - } + accel->cal_g.x = req->buf[4] - accel->cal_zero.x; + accel->cal_g.y = req->buf[5] - accel->cal_zero.y; + accel->cal_g.z = req->buf[6] - accel->cal_zero.z; + + /* done with the buffer */ + free(req->buf); + + /* handshake is done */ + WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x", + accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z, + accel->cal_g.x, accel->cal_g.y, accel->cal_g.z); + + /* M+ off */ + val = 0x55; + wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus1); + + break; + } + + case 2: { + /* request the status of the wiimote to check for any expansion */ + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); + wm->handshake_state++; + + /* now enable IR if it was set before the handshake completed */ + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { + WIIUSE_DEBUG("Handshake finished, enabling IR."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); + wiiuse_set_ir(wm, 1); + } + + wm->event = WIIUSE_CONNECT; + wiiuse_status(wm); + + break; + } + + default: { + break; + } } } -static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned short len) -{ +static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len) { byte val = 0x00; wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2); } -static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len) -{ +static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); wiiuse_set_ir_mode(wm); diff --git a/src/io.h b/src/io.h index 9dd1da8..0149cb0 100644 --- a/src/io.h +++ b/src/io.h @@ -40,13 +40,13 @@ extern "C" { #endif -/** @defgroup internal_io Internal: Device I/O */ -/** @{ */ -void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len); + /** @defgroup internal_io Internal: Device I/O */ + /** @{ */ + void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len); -void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength); -void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data); -/** @} */ + void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength); + void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data); + /** @} */ #ifdef __cplusplus } diff --git a/src/ir.c b/src/ir.c index f7e833a..25137fb 100644 --- a/src/ir.c +++ b/src/ir.c @@ -57,16 +57,22 @@ static const byte WM_IR_BLOCK2_LEVEL4[] = "\x35\x03"; static const byte WM_IR_BLOCK1_LEVEL5[] = "\x07\x00\x00\x71\x01\x00\x72\x00\x20"; static const byte WM_IR_BLOCK2_LEVEL5[] = "\x1f\x03"; -void wiiuse_set_ir_mode(struct wiimote_t *wm) -{ +void wiiuse_set_ir_mode(struct wiimote_t *wm) { byte buf = 0x00; - if(!wm) return; - if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return; + if (!wm) { + return; + } + if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { + return; + } - if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP)) buf = WM_IR_TYPE_BASIC; - else buf = WM_IR_TYPE_EXTENDED; - wiiuse_write_data(wm,WM_REG_IR_MODENUM, &buf, 1); + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { + buf = WM_IR_TYPE_BASIC; + } else { + buf = WM_IR_TYPE_EXTENDED; + } + wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1); } /** * @brief Set if the wiimote should track IR targets. @@ -80,8 +86,9 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) { const byte* block2 = NULL; int ir_level; - if (!wm) + if (!wm) { return; + } /* * Wait for the handshake to finish first. @@ -90,7 +97,7 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) { * again to actually enable IR. */ if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE)) { - if(status) { + if (status) { WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes."); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR); } /* else ignoring request to turn off, since it's turned off by default */ @@ -108,13 +115,15 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) { if (status) { /* if already enabled then stop */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { return; + } WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR); } else { /* if already disabled then stop */ - if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) + if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { return; + } WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR); } @@ -141,10 +150,11 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) { wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2); /* set the IR mode */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { buf = WM_IR_TYPE_BASIC; - else + } else { buf = WM_IR_TYPE_EXTENDED; + } wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1); wiiuse_millisleep(50); @@ -201,10 +211,12 @@ static int get_ir_sens(struct wiimote_t* wm, const byte** block1, const byte** b * @param status 1 to enable, 0 to disable. */ void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) { - if (!wm) return; + if (!wm) { + return; + } - wm->ir.vres[0] = (x-1); - wm->ir.vres[1] = (y-1); + wm->ir.vres[0] = (x - 1); + wm->ir.vres[1] = (y - 1); } @@ -214,7 +226,9 @@ void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) { * @param wm Pointer to a wiimote_t structure. */ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) { - if (!wm) return; + if (!wm) { + return; + } wm->ir.pos = pos; @@ -223,20 +237,22 @@ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) { case WIIUSE_IR_ABOVE: wm->ir.offset[0] = 0; - if (wm->ir.aspect == WIIUSE_ASPECT_16_9) - wm->ir.offset[1] = WM_ASPECT_16_9_Y/2 - 70; - else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) - wm->ir.offset[1] = WM_ASPECT_4_3_Y/2 - 100; + if (wm->ir.aspect == WIIUSE_ASPECT_16_9) { + wm->ir.offset[1] = WM_ASPECT_16_9_Y / 2 - 70; + } else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) { + wm->ir.offset[1] = WM_ASPECT_4_3_Y / 2 - 100; + } return; case WIIUSE_IR_BELOW: wm->ir.offset[0] = 0; - if (wm->ir.aspect == WIIUSE_ASPECT_16_9) - wm->ir.offset[1] = -WM_ASPECT_16_9_Y/2 + 100; - else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) - wm->ir.offset[1] = -WM_ASPECT_4_3_Y/2 + 70; + if (wm->ir.aspect == WIIUSE_ASPECT_16_9) { + wm->ir.offset[1] = -WM_ASPECT_16_9_Y / 2 + 100; + } else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) { + wm->ir.offset[1] = -WM_ASPECT_4_3_Y / 2 + 70; + } return; @@ -253,7 +269,9 @@ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) { * @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3 */ void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) { - if (!wm) return; + if (!wm) { + return; + } wm->ir.aspect = aspect; @@ -283,16 +301,22 @@ void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) { const byte* block1 = NULL; const byte* block2 = NULL; - if (!wm) return; + if (!wm) { + return; + } - if (level > 5) level = 5; - if (level < 1) level = 1; + if (level > 5) { + level = 5; + } + if (level < 1) { + level = 1; + } WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 | - WIIMOTE_STATE_IR_SENS_LVL2 | - WIIMOTE_STATE_IR_SENS_LVL3 | - WIIMOTE_STATE_IR_SENS_LVL4 | - WIIMOTE_STATE_IR_SENS_LVL5)); + WIIMOTE_STATE_IR_SENS_LVL2 | + WIIMOTE_STATE_IR_SENS_LVL3 | + WIIMOTE_STATE_IR_SENS_LVL4 | + WIIMOTE_STATE_IR_SENS_LVL5)); switch (level) { case 1: @@ -348,9 +372,9 @@ void calculate_basic_ir(struct wiimote_t* wm, byte* data) { /* set each IR spot to visible if spot is in range */ for (i = 0; i < 4; ++i) { - if (dot[i].ry == 1023) + if (dot[i].ry == 1023) { dot[i].visible = 0; - else { + } else { dot[i].visible = 1; dot[i].size = 0; /* since we don't know the size, set it as 0 */ } @@ -371,16 +395,17 @@ void calculate_extended_ir(struct wiimote_t* wm, byte* data) { int i; for (i = 0; i < 4; ++i) { - dot[i].rx = 1023 - (data[3*i] | ((data[(3*i)+2] & 0x30) << 4)); - dot[i].ry = data[(3*i)+1] | ((data[(3*i)+2] & 0xC0) << 2); + dot[i].rx = 1023 - (data[3 * i] | ((data[(3 * i) + 2] & 0x30) << 4)); + dot[i].ry = data[(3 * i) + 1] | ((data[(3 * i) + 2] & 0xC0) << 2); - dot[i].size = data[(3*i)+2] & 0x0F; + dot[i].size = data[(3 * i) + 2] & 0x0F; /* if in range set to visible */ - if (dot[i].ry == 1023) + if (dot[i].ry == 1023) { dot[i].visible = 0; - else + } else { dot[i].visible = 1; + } } interpret_ir_data(wm); @@ -398,147 +423,150 @@ static void interpret_ir_data(struct wiimote_t* wm) { float roll = 0.0f; int last_num_dots = wm->ir.num_dots; - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC)) { roll = wm->orient.roll; + } /* count visible dots */ wm->ir.num_dots = 0; for (i = 0; i < 4; ++i) { - if (dot[i].visible) + if (dot[i].visible) { wm->ir.num_dots++; + } } switch (wm->ir.num_dots) { - case 0: - { - wm->ir.state = 0; + case 0: { + wm->ir.state = 0; - /* reset the dot ordering */ - for (i = 0; i < 4; ++i) - dot[i].order = 0; - - wm->ir.x = 0; - wm->ir.y = 0; - wm->ir.z = 0.0f; - - return; - } - case 1: - { - fix_rotated_ir_dots(wm->ir.dot, roll); - - if (wm->ir.state < 2) { - /* - * Only 1 known dot, so use just that. - */ + /* reset the dot ordering */ for (i = 0; i < 4; ++i) { - if (dot[i].visible) { - wm->ir.x = dot[i].x; - wm->ir.y = dot[i].y; - - wm->ir.ax = wm->ir.x; - wm->ir.ay = wm->ir.y; - - /* can't calculate yaw because we don't have the distance */ - /* wm->orient.yaw = calc_yaw(&wm->ir); */ - - ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); - break; - } + dot[i].order = 0; } - } else { - /* - * Only see 1 dot but know theres 2. - * Try to estimate where the other one - * should be and use that. - */ - for (i = 0; i < 4; ++i) { - if (dot[i].visible) { - int ox = 0; - int x, y; - if (dot[i].order == 1) - /* visible is the left dot - estimate where the right is */ - ox = (int32_t)(dot[i].x + wm->ir.distance); - else if (dot[i].order == 2) - /* visible is the right dot - estimate where the left is */ - ox = (int32_t)(dot[i].x - wm->ir.distance); - - x = ((signed int)dot[i].x + ox) / 2; - y = dot[i].y; - - wm->ir.ax = x; - wm->ir.ay = y; - wm->orient.yaw = calc_yaw(&wm->ir); - - if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) { - ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); - wm->ir.x = x; - wm->ir.y = y; - } - - break; - } - } - } - - break; - } - case 2: - case 3: - case 4: - { - /* - * Two (or more) dots known and seen. - * Average them together to estimate the true location. - */ - int x, y; - wm->ir.state = 2; - - fix_rotated_ir_dots(wm->ir.dot, roll); - - /* if there is at least 1 new dot, reorder them all */ - if (wm->ir.num_dots > last_num_dots) { - reorder_ir_dots(dot); wm->ir.x = 0; wm->ir.y = 0; + wm->ir.z = 0.0f; + + return; } + case 1: { + fix_rotated_ir_dots(wm->ir.dot, roll); - wm->ir.distance = ir_distance(dot); - wm->ir.z = 1023 - wm->ir.distance; + if (wm->ir.state < 2) { + /* + * Only 1 known dot, so use just that. + */ + for (i = 0; i < 4; ++i) { + if (dot[i].visible) { + wm->ir.x = dot[i].x; + wm->ir.y = dot[i].y; - get_ir_dot_avg(wm->ir.dot, &x, &y); + wm->ir.ax = wm->ir.x; + wm->ir.ay = wm->ir.y; - wm->ir.ax = x; - wm->ir.ay = y; - wm->orient.yaw = calc_yaw(&wm->ir); + /* can't calculate yaw because we don't have the distance */ + /* wm->orient.yaw = calc_yaw(&wm->ir); */ - if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) { - ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); - wm->ir.x = x; - wm->ir.y = y; + ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); + break; + } + } + } else { + /* + * Only see 1 dot but know theres 2. + * Try to estimate where the other one + * should be and use that. + */ + for (i = 0; i < 4; ++i) { + if (dot[i].visible) { + int ox = 0; + int x, y; + + if (dot[i].order == 1) + /* visible is the left dot - estimate where the right is */ + { + ox = (int32_t)(dot[i].x + wm->ir.distance); + } else if (dot[i].order == 2) + /* visible is the right dot - estimate where the left is */ + { + ox = (int32_t)(dot[i].x - wm->ir.distance); + } + + x = ((signed int)dot[i].x + ox) / 2; + y = dot[i].y; + + wm->ir.ax = x; + wm->ir.ay = y; + wm->orient.yaw = calc_yaw(&wm->ir); + + if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) { + ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); + wm->ir.x = x; + wm->ir.y = y; + } + + break; + } + } + } + + break; } + case 2: + case 3: + case 4: { + /* + * Two (or more) dots known and seen. + * Average them together to estimate the true location. + */ + int x, y; + wm->ir.state = 2; - break; - } - default: - { - break; - } + fix_rotated_ir_dots(wm->ir.dot, roll); + + /* if there is at least 1 new dot, reorder them all */ + if (wm->ir.num_dots > last_num_dots) { + reorder_ir_dots(dot); + wm->ir.x = 0; + wm->ir.y = 0; + } + + wm->ir.distance = ir_distance(dot); + wm->ir.z = 1023 - wm->ir.distance; + + get_ir_dot_avg(wm->ir.dot, &x, &y); + + wm->ir.ax = x; + wm->ir.ay = y; + wm->orient.yaw = calc_yaw(&wm->ir); + + if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) { + ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]); + wm->ir.x = x; + wm->ir.y = y; + } + + break; + } + default: { + break; + } } - #ifdef WITH_WIIUSE_DEBUG +#ifdef WITH_WIIUSE_DEBUG { - int ir_level; - WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level); - WIIUSE_DEBUG("IR sensitivity: %i", ir_level); - WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots); - for (i = 0; i < 4; ++i) - if (dot[i].visible) - WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y); - WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y); + int ir_level; + WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level); + WIIUSE_DEBUG("IR sensitivity: %i", ir_level); + WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots); + for (i = 0; i < 4; ++i) + if (dot[i].visible) { + WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y); + } + WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y); } - #endif +#endif } @@ -579,17 +607,18 @@ static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) { */ for (i = 0; i < 4; ++i) { - if (!dot[i].visible) + if (!dot[i].visible) { continue; + } - x = dot[i].rx - (1024/2); - y = dot[i].ry - (768/2); + x = dot[i].rx - (1024 / 2); + y = dot[i].ry - (768 / 2); dot[i].x = (uint32_t)((c * x) + (-s * y)); dot[i].y = (uint32_t)((s * x) + (c * y)); - dot[i].x += (1024/2); - dot[i].y += (768/2); + dot[i].x += (1024 / 2); + dot[i].y += (768 / 2); } } @@ -629,19 +658,22 @@ static void reorder_ir_dots(struct ir_dot_t* dot) { int i, j, order; /* reset the dot ordering */ - for (i = 0; i < 4; ++i) + for (i = 0; i < 4; ++i) { dot[i].order = 0; + } for (order = 1; order < 5; ++order) { i = 0; for (; !dot[i].visible || dot[i].order; ++i) - if (i >= 3) - return; + if (i >= 3) { + return; + } for (j = 0; j < 4; ++j) { - if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x)) + if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x)) { i = j; + } } dot[i].order = order; @@ -659,21 +691,25 @@ static float ir_distance(struct ir_dot_t* dot) { int xd, yd; for (i1 = 0; i1 < 4; ++i1) - if (dot[i1].visible) + if (dot[i1].visible) { break; - if (i1 == 4) + } + if (i1 == 4) { return 0.0f; + } - for (i2 = i1+1; i2 < 4; ++i2) - if (dot[i2].visible) + for (i2 = i1 + 1; i2 < 4; ++i2) + if (dot[i2].visible) { break; - if (i2 == 4) + } + if (i2 == 4) { return 0.0f; + } xd = dot[i2].x - dot[i1].x; yd = dot[i2].y - dot[i1].y; - return sqrtf(xd*xd + yd*yd); + return sqrtf(xd * xd + yd * yd); } @@ -707,10 +743,9 @@ static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offse y0 = ((768 - ys) / 2) + offset_y; if ((*x >= x0) - && (*x <= (x0 + xs)) - && (*y >= y0) - && (*y <= (y0 + ys))) - { + && (*x <= (x0 + xs)) + && (*y >= y0) + && (*y <= (y0 + ys))) { *x -= offset_x; *y -= offset_y; @@ -735,8 +770,8 @@ static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int ys = WM_ASPECT_4_3_Y; } - *x -= ((1024-xs)/2); - *y -= ((768-ys)/2); + *x -= ((1024 - xs) / 2); + *y -= ((768 - ys) / 2); *x = (int)((*x / (float)xs) * vx); *y = (int)((*y / (float)ys) * vy); @@ -754,5 +789,5 @@ float calc_yaw(struct ir_t* ir) { x = (float)(ir->ax - 512); x = x * (ir->z / 1024.0f); - return RAD_TO_DEGREE( atanf(x / ir->z) ); + return RAD_TO_DEGREE(atanf(x / ir->z)); } diff --git a/src/ir.h b/src/ir.h index 03e982a..7e3dbc5 100644 --- a/src/ir.h +++ b/src/ir.h @@ -44,13 +44,13 @@ extern "C" { #endif -/** @defgroup internal_ir Internal: IR Sensor */ -/** @{ */ -void wiiuse_set_ir_mode(struct wiimote_t *wm); -void calculate_basic_ir(struct wiimote_t* wm, byte* data); -void calculate_extended_ir(struct wiimote_t* wm, byte* data); -float calc_yaw(struct ir_t* ir); -/** @} */ + /** @defgroup internal_ir Internal: IR Sensor */ + /** @{ */ + void wiiuse_set_ir_mode(struct wiimote_t *wm); + void calculate_basic_ir(struct wiimote_t* wm, byte* data); + void calculate_extended_ir(struct wiimote_t* wm, byte* data); + float calc_yaw(struct ir_t* ir); + /** @} */ #ifdef __cplusplus } diff --git a/src/motion_plus.c b/src/motion_plus.c index 84a3699..117832b 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -43,92 +43,83 @@ static void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp); static void calculate_gyro_rates(struct motion_plus_t* mp); -void wiiuse_probe_motion_plus(struct wiimote_t *wm) -{ - byte buf[MAX_PAYLOAD]; - unsigned id; +void wiiuse_probe_motion_plus(struct wiimote_t *wm) { + byte buf[MAX_PAYLOAD]; + unsigned id; - wiiuse_read_data_sync(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); + wiiuse_read_data_sync(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf); - /* check error code */ - if(buf[4] & 0x0f) - { - WIIUSE_DEBUG("No Motion+ available, stopping probe."); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); - return; - } + /* check error code */ + if (buf[4] & 0x0f) { + WIIUSE_DEBUG("No Motion+ available, stopping probe."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); + return; + } - /* decode the id */ - id = from_big_endian_uint32_t(buf + 2); + /* decode the id */ + id = from_big_endian_uint32_t(buf + 2); - if(id != EXP_ID_CODE_INACTIVE_MOTION_PLUS && - id != EXP_ID_CODE_NLA_MOTION_PLUS && - id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK && - id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC) - { - /* we have read something weird */ - WIIUSE_DEBUG("Motion+ ID doesn't match, probably not connected."); - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); - return; - } + if (id != EXP_ID_CODE_INACTIVE_MOTION_PLUS && + id != EXP_ID_CODE_NLA_MOTION_PLUS && + id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK && + id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC) { + /* we have read something weird */ + WIIUSE_DEBUG("Motion+ ID doesn't match, probably not connected."); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); + return; + } - WIIUSE_DEBUG("Detected inactive Motion+!"); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); + WIIUSE_DEBUG("Detected inactive Motion+!"); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT); - /* init M+ */ - buf[0] = 0x55; - wiiuse_write_data(wm, WM_EXP_MOTION_PLUS_INIT, buf, 1); + /* init M+ */ + buf[0] = 0x55; + wiiuse_write_data(wm, WM_EXP_MOTION_PLUS_INIT, buf, 1); - /* Init whatever is hanging on the pass-through port */ - buf[0] = 0x55; - wiiuse_write_data(wm, WM_EXP_MEM_ENABLE1, buf, 1); + /* Init whatever is hanging on the pass-through port */ + buf[0] = 0x55; + wiiuse_write_data(wm, WM_EXP_MEM_ENABLE1, buf, 1); - buf[0] = 0x00; - wiiuse_write_data(wm, WM_EXP_MEM_ENABLE2, buf, 1); + buf[0] = 0x00; + wiiuse_write_data(wm, WM_EXP_MEM_ENABLE2, buf, 1); - /* Init gyroscope data */ - wm->exp.mp.cal_gyro.roll = 0; - wm->exp.mp.cal_gyro.pitch = 0; - wm->exp.mp.cal_gyro.yaw = 0; - wm->exp.mp.orient.roll = 0.0; - wm->exp.mp.orient.pitch = 0.0; - wm->exp.mp.orient.yaw = 0.0; - wm->exp.mp.raw_gyro_threshold = 10; + /* Init gyroscope data */ + wm->exp.mp.cal_gyro.roll = 0; + wm->exp.mp.cal_gyro.pitch = 0; + wm->exp.mp.cal_gyro.yaw = 0; + wm->exp.mp.orient.roll = 0.0; + wm->exp.mp.orient.pitch = 0.0; + wm->exp.mp.orient.yaw = 0.0; + wm->exp.mp.raw_gyro_threshold = 10; - wm->exp.mp.nc = &(wm->exp.nunchuk); - wm->exp.mp.classic = &(wm->exp.classic); - wm->exp.nunchuk.flags = &wm->flags; + wm->exp.mp.nc = &(wm->exp.nunchuk); + wm->exp.mp.classic = &(wm->exp.classic); + wm->exp.nunchuk.flags = &wm->flags; - wm->exp.mp.ext = 0; + wm->exp.mp.ext = 0; - wiiuse_set_ir_mode(wm); - wiiuse_set_report_type(wm); + wiiuse_set_ir_mode(wm); + wiiuse_set_report_type(wm); } -void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short len) -{ +void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data, unsigned short len) { uint32_t val; - if(data == NULL) - { + if (data == NULL) { wiiuse_read_data_cb(wm, wiiuse_motion_plus_handshake, wm->motion_plus_id, WM_EXP_ID, 6); - } - else - { + } else { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); /* tell wiimote to include exp. data in reports */ val = from_big_endian_uint32_t(data + 2); - if(val == EXP_ID_CODE_MOTION_PLUS || - val == EXP_ID_CODE_MOTION_PLUS_NUNCHUK || - val == EXP_ID_CODE_MOTION_PLUS_CLASSIC) - { + if (val == EXP_ID_CODE_MOTION_PLUS || + val == EXP_ID_CODE_MOTION_PLUS_NUNCHUK || + val == EXP_ID_CODE_MOTION_PLUS_CLASSIC) { /* handshake done */ wm->event = WIIUSE_MOTION_PLUS_ACTIVATED; - switch(val) - { + switch (val) { case EXP_ID_CODE_MOTION_PLUS: wm->exp.type = EXP_MOTION_PLUS; break; @@ -171,16 +162,14 @@ void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short } } -static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm,byte *data,unsigned short len) -{ +static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm, byte *data, unsigned short len) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); wiiuse_set_ir_mode(wm); wiiuse_status(wm); } -static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,byte *data,unsigned short len) -{ +static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm, byte *data, unsigned short len) { byte val = 0x00; wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear2); } @@ -188,40 +177,35 @@ static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,byte *data,unsign /** * @brief Enable/disable Motion+ expansion * - * @param wm Pointer to the wiimote with Motion+ + * @param wm Pointer to the wiimote with Motion+ * @param status 0 - off, 1 - on, standalone, 2 - nunchuk pass-through * */ -void wiiuse_set_motion_plus(struct wiimote_t *wm, int status) -{ +void wiiuse_set_motion_plus(struct wiimote_t *wm, int status) { byte val; - if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT) || - WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) - return; + if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT) || + WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) { + return; + } - if(status) - { + if (status) { WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); val = (status == 1) ? 0x04 : 0x05; wiiuse_write_data_cb(wm, WM_EXP_MOTION_PLUS_ENABLE, &val, 1, wiiuse_motion_plus_handshake); - } - else - { + } else { disable_expansion(wm); val = 0x55; wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear1); } } -void motion_plus_disconnected(struct motion_plus_t* mp) -{ +void motion_plus_disconnected(struct motion_plus_t* mp) { WIIUSE_DEBUG("Motion plus disconnected"); memset(mp, 0, sizeof(struct motion_plus_t)); } -void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) -{ +void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) { /* * Pass-through modes interleave data from the gyro * with the expansion data. This extracts the tag @@ -230,8 +214,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) int isMPFrame = (1 << 1) & msg[5]; mp->ext = msg[4] & 0x1; /* extension attached to pass-through port? */ - if (mp->ext == 0 || isMPFrame) /* reading gyro frame */ - { + if (mp->ext == 0 || isMPFrame) { /* reading gyro frame */ /* Check if the gyroscope is in fast or slow mode (0 if rotating fast, 1 if slow or still) */ mp->acc_mode = ((msg[4] & 0x2) << 1) | ((msg[3] & 0x1) << 1) | ((msg[3] & 0x2) >> 1); @@ -241,15 +224,14 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) /* First calibration */ if ((mp->raw_gyro.roll > 5000) && - (mp->raw_gyro.pitch > 5000) && - (mp->raw_gyro.yaw > 5000) && - (mp->raw_gyro.roll < 0x3fff) && - (mp->raw_gyro.pitch < 0x3fff) && - (mp->raw_gyro.yaw < 0x3fff) && - !(mp->cal_gyro.roll) && - !(mp->cal_gyro.pitch) && - !(mp->cal_gyro.yaw)) - { + (mp->raw_gyro.pitch > 5000) && + (mp->raw_gyro.yaw > 5000) && + (mp->raw_gyro.roll < 0x3fff) && + (mp->raw_gyro.pitch < 0x3fff) && + (mp->raw_gyro.yaw < 0x3fff) && + !(mp->cal_gyro.roll) && + !(mp->cal_gyro.pitch) && + !(mp->cal_gyro.yaw)) { wiiuse_calibrate_motion_plus(mp); } @@ -257,11 +239,9 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) calculate_gyro_rates(mp); } - else - { + else { /* expansion frame */ - if (exp_type == EXP_MOTION_PLUS_NUNCHUK) - { + if (exp_type == EXP_MOTION_PLUS_NUNCHUK) { /* ok, this is nunchuck, re-encode it as regular nunchuck packet */ /* get button states */ @@ -276,23 +256,21 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) mp->nc->accel.z = (msg[4] & 0xFE) | ((msg[5] >> 5) & 0x04); calculate_orientation(&(mp->nc->accel_calib), - &(mp->nc->accel), - &(mp->nc->orient), - NUNCHUK_IS_FLAG_SET(mp->nc, WIIUSE_SMOOTHING)); + &(mp->nc->accel), + &(mp->nc->orient), + NUNCHUK_IS_FLAG_SET(mp->nc, WIIUSE_SMOOTHING)); calculate_gforce(&(mp->nc->accel_calib), - &(mp->nc->accel), - &(mp->nc->gforce)); + &(mp->nc->accel), + &(mp->nc->gforce)); } - else if (exp_type == EXP_MOTION_PLUS_CLASSIC) - { + else if (exp_type == EXP_MOTION_PLUS_CLASSIC) { WIIUSE_ERROR("Classic controller pass-through is not implemented!\n"); } - else - { + else { WIIUSE_ERROR("Unsupported mode passed to motion_plus_event() !\n"); } } @@ -306,8 +284,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) * This should be called only after receiving the first values * from the Motion Plus. */ -void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp) -{ +void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp) { mp->cal_gyro.roll = mp->raw_gyro.roll; mp->cal_gyro.pitch = mp->raw_gyro.pitch; mp->cal_gyro.yaw = mp->raw_gyro.yaw; @@ -316,8 +293,7 @@ void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp) mp->orient.yaw = 0.0; } -static void calculate_gyro_rates(struct motion_plus_t* mp) -{ +static void calculate_gyro_rates(struct motion_plus_t* mp) { short int tmp_r, tmp_p, tmp_y; float tmp_roll, tmp_pitch, tmp_yaw; @@ -327,28 +303,34 @@ static void calculate_gyro_rates(struct motion_plus_t* mp) tmp_y = mp->raw_gyro.yaw - mp->cal_gyro.yaw; /* We convert to degree/sec according to fast/slow mode */ - if (mp->acc_mode & 0x04) + if (mp->acc_mode & 0x04) { tmp_roll = (float)tmp_r / 20.0f; - else + } else { tmp_roll = (float)tmp_r / 4.0f; + } - if (mp->acc_mode & 0x02) + if (mp->acc_mode & 0x02) { tmp_pitch = (float)tmp_p / 20.0f; - else + } else { tmp_pitch = (float)tmp_p / 4.0f; + } - if (mp->acc_mode & 0x01) + if (mp->acc_mode & 0x01) { tmp_yaw = (float)tmp_y / 20.0f; - else + } else { tmp_yaw = (float)tmp_y / 4.0f; + } /* Simple filtering */ - if (fabs(tmp_roll) < 0.5f) + if (fabs(tmp_roll) < 0.5f) { tmp_roll = 0.0f; - if (fabs(tmp_pitch) < 0.5f) + } + if (fabs(tmp_pitch) < 0.5f) { tmp_pitch = 0.0f; - if (fabs(tmp_yaw) < 0.5f) + } + if (fabs(tmp_yaw) < 0.5f) { tmp_yaw = 0.0f; + } mp->angle_rate_gyro.roll = tmp_roll; mp->angle_rate_gyro.pitch = tmp_pitch; diff --git a/src/motion_plus.h b/src/motion_plus.h index b0c0401..5aa7534 100644 --- a/src/motion_plus.h +++ b/src/motion_plus.h @@ -27,10 +27,10 @@ * $Header$ * */ - /** - * @file - * @brief Motion plus extension - */ +/** +* @file +* @brief Motion plus extension +*/ #ifndef MOTION_PLUS_H_INCLUDED #define MOTION_PLUS_H_INCLUDED @@ -41,17 +41,17 @@ extern "C" { #endif -/** @defgroup internal_mp Internal: MotionPlus */ -/** @{ */ -void motion_plus_disconnected(struct motion_plus_t* mp); + /** @defgroup internal_mp Internal: MotionPlus */ + /** @{ */ + void motion_plus_disconnected(struct motion_plus_t* mp); -void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg); + void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg); -void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data,unsigned short len); + void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data, unsigned short len); -void wiiuse_probe_motion_plus(struct wiimote_t *wm); + void wiiuse_probe_motion_plus(struct wiimote_t *wm); -/** @} */ + /** @} */ #ifdef __cplusplus } diff --git a/src/nunchuk.c b/src/nunchuk.c index d34b668..12ec0aa 100644 --- a/src/nunchuk.c +++ b/src/nunchuk.c @@ -77,8 +77,9 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); return 0; - } else + } else { data += 16; + } } nc->accel_calib.cal_zero.x = data[0]; @@ -94,8 +95,8 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un nc->js.min.y = data[12]; nc->js.center.y = data[13]; WIIUSE_DEBUG("Nunchuk calibration X: min %x, max %x, center %x Y: min %x, max %x, center %x", - nc->js.min.x, nc->js.max.x, nc->js.center.x, - nc->js.min.y, nc->js.max.y, nc->js.center.y); + nc->js.min.x, nc->js.max.x, nc->js.center.x, + nc->js.min.y, nc->js.max.y, nc->js.center.y); /* default the thresholds to the same as the wiimote */ nc->orient_threshold = wm->orient_threshold; @@ -104,9 +105,9 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un /* handshake done */ wm->exp.type = EXP_NUNCHUK; - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif +#endif return 1; } @@ -177,7 +178,9 @@ void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) { * See wiiuse_set_orient_threshold() for details. */ void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) { - if (!wm) return; + if (!wm) { + return; + } wm->exp.nunchuk.orient_threshold = threshold; } @@ -192,7 +195,9 @@ void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) * See wiiuse_set_orient_threshold() for details. */ void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) { - if (!wm) return; + if (!wm) { + return; + } wm->exp.nunchuk.accel_threshold = threshold; } diff --git a/src/nunchuk.h b/src/nunchuk.h index 951749d..289a546 100644 --- a/src/nunchuk.h +++ b/src/nunchuk.h @@ -41,16 +41,16 @@ extern "C" { #endif -/** @defgroup internal_nunchuk Internal: Nunchuk */ -/** @{ */ -int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len); + /** @defgroup internal_nunchuk Internal: Nunchuk */ + /** @{ */ + int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len); -void nunchuk_disconnected(struct nunchuk_t* nc); + void nunchuk_disconnected(struct nunchuk_t* nc); -void nunchuk_event(struct nunchuk_t* nc, byte* msg); + void nunchuk_event(struct nunchuk_t* nc, byte* msg); -void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now); -/** @} */ + void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now); + /** @} */ #ifdef __cplusplus } diff --git a/src/os.h b/src/os.h index a1b6b60..e77ebf9 100644 --- a/src/os.h +++ b/src/os.h @@ -41,21 +41,21 @@ extern "C" { #endif -/** @defgroup internal_io Internal: Platform-specific Device I/O */ -/** @{ */ -void wiiuse_init_platform_fields(struct wiimote_t* wm); -void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); + /** @defgroup internal_io Internal: Platform-specific Device I/O */ + /** @{ */ + void wiiuse_init_platform_fields(struct wiimote_t* wm); + void wiiuse_cleanup_platform_fields(struct wiimote_t* wm); -int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout); + int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout); -int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes); -void wiiuse_os_disconnect(struct wiimote_t* wm); + int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes); + void wiiuse_os_disconnect(struct wiimote_t* wm); -int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes); -/* buf[0] will be the report type, buf+1 the rest of the report */ -int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len); -int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len); -/** @} */ + int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes); + /* buf[0] will be the report type, buf+1 the rest of the report */ + int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len); + int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len); + /** @} */ #ifdef __cplusplus } diff --git a/src/os_nix.c b/src/os_nix.c index 4df8a27..ffacf94 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -99,9 +99,8 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { /* display discovered devices */ for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) { if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) && - (scan_info[i].dev_class[1] == WM_DEV_CLASS_1) && - (scan_info[i].dev_class[2] == WM_DEV_CLASS_2)) - { + (scan_info[i].dev_class[1] == WM_DEV_CLASS_1) && + (scan_info[i].dev_class[2] == WM_DEV_CLASS_2)) { /* found a device */ ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str); @@ -129,10 +128,13 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { for (; i < wiimotes; ++i) { if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND)) /* if the device address is not set, skip it */ + { continue; + } - if (wiiuse_os_connect_single(wm[i], NULL)) + if (wiiuse_os_connect_single(wm[i], NULL)) { ++connected; + } } return connected; @@ -150,18 +152,19 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { */ static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) { struct sockaddr_l2 addr; - memset(&addr, 0, sizeof (addr)); + memset(&addr, 0, sizeof(addr)); - if (!wm || WIIMOTE_IS_CONNECTED(wm)) + if (!wm || WIIMOTE_IS_CONNECTED(wm)) { return 0; + } addr.l2_family = AF_BLUETOOTH; bdaddr_t *bdaddr = &wm->bdaddr; if (address) /* use provided address */ - str2ba(address, &addr.l2_bdaddr); - else { + str2ba(address, &addr.l2_bdaddr); + } else { /** @todo this line doesn't make sense bacmp(bdaddr, BDADDR_ANY);*/ /* use address of device discovered */ @@ -173,8 +176,9 @@ static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) { * OUTPUT CHANNEL */ wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); - if (wm->out_sock == -1) + if (wm->out_sock == -1) { return 0; + } addr.l2_psm = htobs(WM_OUTPUT_CHANNEL); @@ -216,8 +220,9 @@ static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) { } void wiiuse_os_disconnect(struct wiimote_t* wm) { - if (!wm || WIIMOTE_IS_CONNECTED(wm)) + if (!wm || WIIMOTE_IS_CONNECTED(wm)) { return; + } close(wm->out_sock); close(wm->in_sock); @@ -241,7 +246,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int highest_fd = -1; evnt = 0; - if (!wm) return 0; + if (!wm) { + return 0; + } /* block select() for 1/2000th of a second */ tv.tv_sec = 0; @@ -255,8 +262,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { FD_SET(wm[i]->in_sock, &fds); /* find the highest fd of the connected wiimotes */ - if (wm[i]->in_sock > highest_fd) + if (wm[i]->in_sock > highest_fd) { highest_fd = wm[i]->in_sock; + } } wm[i]->event = WIIUSE_NONE; @@ -264,7 +272,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { if (highest_fd == -1) /* nothing to poll */ + { return 0; + } if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) { WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s)."); @@ -275,8 +285,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { /* check each socket for an event */ for (i = 0; i < wiimotes; ++i) { /* if this wiimote is not connected, skip it */ - if (!WIIMOTE_IS_CONNECTED(wm[i])) + if (!WIIMOTE_IS_CONNECTED(wm[i])) { continue; + } if (FD_ISSET(wm[i]->in_sock, &fds)) { /* clear out the event buffer */ @@ -289,7 +300,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { r = wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer)); if (r > 0) { /* propagate the event */ - propagate_event(wm[i], read_buffer[0], read_buffer+1); + propagate_event(wm[i], read_buffer[0], read_buffer + 1); evnt += (wm[i]->event != WIIUSE_NONE); } } else { @@ -319,20 +330,20 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { wiiuse_os_disconnect(wm); wiiuse_disconnected(wm); } - } else if(rc == 0) { + } else if (rc == 0) { /* remote disconnect */ wiiuse_disconnected(wm); } else { /* read successful */ /* on *nix we ignore the first byte */ - memmove(buf, buf+1, len-1); + memmove(buf, buf + 1, len - 1); /* log the received data */ #ifdef WITH_WIIUSE_DEBUG { int i; printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); - for(i = 1; i < rc; i++) { + for (i = 1; i < rc; i++) { printf("%.2x ", buf[i]); } printf("\n"); @@ -349,11 +360,12 @@ int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) write_buffer[0] = WM_SET_REPORT | WM_BT_OUTPUT; write_buffer[1] = report_type; - memcpy(write_buffer+2, buf, len); - rc = write(wm->out_sock, write_buffer, len+2); + memcpy(write_buffer + 2, buf, len); + rc = write(wm->out_sock, write_buffer, len + 2); - if(rc < 0) + if (rc < 0) { wiiuse_disconnected(wm); + } return rc; } diff --git a/src/os_win.c b/src/os_win.c index b8d7f90..c0f0010 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -84,8 +84,9 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { } /* query the next hid device info */ - if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data)) + if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data)) { break; + } /* get the size of the data block required */ i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL); @@ -93,16 +94,18 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); /* query the data for this device */ - if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL)) + if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL)) { continue; + } /* open the device */ dev = CreateFile(detail_data->DevicePath, - (GENERIC_READ | GENERIC_WRITE), - (FILE_SHARE_READ | FILE_SHARE_WRITE), - NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (dev == INVALID_HANDLE_VALUE) + (GENERIC_READ | GENERIC_WRITE), + (FILE_SHARE_READ | FILE_SHARE_WRITE), + NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + if (dev == INVALID_HANDLE_VALUE) { continue; + } /* get device attributes */ attr.Size = sizeof(attr); @@ -131,16 +134,18 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid); ++found; - if (found >= max_wiimotes) + if (found >= max_wiimotes) { break; + } } else { /* not a wiimote */ CloseHandle(dev); } } - if (detail_data) + if (detail_data) { free(detail_data); + } SetupDiDestroyDeviceInfoList(device_info); @@ -153,10 +158,12 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { int i = 0; for (; i < wiimotes; ++i) { - if (!wm[i]) + if (!wm[i]) { continue; - if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) + } + if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) { ++connected; + } } return connected; @@ -164,8 +171,9 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) { void wiiuse_os_disconnect(struct wiimote_t* wm) { - if (!wm || WIIMOTE_IS_CONNECTED(wm)) + if (!wm || WIIMOTE_IS_CONNECTED(wm)) { return; + } CloseHandle(wm->dev_handle); wm->dev_handle = 0; @@ -184,7 +192,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { byte read_buffer[MAX_PAYLOAD]; int evnt = 0; - if (!wm) return 0; + if (!wm) { + return 0; + } for (i = 0; i < wiimotes; ++i) { wm[i]->event = WIIUSE_NONE; @@ -194,7 +204,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { /* read */ if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) { /* propagate the event */ - propagate_event(wm[i], read_buffer[0], read_buffer+1); + propagate_event(wm[i], read_buffer[0], read_buffer + 1); evnt += (wm[i]->event != WIIUSE_NONE); } else { /* send out any waiting writes */ @@ -209,8 +219,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { DWORD b, r; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return 0; + } if (!ReadFile(wm->dev_handle, buf, len, &b, &wm->hid_overlap)) { /* partial read */ @@ -226,8 +237,9 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { if (r == WAIT_TIMEOUT) { /* timeout - cancel and continue */ - if (*buf) + if (*buf) { WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout); + } CancelIo(wm->dev_handle); ResetEvent(wm->hid_overlap.hEvent); @@ -237,15 +249,16 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { return 0; } - if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) + if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) { return 0; + } /* log the received data */ #ifdef WITH_WIIUSE_DEBUG { DWORD i; printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); - for(i = 1; i < b; i++) { + for (i = 1; i < b; i++) { printf("%.2x ", buf[i]); } printf("\n"); @@ -263,33 +276,33 @@ int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) int i; byte write_buffer[MAX_PAYLOAD]; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return 0; + } write_buffer[0] = report_type; - memcpy(write_buffer+1, buf, len); + memcpy(write_buffer + 1, buf, len); switch (wm->stack) { - case WIIUSE_STACK_UNKNOWN: - { - /* try to auto-detect the stack type */ - if (i = WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap)) { - /* bluesoleil will always return 1 here, even if it's not connected */ - wm->stack = WIIUSE_STACK_BLUESOLEIL; - return i; - } + case WIIUSE_STACK_UNKNOWN: { + /* try to auto-detect the stack type */ + if (i = WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap)) { + /* bluesoleil will always return 1 here, even if it's not connected */ + wm->stack = WIIUSE_STACK_BLUESOLEIL; + return i; + } - if (i = HidD_SetOutputReport(wm->dev_handle, write_buffer, len+1)) { - wm->stack = WIIUSE_STACK_MS; - return i; - } + if (i = HidD_SetOutputReport(wm->dev_handle, write_buffer, len + 1)) { + wm->stack = WIIUSE_STACK_MS; + return i; + } - WIIUSE_ERROR("Unable to determine bluetooth stack type."); - return 0; - } + WIIUSE_ERROR("Unable to determine bluetooth stack type."); + return 0; + } case WIIUSE_STACK_MS: - return HidD_SetOutputReport(wm->dev_handle, write_buffer, len+1); + return HidD_SetOutputReport(wm->dev_handle, write_buffer, len + 1); case WIIUSE_STACK_BLUESOLEIL: return WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap); diff --git a/src/wiiboard.c b/src/wiiboard.c index 275745b..8c4f9f0 100644 --- a/src/wiiboard.c +++ b/src/wiiboard.c @@ -53,14 +53,13 @@ int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data #ifdef WITH_WIIUSE_DEBUG int i; printf("DECRYPTED DATA WIIBOARD\n"); - for (i = 0; i < len; ++i) - { - if(i%16==0) - { - if(i!=0) + for (i = 0; i < len; ++i) { + if (i % 16 == 0) { + if (i != 0) { printf("\n"); + } - printf("%X: ",0x4a40000+32+i); + printf("%X: ", 0x4a40000 + 32 + i); } printf("%02X ", data[i]); } @@ -87,9 +86,9 @@ int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED; wm->exp.type = EXP_WII_BOARD; - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 wm->timeout = WIIMOTE_DEFAULT_TIMEOUT; - #endif +#endif return 1; } @@ -109,9 +108,9 @@ static float do_interpolate(uint16_t raw, uint16_t cal[3]) { if (raw < cal[0]) { return 0.0f; } else if (raw < cal[1]) { - return ((float)(raw-cal[0]) * WIIBOARD_MIDDLE_CALIB)/(float)(cal[1] - cal[0]); + return ((float)(raw - cal[0]) * WIIBOARD_MIDDLE_CALIB) / (float)(cal[1] - cal[0]); } else if (raw < cal[2]) { - return ((float)(raw-cal[1]) * WIIBOARD_MIDDLE_CALIB)/(float)(cal[2] - cal[1]) + WIIBOARD_MIDDLE_CALIB; + return ((float)(raw - cal[1]) * WIIBOARD_MIDDLE_CALIB) / (float)(cal[2] - cal[1]) + WIIBOARD_MIDDLE_CALIB; } else { return WIIBOARD_MIDDLE_CALIB * 2.0f; } @@ -143,6 +142,5 @@ void wii_board_event(struct wii_board_t* wb, byte* msg) { /** @todo not implemented! */ -void wiiuse_set_wii_board_calib(struct wiimote_t *wm) -{ +void wiiuse_set_wii_board_calib(struct wiimote_t *wm) { } diff --git a/src/wiiboard.h b/src/wiiboard.h index 0b175e2..e0d7616 100644 --- a/src/wiiboard.h +++ b/src/wiiboard.h @@ -40,14 +40,14 @@ extern "C" { #endif -/** @defgroup internal_wiiboard Internal: Wii Balance Board */ -/** @{ */ -int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, uint16_t len); + /** @defgroup internal_wiiboard Internal: Wii Balance Board */ + /** @{ */ + int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, uint16_t len); -void wii_board_disconnected(struct wii_board_t* wb); + void wii_board_disconnected(struct wii_board_t* wb); -void wii_board_event(struct wii_board_t* wb, byte* msg); -/** @} */ + void wii_board_event(struct wii_board_t* wb, byte* msg); + /** @} */ #ifdef __cplusplus } #endif diff --git a/src/wiiuse.c b/src/wiiuse.c index 839f0b6..5aa5b2d 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -67,8 +67,7 @@ FILE* logtarget[4]; * * The default FILE* for all loglevels is stderr */ -void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile) -{ +void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile) { logtarget[(int)loglevel] = logfile; } @@ -78,8 +77,9 @@ void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile) void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) { int i = 0; - if (!wm) + if (!wm) { return; + } WIIUSE_INFO("wiiuse clean up..."); @@ -120,9 +120,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) { * to call this function again it won't be intrusive. */ if (!g_banner) { - printf( "wiiuse v" WIIUSE_VERSION " loaded.\n" - " Fork at http://github.com/rpavlik/wiiuse\n" - " Original By: Michael Laforest http://wiiuse.net\n"); + printf("wiiuse v" WIIUSE_VERSION " loaded.\n" + " Fork at http://github.com/rpavlik/wiiuse\n" + " Original By: Michael Laforest http://wiiuse.net\n"); g_banner = 1; } @@ -131,8 +131,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) { logtarget[2] = stderr; logtarget[3] = stderr; - if (!wiimotes) + if (!wiimotes) { return NULL; + } wm = malloc(sizeof(struct wiimote_t*) * wiimotes); @@ -140,7 +141,7 @@ struct wiimote_t** wiiuse_init(int wiimotes) { wm[i] = malloc(sizeof(struct wiimote_t)); memset(wm[i], 0, sizeof(struct wiimote_t)); - wm[i]->unid = i+1; + wm[i]->unid = i + 1; wiiuse_init_platform_fields(wm[i]); wm[i]->state = WIIMOTE_INIT_STATES; @@ -170,7 +171,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) { * @param wm Pointer to a wiimote_t structure. */ void wiiuse_disconnected(struct wiimote_t* wm) { - if (!wm) return; + if (!wm) { + return; + } WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid); @@ -201,8 +204,9 @@ void wiiuse_disconnected(struct wiimote_t* wm) { void wiiuse_rumble(struct wiimote_t* wm, int status) { byte buf; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return; + } /* make sure to keep the current lit leds */ buf = wm->leds; @@ -218,8 +222,9 @@ void wiiuse_rumble(struct wiimote_t* wm, int status) { } /* preserve IR state */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) { buf |= 0x04; + } wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1); } @@ -231,7 +236,9 @@ void wiiuse_rumble(struct wiimote_t* wm, int status) { * @param wm Pointer to a wiimote_t structure. */ void wiiuse_toggle_rumble(struct wiimote_t* wm) { - if (!wm) return; + if (!wm) { + return; + } wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)); } @@ -248,15 +255,17 @@ void wiiuse_toggle_rumble(struct wiimote_t* wm) { void wiiuse_set_leds(struct wiimote_t* wm, int leds) { byte buf; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return; + } /* remove the lower 4 bits because they control rumble */ wm->leds = (leds & 0xF0); /* make sure if the rumble is on that we keep it on */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) { wm->leds |= 0x01; + } buf = wm->leds; @@ -275,10 +284,11 @@ void wiiuse_set_leds(struct wiimote_t* wm, int leds) { * by default. */ void wiiuse_motion_sensing(struct wiimote_t* wm, int status) { - if (status) + if (status) { WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC); - else + } else { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC); + } wiiuse_set_report_type(wm); } @@ -300,34 +310,46 @@ int wiiuse_set_report_type(struct wiimote_t* wm) { byte buf[2]; int motion, exp, ir; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return 0; + } buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */ buf[1] = 0x00; /* if rumble is enabled, make sure we keep it */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) { buf[0] |= 0x01; + } motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC); exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP); ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR); - if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP; - else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP; - else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR; - else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP; - else if (ir) buf[1] = WM_RPT_BTN_ACC_IR; - else if (exp) buf[1] = WM_RPT_BTN_EXP; - else if (motion) buf[1] = WM_RPT_BTN_ACC; - else buf[1] = WM_RPT_BTN; + if (motion && ir && exp) { + buf[1] = WM_RPT_BTN_ACC_IR_EXP; + } else if (motion && exp) { + buf[1] = WM_RPT_BTN_ACC_EXP; + } else if (motion && ir) { + buf[1] = WM_RPT_BTN_ACC_IR; + } else if (ir && exp) { + buf[1] = WM_RPT_BTN_IR_EXP; + } else if (ir) { + buf[1] = WM_RPT_BTN_ACC_IR; + } else if (exp) { + buf[1] = WM_RPT_BTN_EXP; + } else if (motion) { + buf[1] = WM_RPT_BTN_ACC; + } else { + buf[1] = WM_RPT_BTN; + } WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]); exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2); - if (exp <= 0) + if (exp <= 0) { return exp; + } return buf[1]; } @@ -353,15 +375,18 @@ int wiiuse_set_report_type(struct wiimote_t* wm) { int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, uint16_t len) { struct read_req_t* req; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return 0; - if (!buffer || !len) + } + if (!buffer || !len) { return 0; + } /* make this request structure */ req = (struct read_req_t*)malloc(sizeof(struct read_req_t)); - if (req == NULL) + if (req == NULL) { return 0; + } req->cb = read_cb; req->buf = buffer; req->addr = addr; @@ -381,7 +406,9 @@ int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buff wiiuse_send_next_pending_read_request(wm); } else { struct read_req_t* nptr = wm->read_req; - for (; nptr->next; nptr = nptr->next); + for (; nptr->next; nptr = nptr->next) { + ; + } nptr->next = req; WIIUSE_DEBUG("Added pending data read request."); @@ -425,16 +452,21 @@ void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) { byte buf[6]; struct read_req_t* req; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return; - if (!wm->read_req) return; + } + if (!wm->read_req) { + return; + } /* skip over dirty ones since they have already been read */ req = wm->read_req; - while (req && req->dirty) + while (req && req->dirty) { req = req->next; - if (!req) + } + if (!req) { return; + } /* the offset is in big endian */ to_big_endian_uint32_t(buf, req->addr); @@ -457,8 +489,9 @@ void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) { void wiiuse_status(struct wiimote_t* wm) { byte buf = 0; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return; + } WIIUSE_DEBUG("Requested wiimote status."); @@ -477,14 +510,17 @@ void wiiuse_status(struct wiimote_t* wm) { */ struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) { int i = 0; - if (!wm) + if (!wm) { return NULL; + } for (; i < wiimotes; ++i) { - if (!wm[i]) + if (!wm[i]) { continue; - if (wm[i]->unid == unid) + } + if (wm[i]->unid == unid) { return wm[i]; + } } return NULL; @@ -503,22 +539,25 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data, byte buf[21] = {0}; /* the payload is always 23 */ byte * bufPtr = buf; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return 0; - if (!data || !len) + } + if (!data || !len) { return 0; + } WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr); - #ifdef WITH_WIIUSE_DEBUG +#ifdef WITH_WIIUSE_DEBUG { int i = 0; printf("Write data is: "); - for (; i < len; ++i) + for (; i < len; ++i) { printf("%x ", data[i]); + } printf("\n"); } - #endif +#endif /* the offset is in big endian */ buffer_big_endian_uint32_t(&bufPtr, (uint32_t)addr); @@ -549,17 +588,20 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data, * to a pending list and be sent out when the previous * finishes. */ -int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb) -{ +int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb) { struct data_req_t* req; - if(!wm || !WIIMOTE_IS_CONNECTED(wm)) return 0; - if( !data || !len ) return 0; + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { + return 0; + } + if (!data || !len) { + return 0; + } req = (struct data_req_t*)malloc(sizeof(struct data_req_t)); req->cb = write_cb; req->len = len; - memcpy(req->data,data,req->len); + memcpy(req->data, data, req->len); req->state = REQ_READY; req->addr = addr;/* BIG_ENDIAN_LONG(addr); */ req->next = NULL; @@ -574,8 +616,10 @@ int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, by wiiuse_send_next_pending_write_request(wm); } else { struct data_req_t* nptr = wm->data_req; -WIIUSE_DEBUG("chaud2fois"); - for (; nptr->next; nptr = nptr->next); + WIIUSE_DEBUG("chaud2fois"); + for (; nptr->next; nptr = nptr->next) { + ; + } nptr->next = req; WIIUSE_DEBUG("Added pending data write request."); @@ -596,14 +640,19 @@ WIIUSE_DEBUG("chaud2fois"); void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) { struct data_req_t* req; - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm)) { return; + } req = wm->data_req; - if (!req) + if (!req) { return; - if (!req->data || !req->len) + } + if (!req->data || !req->len) { return; - if(req->state!=REQ_READY) return; + } + if (req->state != REQ_READY) { + return; + } wiiuse_write_data(wm, req->addr, req->data, req->len); @@ -625,26 +674,27 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { switch (report_type) { case WM_CMD_LED: case WM_CMD_RUMBLE: - case WM_CMD_CTRL_STATUS: - { - /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */ - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) - msg[0] |= 0x01; - break; - } + case WM_CMD_CTRL_STATUS: { + /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */ + if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) { + msg[0] |= 0x01; + } + break; + } default: break; } - #ifdef WITH_WIIUSE_DEBUG +#ifdef WITH_WIIUSE_DEBUG { int x; printf("[DEBUG] (id %i) SEND: (%.2x) %.2x ", wm->unid, report_type, msg[0]); - for (x = 1; x < len; ++x) + for (x = 1; x < len; ++x) { printf("%.2x ", msg[x]); + } printf("\n"); } - #endif +#endif return wiiuse_os_write(wm, report_type, msg, len); } @@ -663,7 +713,9 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { * Flags are defined in wiiuse.h. */ int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) { - if (!wm) return 0; + if (!wm) { + return 0; + } /* remove mutually exclusive flags */ enable &= ~disable; @@ -692,15 +744,18 @@ int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) { float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) { float old; - if (!wm) return 0.0f; + if (!wm) { + return 0.0f; + } old = wm->accel_calib.st_alpha; wm->accel_calib.st_alpha = alpha; /* if there is a nunchuk set that too */ - if (wm->exp.type == EXP_NUNCHUK) + if (wm->exp.type == EXP_NUNCHUK) { wm->exp.nunchuk.accel_calib.st_alpha = alpha; + } return old; } @@ -714,14 +769,17 @@ float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) { * @param type The type of bluetooth stack to use. */ void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type) { - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 int i; - if (!wm) return; + if (!wm) { + return; + } - for (i = 0; i < wiimotes; ++i) + for (i = 0; i < wiimotes; ++i) { wm[i]->stack = type; - #endif + } +#endif } @@ -736,7 +794,9 @@ void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt * the angle has to change by a full degree to generate an event. */ void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) { - if (!wm) return; + if (!wm) { + return; + } wm->orient_threshold = threshold; } @@ -749,7 +809,9 @@ void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) { * @param threshold The decimal place that should be considered a significant change. */ void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) { - if (!wm) return; + if (!wm) { + return; + } wm->accel_threshold = threshold; } @@ -761,7 +823,9 @@ void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) { * @param wm Pointer to a wiimote_t structure. */ void wiiuse_resync(struct wiimote_t* wm) { - if (!wm) return; + if (!wm) { + return; + } #ifndef WIIUSE_SYNC_HANDSHAKE wm->handshake_state = 0; @@ -779,14 +843,16 @@ void wiiuse_resync(struct wiimote_t* wm) { * @param exp_timeout The timeout in millisecondsd to wait for an expansion handshake. */ void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout) { - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 int i; - if (!wm) return; + if (!wm) { + return; + } for (i = 0; i < wiimotes; ++i) { wm[i]->normal_timeout = normal_timeout; wm[i]->exp_timeout = exp_timeout; } - #endif +#endif } diff --git a/src/wiiuse.h b/src/wiiuse.h index 84affea..0c108e2 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -363,7 +363,7 @@ struct read_req_t { * @brief Roll/Pitch/Yaw short angles. */ typedef struct ang3s_t { - int16_t roll, pitch, yaw; + int16_t roll, pitch, yaw; } ang3s_t; /** @@ -371,7 +371,7 @@ typedef struct ang3s_t { * @brief Roll/Pitch/Yaw float angles. */ typedef struct ang3f_t { - float roll, pitch, yaw; + float roll, pitch, yaw; } ang3f_t; /** @@ -566,9 +566,8 @@ typedef struct guitar_hero_3_t { /** * @brief Motion Plus expansion device */ -typedef struct motion_plus_t -{ - byte ext; /**< is there a device on the pass-through port? */ +typedef struct motion_plus_t { + byte ext; /**< is there a device on the pass-through port? */ struct ang3s_t raw_gyro; /**< current raw gyroscope data */ struct ang3s_t cal_gyro; /**< calibration raw gyroscope data */ @@ -577,7 +576,7 @@ typedef struct motion_plus_t byte acc_mode; /**< Fast/slow rotation mode for roll, pitch and yaw (0 if rotating fast, 1 if slow or still) */ int raw_gyro_threshold; /**< threshold for gyroscopes to generate an event */ - struct nunchuk_t *nc; /**< pointers to nunchuk & classic in pass-through-mode */ + struct nunchuk_t *nc; /**< pointers to nunchuk & classic in pass-through-mode */ struct classic_ctrl_t *classic; } motion_plus_t; @@ -718,34 +717,34 @@ typedef enum WIIUSE_EVENT_TYPE { typedef struct wiimote_t { WCONST int unid; /**< user specified id */ - #ifdef WIIUSE_BLUEZ +#ifdef WIIUSE_BLUEZ /** @name Linux-specific (BlueZ) members */ /** @{ */ - WCONST char bdaddr_str[18]; /**< readable bt address */ - WCONST bdaddr_t bdaddr; /**< bt address */ - WCONST int out_sock; /**< output socket */ - WCONST int in_sock; /**< input socket */ + WCONST char bdaddr_str[18]; /**< readable bt address */ + WCONST bdaddr_t bdaddr; /**< bt address */ + WCONST int out_sock; /**< output socket */ + WCONST int in_sock; /**< input socket */ /** @} */ - #endif +#endif - #ifdef WIIUSE_WIN32 +#ifdef WIIUSE_WIN32 /** @name Windows-specific members */ /** @{ */ - WCONST HANDLE dev_handle; /**< HID handle */ - WCONST OVERLAPPED hid_overlap; /**< overlap handle */ - WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */ - WCONST int timeout; /**< read timeout */ - WCONST byte normal_timeout; /**< normal timeout */ - WCONST byte exp_timeout; /**< timeout for expansion handshake */ + WCONST HANDLE dev_handle; /**< HID handle */ + WCONST OVERLAPPED hid_overlap; /**< overlap handle */ + WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */ + WCONST int timeout; /**< read timeout */ + WCONST byte normal_timeout; /**< normal timeout */ + WCONST byte exp_timeout; /**< timeout for expansion handshake */ /** @} */ - #endif - - #ifdef WIIUSE_MAC +#endif + +#ifdef WIIUSE_MAC /** @name Mac OS X-specific members */ /** @{ */ - WCONST void* objc_wm; /** WiiuseWiimote* as opaque pointer */ + WCONST void* objc_wm; /** WiiuseWiimote* as opaque pointer */ /** @} */ - #endif +#endif WCONST int state; /**< various state flags */ WCONST byte leds; /**< currently lit leds */ @@ -817,8 +816,7 @@ typedef void (*wiiuse_update_cb)(struct wiimote_callback_data_t* wm); */ typedef void (*wiiuse_write_cb)(struct wiimote_t* wm, unsigned char* data, unsigned short len); -typedef enum data_req_s -{ +typedef enum data_req_s { REQ_READY = 0, REQ_SENT, REQ_DONE @@ -877,69 +875,69 @@ typedef enum wiiuse_loglevel { extern "C" { #endif -/* wiiuse.c */ -WIIUSE_EXPORT extern const char* wiiuse_version(); + /* wiiuse.c */ + WIIUSE_EXPORT extern const char* wiiuse_version(); -/** @brief Define indicating the presence of the feature allowing you to - * redirect output for one or more logging levels within the library. - */ + /** @brief Define indicating the presence of the feature allowing you to + * redirect output for one or more logging levels within the library. + */ #define WIIUSE_HAS_OUTPUT_REDIRECTION -WIIUSE_EXPORT extern void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget); + WIIUSE_EXPORT extern void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget); -WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes); -WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes); -WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds); -WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, uint16_t len); -WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data, byte len); -WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm); -WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid); -WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable); -WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha); -WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type); -WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold); -WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); -WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout); -WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold); + WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes); + WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm); + WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes); + WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status); + WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm); + WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds); + WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status); + WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, uint16_t len); + WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data, byte len); + WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm); + WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid); + WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable); + WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha); + WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type); + WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold); + WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); + WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout); + WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold); -/* io.c */ -WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); -WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); -WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); + /* io.c */ + WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); + WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); + WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); -/* events.c */ -WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes); + /* events.c */ + WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes); -/** - * @brief Poll Wiimotes, and call the provided callback with information - * on each Wiimote that had an event. - * - * Alternative to calling wiiuse_poll yourself, and provides the same - * information struct on all platforms. - * - * @return Number of wiimotes that had an event. - */ -WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t** wm, int wiimotes, wiiuse_update_cb callback); + /** + * @brief Poll Wiimotes, and call the provided callback with information + * on each Wiimote that had an event. + * + * Alternative to calling wiiuse_poll yourself, and provides the same + * information struct on all platforms. + * + * @return Number of wiimotes that had an event. + */ + WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t** wm, int wiimotes, wiiuse_update_cb callback); -/* ir.c */ -WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status); -WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y); -WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos); -WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect); -WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level); + /* ir.c */ + WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status); + WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y); + WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos); + WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect); + WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level); -/* nunchuk.c */ -WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold); -WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold); + /* nunchuk.c */ + WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold); + WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold); -/* wiiboard.c */ -/* this function not currently implemented... */ -WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm); + /* wiiboard.c */ + /* this function not currently implemented... */ + WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm); -WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status); + WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status); #ifdef __cplusplus } diff --git a/src/wiiuse_internal.h b/src/wiiuse_internal.h index e4830c0..b484409 100644 --- a/src/wiiuse_internal.h +++ b/src/wiiuse_internal.h @@ -143,12 +143,12 @@ * not store them in such a way, rather it uses * the concept of major service, major class, * and minor class, that are respectivelly - * 11bit, 5bit, and 6bit long. Hence, the + * 11bit, 5bit, and 6bit long. Hence, the * numbers are different. * The Wiimote CoD Bluetooth division is the following: * 00000000001 00101 000001 00 (major service - major class - minor class - format type) * This can also be seen in the WiiC Linux way: - * 00000000 00100101 00000100 + * 00000000 00100101 00000100 */ #ifdef WIIUSE_MAC #define WM_DEV_MINOR_CLASS 0x01 @@ -280,121 +280,121 @@ extern "C" { #endif -/* not part of the api */ + /* not part of the api */ -/** @brief Cross-platform call to sleep for at least the specified number - * of milliseconds. - * - * Use instead of Sleep(), usleep(), or similar functions. - * Defined in util.c - */ -void wiiuse_millisleep(int durationMilliseconds); + /** @brief Cross-platform call to sleep for at least the specified number + * of milliseconds. + * + * Use instead of Sleep(), usleep(), or similar functions. + * Defined in util.c + */ + void wiiuse_millisleep(int durationMilliseconds); -int wiiuse_set_report_type(struct wiimote_t* wm); -void wiiuse_send_next_pending_read_request(struct wiimote_t* wm); -void wiiuse_send_next_pending_write_request(struct wiimote_t* wm); -int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len); -int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, uint16_t len); -int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte* data, byte len, wiiuse_write_cb write_cb); + int wiiuse_set_report_type(struct wiimote_t* wm); + void wiiuse_send_next_pending_read_request(struct wiimote_t* wm); + void wiiuse_send_next_pending_write_request(struct wiimote_t* wm); + int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len); + int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, uint16_t len); + int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte* data, byte len, wiiuse_write_cb write_cb); #ifdef WIIUSE_DOXYGEN_PARSING -/** @addtogroup betosystem Big-endian buffer to system-byte-order value - @{ */ + /** @addtogroup betosystem Big-endian buffer to system-byte-order value + @{ */ -/** @brief Given a buffer buf, copy and return a value of type uint8_t. -*/ -uint8_t from_big_endian_uint8_t(byte * buf); -/** @brief Given a buffer buf, copy out a uint16_t, convert it from big-endian - to system byte order, and return it. + /** @brief Given a buffer buf, copy and return a value of type uint8_t. + */ + uint8_t from_big_endian_uint8_t(byte * buf); + /** @brief Given a buffer buf, copy out a uint16_t, convert it from big-endian + to system byte order, and return it. - @note Requires that at least 2 bytes be available in buf, but does not - check this - it is your responsibility. -*/ -uint16_t from_big_endian_uint16_t(byte * buf); + @note Requires that at least 2 bytes be available in buf, but does not + check this - it is your responsibility. + */ + uint16_t from_big_endian_uint16_t(byte * buf); -/** @brief Given a buffer buf, copy out a uint32_t, convert it from big-endian - to system byte order, and return it. + /** @brief Given a buffer buf, copy out a uint32_t, convert it from big-endian + to system byte order, and return it. - @note Requires that at least 4 bytes be available in buf, but does not - check this - it is your responsibility. -*/ -uint32_t from_big_endian_uint32_t(byte * buf); -/** @} */ + @note Requires that at least 4 bytes be available in buf, but does not + check this - it is your responsibility. + */ + uint32_t from_big_endian_uint32_t(byte * buf); + /** @} */ -/** @addtogroup systemtobe System-byte-order value to big-endian buffer - @{ -*/ + /** @addtogroup systemtobe System-byte-order value to big-endian buffer + @{ + */ -/** @brief Copies the value val into the buffer buf. - @note Requires that at least 1 byte is available in buf, but does not - check this - it is your responsibility. -*/ -void to_big_endian_uint8_t(byte * buf, uint8_t val); + /** @brief Copies the value val into the buffer buf. + @note Requires that at least 1 byte is available in buf, but does not + check this - it is your responsibility. + */ + void to_big_endian_uint8_t(byte * buf, uint8_t val); -/** @brief Converts the value val from system byte order to big endian, - and copies it into the given buffer starting at buf. + /** @brief Converts the value val from system byte order to big endian, + and copies it into the given buffer starting at buf. - @note Requires that at least 2 bytes be available in buf, but does not - check this - it is your responsibility. -*/ -void to_big_endian_uint16_t(byte * buf, uint16_t val); + @note Requires that at least 2 bytes be available in buf, but does not + check this - it is your responsibility. + */ + void to_big_endian_uint16_t(byte * buf, uint16_t val); -/** @brief Converts the value val from system byte order to big endian, - and copies it into the given buffer starting at buf. + /** @brief Converts the value val from system byte order to big endian, + and copies it into the given buffer starting at buf. - @note Requires that at least 4 bytes be available in buf, but does not - check this - it is your responsibility. -*/ -void to_big_endian_uint32_t(byte * buf, uint32_t val); -/** @} -*/ + @note Requires that at least 4 bytes be available in buf, but does not + check this - it is your responsibility. + */ + void to_big_endian_uint32_t(byte * buf, uint32_t val); + /** @} + */ -/** @addtogroup bufferfunc Buffering functions - @brief These wrap around from/to_big_endian_TYPE, but take a byte** so that - they can advance the input/output pointer appropriately. - @{ -*/ -/** @brief Converts the value val from system byte order to big endian, - copies it into the given buffer starting at *buf, and advances buf by - sizeof(uint16_t). -*/ -void buffer_big_endian_uint16_t(byte ** buf, uint16_t val); + /** @addtogroup bufferfunc Buffering functions + @brief These wrap around from/to_big_endian_TYPE, but take a byte** so that + they can advance the input/output pointer appropriately. + @{ + */ + /** @brief Converts the value val from system byte order to big endian, + copies it into the given buffer starting at *buf, and advances buf by + sizeof(uint16_t). + */ + void buffer_big_endian_uint16_t(byte ** buf, uint16_t val); -/** @brief Given the address of a buffer pointer buf, copy out a uint16_t - from *buf, convert it from big-endian to system byte order, advance - buf by sizeof(uint16_t), and return the value retrieved. -*/ -uint16_t unbuffer_big_endian_uint16_t(byte ** buf); + /** @brief Given the address of a buffer pointer buf, copy out a uint16_t + from *buf, convert it from big-endian to system byte order, advance + buf by sizeof(uint16_t), and return the value retrieved. + */ + uint16_t unbuffer_big_endian_uint16_t(byte ** buf); -/** @sa buffer_big_endian_uint16_t() -*/ -void buffer_big_endian_uint8_t(byte ** buf, uint8_t val); + /** @sa buffer_big_endian_uint16_t() + */ + void buffer_big_endian_uint8_t(byte ** buf, uint8_t val); -/** @sa unbuffer_big_endian_uint8_t -*/ -uint8_t unbuffer_big_endian_uint8_t(byte ** buf); + /** @sa unbuffer_big_endian_uint8_t + */ + uint8_t unbuffer_big_endian_uint8_t(byte ** buf); -/** @sa buffer_big_endian_uint16_t -*/ -void buffer_big_endian_uint32_t(byte ** buf, uint32_t val); + /** @sa buffer_big_endian_uint16_t + */ + void buffer_big_endian_uint32_t(byte ** buf, uint32_t val); -/** @sa unbuffer_big_endian_uint32_t -*/ -uint8_t unbuffer_big_endian_uint32_t(byte ** buf) + /** @sa unbuffer_big_endian_uint32_t + */ + uint8_t unbuffer_big_endian_uint32_t(byte ** buf) -/** @} */ + /** @} */ #else /* this else is true when not in doxygen */ -INLINE_UTIL void to_big_endian_uint8_t(byte * buf, uint8_t val) { - memcpy(buf, &val, 1); -} + INLINE_UTIL void to_big_endian_uint8_t(byte * buf, uint8_t val) { + memcpy(buf, &val, 1); + } -INLINE_UTIL uint8_t from_big_endian_uint8_t(byte * buf) { - uint8_t beVal; - memcpy(&beVal, buf, 1); - return beVal; -} + INLINE_UTIL uint8_t from_big_endian_uint8_t(byte * buf) { + uint8_t beVal; + memcpy(&beVal, buf, 1); + return beVal; + } #define WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(_TYPE, _TOBE, _FROMBE) \ INLINE_UTIL void to_big_endian_##_TYPE(byte * buf, _TYPE val) { \ @@ -407,8 +407,8 @@ INLINE_UTIL _TYPE from_big_endian_##_TYPE(byte * buf) { \ return _FROMBE(beVal); \ } -WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint16_t, htons, ntohs) -WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint32_t, htonl, ntohl) + WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint16_t, htons, ntohs) + WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint32_t, htonl, ntohl) #undef WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS @@ -423,9 +423,9 @@ INLINE_UTIL _TYPE unbuffer_big_endian_##_TYPE (byte ** buf) { \ return from_big_endian_##_TYPE(current); \ } -WIIUSE_DECLARE_BUFFERING_OPS(uint8_t) -WIIUSE_DECLARE_BUFFERING_OPS(uint16_t) -WIIUSE_DECLARE_BUFFERING_OPS(uint32_t) + WIIUSE_DECLARE_BUFFERING_OPS(uint8_t) + WIIUSE_DECLARE_BUFFERING_OPS(uint16_t) + WIIUSE_DECLARE_BUFFERING_OPS(uint32_t) #undef WIIUSE_DECLARE_BUFFERING_OPS From f1b6c4ad2bf51bfbaaa0f1bb9dd76ecbfdc11651 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 10 Dec 2012 14:14:07 -0600 Subject: [PATCH 48/55] Add missing include. --- src/os_nix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/os_nix.c b/src/os_nix.c index ffacf94..4748be1 100644 --- a/src/os_nix.c +++ b/src/os_nix.c @@ -46,6 +46,7 @@ #include /* for perror */ #include /* for memset */ #include /* for connect, socket */ +#include /* for struct timeval */ #include /* for close, write */ #include From b3c0c390c464a27a5bdf66bbb98853b00c87e57a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 10 Dec 2012 14:16:45 -0600 Subject: [PATCH 49/55] Astyle the examples. --- example-sdl/sdl.c | 217 +++++++++++++++++++++------------------- example/example.c | 246 ++++++++++++++++++++++++++++++---------------- 2 files changed, 280 insertions(+), 183 deletions(-) diff --git a/example-sdl/sdl.c b/example-sdl/sdl.c index e8162aa..97a9470 100644 --- a/example-sdl/sdl.c +++ b/example-sdl/sdl.c @@ -56,7 +56,7 @@ #define MAX_WIIMOTES 2 GLint width = 1024, height = 768; -GLfloat backColor[4] = {1.0,1.0,1.0,1.0}; +GLfloat backColor[4] = {1.0, 1.0, 1.0, 1.0}; wiimote** wiimotes = NULL; @@ -65,11 +65,11 @@ int xcoord = 0; int ycoord = 0; #ifdef WIN32 - DWORD last_render; +DWORD last_render; #else - struct timeval last_render; - int last_sec = 0; - int fps = 0; +struct timeval last_render; +int last_sec = 0; +int fps = 0; #endif enum render_mode_t { @@ -123,39 +123,45 @@ void set_material(struct material_t* mptr); void resize_window(GLint new_width, GLint new_height); 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); - if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) + } + if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) { 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); - if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) + } + 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)) { int level; WIIUSE_GET_IR_SENSITIVITY(wm, &level); - wiiuse_set_ir_sensitivity(wm, level+1); + wiiuse_set_ir_sensitivity(wm, level + 1); } if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) { int level; WIIUSE_GET_IR_SENSITIVITY(wm, &level); - wiiuse_set_ir_sensitivity(wm, level-1); + wiiuse_set_ir_sensitivity(wm, level - 1); } - #if 0 +#if 0 if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) { - if (render_mode == IR) + if (render_mode == IR) { render_mode = TEAPOT; - else + } else { render_mode = IR; + } resize_window(width, height); } - #endif +#endif } #define DRAW_TRIANGLE(x, y, z, s) do { \ @@ -166,52 +172,57 @@ void handle_event(struct wiimote_t* wm) { 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 1; - #else - struct timeval now; - long elapsed_usec = 0; +#ifdef WIN32 + if (GetTickCount() < (last_render + 16)) { + return 0; + } + last_render = GetTickCount(); + return 1; +#else + struct timeval now; + long elapsed_usec = 0; - gettimeofday(&now, NULL); + gettimeofday(&now, NULL); - if (now.tv_usec > 1000000) { - now.tv_usec -= 1000000; - ++now.tv_sec; - } + if (now.tv_usec > 1000000) { + now.tv_usec -= 1000000; + ++now.tv_sec; + } - if (now.tv_sec > last_render.tv_sec) - elapsed_usec = ((now.tv_sec - last_render.tv_sec) * 1000000); + if (now.tv_sec > last_render.tv_sec) { + elapsed_usec = ((now.tv_sec - last_render.tv_sec) * 1000000); + } - if (now.tv_usec > last_render.tv_usec) - elapsed_usec += now.tv_usec - last_render.tv_usec; - else - elapsed_usec += last_render.tv_usec - now.tv_usec; + if (now.tv_usec > last_render.tv_usec) { + elapsed_usec += now.tv_usec - last_render.tv_usec; + } else { + elapsed_usec += last_render.tv_usec - now.tv_usec; + } - if (time(NULL) > last_sec) { - printf("fps: %i\n", fps); - fps = 0; - last_sec = time(NULL); - } + if (time(NULL) > last_sec) { + printf("fps: %i\n", fps); + fps = 0; + last_sec = time(NULL); + } - if (elapsed_usec < 16000) - return 0; + if (elapsed_usec < 16000) { + return 0; + } - last_render = now; - ++fps; + last_render = now; + ++fps; - return 1; - #endif + return 1; +#endif } void display() { int i, wm; float size = 5; - if (!can_render()) + if (!can_render()) { return; + } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); @@ -223,37 +234,39 @@ void display() { glDisable(GL_LIGHTING); glBegin(GL_TRIANGLES); - /* green center */ - glColor3f(0.0, 1.0, 0.0); - DRAW_TRIANGLE(width/2, height/2, 0, size); + /* 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 */ - glColor3f(1.0, 0.0, 0.0); - for (i = 0; i < 4; ++i) { - if (wiimotes[wm]->ir.dot[i].visible) - DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size); + /* red ir */ + glColor3f(1.0, 0.0, 0.0); + for (i = 0; i < 4; ++i) { + if (wiimotes[wm]->ir.dot[i].visible) { + DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size); } + } - /* yellow corrected ir */ - glColor3f(1.0, 1.0, 0.0); - for (i = 0; i < 4; ++i) { - if (wiimotes[wm]->ir.dot[i].visible) - DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size); + /* yellow corrected ir */ + glColor3f(1.0, 1.0, 0.0); + for (i = 0; i < 4; ++i) { + if (wiimotes[wm]->ir.dot[i].visible) { + DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size); } + } - /* blue cursor */ - glColor3f(0.0, 0.0, 1.0); - DRAW_TRIANGLE(wiimotes[wm]->ir.x, wiimotes[wm]->ir.y-size, 0, size); + /* blue cursor */ + glColor3f(0.0, 0.0, 1.0); + DRAW_TRIANGLE(wiimotes[wm]->ir.x, wiimotes[wm]->ir.y - size, 0, size); glEnd(); } } else { /* draw the teapot */ gluLookAt(0.0, 0.0, -5.0, - 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0); + 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); @@ -300,8 +313,9 @@ void resize_window(GLint new_width, GLint new_height) { width = new_width; height = new_height; - if (new_height == 0) + if (new_height == 0) { new_height = 1; + } 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); glLoadIdentity(); - if (render_mode == IR) + if (render_mode == IR) { gluOrtho2D(0, width, height, 0); - else - gluPerspective(60.0f, (float)new_width/(float)new_height, 0.1f, 100.0f); + } else { + gluPerspective(60.0f, (float)new_width / (float)new_height, 0.1f, 100.0f); + } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -321,8 +336,9 @@ 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); + } } #ifndef WIN32 @@ -337,12 +353,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine wiimotes = wiiuse_init(MAX_WIIMOTES); found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5); - if (!found) + if (!found) { return 0; + } connected = wiiuse_connect(wiimotes, MAX_WIIMOTES); - if (connected) + if (connected) { printf("Connected to %i wiimotes (of %i found).\n", connected, found); - else { + } else { printf("Failed to connect to any wiimote.\n"); return 0; } @@ -350,11 +367,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4); wiiuse_rumble(wiimotes[0], 1); - #ifndef WIN32 - usleep(200000); - #else - Sleep(200); - #endif +#ifndef WIN32 + usleep(200000); +#else + Sleep(200); +#endif wiiuse_rumble(wiimotes[0], 0); @@ -379,49 +396,47 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine height = wiimotes[0]->ir.vres[1]; 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); + } /* set OpenGL stuff */ glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); + glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthFunc(GL_LEQUAL); - glClearColor(0, 0, 0, 0); + glDepthFunc(GL_LEQUAL); + glClearColor(0, 0, 0, 0); /* set the size of the window */ resize_window(width, height); display(); - #ifdef WIN32 - last_render = GetTickCount(); - #endif +#ifdef WIN32 + last_render = GetTickCount(); +#endif while (1) { SDL_Event event; if (SDL_PollEvent(&event)) { switch (event.type) { - case SDL_VIDEORESIZE: - { - /* resize the window */ - resize_window(event.resize.w, event.resize.h); - break; - } - case SDL_QUIT: - { - /* shutdown */ - SDL_Quit(); - wiiuse_cleanup(wiimotes, MAX_WIIMOTES); - return 0; - } - default: - { - } + case SDL_VIDEORESIZE: { + /* resize the window */ + resize_window(event.resize.w, event.resize.h); + break; + } + case SDL_QUIT: { + /* shutdown */ + SDL_Quit(); + wiiuse_cleanup(wiimotes, MAX_WIIMOTES); + return 0; + } + default: { + } } } diff --git a/example/example.c b/example/example.c index f35f907..22bed24 100644 --- a/example/example.c +++ b/example/example.c @@ -58,59 +58,85 @@ 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"); + 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)) + 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)) + 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)) + if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) { 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); - if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) + } + if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) { wiiuse_set_ir(wm, 0); + } - /* - * Motion+ support - */ - if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) - { - if(WIIUSE_USING_EXP(wm)) - wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through - else - wiiuse_set_motion_plus(wm, 1); // standalone - } + /* + * Motion+ support + */ + if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) { + if (WIIUSE_USING_EXP(wm)) { + wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through + } else { + wiiuse_set_motion_plus(wm, 1); // standalone + } + } - if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) - { - wiiuse_set_motion_plus(wm, 0); // off - } + if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) { + wiiuse_set_motion_plus(wm, 0); // off + } /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { @@ -131,8 +157,9 @@ void handle_event(struct wiimote_t* wm) { /* 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) + 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); @@ -144,8 +171,12 @@ void handle_event(struct wiimote_t* wm) { /* 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"); + 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); @@ -157,21 +188,51 @@ void handle_event(struct wiimote_t* wm) { /* 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"); + 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); @@ -183,15 +244,33 @@ void handle_event(struct wiimote_t* wm) { /* 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"); + 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); @@ -207,15 +286,14 @@ void handle_event(struct wiimote_t* wm) { /* printf("Raw: TL:%d TR:%d BL:%d BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr); */ } - if(wm->exp.type == EXP_MOTION_PLUS || - wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) - { - 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.roll, - wm->exp.mp.angle_rate_gyro.yaw); - } - } + if (wm->exp.type == EXP_MOTION_PLUS || + wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { + 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.roll, + wm->exp.mp.angle_rate_gyro.yaw); + } +} /** * @brief Callback that handles a read event. @@ -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("finished read of size %i\n", len); for (; i < len; ++i) { - if (!(i%16)) + if (!(i % 16)) { printf("\n"); + } printf("%x ", data[i]); } printf("\n\n"); @@ -296,13 +375,16 @@ void test(struct wiimote_t* wm, byte* data, unsigned short len) { short any_wiimote_connected(wiimote** wm, int wiimotes) { int i; - if(!wm) return 0; - - for(i = 0; i < wiimotes; i++) { - if(wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) - return 1; + if (!wm) { + return 0; } - + + for (i = 0; i < wiimotes; i++) { + if (wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) { + return 1; + } + } + return 0; } @@ -337,7 +419,7 @@ int main(int argc, char** argv) { */ found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5); if (!found) { - printf ("No wiimotes found.\n"); + printf("No wiimotes found.\n"); return 0; } @@ -351,9 +433,9 @@ int main(int argc, char** argv) { * This will return the number of established connections to the found wiimotes. */ connected = wiiuse_connect(wiimotes, MAX_WIIMOTES); - if (connected) + if (connected) { printf("Connected to %i wiimotes (of %i found).\n", connected, found); - else { + } else { printf("Failed to connect to any wiimote.\n"); return 0; } @@ -441,8 +523,8 @@ int main(int argc, char** argv) { * 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); */ + /* 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; @@ -460,15 +542,15 @@ int main(int argc, char** argv) { printf("Guitar Hero 3 controller inserted.\n"); break; - case WIIUSE_MOTION_PLUS_ACTIVATED: - printf("Motion+ was activated\n"); - break; + case WIIUSE_MOTION_PLUS_ACTIVATED: + printf("Motion+ was activated\n"); + break; case WIIUSE_NUNCHUK_REMOVED: case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: case WIIUSE_WII_BOARD_CTRL_REMOVED: - case WIIUSE_MOTION_PLUS_REMOVED: + case WIIUSE_MOTION_PLUS_REMOVED: /* some expansion was removed */ handle_ctrl_status(wiimotes[i]); printf("An expansion was removed.\n"); From 2c2e47478a601776f2d8056ab3bcf248da9555e2 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 10 Dec 2012 14:17:00 -0600 Subject: [PATCH 50/55] Slightly more tidy on the regular example --- example/example.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/example/example.c b/example/example.c index 22bed24..00f5edc 100644 --- a/example/example.c +++ b/example/example.c @@ -36,12 +36,11 @@ #include /* for printf */ -#ifndef WIN32 - #include /* for usleep */ -#endif - #include "wiiuse.h" /* for wiimote_t, classic_ctrl_t, etc */ +#ifndef WIIUSE_WIN32 +#include /* for usleep */ +#endif #define MAX_WIIMOTES 4 @@ -451,11 +450,11 @@ int main(int argc, char** argv) { wiiuse_rumble(wiimotes[0], 1); wiiuse_rumble(wiimotes[1], 1); - #ifndef WIN32 - usleep(200000); - #else - Sleep(200); - #endif +#ifndef WIIUSE_WIN32 + usleep(200000); +#else + Sleep(200); +#endif wiiuse_rumble(wiimotes[0], 0); wiiuse_rumble(wiimotes[1], 0); From dd2c7e902aa095fd7844329e38bca7cd7c51e6d9 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 12 Dec 2012 11:27:56 -0600 Subject: [PATCH 51/55] Squashed 'cmake/' changes from b0d0a58..cac13f1 cac13f1 Add CMakePackageConfigHelpers as a backported module from 2.8.10 44e17a5 Update help 92f9405 Add FindDirectShow from VRPN a93bf46 Update FindVRPN edf459d clean up some modules 0bf8b53 Update documentation/help 900ae37 Improvements to findcppdom bcdd5ed Adrienne timecode generator finder fc14864 IDLJ finder/script 5fa91d4 Finder for windows/platform SDK 835a160 Add module to find perl modules: pass them as components 7dc76c3 cleanup 38e2a0d Create a doc_open target to open html docs e8de008 Improved directx finding 787900c Conditionally use libuuid for VPR22 1c73e35 Add a helper error message to findcppcheck. 9e8b357 Generate, rather than enumerate, juggler lib names. d42ae48 Add another compiler flag for warnings. 911f522 Just a little cleanup. a466ea5 Update help 30af184 Add two new scripts written for VR Juggler 09ccc48 Update VR Juggler finders for 3.0.1 f9a5b86 VR JuggLua is no longer unreleased research software - ditch the scary warning. 1adb75e Update GetGitRevisionDescription to handle new submodules a little better. 187b7b2 Add new FindViewPoint d1ec683 Enhance FindOpenHaptics to handle 3.1 de68fc0 Restore some tabs that went missing feb11f6 Improve GHOST finder. b922e06 Update help 7ff9c53 Run cmake-bulk-decrufter. 0873f79 Merge branch 'jscasallas/master' e2ec7cd Add helpful comment about use as submodule 2a42dc5 Simplify FindQVRPN. 8ddcb84 Windows compatibility for the pull request just merged 4fcc618 Merge pull request #6 from phire/cmake-modules fa1ef4c Add additional versions of cppdom and gmtl. 7db0714 Regenerate help 39c0f2f Add find directinput d2e2a74 Update copyright year 5c05172 Update module help 5b62638 Rename to UseMarkdown and add rename feature f92055a Add markdown scripts (finding and targets) 00cefbe GetGitRevisionDescription: Search parent dirs for .git/ 0fb259a New module: FindQVRPN.cmake 9616f6e Find jccl and vrjuggler plugins, and split between debug and release 4856978 Set WIIUSE_RUNTIME_LIBRARY in Wiiuse even not on Windows d94b209 make FindWinHID work on MinGW. 4c110cb Fix copy-pasteo in findcppunit 8be460a fix doc typo 6a78da3 Handle other compilers better by using compiler ID a90f87b Use compiler behavior, not identity, to decide what warning flags to use f03d7a8 Properly check the various arguments to cppcheck rather than assume based on a few tests. d3ffd8a get git revision more robustly 1fb0e41 update ghost fake stl to simplify header 6fbe007 No more checking the stdc++ version for openhaptics db11bb9 make sure we actually link against HDU/HLU nested targets! a6580e9 remove unused variables in test file f4a26c5 update copyright 16a6266 fix dcubed nested target ca5cd7a mark luac item as advanced f131cbe actually use the jttk root dir specified 501dbb2 improve dcubed include dirs ae8764f improve splitting osg plugins into debug and release git-subtree-dir: cmake git-subtree-split: cac13f1c3225555cec9ae06a1ba47baa8c90442a --- AboutTheseModules.cmake | 2 +- BundleOSGPlugins.cmake | 16 +- CheckMacHIDAPI.cpp | 2 - CreateDashboardScripts.cmake | 2 +- CreateLaunchers.cmake | 2 +- DoxygenTargets.cmake | 23 + EnableExtraCompilerWarnings.cmake | 25 +- FileCopyTargets.cmake | 4 +- FindAdrienne.cmake | 202 +++++++ FindCPPDOM.cmake | 30 +- FindDCubed.cmake | 1 + FindDirectInput.cmake | 180 +++++++ FindDirectShow.cmake | 126 +++++ FindDirectX.cmake | 244 +++++++++ FindGDB.cmake | 24 +- FindGHOST.cmake | 44 +- FindGMTL.cmake | 7 +- FindGadgeteer20.cmake | 10 +- FindIDLJ.cmake | 92 ++++ FindJCCL14.cmake | 10 +- FindJtTk.cmake | 6 +- FindLibusb1.cmake | 10 +- FindLyX.cmake | 6 +- FindMarkdown.cmake | 56 ++ FindOpenCV.cmake | 6 +- FindOpenHaptics.cmake | 119 ++--- FindOpenHaptics.cpp | 18 - FindPerformer.cmake | 153 ++++++ FindPerlModules.cmake | 78 +++ FindQVRPN.cmake | 81 +++ FindSonix14.cmake | 10 +- FindTR1.cmake | 5 +- FindTweek14.cmake | 10 +- FindVPR22.cmake | 15 +- FindVRJ30.cmake | 10 +- FindVRJOGL30.cmake | 10 +- FindVRJuggler.cmake | 5 +- FindVRJuggler30.cmake | 38 +- FindVRPN.cmake | 26 +- FindViewPoint.cmake | 94 ++++ FindWiiUse.cmake | 2 + FindWinHID.cmake | 163 +++--- FindWindowsSDK.cmake | 163 ++++++ Findcppcheck.cmake | 97 ++-- Findcppunit.cmake | 2 +- Findcutil.cmake | 18 +- GetCompilerInfoString.cmake | 6 +- GetGitRevisionDescription.cmake | 53 +- GetGitRevisionDescription.cmake.in | 16 +- LuaTargets.cmake | 18 +- OptionRequires.cmake | 13 +- README.markdown | 2 +- UseMarkdown.cmake | 116 ++++ .../CMakePackageConfigHelpers.cmake | 254 +++++++++ ghost-fake-stl/iostream.h | 2 +- ghost-fake-stl/list.h | 2 +- ghost-fake-stl/set.h | 6 +- ghost-fake-stl/vector.h | 2 +- module-help.html | 237 ++++++++- module-help.txt | 503 +++++++++++++++++- .../DCubed/d3ew_scene/CMakeLists.txt | 1 - package-licensing/VRJuggLua.cmake | 10 +- 62 files changed, 3122 insertions(+), 366 deletions(-) create mode 100644 FindAdrienne.cmake create mode 100644 FindDirectInput.cmake create mode 100644 FindDirectShow.cmake create mode 100644 FindDirectX.cmake create mode 100644 FindIDLJ.cmake create mode 100644 FindMarkdown.cmake delete mode 100644 FindOpenHaptics.cpp create mode 100644 FindPerformer.cmake create mode 100644 FindPerlModules.cmake create mode 100644 FindQVRPN.cmake create mode 100644 FindViewPoint.cmake create mode 100644 FindWindowsSDK.cmake create mode 100644 UseMarkdown.cmake create mode 100644 cmake-2.8.10-modules/CMakePackageConfigHelpers.cmake diff --git a/AboutTheseModules.cmake b/AboutTheseModules.cmake index 3d2beaf..72082b1 100644 --- a/AboutTheseModules.cmake +++ b/AboutTheseModules.cmake @@ -22,7 +22,7 @@ # need to call: # include(BoostTestTargets) # -# For more information, see the documentation for individual modules, the +# For more information, see the documentation for individual modules, the # cmake-modules github page, and/or the upstream CMake documentation at # http://www.cmake.org/cmake/help/cmake-2-8-docs.html # diff --git a/BundleOSGPlugins.cmake b/BundleOSGPlugins.cmake index c8e482b..ef491d8 100644 --- a/BundleOSGPlugins.cmake +++ b/BundleOSGPlugins.cmake @@ -31,7 +31,7 @@ function(_osgbundle_split_debug_versions releasevar debugvar) set(debug) foreach(fn ${ARGN}) get_filename_component(name "${fn}" NAME_WE) - if(${name} MATCHES "d$") + if("${name}" MATCHES "d$") list(APPEND debug "${fn}") else() list(APPEND release "${fn}") @@ -75,9 +75,21 @@ endif() function(install_osg_plugins var) set(INSTALLEDPLUGINS) foreach(plugin ${OSGDB_PLUGINS_RELEASE} ${OSGWRAPPER_PLUGINS_RELEASE}) - install(FILES "${plugin}" DESTINATION "${OSG_PATH_TO_PLUGINS}") + install(FILES "${plugin}" + DESTINATION "${OSG_PATH_TO_PLUGINS}" + CONFIGURATIONS Release RelWithDebInfo MinSizeRel) get_filename_component(name "${plugin}" NAME) list(APPEND INSTALLEDPLUGINS "${OSG_PATH_TO_PLUGINS}/${name}") endforeach() + foreach(plugin ${OSGDB_PLUGINS_DEBUG} ${OSGWRAPPER_PLUGINS_DEBUG}) + install(FILES + "${plugin}" + DESTINATION + "${OSG_PATH_TO_PLUGINS}" + CONFIGURATIONS + Debug) + #get_filename_component(name "${plugin}" NAME) + #list(APPEND INSTALLEDPLUGINS "${OSG_PATH_TO_PLUGINS}/${name}") + endforeach() set(${var} ${INSTALLEDPLUGINS} PARENT_SCOPE) endfunction() diff --git a/CheckMacHIDAPI.cpp b/CheckMacHIDAPI.cpp index ba5e415..00d2a46 100644 --- a/CheckMacHIDAPI.cpp +++ b/CheckMacHIDAPI.cpp @@ -35,8 +35,6 @@ int main(int argc, char* argv[]) { #if defined(__APPLE__) io_object_t _ioObject; IOHIDDeviceInterface122 **_interface; - bool _gotdata; - int _gotsize; unsigned char _buffer[512]; IOReturn result = (*_interface)->setInterruptReportHandlerCallback(_interface, _buffer, 512, diff --git a/CreateDashboardScripts.cmake b/CreateDashboardScripts.cmake index 9729839..ec1664a 100644 --- a/CreateDashboardScripts.cmake +++ b/CreateDashboardScripts.cmake @@ -165,7 +165,7 @@ function(create_dashboard_scripts) endif() set(_msg) - + if(NOT DASHBOARDSCRIPT_BUILD_CONFIGURATION) set(DASHBOARDSCRIPT_BUILD_CONFIGURATION "RelWithDebInfo") endif() diff --git a/CreateLaunchers.cmake b/CreateLaunchers.cmake index 0f3f5b3..6cbf234 100644 --- a/CreateLaunchers.cmake +++ b/CreateLaunchers.cmake @@ -97,7 +97,7 @@ macro(_launcher_system_settings) set(LAUNCHERS_GOT_GDB YES) if(GDB_HAS_RETURN_CHILD_RESULT) set(LAUNCHERS_GDB_ARG --return-child-result) - endif() + endif() else() set(LAUNCHERS_GOT_GDB) endif() diff --git a/DoxygenTargets.cmake b/DoxygenTargets.cmake index ce98a91..2c6bc78 100644 --- a/DoxygenTargets.cmake +++ b/DoxygenTargets.cmake @@ -213,6 +213,7 @@ function(add_doxygen _doxyfile) else() add_custom_target(${DOC_TARGET} ALL) endif() + endif() if(NOT IS_ABSOLUTE "${OUTPUT_DIRECTORY}") @@ -228,6 +229,28 @@ function(add_doxygen _doxyfile) "${OUTPUT_DIRECTORY}/html" "${OUTPUT_DIRECTORY}/latex") + if(NOT TARGET ${DOC_TARGET}_open) + # Create a target to open the generated HTML file. + if(WIN32) + set(DOXYGEN_LAUNCHER_COMMAND start "Documentation") + elseif(NOT APPLE) + set(DOXYGEN_LAUNCHER_COMMAND xdg-open) + endif() + if(DOXYGEN_LAUNCHER_COMMAND) + add_custom_target(${DOC_TARGET}_open + COMMAND ${DOXYGEN_LAUNCHER_COMMAND} "${OUTPUT_DIRECTORY}/html/index.html") + set_target_properties(${DOC_TARGET}_open + PROPERTIES + EXCLUDE_FROM_ALL + TRUE) + set_target_properties(${DOC_TARGET}_open + PROPERTIES + EXCLUDE_FROM_DEFAULT_BUILD + TRUE) + add_dependencies(${DOC_TARGET}_open ${DOC_TARGET}) + endif() + endif() + get_filename_component(_doxyfileabs "${_doxyfile}" ABSOLUTE) get_filename_component(INCLUDE_FILE "${_doxyfileabs}" NAME) get_filename_component(INCLUDE_PATH "${_doxyfileabs}" PATH) diff --git a/EnableExtraCompilerWarnings.cmake b/EnableExtraCompilerWarnings.cmake index f2c4227..0115ef3 100644 --- a/EnableExtraCompilerWarnings.cmake +++ b/EnableExtraCompilerWarnings.cmake @@ -31,8 +31,29 @@ macro(_enable_extra_compiler_warnings_flags) if(COMPILER_WARNINGS_EXTREME) set(_flags "${_flags} /Wall /wd4619 /wd4668 /wd4820 /wd4571 /wd4710") endif() - elseif(CMAKE_COMPILER_IS_GNUCXX) - set(_flags "-W -Wall") + else() + include(CheckCXXCompilerFlag) + set(_flags) + + check_cxx_compiler_flag(-W SUPPORTS_W_FLAG) + if(SUPPORTS_W_FLAG) + set(_flags "${_flags} -W") + endif() + + check_cxx_compiler_flag(-Wall SUPPORTS_WALL_FLAG) + if(SUPPORTS_WALL_FLAG) + set(_flags "${_flags} -Wall") + endif() + + check_cxx_compiler_flag(-Wextra SUPPORTS_WEXTRA_FLAG) + if(SUPPORTS_WEXTRA_FLAG) + set(_flags "${_flags} -Wextra") + endif() + + check_cxx_compiler_flag(-Weffc++ SUPPORTS_WEFFCXX_FLAG) + if(SUPPORTS_WEFFCXX_FLAG) + set(_flags "${_flags} -Weffc++") + endif() endif() endmacro() diff --git a/FileCopyTargets.cmake b/FileCopyTargets.cmake index d92df16..13eb11a 100644 --- a/FileCopyTargets.cmake +++ b/FileCopyTargets.cmake @@ -54,7 +54,9 @@ function(add_file_copy_target _target _dest) get_filename_component(fullpath "${fn}" ABSOLUTE) get_filename_component(fn "${fn}" NAME) else() - get_filename_component(fullpath "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" ABSOLUTE) + get_filename_component(fullpath + "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" + ABSOLUTE) endif() # Clean up output file name diff --git a/FindAdrienne.cmake b/FindAdrienne.cmake new file mode 100644 index 0000000..d4f174c --- /dev/null +++ b/FindAdrienne.cmake @@ -0,0 +1,202 @@ +# - try to find Adrienne Electronics Corporation timecode card library +# +# SDK available from the manufacturer: http://www.adrielec.com/ +# +# Cache Variables: (probably not for direct use in your scripts) +# ADRIENNE_INCLUDE_DIR +# ADRIENNE_LIBRARY +# ADRIENNE_RUNTIME_LIBRARY +# ADRIENNE_INCLUDE_FILE +# +# Variables you might use in your CMakeLists.txt: +# ADRIENNE_FOUND +# ADRIENNE_INCLUDE_DIRS +# ADRIENNE_LIBRARIES +# ADRIENNE_RUNTIME_LIBRARIES - the AEC_NTTC.dll file +# ADRIENNE_RUNTIME_LIBRARY_DIRS +# +# ADRIENNE_INCLUDE_FILENAME - this is probably AEC_NTTC.h, but it might also +# be AECINTTC.H. +# +# ADRIENNE_INCLUDE_HAS_EXTERN_C - Some (most) versions of the header already +# wrap their definitions in extern "C" { }, but some do not. +# +# ADRIENNE_DEFINITIONS - defines a quoted ADRIENNE_INCLUDE_FILENAME as above, +# so you can write a line like #include ADRIENNE_INCLUDE_FILENAME +# Also defines ADRIENNE_BEFORE_INCLUDE and ADRIENNE_AFTER_INCLUDE to handle +# adding extern "C" { and } if the header file doesn't do so itself. +# +# Variables that might be set by the user in the gui/command line to help +# find the library: +# ADRIENNE_ROOT_DIR - root of an Adrienne CD, disk, or extracted/copied contents +# thereof. +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Apparently Windows only. +if(WIN32 OR CYGWIN) + set(ADRIENNE_ROOT_DIR + "${ADRIENNE_ROOT_DIR}" + CACHE + PATH + "Directory to search for Adrienne Electronics Timecode data - root of a software distribution or extracted download from http://www.adrielec.com/") + + set(ADRIENNE_DEFINITIONS) + + set(ADRIENNE_INCLUDE_SEARCH + # from AecPCIeTC_8-12a: contains AEC_NTTC.h with extern "C" and three extra functions: + # AEC_PCTC_OPEN_ALL, AEC_PCTC_CLOSE_ALL, AEC_PCTC_INITIALIZE_EVENT + "SDK_SourceCode" + + # from AecPci6_02_CD - called AECINTTC.H but otherwise essentially identical to earlier versions + "TestPrograms_WithDLL/DLL_API_INFO" + # A zipped development project contains essentially the same, named AEC_NTTC.h so we'll add this in case it's unzipped. + "TestPrograms_WithDLL/ZippedDevelopmentProjects/AecMfc32_Rel504" + + # from pc-ltc - called AECINTTC.H and lacks extern "C" + "NT-CODE/C40-APP1" + ) + set(ADRIENNE_HEADER_NAMES + AEC_NTTC.H + AEC_NTTC.h + Aec_nttc.h + AECINTTC.H) + + set(ADRIENNE_LIB_SEARCH) + set(ADRIENNE_DLL_SEARCH) + + if(CMAKE_SIZEOF_VOID_P MATCHES "8") + # 64 bit code - apparently initially packaged only in the + # PCIe version of their software + list(APPEND ADRIENNE_LIB_SEARCH + # from AecPCIeTC_8-12a + "64BitOS_files/DLL Versions") + + list(APPEND ADRIENNE_DLL_SEARCH + # from AecPCIeTC_8-12a + "64BitOS_files/DLL Versions") + else() + # 32-bit code, much more prevalent. + list(APPEND ADRIENNE_LIB_SEARCH + # from AecPCIeTC_8-12a + "32BitOS_files/DLLversions" + + # from AecPci6_02_CD + "TestPrograms_WithDLL/DLL_API_INFO" + + # from pc-ltc + "NT-CODE/DLL" + ) + + list(APPEND ADRIENNE_DLL_SEARCH + # from AecPCIeTC_8-12a + "32BitOS_files/DLLversions" + + # from AecPci6_02_CD + "TestPrograms_WithDLL" + + # from pc-ltc + "NT-CODE/DLL") + endif() + + find_library(ADRIENNE_LIBRARY + NAMES + AEC_NTTC + PATHS + "${ADRIENNE_ROOT_DIR}" + PATH_SUFFIXES + ${ADRIENNE_LIB_SEARCH}) + + find_path(ADRIENNE_INCLUDE_DIR + NAMES + ${ADRIENNE_HEADER_NAMES} + PATHS + "${ADRIENNE_ROOT_DIR}" + PATH_SUFFIXES + ${ADRIENNE_INCLUDE_SEARCH}) + + if(ADRIENNE_INCLUDE_DIR) + find_file(ADRIENNE_INCLUDE_FILE + NAMES + ${ADRIENNE_HEADER_NAMES} + HINTS + ${ADRIENNE_INCLUDE_DIR}) + + # Get include filename + get_filename_component(ADRIENNE_INCLUDE_FILENAME + "${ADRIENNE_INCLUDE_FILE}" + NAME) + list(APPEND ADRIENNE_DEFINITIONS -DADRIENNE_INCLUDE_FILENAME="ADRIENNE_INCLUDE_FILENAME") + + # Find out if it has extern "C" in it. + file(STRINGS "${ADRIENNE_INCLUDE_FILE}" strings) + set(ADRIENNE_INCLUDE_HAS_EXTERN_C OFF) + foreach(_line ${strings}) + if("${_line}" STREQUAL "extern \"C\"") + set(ADRIENNE_INCLUDE_HAS_EXTERN_C ON) + break() + endif() + endforeach() + + if(ADRIENNE_INCLUDE_HAS_EXTERN_C) + list(APPEND ADRIENNE_DEFINITIONS -DADRIENNE_BEFORE_INCLUDE -DADRIENNE_AFTER_INCLUDE) + else() + list(APPEND ADRIENNE_DEFINITIONS "-DADRIENNE_BEFORE_INCLUDE=extern \"C\" {" "-DADRIENNE_AFTER_INCLUDE=}") + endif() + endif() + + get_filename_component(_adrienne_libdir "${ADRIENNE_LIBRARY}" PATH) + find_file(ADRIENNE_RUNTIME_LIBRARY + NAMES + AEC_NTTC.dll + HINTS + "${_adrienne_libdir}" + "${_adrienne_libdir}/.." + PATHS + "${ADRIENNE_ROOT_DIR}" + PATH_SUFFIXES + ${ADRIENNE_DLL_SEARCH}) + + + set(ADRIENNE_RUNTIME_LIBRARIES "${ADRIENNE_RUNTIME_LIBRARY}") + get_filename_component(ADRIENNE_RUNTIME_LIBRARY_DIRS + "${ADRIENNE_RUNTIME_LIBRARY}" + PATH) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Adrienne + DEFAULT_MSG + ADRIENNE_LIBRARY + ADRIENNE_RUNTIME_LIBRARY + ADRIENNE_INCLUDE_DIR + ADRIENNE_INCLUDE_FILENAME) + + if(ADRIENNE_FOUND) + set(ADRIENNE_LIBRARIES "${ADRIENNE_LIBRARY}") + set(ADRIENNE_INCLUDE_DIRS "${ADRIENNE_INCLUDE_DIR}") + mark_as_advanced(ADRIENNE_ROOT_DIR) + endif() + + mark_as_advanced( + ADRIENNE_LIBRARY + ADRIENNE_RUNTIME_LIBRARY + ADRIENNE_INCLUDE_DIR + ADRIENNE_INCLUDE_FILE) +else() + set(ADRIENNE_FOUND OFF) + set(ADRIENNE_SDK_IS_WINDOWS_ONLY NOTFOUND) + find_package_handle_standard_args(Adrienne + DEFAULT_MSG + ADRIENNE_SDK_IS_WINDOWS_ONLY) +endif() diff --git a/FindCPPDOM.cmake b/FindCPPDOM.cmake index 8950620..7fa8808 100644 --- a/FindCPPDOM.cmake +++ b/FindCPPDOM.cmake @@ -10,7 +10,7 @@ # Useful configuration variables you might want to add to your cache: # CPPDOM_ROOT_DIR - A directory prefix to search # (a path that contains include/ as a subdirectory) -# CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.0.0) +# CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.2.0) # to use when constructing search names and paths # # This script will use Flagpoll, if found, to provide hints to the location @@ -26,11 +26,11 @@ # and trigger an automatic re-run. # # Original Author: -# 2009-2010 Ryan Pavlik +# 2009-2012 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # -# Copyright Iowa State University 2009-2010. +# Copyright Iowa State University 2009-2012. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) @@ -41,6 +41,8 @@ set(_FP_PKG_NAME cppdom) set(CPPDOM_VERSIONS ${CPPDOM_ADDITIONAL_VERSIONS} + 1.3.0 + 1.2.0 1.1.2 1.1.1 1.1.0 @@ -99,6 +101,28 @@ endif() set(_ROOT_DIR "${CPPDOM_ROOT_DIR}") +if(CMAKE_SIZEOF_VOID_P MATCHES "8") + set(_VRJ_LIBSUFFIXES lib64 lib) + set(_VRJ_LIBDSUFFIXES + debug + lib64/x86_64/debug + lib64/debug + lib64 + lib/x86_64/debug + lib/debug + lib) + set(_VRJ_LIBDSUFFIXES_ONLY + debug + lib64/x86_64/debug + lib64/debug + lib/x86_64/debug + lib/debug) +else() + set(_VRJ_LIBSUFFIXES lib) + set(_VRJ_LIBDSUFFIXES debug lib/i686/debug lib/debug lib) + set(_VRJ_LIBDSUFFIXES_ONLY debug lib/i686/debug lib/debug) +endif() + find_path(CPPDOM_INCLUDE_DIR ${_HEADER} HINTS diff --git a/FindDCubed.cmake b/FindDCubed.cmake index a362da6..4ca33d2 100644 --- a/FindDCubed.cmake +++ b/FindDCubed.cmake @@ -184,6 +184,7 @@ if(DCUBED_FOUND) set(DCUBED_INCLUDE_DIRS "${DCUBED_CORE_INCLUDE_DIR}" "${DCUBED_CORE_INCLUDE_DIR}/if3" + "${DCUBED_CORE_INCLUDE_DIR}/.." "${DCUBED_WRAPPER_INCLUDE_DIR}") mark_as_advanced(DCUBED_ROOT_DIR) endif() diff --git a/FindDirectInput.cmake b/FindDirectInput.cmake new file mode 100644 index 0000000..a530ff0 --- /dev/null +++ b/FindDirectInput.cmake @@ -0,0 +1,180 @@ +# - try to find DirectInput library (part of DirectX SDK) +# +# Cache Variables: (probably not for direct use in your scripts) +# DIRECTINPUT_DXGUID_LIBRARY +# DIRECTINPUT_DXERR_LIBRARY +# DIRECTINPUT_DINPUT_LIBRARY +# DIRECTINPUT_INCLUDE_DIR +# +# Non-cache variables you should use in your CMakeLists.txt: +# DIRECTINPUT_LIBRARIES +# DIRECTINPUT_INCLUDE_DIRS +# DIRECTINPUT_FOUND - if this is not true, do not attempt to use this library +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2011 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2011. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + + +set(DIRECTINPUT_ROOT_DIR + "${DIRECTINPUT_ROOT_DIR}" + CACHE + PATH + "Root directory to search for DirectX/DirectInput") + +if(MSVC) + file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _PROG_FILES) + file(TO_CMAKE_PATH "$ENV{ProgramFiles(x86)}" _PROG_FILES_X86) + if(_PROG_FILES_X86) + set(_PROG_FILES "${_PROG_FILES_X86}") + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_lib_suffixes lib/x64 lib) + else() + set(_lib_suffixes lib/x86 lib) + endif() + macro(_append_dxsdk_in_inclusive_range _low _high) + if((NOT MSVC_VERSION LESS ${_low}) AND (NOT MSVC_VERSION GREATER ${_high})) + list(APPEND DXSDK_DIRS ${ARGN}) + endif() + endmacro() + _append_dxsdk_in_inclusive_range(1500 1600 "${_PROG_FILES}/Microsoft DirectX SDK (June 2010)") + _append_dxsdk_in_inclusive_range(1400 1600 + "${_PROG_FILES}/Microsoft DirectX SDK (February 2010)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2009)" + "${_PROG_FILES}/Microsoft DirectX SDK (March 2009)" + "${_PROG_FILES}/Microsoft DirectX SDK (November 2008)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2008)" + "${_PROG_FILES}/Microsoft DirectX SDK (June 2008)" + "${_PROG_FILES}/Microsoft DirectX SDK (March 2008)") + _append_dxsdk_in_inclusive_range(1310 1500 + "${_PROG_FILES}/Microsoft DirectX SDK (November 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (June 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (April 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (February 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (December 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (October 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (June 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (April 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (February 2006)") + + file(TO_CMAKE_PATH "$ENV{DXSDK_DIR}" ENV_DXSDK_DIR) + if(ENV_DXSDK_DIR) + list(APPEND DXSDK_DIRS ${ENV_DXSDK_DIR}) + endif() +else() + set(_lib_suffixes lib) + set(DXSDK_DIRS /mingw) +endif() + +find_path(DIRECTINPUT_INCLUDE_DIR + NAMES + dinput.h + PATHS + ${DXSDK_DIRS} + HINTS + "${DIRECTINPUT_ROOT_DIR}" + PATH_SUFFIXES + include) + +find_library(DIRECTINPUT_DXGUID_LIBRARY + NAMES + dxguid + PATHS + ${DXSDK_DIRS} + HINTS + "${DIRECTINPUT_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +if(DIRECTINPUT_DXGUID_LIBRARY) + get_filename_component(_dinput_lib_dir + ${DIRECTINPUT_DXGUID_LIBRARY} + PATH) +endif() + +find_library(DIRECTINPUT_DINPUT_LIBRARY + NAMES + dinput8 + dinput + PATHS + ${DXSDK_DIRS} + HINTS + "${_dinput_lib_dir}" + "${DIRECTINPUT_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +find_library(DIRECTINPUT_DXERR_LIBRARY + NAMES + dxerr + dxerr9 + dxerr8 + PATHS + ${DXSDK_DIRS} + HINTS + "${_dinput_lib_dir}" + "${DIRECTINPUT_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) +set(DIRECTINPUT_EXTRA_CHECK) +if(DIRECTINPUT_INCLUDE_DIR) + if(MSVC80) + set(DXSDK_DEPRECATION_BUILD 1962) + endif() + + if(DXSDK_DEPRECATION_BUILD) + include(CheckCSourceCompiles) + set(_dinput_old_includes ${CMAKE_REQUIRED_INCLUDES}) + set(CMAKE_REQUIRED_INCLUDES "${DIRECTINPUT_INCLUDE_DIR}") + check_c_source_compiles( + " + #include + #if _DXSDK_BUILD_MAJOR >= ${DXSDK_DEPRECATION_BUILD} + #error + #else + int main(int argc, char * argv[]) { + return 0; + } + " + DIRECTINPUT_SDK_SUPPORTS_COMPILER) + set(DIRECTINPUT_EXTRA_CHECK DIRECTINPUT_SDK_SUPPORTS_COMPILER) + set(CMAKE_REQUIRED_INCLUDES "${_dinput_old_includes}") + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(DirectInput + DEFAULT_MSG + DIRECTINPUT_DINPUT_LIBRARY + DIRECTINPUT_DXGUID_LIBRARY + DIRECTINPUT_DXERR_LIBRARY + DIRECTINPUT_INCLUDE_DIR + ${DIRECTINPUT_EXTRA_CHECK}) + +if(DIRECTINPUT_FOUND) + set(DIRECTINPUT_LIBRARIES + "${DIRECTINPUT_DXGUID_LIBRARY}" + "${DIRECTINPUT_DXERR_LIBRARY}" + "${DIRECTINPUT_DINPUT_LIBRARY}") + + set(DIRECTINPUT_INCLUDE_DIRS "${DIRECTINPUT_INCLUDE_DIR}") + + mark_as_advanced(DIRECTINPUT_ROOT_DIR) +endif() + +mark_as_advanced(DIRECTINPUT_DINPUT_LIBRARY + DIRECTINPUT_DXGUID_LIBRARY + DIRECTINPUT_DXERR_LIBRARY + DIRECTINPUT_INCLUDE_DIR) diff --git a/FindDirectShow.cmake b/FindDirectShow.cmake new file mode 100644 index 0000000..69c225b --- /dev/null +++ b/FindDirectShow.cmake @@ -0,0 +1,126 @@ +# - Find Microsoft DirectShow sample files, library, and headers. +# +# DIRECTSHOW_INCLUDE_DIRS - where to find needed include file +# DIRECTSHOW_BASECLASS_DIR- Directory containing the DirectShow baseclass sample code. +# DIRECTSHOW_FOUND - True if DirectShow found. +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Initially in VRPN - Distributed under the Boost Software License, Version 1.0. +# +# Almost entirely re-written by: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Look for one of the sample files. + +find_package(WindowsSDK) +find_package(DirectX QUIET) + +set(DIRECTSHOW_WINDOWSSDK_ROOT + "${DIRECTSHOW_WINDOWSSDK_ROOT}" + CACHE + PATH + "A specific Windows SDK to use for DirectShow.") + +if(MSVC AND CMAKE_CL_64) + set(DIRECTSHOW_LIB_SUBDIR /x64) +else() + set(DIRECTSHOW_LIB_SUBDIR) +endif() + +set(_acceptable_winsdk) +if(WINDOWSSDK_FOUND) + foreach(_sdkdir ${WINDOWSSDK_DIRS}) + if(EXISTS "${_sdkdir}/Samples/Multimedia/DirectShow/BaseClasses/streams.h" + AND EXISTS "${_sdkdir}/Lib${DIRECTSHOW_LIB_SUBDIR}/strmiids.lib" + AND EXISTS "${_sdkdir}/Include/DShow.h") + list(APPEND _acceptable_winsdk "${_sdkdir}") + endif() + endforeach() +endif() + +find_path(DIRECTSHOW_BASECLASS_DIR + NAMES + streams.h + HINTS + "${DIRECTSHOW_WINDOWSSDK_ROOT}" + PATHS + ${_acceptable_winsdk} + PATH_SUFFIXES + "Samples/Multimedia/DirectShow/BaseClasses") + +find_path(DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR + NAMES + DShow.h + HINTS + "${DIRECTSHOW_WINDOWSSDK_ROOT}" + PATHS + ${_acceptable_winsdk} + PATH_SUFFIXES + "Include") + +# This one we can grab from another SDK version. +find_path(DIRECTSHOW_QEDIT_INCLUDE_DIR + NAMES + qedit.h + HINTS + "${DIRECTSHOW_WINDOWSSDK_ROOT}" + PATHS + ${WINDOWSSDK_DIRS} + PATH_SUFFIXES + "Include") + +find_library(DIRECTSHOW_STRMIIDS_LIBRARY + NAMES + strmiids + HINTS + "${DIRECTSHOW_WINDOWSSDK_ROOT}" + PATHS + ${_acceptable_winsdk} + PATH_SUFFIXES + "Lib${DIRECTSHOW_LIB_SUBDIR}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(DirectShow + DEFAULT_MSG + DIRECTSHOW_BASECLASS_DIR + DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR + DIRECTSHOW_QEDIT_INCLUDE_DIR + DIRECTX_INCLUDE_DIR + DIRECTX_FOUND + DIRECTSHOW_STRMIIDS_LIBRARY) + +if(DIRECTSHOW_FOUND) + set(DIRECTSHOW_INCLUDE_DIRS + # Baseclass must be before SDK so it gets the correct refclock.h + "${DIRECTSHOW_BASECLASS_DIR}" + "${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}" + "${DIRECTX_INCLUDE_DIR}" + ) + if(EXISTS "${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}/atl/atlbase.h") + list(APPEND + DIRECTSHOW_INCLUDE_DIRS + "${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}/atl") + endif() + if(NOT "${DIRECTSHOW_QEDIT_INCLUDE_DIR}" STREQUAL "${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}") + # QEdit include dir might be an older SDK, so put it last. + list(APPEND DIRECTSHOW_INCLUDE_DIRS "${DIRECTSHOW_QEDIT_INCLUDE_DIR}") + endif() + + set(DIRECTSHOW_LIBRARIES "${DIRECTSHOW_STRMIIDS_LIBRARY}") + + mark_as_advanced(DIRECTSHOW_WINDOWSSDK_ROOT) +endif() + +mark_as_advanced(DIRECTSHOW_BASECLASS_DIR + DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR + DIRECTSHOW_QEDIT_INCLUDE_DIR + DIRECTSHOW_STRMIIDS_LIBRARY) diff --git a/FindDirectX.cmake b/FindDirectX.cmake new file mode 100644 index 0000000..2c44c7a --- /dev/null +++ b/FindDirectX.cmake @@ -0,0 +1,244 @@ +# - try to find part of DirectX SDK +# +# Cache Variables: (probably not for direct use in your scripts) +# DIRECTX_INCLUDE_DIR +# +# Variables you should use in your CMakeLists.txt: +# DIRECTX_DXGUID_LIBRARY +# DIRECTX_DXERR_LIBRARY +# DIRECTX_DINPUT_LIBRARY +# DIRECTX_DINPUT_INCLUDE_DIR +# DIRECTX_D3D9_LIBRARY +# DIRECTX_D3DXOF_LIBRARY +# DIRECTX_D3DX9_LIBRARIES +# DIRECTX_INCLUDE_DIRS +# DIRECTX_FOUND - if this is not true, do not attempt to use this library +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# SelectLibraryConfigurations +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + + +set(DIRECTX_ROOT_DIR + "${DIRECTX_ROOT_DIR}" + CACHE + PATH + "Root directory to search for DirectX") + +if(MSVC) + file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _PROG_FILES) + file(TO_CMAKE_PATH "$ENV{ProgramFiles(x86)}" _PROG_FILES_X86) + if(_PROG_FILES_X86) + set(_PROG_FILES "${_PROG_FILES_X86}") + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_lib_suffixes lib/x64 lib) + else() + set(_lib_suffixes lib/x86 lib) + endif() + macro(_append_dxsdk_in_inclusive_range _low _high) + if((NOT MSVC_VERSION LESS ${_low}) AND (NOT MSVC_VERSION GREATER ${_high})) + list(APPEND DXSDK_DIRS ${ARGN}) + endif() + endmacro() + _append_dxsdk_in_inclusive_range(1500 1600 "${_PROG_FILES}/Microsoft DirectX SDK (June 2010)") + _append_dxsdk_in_inclusive_range(1400 1600 + "${_PROG_FILES}/Microsoft DirectX SDK (February 2010)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2009)" + "${_PROG_FILES}/Microsoft DirectX SDK (March 2009)" + "${_PROG_FILES}/Microsoft DirectX SDK (November 2008)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2008)" + "${_PROG_FILES}/Microsoft DirectX SDK (June 2008)" + "${_PROG_FILES}/Microsoft DirectX SDK (March 2008)") + _append_dxsdk_in_inclusive_range(1310 1500 + "${_PROG_FILES}/Microsoft DirectX SDK (November 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (June 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (April 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (February 2007)" + "${_PROG_FILES}/Microsoft DirectX SDK (December 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (October 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (August 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (June 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (April 2006)" + "${_PROG_FILES}/Microsoft DirectX SDK (February 2006)") + + file(TO_CMAKE_PATH "$ENV{DXSDK_DIR}" ENV_DXSDK_DIR) + if(ENV_DXSDK_DIR) + list(APPEND DXSDK_DIRS ${ENV_DXSDK_DIR}) + endif() +else() + set(_lib_suffixes lib) + set(DXSDK_DIRS /mingw) +endif() + +find_path(DIRECTX_INCLUDE_DIR + NAMES + dxdiag.h + dinput.h + dxerr8.h + PATHS + ${DXSDK_DIRS} + HINTS + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + include) +find_path(DIRECTX_DINPUT_INCLUDE_DIR + NAMES + dinput.h + PATHS + ${DXSDK_DIRS} + HINTS + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + include) + +find_library(DIRECTX_DXGUID_LIBRARY + NAMES + dxguid + PATHS + ${DXSDK_DIRS} + HINTS + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +if(DIRECTX_DXGUID_LIBRARY) + get_filename_component(_dxsdk_lib_dir ${DIRECTX_DXGUID_LIBRARY} PATH) +endif() + +find_library(DIRECTX_DINPUT_LIBRARY + NAMES + dinput8 + dinput + PATHS + ${DXSDK_DIRS} + HINTS + "${_dxsdk_lib_dir}" + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +find_library(DIRECTX_DXERR_LIBRARY + NAMES + dxerr + dxerr9 + dxerr8 + PATHS + ${DXSDK_DIRS} + HINTS + "${_dxsdk_lib_dir}" + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +find_library(DIRECTX_D3D9_LIBRARY + NAMES + d3d9 + PATHS + ${DXSDK_DIRS} + HINTS + "${_dxsdk_lib_dir}" + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +find_library(DIRECTX_D3DXOF_LIBRARY + NAMES + d3dxof + PATHS + ${DXSDK_DIRS} + HINTS + "${_dxsdk_lib_dir}" + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +find_library(DIRECTX_D3DX9_LIBRARY_RELEASE + NAMES + d3dx9 + PATHS + ${DXSDK_DIRS} + HINTS + "${_dxsdk_lib_dir}" + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +find_library(DIRECTX_D3DX9_LIBRARY_DEBUG + NAMES + d3dx9d + PATHS + ${DXSDK_DIRS} + HINTS + "${_dxsdk_lib_dir}" + "${DIRECTX_ROOT_DIR}" + PATH_SUFFIXES + ${_lib_suffixes}) + +include(SelectLibraryConfigurations) +select_library_configurations(DIRECTX_D3DX9) + +set(DIRECTX_EXTRA_CHECK) +if(DIRECTX_INCLUDE_DIR) + if(MSVC80) + set(DXSDK_DEPRECATION_BUILD 1962) + endif() + + if(DXSDK_DEPRECATION_BUILD) + include(CheckCSourceCompiles) + set(_dinput_old_includes ${CMAKE_REQUIRED_INCLUDES}) + set(CMAKE_REQUIRED_INCLUDES "${DIRECTX_INCLUDE_DIR}") + check_c_source_compiles(" + #include + #if _DXSDK_BUILD_MAJOR >= ${DXSDK_DEPRECATION_BUILD} + #error + #else + int main(int argc, char * argv[]) { + return 0; + } + " + DIRECTX_SDK_SUPPORTS_COMPILER) + set(DIRECTX_EXTRA_CHECK DIRECTX_SDK_SUPPORTS_COMPILER) + set(CMAKE_REQUIRED_INCLUDES "${_dinput_old_includes}") + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(DirectX + DEFAULT_MSG + DIRECTX_DXGUID_LIBRARY + DIRECTX_DINPUT_LIBRARY + DIRECTX_DXERR_LIBRARY + DIRECTX_INCLUDE_DIR + ${DIRECTX_EXTRA_CHECK}) + +if(DIRECTX_FOUND) + set(DIRECTX_LIBRARIES + "${DIRECTX_DXGUID_LIBRARY}" + "${DIRECTX_DXERR_LIBRARY}" + "${DIRECTX_DINPUT_LIBRARY}") + + set(DIRECTX_INCLUDE_DIRS "${DIRECTX_INCLUDE_DIR}") + + mark_as_advanced(DIRECTX_ROOT_DIR) +endif() + +mark_as_advanced(DIRECTX_DINPUT_LIBRARY + DIRECTX_DXGUID_LIBRARY + DIRECTX_DXERR_LIBRARY + DIRECTX_D3D9_LIBRARY + DIRECTX_D3DXOF_LIBRARY + DIRECTX_D3DX9_LIBRARY_RELEASE + DIRECTX_D3DX9_LIBRARY_DEBUG + DIRECTX_INCLUDE_DIR) diff --git a/FindGDB.cmake b/FindGDB.cmake index a5f743d..e7caa19 100644 --- a/FindGDB.cmake +++ b/FindGDB.cmake @@ -36,17 +36,31 @@ find_program(GDB_COMMAND libexec) if(GDB_COMMAND) - execute_process(COMMAND gdb --version - COMMAND head -n 1 - OUTPUT_VARIABLE GDB_VERSION + execute_process(COMMAND + gdb + --version + COMMAND + head + -n + 1 + OUTPUT_VARIABLE + GDB_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX REPLACE "[^0-9]*([0-9]+[0-9.]*).*" "\\1" GDB_VERSION "${GDB_VERSION}") + string(REGEX + REPLACE + "[^0-9]*([0-9]+[0-9.]*).*" + "\\1" + GDB_VERSION + "${GDB_VERSION}") endif() # handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if # all listed variables are TRUE include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GDB DEFAULT_MSG GDB_COMMAND GDB_VERSION) +find_package_handle_standard_args(GDB + DEFAULT_MSG + GDB_COMMAND + GDB_VERSION) if(GDB_FOUND) mark_as_advanced(GDB_ROOT_DIR) diff --git a/FindGHOST.cmake b/FindGHOST.cmake index fbfaa52..71f17ee 100644 --- a/FindGHOST.cmake +++ b/FindGHOST.cmake @@ -40,6 +40,7 @@ find_path(GHOST_INCLUDE_DIR find_library(GHOST_LIBRARY GHOST40 + GHOST31 PATHS ${_dirs} HINTS @@ -47,20 +48,27 @@ find_library(GHOST_LIBRARY PATH_SUFFIXES lib) -if(MSVC_VERSION GREATER 1300) - # .NET and newer: fake the STL headers - get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH) - set(GHOST_STL_INCLUDE_DIR "${_moddir}/ghost-fake-stl") +if(MSVC) + if(MSVC_VERSION GREATER 1300) + # .NET and newer: fake the STL headers + get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH) + set(GHOST_STL_INCLUDE_DIR "${_moddir}/ghost-fake-stl") + else() + # 6.0 and earlier - use GHOST-provided STL + find_path(GHOST_STL_INCLUDE_DIR + vector.h + PATHS + ${_dirs} + HINTS + "${GHOST_ROOT_DIR}" + "${GHOST_INCLUDE_DIR}" + PATH_SUFFIXES + external/stl + stl) + endif() + set(_deps_check GHOST_STL_INCLUDE_DIR) else() - # 6.0 and earlier - use GHOST-provided STL - find_path(GHOST_STL_INCLUDE_DIR - vector.h - PATHS - ${_dirs} - HINTS - "${GHOST_ROOT_DIR}" - PATH_SUFFIXES - external/stl) + set(_deps_check) endif() # handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if @@ -69,18 +77,14 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GHOST DEFAULT_MSG GHOST_LIBRARY - GHOST_STL_INCLUDE_DIR + ${_deps_check} GHOST_INCLUDE_DIR) if(GHOST_FOUND) set(GHOST_LIBRARIES "${GHOST_LIBRARY}") - set(GHOST_INCLUDE_DIRS - "${GHOST_STL_INCLUDE_DIR}" - "${GHOST_INCLUDE_DIR}") + set(GHOST_INCLUDE_DIRS "${GHOST_INCLUDE_DIR}") mark_as_advanced(GHOST_ROOT_DIR) endif() -mark_as_advanced(GHOST_LIBRARY - GHOST_STL_INCLUDE_DIR - GHOST_INCLUDE_DIR) +mark_as_advanced(GHOST_LIBRARY GHOST_STL_INCLUDE_DIR GHOST_INCLUDE_DIR) diff --git a/FindGMTL.cmake b/FindGMTL.cmake index 173d314..bdc23e4 100644 --- a/FindGMTL.cmake +++ b/FindGMTL.cmake @@ -8,7 +8,7 @@ # Useful configuration variables you might want to add to your cache: # GMTL_ROOT_DIR - A directory prefix to search # (a path that contains include/ as a subdirectory) -# GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.6.2) +# GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.7.0) # to use when constructing search names and paths # # This script will use Flagpoll, if found, to provide hints to the location @@ -24,11 +24,11 @@ # and trigger an automatic re-run. # # Original Author: -# 2009-2010 Ryan Pavlik +# 2009-2012 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # -# Copyright Iowa State University 2009-2010. +# Copyright Iowa State University 2009-2012. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) @@ -41,6 +41,7 @@ include(CheckVersion) set(GMTL_VERSIONS ${GMTL_ADDITIONAL_VERSIONS} + 0.7.0 0.6.2 0.6.1 0.6.0 diff --git a/FindGadgeteer20.cmake b/FindGadgeteer20.cmake index 9f8ed58..f6f3b44 100644 --- a/FindGadgeteer20.cmake +++ b/FindGadgeteer20.cmake @@ -37,11 +37,15 @@ # Brandon Newendorp set(_HUMAN "Gadgeteer 2.0") -set(_RELEASE_NAMES gadget-2_0 libgadget-2_0 gadget-2_0_0) -set(_DEBUG_NAMES gadget_d-2_0 libgadget_d-2_0 gadget_d-2_0_0) +set(_FP_PKG_NAME gadgeteer) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 2_0 2_0_0 2_0_1 2_0_2) + list(APPEND _RELEASE_NAMES gadget-${VER}) + list(APPEND _DEBUG_NAMES gadget_d-${VER}) +endforeach() set(_DIR gadgeteer-2.0) set(_HEADER gadget/gadgetConfig.h) -set(_FP_PKG_NAME gadgeteer) include(SelectLibraryConfigurations) include(CreateImportedTarget) diff --git a/FindIDLJ.cmake b/FindIDLJ.cmake new file mode 100644 index 0000000..04def22 --- /dev/null +++ b/FindIDLJ.cmake @@ -0,0 +1,92 @@ +# - try to find Java's IDLJ Interface Definition Language compiler. +# +# Ideally used with CMake 2.8.5 or newer for Java support using FindJava.cmake +# and UseJava.cmake +# +# Variables: +# Java_IDLJ_COMMAND, executable for idlj +# IDLJ_FOUND, If false, do not try to use this +# +# Function: +# java_idlj(varname idlfile [extra idlj args]) - Generates +# the Java source files from the IDL file you indicate, and +# appends filenames suitable to add to a add_jar() call to the +# variable you specified. +# +# Because the files generated from an IDL file are not entirely predictable, +# java_idlj runs idlj in the cmake step, rather than the build step, and triggers +# a CMake re-run when an idl file is modified. Already up-to-date generated source +# is not re-generated, however. +# +# Files are generated in a directory created specifically for +# the particular IDL file and the particular call, in the build directory - +# there should be no worries about overwriting files or picking up too much +# with the wildcard. +# +# You may wish to add the IDL file to your list of sources if you want it +# to appear in your IDE, but it is not necessary. +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(NOT JAVA_FOUND) + find_package(Java QUIET) +endif() + +if(JAVA_FOUND) + get_filename_component(JAVA_BIN_DIR "${Java_JAVAC_EXECUTABLE}" PATH) + find_program(Java_IDLJ_COMMAND + idlj + HINTS + ${JAVA_BIN_DIR} + ) +endif() + +# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(IDLJ + DEFAULT_MSG + Java_IDLJ_COMMAND + JAVA_FOUND) + +if(IDLJ_FOUND) + function(java_idlj _varname _idlfile) + # Get some unique value we can use in a directory name + # TODO would be better to somehow munge the full path relative to CMAKE_CURRENT_SOURCE_DIR + # in case somebody has multiple idl files with the same name + get_filename_component(_idl_name "${_idlfile}" NAME_WE) + get_filename_component(_idl_abs "${_idlfile}" ABSOLUTE) + + # Compute directory name and stamp filename + set(outdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/idlj/${_idl_name}.dir") + set(stampfile "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/idlj/${_idl_name}.stamp") + + # Force re-cmake if idl file changes + configure_file("${_idl_abs}" "${stampfile}" COPY_ONLY) + + if((NOT EXISTS "${outdir}") OR ("${_idl_abs}" IS_NEWER_THAN "${outdir}")) + file(REMOVE_RECURSE "${outdir}") + message(STATUS "Processing ${_idlfile} with Java's idlj") + execute_process(COMMAND + "${Java_IDLJ_COMMAND}" -fclient -fallTIE -td "${outdir}" ${ARGN} "${_idlfile}" + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + file(GLOB_RECURSE _idl_output "${outdir}/*") + + set(${_varname} ${_idl_output} PARENT_SCOPE) + + # Clean up after ourselves on make clean + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outdir}" "${stampfile}") + endfunction() +endif() + +mark_as_advanced(Java_IDLJ_COMMAND) diff --git a/FindJCCL14.cmake b/FindJCCL14.cmake index 3d8c93d..147bb01 100644 --- a/FindJCCL14.cmake +++ b/FindJCCL14.cmake @@ -37,11 +37,15 @@ set(_HUMAN "JCCL 1.4") -set(_RELEASE_NAMES jccl-1_4 libjccl-1_4 jccl-1_4_0) -set(_DEBUG_NAMES jccl_d-1_4 libjccl_d-1_4 jccl_d-1_4_0) +set(_FP_PKG_NAME jccl) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 1_4 1_4_0 1_4_1 1_4_2) + list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER}) + list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER}) +endforeach() set(_DIR jccl-1.4) set(_HEADER jccl/jcclConfig.h) -set(_FP_PKG_NAME jccl) include(SelectLibraryConfigurations) include(CreateImportedTarget) diff --git a/FindJtTk.cmake b/FindJtTk.cmake index 542e6b5..9ef2141 100644 --- a/FindJtTk.cmake +++ b/FindJtTk.cmake @@ -144,13 +144,15 @@ elseif(UNIX) string(TOLOWER "${CMAKE_SYSTEM_NAME}" _sysname) file(TO_CMAKE_PATH "$ENV{JTTK_DEV_PATH}" _envloc) prefix_list_glob(_jttklibs - "lib/${_sysname}_${BITS}${_compiler}/libJtTk*" + "/lib/${_sysname}_${BITS}${_compiler}/libJtTk*" + "${JTTK_ROOT_DIR}" "/usr/" "/usr/local/" "/usr/local/siemens/" "/usr/local/ugs/") prefix_list_glob(_jttklibs2 - "dev/lib/${_sysname}_${BITS}${_compiler}/libJtTk*" + "/dev/lib/${_sysname}_${BITS}${_compiler}/libJtTk*" + "${JTTK_ROOT_DIR}" "/usr/" "/usr/local/" "/usr/local/siemens/" diff --git a/FindLibusb1.cmake b/FindLibusb1.cmake index a61c478..eb3f35a 100644 --- a/FindLibusb1.cmake +++ b/FindLibusb1.cmake @@ -29,7 +29,7 @@ set(LIBUSB1_ROOT_DIR CACHE PATH "Root directory to search for libusb-1") - + if(WIN32) include(ProgramFilesGlob) program_files_fallback_glob(_dirs "LibUSB-Win32") @@ -42,7 +42,7 @@ if(WIN32) set(_lib_suffixes lib/msvc) elseif(COMPILER_IS_GNUCXX) set(_lib_suffixes lib/gcc) - endif() + endif() endif() else() set(_lib_suffixes) @@ -81,11 +81,9 @@ find_package_handle_standard_args(Libusb1 LIBUSB1_INCLUDE_DIR) if(LIBUSB1_FOUND) - set(LIBUSB1_LIBRARIES - "${LIBUSB1_LIBRARY}") + set(LIBUSB1_LIBRARIES "${LIBUSB1_LIBRARY}") - set(LIBUSB1_INCLUDE_DIRS - "${LIBUSB1_INCLUDE_DIR}") + set(LIBUSB1_INCLUDE_DIRS "${LIBUSB1_INCLUDE_DIR}") mark_as_advanced(LIBUSB1_ROOT_DIR) endif() diff --git a/FindLyX.cmake b/FindLyX.cmake index 4dae864..7ec33b7 100644 --- a/FindLyX.cmake +++ b/FindLyX.cmake @@ -65,9 +65,7 @@ mark_as_advanced(LYX_COMMAND) function(lyx_export _format _extension _outvar) set(_nowhere) set(_curdest _nowhere) - set(_val_args - EXTRA_DEPS - INPUT) + set(_val_args EXTRA_DEPS INPUT) set(_bool_args OUTPUT_TO_SOURCE_DIR) foreach(_arg ${_val_args} ${_bool_args}) set(${_arg}) @@ -99,7 +97,7 @@ function(lyx_export _format _extension _outvar) else() set(_outname "${CMAKE_CURRENT_SOURCE_DIR}/${_base}.${_extension}") endif() - + list(APPEND _out "${_outname}") if(LYX_COMMAND) add_custom_command(OUTPUT "${_outname}" diff --git a/FindMarkdown.cmake b/FindMarkdown.cmake new file mode 100644 index 0000000..63b9305 --- /dev/null +++ b/FindMarkdown.cmake @@ -0,0 +1,56 @@ +# - try to find Markdown tool +# +# Cache Variables: +# MARKDOWN_EXECUTABLE +# +# Non-cache variables you might use in your CMakeLists.txt: +# MARKDOWN_FOUND +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2011 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2011. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +file(TO_CMAKE_PATH "${MARKDOWN_ROOT_DIR}" MARKDOWN_ROOT_DIR) +set(MARKDOWN_ROOT_DIR + "${MARKDOWN_ROOT_DIR}" + CACHE + PATH + "Path to search for Markdown") + +if(MARKDOWN_EXECUTABLE AND NOT EXISTS "${MARKDOWN_EXECUTABLE}") + set(MARKDOWN_EXECUTABLE "notfound" CACHE PATH FORCE "") +endif() + +# If we have a custom path, look there first. +if(MARKDOWN_ROOT_DIR) + find_program(MARKDOWN_EXECUTABLE + NAMES + markdown + PATHS + "${MARKDOWN_ROOT_DIR}" + PATH_SUFFIXES + bin + NO_DEFAULT_PATH) +endif() + +find_program(MARKDOWN_EXECUTABLE NAMES markdown) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Markdown + DEFAULT_MSG + MARKDOWN_EXECUTABLE) + +if(MARKDOWN_FOUND) + mark_as_advanced(MARKDOWN_ROOT_DIR) +endif() + +mark_as_advanced(MARKDOWN_EXECUTABLE) diff --git a/FindOpenCV.cmake b/FindOpenCV.cmake index 8acfef2..148af56 100644 --- a/FindOpenCV.cmake +++ b/FindOpenCV.cmake @@ -73,7 +73,11 @@ else() otherlibs/_graphics/include) # library linkdir suffixes appended to OPENCV_BASE_DIR - set(OPENCV_LIBDIR_SUFFIXES lib lib64 OpenCV/lib otherlibs/_graphics/lib) + set(OPENCV_LIBDIR_SUFFIXES + lib + lib64 + OpenCV/lib + otherlibs/_graphics/lib) # diff --git a/FindOpenHaptics.cmake b/FindOpenHaptics.cmake index 918ca23..ea7b0f2 100644 --- a/FindOpenHaptics.cmake +++ b/FindOpenHaptics.cmake @@ -3,12 +3,16 @@ # Cache Variables: (probably not for direct use in your scripts) # HDAPI_INCLUDE_DIR # HDAPI_LIBRARY +# HDAPI_LIBRARY_RELEASE +# HDAPI_LIBRARY_DEBUG # HDAPI_HDU_INCLUDE_DIR # HDAPI_HDU_LIBRARY # HDAPI_HDU_LIBRARY_RELEASE # HDAPI_HDU_LIBRARY_DEBUG # HLAPI_INCLUDE_DIR # HLAPI_LIBRARY +# HLAPI_LIBRARY_RELEASE +# HLAPI_LIBRARY_DEBUG # HLAPI_HLU_INCLUDE_DIR # HLAPI_HLU_LIBRARY # HLAPI_HLU_LIBRARY_RELEASE @@ -40,7 +44,7 @@ # CMake 2.6.3 (uses "unset") # # Original Author: -# 2009-2010 Ryan Pavlik +# 2009-2012 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # @@ -77,8 +81,20 @@ set(_libsearchdirs) set(OPENHAPTICS_ENVIRONMENT) set(OPENHAPTICS_RUNTIME_LIBRARY_DIRS) +set(_dirs) +if(NOT "$ENV{OH_SDK_BASE}" STREQUAL "") + list(APPEND _dirs "$ENV{OH_SDK_BASE}") +elseif(NOT "$ENV{3DTOUCH_BASE}" STREQUAL "") + list(APPEND _dirs "$ENV{3DTOUCH_BASE}") +endif() if(WIN32) - program_files_fallback_glob(_dirs "/Sensable/3DTouch*/") + program_files_fallback_glob(_pfdirs "/Sensable/3DTouch*/") + foreach(_OH_DEFAULT_LOCATION "C:/OpenHaptics/3.1" "C:/OpenHaptics/Academic/3.1") + if(EXISTS "${_OH_DEFAULT_LOCATION}") + list(APPEND _dirs "${_OH_DEFAULT_LOCATION}") + endif() + endforeach() + set(_dirs "${_dirs};${_pfdirs}") if(MSVC60) set(_vc "vc6") elseif(MSVC70 OR MSVC71) @@ -160,12 +176,26 @@ find_path(HDAPI_INCLUDE_DIR HINTS ${_incsearchdirs}) -find_library(HDAPI_LIBRARY +find_library(HDAPI_LIBRARY_RELEASE NAMES HD + PATH_SUFFIXES + ReleaseAcademicEdition + Release HINTS ${_libsearchdirs}) +find_library(HDAPI_LIBRARY_DEBUG + NAMES + HD + PATH_SUFFIXES + DebugAcademicEdition + Debug + HINTS + ${_libsearchdirs}) + +select_library_configurations(HDAPI) + ### # HDAPI: HDU ### @@ -230,6 +260,7 @@ if(OPENHAPTICS_NESTED_TARGETS OR NOT HDAPI_HDU_LIBRARY) STRING "We will build the OpenHaptics HDU lib." FORCE) + set(HDAPI_HDU_LIBRARIES ${HDAPI_HDU_LIBRARY}) endif() endif() @@ -243,12 +274,25 @@ find_path(HLAPI_INCLUDE_DIR HINTS ${_incsearchdirs}) -find_library(HLAPI_LIBRARY +find_library(HLAPI_LIBRARY_RELEASE NAMES HL + PATH_SUFFIXES + ReleaseAcademicEdition + Release HINTS ${_libsearchdirs}) +find_library(HLAPI_LIBRARY_DEBUG + NAMES + HL + PATH_SUFFIXES + DebugAcademicEdition + Debug + HINTS + ${_libsearchdirs}) + +select_library_configurations(HLAPI) ### # HLAPI: HLU @@ -314,63 +358,10 @@ if(OPENHAPTICS_NESTED_TARGETS OR NOT HLAPI_HLU_LIBRARY) STRING "We will build the OpenHaptics HLU lib." FORCE) + set(HLAPI_HLU_LIBRARIES ${HLAPI_HLU_LIBRARY}) endif() endif() - -### -# Unix: check stdc++ version -### - -if(UNIX - AND - HDAPI_LIBRARY - AND - HDAPI_PHANToMIO_LIBRARY - AND - HDAPI_INCLUDE_DIR) - find_file(OPENHAPTICS_LINKTEST_FILE - FindOpenHaptics.cpp - PATHS - ${CMAKE_MODULE_PATH}) - mark_as_advanced(OPENHAPTICS_LINKTEST_FILE) - - try_compile(_result - ${CMAKE_CURRENT_BINARY_DIR}/FindOpenHaptics - "${OPENHAPTICS_LINKTEST_FILE}" - CMAKE_FLAGS - "-DLINK_LIBRARIES=${HDAPI_LIBRARY}\;${HDAPI_PHANToMIO_LIBRARY} -DINCLUDE_DIRECTORIES=${HDAPI_INCLUDE_DIR}") - if(NOT _result) - set(OPENHAPTICS_LIBSTDCPP_DIR - "${OPENHAPTICS_LIBSTDCPP_DIR}" - CACHE - PATH - "The path to search for a libstdc++ with GLIBCXX_3.4.9 defined.") - if(OPENHAPTICS_LIBSTDCPP_DIR) - mark_as_advanced(OPENHAPTICS_LIBSTDCPP_DIR) - endif() - find_library(OPENHAPTICS_LIBSTDCPP_LIBRARY - libstdc++ - PATHS - ${OPENHAPTICS_LIBSTDCPP_DIR} - NO_DEFAULT_PATH) - if(OPENHAPTICS_LIBSTDCPP_LIBRARY) - mark_as_advanced(OPENHAPTICS_LIBSTDCPP_LIBRARY) - endif() - list(APPEND _deps_check OPENHAPTICS_LIBSTDCPP_LIBRARY) - list(APPEND _deps_libs "${OPENHAPTICS_LIBSTDCPP_LIBRARY}") - - get_filename_component(_stdcppdir - "${OPENHAPTICS_LIBSTDCPP_LIBRARY}" - PATH) - list(APPEND - OPENHAPTICS_ENVIRONMENT - "LD_LIBRARY_PATH=${_stdcppdir}:$LD_LIBRARY_PATH") - list(APPEND OPENHAPTICS_RUNTIME_LIBRARY_DIRS "${_stdcppdir}") - endif() -endif() - - ### # Add dependencies: Libraries ### @@ -448,10 +439,12 @@ if(OPENHAPTICS_FOUND) set(OPENHAPTICS_LIBRARY_DIRS) foreach(_lib ${_deps_check} - HDAPI_LIBRARY + HDAPI_LIBRARY_RELEASE + HDAPI_LIBRARY_DEBUG HDAPI_HDU_LIBRARY_RELEASE HDAPI_HDU_LIBRARY_DEBUG - HLAPI_LIBRARY + HLAPI_LIBRARY_RELEASE + HLAPI_LIBRARY_DEBUG HLAPI_HLU_LIBRARY_RELEASE HLAPI_HLU_LIBRARY_DEBUG) get_filename_component(_libdir ${${_lib}} PATH) @@ -475,12 +468,14 @@ if(OPENHAPTICS_FOUND) endif() mark_as_advanced(HDAPI_INCLUDE_DIR - HDAPI_LIBRARY + HDAPI_LIBRARY_RELEASE + HDAPI_LIBRARY_DEBUG HDAPI_HDU_INCLUDE_DIR HDAPI_HDU_LIBRARY_RELEASE HDAPI_HDU_LIBRARY_DEBUG HLAPI_INCLUDE_DIR - HLAPI_LIBRARY + HLAPI_LIBRARY_RELEASE + HLAPI_LIBRARY_DEBUG HLAPI_HLU_INCLUDE_DIR HLAPI_HLU_LIBRARY_RELEASE HLAPI_HLU_LIBRARY_DEBUG) diff --git a/FindOpenHaptics.cpp b/FindOpenHaptics.cpp deleted file mode 100644 index fe9edbb..0000000 --- a/FindOpenHaptics.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/** - * \file FindOpenHaptics.cpp - * \brief C++ source file used by CMake module FindOpenHaptics.cmake - * - * \author - * Ryan Pavlik, 2009-2010 - * - * http://academic.cleardefinition.com/ - * - * Used to check stdc++ version - * - */ - -#include - -int main(int argc, char* argv[]) { - return 0; -} diff --git a/FindPerformer.cmake b/FindPerformer.cmake new file mode 100644 index 0000000..db2b9c5 --- /dev/null +++ b/FindPerformer.cmake @@ -0,0 +1,153 @@ +# - try to find the OpenGL Performer library +# +# Users may optionally supply: +# PERFORMER_ROOT_DIR - a prefix to start searching. +# +# Cache Variables: (probably not for direct use in your scripts) +# PERFORMER_INCLUDE_DIR +# PERFORMER_LIBRARY +# PERFORMER_PFUI_LIBRARY - doesn't get included in PERFORMER_LIBRARIES +# PERFORMER_PFDU_UTIL_LIBRARY - doesn't get included in PERFORMER_LIBRARIES +# PERFORMER_PFV_LIBRARY - doesn't get included in PERFORMER_LIBRARIES +# +# Non-cache variables you might use in your CMakeLists.txt: +# PERFORMER_FOUND +# PERFORMER_INCLUDE_DIRS +# PERFORMER_LIBRARIES +# PERFORMER_RUNTIME_LIBRARY_DIRS +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(PERFORMER_ROOT_DIR + "${PERFORMER_ROOT_DIR}" + CACHE + PATH + "Path to search for OpenGL Performer library") + + +find_path(PERFORMER_INCLUDE_DIR + NAMES + pf.h + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + include + include/Performer + Performer + PATHS + $ENV{PFROOT}) +mark_as_advanced(PERFORMER_INCLUDE_DIR) + +if(WIN32) + set(_pf_libnameprefix lib) + find_library(PERFORMER_PFDU_UTIL_LIBRARY + NAMES + libpfdu-util + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + lib + PATHS + $ENV{PFROOT}) +else() + set(_pf_libnameprefix) + find_library(PERFORMER_PFDU_LIBRARY + NAMES + pfdu + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + lib + PATHS + $ENV{PFROOT}) + find_library(PERFORMER_PFUTIL_LIBRARY + NAMES + pfutil + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + lib + PATHS + $ENV{PFROOT}) + if(PERFORMER_PFDU_LIBRARY AND PERFORMER_PFUTIL_LIBRARY) + set(PERFORMER_PFDU_UTIL_LIBRARY + ${PERFORMER_PFDU_LIBRARY} + ${PERFORMER_PFUTIL_LIBRARY}) + endif() +endif() + +find_library(PERFORMER_LIBRARY + NAMES + ${_pf_libnameprefix}pf + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + lib + PATHS + $ENV{PFROOT}) +find_library(PERFORMER_PFUI_LIBRARY + NAMES + ${_pf_libnameprefix}pfui + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + lib + PATHS + $ENV{PFROOT}) +find_library(PERFORMER_PFV_LIBRARY + NAMES + ${_pf_libnameprefix}pfv + HINTS + "${PERFORMER_ROOT_DIR}" + PATH_SUFFIXES + lib + PATHS + $ENV{PFROOT}) + +### +# Prereq: OpenGL +### + +find_package(OpenGL QUIET) + +# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Performer + DEFAULT_MSG + PERFORMER_LIBRARY + PERFORMER_PFUI_LIBRARY + PERFORMER_PFV_LIBRARY + PERFORMER_PFDU_UTIL_LIBRARY + PERFORMER_INCLUDE_DIR + OPENGL_FOUND) + +if(PERFORMER_FOUND) + set(PERFORMER_INCLUDE_DIRS + "${OPENGL_INCLUDE_DIR}" + "${PERFORMER_INCLUDE_DIR}") + if(PERFORMER_INCLUDE_DIR MATCHES ".*Performer.*") + list(APPEND PERFORMER_INCLUDE_DIRS "${PERFORMER_INCLUDE_DIR}/..") + endif() + set(PERFORMER_LIBRARIES "${OPENGL_LIBRARY}" "${PERFORMER_LIBRARY}") + mark_as_advanced(PERFORMER_ROOT_DIR) +endif() + +mark_as_advanced(PERFORMER_LIBRARY + PERFORMER_PFUI_LIBRARY + PERFORMER_PFV_LIBRARY + PERFORMER_PFDU_LIBRARY + PERFORMER_PFUTIL_LIBRARY + PERFORMER_PFDU_UTIL_LIBRARY + PERFORMER_INCLUDE_DIR) diff --git a/FindPerlModules.cmake b/FindPerlModules.cmake new file mode 100644 index 0000000..f09ff85 --- /dev/null +++ b/FindPerlModules.cmake @@ -0,0 +1,78 @@ +# - try to find perl modules, passed as COMPONENTS +# +# Non-cache variable you might use in your CMakeLists.txt: +# PERLMODULES_FOUND +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(NOT PERL_FOUND) + find_package(Perl QUIET) +endif() + +set(_deps_check) +if(PERL_FOUND) + foreach(module ${PerlModules_FIND_COMPONENTS}) + string(REPLACE "::" "/" modfilename "${module}.pm") + string(REPLACE "::" "_" modvarname "PERLMODULES_${module}_MODULE") + string(TOUPPER "${modvarname}" modvarname) + list(APPEND _deps_check ${modvarname}) + if(NOT ${modvarname}) + if(NOT PerlModules_FIND_QUIETLY) + message(STATUS "Checking for perl module ${module}") + endif() + execute_process(COMMAND + "${PERL_EXECUTABLE}" + "-e" + "use ${module}; print \$INC{\"${modfilename}\"}" + RESULT_VARIABLE result_code + OUTPUT_VARIABLE filename + ERROR_VARIABLE error_info + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(result_code EQUAL 0) + if(NOT PerlModules_FIND_QUIETLY) + message(STATUS + "Checking for perl module ${module} - found at ${filename}") + endif() + set(${modvarname} + "${filename}" + CACHE + FILEPATH + "Location found for module ${module}" + FORCE) + mark_as_advanced(${modvarname}) + else() + if(NOT PerlModules_FIND_QUIETLY) + message(STATUS "Checking for perl module ${module} - failed") + endif() + set(${modvarname} + "NOTFOUND" + CACHE + FILEPATH + "No location found for module ${module}" + FORCE) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Perl module ${module} exists failed with the following error output:\n" + "${error_info}\n\n") + endif() + endif() + endforeach() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PerlModules + DEFAULT_MSG + PERL_FOUND + ${_deps_check}) + diff --git a/FindQVRPN.cmake b/FindQVRPN.cmake new file mode 100644 index 0000000..37e1af2 --- /dev/null +++ b/FindQVRPN.cmake @@ -0,0 +1,81 @@ +# - try to find QVRPN library +# +# Of course, you may also just choose to make QVRPN a submodule of your +# project itself. +# +# Cache Variables: +# QVRPN_LIBRARY +# QVRPN_INCLUDE_DIR +# +# Non-cache variables you might use in your CMakeLists.txt: +# QVRPN_FOUND +# QVRPN_LIBRARIES +# QVRPN_INCLUDE_DIRS +# +# QVRPN_ROOT_DIR is searched preferentially for these files +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Refactored from FindVRPN.cmake by: +# Juan Sebastian Casallas +# +# FindVRPN.cmake Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(QVRPN_ROOT_DIR + "${QVRPN_ROOT_DIR}" + CACHE + PATH + "Root directory to search for QVRPN") + +if(CMAKE_SIZEOF_VOID_P MATCHES "8") + set(_LIBSUFFIXES /lib64 /lib) +else() + set(_LIBSUFFIXES /lib) +endif() + +### +# Configure QVRPN +### + +find_path(QVRPN_INCLUDE_DIR + NAMES + vrpn_QMainloopContainer.h + PATH_SUFFIXES + include + include/qvrpn + HINTS + "${QVRPN_ROOT_DIR}") + +find_library(QVRPN_LIBRARY + NAMES + qvrpn + PATH_SUFFIXES + ${_libsuffixes} + HINTS + "${QVRPN_ROOT_DIR}") + +# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(QVRPN + DEFAULT_MSG + QVRPN_LIBRARY + QVRPN_INCLUDE_DIR) + +if(QVRPN_FOUND) + set(QVRPN_INCLUDE_DIRS "${QVRPN_INCLUDE_DIR}") + set(QVRPN_LIBRARIES "${QVRPN_LIBRARY}") + + mark_as_advanced(QVRPN_ROOT_DIR) +endif() + +mark_as_advanced(QVRPN_LIBRARY QVRPN_INCLUDE_DIR) diff --git a/FindSonix14.cmake b/FindSonix14.cmake index cf86eb3..692216f 100644 --- a/FindSonix14.cmake +++ b/FindSonix14.cmake @@ -37,11 +37,15 @@ set(_HUMAN "Sonix 1.4") -set(_RELEASE_NAMES sonix-1_4 libsonix-1_4 sonix-1_4_0) -set(_DEBUG_NAMES sonix_d-1_4 libsonix_d-1_4 sonix_d-1_4_0) +set(_FP_PKG_NAME sonix) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 1_4 1_4_0 1_4_1 1_4_2) + list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER}) + list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER}) +endforeach() set(_DIR sonix-1.4) set(_HEADER snx/sonix.h) -set(_FP_PKG_NAME sonix) include(SelectLibraryConfigurations) include(CreateImportedTarget) diff --git a/FindTR1.cmake b/FindTR1.cmake index 133ec78..82bb1db 100644 --- a/FindTR1.cmake +++ b/FindTR1.cmake @@ -70,7 +70,4 @@ endif() # handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if # all listed variables are TRUE include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(TR1 - DEFAULT_MSG - PLATFORM - ${_check}) +find_package_handle_standard_args(TR1 DEFAULT_MSG PLATFORM ${_check}) diff --git a/FindTweek14.cmake b/FindTweek14.cmake index ea0f3c9..c6e1e5b 100644 --- a/FindTweek14.cmake +++ b/FindTweek14.cmake @@ -37,11 +37,15 @@ set(_HUMAN "Tweek 1.4") -set(_RELEASE_NAMES tweek-1_4 libtweek-1_4 tweek-1_4_0) -set(_DEBUG_NAMES tweek_d-1_4 libtweek_d-1_4 tweek_d-1_4_0) +set(_FP_PKG_NAME sonix) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 1_4 1_4_0 1_4_1 1_4_2) + list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER}) + list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER}) +endforeach() set(_DIR tweek-1.4) set(_HEADER tweek/tweek.h) -set(_FP_PKG_NAME tweek) include(SelectLibraryConfigurations) include(CreateImportedTarget) diff --git a/FindVPR22.cmake b/FindVPR22.cmake index b34bd99..d9ab26f 100644 --- a/FindVPR22.cmake +++ b/FindVPR22.cmake @@ -40,11 +40,15 @@ # Brandon Newendorp set(_HUMAN "VPR 2.2") -set(_RELEASE_NAMES vpr-2_2 libvpr-2_2 vpr-2_2_0) -set(_DEBUG_NAMES vpr_d-2_2 libvpr_d-2_2 vpr_d-2_2_0) +set(_FP_PKG_NAME vpr) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 2_2 2_2_0 2_2_1 2_2_2) + list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER}) + list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER}) +endforeach() set(_DIR vpr-2.2) set(_HEADER vpr/vpr.h) -set(_FP_PKG_NAME vpr) include(SelectLibraryConfigurations) include(CreateImportedTarget) @@ -193,8 +197,9 @@ if(UNIX AND NOT WIN32) if(NOT APPLE) find_library(VPR22_libuuid_LIBRARY NAMES uuid) mark_as_advanced(VPR22_libuuid_LIBRARY) - list(APPEND _deps_check VPR22_libuuid_LIBRARY) - list(APPEND _deps_libs ${VPR22_libuuid_LIBRARY}) + if(VPR22_libuuid_LIBRARY) + list(APPEND _deps_libs ${VPR22_libuuid_LIBRARY}) + endif() endif() endif() diff --git a/FindVRJ30.cmake b/FindVRJ30.cmake index 91c260e..30091bc 100644 --- a/FindVRJ30.cmake +++ b/FindVRJ30.cmake @@ -45,11 +45,15 @@ set(_HUMAN "VR Juggler 3.0 Core") -set(_RELEASE_NAMES vrj-3_0 libvrj-3_0 vrj-3_0_0) -set(_DEBUG_NAMES vrj_d-3_0 libvrj_d-3_0 vrj_d-3_0_0) +set(_FP_PKG_NAME vrjuggler) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 3_0 3_0_0 3_0_1 3_0_2) + list(APPEND _RELEASE_NAMES vrj-${VER}) + list(APPEND _DEBUG_NAMES vrj_d-${VER}) +endforeach() set(_DIR vrjuggler-3.0) set(_HEADER vrj/Kernel/Kernel.h) -set(_FP_PKG_NAME vrjuggler) include(SelectLibraryConfigurations) include(CreateImportedTarget) diff --git a/FindVRJOGL30.cmake b/FindVRJOGL30.cmake index d89e93f..780e2c3 100644 --- a/FindVRJOGL30.cmake +++ b/FindVRJOGL30.cmake @@ -38,10 +38,14 @@ set(_HUMAN "VR Juggler 3.0 OpenGL Core") -set(_RELEASE_NAMES vrj_ogl-3_0 libvrj_ogl-3_0 vrj_ogl-3_0_0) -set(_DEBUG_NAMES vrj_ogl_d-3_0 libvrj_ogl_d-3_0 vrj_ogl_d-3_0_0) -set(_DIR vrjuggler-3.0) set(_FP_PKG_NAME vrjuggler-opengl) +set(_RELEASE_NAMES) +set(_DEBUG_NAMES) +foreach(VER 3_0 3_0_0 3_0_1 3_0_2) + list(APPEND _RELEASE_NAMES vrj_ogl-${VER}) + list(APPEND _DEBUG_NAMES vrj_ogl_d-${VER}) +endforeach() +set(_DIR vrjuggler-3.0) include(SelectLibraryConfigurations) include(CreateImportedTarget) diff --git a/FindVRJuggler.cmake b/FindVRJuggler.cmake index c6a66ad..490b959 100644 --- a/FindVRJuggler.cmake +++ b/FindVRJuggler.cmake @@ -171,7 +171,10 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(VRJuggler - DEFAULT_MSG VRJUGGLER_VERSION VRJUGGLER_LIBRARIES VRJUGGLER_FOUND) + DEFAULT_MSG + VRJUGGLER_VERSION + VRJUGGLER_LIBRARIES + VRJUGGLER_FOUND) if(VRJUGGLER_FOUND) mark_as_advanced(VRJUGGLER_ROOT_DIR) diff --git a/FindVRJuggler30.cmake b/FindVRJuggler30.cmake index 66382d8..097056d 100644 --- a/FindVRJuggler30.cmake +++ b/FindVRJuggler30.cmake @@ -334,6 +334,20 @@ if(VRJUGGLER30_FOUND) list(APPEND _plugin_dirs "${_libdir}/sonix-1.4/plugins/dbg") list(APPEND _plugin_dirs "${_libdir}/sonix-1.4/plugins/opt") endif() + + # Find directories of JCCL plugins + if(EXISTS "${_libdir}/jccl/plugins") + list(APPEND _plugin_dirs "${_libdir}/jccl/plugins") + elseif(EXISTS "${_libdir}/jccl-1.4/plugins") + list(APPEND _plugin_dirs "${_libdir}/jccl-1.4/plugins") + endif() + + # Find directories of VR Juggler plugins + if(EXISTS "${_libdir}/vrjuggler/plugins") + list(APPEND _plugin_dirs "${_libdir}/vrjuggler/plugins") + elseif(EXISTS "${_libdir}/vrjuggler-3.0/plugins") + list(APPEND _plugin_dirs "${_libdir}/vrjuggler-3.0/plugins") + endif() endforeach() # Grab the actual plugins @@ -341,7 +355,13 @@ if(VRJUGGLER30_FOUND) if(EXISTS "${_libdir}") list(APPEND VRJUGGLER30_RUNTIME_LIBRARY_DIRS "${_libdir}") file(GLOB _plugins "${_libdir}/*${CMAKE_SHARED_LIBRARY_SUFFIX}") - list(APPEND VRJUGGLER30_BUNDLE_PLUGINS ${_plugins}) + foreach(_plugin ${_plugins}) + if("${_plugin}" MATCHES "_d${CMAKE_SHARED_LIBRARY_SUFFIX}") + list(APPEND VRJUGGLER30_BUNDLE_PLUGINS_DEBUG ${_plugin}) + else() + list(APPEND VRJUGGLER30_BUNDLE_PLUGINS ${_plugin}) + endif() + endforeach() endif() endforeach() @@ -391,19 +411,23 @@ function(install_vrjuggler30_data_files prefix) install(FILES "${base}/calibration.table" DESTINATION "${DEST}") endfunction() -function(install_vrjuggler30_plugins prefix varForFilenames) - set(DEST "${prefix}") - - set(out) - foreach(plugin ${VRJUGGLER30_BUNDLE_PLUGINS}) +macro(_vrjuggler30_plugin_install _VAR) + foreach(plugin ${${_VAR}}) get_filename_component(full "${plugin}" ABSOLUTE) file(RELATIVE_PATH relloc "${VRJUGGLER30_VJ_BASE_DIR}" "${full}") set(filedest "${DEST}/${relloc}") get_filename_component(path "${filedest}" PATH) list(APPEND out "${filedest}") - install(FILES "${full}" DESTINATION "${path}") + install(FILES "${full}" DESTINATION "${path}" ${ARGN}) endforeach() +endmacro() +function(install_vrjuggler30_plugins prefix varForFilenames) + set(DEST "${prefix}") + + set(out) + _vrjuggler30_plugin_install(VRJUGGLER30_BUNDLE_PLUGINS) + _vrjuggler30_plugin_install(VRJUGGLER30_BUNDLE_PLUGINS_DEBUG CONFIGURATIONS DEBUG) set(${varForFilenames} ${out} PARENT_SCOPE) endfunction() diff --git a/FindVRPN.cmake b/FindVRPN.cmake index b2dabc6..2981fcd 100644 --- a/FindVRPN.cmake +++ b/FindVRPN.cmake @@ -7,8 +7,10 @@ # # Non-cache variables you might use in your CMakeLists.txt: # VRPN_FOUND -# VRPN_SERVER_LIBRARIES -# VRPN_LIBRARIES +# VRPN_SERVER_LIBRARIES - server libraries +# VRPN_LIBRARIES - client libraries +# VRPN_CLIENT_DEFINITIONS - definitions if you only use the client library +# VRPN_DEFINITIONS - Client-only definition if all we found was the client library. # VRPN_INCLUDE_DIRS # # VRPN_ROOT_DIR is searched preferentially for these files @@ -17,11 +19,11 @@ # FindPackageHandleStandardArgs (known included with CMake >=2.6.2) # # Original Author: -# 2009-2010 Ryan Pavlik +# 2009-2012 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # -# Copyright Iowa State University 2009-2010. +# Copyright Iowa State University 2009-2012. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) @@ -116,9 +118,19 @@ if(VRPN_FOUND) set(VRPN_LIBRARIES "${VRPN_LIBRARY}" ${_deps_libs}) set(VRPN_SERVER_LIBRARIES "${VRPN_SERVER_LIBRARY}" ${_deps_libs}) + if(VRPN_LIBRARY) + set(VRPN_CLIENT_DEFINITIONS -DVRPN_CLIENT_ONLY) + else() + unset(VRPN_CLIENT_DEFINITIONS) + endif() + + if(VRPN_LIBRARY AND NOT VRPN_SERVER_LIBRARY) + set(VRPN_DEFINITIONS -DVRPN_CLIENT_ONLY) + else() + unset(VRPN_DEFINITIONS) + endif() + mark_as_advanced(VRPN_ROOT_DIR) endif() -mark_as_advanced(VRPN_LIBRARY - VRPN_SERVER_LIBRARY - VRPN_INCLUDE_DIR) +mark_as_advanced(VRPN_LIBRARY VRPN_SERVER_LIBRARY VRPN_INCLUDE_DIR) diff --git a/FindViewPoint.cmake b/FindViewPoint.cmake new file mode 100644 index 0000000..a18b614 --- /dev/null +++ b/FindViewPoint.cmake @@ -0,0 +1,94 @@ +# - try to find Arrington Research ViewPoint EyeTracker SDK +# +# Cache Variables: (probably not for direct use in your scripts) +# VIEWPOINT_INCLUDE_DIR +# VIEWPOINT_LIBRARY +# VIEWPOINT_RUNTIME_LIBRARY +# +# Non-cache variables you might use in your CMakeLists.txt: +# VIEWPOINT_FOUND +# VIEWPOINT_INCLUDE_DIRS +# VIEWPOINT_LIBRARIES +# VIEWPOINT_RUNTIME_LIBRARIES - aka the dll for installing +# VIEWPOINT_RUNTIME_LIBRARY_DIRS +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(VIEWPOINT_ROOT_DIR + "${VIEWPOINT_ROOT_DIR}" + CACHE + PATH + "Directory to search for Arrington Research ViewPoint EyeTracker SDK") + +if(CMAKE_SIZEOF_VOID_P MATCHES "8") + set(_LIBSUFFIXES /lib64 /lib) +else() + set(_LIBSUFFIXES /lib) +endif() + +find_library(VIEWPOINT_LIBRARY + NAMES + VPX_InterApp + PATHS + "${VIEWPOINT_ROOT_DIR}" + PATH_SUFFIXES + "${_LIBSUFFIXES}") + +get_filename_component(_libdir "${VIEWPOINT_LIBRARY}" PATH) + +find_path(VIEWPOINT_INCLUDE_DIR + NAMES + vpx.h + HINTS + "${_libdir}" + PATHS + "${VIEWPOINT_ROOT_DIR}" + PATH_SUFFIXES + include/) + +set(_deps_check) +if(WIN32) + find_file(VIEWPOINT_RUNTIME_LIBRARY + NAMES + VPX_InterApp.dll + HINTS + "${_libdir}") + + set(VIEWPOINT_RUNTIME_LIBRARIES "${VIEWPOINT_RUNTIME_LIBRARY}") + get_filename_component(VIEWPOINT_RUNTIME_LIBRARY_DIRS + "${VIEWPOINT_RUNTIME_LIBRARY}" + PATH) + list(APPEND _deps_check VIEWPOINT_RUNTIME_LIBRARY) +else() + get_filename_component(VIEWPOINT_RUNTIME_LIBRARY_DIRS + "${VIEWPOINT_LIBRARY}" + PATH) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ViewPoint + DEFAULT_MSG + VIEWPOINT_LIBRARY + VIEWPOINT_INCLUDE_DIR + ${_deps_check}) + +if(VIEWPOINT_FOUND) + set(VIEWPOINT_LIBRARIES "${VIEWPOINT_LIBRARY}") + set(VIEWPOINT_INCLUDE_DIRS "${VIEWPOINT_INCLUDE_DIR}") + mark_as_advanced(VIEWPOINT_ROOT_DIR) +endif() + +mark_as_advanced(VIEWPOINT_INCLUDE_DIR + VIEWPOINT_LIBRARY + VIEWPOINT_RUNTIME_LIBRARY) diff --git a/FindWiiUse.cmake b/FindWiiUse.cmake index 80bc3b0..2657cbb 100644 --- a/FindWiiUse.cmake +++ b/FindWiiUse.cmake @@ -74,6 +74,8 @@ if(WIN32) PATH) list(APPEND _deps_check WIIUSE_RUNTIME_LIBRARY) else() + set(WIIUSE_RUNTIME_LIBRARY "${WIIUSE_LIBRARY}") + set(WIIUSE_RUNTIME_LIBRARIES "${WIIUSE_RUNTIME_LIBRARY}") get_filename_component(WIIUSE_RUNTIME_LIBRARY_DIRS "${WIIUSE_LIBRARY}" PATH) diff --git a/FindWinHID.cmake b/FindWinHID.cmake index 7ef08f7..2d91bb0 100644 --- a/FindWinHID.cmake +++ b/FindWinHID.cmake @@ -31,9 +31,10 @@ if(NOT WIN32) WIN32) return() endif() - -if( (NOT WINHID_ROOT_DIR) AND (NOT ENV{DDKROOT} STREQUAL "") ) - set(WINHID_ROOT_DIR "$ENV{DDKROOT}") +if(MSVC) + if( (NOT WINHID_ROOT_DIR) AND (NOT ENV{DDKROOT} STREQUAL "") ) + set(WINHID_ROOT_DIR "$ENV{DDKROOT}") + endif() endif() set(WINHID_ROOT_DIR "${WINHID_ROOT_DIR}" @@ -47,81 +48,109 @@ else() set(_arch i386) endif() -include(PrefixListGlob) -include(CleanDirectoryList) -prefix_list_glob(_prefixed "*/" "$ENV{SYSTEMDRIVE}/WinDDK/" "c:/WinDDK/") -clean_directory_list(_prefixed) +if(MSVC) + include(PrefixListGlob) + include(CleanDirectoryList) + prefix_list_glob(_prefixed + "*/" + "$ENV{SYSTEMDRIVE}/WinDDK/" + "c:/WinDDK/") + clean_directory_list(_prefixed) + find_library(WINHID_LIBRARY + NAMES + hid + libhid + HINTS + "${WINHID_ROOT_DIR}" + ${_prefixed} + PATH_SUFFIXES + "lib/w2k/${_arch}" # Win2k min requirement + "lib/wxp/${_arch}" # WinXP min requirement + "lib/wnet/${_arch}" # Win Server 2003 min requirement + "lib/wlh/${_arch}" # Win Vista ("Long Horn") min requirement + "lib/win7/${_arch}" # Win 7 min requirement + ) + # Might want to look close to the library first for the includes. + get_filename_component(_libdir "${WINHID_LIBRARY}" PATH) + get_filename_component(_basedir "${_libdir}/../../.." ABSOLUTE) -find_library(WINHID_LIBRARY - NAMES - hid - HINTS - "${WINHID_ROOT_DIR}" - ${_prefixed} - PATH_SUFFIXES - "lib/w2k/${_arch}" # Win2k min requirement - "lib/wxp/${_arch}" # WinXP min requirement - "lib/wnet/${_arch}" # Win Server 2003 min requirement - "lib/wlh/${_arch}" # Win Vista ("Long Horn") min requirement - "lib/win7/${_arch}" # Win 7 min requirement - ) - -# Might want to look close to the library first for the includes. -get_filename_component(_libdir "${WINHID_LIBRARY}" PATH) -get_filename_component(_basedir "${_libdir}/../../.." ABSOLUTE) - -find_path(WINHID_INCLUDE_DIR - NAMES - hidsdi.h - HINTS - "${_basedir}" - PATHS - "${WINHID_ROOT_DIR}" - PATH_SUFFIXES - inc/api - inc/w2k - inc/wxp - inc/wnet) - -find_path(WINHID_CRT_INCLUDE_DIR # otherwise you get weird compile errors - NAMES - stdio.h - HINTS - "${_basedir}" - PATHS - "${WINHID_ROOT_DIR}" - PATH_SUFFIXES - inc/crt - NO_DEFAULT_PATH) + find_path(WINHID_CRT_INCLUDE_DIR # otherwise you get weird compile errors + NAMES + stdio.h + HINTS + "${_basedir}" + PATHS + "${WINHID_ROOT_DIR}" + PATH_SUFFIXES + inc/crt + NO_DEFAULT_PATH) + find_path(WINHID_INCLUDE_DIR + NAMES + hidsdi.h + HINTS + "${_basedir}" + PATHS + "${WINHID_ROOT_DIR}" + PATH_SUFFIXES + inc/ddk + inc/api + inc/w2k + inc/wxp + inc/wnet) +else() + find_library(WINHID_LIBRARY + NAMES + libhid + HINTS + "${WINHID_ROOT_DIR}" + /mingw + PATH_SUFFIXES + lib + lib/w32api) + find_path(WINHID_INCLUDE_DIR + NAMES + hidsdi.h + PATHS + "${WINHID_ROOT_DIR}" + /mingw + PATH_SUFFIXES + include/w32api/ddk + include/ddk + ddk) +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(WinHID DEFAULT_MSG WINHID_LIBRARY - WINHID_INCLUDE_DIR - WINHID_CRT_INCLUDE_DIR) + WINHID_INCLUDE_DIR) if(WINHID_FOUND) - set(_winreq "Unknown") - if(WINHID_LIBRARY MATCHES "lib/w2k") - set(_winreq "Windows 2000") - elseif(WINHID_LIBRARY MATCHES "lib/wxp") - set(_winreq "Windows XP") - elseif(WINHID_LIBRARY MATCHES "lib/wnet") - set(_winreq "Windows Server 2003") - elseif(WINHID_LIBRARY MATCHES "lib/wlh") - set(_winreq "Windows Vista") - elseif(WINHID_LIBRARY MATCHES "lib/win7") - set(_winreq "Windows 7") - endif() - if(NOT "${WINHID_MIN_WINDOWS_VER}" STREQUAL "${_winreq}") - if(NOT WinHID_FIND_QUIETLY) - message(STATUS "Linking against WINHID_LIBRARY will enforce this minimum version: ${_winreq}") + if(MSVC) + set(_winreq "Unknown") + if(WINHID_LIBRARY MATCHES "lib/w2k") + set(_winreq "Windows 2000") + elseif(WINHID_LIBRARY MATCHES "lib/wxp") + set(_winreq "Windows XP") + elseif(WINHID_LIBRARY MATCHES "lib/wnet") + set(_winreq "Windows Server 2003") + elseif(WINHID_LIBRARY MATCHES "lib/wlh") + set(_winreq "Windows Vista") + elseif(WINHID_LIBRARY MATCHES "lib/win7") + set(_winreq "Windows 7") + endif() + if(NOT "${WINHID_MIN_WINDOWS_VER}" STREQUAL "${_winreq}") + if(NOT WinHID_FIND_QUIETLY) + message(STATUS + "Linking against WINHID_LIBRARY will enforce this minimum version: ${_winreq}") + endif() + set(WINHID_MIN_WINDOWS_VER "${_winreq}" CACHE INTERNAL "" FORCE) endif() - set(WINHID_MIN_WINDOWS_VER "${_winreq}" CACHE INTERNAL "" FORCE) endif() set(WINHID_LIBRARIES "${WINHID_LIBRARY}") - set(WINHID_INCLUDE_DIRS "${WINHID_CRT_INCLUDE_DIR}" "${WINHID_INCLUDE_DIR}") + set(WINHID_INCLUDE_DIRS + "${WINHID_CRT_INCLUDE_DIR}" + "${WINHID_INCLUDE_DIR}") mark_as_advanced(WINHID_ROOT_DIR) endif() diff --git a/FindWindowsSDK.cmake b/FindWindowsSDK.cmake new file mode 100644 index 0000000..04992d1 --- /dev/null +++ b/FindWindowsSDK.cmake @@ -0,0 +1,163 @@ +# - Find the Windows SDK aka Platform SDK +# +# Variables: +# WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio +# WINDOWSSDK_LATEST_DIR +# WINDOWSSDK_LATEST_NAME +# WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version +# WINDOWSSDK_PREFERRED_DIR +# WINDOWSSDK_PREFERRED_NAME +# +# WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first. +# WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency +# +# Functions: +# windowssdk_name_lookup( ) - Find the name corresponding with the SDK directory you pass in, or +# NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work. +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2012 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(_preferred_sdk_dirs) +set(_win_sdk_dirs) +set(_win_sdk_versanddirs) +if(MSVC_VERSION GREATER 1310) # Newer than VS .NET/VS Toolkit 2003 + + # Environment variable for SDK dir + if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL "")) + message(STATUS "Got $ENV{WindowsSDKDir} - Windows/Platform SDK directories: ${_win_sdk_dirs}") + list(APPEND _preferred_sdk_dirs "$ENV{WindowsSDKDir}") + endif() + + if(MSVC_VERSION LESS 1600) + # Per-user current Windows SDK for VS2005/2008 + get_filename_component(_sdkdir + "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" + ABSOLUTE) + if(EXISTS "${_sdkdir}") + list(APPEND _preferred_sdk_dirs "${_sdkdir}") + endif() + + # System-wide current Windows SDK for VS2005/2008 + get_filename_component(_sdkdir + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" + ABSOLUTE) + if(EXISTS "${_sdkdir}") + list(APPEND _preferred_sdk_dirs "${_sdkdir}") + endif() + endif() + + foreach(_winsdkver v8.0A v7.1 v7.0A v6.1 v6.0A v6.0) + get_filename_component(_sdkdir + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver};InstallationFolder]" + ABSOLUTE) + if(EXISTS "${_sdkdir}") + list(APPEND _win_sdk_dirs "${_sdkdir}") + list(APPEND + _win_sdk_versanddirs + "Windows SDK ${_winsdkver}" + "${_sdkdir}") + endif() + endforeach() +endif() +if(MSVC_VERSION GREATER 1200) + foreach(_platformsdkinfo + "D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1_Microsoft Platform SDK for Windows Server 2003 R2" + "8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3_Microsoft Platform SDK for Windows Server 2003 SP1") + string(SUBSTRING "${_platformsdkinfo}" 0 36 _platformsdkguid) + string(SUBSTRING "${_platformsdkinfo}" 37 -1 _platformsdkname) + get_filename_component(_sdkdir + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]" + ABSOLUTE) + if(EXISTS "${_sdkdir}") + list(APPEND _win_sdk_dirs "${_sdkdir}") + list(APPEND _win_sdk_versanddirs "${_platformsdkname}" "${_sdkdir}") + endif() + + get_filename_component(_sdkdir + "[HKEY_CURRENT_USER\\Software\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]" + ABSOLUTE) + if(EXISTS "${_sdkdir}") + list(APPEND _win_sdk_dirs "${_sdkdir}") + list(APPEND _win_sdk_versanddirs "${_platformsdkname}" "${_sdkdir}") + endif() + endforeach() +endif() + +set(_win_sdk_versanddirs + "${_win_sdk_versanddirs}" + CACHE + INTERNAL + "mapping between windows sdk version locations and names" + FORCE) + +function(windowssdk_name_lookup _dir _outvar) + list(FIND _win_sdk_versanddirs "${_dir}" _diridx) + math(EXPR _nameidx "${_diridx} - 1") + if(${_nameidx} GREATER -1) + list(GET _win_sdk_versanddirs ${_nameidx} _sdkname) + else() + set(_sdkname "NOTFOUND") + endif() + set(${_outvar} "${_sdkname}" PARENT_SCOPE) +endfunction() + +if(_win_sdk_dirs) + # Remove duplicates + list(REMOVE_DUPLICATES _win_sdk_dirs) + list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR) + windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}" + WINDOWSSDK_LATEST_NAME) + set(WINDOWSSDK_DIRS ${_win_sdk_dirs}) +endif() +if(_preferred_sdk_dirs) + list(GET _preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR) + windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}" + WINDOWSSDK_PREFERRED_NAME) + set(WINDOWSSDK_PREFERRED_FIRST_DIRS + ${_preferred_sdk_dirs} + ${_win_sdk_dirs}) + list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS) + set(WINDOWSSDK_FOUND_PREFERENCE ON) + + # In case a preferred dir was found that isn't found otherwise + #set(WINDOWSSDK_DIRS ${WINDOWSSDK_DIRS} ${WINDOWSSDK_PREFERRED_FIRST_DIRS}) + #list(REMOVE_DUPLICATES WINDOWSSDK_DIRS) +else() + set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}") + set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}") + set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS}) + set(WINDOWSSDK_FOUND_PREFERENCE OFF) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WindowsSDK + "No compatible version of the Windows SDK or Platform SDK found." + WINDOWSSDK_DIRS) + +if(WINDOWSSDK_FOUND) + if(NOT _winsdk_remembered_dirs STREQUAL WINDOWSSDK_DIRS) + set(_winsdk_remembered_dirs + "${WINDOWSSDK_DIRS}" + CACHE + INTERNAL + "" + FORCE) + if(NOT WindowsSDK_FIND_QUIETLY) + foreach(_sdkdir ${WINDOWSSDK_DIRS}) + windowssdk_name_lookup("${_sdkdir}" _sdkname) + message(STATUS " - Found ${_sdkname} at ${_sdkdir}") + endforeach() + endif() + endif() +endif() diff --git a/Findcppcheck.cmake b/Findcppcheck.cmake index a044203..518d33b 100644 --- a/Findcppcheck.cmake +++ b/Findcppcheck.cmake @@ -39,6 +39,10 @@ set(CPPCHECK_ROOT_DIR set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE}) set(CMAKE_FIND_APPBUNDLE NEVER) +if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}") + set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "") +endif() + # If we have a custom path, look there first. if(CPPCHECK_ROOT_DIR) find_program(CPPCHECK_EXECUTABLE @@ -57,37 +61,61 @@ find_program(CPPCHECK_EXECUTABLE NAMES cppcheck) # Restore original setting for appbundle finding set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting}) +# Find out where our test file is +get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) +set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp") +if(NOT EXISTS "${_cppcheckdummyfile}") + message(FATAL_ERROR + "Missing file ${_cppcheckdummyfile} - should be alongside Findcppcheck.cmake, can be found at https://github.com/rpavlik/cmake-modules") +endif() + +function(_cppcheck_test_arg _resultvar _arg) + if(NOT CPPCHECK_EXECUTABLE) + set(${_resultvar} NO) + return() + endif() + execute_process(COMMAND + "${CPPCHECK_EXECUTABLE}" + "${_arg}" + "--quiet" + "${_cppcheckdummyfile}" + RESULT_VARIABLE + _cppcheck_result + OUTPUT_QUIET + ERROR_QUIET) + if("${_cppcheck_result}" EQUAL 0) + set(${_resultvar} YES PARENT_SCOPE) + else() + set(${_resultvar} NO PARENT_SCOPE) + endif() +endfunction() + +function(_cppcheck_set_arg_var _argvar _arg) + if("${${_argvar}}" STREQUAL "") + _cppcheck_test_arg(_cppcheck_arg "${_arg}") + if(_cppcheck_arg) + set(${_argvar} "${_arg}" PARENT_SCOPE) + endif() + endif() +endfunction() + if(CPPCHECK_EXECUTABLE) - # Find out where our test file is - get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) - set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp") # Check for the two types of command line arguments by just trying them - execute_process(COMMAND - "${CPPCHECK_EXECUTABLE}" - "--enable=style" - "--quiet" - "${_cppcheckdummyfile}" - RESULT_VARIABLE - _cppcheck_new_result - OUTPUT_QUIET - ERROR_QUIET) - execute_process(COMMAND - "${CPPCHECK_EXECUTABLE}" - "--style" - "--quiet" - "${_cppcheckdummyfile}" - RESULT_VARIABLE - _cppcheck_old_result - OUTPUT_QUIET - ERROR_QUIET) - if("${_cppcheck_new_result}" EQUAL 0) - # New arguments - set(CPPCHECK_UNUSEDFUNC_ARG "--enable=unusedFunctions") - set(CPPCHECK_POSSIBLEERROR_ARG "--enable=possibleError") - set(CPPCHECK_STYLE_ARG "--enable=style") - set(CPPCHECK_QUIET_ARG "--quiet") - set(CPPCHECK_INCLUDEPATH_ARG "-I") + _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style") + _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style") + if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style") + + _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG + "--enable=unusedFunctions") + _cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information") + _cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG + "--enable=missingInclude") + _cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix") + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG + "--enable=possibleError") + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all") + if(MSVC) set(CPPCHECK_TEMPLATE_ARG --template vs) set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]") @@ -97,19 +125,14 @@ if(CPPCHECK_EXECUTABLE) set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ") set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ") else() - message(STATUS - "Warning: FindCppcheck doesn't know how to format error messages for your compiler!") set(CPPCHECK_TEMPLATE_ARG --template gcc) set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ") set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ") endif() - elseif("${_cppcheck_old_result}" EQUAL 0) + elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style") # Old arguments - set(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions") - set(CPPCHECK_POSSIBLEERROR_ARG "--all") - set(CPPCHECK_STYLE_ARG "--style") - set(CPPCHECK_QUIET_ARG "--quiet") - set(CPPCHECK_INCLUDEPATH_ARG "-I") + _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions") + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all") set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:") set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]") else() @@ -118,6 +141,8 @@ if(CPPCHECK_EXECUTABLE) "WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!") endif() + set(CPPCHECK_QUIET_ARG "--quiet") + set(CPPCHECK_INCLUDEPATH_ARG "-I") endif() diff --git a/Findcppunit.cmake b/Findcppunit.cmake index 32daf17..6915016 100644 --- a/Findcppunit.cmake +++ b/Findcppunit.cmake @@ -45,7 +45,7 @@ include(SelectLibraryConfigurations) select_library_configurations(CPPUNIT) # Might want to look close to the library first for the includes. -get_filename_component(_libdir "${MYSIMPLEPACKAGE_LIBRARY}" PATH) +get_filename_component(_libdir "${CPPUNIT_LIBRARY_RELEASE}" PATH) find_path(CPPUNIT_INCLUDE_DIR NAMES diff --git a/Findcutil.cmake b/Findcutil.cmake index a7c0340..495f284 100644 --- a/Findcutil.cmake +++ b/Findcutil.cmake @@ -23,19 +23,27 @@ find_package(CUDA QUIET) file(TO_CMAKE_PATH "${CUDA_SDK_ROOT_DIR}/C/common" CUTIL_ROOT_DIR) if(NOT EXISTS "${CUTIL_ROOT_DIR}/src/cutil.cpp") - set(CUDA_SDK_ROOT_DIR SDKDIR-NOTFOUND CACHE PATH "NVIDIA GPU Computing SDK dir" FORCE) + set(CUDA_SDK_ROOT_DIR + SDKDIR-NOTFOUND + CACHE + PATH + "NVIDIA GPU Computing SDK dir" + FORCE) endif() # handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if # all listed variables are TRUE include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(cutil DEFAULT_MSG CUDA_SDK_ROOT_DIR CUDA_FOUND) +find_package_handle_standard_args(cutil + DEFAULT_MSG + CUDA_SDK_ROOT_DIR + CUDA_FOUND) -if(CUTIL_FOUND) +if(CUTIL_FOUND) get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH) add_subdirectory("${_moddir}/nested_targets/cutil") - - + + function(install_cutil dest) install(TARGETS cutil RUNTIME DESTINATION "${dest}" diff --git a/GetCompilerInfoString.cmake b/GetCompilerInfoString.cmake index 7bcd9d9..1ee5b1f 100644 --- a/GetCompilerInfoString.cmake +++ b/GetCompilerInfoString.cmake @@ -106,11 +106,9 @@ function(get_compiler_info_string _var) set(_verstring "gcc${_gccver}") else() - # Some other compiler we don't handle yet. - message(STATUS - "WARNING: Not GCC or MSVC, so we invented a messy compiler info string") + # Some other compiler we don't handle in more detail yet. string(REGEX REPLACE " " "_" _verstring "${CMAKE_GENERATOR}") - set(_verstring "generator:${_verstring}") + set(_verstring "${CMAKE_CXX_COMPILER_ID}:generator:${_verstring}") endif() # Return _verstring diff --git a/GetGitRevisionDescription.cmake b/GetGitRevisionDescription.cmake index f6f07ca..1bf0230 100644 --- a/GetGitRevisionDescription.cmake +++ b/GetGitRevisionDescription.cmake @@ -3,16 +3,16 @@ # These functions force a re-configure on each git commit so that you can # trust the values of the variables in your build system. # -# get_git_head_revision( [ ...]) +# get_git_head_revision( [ ...]) # # Returns the refspec and sha hash of the current head revision # -# git_describe( [ ...]) +# git_describe( [ ...]) # # Returns the results of git describe on the source tree, and adjusting # the output so that it tests false if an error occurs. # -# git_get_exact_tag( [ ...]) +# git_get_exact_tag( [ ...]) # # Returns the results of git describe --exact-match on the source tree, # and adjusting the output so that it tests false if there was no exact @@ -40,21 +40,33 @@ set(__get_git_revision_description YES) get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) function(get_git_head_revision _refspecvar _hashvar) - set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git") - if(NOT EXISTS "${GIT_DIR}") - # not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - return() - endif() + set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") if(NOT EXISTS "${GIT_DATA}") file(MAKE_DIRECTORY "${GIT_DATA}") endif() + + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() set(HEAD_FILE "${GIT_DATA}/HEAD") configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) - configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" "${GIT_DATA}/grabRef.cmake" @ONLY) + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) include("${GIT_DATA}/grabRef.cmake") set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) @@ -67,11 +79,11 @@ function(git_describe _var) endif() get_git_head_revision(refspec hash) if(NOT GIT_FOUND) - set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) return() endif() if(NOT hash) - set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) return() endif() @@ -85,10 +97,17 @@ function(git_describe _var) #message(STATUS "Arguments to execute_process: ${ARGN}") - execute_process(COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE res - OUTPUT_VARIABLE out + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + ${hash} + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if(NOT res EQUAL 0) diff --git a/GetGitRevisionDescription.cmake.in b/GetGitRevisionDescription.cmake.in index c04662c..888ce13 100644 --- a/GetGitRevisionDescription.cmake.in +++ b/GetGitRevisionDescription.cmake.in @@ -13,18 +13,26 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +set(HEAD_HASH) + file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) if(HEAD_CONTENTS MATCHES "ref") # named branch string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") - - configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + if(EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") + configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + set(HEAD_HASH "${HEAD_REF}") + endif() else() # detached HEAD configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) endif() -file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) -string(STRIP "${HEAD_HASH}" HEAD_HASH) +if(NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() diff --git a/LuaTargets.cmake b/LuaTargets.cmake index e5532a2..040f6b4 100644 --- a/LuaTargets.cmake +++ b/LuaTargets.cmake @@ -40,15 +40,15 @@ function(add_lua_target _target _dest) if(NOT LUA_TARGET_LUAC_EXECUTABLE) if(TARGET luac) set(LUA_TARGET_LUAC_EXECUTABLE luac) + mark_as_advanced(LUA_TARGET_LUAC_EXECUTABLE) else() - find_program(LUA_TARGET_LUAC_EXECUTABLE - NAMES - luac) + find_program(LUA_TARGET_LUAC_EXECUTABLE NAMES luac) endif() endif() if(NOT LUA_TARGET_LUAC_EXECUTABLE) - message(FATAL_ERROR "Can't find luac: please give LUA_TARGET_LUAC_EXECUTABLE a useful value - currently ${LUA_TARGET_LUAC_EXECUTABLE}") + message(FATAL_ERROR + "Can't find luac: please give LUA_TARGET_LUAC_EXECUTABLE a useful value - currently ${LUA_TARGET_LUAC_EXECUTABLE}") endif() mark_as_advanced(LUA_TARGET_LUAC_EXECUTABLE) @@ -60,7 +60,9 @@ function(add_lua_target _target _dest) get_filename_component(fullpath "${fn}" ABSOLUTE) get_filename_component(fn "${fn}" NAME) else() - get_filename_component(fullpath "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" ABSOLUTE) + get_filename_component(fullpath + "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" + ABSOLUTE) endif() # Clean up output file name @@ -88,7 +90,11 @@ function(add_lua_target _target _dest) SOURCES ${SOURCES} DEPENDS ${ALLFILES}) if(TARGET "${LUA_TARGET_LUAC_EXECUTABLE}") - get_property(_luac_imported TARGET "${LUA_TARGET_LUAC_EXECUTABLE}" PROPERTY IMPORTED) + get_property(_luac_imported + TARGET + "${LUA_TARGET_LUAC_EXECUTABLE}" + PROPERTY + IMPORTED) if(NOT _luac_imported) add_dependencies(${_target} ${LUA_TARGET_LUAC_EXECUTABLE}) endif() diff --git a/OptionRequires.cmake b/OptionRequires.cmake index 5505664..662121f 100644 --- a/OptionRequires.cmake +++ b/OptionRequires.cmake @@ -21,7 +21,7 @@ function(option_requires name desc) list(REMOVE_AT args ${_off_found}) set(OFF_BY_DEFAULT true) endif() - + set(found) set(missing) foreach(var ${args}) @@ -31,22 +31,23 @@ function(option_requires name desc) list(APPEND missing ${var}) endif() endforeach() - + if(NOT missing) set(OK TRUE) else() set(OK FALSE) endif() - + set(default ${OK}) if(OFF_BY_DEFAULT) set(default OFF) endif() - + option(${name} "${desc}" ${default}) - + if(${name} AND (NOT OK)) - message(FATAL_ERROR "${name} enabled but these dependencies were not valid: ${missing}") + message(FATAL_ERROR + "${name} enabled but these dependencies were not valid: ${missing}") endif() endfunction() diff --git a/README.markdown b/README.markdown index b85bf2c..30f0b2b 100644 --- a/README.markdown +++ b/README.markdown @@ -72,7 +72,7 @@ Licenses The modules that I wrote myself are all subject to this license: -> Copyright Iowa State University 2009-2010 +> Copyright Iowa State University 2009-2012 > > Distributed under the Boost Software License, Version 1.0. > diff --git a/UseMarkdown.cmake b/UseMarkdown.cmake new file mode 100644 index 0000000..3853167 --- /dev/null +++ b/UseMarkdown.cmake @@ -0,0 +1,116 @@ +# - Convert markdown source files to HTML as a custom target +# +# include(UseMarkdown) +# add_markdown_target( [...] [RENAME ]) +# Relative paths for the destination directory are considered with +# with respect to CMAKE_CURRENT_BINARY_DIR. The RENAME argument is only +# valid with a single markdown file as input. +# +# +# install_markdown_target( [extra arguments to INSTALL(FILES ...) ]) +# +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2011 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2011-2012. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__add_markdown_target) + return() +endif() +set(__add_markdown_target YES) + +define_property(TARGET + PROPERTY + MARKDOWN_TARGET_OUTPUTS + BRIEF_DOCS + "Markdown target outputs" + FULL_DOCS + "Output files of a target created by add_markdown_target") + +function(add_markdown_target _target _dest) + + if(NOT ARGN) + message(WARNING + "In add_markdown_target call for target ${_target}, no source files were specified!") + return() + endif() + + find_package(Markdown QUIET) + if(NOT MARKDOWN_EXECUTABLE) + message(FATAL_ERROR "Can't find a markdown conversion tool!") + endif() + + set(NEW_NAME) + list(FIND ARGN "RENAME" _renameloc) + if(_renameloc GREATER -1) + list(LENGTH ARGN _len) + if(NOT _len EQUAL 3) + message(FATAL_ERROR + "Specifying RENAME requires 1 input file and 1 output name!") + endif() + list(GET ARGN 2 NEW_NAME) + list(GET ARGN 0 ARGN) + endif() + + set(ALLFILES) + set(SOURCES) + foreach(fn ${ARGN}) + # Produce an absolute path to the input file + if(IS_ABSOLUTE "${fn}") + get_filename_component(fullpath "${fn}" ABSOLUTE) + get_filename_component(fn "${fn}" NAME) + else() + get_filename_component(fullpath + "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" + ABSOLUTE) + endif() + get_filename_component(fn_noext "${fn}" NAME_WE) + + # Clean up output file name + if(NEW_NAME) + get_filename_component(absout "${_dest}/${NEW_NAME}" ABSOLUTE) + else() + get_filename_component(absout "${_dest}/${fn_noext}.html" ABSOLUTE) + endif() + + add_custom_command(OUTPUT "${absout}" + COMMAND + ${CMAKE_COMMAND} + ARGS -E make_directory "${_dest}" + COMMAND + ${MARKDOWN_EXECUTABLE} + ARGS "${fullpath}" > "${absout}" + MAIN_DEPENDENCY "${fullpath}" + VERBATIM + COMMENT "Converting Markdown ${fn} to HTML in ${absout}...") + list(APPEND SOURCES "${fullpath}") + list(APPEND ALLFILES "${absout}") + endforeach() + + # Custom target depending on all the file copy commands + add_custom_target(${_target} + ALL + SOURCES ${SOURCES} + DEPENDS ${ALLFILES}) + set_property(TARGET ${_target} PROPERTY MARKDOWN_TARGET_OUTPUTS "${ALLFILES}") +endfunction() + +function(install_markdown_target _target) + get_target_property(_mtoutputs ${_target} MARKDOWN_TARGET_OUTPUTS) + if(NOT _mtoutputs) + message(WARNING + "install_markdown_target called on a target not created with add_markdown_target!") + return() + endif() + + # Forward the call to install + install(FILES ${_mtoutputs} ${ARGN}) +endfunction() diff --git a/cmake-2.8.10-modules/CMakePackageConfigHelpers.cmake b/cmake-2.8.10-modules/CMakePackageConfigHelpers.cmake new file mode 100644 index 0000000..2e5c528 --- /dev/null +++ b/cmake-2.8.10-modules/CMakePackageConfigHelpers.cmake @@ -0,0 +1,254 @@ +# - CONFIGURE_PACKAGE_CONFIG_FILE(), WRITE_BASIC_PACKAGE_VERSION_FILE() +# +# CONFIGURE_PACKAGE_CONFIG_FILE( INSTALL_DESTINATION +# [PATH_VARS ... ] +# [NO_SET_AND_CHECK_MACRO] +# [NO_CHECK_REQUIRED_COMPONENTS_MACRO]) +# +# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain +# configure_file() command when creating the Config.cmake or -config.cmake +# file for installing a project or library. It helps making the resulting package +# relocatable by avoiding hardcoded paths in the installed Config.cmake file. +# +# In a FooConfig.cmake file there may be code like this to make the +# install destinations know to the using project: +# set(FOO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" ) +# set(FOO_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" ) +# set(FOO_ICONS_DIR "@CMAKE_INSTALL_PREFIX@/share/icons" ) +# ...logic to determine installedPrefix from the own location... +# set(FOO_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" ) +# All 4 options shown above are not sufficient, since the first 3 hardcode +# the absolute directory locations, and the 4th case works only if the logic +# to determine the installedPrefix is correct, and if CONFIG_INSTALL_DIR contains +# a relative path, which in general cannot be guaranteed. +# This has the effect that the resulting FooConfig.cmake file would work poorly +# under Windows and OSX, where users are used to choose the install location +# of a binary package at install time, independent from how CMAKE_INSTALL_PREFIX +# was set at build/cmake time. +# +# Using CONFIGURE_PACKAGE_CONFIG_FILE() helps. If used correctly, it makes the +# resulting FooConfig.cmake file relocatable. +# Usage: +# 1. write a FooConfig.cmake.in file as you are used to +# 2. insert a line containing only the string "@PACKAGE_INIT@" +# 3. instead of set(FOO_DIR "@SOME_INSTALL_DIR@"), use set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@") +# (this must be after the @PACKAGE_INIT@ line) +# 4. instead of using the normal configure_file(), use CONFIGURE_PACKAGE_CONFIG_FILE() +# +# The and arguments are the input and output file, the same way +# as in configure_file(). +# +# The given to INSTALL_DESTINATION must be the destination where the FooConfig.cmake +# file will be installed to. This can either be a relative or absolute path, both work. +# +# The variables to given as PATH_VARS are the variables which contain +# install destinations. For each of them the macro will create a helper variable +# PACKAGE_. These helper variables must be used +# in the FooConfig.cmake.in file for setting the installed location. They are calculated +# by CONFIGURE_PACKAGE_CONFIG_FILE() so that they are always relative to the +# installed location of the package. This works both for relative and also for absolute locations. +# For absolute locations it works only if the absolute location is a subdirectory +# of CMAKE_INSTALL_PREFIX. +# +# By default configure_package_config_file() also generates two helper macros, +# set_and_check() and check_required_components() into the FooConfig.cmake file. +# +# set_and_check() should be used instead of the normal set() +# command for setting directories and file locations. Additionally to setting the +# variable it also checks that the referenced file or directory actually exists +# and fails with a FATAL_ERROR otherwise. This makes sure that the created +# FooConfig.cmake file does not contain wrong references. +# When using the NO_SET_AND_CHECK_MACRO, this macro is not generated into the +# FooConfig.cmake file. +# +# check_required_components() should be called at the end of the +# FooConfig.cmake file if the package supports components. +# This macro checks whether all requested, non-optional components have been found, +# and if this is not the case, sets the Foo_FOUND variable to FALSE, so that the package +# is considered to be not found. +# It does that by testing the Foo__FOUND variables for all requested +# required components. +# When using the NO_CHECK_REQUIRED_COMPONENTS option, this macro is not generated +# into the FooConfig.cmake file. +# +# For an example see below the documentation for WRITE_BASIC_PACKAGE_VERSION_FILE(). +# +# +# WRITE_BASIC_PACKAGE_VERSION_FILE( filename VERSION major.minor.patch COMPATIBILITY (AnyNewerVersion|SameMajorVersion|ExactVersion) ) +# +# Writes a file for use as ConfigVersion.cmake file to . +# See the documentation of find_package() for details on this. +# filename is the output filename, it should be in the build tree. +# major.minor.patch is the version number of the project to be installed +# The COMPATIBILITY mode AnyNewerVersion means that the installed package version +# will be considered compatible if it is newer or exactly the same as the requested version. +# This mode should be used for packages which are fully backward compatible, +# also across major versions. +# If SameMajorVersion is used instead, then the behaviour differs from AnyNewerVersion +# in that the major version number must be the same as requested, e.g. version 2.0 will +# not be considered compatible if 1.0 is requested. +# This mode should be used for packages which guarantee backward compatibility within the +# same major version. +# If ExactVersion is used, then the package is only considered compatible if the requested +# version matches exactly its own version number (not considering the tweak version). +# For example, version 1.2.3 of a package is only considered compatible to requested version 1.2.3. +# This mode is for packages without compatibility guarantees. +# If your project has more elaborated version matching rules, you will need to write your +# own custom ConfigVersion.cmake file instead of using this macro. +# +# Internally, this macro executes configure_file() to create the resulting +# version file. Depending on the COMPATIBLITY, either the file +# BasicConfigVersion-SameMajorVersion.cmake.in or BasicConfigVersion-AnyNewerVersion.cmake.in +# is used. Please note that these two files are internal to CMake and you should +# not call configure_file() on them yourself, but they can be used as starting +# point to create more sophisticted custom ConfigVersion.cmake files. +# +# +# Example using both configure_package_config_file() and write_basic_package_version_file(): +# CMakeLists.txt: +# set(INCLUDE_INSTALL_DIR include/ ... CACHE ) +# set(LIB_INSTALL_DIR lib/ ... CACHE ) +# set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE ) +# ... +# include(CMakePackageConfigHelpers) +# configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake +# INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake +# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR) +# write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake +# VERSION 1.2.3 +# COMPATIBILITY SameMajorVersion ) +# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake +# DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake ) +# +# With a FooConfig.cmake.in: +# set(FOO_VERSION x.y.z) +# ... +# @PACKAGE_INIT@ +# ... +# set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +# set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@") +# +# check_required_components(Foo) + + +#============================================================================= +# Copyright 2012 Alexander Neundorf +# +# Distributed under the OSI-approved BSD License (the "License"); +# see below. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * 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. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "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 COPYRIGHT +# HOLDER OR CONTRIBUTORS 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. +#============================================================================= + +include(CMakeParseArguments) + +include(WriteBasicConfigVersionFile) + +macro(WRITE_BASIC_PACKAGE_VERSION_FILE) + write_basic_config_version_file(${ARGN}) +endmacro() + + +function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile) + set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) + set(oneValueArgs INSTALL_DESTINATION ) + set(multiValueArgs PATH_VARS ) + + cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(CCF_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"") + endif() + + if(NOT CCF_INSTALL_DESTINATION) + message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()") + endif() + + if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}") + set(absInstallDir "${CCF_INSTALL_DESTINATION}") + else() + set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}") + endif() + file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" ) + + foreach(var ${CCF_PATH_VARS}) + if(NOT DEFINED ${var}) + message(FATAL_ERROR "Variable ${var} does not exist") + else() + if(IS_ABSOLUTE "${${var}}") + string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}" + PACKAGE_${var} "${${var}}") + else() + set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}") + endif() + endif() + endforeach() + + set(PACKAGE_INIT " +####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### +get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE) +") + + if(NOT CCF_NO_SET_AND_CHECK_MACRO) + set(PACKAGE_INIT "${PACKAGE_INIT} +macro(set_and_check _var _file) + set(\${_var} \"\${_file}\") + if(NOT EXISTS \"\${_file}\") + message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\") + endif() +endmacro() +") + endif() + + + if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO) + set(PACKAGE_INIT "${PACKAGE_INIT} +macro(check_required_components _NAME) + foreach(comp \${\${_NAME}_FIND_COMPONENTS}) + if(NOT \${_NAME}_\${comp}_FOUND) + if(\${_NAME}_FIND_REQUIRED_\${comp}) + set(\${_NAME}_FOUND FALSE) + endif() + endif() + endforeach() +endmacro() +") + endif() + + set(PACKAGE_INIT "${PACKAGE_INIT} +####################################################################################") + + configure_file("${_inputFile}" "${_outputFile}" @ONLY) + +endfunction() diff --git a/ghost-fake-stl/iostream.h b/ghost-fake-stl/iostream.h index 7361d64..7d7195f 100644 --- a/ghost-fake-stl/iostream.h +++ b/ghost-fake-stl/iostream.h @@ -1,4 +1,4 @@ -/** @file list.h +/** @file @brief Fake header to allow GHOST 4.09 use with MSVC 2005 @date 2010 diff --git a/ghost-fake-stl/list.h b/ghost-fake-stl/list.h index 017aeb1..a8b3fc2 100644 --- a/ghost-fake-stl/list.h +++ b/ghost-fake-stl/list.h @@ -1,4 +1,4 @@ -/** @file list.h +/** @file @brief Fake header to allow GHOST 4.09 use with MSVC 2005 @date 2010 diff --git a/ghost-fake-stl/set.h b/ghost-fake-stl/set.h index 0f37e1a..8806961 100644 --- a/ghost-fake-stl/set.h +++ b/ghost-fake-stl/set.h @@ -1,4 +1,4 @@ -/** @file set.h +/** @file @brief Fake header to allow GHOST 4.09 use with MSVC 2005 @date 2010 @@ -14,4 +14,6 @@ #pragma once #include -using std::set; \ No newline at end of file +#include +using std::set; +using std::less; \ No newline at end of file diff --git a/ghost-fake-stl/vector.h b/ghost-fake-stl/vector.h index e95b731..659db2d 100644 --- a/ghost-fake-stl/vector.h +++ b/ghost-fake-stl/vector.h @@ -1,4 +1,4 @@ -/** @file vector.h +/** @file @brief Fake header to allow GHOST 4.09 use with MSVC 2005 @date 2010 diff --git a/module-help.html b/module-help.html index 83201b3..dc35875 100644 --- a/module-help.html +++ b/module-help.html @@ -1,7 +1,7 @@ module-help - cmake -

Master Index CMake 2.8.3

+

Master Index CMake 2.8.6

The following modules are also available for CMake. They can be used with INCLUDE(ModuleName).

  Custom CMake Modules - Additional Modules for CMake.
@@ -35,7 +35,7 @@

All other modules provide functionality, either immediately upon including them, or by defining functions that perform some task of varying utility that you can use any time after including them. Note that if a module has the filename, for example, cmake/BoostTestTargets.cmake, you only need to call:

  include(BoostTestTargets)


-

For more information, see the documentation for individual modules, the cmake-modules github page, and/or the upstream CMake documentation at http://www.cmake.org/cmake/help/cmake-2-8-docs.html

+

For more information, see the documentation for individual modules, the cmake-modules github page, and/or the upstream CMake documentation at http://www.cmake.org/cmake/help/cmake-2-8-docs.html


Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

@@ -285,6 +285,32 @@

Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

+ +
  • + FindAdrienne: try to find Adrienne Electronics Corporation timecode card library
    +


    +

    SDK available from the manufacturer: http://www.adrielec.com/

    +

    Cache Variables: (probably not for direct use in your scripts)

    +
      ADRIENNE_INCLUDE_DIR
    ADRIENNE_LIBRARY
    ADRIENNE_RUNTIME_LIBRARY
    ADRIENNE_INCLUDE_FILE
    +


    +

    Variables you might use in your CMakeLists.txt:

    +
      ADRIENNE_FOUND
    ADRIENNE_INCLUDE_DIRS
    ADRIENNE_LIBRARIES
    ADRIENNE_RUNTIME_LIBRARIES - the AEC_NTTC.dll file
    ADRIENNE_RUNTIME_LIBRARY_DIRS
    +


    +
      ADRIENNE_INCLUDE_FILENAME - this is probably AEC_NTTC.h, but it might also
    be AECINTTC.H.
    +


    +
      ADRIENNE_INCLUDE_HAS_EXTERN_C - Some (most) versions of the header already
    wrap their definitions in extern "C" { }, but some do not.
    +


    +
      ADRIENNE_DEFINITIONS - defines a quoted ADRIENNE_INCLUDE_FILENAME as above,
    so you can write a line like #include ADRIENNE_INCLUDE_FILENAME
    Also defines ADRIENNE_BEFORE_INCLUDE and ADRIENNE_AFTER_INCLUDE to handle
    adding extern "C" { and } if the header file doesn't do so itself.
    +


    +

    Variables that might be set by the user in the gui/command line to help find the library:

    +
      ADRIENNE_ROOT_DIR - root of an Adrienne CD, disk, or extracted/copied contents
    thereof.
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • FindBluez: try to find Bluez
    @@ -308,12 +334,12 @@
      CPPDOM_LIBRARY_DIR, library search path
    CPPDOM_INCLUDE_DIR, include search path
    CPPDOM_LIBRARY, the library to link against
    CPPDOM_CXX_FLAGS
    CPPDOM_FOUND, If false, do not try to use this library.


    Useful configuration variables you might want to add to your cache:

    -
      CPPDOM_ROOT_DIR - A directory prefix to search
    (a path that contains include/ as a subdirectory)
    CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.0.0)
    to use when constructing search names and paths
    +
      CPPDOM_ROOT_DIR - A directory prefix to search
    (a path that contains include/ as a subdirectory)
    CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.2.0)
    to use when constructing search names and paths


    This script will use Flagpoll, if found, to provide hints to the location of this library, but does not use the compiler flags returned by Flagpoll directly.

    VR Juggler requires this package, so this Find script takes that into account when determining where to search for the desired files. The VJ_BASE_DIR environment variable is searched (preferentially) when searching for this package, so most sane VR Juggler build environments should "just work." Note that you need to manually re-run CMake if you change this environment variable, because it cannot auto-detect this change and trigger an automatic re-run.

    -

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    -

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +

    Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

  • @@ -328,6 +354,51 @@

    2009-2010 Ryan Pavlik <rpavlik@iastate.edu> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • +
  • + FindDirectInput: try to find DirectInput library (part of DirectX SDK)
    +


    +

    Cache Variables: (probably not for direct use in your scripts)

    +
      DIRECTINPUT_DXGUID_LIBRARY
    DIRECTINPUT_DXERR_LIBRARY
    DIRECTINPUT_DINPUT_LIBRARY
    DIRECTINPUT_INCLUDE_DIR
    +


    +

    Non-cache variables you should use in your CMakeLists.txt:

    +
      DIRECTINPUT_LIBRARIES
    DIRECTINPUT_INCLUDE_DIRS
    DIRECTINPUT_FOUND - if this is not true, do not attempt to use this library
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    + +
  • +
  • + FindDirectShow: Find Microsoft DirectShow sample files, library, and headers.
    +


    +
      DIRECTSHOW_INCLUDE_DIRS - where to find needed include file
    DIRECTSHOW_BASECLASS_DIR- Directory containing the DirectShow baseclass sample code.
    DIRECTSHOW_FOUND - True if DirectShow found.
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Initially in VRPN - Distributed under the Boost Software License, Version 1.0.

    +

    Almost entirely re-written by: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    + +
  • +
  • + FindDirectX: try to find part of DirectX SDK
    +


    +

    Cache Variables: (probably not for direct use in your scripts)

    +
      DIRECTX_INCLUDE_DIR
    +


    +

    Variables you should use in your CMakeLists.txt:

    +
      DIRECTX_DXGUID_LIBRARY
    DIRECTX_DXERR_LIBRARY
    DIRECTX_DINPUT_LIBRARY
    DIRECTX_DINPUT_INCLUDE_DIR
    DIRECTX_D3D9_LIBRARY
    DIRECTX_D3DXOF_LIBRARY
    DIRECTX_D3DX9_LIBRARIES
    DIRECTX_INCLUDE_DIRS
    DIRECTX_FOUND - if this is not true, do not attempt to use this library
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    SelectLibraryConfigurations
    +


    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • FindFlagpoll: try to find Flagpoll application, and offer package-finding services
    @@ -397,12 +468,12 @@
      GMTL_FOUND - system has GMTL
    GMTL_INCLUDE_DIR - the GMTL include directory


    Useful configuration variables you might want to add to your cache:

    -
      GMTL_ROOT_DIR - A directory prefix to search
    (a path that contains include/ as a subdirectory)
    GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.6.2)
    to use when constructing search names and paths
    +
      GMTL_ROOT_DIR - A directory prefix to search
    (a path that contains include/ as a subdirectory)
    GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.7.0)
    to use when constructing search names and paths


    This script will use Flagpoll, if found, to provide hints to the location of this library, but does not use the compiler flags returned by Flagpoll directly.

    VR Juggler requires this package, so this Find script takes that into account when determining where to search for the desired files. The VJ_BASE_DIR environment variable is searched (preferentially) when searching for this package, so most sane VR Juggler build environments should "just work." Note that you need to manually re-run CMake if you change this environment variable, because it cannot auto-detect this change and trigger an automatic re-run.

    -

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    -

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +

    Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

  • @@ -483,6 +554,23 @@

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • +
  • + FindIDLJ: try to find Java's IDLJ Interface Definition Language compiler.
    +


    +

    Ideally used with CMake 2.8.5 or newer for Java support using FindJava.cmake and UseJava.cmake

    +

    Variables:

    +
      Java_IDLJ_COMMAND, executable for idlj
    IDLJ_FOUND, If false, do not try to use this
    +


    +

    Function:

    +
      java_idlj(varname idlfile [extra idlj args]) - Generates
    the Java source files from the IDL file you indicate, and
    appends filenames suitable to add to a add_jar() call to the
    variable you specified.
    +


    +

    Because the files generated from an IDL file are not entirely predictable, java_idlj runs idlj in the cmake step, rather than the build step, and triggers a CMake re-run when an idl file is modified. Already up-to-date generated source is not re-generated, however.

    +

    Files are generated in a directory created specifically for the particular IDL file and the particular call, in the build directory - there should be no worries about overwriting files or picking up too much with the wildcard.

    +

    You may wish to add the IDL file to your list of sources if you want it to appear in your IDE, but it is not necessary.

    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • FindJCCL12: try to find JCCL 1.2 library
    @@ -612,6 +700,22 @@

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • +
  • + FindMarkdown: try to find Markdown tool
    +


    +

    Cache Variables:

    +
      MARKDOWN_EXECUTABLE
    +


    +

    Non-cache variables you might use in your CMakeLists.txt:

    +
      MARKDOWN_FOUND
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • FindOpenCV: ------------------------------
    @@ -634,7 +738,7 @@ FindOpenHaptics: try to find OpenHaptics libraries


    Cache Variables: (probably not for direct use in your scripts)

    -
      HDAPI_INCLUDE_DIR
    HDAPI_LIBRARY
    HDAPI_HDU_INCLUDE_DIR
    HDAPI_HDU_LIBRARY
    HDAPI_HDU_LIBRARY_RELEASE
    HDAPI_HDU_LIBRARY_DEBUG
    HLAPI_INCLUDE_DIR
    HLAPI_LIBRARY
    HLAPI_HLU_INCLUDE_DIR
    HLAPI_HLU_LIBRARY
    HLAPI_HLU_LIBRARY_RELEASE
    HLAPI_HLU_LIBRARY_DEBUG
    +
      HDAPI_INCLUDE_DIR
    HDAPI_LIBRARY
    HDAPI_LIBRARY_RELEASE
    HDAPI_LIBRARY_DEBUG
    HDAPI_HDU_INCLUDE_DIR
    HDAPI_HDU_LIBRARY
    HDAPI_HDU_LIBRARY_RELEASE
    HDAPI_HDU_LIBRARY_DEBUG
    HLAPI_INCLUDE_DIR
    HLAPI_LIBRARY
    HLAPI_LIBRARY_RELEASE
    HLAPI_LIBRARY_DEBUG
    HLAPI_HLU_INCLUDE_DIR
    HLAPI_HLU_LIBRARY
    HLAPI_HLU_LIBRARY_RELEASE
    HLAPI_HLU_LIBRARY_DEBUG


    Non-cache variables you might use in your CMakeLists.txt:

      OPENHAPTICS_FOUND
    HDAPI_INCLUDE_DIRS
    HDAPI_LIBRARIES
    HDAPI_HDU_INCLUDE_DIRS
    HDAPI_HDU_LIBRARIES
    HLAPI_INCLUDE_DIRS
    HLAPI_LIBRARIES
    HLAPI_HLU_INCLUDE_DIRS
    HLAPI_HLU_LIBRARIES
    OPENHAPTICS_LIBRARIES - includes HD, HDU, HL, HLU
    OPENHAPTICS_RUNTIME_LIBRARY_DIRS
    OPENHAPTICS_ENVIRONMENT
    OPENHAPTICS_LIBRARY_DIRS
    OPENHAPTICS_INCLUDE_DIRS
    @@ -642,7 +746,7 @@

    Requires these CMake modules:

      CleanDirectoryList
    CleanLibraryList
    ListCombinations
    ProgramFilesGlob
    SelectLibraryConfigurations (included with CMake >=2.8.0)
    FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    CMake 2.6.3 (uses "unset")


    -

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

  • @@ -660,6 +764,57 @@

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    + +
  • + FindPerformer: try to find the OpenGL Performer library
    +


    +

    Users may optionally supply:

    +
      PERFORMER_ROOT_DIR - a prefix to start searching.
    +


    +

    Cache Variables: (probably not for direct use in your scripts)

    +
      PERFORMER_INCLUDE_DIR
    PERFORMER_LIBRARY
    PERFORMER_PFUI_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
    PERFORMER_PFDU_UTIL_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
    PERFORMER_PFV_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
    +


    +

    Non-cache variables you might use in your CMakeLists.txt:

    +
      PERFORMER_FOUND
    PERFORMER_INCLUDE_DIRS
    PERFORMER_LIBRARIES
    PERFORMER_RUNTIME_LIBRARY_DIRS
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    + +
  • +
  • + FindPerlModules: try to find perl modules, passed as COMPONENTS
    +


    +

    Non-cache variable you might use in your CMakeLists.txt:

    +
      PERLMODULES_FOUND
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    + +
  • +
  • + FindQVRPN: try to find QVRPN library
    +


    +

    Of course, you may also just choose to make QVRPN a submodule of your project itself.

    +

    Cache Variables:

    +
      QVRPN_LIBRARY
    QVRPN_INCLUDE_DIR
    +


    +

    Non-cache variables you might use in your CMakeLists.txt:

    +
      QVRPN_FOUND
    QVRPN_LIBRARIES
    QVRPN_INCLUDE_DIRS
    +


    +

    QVRPN_ROOT_DIR is searched preferentially for these files

    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Refactored from FindVRPN.cmake by: Juan Sebastian Casallas <casallas@iastate.edu>

    +

    FindVRPN.cmake Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • FindSonix12: try to find Sonix 1.2 library
    @@ -957,14 +1112,30 @@
      VRPN_LIBRARY
    VRPN_SERVER_LIBRARY
    VRPN_INCLUDE_DIR


    Non-cache variables you might use in your CMakeLists.txt:

    -
      VRPN_FOUND
    VRPN_SERVER_LIBRARIES
    VRPN_LIBRARIES
    VRPN_INCLUDE_DIRS
    +
      VRPN_FOUND
    VRPN_SERVER_LIBRARIES - server libraries
    VRPN_LIBRARIES - client libraries
    VRPN_CLIENT_DEFINITIONS - definitions if you only use the client library
    VRPN_DEFINITIONS - Client-only definition if all we found was the client library.
    VRPN_INCLUDE_DIRS


    VRPN_ROOT_DIR is searched preferentially for these files

    Requires these CMake modules:

      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)


    -

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    -

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +

    Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    + +
  • +
  • + FindViewPoint: try to find Arrington Research ViewPoint EyeTracker SDK
    +


    +

    Cache Variables: (probably not for direct use in your scripts)

    +
      VIEWPOINT_INCLUDE_DIR
    VIEWPOINT_LIBRARY
    VIEWPOINT_RUNTIME_LIBRARY
    +


    +

    Non-cache variables you might use in your CMakeLists.txt:

    +
      VIEWPOINT_FOUND
    VIEWPOINT_INCLUDE_DIRS
    VIEWPOINT_LIBRARIES
    VIEWPOINT_RUNTIME_LIBRARIES - aka the dll for installing
    VIEWPOINT_RUNTIME_LIBRARY_DIRS
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

  • @@ -1030,6 +1201,24 @@

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • +
  • + FindWindowsSDK: Find the Windows SDK aka Platform SDK
    +


    +

    Variables:

    +
      WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio
    WINDOWSSDK_LATEST_DIR
    WINDOWSSDK_LATEST_NAME
    WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version
    WINDOWSSDK_PREFERRED_DIR
    WINDOWSSDK_PREFERRED_NAME
    +


    +
      WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first.
    WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency
    +


    +

    Functions:

    +
      windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or
    NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
    +


    +

    Requires these CMake modules:

    +
      FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
    +


    +

    Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • Findargp: try to find the argp library/component of glibc
    @@ -1213,13 +1402,13 @@ GetGitRevisionDescription: Returns a version string from Git


    These functions force a re-configure on each git commit so that you can trust the values of the variables in your build system.

    -
      get_git_head_revision(<refspecvar> <hashvar> [<additonal arguments to git describe> ...])
    +
      get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])


    Returns the refspec and sha hash of the current head revision

    -
      git_describe(<var> [<additonal arguments to git describe> ...])
    +
      git_describe(<var> [<additional arguments to git describe> ...])


    Returns the results of git describe on the source tree, and adjusting the output so that it tests false if an error occurs.

    -
      git_get_exact_tag(<var> [<additonal arguments to git describe> ...])
    +
      git_get_exact_tag(<var> [<additional arguments to git describe> ...])


    Returns the results of git describe --exact-match on the source tree, and adjusting the output so that it tests false if there was no exact matching tag.

    Requires CMake 2.6 or newer (uses the 'function' command)

    @@ -1428,6 +1617,20 @@

    Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    Copyright Iowa State University 2009-2010. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • +
  • + UseMarkdown: Convert markdown source files to HTML as a custom target
    +


    +
      include(UseMarkdown)
    add_markdown_target(<target_name> <directory to copy to> <markdownfile> [<markdownfile>...] [RENAME <newname>])
    Relative paths for the destination directory are considered with
    with respect to CMAKE_CURRENT_BINARY_DIR. The RENAME argument is only
    valid with a single markdown file as input.
    +


    +


    +
      install_markdown_target(<target_name> [extra arguments to INSTALL(FILES ...) ])
    +


    +


    +

    Requires CMake 2.6 or newer (uses the 'function' command)

    +

    Original Author: 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC

    +

    Copyright Iowa State University 2011-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    +
  • UseTR1: Use settings to enable access to C++ TR1
    diff --git a/module-help.txt b/module-help.txt index 5bccc1d..07c4178 100644 --- a/module-help.txt +++ b/module-help.txt @@ -1,4 +1,4 @@ -cmake version 2.8.3 +cmake version 2.8.6 ------------------------------------------------------------------------------ Introduction @@ -645,6 +645,71 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindAdrienne + try to find Adrienne Electronics Corporation timecode card library + + + + SDK available from the manufacturer: http://www.adrielec.com/ + + Cache Variables: (probably not for direct use in your scripts) + + ADRIENNE_INCLUDE_DIR + ADRIENNE_LIBRARY + ADRIENNE_RUNTIME_LIBRARY + ADRIENNE_INCLUDE_FILE + + + + Variables you might use in your CMakeLists.txt: + + ADRIENNE_FOUND + ADRIENNE_INCLUDE_DIRS + ADRIENNE_LIBRARIES + ADRIENNE_RUNTIME_LIBRARIES - the AEC_NTTC.dll file + ADRIENNE_RUNTIME_LIBRARY_DIRS + + + + ADRIENNE_INCLUDE_FILENAME - this is probably AEC_NTTC.h, but it might also + be AECINTTC.H. + + + + ADRIENNE_INCLUDE_HAS_EXTERN_C - Some (most) versions of the header already + wrap their definitions in extern "C" { }, but some do not. + + + + ADRIENNE_DEFINITIONS - defines a quoted ADRIENNE_INCLUDE_FILENAME as above, + so you can write a line like #include ADRIENNE_INCLUDE_FILENAME + Also defines ADRIENNE_BEFORE_INCLUDE and ADRIENNE_AFTER_INCLUDE to handle + adding extern "C" { and } if the header file doesn't do so itself. + + + + Variables that might be set by the user in the gui/command line to + help find the library: + + ADRIENNE_ROOT_DIR - root of an Adrienne CD, disk, or extracted/copied contents + thereof. + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + FindBluez try to find Bluez @@ -696,7 +761,7 @@ a few. CPPDOM_ROOT_DIR - A directory prefix to search (a path that contains include/ as a subdirectory) - CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.0.0) + CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.2.0) to use when constructing search names and paths @@ -713,11 +778,11 @@ a few. change this environment variable, because it cannot auto-detect this change and trigger an automatic re-run. - Original Author: 2009-2010 Ryan Pavlik + Original Author: 2009-2012 Ryan Pavlik http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC - Copyright Iowa State University 2009-2010. Distributed under the + Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -752,6 +817,110 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindDirectInput + try to find DirectInput library (part of DirectX SDK) + + + + Cache Variables: (probably not for direct use in your scripts) + + DIRECTINPUT_DXGUID_LIBRARY + DIRECTINPUT_DXERR_LIBRARY + DIRECTINPUT_DINPUT_LIBRARY + DIRECTINPUT_INCLUDE_DIR + + + + Non-cache variables you should use in your CMakeLists.txt: + + DIRECTINPUT_LIBRARIES + DIRECTINPUT_INCLUDE_DIRS + DIRECTINPUT_FOUND - if this is not true, do not attempt to use this library + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2011 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2011. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + + FindDirectShow + Find Microsoft DirectShow sample files, library, and headers. + + + + DIRECTSHOW_INCLUDE_DIRS - where to find needed include file + DIRECTSHOW_BASECLASS_DIR- Directory containing the DirectShow baseclass sample code. + DIRECTSHOW_FOUND - True if DirectShow found. + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Initially in VRPN - Distributed under the Boost Software License, + Version 1.0. + + Almost entirely re-written by: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + + FindDirectX + try to find part of DirectX SDK + + + + Cache Variables: (probably not for direct use in your scripts) + + DIRECTX_INCLUDE_DIR + + + + Variables you should use in your CMakeLists.txt: + + DIRECTX_DXGUID_LIBRARY + DIRECTX_DXERR_LIBRARY + DIRECTX_DINPUT_LIBRARY + DIRECTX_DINPUT_INCLUDE_DIR + DIRECTX_D3D9_LIBRARY + DIRECTX_D3DXOF_LIBRARY + DIRECTX_D3DX9_LIBRARIES + DIRECTX_INCLUDE_DIRS + DIRECTX_FOUND - if this is not true, do not attempt to use this library + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + SelectLibraryConfigurations + + + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + FindFlagpoll try to find Flagpoll application, and offer package-finding services @@ -913,7 +1082,7 @@ a few. GMTL_ROOT_DIR - A directory prefix to search (a path that contains include/ as a subdirectory) - GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.6.2) + GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.7.0) to use when constructing search names and paths @@ -930,11 +1099,11 @@ a few. change this environment variable, because it cannot auto-detect this change and trigger an automatic re-run. - Original Author: 2009-2010 Ryan Pavlik + Original Author: 2009-2012 Ryan Pavlik http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC - Copyright Iowa State University 2009-2010. Distributed under the + Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -1139,6 +1308,51 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindIDLJ + try to find Java's IDLJ Interface Definition Language compiler. + + + + Ideally used with CMake 2.8.5 or newer for Java support using + FindJava.cmake and UseJava.cmake + + Variables: + + Java_IDLJ_COMMAND, executable for idlj + IDLJ_FOUND, If false, do not try to use this + + + + Function: + + java_idlj(varname idlfile [extra idlj args]) - Generates + the Java source files from the IDL file you indicate, and + appends filenames suitable to add to a add_jar() call to the + variable you specified. + + + + Because the files generated from an IDL file are not entirely + predictable, java_idlj runs idlj in the cmake step, rather than the + build step, and triggers a CMake re-run when an idl file is modified. + Already up-to-date generated source is not re-generated, however. + + Files are generated in a directory created specifically for the + particular IDL file and the particular call, in the build directory - + there should be no worries about overwriting files or picking up too + much with the wildcard. + + You may wish to add the IDL file to your list of sources if you want + it to appear in your IDE, but it is not necessary. + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + FindJCCL12 try to find JCCL 1.2 library @@ -1451,6 +1665,37 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindMarkdown + try to find Markdown tool + + + + Cache Variables: + + MARKDOWN_EXECUTABLE + + + + Non-cache variables you might use in your CMakeLists.txt: + + MARKDOWN_FOUND + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2011 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2011. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + FindOpenCV ------------------------------ @@ -1493,12 +1738,16 @@ a few. HDAPI_INCLUDE_DIR HDAPI_LIBRARY + HDAPI_LIBRARY_RELEASE + HDAPI_LIBRARY_DEBUG HDAPI_HDU_INCLUDE_DIR HDAPI_HDU_LIBRARY HDAPI_HDU_LIBRARY_RELEASE HDAPI_HDU_LIBRARY_DEBUG HLAPI_INCLUDE_DIR HLAPI_LIBRARY + HLAPI_LIBRARY_RELEASE + HLAPI_LIBRARY_DEBUG HLAPI_HLU_INCLUDE_DIR HLAPI_HLU_LIBRARY HLAPI_HLU_LIBRARY_RELEASE @@ -1537,7 +1786,7 @@ a few. - Original Author: 2009-2010 Ryan Pavlik + Original Author: 2009-2012 Ryan Pavlik http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC @@ -1581,6 +1830,118 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindPerformer + try to find the OpenGL Performer library + + + + Users may optionally supply: + + PERFORMER_ROOT_DIR - a prefix to start searching. + + + + Cache Variables: (probably not for direct use in your scripts) + + PERFORMER_INCLUDE_DIR + PERFORMER_LIBRARY + PERFORMER_PFUI_LIBRARY - doesn't get included in PERFORMER_LIBRARIES + PERFORMER_PFDU_UTIL_LIBRARY - doesn't get included in PERFORMER_LIBRARIES + PERFORMER_PFV_LIBRARY - doesn't get included in PERFORMER_LIBRARIES + + + + Non-cache variables you might use in your CMakeLists.txt: + + PERFORMER_FOUND + PERFORMER_INCLUDE_DIRS + PERFORMER_LIBRARIES + PERFORMER_RUNTIME_LIBRARY_DIRS + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + + FindPerlModules + try to find perl modules, passed as COMPONENTS + + + + Non-cache variable you might use in your CMakeLists.txt: + + PERLMODULES_FOUND + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + + FindQVRPN + try to find QVRPN library + + + + Of course, you may also just choose to make QVRPN a submodule of your + project itself. + + Cache Variables: + + QVRPN_LIBRARY + QVRPN_INCLUDE_DIR + + + + Non-cache variables you might use in your CMakeLists.txt: + + QVRPN_FOUND + QVRPN_LIBRARIES + QVRPN_INCLUDE_DIRS + + + + QVRPN_ROOT_DIR is searched preferentially for these files + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Refactored from FindVRPN.cmake by: Juan Sebastian Casallas + + + FindVRPN.cmake Original Author: 2009-2010 Ryan Pavlik + + http://academic.cleardefinition.com Iowa State University HCI Graduate + Program/VRAC + + Copyright Iowa State University 2009-2012. Distributed under the + Boost Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindSonix12 try to find Sonix 1.2 library @@ -2416,8 +2777,10 @@ a few. Non-cache variables you might use in your CMakeLists.txt: VRPN_FOUND - VRPN_SERVER_LIBRARIES - VRPN_LIBRARIES + VRPN_SERVER_LIBRARIES - server libraries + VRPN_LIBRARIES - client libraries + VRPN_CLIENT_DEFINITIONS - definitions if you only use the client library + VRPN_DEFINITIONS - Client-only definition if all we found was the client library. VRPN_INCLUDE_DIRS @@ -2430,14 +2793,51 @@ a few. - Original Author: 2009-2010 Ryan Pavlik + Original Author: 2009-2012 Ryan Pavlik http://academic.cleardefinition.com Iowa State University HCI Graduate Program/VRAC - Copyright Iowa State University 2009-2010. Distributed under the + Copyright Iowa State University 2009-2012. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindViewPoint + try to find Arrington Research ViewPoint EyeTracker SDK + + + + Cache Variables: (probably not for direct use in your scripts) + + VIEWPOINT_INCLUDE_DIR + VIEWPOINT_LIBRARY + VIEWPOINT_RUNTIME_LIBRARY + + + + Non-cache variables you might use in your CMakeLists.txt: + + VIEWPOINT_FOUND + VIEWPOINT_INCLUDE_DIRS + VIEWPOINT_LIBRARIES + VIEWPOINT_RUNTIME_LIBRARIES - aka the dll for installing + VIEWPOINT_RUNTIME_LIBRARY_DIRS + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + FindVirtuoseAPI try to find Haption VirtuoseAPI library and include files @@ -2578,6 +2978,48 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + FindWindowsSDK + Find the Windows SDK aka Platform SDK + + + + Variables: + + WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio + WINDOWSSDK_LATEST_DIR + WINDOWSSDK_LATEST_NAME + WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version + WINDOWSSDK_PREFERRED_DIR + WINDOWSSDK_PREFERRED_NAME + + + + WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first. + WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency + + + + Functions: + + windowssdk_name_lookup( ) - Find the name corresponding with the SDK directory you pass in, or + NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work. + + + + Requires these CMake modules: + + FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + + + + Original Author: 2012 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2012. Distributed under the Boost + Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) + Findargp try to find the argp library/component of glibc @@ -3002,20 +3444,20 @@ a few. These functions force a re-configure on each git commit so that you can trust the values of the variables in your build system. - get_git_head_revision( [ ...]) + get_git_head_revision( [ ...]) Returns the refspec and sha hash of the current head revision - git_describe( [ ...]) + git_describe( [ ...]) Returns the results of git describe on the source tree, and adjusting the output so that it tests false if an error occurs. - git_get_exact_tag( [ ...]) + git_get_exact_tag( [ ...]) @@ -3463,6 +3905,37 @@ a few. Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + UseMarkdown + Convert markdown source files to HTML as a custom target + + + + include(UseMarkdown) + add_markdown_target( [...] [RENAME ]) + Relative paths for the destination directory are considered with + with respect to CMAKE_CURRENT_BINARY_DIR. The RENAME argument is only + valid with a single markdown file as input. + + + + + + install_markdown_target( [extra arguments to INSTALL(FILES ...) ]) + + + + + + Requires CMake 2.6 or newer (uses the 'function' command) + + Original Author: 2011 Ryan Pavlik + http://academic.cleardefinition.com Iowa State + University HCI Graduate Program/VRAC + + Copyright Iowa State University 2011-2012. Distributed under the + Boost Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + UseTR1 Use settings to enable access to C++ TR1 diff --git a/nested_targets/DCubed/d3ew_scene/CMakeLists.txt b/nested_targets/DCubed/d3ew_scene/CMakeLists.txt index dcc3997..1f881b9 100644 --- a/nested_targets/DCubed/d3ew_scene/CMakeLists.txt +++ b/nested_targets/DCubed/d3ew_scene/CMakeLists.txt @@ -26,7 +26,6 @@ foreach(filename ansi.hxx ehlc_timer.hxx face.cpp face.hxx - files.txt frustum.cpp frustum.hxx hldeb.hxx diff --git a/package-licensing/VRJuggLua.cmake b/package-licensing/VRJuggLua.cmake index bc4301b..d2da335 100644 --- a/package-licensing/VRJuggLua.cmake +++ b/package-licensing/VRJuggLua.cmake @@ -1,16 +1,16 @@ # Original Author: -# 2009-2010 Ryan Pavlik +# 2009-2012 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # -# Copyright Iowa State University 2009-2010. +# Copyright Iowa State University 2009-2012. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file ../LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -add_proprietary_license("VR JuggLua" - "Based in part on VR JuggLua, Copyright 2010 Iowa State University. This version of VR JuggLua is unreleased research software - NOT FOR REDISTRIBUTION.") -add_redistribution_warning("This version of VR JuggLua is unreleased research software - NOT FOR REDISTRIBUTION.") +add_permissive_license("VR JuggLua" + "Based in part on VR JuggLua, Copyright 2010-2012 Iowa State University. VR JuggLua is distributed under the Boost Software License, Version 1.0. See copy at http://www.boost.org/LICENSE_1_0.txt" + "") include("package-licensing/VRJuggler") include("package-licensing/OpenSceneGraph") include("package-licensing/Lua") From 2a7702c043d6829875decf6a79047c70a5e64d99 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 12 Dec 2012 12:02:28 -0600 Subject: [PATCH 52/55] Fix spelling error caught with Codespell. --- src/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io.c b/src/io.c index e94064f..fcbc0b2 100644 --- a/src/io.c +++ b/src/io.c @@ -274,7 +274,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { case 0: { byte* buf; - /* continous reporting off, report to buttons only */ + /* continuous reporting off, report to buttons only */ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); wiiuse_set_leds(wm, WIIMOTE_LED_NONE); From 97ac193d5655fddc3f75dd388bbbc0fa25cef101 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 12 Dec 2012 13:41:34 -0600 Subject: [PATCH 53/55] Add on-screen help for the controls in the example. --- example/example.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/example.c b/example/example.c index 00f5edc..8c4c228 100644 --- a/example/example.c +++ b/example/example.c @@ -459,6 +459,13 @@ int main(int argc, char** argv) { wiiuse_rumble(wiimotes[0], 0); wiiuse_rumble(wiimotes[1], 0); + printf("\nControls:\n"); + printf("\tB toggles rumble.\n"); + printf("\t+ to start Wiimote accelerometer reporting, - to stop\n"); + printf("\tUP to start IR camera (sensor bar mode), DOWN to stop.\n"); + printf("\t1 to start Motion+ reporting, 2 to stop.\n"); + printf("\n\n"); + /* * Maybe I'm interested in the battery power of the 0th * wiimote. This should be WIIMOTE_ID_1 but to be sure From 4f47a2edbe9aeb100d5475c50597f7d12d7ef668 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Wed, 12 Dec 2012 20:58:58 +0100 Subject: [PATCH 54/55] wiiuse_wait_report: WIIUSE_DEBUG instead of WIIUSE_WARNING for dropped reports --- src/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io.c b/src/io.c index e94064f..5d52747 100644 --- a/src/io.c +++ b/src/io.c @@ -126,7 +126,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buff if (buffer[0] == report) { break; } else { - WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[0], report); + WIIUSE_DEBUG("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[0], report); } } } From ca0f10f7f7c692fb7783cf76ca1c9ee1b4fa4831 Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Wed, 12 Dec 2012 21:28:08 +0100 Subject: [PATCH 55/55] add myself to the list of contributors :) --- README.mkd | 1 + 1 file changed, 1 insertion(+) diff --git a/README.mkd b/README.mkd index 665a6b4..19ba175 100644 --- a/README.mkd +++ b/README.mkd @@ -57,6 +57,7 @@ Additional Contributors: - Jan Ciger - Reviatech SAS - Gabriele Randelli and the WiiC project - Juan Sebastian Casallas +- Lysann Schlegel License