improved platform definitions and definition checks

This commit is contained in:
Ryan Pavlik
2011-05-02 10:32:26 -05:00
parent 51674ce9de
commit 6c7fb6f12f
15 changed files with 82 additions and 53 deletions

View File

@@ -105,7 +105,7 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
/* handshake done */
wm->exp.type = EXP_CLASSIC;
#ifdef WIN32
#ifdef WIIUSE_WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif

View File

@@ -61,7 +61,7 @@ extern FILE* logtarget[];
#define WIIUSE_INFO(fmt, ...) do { if (OUTF_INFO) fprintf(OUTF_INFO, "[INFO] " fmt "\n", ##__VA_ARGS__); } while(0)
#ifdef WITH_WIIUSE_DEBUG
#ifdef WIN32
#ifdef WIIUSE_WIN32
#define WIIUSE_DEBUG(fmt, ...) do { \
if (OUTF_DEBUG) { \
char* file = __FILE__; \

View File

@@ -40,10 +40,7 @@
#include <stdlib.h>
#include <math.h>
#ifdef WIN32
#include <float.h>
#endif
#include <float.h>
/**

View File

@@ -44,7 +44,7 @@
#include "guitar_hero_3.h"
#include "wiiboard.h"
#ifndef WIN32
#ifndef WIIUSE_WIN32
#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
@@ -79,7 +79,7 @@ static int state_changed(struct wiimote_t* wm);
int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
int evnt = 0;
#ifndef WIN32
#ifdef WIIUSE_BLUEZ
/*
* *nix
*/
@@ -566,7 +566,7 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
exp_changed = 1;
}
#ifdef WIN32
#ifdef WIIUSE_WIN32
if (!attachment) {
WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
wm->timeout = wm->normal_timeout;
@@ -640,7 +640,7 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
disable_expansion(wm);
/* increase the timeout until the handshake completes */
#ifdef WIN32
#ifdef WIIUSE_WIN32
WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout);
wm->timeout = wm->exp_timeout;
#endif

View File

@@ -103,7 +103,7 @@ 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 WIN32
#ifdef WIIUSE_WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif

View File

@@ -34,7 +34,7 @@
#ifndef CONNECT_H_INCLUDED
#define CONNECT_H_INCLUDED
#ifndef WIN32
#ifdef WIIUSE_BLUEZ
#include <bluetooth/bluetooth.h>
#endif

View File

@@ -31,10 +31,10 @@
* @brief Handles device I/O for *nix.
*/
#ifndef WIN32
#include "io.h"
#ifdef WIIUSE_BLUEZ
#include <stdlib.h>
#include <unistd.h>
@@ -265,4 +265,4 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
#endif /* ifndef WIN32 */
#endif /* ifdef WIIUSE_BLUEZ */

View File

@@ -31,10 +31,10 @@
* @brief Handles device I/O for Windows.
*/
#ifdef WIN32
#include "io.h"
#ifdef WIIUSE_WIN32
#include <stdlib.h>
#include <hidsdi.h>
@@ -241,4 +241,4 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
return 0;
}
#endif /* ifdef WIN32 */
#endif /* ifdef WIIUSE_WIN32 */

View File

@@ -35,7 +35,7 @@
#include <math.h>
#ifndef WIN32
#ifndef WIIUSE_WIN32
#include <unistd.h>
#endif
@@ -115,10 +115,10 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
wiiuse_write_data(wm, WM_REG_IR, &buf, 1);
/* wait for the wiimote to catch up */
#ifndef WIN32
usleep(50000);
#else
#ifdef WIIUSE_WIN32
Sleep(50);
#else
usleep(50000);
#endif
/* write sensitivity blocks */
@@ -132,10 +132,10 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
buf = WM_IR_TYPE_EXTENDED;
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
#ifndef WIN32
usleep(50000);
#else
#ifdef WIIUSE_WIN32
Sleep(50);
#else
usleep(50000);
#endif
/* set the wiimote report type */

View File

@@ -110,7 +110,7 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
/* handshake done */
wm->exp.type = EXP_NUNCHUK;
#ifdef WIN32
#ifdef WIIUSE_WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif

View File

@@ -39,18 +39,14 @@
#ifndef OS_H_INCLUDED
#define OS_H_INCLUDED
#ifdef WIN32
/* windows */
#ifdef _MSC_VER
/* windows with visual c */
#define isnan(x) _isnan(x)
#define isinf(x) !_finite(x)
/* disable warnings I don't care about */
#pragma warning(disable:4244) /* possible loss of data conversion */
#pragma warning(disable:4273) /* inconsistent dll linkage */
#pragma warning(disable:4217)
#else
/* nix */
#endif
#endif // OS_H_INCLUDED

View File

@@ -101,7 +101,7 @@ 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 WIN32
#ifdef WIIUSE_WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif

View File

