Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…/blob/master/SuperTuxKart-0.8.1/lib/wiiuse/

to support the newer RVL-CNT-01-TR (MotionPlus Inside)
  • Loading branch information
windywang(王学强) committed Apr 22, 2015
1 parent ae54291 commit d5dc22c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
}

/* step 1 - calibration of accelerometers */
if(wm->type != WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE) // MotionPlus Inside wiimotes don't answer to that
{
struct accel_t* accel = &wm->accel_calib;

Expand Down
1 change: 0 additions & 1 deletion src/motion_plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm) {
id = from_big_endian_uint32_t(buf + 2);

if (id != EXP_ID_CODE_INACTIVE_MOTION_PLUS &&
id != EXP_ID_CODE_INACTIVE_MOTION_PLUS_BUILTIN &&
id != EXP_ID_CODE_NLA_MOTION_PLUS &&
id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK &&
id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC) {
Expand Down
35 changes: 22 additions & 13 deletions src/os_nix.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @brief Handles device I/O for *nix.
*/

#include "wiiuse_internal.h" /* for WM_RPT_CTRL_STATUS */
#include "io.h"
#include "events.h"
#include "os.h"
Expand All @@ -50,6 +49,7 @@
#include <sys/time.h> /* for struct timeval */
#include <unistd.h> /* for close, write */
#include <errno.h>
#include <stdbool.h>

static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address);

Expand Down Expand Up @@ -93,21 +93,37 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
found_devices = hci_inquiry(device_id, timeout, 128, NULL, &scan_info, IREQ_CACHE_FLUSH);
if (found_devices < 0) {
perror("hci_inquiry");
close(device_sock);
return 0;
}

WIIUSE_INFO("Found %i bluetooth device(s).", found_devices);

/* 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)) {
bool is_wiimote_regular = (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);

bool is_wiimote_plus = (scan_info[i].dev_class[0] == WM_PLUS_DEV_CLASS_0) &&
(scan_info[i].dev_class[1] == WM_PLUS_DEV_CLASS_1) &&
(scan_info[i].dev_class[2] == WM_PLUS_DEV_CLASS_2);
if (is_wiimote_regular || is_wiimote_plus) {
/* found a device */
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);

const char* str_type;
if(is_wiimote_regular)
{
wm[found_wiimotes]->type = WIIUSE_WIIMOTE_REGULAR;
str_type = " (regular wiimote)";
}
else if(is_wiimote_plus)
{
wm[found_wiimotes]->type = WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE;
str_type = " (motion plus inside)";
}

WIIUSE_INFO("Found wiimote (%s) [id %i].", wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid);
WIIUSE_INFO("Found wiimote (type: %s) (%s) [id %i].", str_type, wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid);

