External/wiiuse clean up, part 2.

- More removal of unnecessary code
- Windows: Modification of Wiiuse_Find under windows,
  instead of always deleting and recreating the whole wiimote_t struct, we do maintain the old one,
  adding/removing new wiimotes to/from it
- some wiimote bugfixes, see below for details

Windows related stuff:
Fixed most of the disconnection issues (single and mulitple real wiimotes, both wiimote plugins) (I haven't had a disconnect msg in hours anymore(ms stack)).
Rumble bug should be fixed now(both plugins,pls verify).
Fixed some pair up issues( sometimes you had to press the pair up button up to 3 times, till it paired up your wiimote).
More dongles might be now supported via ms stack, pls try and report back!
Fixed a problem where multiple wiimotes would swap slots on pair-up/addition of a real wiimote (2-4 real wiimotes) (both plugins, but not integrated into new plugin).
Improved ingame auto-pairup for real wiimotes(thx to the new wiiuse_find routine).
Fixed a bug on setting wiimote timeouts, which means changing the timeout was just a dummy earlier.
Most of the stuff concerns stuff in the old wiimote plugin, dont worry, in the end it's important for both plugins. It will get ported to the new plugin sooner or later.:')
Some minor stuff.
This might break osx/linux build and maybe the new plugin realwiimote-wise only. Thx to glennrics to pointing me to some breakings on linux, I didn't fix them all. 
PS I hope i haven't forgotten anything, enjoy.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5940 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
snzgoo 2010-07-22 04:31:36 +00:00
parent 4230c2501e
commit 987832cbb0
19 changed files with 180 additions and 740 deletions

View File

@ -60,115 +60,7 @@
#define WIIMOTE_LED_3 0x40
#define WIIMOTE_LED_4 0x80
/* button codes */
#define WIIMOTE_BUTTON_TWO 0x0001
#define WIIMOTE_BUTTON_ONE 0x0002
#define WIIMOTE_BUTTON_B 0x0004
#define WIIMOTE_BUTTON_A 0x0008
#define WIIMOTE_BUTTON_MINUS 0x0010
#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
#define WIIMOTE_BUTTON_HOME 0x0080
#define WIIMOTE_BUTTON_LEFT 0x0100
#define WIIMOTE_BUTTON_RIGHT 0x0200
#define WIIMOTE_BUTTON_DOWN 0x0400
#define WIIMOTE_BUTTON_UP 0x0800
#define WIIMOTE_BUTTON_PLUS 0x1000
#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
#define WIIMOTE_BUTTON_UNKNOWN 0x8000
#define WIIMOTE_BUTTON_ALL 0x1F9F
/* nunchul button codes */
#define NUNCHUK_BUTTON_Z 0x01
#define NUNCHUK_BUTTON_C 0x02
#define NUNCHUK_BUTTON_ALL 0x03
/* classic controller button codes */
#define CLASSIC_CTRL_BUTTON_UP 0x0001
#define CLASSIC_CTRL_BUTTON_LEFT 0x0002
#define CLASSIC_CTRL_BUTTON_ZR 0x0004
#define CLASSIC_CTRL_BUTTON_X 0x0008
#define CLASSIC_CTRL_BUTTON_A 0x0010
#define CLASSIC_CTRL_BUTTON_Y 0x0020
#define CLASSIC_CTRL_BUTTON_B 0x0040
#define CLASSIC_CTRL_BUTTON_ZL 0x0080
#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
#define CLASSIC_CTRL_BUTTON_PLUS 0x0400
#define CLASSIC_CTRL_BUTTON_HOME 0x0800
#define CLASSIC_CTRL_BUTTON_MINUS 0x1000
#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
#define CLASSIC_CTRL_BUTTON_DOWN 0x4000
#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
/* guitar hero 3 button codes */
#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
#define GUITAR_HERO_3_BUTTON_GREEN 0x0010
#define GUITAR_HERO_3_BUTTON_BLUE 0x0020
#define GUITAR_HERO_3_BUTTON_RED 0x0040
#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
#define GUITAR_HERO_3_BUTTON_PLUS 0x0400
#define GUITAR_HERO_3_BUTTON_MINUS 0x1000
#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
/* wiimote option flags */
#define WIIUSE_SMOOTHING 0x01
#define WIIUSE_CONTINUOUS 0x02
#define WIIUSE_ORIENT_THRESH 0x04
#define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
#define WIIUSE_ORIENT_PRECISION 100.0f
/* expansion codes */
#define EXP_NONE 0
#define EXP_NUNCHUK 1
#define EXP_CLASSIC 2
#define EXP_GUITAR_HERO_3 3
/* IR correction types */
typedef enum ir_position_t {
WIIUSE_IR_ABOVE,
WIIUSE_IR_BELOW
} ir_position_t;
/**
* @brief Check if a button is pressed.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is pressed, 0 if not.
*/
#define IS_PRESSED(dev, button) ((dev->btns & button) == button)
/**
* @brief Check if a button is being held.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is held, 0 if not.
*/
#define IS_HELD(dev, button) ((dev->btns_held & button) == button)
/**
* @brief Check if a button is released on this event. \n\n
* This does not mean the button is not pressed, it means \n
* this button was just now released.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is released, 0 if not.
*
*/
#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
/**
* @brief Check if a button has just been pressed this event.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is pressed, 0 if not.
*/
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
/**
* @brief Return the IR sensitivity level.
@ -186,10 +78,6 @@ typedef enum ir_position_t {
else *lvl = 0; \
} while (0)
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
@ -204,7 +92,7 @@ typedef enum ir_position_t {
* be a useful feature to keep so it wasn't removed.
*/
#ifdef WIN32
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_DEFAULT_TIMEOUT 30
#define WIIMOTE_EXP_TIMEOUT 10
#endif
@ -212,9 +100,7 @@ typedef unsigned char byte;
typedef char sbyte;
struct wiimote_t;
struct vec3b_t;
struct orient_t;
struct gforce_t;
/**
@ -538,41 +424,19 @@ typedef struct wiimote_t {
WCONST int out_sock; /**< output socket */
WCONST int in_sock; /**< input socket */
#else
WCONST char devicepath[255]; /**< reference for removing/adding new wiimotes to wiimote_t */
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 */
WCONST byte leds; /**< currently lit leds */
WCONST float battery_level; /**< battery level */
WCONST int flags; /**< options flag */
WCONST byte handshake_state; /**< the state of the connection handshake */
WCONST struct read_req_t* read_req; /**< list of data read requests */
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
WCONST struct expansion_t expansion; /**< wiimote expansion device */
WCONST struct vec3b_t accel; /**< current raw acceleration data */
WCONST struct orient_t orient; /**< current orientation on each axis */
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
WCONST struct ir_t ir; /**< IR data */
WCONST unsigned short btns; /**< what buttons have just been pressed */
WCONST unsigned short btns_held; /**< what buttons are being held down */
WCONST unsigned short btns_released; /**< what buttons were just released this */
WCONST float orient_threshold; /**< threshold for orient to generate an event */
WCONST int accel_threshold; /**< threshold for accel to generate an event */
WCONST struct wiimote_state_t lstate; /**< last saved state */
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
} wiimote;
@ -611,14 +475,17 @@ 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 int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
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_timeout(struct wiimote_t** wm, int wiimotes, byte timeout);
/* connect.c */
#ifdef _WIN32
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int wiimotes);
#else
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
#endif
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
#ifdef WIN32
@ -627,8 +494,6 @@ WIIUSE_EXPORT extern int wiiuse_register_system_notification(HWND hwnd);
#endif
/* ir.c */
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);
/* io.c */

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -48,7 +48,6 @@ INCLUDES = -I.
# Generate a list of object files
#
OBJS = \
$(OBJ_DIR)/io.o \
$(OBJ_DIR)/io_nix.o \
$(OBJ_DIR)/ir.o \
$(OBJ_DIR)/wiiuse.o