@@ -41,7 +41,7 @@
#include <stdlib.h>
#ifndef WIN32
#ifndef WIIUSE_WIN32
#include <unistd.h>
#endif
@@ -142,11 +142,12 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
wm[i]->unid = i+1;
#ifndef WIN32
#ifdef WIIUSE_BLUEZ
wm[i]->bdaddr = *BDADDR_ANY;
wm[i]->out_sock = -1;
wm[i]->in_sock = -1;
#else
#endif
#ifdef WIIUSE_WIN32
wm[i]->dev_handle = 0;
wm[i]->stack = WIIUSE_STACK_UNKNOWN;
wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
@@ -188,10 +189,11 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
/* reset a bunch of stuff */
#ifndef WIN32
#ifdef WIIUSE_BLUEZ
wm->out_sock = -1;
wm->in_sock = -1;
#else
#endif
#ifdef WIIUSE_WIN32
wm->dev_handle = 0;
#endif
@@ -594,11 +596,11 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
byte buf[32]; /* no payload is better than this */
int rumble = 0;
#ifndef WIN32
#ifdef WIIUSE_WIN32
buf[0] = report_type;
#else
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
buf[1] = report_type;
#else
buf[0] = report_type;
#endif
switch (report_type) {
@@ -615,7 +617,7 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
break;
}
#ifndef WIN32
#ifndef WIIUSE_WIN32
memcpy(buf+2, msg, len);
if (rumble)
buf[2] |= 0x01;
@@ -629,7 +631,7 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
{
int x = 2;
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
#ifndef WIN32
#ifndef WIIUSE_WIN32
for (; x < len+2; ++x)
#else
for (; x < len+1; ++x)
@@ -639,7 +641,7 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
}
#endif
#ifndef WIN32
#ifndef WIIUSE_WIN32
return wiiuse_io_write(wm, buf, len+2);
#else
return wiiuse_io_write(wm, buf, len+1);
@@ -711,7 +713,7 @@ 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 WIN32
#ifdef WIIUSE_WIN32
int i;
if (!wm) return;
@@ -774,7 +776,7 @@ 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 WIN32
#ifdef WIIUSE_WIN32
int i;
if (!wm) return;

View File

@@ -69,10 +69,23 @@
#define WIIUSE_MINOR 13
#define WIIUSE_MICRO 1
#ifdef _WIN32
#ifndef WIIUSE_PLATFORM
#if defined(_WIN32)
#define WIIUSE_PLATFORM
#define WIIUSE_WIN32
#elif defined(__linux)
#define WIIUSE_PLATFORM
#define WIIUSE_BLUEZ
#else
#error "Platform not yet supported!"
#endif
#endif
#ifdef WIIUSE_WIN32
/* windows */
#include <windows.h>
#else
#endif
#ifdef WIIUSE_BLUEZ
/* nix */
#include <bluetooth/bluetooth.h>
#endif
@@ -262,7 +275,7 @@ typedef enum ir_position_t {
* This is left over from an old hack, but it may actually
* be a useful feature to keep so it wasn't removed.
*/
#ifdef WIN32
#ifdef WIIUSE_WIN32
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_EXP_TIMEOUT 10
#endif
@@ -605,18 +618,26 @@ typedef enum WIIUSE_EVENT_TYPE {
typedef struct wiimote_t {
WCONST int unid; /**< user specified id */
#ifndef WIN32
#ifdef WIIUSE_BLUEZ
/** @name Linux-specific (BlueZ) members */
/** @{ */
WCONST bdaddr_t bdaddr; /**< bt address */
WCONST char bdaddr_str[18]; /**< readable bt address */
WCONST int out_sock; /**< output socket */
WCONST int in_sock; /**< input socket */
#else
/** @} */
#endif
#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 */
/** @} */
#endif
WCONST int state; /**< various state flags */
@@ -666,7 +687,7 @@ typedef enum wiiuse_loglevel {
*
*****************************************/
#ifdef _WIN32
#ifdef WIIUSE_WIN32
#define WIIUSE_EXPORT_DECL __declspec(dllexport)
#define WIIUSE_IMPORT_DECL __declspec(dllimport)
#else

View File

@@ -44,9 +44,22 @@
#ifndef WIIUSE_INTERNAL_H_INCLUDED
#define WIIUSE_INTERNAL_H_INCLUDED
#ifdef WIN32
#ifndef WIIUSE_PLATFORM
#if defined(_WIN32)
#define WIIUSE_PLATFORM
#define WIIUSE_WIN32
#elif defined(__linux)
#define WIIUSE_PLATFORM
#define WIIUSE_BLUEZ
#else
#error "Platform not yet supported!"
#endif
#endif
#ifdef WIIUSE_WIN32
#include <Winsock2.h>
#else
#endif
#ifdef WIIUSE_BLUEZ
#include <arpa/inet.h> /* htons() */
#include <bluetooth/bluetooth.h>
#endif