wm[found_wiimotes]->bdaddr = scan_info[i].bdaddr;
WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND);
Expand Down Expand Up @@ -305,13 +321,6 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
/* propagate the event */
propagate_event(wm[i], read_buffer[0], read_buffer + 1);
evnt += (wm[i]->event != WIIUSE_NONE);
} else if (!WIIMOTE_IS_CONNECTED(wm[i])) {
/* freshly disconnected */
wm[i]->event = (r==0) ? WIIUSE_DISCONNECT : WIIUSE_UNEXPECTED_DISCONNECT;
evnt++;
/* propagate the event:
Emit a controller-status type event. */
propagate_event(wm[i], WM_RPT_CTRL_STATUS, 0);
}
} else {
/* send out any waiting writes */
Expand Down
5 changes: 4 additions & 1 deletion src/os_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
attr.Size = sizeof(attr);
i = HidD_GetAttributes(dev, &attr);

if ((attr.VendorID == WM_VENDOR_ID) && (attr.ProductID == WM_PRODUCT_ID)) {
if ((attr.VendorID == WM_VENDOR_ID) && (attr.ProductID == WM_PRODUCT_ID || attr.ProductID == WM_PLUS_PRODUCT_ID)) {
/* this is a wiimote */
wm[found]->dev_handle = dev;

if(attr.ProductID == WM_PLUS_PRODUCT_ID)
wm[found]->type = WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE;

wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, "");
wm[found]->hid_overlap.Offset = 0;
wm[found]->hid_overlap.OffsetHigh = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/wiiuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
wm[i]->accel_threshold = 5;

wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA;

wm[i]->type = WIIUSE_WIIMOTE_REGULAR;
}

return wm;
Expand Down
16 changes: 11 additions & 5 deletions src/wiiuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@

#define WIIUSE_MAJOR 0
#define WIIUSE_MINOR 14
#define WIIUSE_MICRO 2

#define WIIUSE_VERSION_TRANSFORM(MAJ, MIN, MICRO) (MAJ * 1000000 + MIN * 1000 + MICRO)
#define WIIUSE_HAS_VERSION(MAJ, MIN, MICRO) ( WIIUSE_VERSION_TRANSFORM(MAJ, MIN, MICRO) <= WIIUSE_VERSION_TRANSFORM(WIIUSE_MAJOR, WIIUSE_MINOR, WIIUSE_MICRO) )
#define WIIUSE_MICRO 0

#ifndef WIIUSE_PLATFORM
#if defined(_WIN32)
Expand Down Expand Up @@ -294,7 +291,7 @@ typedef enum ir_position_t {
* @param lvl [out] Pointer to an int that will hold the level setting.
* If no level is set 'lvl' will be set to 0.
*/
#define WIIUSE_GET_IR_SENSITIVITY(wm, lvl) \
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
do { \
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
Expand Down Expand Up @@ -716,6 +713,14 @@ typedef enum WIIUSE_EVENT_TYPE {
WIIUSE_MOTION_PLUS_REMOVED
} WIIUSE_EVENT_TYPE;

/**
* @brief Type of wiimote peripheral
*/
typedef enum WIIUSE_WIIMOTE_TYPE {
WIIUSE_WIIMOTE_REGULAR = 0,
WIIUSE_WIIMOTE_MOTION_PLUS_INSIDE,
} WIIUSE_WIIMOTE_TYPE;

/**
* @brief Main Wiimote device structure.
*
Expand Down Expand Up @@ -786,6 +791,7 @@ typedef struct wiimote_t {

WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */
WCONST byte motion_plus_id[6];
WCONST WIIUSE_WIIMOTE_TYPE type;
} wiimote;

/** @brief Data passed to a callback during wiiuse_update() */
Expand Down
24 changes: 16 additions & 8 deletions src/wiiuse_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,25 @@
* 00000000 00100101 00000100
*/
#ifdef WIIUSE_MAC
#define WM_DEV_MINOR_CLASS 0x01
#define WM_DEV_MINOR_CLASS 0x01 // Regular wiimote
#define WM_DEV_MAJOR_CLASS 0x05
#define WM_DEV_MAJOR_SERVICE 0x01

#define WM_PLUS_DEV_MINOR_CLASS 0x02 // For the newer RVL-CNT-01-TR (MotionPlus Inside)
#define WM_PLUS_DEV_MAJOR_CLASS 0x05
#define WM_PLUS_DEV_MAJOR_SERVICE 0x00
#else
#define WM_DEV_CLASS_0 0x04
#define WM_DEV_CLASS_0 0x04 // Regular wiimote
#define WM_DEV_CLASS_1 0x25
#define WM_DEV_CLASS_2 0x00

#define WM_PLUS_DEV_CLASS_0 0x08 // For the newer RVL-CNT-01-TR (MotionPlus Inside)
#define WM_PLUS_DEV_CLASS_1 0x05
#define WM_PLUS_DEV_CLASS_2 0x00
#endif
#define WM_VENDOR_ID 0x057E
#define WM_PRODUCT_ID 0x0306
#define WM_PRODUCT_ID 0x0306 // Regular wiimote
#define WM_PLUS_PRODUCT_ID 0x0330 // For the newer RVL-CNT-01-TR (MotionPlus Inside)

/* controller status stuff */
#define WM_MAX_BATTERY_CODE 0xC8
Expand Down Expand Up @@ -216,11 +225,10 @@
#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_INACTIVE_MOTION_PLUS_BUILTIN 0xA4200005 /** Inactive Motion Plus ID in Wii Remote Plus */
#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_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

Expand Down
27 changes: 27 additions & 0 deletions src/wiiuse_msvcstdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ extern "C" {
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;


// 7.18.1.2 Minimum-width integer types
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;

// 7.18.1.3 Fastest minimum-width integer types
typedef int8_t int_fast8_t;
// Redefinition with different type on VS 2012
#if (_MSC_VER < 1700)
typedef int16_t int_fast16_t;
#endif
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
// Redefinition with different type on VS 2012
#if (_MSC_VER < 1700)
typedef uint16_t uint_fast16_t;
#endif
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;

// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
typedef signed __int64 intptr_t;
Expand Down

0 comments on commit d5dc22c

Please sign in to comment.