View File

@ -13,7 +13,6 @@ if (sys.platform == 'linux2' and not env['HAVE_BLUEZ']) or \
env['HAVE_WIIUSE'] = 1
files = [
"io.c",
"ir.c",
"wiiuse.c",
]

View File

@ -34,7 +34,7 @@
#ifndef DEFINITIONS_H_INCLUDED
#define DEFINITIONS_H_INCLUDED
#if 1 // Use Dolphin logging
#if 0 // Use Dolphin logging
#include "Log.h"
// NOTICE_LEVEL is more appropriate for the uses of WIIUSE_INFO than INFO_LEVEL
@ -77,17 +77,10 @@
#endif // Use Dolphin logging
#define WIIMOTE_PI 3.14159265f
/* Convert between radians and degrees */
#define RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI)
#define DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f))
/* Convert to big endian */
#define BIG_ENDIAN_LONG(i) (htonl(i))
#define BIG_ENDIAN_SHORT(i) (htons(i))
#define absf(x) ((x >= 0) ? (x) : (x * -1.0f))
#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x)))
#endif // DEFINITIONS_H_INCLUDED

View File

@ -1,109 +0,0 @@
/*
* wiiuse
*
* Written By:
* Michael Laforest < para >
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
*
* Copyright 2006-2007
*
* This file is part of wiiuse.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* $Header$
*
*/
/**
* @file
* @brief Handles device I/O (non-OS specific).
*/
#include <stdio.h>
#include <stdlib.h>
#include "definitions.h"
#include "wiiuse_internal.h"
#include "io.h"
/**
* @brief Get initialization data from the wiimote.
*
* @param wm Pointer to a wiimote_t structure.
* @param data unused
* @param len unused
*
* When first called for a wiimote_t structure, a request
* is sent to the wiimote for initialization information.
* This includes factory set accelerometer data.
* The handshake will be concluded when the wiimote responds
* with this data.
*/
void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
if (!wm) return;
switch (wm->handshake_state) {
case 0:
{
/* send request to wiimote for accelerometer calibration */
byte* buf;
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
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;
/* 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);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
wm->handshake_state++;
break;
}
default:
{
break;
}
}
}

View File

@ -46,49 +46,64 @@
#include "io.h"
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int wiimotes) {
GUID device_id;
HANDLE dev;
HDEVINFO device_info;
int i, index;
int i, x, found, index, udisc = 0;
DWORD len;
SP_DEVICE_INTERFACE_DATA device_data;
PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL;
HIDD_ATTRIBUTES attr;
int found = 0;
(void) timeout; // unused
// todo: handle/remove (unexpected and forced) disconnected wiimotes here
// removal of unneeded wiimotes and exiting when we got enough wiimotes connected
if(wiiuse_remove(wm, wiimotes, max_wiimotes))
return wm;
device_data.cbSize = sizeof(device_data);
index = 0;
/* get the device id */
// get the device id
HidD_GetHidGuid(&device_id);
/* get all hid devices connected */
// get all hid devices connected
device_info = SetupDiGetClassDevs(&device_id, NULL, NULL, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
for (;; ++index) {
for (;wiimotes < max_wiimotes; ++index) {
if (detail_data) {
free(detail_data);
detail_data = NULL;
}
found = 0;
/* query the next hid device info */
// query the next hid device info
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
break;
/* get the size of the data block required */
// get the size of the data block required
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
detail_data = malloc(len);
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
/* query the data for this device */
// query the data for this device
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
continue;
/* open the device */
// Wiimote already added
for(x = 0; x < wiimotes; x++)
{
if(memcmp(wm[x]->devicepath,detail_data->DevicePath,197) == 0) {
found = 1;
break;
}
}
if (found)
continue;
// open new device
dev = CreateFile(detail_data->DevicePath,
(GENERIC_READ | GENERIC_WRITE),
(FILE_SHARE_READ | FILE_SHARE_WRITE),
@ -96,40 +111,43 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
if (dev == INVALID_HANDLE_VALUE)
continue;
/* get device attributes */
// get device attributes
attr.Size = sizeof(attr);
i = HidD_GetAttributes(dev, &attr);
if ((attr.VendorID == WM_VENDOR_ID) && (attr.ProductID == WM_PRODUCT_ID)) {
/* this is a wiimote */
wm[found]->dev_handle = dev;
wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, L"");
wm[found]->hid_overlap.Offset = 0;
wm[found]->hid_overlap.OffsetHigh = 0;
WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_DEV_FOUND);
WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED);
//this is a wiimote
wm[wiimotes]->dev_handle = dev;
/* try to set the output report to see if the device is actually connected */
if (!wiiuse_set_report_type(wm[found])) {
Sleep(10);
WIIMOTE_DISABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED);
if (wm[found]->event == WIIUSE_UNEXPECTED_DISCONNECT)
break;
wm[wiimotes]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, L"");
wm[wiimotes]->hid_overlap.Offset = 0;
wm[wiimotes]->hid_overlap.OffsetHigh = 0;
WIIMOTE_ENABLE_STATE(wm[wiimotes], WIIMOTE_STATE_DEV_FOUND);
WIIMOTE_ENABLE_STATE(wm[wiimotes], WIIMOTE_STATE_CONNECTED);
WIIMOTE_ENABLE_STATE(wm[wiimotes], WIIUSE_CONTINUOUS);
// try to set the output report to see if the device is actually connected
if (!wiiuse_set_report_type(wm[wiimotes])) {
WIIMOTE_DISABLE_STATE(wm[wiimotes], WIIMOTE_STATE_CONNECTED);
if (wm[wiimotes]->event == WIIUSE_UNEXPECTED_DISCONNECT)
{
wiiuse_disconnect(wm[wiimotes]);
memset(wm[wiimotes],0,sizeof(wm[wiimotes]));
}
continue;
}
/* do the handshake * shouldn't be needed as well, I'm gonna leave first it tho*/
wiiuse_handshake(wm[found], NULL, 0);
memcpy(wm[wiimotes]->devicepath,detail_data->DevicePath,197);
WIIUSE_INFO("Connected to wiimote [id %i].", wm[wiimotes]->unid);
++wiimotes;
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
++found;
if (found >= max_wiimotes)
break;
} else {
/* not a wiimote */
// not a wiimote
CloseHandle(dev);
}
}
@ -139,15 +157,23 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
SetupDiDestroyDeviceInfoList(device_info);
return found;
return wiimotes;
}
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
int connected = 0;
int i = 0;
for (; i < wiimotes; ++i) {
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
int i,connected=0;
for (i = 0; i < wiimotes; ++i) {
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED))
++connected;
}
@ -317,7 +343,6 @@ int wiiuse_check_system_notification(unsigned int nMsg, WPARAM wParam, LPARAM lP
else { //different method to acquire the "wiimote vid/pid" for a comparison when the device is already unavailable @CreateFile()
wcstombs(stringbuf, pDeviceInfo->dbcc_name, 255);
//ms bt stack + bluesoleil vid/pid dbccname format
if ( (strstr(stringbuf, "VID&0002057e_PID&0306") != NULL) || (strstr(stringbuf, "VID_057e&PID_0306") != NULL) )
{
@ -348,4 +373,31 @@ int wiiuse_register_system_notification(HWND hwnd) {
return RegisterDeviceNotification(hwnd,&Filter, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
}
int wiiuse_remove(struct wiimote_t** wm, int wiimotes, int max_wiimotes) {
int i = 0;
WIIUSE_INFO("Remove Wiimotes, WM: %i MAX_WM: %i",wiimotes, max_wiimotes);
//No cleanup needed, less wiimotes available than needed
if (wiimotes <= max_wiimotes)
return 0;
else if (!wm)
return 0;
for (i = max_wiimotes; i < wiimotes; i++) {
if(wm[i]) {
wiiuse_disconnect(wm[i]);
wm[i]->state = WIIMOTE_INIT_STATES;
wm[i]->flags = WIIUSE_INIT_FLAGS;
wm[i]->event = WIIUSE_NONE;
}
}
return i;
}
#endif /* ifdef WIN32 */

View File

@ -81,69 +81,6 @@ static int get_ir_sens(struct wiimote_t* wm, const char** block1, const char** b
}
/**
* @brief Set the XY position for the IR cursor.
*
* @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;
wm->ir.pos = pos;
switch (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;
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;
return;
default:
return;
};
}
/**
* @brief Set the aspect ratio of the TV/monitor.
*
* @param wm Pointer to a wiimote_t structure.
* @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;
wm->ir.aspect = aspect;
if (aspect == WIIUSE_ASPECT_4_3) {
wm->ir.vres[0] = WM_ASPECT_4_3_X;
wm->ir.vres[1] = WM_ASPECT_4_3_Y;
} else {
wm->ir.vres[0] = WM_ASPECT_16_9_X;
wm->ir.vres[1] = WM_ASPECT_16_9_Y;
}
/* reset the position offsets */
wiiuse_set_ir_position(wm, wm->ir.pos);
}
/**
* @brief Set the IR sensitivity.
*

View File

@ -41,8 +41,7 @@
#ifdef WIN32
/* windows */
#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 */

View File

@ -131,24 +131,10 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
wm[i]->stack = WIIUSE_STACK_UNKNOWN;
#endif
wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
wm[i]->timeout = wm[i]->normal_timeout;
wm[i]->timeout = WIIMOTE_DEFAULT_TIMEOUT;
wm[i]->state = WIIMOTE_INIT_STATES;
wm[i]->flags = WIIUSE_INIT_FLAGS;
wm[i]->event = WIIUSE_NONE;
wm[i]->expansion.type = EXP_NONE;
wiiuse_set_aspect_ratio(wm[i], WIIUSE_ASPECT_4_3);
wiiuse_set_ir_position(wm[i], WIIUSE_IR_ABOVE);
wm[i]->orient_threshold = 0.5f;
wm[i]->accel_threshold = 5;
wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA;
}
return wm;
@ -172,10 +158,6 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
wm->leds = 0;
wm->state = WIIMOTE_INIT_STATES;
wm->read_req = NULL;
wm->handshake_state = 0;
wm->btns = 0;
wm->btns_held = 0;
wm->btns_released = 0;
memset(wm->event_buf, 0, sizeof(wm->event_buf));
#ifdef __linux__
@ -267,7 +249,6 @@ int wiiuse_set_report_type(struct wiimote_t* 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))
@ -277,14 +258,8 @@ int wiiuse_set_report_type(struct wiimote_t* wm) {
expansion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
if (motion && ir && expansion) buf[1] = WM_RPT_BTN_ACC_IR_EXP;
else if (motion && expansion) buf[1] = WM_RPT_BTN_ACC_EXP;
else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR;
else if (ir && expansion) buf[1] = WM_RPT_BTN_IR_EXP;
else if (ir) buf[1] = WM_RPT_BTN_ACC_IR;
else if (expansion) buf[1] = WM_RPT_BTN_EXP;
else if (motion) buf[1] = WM_RPT_BTN_ACC;
else buf[1] = WM_RPT_BTN;
buf[1] = 0x30;
WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
@ -296,97 +271,6 @@ int wiiuse_set_report_type(struct wiimote_t* wm) {
}
/**
* @brief Read data from the wiimote (callback version).
*
* @param wm Pointer to a wiimote_t structure.
* @param read_cb Function pointer to call when the data arrives from the wiimote.
* @param buffer An allocated buffer to store the data as it arrives from the wiimote.
* Must be persistent in memory and large enough to hold the data.
* @param addr The address of wiimote memory to read from.
* @param len The length of the block to be read.
*
* The library can only handle one data read request at a time
* because it must keep track of the buffer and other
* events that are specific to that request. So if a request
* has already been made, subsequent requests will be added
* to a pending list and be sent out when the previous
* finishes.
*/
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, unsigned short len) {
struct read_req_t* req;
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
return 0;
if (!buffer || !len || !read_cb)
return 0;
/* make this request structure */
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
req->cb = read_cb;
req->buf = buffer;
req->addr = addr;
req->size = len;
req->wait = len;
req->dirty = 0;
req->next = NULL;
/* add this to the request list */
if (!wm->read_req) {
/* root node */
wm->read_req = req;
WIIUSE_DEBUG("Data read request can be sent out immediately.");
/* send the request out immediately */
wiiuse_send_next_pending_read_request(wm);
} else {
struct read_req_t* nptr = wm->read_req;
for (; nptr->next; nptr = nptr->next);
nptr->next = req;
WIIUSE_DEBUG("Added pending data read request.");
}
return 1;
}
/**
* @brief Send the next pending data read request to the wiimote.
*
* @param wm Pointer to a wiimote_t structure.
*
* @see wiiuse_read_data()
*
* This function is not part of the wiiuse API.
*/
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))
return;
if (!wm->read_req) return;
/* skip over dirty ones since they have already been read */
req = wm->read_req;
while (req && req->dirty)
req = req->next;
if (!req)
return;
/* the offset is in big endian */
*(int*)(buf) = BIG_ENDIAN_LONG(req->addr);
/* the length is in big endian */
*(short*)(buf + 4) = BIG_ENDIAN_SHORT(req->size);
WIIUSE_DEBUG("Request read at address: 0x%x length: %i", req->addr, req->size);
wiiuse_send(wm, WM_CMD_READ_DATA, buf, 6);
}
/**
* @brief Write data to the wiimote.
@ -511,13 +395,12 @@ void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt
* @param normal_timeout The timeout in milliseconds for a normal read.
* @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) {
void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte timeout) {
int i;
if (!wm) return;
for (i = 0; i < wiimotes; ++i) {
wm[i]->normal_timeout = normal_timeout;
wm[i]->exp_timeout = exp_timeout;
wm[i]->timeout = timeout;
}
}

View File

@ -64,67 +64,6 @@
#define WIIMOTE_LED_3 0x40
#define WIIMOTE_LED_4 0x80
/* button codes */
#define WIIMOTE_BUTTON_TWO 0x0001
#define WIIMOTE_BUTTON_ONE 0x0002
#define WIIMOTE_BUTTON_B 0x0004
#define WIIMOTE_BUTTON_A 0x0008
#define WIIMOTE_BUTTON_MINUS 0x0010
#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
#define WIIMOTE_BUTTON_HOME 0x0080
#define WIIMOTE_BUTTON_LEFT 0x0100
#define WIIMOTE_BUTTON_RIGHT 0x0200
#define WIIMOTE_BUTTON_DOWN 0x0400
#define WIIMOTE_BUTTON_UP 0x0800
#define WIIMOTE_BUTTON_PLUS 0x1000
#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
#define WIIMOTE_BUTTON_UNKNOWN 0x8000
#define WIIMOTE_BUTTON_ALL 0x1F9F
/* nunchul button codes */
#define NUNCHUK_BUTTON_Z 0x01
#define NUNCHUK_BUTTON_C 0x02
#define NUNCHUK_BUTTON_ALL 0x03
/* classic controller button codes */
#define CLASSIC_CTRL_BUTTON_UP 0x0001
#define CLASSIC_CTRL_BUTTON_LEFT 0x0002
#define CLASSIC_CTRL_BUTTON_ZR 0x0004
#define CLASSIC_CTRL_BUTTON_X 0x0008
#define CLASSIC_CTRL_BUTTON_A 0x0010
#define CLASSIC_CTRL_BUTTON_Y 0x0020
#define CLASSIC_CTRL_BUTTON_B 0x0040
#define CLASSIC_CTRL_BUTTON_ZL 0x0080
#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
#define CLASSIC_CTRL_BUTTON_PLUS 0x0400
#define CLASSIC_CTRL_BUTTON_HOME 0x0800
#define CLASSIC_CTRL_BUTTON_MINUS 0x1000
#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
#define CLASSIC_CTRL_BUTTON_DOWN 0x4000
#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
/* guitar hero 3 button codes */
#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
#define GUITAR_HERO_3_BUTTON_GREEN 0x0010
#define GUITAR_HERO_3_BUTTON_BLUE 0x0020
#define GUITAR_HERO_3_BUTTON_RED 0x0040
#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
#define GUITAR_HERO_3_BUTTON_PLUS 0x0400
#define GUITAR_HERO_3_BUTTON_MINUS 0x1000
#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
/* guitar hero world tour touch bar codes */
#define GUITAR_HERO_3_TOUCH_AVAILABLE 0x1000
#define GUITAR_HERO_3_TOUCH_GREEN 0x1001
#define GUITAR_HERO_3_TOUCH_RED 0x1002
#define GUITAR_HERO_3_TOUCH_YELLOW 0x1004
#define GUITAR_HERO_3_TOUCH_BLUE 0x1008
#define GUITAR_HERO_3_TOUCH_ORANGE 0x1010
/* wiimote option flags */
#define WIIUSE_SMOOTHING 0x01
@ -132,57 +71,9 @@
#define WIIUSE_ORIENT_THRESH 0x04
#define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
#define WIIUSE_ORIENT_PRECISION 100.0f
/* expansion codes */
#define EXP_NONE 0
#define EXP_NUNCHUK 1
#define EXP_CLASSIC 2
#define EXP_GUITAR_HERO_3 3
#define EXP_WII_BOARD 4
#define EXP_WII_MOTION_PLUS 5
#define EXP_WII_MOTION_PLUS_NUNCHUK 6
/* IR correction types */
typedef enum ir_position_t {
WIIUSE_IR_ABOVE,
WIIUSE_IR_BELOW
} ir_position_t;
/**
* @brief Check if a button is pressed.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is pressed, 0 if not.
*/
#define IS_PRESSED(dev, button) ((dev->btns & button) == button)
/**
* @brief Check if a button is being held.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is held, 0 if not.
*/
#define IS_HELD(dev, button) ((dev->btns_held & button) == button)
/**
* @brief Check if a button is released on this event. \n\n
* This does not mean the button is not pressed, it means \n
* this button was just now released.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is released, 0 if not.
*
*/
#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
/**
* @brief Check if a button has just been pressed this event.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is pressed, 0 if not.
*/
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
/**
* @brief Return the IR sensitivity level.
@ -200,10 +91,7 @@ typedef enum ir_position_t {
else *lvl = 0; \
} while (0)
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
@ -217,8 +105,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.
*/
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_EXP_TIMEOUT 10
#define WIIMOTE_DEFAULT_TIMEOUT 30
typedef unsigned char byte;
typedef char sbyte;
@ -615,41 +502,21 @@ typedef struct wiimote_t {
WCONST int out_sock; /**< output socket */
WCONST int in_sock; /**< input socket */
#elif defined(_WIN32)
WCONST char devicepath[255]; /**< unique wiimote reference */
//WCONST ULONGLONG btaddr; /**< bt address (windows) */
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 */
#endif
WCONST int timeout; /**< read timeout */
WCONST byte normal_timeout; /**< normal timeout */
WCONST byte exp_timeout; /**< timeout for expansion handshake */
WCONST int state; /**< various state flags */
WCONST byte leds; /**< currently lit leds */
WCONST float battery_level; /**< battery level */
WCONST int flags; /**< options flag */
WCONST byte handshake_state; /**< the state of the connection handshake */
WCONST struct read_req_t* read_req; /**< list of data read requests */
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
WCONST struct expansion_t expansion; /**< wiimote expansion device */
WCONST struct vec3b_t accel; /**< current raw acceleration data */
WCONST struct orient_t orient; /**< current orientation on each axis */
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
WCONST struct ir_t ir; /**< IR data */
WCONST unsigned short btns; /**< what buttons have just been pressed */
WCONST unsigned short btns_held; /**< what buttons are being held down */
WCONST unsigned short btns_released; /**< what buttons were just released this */
WCONST float orient_threshold; /**< threshold for orient to generate an event */
WCONST int accel_threshold; /**< threshold for accel to generate an event */
WCONST struct wiimote_state_t lstate; /**< last saved state */
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
@ -691,10 +558,14 @@ WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
/* connect.c / io_win.c */
#ifdef _WIN32
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int wiimotes);
#else
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
#endif
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
WIIUSE_EXPORT extern void wiiuse_disconnect(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_timeout(struct wiimote_t** wm, int wiimotes, byte timeout);
#ifdef WIN32
WIIUSE_EXPORT extern int wiiuse_check_system_notification(unsigned int nMsg, WPARAM wParam, LPARAM lParam);
@ -706,9 +577,7 @@ int wiiuse_find_more(struct wiimote_t** wm, int max_wiimotes, int timeout);
#endif
/* ir.c */
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
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);
/* io.c */

View File

@ -79,17 +79,6 @@
#define WM_CMD_SPEAKER_MUTE 0x19// Size 1
#define WM_CMD_IR_2 0x1A
/* input report ids */
#define WM_RPT_CTRL_STATUS 0x20
#define WM_RPT_READ 0x21
#define WM_RPT_WRITE 0x22
#define WM_RPT_BTN 0x30
#define WM_RPT_BTN_ACC 0x31
#define WM_RPT_BTN_ACC_IR 0x33
#define WM_RPT_BTN_EXP 0x34
#define WM_RPT_BTN_ACC_EXP 0x35
#define WM_RPT_BTN_IR_EXP 0x36
#define WM_RPT_BTN_ACC_IR_EXP 0x37
#define WM_BT_INPUT 0x01
#define WM_BT_OUTPUT 0x02
@ -101,26 +90,14 @@
#define WM_VENDOR_ID 0x057E
#define WM_PRODUCT_ID 0x0306
/* controller status stuff */
#define WM_MAX_BATTERY_CODE 0xC8
/* offsets in wiimote memory */
#define WM_MEM_OFFSET_CALIBRATION 0x16
#define WM_EXP_MEM_BASE 0x04A40000
#define WM_EXP_MEM_ENABLE 0x04A40040
#define WM_EXP_MEM_CALIBR 0x04A40020
#define WM_EXP_MEM_ENABLE1 0x04A400F0
#define WM_EXP_MEM_ENABLE2 0x04A400FB
#define WM_REG_IR 0x04B00030
#define WM_REG_IR_BLOCK1 0x04B00000
#define WM_REG_IR_BLOCK2 0x04B0001A
#define WM_REG_IR_MODENUM 0x04B00033
#define WM_EXT_MP_MEM_BASE 0x04A60000
#define WM_EXT_MP_MEM_ENABLE1 0x04A600F0
#define WM_EXT_MP_MEM_ENABLE2 0x04A600FE
#define WM_EXT_MP_MEM_ENABLE3 0x04A400FB
/* ir block data */
#define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
@ -138,40 +115,8 @@
#define WM_IR_TYPE_EXTENDED 0x03
#define WM_IR_TYPE_FULL 0x05
/* controller status flags for the first message byte */
/* bit 1 is unknown */
#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
#define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
#define WM_CTRL_STATUS_BYTE1_LED_1 0x10
#define WM_CTRL_STATUS_BYTE1_LED_2 0x20
#define WM_CTRL_STATUS_BYTE1_LED_3 0x40
#define WM_CTRL_STATUS_BYTE1_LED_4 0x80
/* aspect ratio */
#define WM_ASPECT_16_9_X 660
#define WM_ASPECT_16_9_Y 370
#define WM_ASPECT_4_3_X 560
#define WM_ASPECT_4_3_Y 420
/**
* Expansion stuff
*/
/* encrypted expansion id codes (located at 0x04A400FC) */
/*#define EXP_ID_CODE_NUNCHUK 0x9A1EFEFE
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
#define EXP_ID_CODE_GUITAR 0x9A1EFDFB
*/
#define EXP_ID_CODE_NUNCHUK 0xa4200000
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0xa4200101
#define EXP_ID_CODE_GUITAR 0xa4200103 // 4 bytes are not unique enough
#define EXP_ID_CODE_WII_BOARD 0xa4200402
#define EXP_ID_CODE_MOTIONPLUS 0xa4200405
#define EXP_ID_CODE_MOTIONPLUS_EXT 0xa4200505
#define EXP_HANDSHAKE_LEN 224
/********************
*
@ -214,16 +159,7 @@
#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:
* St = St_last + (alpha * (tilt - St_last))
* alpha is between 0 and 1
*/
#define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f
#define SMOOTH_ROLL 0x01
#define SMOOTH_PITCH 0x02
#include "wiiuse.h"
@ -233,9 +169,7 @@ extern "C" {
/* not part of the api */
int wiiuse_set_report_type(struct wiimote_t* wm);
void wiiuse_send_next_pending_read_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, unsigned short len);
#ifdef __cplusplus
}

View File

@ -411,10 +411,6 @@
<Filter
Name="I/O"
>
<File
RelativePath=".\Src\io.c"
>
</File>
<File
RelativePath=".\Src\io.h"
>

View File

@ -544,7 +544,7 @@ void WiimoteBasicConfigDialog::IRCursorChanged(wxScrollEvent& event)
case IDS_TIMEOUT:
g_Config.bWiiReadTimeout = m_WiimoteTimeout[m_Page]->GetValue();
if (g_RealWiiMotePresent) {
wiiuse_set_timeout(WiiMoteReal::g_WiiMotesFromWiiUse, WiiMoteReal::g_NumberOfWiiMotes, g_Config.bWiiReadTimeout, g_Config.bWiiReadTimeout);
wiiuse_set_timeout(WiiMoteReal::g_WiiMotesFromWiiUse, WiiMoteReal::g_NumberOfWiiMotes, g_Config.bWiiReadTimeout);
}
break;
}

View File

@ -49,8 +49,8 @@ extern SWiimoteInitialize g_WiimoteInitialize;
namespace WiiMoteReal
{
bool g_RealWiiMoteInitialized = false;
bool g_RealWiiMoteAllocated = false;
bool g_RealWiiMoteInitialized = false;
bool g_RealWiiMoteAllocated = false;
// Forwarding
@ -61,6 +61,7 @@ class CWiiMote;
wiimote_t** g_WiiMotesFromWiiUse = NULL;
Common::Thread* g_pReadThread = NULL;
int g_NumberOfWiiMotes;
volatile int LastNumberOfWiimotes = 0;
CWiiMote* g_WiiMotes[MAX_WIIMOTES];
volatile bool g_Shutdown = false;
bool g_WiimoteInUse[MAX_WIIMOTES];
@ -78,6 +79,7 @@ unsigned int PairUpTimer = 2000;
int PairUpRefreshWiimote(bool addwiimote);
int PairUpFindNewSlot(void);
void ToggleEmulatorState(bool stop);
THREAD_RETURN PairUp_ThreadFunc(void* arg);
THREAD_RETURN RunInvisibleMessageWindow_ThreadFunc(void* arg);
#endif
@ -103,7 +105,8 @@ CWiiMote(u8 _WiimoteNumber, wiimote_t* _pWiimote)
#ifdef _WIN32
// F|RES: i dunno if we really need this
CancelIo(m_pWiiMote->dev_handle);
//CancelIo(m_pWiiMote->dev_handle);
CancelIoEx(m_pWiiMote->dev_handle,NULL);
#endif
}
@ -338,6 +341,8 @@ int Initialize()
// Return if already initialized
if (g_RealWiiMoteInitialized)
return g_NumberOfWiiMotes;
NeedsConnect.Init();
Connected.Init();
@ -363,18 +368,19 @@ int Initialize()
return 0;
// Call Wiiuse.dll
if(!g_WiiMotesFromWiiUse)
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, wiimote_slots, 5);
#ifdef _WIN32
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, wiimote_slots, LastNumberOfWiimotes);
#else
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, wiimote_slots, 5); //move the timeout var into wiimote_t structure to avoid confusion
#endif
LastNumberOfWiimotes = g_NumberOfWiiMotes;
DEBUG_LOG(WIIMOTE, "Found No of Wiimotes: %i", g_NumberOfWiiMotes);
if (g_NumberOfWiiMotes > 0)
{
/*
//TODO: We need here to re-order the wiimote structure, after we shutdown() and re-init().
// If we don't do this Wiimotes will change slots on addition of a new real wiimote during a game,
// causing a disconnect as well.
if (g_EmulatorState == PLUGIN_EMUSTATE_PAUSE)
SortWiimotes();
*/
g_RealWiiMotePresent = true;
// Create a new thread for listening for Wiimote data
// and also connecting in Linux/OSX.
@ -396,15 +402,12 @@ int Initialize()
if (g_Config.iIRLevel) {
wiiuse_set_ir_sensitivity(g_WiiMotesFromWiiUse[i], g_Config.iIRLevel);
}
// Set the sensor bar position, this should only affect the internal wiiuse api functions
wiiuse_set_ir_position(g_WiiMotesFromWiiUse[i], WIIUSE_IR_ABOVE);
}
if (g_Config.bWiiReadTimeout != 10)
wiiuse_set_timeout(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes, g_Config.bWiiReadTimeout, g_Config.bWiiReadTimeout);
if (g_Config.bWiiReadTimeout != 30)
wiiuse_set_timeout(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes, g_Config.bWiiReadTimeout);
// If we are connecting from the config window without a game running we set the LEDs
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY && g_RealWiiMotePresent)
if (g_EmulatorState == PLUGIN_EMUSTATE_STOP && g_RealWiiMotePresent)
FlashLights(true);
// Initialized, even if we didn't find a Wiimote
@ -416,7 +419,7 @@ int Initialize()
// Allocate each Real WiiMote found to a WiiMote slot with Source set to "WiiMote Real"
void Allocate()
{
if (g_RealWiiMoteAllocated)
if (g_RealWiiMoteAllocated)// && (g_NumberOfWiiMotes == LastNumberOfWiimotes))
return;
if (!g_RealWiiMoteInitialized)
Initialize();
@ -519,17 +522,14 @@ void Shutdown(void)
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY && g_RealWiiMotePresent)
FlashLights(false);
// TODOE: Save Wiimote-order here to restore it after an Init()
// we should best use the btaddress for this purpose, unfortunately it is a bit of a work to make wiiuse_find()
// get the btaddress of a bt device on windows with only a createfile() handle etc., but it wiiuse_find() is already doing that on linux
// Clean up wiiuse
#ifndef WIN32
wiiuse_cleanup(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes);
#endif
// Uninitialized
g_RealWiiMoteInitialized = false;
g_RealWiiMotePresent = false;
g_RealWiiMoteAllocated = false;
}
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size)
@ -613,7 +613,7 @@ int WiimotePairUp(bool unpair)
return -1;
}
nRadios--;
//DEBUG_LOG(WIIMOTE, "Pair-Up: Found %d radios\n", nRadios);
DEBUG_LOG(WIIMOTE, "Pair-Up: Found %d radios\n", nRadios);
// Pair with Wii device(s)
int radio = 0;
@ -637,7 +637,7 @@ int WiimotePairUp(bool unpair)
srch.fReturnConnected = TRUE; // does not filter properly somehow, so we 've to do an additional check on fConnected BT Devices
srch.fReturnUnknown = TRUE;
srch.fIssueInquiry = TRUE;
srch.cTimeoutMultiplier = 1;
srch.cTimeoutMultiplier = 2;
srch.hRadio = hRadios[radio];
//DEBUG_LOG(WIIMOTE, "Pair-Up: Scanning for BT Device(s)");
@ -653,6 +653,9 @@ int WiimotePairUp(bool unpair)
do
{
//btdi.szName is sometimes missings it's content - it's a bt feature..
DEBUG_LOG(WIIMOTE, "authed %i connected %i remembered %i ", btdi.fAuthenticated, btdi.fConnected, btdi.fRemembered);
if ((!wcscmp(btdi.szName, L"Nintendo RVL-WBC-01") || !wcscmp(btdi.szName, L"Nintendo RVL-CNT-01")) && !btdi.fConnected && !unpair)
{
//TODO: improve the read of the BT driver, esp. when batteries of the wiimote are removed while being fConnected
@ -708,7 +711,6 @@ LRESULT CALLBACK CallBackDeviceChange(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{
case WM_DEVICECHANGE:
// DBT_DEVNODES_CHANGED 0x007 (devnodes are atm not received); DBT_DEVICEARRIVAL 0x8000 DBT_DEVICEREMOVECOMPLETE 0x8004 // avoiding header file^^
if ( ( wParam == 0x8000 || wParam == 0x8004 || wParam == 0x0007 ) )
{
@ -733,6 +735,7 @@ LRESULT CALLBACK CallBackDeviceChange(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
PairUpRefreshWiimote(false);
}
break;
}
}
}
@ -787,6 +790,19 @@ THREAD_RETURN RunInvisibleMessageWindow_ThreadFunc(void* arg)
return (int)Msg.wParam;
}
void ToggleEmulatorState(bool stop) {
PostMessage(GetParent(g_WiimoteInitialize.hWnd), WM_USER, WM_USER_PAUSE, 0);
if (stop) {
while (g_EmulatorState != PLUGIN_EMUSTATE_PLAY) Sleep(50);
}
else {
while (g_EmulatorState == PLUGIN_EMUSTATE_PLAY) Sleep(50);
}
}
// function gets called by windows callbacks if a wiimote was either installed or removed
int PairUpRefreshWiimote(bool addwiimote)
{
@ -795,24 +811,25 @@ int PairUpRefreshWiimote(bool addwiimote)
if (g_EmulatorState != PLUGIN_EMUSTATE_PLAY)
{
Shutdown();
if (addwiimote)
{
connectslot = PairUpFindNewSlot();
}
Initialize();
//Allocate();
if (m_BasicConfigFrame != NULL)
m_BasicConfigFrame->UpdateGUI();
}
else {
Sleep(100);
PostMessage(GetParent(g_WiimoteInitialize.hWnd), WM_USER, WM_USER_PAUSE, 0);
while (g_EmulatorState == PLUGIN_EMUSTATE_PLAY) Sleep(50);
ToggleEmulatorState(true);
Shutdown();
if (addwiimote) {
if (addwiimote)
{
connectslot = PairUpFindNewSlot();
}
Initialize();
Allocate();
PostMessage(GetParent(g_WiimoteInitialize.hWnd), WM_USER, WM_USER_PAUSE, 0);
while (g_EmulatorState != PLUGIN_EMUSTATE_PLAY) Sleep(50);
ToggleEmulatorState(false);
if (addwiimote)
PostMessage(GetParent(g_WiimoteInitialize.hWnd), WM_USER, WM_USER_KEYDOWN, (3 + connectslot));
@ -821,12 +838,17 @@ int PairUpRefreshWiimote(bool addwiimote)
}
// returns first inactive wiimote slot to place new wiimote and set type to real wiimote
int PairUpFindNewSlot() {
int realWM = 0;
for(int x=0; x<MAX_WIIMOTES; x++)
{
if (WiiMoteEmu::WiiMapping[x].Source == 0)
{
WiiMoteEmu::WiiMapping[x].Source = 2;
return x;
} else if (WiiMoteEmu::WiiMapping[x].Source == 2) {
realWM++;
if (realWM>g_NumberOfWiiMotes)
return x;
}
}
return -1;

View File

@ -51,6 +51,7 @@ void ClearEvents();
extern wiimote_t** g_WiiMotesFromWiiUse;
extern bool g_Shutdown;
extern int g_NumberOfWiiMotes;
extern int LastNumberOfWiimotes;
#ifdef _WIN32
extern Common::Thread* g_AutoPairUpInvisibleWindow;
extern Common::Thread* g_AutoPairUpMonitoring;