From db4c7934ec5f8389367cbe2097cb60a60ab74ccd Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Mon, 7 Feb 2011 07:43:34 +0000 Subject: [PATCH] --- lib/wiiuse.lib | Bin 0 -> 10344 bytes msvc/WiiUseJ.sln | 20 ++ msvc/WiiUseJ.suo | Bin 0 -> 19456 bytes msvc/WiiUseJ.vcxproj | 98 +++++ msvc/WiiUseJ.vcxproj.filters | 33 ++ msvc/WiiUseJ.vcxproj.user | 3 + msvc/copy.bat | 1 + speaker.h | 23 ++ wiiuse.h | 653 ++++++++++++++++++++++++++++++++++ wiiusej_Speaker.c | 68 ++++ wiiusej_Speaker.h | 317 +++++++++++++++++ wiiusej_WiiUseApi.c | 671 +++++++++++++++++++++++++++++++++++ wiiusej_WiiUseApi.def | 34 ++ wiiusej_WiiUseApi.h | 317 +++++++++++++++++ 14 files changed, 2238 insertions(+) create mode 100644 lib/wiiuse.lib create mode 100644 msvc/WiiUseJ.sln create mode 100644 msvc/WiiUseJ.suo create mode 100644 msvc/WiiUseJ.vcxproj create mode 100644 msvc/WiiUseJ.vcxproj.filters create mode 100644 msvc/WiiUseJ.vcxproj.user create mode 100644 msvc/copy.bat create mode 100644 speaker.h create mode 100644 wiiuse.h create mode 100644 wiiusej_Speaker.c create mode 100644 wiiusej_Speaker.h create mode 100644 wiiusej_WiiUseApi.c create mode 100644 wiiusej_WiiUseApi.def create mode 100644 wiiusej_WiiUseApi.h diff --git a/lib/wiiuse.lib b/lib/wiiuse.lib new file mode 100644 index 0000000000000000000000000000000000000000..fe754f9a599d9ecd20d478e8adbd85489ca1ee23 GIT binary patch literal 10344 zcmb_iOK%iM5H8yRj6;Zd7{BfH0~!j>L&!*&W*>);pWs*+rbl zDW@pEAcq{Hh!ck>ha4k>I3binet?gN6K4)ds;9fBt9yFJvssT+p6=?Z{`yrl)wQ1b ztXMB?ecpFAr$6TxFD@093(NU}&Oaxrix? zr<`Vfz&g_G8%}d80F35wtc(UfffYH!*oQCgW9cla-r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JPl(=QLa;otVweCdwkkG&r}vTYuhkUJE$ zg)aLN-WiK!({g{8x~RsXm?zmy2Va_TMIsxI(?zr@_WqA`27V&`*KHu^1&t_s{MH$G z;@5}%R%;da_M-8$c43d-Iszm9%P<$eY2dMG(^^*F#$D(5tvzty&tn`*#M;e=Q49a` z9t-&|MF8}+lkdNZecSoQMf?76r}XT!zwWKP@9!TsT}RT*1mxt4_1Wg zz4$Bk1N`X7P%7C!ny3EShZAA+4rb%wOe&ig(CIv(F4~9W$N>JeamVQB?vS_H*H|5_ zaX0y^>m26Y@xfCC;|`PZSuG`6+ETO+qLc;kI{?ak=;5h7m7EeUaWPAE=VGbAPv!sl z&6m?JXN+1+Z|1Ec2AX&C{J)4_rXqgT@x)kjxN!ceJfD;3w@d_4QR$gOFD4I0YUdt* zzVhbK%l(6EK#-YwAEUES<1?Y(nYu4Ta$bLGviINkIgf#Md;iD!3k3Qfmt#fZ@bVT{ z;NnsA3;)9&zjX$FBL2^hfd5{NHhcWmZ$Rk(EyrAL0QW$f*0OpMcLjdSfevqqy?2UV yKdqyWjPwr}+EdQIQR#(OKE3nmvu{}MJ{DY)I{&?+GeMGm3nsD+hE@IlT>b}PU~q>3 literal 0 HcmV?d00001 diff --git a/msvc/WiiUseJ.vcxproj b/msvc/WiiUseJ.vcxproj new file mode 100644 index 0000000..5364935 --- /dev/null +++ b/msvc/WiiUseJ.vcxproj @@ -0,0 +1,98 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {A4941142-CEF2-43EF-873E-D8C5F0D33BC4} + Win32Proj + WiiUseJ + + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + + + + + + + + + + + true + C:\Program Files\Java\jdk1.6.0_20\include;C:\Program Files\Java\jdk1.6.0_20\include\win32;C:\Users\Rik\My Dropbox\Eclipse\WiiTunes\c\wiiuse;$(IncludePath) + + + false + C:\Program Files (x86)\Java\jdk1.6.0_23\include;C:\Program Files (x86)\Java\jdk1.6.0_23\include\win32;$(IncludePath) + .\Release\ + $(ExtensionsToDeleteOnClean) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;WIIUSEJ_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + C:\Users\Rik\My Dropbox\Eclipse\WiiTunes\c\wiiuse\msvc\Release;%(AdditionalLibraryDirectories) + wiiuse.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;WIIUSEJ_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + wiiuse.lib;%(AdditionalDependencies) + ..\..\wiiuse\msvc\Release;%(AdditionalLibraryDirectories) + + + copy.bat + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/WiiUseJ.vcxproj.filters b/msvc/WiiUseJ.vcxproj.filters new file mode 100644 index 0000000..cc1e8b3 --- /dev/null +++ b/msvc/WiiUseJ.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/msvc/WiiUseJ.vcxproj.user b/msvc/WiiUseJ.vcxproj.user new file mode 100644 index 0000000..695b5c7 --- /dev/null +++ b/msvc/WiiUseJ.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/msvc/copy.bat b/msvc/copy.bat new file mode 100644 index 0000000..017a544 --- /dev/null +++ b/msvc/copy.bat @@ -0,0 +1 @@ +copy Release\WiiUseJ.dll ..\..\..\java\native\ \ No newline at end of file diff --git a/speaker.h b/speaker.h new file mode 100644 index 0000000..8b8267d --- /dev/null +++ b/speaker.h @@ -0,0 +1,23 @@ +#include "wiiuse.h" + +#define WIIMOTE_GET_RUMBLE(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE) ? 0x01 : 0x00) + +#define WM_CMD_SPEAKER_ENABLE 0x14 +#define WM_CMD_STREAM_DATA 0x18 +#define WM_CMD_SPEAKER_MUTE 0x19 + +#define WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE 0x04 + +#define WM_REG_SPEAKER 0x04a20001 + +static byte cfg[9] = {0x00, 0x00, 0x00, 0xdd, 0x40, 0x00, 0x00, 0x01, 0x01}; + +WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm); +WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm); +WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm); +WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm); +WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm); +WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm); +WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, byte vol); +WIIUSE_EXPORT extern void wiiuse_speaker_frequency(struct wiimote_t* wm, unsigned short freq); +WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data); \ No newline at end of file diff --git a/wiiuse.h b/wiiuse.h new file mode 100644 index 0000000..9dff81c --- /dev/null +++ b/wiiuse.h @@ -0,0 +1,653 @@ +/* + * 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 API header file. + * + * If this file is included from inside the wiiuse source + * and not from a third party program, then wiimote_internal.h + * is also included which extends this file. + */ + +#ifndef WIIUSE_H_INCLUDED +#define WIIUSE_H_INCLUDED + +#ifdef _WIN32 + /* windows */ + #include +#else + /* nix */ + #include +#endif + +#ifdef WIIUSE_INTERNAL_H_INCLUDED + #define WCONST +#else + #define WCONST const +#endif + +/* led bit masks */ +#define WIIMOTE_LED_NONE 0x00 +#define WIIMOTE_LED_1 0x10 +#define WIIMOTE_LED_2 0x20 +#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. + * @param wm Pointer to a wiimote_t structure. + * @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(dev, lvl) \ + do { \ + if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \ + else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \ + else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \ + else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \ + else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \ + 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) + +/* + * 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. + */ +#ifdef WIN32 + #define WIIMOTE_DEFAULT_TIMEOUT 10 + #define WIIMOTE_EXP_TIMEOUT 10 +#endif + +typedef unsigned char byte; +typedef char sbyte; + +struct wiimote_t; +struct vec3b_t; +struct orient_t; +struct gforce_t; + + +/** + * @brief Callback that handles a read event. + * + * @param wm Pointer to a wiimote_t structure. + * @param data Pointer to the filled data block. + * @param len Length in bytes of the data block. + * + * @see wiiuse_init() + * + * A registered function of this type is called automatically by the wiiuse + * library when the wiimote has returned the full data requested by a previous + * call to wiiuse_read_data(). + */ +typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len); + + +/** + * @struct read_req_t + * @brief Data read request structure. + */ +struct read_req_t { + wiiuse_read_cb cb; /**< read data callback */ + byte* buf; /**< buffer where read data is written */ + unsigned int addr; /**< the offset that the read started at */ + unsigned short size; /**< the length of the data read */ + unsigned short wait; /**< num bytes still needed to finish read */ + byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */ + + struct read_req_t* next; /**< next read request in the queue */ +}; + + +/** + * @struct vec2b_t + * @brief Unsigned x,y byte vector. + */ +typedef struct vec2b_t { + byte x, y; +} vec2b_t; + + +/** + * @struct vec3b_t + * @brief Unsigned x,y,z byte vector. + */ +typedef struct vec3b_t { + byte x, y, z; +} vec3b_t; + + +/** + * @struct vec3f_t + * @brief Signed x,y,z float struct. + */ +typedef struct vec3f_t { + float x, y, z; +} vec3f_t; + + +/** + * @struct orient_t + * @brief Orientation struct. + * + * Yaw, pitch, and roll range from -180 to 180 degrees. + */ +typedef struct orient_t { + float roll; /**< roll, this may be smoothed if enabled */ + float pitch; /**< pitch, this may be smoothed if enabled */ + float yaw; + + float a_roll; /**< absolute roll, unsmoothed */ + float a_pitch; /**< absolute pitch, unsmoothed */ +} orient_t; + + +/** + * @struct gforce_t + * @brief Gravity force struct. + */ +typedef struct gforce_t { + float x, y, z; +} gforce_t; + + +/** + * @struct accel_t + * @brief Accelerometer struct. For any device with an accelerometer. + */ +typedef struct accel_t { + struct vec3b_t cal_zero; /**< zero calibration */ + struct vec3b_t cal_g; /**< 1g difference around 0cal */ + + float st_roll; /**< last smoothed roll value */ + float st_pitch; /**< last smoothed roll pitch */ + float st_alpha; /**< alpha value for smoothing [0-1] */ +} accel_t; + + +/** + * @struct ir_dot_t + * @brief A single IR source. + */ +typedef struct ir_dot_t { + byte visible; /**< if the IR source is visible */ + + unsigned int x; /**< interpolated X coordinate */ + unsigned int y; /**< interpolated Y coordinate */ + + short rx; /**< raw X coordinate (0-1023) */ + short ry; /**< raw Y coordinate (0-767) */ + + byte order; /**< increasing order by x-axis value */ + + byte size; /**< size of the IR dot (0-15) */ +} ir_dot_t; + + +/** + * @enum aspect_t + * @brief Screen aspect ratio. + */ +typedef enum aspect_t { + WIIUSE_ASPECT_4_3, + WIIUSE_ASPECT_16_9 +} aspect_t; + + +/** + * @struct ir_t + * @brief IR struct. Hold all data related to the IR tracking. + */ +typedef struct ir_t { + struct ir_dot_t dot[4]; /**< IR dots */ + byte num_dots; /**< number of dots at this time */ + + enum aspect_t aspect; /**< aspect ratio of the screen */ + + enum ir_position_t pos; /**< IR sensor bar position */ + + unsigned int vres[2]; /**< IR virtual screen resolution */ + int offset[2]; /**< IR XY correction offset */ + int state; /**< keeps track of the IR state */ + + int ax; /**< absolute X coordinate */ + int ay; /**< absolute Y coordinate */ + + int x; /**< calculated X coordinate */ + int y; /**< calculated Y coordinate */ + + float distance; /**< pixel distance between first 2 dots*/ + float z; /**< calculated distance */ +} ir_t; + + +/** + * @struct joystick_t + * @brief Joystick calibration structure. + * + * The angle \a ang is relative to the positive y-axis into quadrant I + * and ranges from 0 to 360 degrees. So if the joystick is held straight + * upwards then angle is 0 degrees. If it is held to the right it is 90, + * down is 180, and left is 270. + * + * The magnitude \a mag is the distance from the center to where the + * joystick is being held. The magnitude ranges from 0 to 1. + * If the joystick is only slightly tilted from the center the magnitude + * will be low, but if it is closer to the outter edge the value will + * be higher. + */ +typedef struct joystick_t { + struct vec2b_t max; /**< maximum joystick values */ + struct vec2b_t min; /**< minimum joystick values */ + struct vec2b_t center; /**< center joystick values */ + + float ang; /**< angle the joystick is being held */ + float mag; /**< magnitude of the joystick (range 0-1) */ +} joystick_t; + + +/** + * @struct nunchuk_t + * @brief Nunchuk expansion device. + */ +typedef struct nunchuk_t { + struct accel_t accel_calib; /**< nunchuk accelerometer calibration */ + struct joystick_t js; /**< joystick calibration */ + + int* flags; /**< options flag (points to wiimote_t.flags) */ + + byte btns; /**< what buttons have just been pressed */ + byte btns_held; /**< what buttons are being held down */ + byte btns_released; /**< what buttons were just released this */ + + float orient_threshold; /**< threshold for orient to generate an event */ + int accel_threshold; /**< threshold for accel to generate an event */ + + struct vec3b_t accel; /**< current raw acceleration data */ + struct orient_t orient; /**< current orientation on each axis */ + struct gforce_t gforce; /**< current gravity forces on each axis */ +} nunchuk_t; + + +/** + * @struct classic_ctrl_t + * @brief Classic controller expansion device. + */ +typedef struct classic_ctrl_t { + short btns; /**< what buttons have just been pressed */ + short btns_held; /**< what buttons are being held down */ + short btns_released; /**< what buttons were just released this */ + + float r_shoulder; /**< right shoulder button (range 0-1) */ + float l_shoulder; /**< left shoulder button (range 0-1) */ + + struct joystick_t ljs; /**< left joystick calibration */ + struct joystick_t rjs; /**< right joystick calibration */ +} classic_ctrl_t; + + +/** + * @struct guitar_hero_3_t + * @brief Guitar Hero 3 expansion device. + */ +typedef struct guitar_hero_3_t { + short btns; /**< what buttons have just been pressed */ + short btns_held; /**< what buttons are being held down */ + short btns_released; /**< what buttons were just released this */ + + float whammy_bar; /**< whammy bar (range 0-1) */ + + struct joystick_t js; /**< joystick calibration */ +} guitar_hero_3_t; + + +/** + * @struct expansion_t + * @brief Generic expansion device plugged into wiimote. + */ +typedef struct expansion_t { + int type; /**< type of expansion attached */ + + union { + struct nunchuk_t nunchuk; + struct classic_ctrl_t classic; + struct guitar_hero_3_t gh3; + }; +} expansion_t; + + +/** + * @enum win32_bt_stack_t + * @brief Available bluetooth stacks for Windows. + */ +typedef enum win_bt_stack_t { + WIIUSE_STACK_UNKNOWN, + WIIUSE_STACK_MS, + WIIUSE_STACK_BLUESOLEIL +} win_bt_stack_t; + + +/** + * @struct wiimote_state_t + * @brief Significant data from the previous event. + */ +typedef struct wiimote_state_t { + /* expansion_t */ + float exp_ljs_ang; + float exp_rjs_ang; + float exp_ljs_mag; + float exp_rjs_mag; + unsigned short exp_btns; + struct orient_t exp_orient; + struct vec3b_t exp_accel; + float exp_r_shoulder; + float exp_l_shoulder; + + /* ir_t */ + int ir_ax; + int ir_ay; + float ir_distance; + + struct orient_t orient; + unsigned short btns; + + struct vec3b_t accel; +} wiimote_state_t; + + +/** + * @enum WIIUSE_EVENT_TYPE + * @brief Events that wiiuse can generate from a poll. + */ +typedef enum WIIUSE_EVENT_TYPE { + WIIUSE_NONE = 0, + WIIUSE_EVENT, + WIIUSE_STATUS, + WIIUSE_CONNECT, + WIIUSE_DISCONNECT, + WIIUSE_UNEXPECTED_DISCONNECT, + WIIUSE_READ_DATA, + WIIUSE_NUNCHUK_INSERTED, + WIIUSE_NUNCHUK_REMOVED, + WIIUSE_CLASSIC_CTRL_INSERTED, + WIIUSE_CLASSIC_CTRL_REMOVED, + WIIUSE_GUITAR_HERO_3_CTRL_INSERTED, + WIIUSE_GUITAR_HERO_3_CTRL_REMOVED +} WIIUSE_EVENT_TYPE; + +/** + * @struct wiimote_t + * @brief Wiimote structure. + */ +typedef struct wiimote_t { + WCONST int unid; /**< user specified id */ + + #ifndef WIN32 + 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 + 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 exp; /**< 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; + + +/***************************************** + * + * Include API specific stuff + * + *****************************************/ + +#ifdef _WIN32 + #define WIIUSE_EXPORT_DECL __declspec(dllexport) + #define WIIUSE_IMPORT_DECL __declspec(dllimport) +#else + #define WIIUSE_EXPORT_DECL + #define WIIUSE_IMPORT_DECL +#endif + +#ifdef WIIUSE_COMPILE_LIB + #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL +#else + #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* wiiuse.c */ +WIIUSE_EXPORT extern const char* wiiuse_version(); + +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, unsigned short len); +WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, 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); + +/* connect.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); + +/* 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); + + +#ifdef __cplusplus +} +#endif + + +#endif /* WIIUSE_H_INCLUDED */ + diff --git a/wiiusej_Speaker.c b/wiiusej_Speaker.c new file mode 100644 index 0000000..c795649 --- /dev/null +++ b/wiiusej_Speaker.c @@ -0,0 +1,68 @@ +#include "wiiusej_WiiUseApi.h" +#include "speaker.h" +#include "wiiuse.h" + +static wiimote** wiimotes; +static int nbMaxWiimotes; + +/* +void test(struct wiimote_t* wm) { + int i; + byte data[20] = { + 0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3, + 0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3}; + wiiuse_speaker_activate(wm); + for (i = 0; i < 50; ++i) { + wiiuse_speaker_data(wm, data); + } + wiiuse_speaker_deactivate(wm); +}*/ + +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker +(JNIEnv *env, jobject obj, jint id) { + wiiuse_speaker_activate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); +} + +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker +(JNIEnv *env, jobject obj, jint id) { + wiiuse_speaker_deactivate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); +} +/* +void testen(struct wiimote_t* wm, unsigned short freq) { + if (freq > 0x0000) { + cfg[2] = freq & 0x00ff; + cfg[3] = (freq & 0xff00) >> 8; + } + printf("unaangepast %d\n", freq); + printf("speaker 0x%02x%02x\n", cfg[2], cfg[3]); + fflush(stdout); + wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 9); +}*/ + + +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFrequency +(JNIEnv *env, jobject obj, jint id, jint freq) { + wiiuse_speaker_frequency(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (unsigned short) freq); + //short a = ((short) freq) & 0xffff; + //printf("jni %d %d\n", freq, a); + //fflush(stdout); + //testen(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (unsigned short) freq); +} + +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume +(JNIEnv *env, jobject obj, jint id, jshort vol) { + wiiuse_speaker_frequency(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), vol); +} + + +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData +(JNIEnv *env, jobject obj, jint id, jshortArray sArray) { + int i = 0; + jshort *jShorts = (*env)->GetShortArrayElements(env, sArray, JNI_FALSE); + byte data[sizeof(jShorts)]; + for (i = 0; i < sizeof(jShorts); ++i) { + data[i] = (byte) jShorts[i]; + } + wiiuse_speaker_data(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), data); + (*env)->ReleaseShortArrayElements(env, sArray, jShorts, JNI_FALSE); +} \ No newline at end of file diff --git a/wiiusej_Speaker.h b/wiiusej_Speaker.h new file mode 100644 index 0000000..031958b --- /dev/null +++ b/wiiusej_Speaker.h @@ -0,0 +1,317 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class wiiusej_WiiUseApi */ + +#ifndef _Included_wiiusej_WiiUseApi +#define _Included_wiiusej_WiiUseApi +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: wiiusej_WiiUseApi + * Method: connect + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: find + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: closeConnection + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: getUnId + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: cleanUp + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp + (JNIEnv *, jobject); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateRumble + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateRumble + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateIRTracking + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateIRTracking + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateMotionSensing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateMotionSensing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setLeds + * Signature: (IZZZZ)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds + (JNIEnv *, jobject, jint, jboolean, jboolean, jboolean, jboolean); + +/* + * Class: wiiusej_WiiUseApi + * Method: setOrientThreshold + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: setAccelThreshold + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setAlphaSmoothing + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: reSync + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateSmoothing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateSmoothing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateContinuous + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateContinuous + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setScreenRatio43 + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43 + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setScreenRatio169 + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169 + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSensorBarAboveScreen + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSensorBarBelowScreen + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setVirtualScreenResolution + * Signature: (III)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution + (JNIEnv *, jobject, jint, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: getStatus + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setTimeout + * Signature: (ISS)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout + (JNIEnv *, jobject, jint, jshort, jshort); + +/* + * Class: wiiusej_WiiUseApi + * Method: setIrSensitivity + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setNunchukOrientationThreshold + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: setNunchukAccelerationThreshold + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: windowsSetBluetoothStack + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: specialPoll + * Signature: (Lwiiusej/wiiusejevents/utils/EventsGatherer;)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll + (JNIEnv *, jobject, jobject); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateSpeaker + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateSpeaker + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSpeakerVolume + * Signature: (IS)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume + (JNIEnv *, jobject, jint, jshort); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSpeakerFrequency + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFrequency + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: streamSpeakerData + * Signature: (I[S)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData + (JNIEnv *, jobject, jint, jshortArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/wiiusej_WiiUseApi.c b/wiiusej_WiiUseApi.c new file mode 100644 index 0000000..8d43e93 --- /dev/null +++ b/wiiusej_WiiUseApi.c @@ -0,0 +1,671 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ 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. + * + * WiiuseJ 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 WiiuseJ. If not, see . + */ +#ifndef WIN32 +#include +#else + +#endif + +#include "wiiusej_WiiUseApi.h" +#include "wiiuse.h" +/* + * These are some identifiers for wiimotes + * + * See below in main() for what they are used for. + */ +#define WIIMOTE_STATE_RUMBLE 0x0010 +#define WIIMOTE_STATE_CONNECTED 0x0008 +#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) +#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s)) +#define WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wm, lvl) \ + do { \ + if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \ + else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \ + else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \ + else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \ + else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \ + else *lvl = 0; \ + } while (0) + +/********************* VARIABLES DECLARATIONS *****************************/ + +/* + * Make a temp array of wiimote ids. + * Here I only anticipate connecting up to + * two wiimotes. Each wiimote connected + * will get one of these ids. + */ +static wiimote** wiimotes; +static int nbMaxWiimotes; + +/****************** GENERAL FUNCTIONS DEFINITIONS *************************/ + +/** + * Connect to a wiimote or wiimotes once an address is known. + * @param nbWiimotes The number of wiimotes. + * @return The number of wiimotes that successfully connected. + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect +(JNIEnv *env, jobject obj, jint nbWiimotes) { + return wiiuse_connect(wiimotes, nbWiimotes); +} + +/** + * Find a wiimote or wiimotes. + * @param nbMaxWiimotes The number of wiimotes. + * @param timeout The number of seconds before the search times out. + * @return The number of wiimotes found. + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find +(JNIEnv *env, jobject obj, jint nbMaxWiimotes, jint timeout) { + return wiiuse_find(wiimotes, nbMaxWiimotes, timeout); +} + +/** + * Initialize an array of wiimote structures (for the C side of the library). + * @param nbPossibleWiimotes size of the array. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init +(JNIEnv *env, jobject obj, jint nbPossibleWiimotes) { + wiimotes = wiiuse_init(nbPossibleWiimotes); + nbMaxWiimotes = nbPossibleWiimotes; +} + +/** + * Close connection to the wiimote with the given id. + * + * @param id the id of the wiimote to disconnect.Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection +(JNIEnv *env, jobject obj, jint id) { + wiiuse_disconnect(wiimotes[id]); +} + +/** + * Get unique id of a wiimote in the wiimotes array. + * Please make sure you call an existing index with a + * wiimote initialized at this index, + * other wise you'll get a wrong value. + * @param index index of the wiimote in the wiimotes array. + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId +(JNIEnv *env, jobject obj, jint index) { + return wiimotes[index]->unid; +} + +/** + * Shutdown api. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp +(JNIEnv *env, jobject obj) { + wiiuse_cleanup(wiimotes, nbMaxWiimotes); +} + +/** + * Activate rumble for the wiimote with the given id. + * @param id the id of the wiimote.Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble +(JNIEnv *env, jobject obj, jint id) { + wiiuse_rumble(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1); +} + +/** + * Deactivate rumble for the wiimote with the given id. + * @param id the id of the wiimote.Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble +(JNIEnv *env, jobject obj, jint id) { + wiiuse_rumble(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0); +} + +/** + * Activate IR TRacking for the wiimote with the given id. + * @param id the id of the wiimote. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_ir(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1); +} + +/** + * Deactivate IR TRacking for the wiimote with the given id. + * @param id the id of the wiimote.Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_ir(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0); +} + +/** + * Activate Motion Sensing for the wiimote with the given id. + * @param id the id of the wiimote.Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing +(JNIEnv *env, jobject obj, jint id) { + wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1); +} + +/** + * Deactivate Motion Sensing for the wiimote with the given id. + * @param id the id of the wiimote.Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing +(JNIEnv *env, jobject obj, jint id) { + wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0); +} + +/** + * Set wiimote leds status. + * @param id the id of the wiimote concerned + * @param led1 status of led1: True=ON, False=OFF + * @param led2 status of led2: True=ON, False=OFF + * @param led3 status of led3: True=ON, False=OFF + * @param led4 status of led4: True=ON, False=OFF + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds +(JNIEnv *env, jobject obj, jint id, jboolean led1, jboolean led2, jboolean led3, jboolean led4) { + int leds = 0; + + if (led1) leds |= WIIMOTE_LED_1; + if (led2) leds |= WIIMOTE_LED_2; + if (led3) leds |= WIIMOTE_LED_3; + if (led4) leds |= WIIMOTE_LED_4; + + wiiuse_set_leds(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), leds); +} + +/** + * Set how many degrees an angle must change to generate an event. + * @param id id of the wiimote concerned + * @param thresh minimum angle detected by an event + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold +(JNIEnv *env, jobject obj, jint id, jfloat thresh) { + wiiuse_set_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh); +} + +/** + * Set how much acceleration must change to generate an event. + * @param id id of the wiimote concerned + * @param val minimum value detected by an event + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold +(JNIEnv *env, jobject obj, jint id, jint val) { + wiiuse_set_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); +} + +/** + * Set alpha smoothing parameter for the given id. + * @param id id of the wiimote concerned + * @param value alpha smoothing value + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing +(JNIEnv *env, jobject obj, jint id, jfloat val) { + wiiuse_set_smooth_alpha(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); +} + +/** + * Try to resync with the wiimote by starting a new handshake. + * @param id id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync +(JNIEnv *env, jobject obj, jint id) { + wiiuse_resync(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); +} + +/** + * Make the the accelerometers give smoother results. + * This is set by default. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_SMOOTHING, 0); +} + +/** + * Make the the accelerometers give raw results. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0, WIIUSE_SMOOTHING); +} + +/** + * Make the wiimote generate an event each time we poll. + * Not set by default. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_CONTINUOUS, 0); +} + +/** + * Make the wiimote generate an event only when there is one. + * (default behavior) + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0, WIIUSE_CONTINUOUS); +} + +/** + * Notify wiiuse that your screen has an aspect ratio of 4/3. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43 +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_aspect_ratio(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_ASPECT_4_3); +} + +/** + * Notify wiiuse that your screen has an aspect ratio of 16/9. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169 +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_aspect_ratio(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_ASPECT_4_3); +} + +/** + * Notify wiiuse that the sensor bar is above your screen. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_ir_position(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_IR_ABOVE); +} + +/** + * Notify wiiuse that the sensor bar is below your screen. + * @param id the id of the wiimote concerned + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen +(JNIEnv *env, jobject obj, jint id) { + wiiuse_set_ir_position(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_IR_BELOW); +} + +/** + * Set virtual screen resolution. It is used to automatically + * compute the position of a cursor on this virtual screen + * using the sensor bar. These results come in the IREvent. + * @param id the id of the wiimote concerned + * @param x x resolution. + * @param y y resolution. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution +(JNIEnv *env, jobject obj, jint id, jint x, jint y) { + wiiuse_set_ir_vres(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), x, y); +} + +/** + * Get status from the wiimotes and send it through call backs. + * + * @param id the id of the wiimote. Must be 1 or 2. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus +(JNIEnv *env, jobject obj, jint id) { + wiiuse_status(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); +} + +/** + * Set the normal and expansion handshake timeouts. + * + * @param id + * the id of the wiimote concerned. + * @param normalTimeout + * The timeout in milliseconds for a normal read. + * @param expansionTimeout + * The timeout in millisecondsd to wait for an expansion + * handshake. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout +(JNIEnv *env, jobject obj, jint id, jshort normalTimeout, jshort expansionTimeout) { + wiiuse_set_timeout(wiimotes, nbMaxWiimotes, normalTimeout, expansionTimeout); +} + +/** + * Set the IR sensitivity. + * + * @param id + * the id of the wiimote concerned. + * @param level + * 1-5, same as Wii system sensitivity setting. If the level is < + * 1, then level will be set to 1. If the level is > 5, then + * level will be set to 5. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity +(JNIEnv *env, jobject obj, jint id, jint level) { + wiiuse_set_ir_sensitivity(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), level); +} + +/** + * Set how many degrees an angle must change to generate an event for the nunchuk. + * @param id id of the wiimote concerned + * @param thresh minimum angle detected by an event + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold +(JNIEnv *env, jobject obj, jint id, jfloat thresh) { + wiiuse_set_nunchuk_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh); +} + +/** + * Set how much acceleration must change to generate an event for the nunchuk. + * @param id id of the wiimote concerned + * @param val minimum value detected by an event + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold +(JNIEnv *env, jobject obj, jint id, jint val) { + wiiuse_set_nunchuk_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); +} + +/** + * Force the bluetooth stack type.(useful only for windows) + * + * @param bluetoothStackType + * must be WiiUseApi.WIIUSE_STACK_UNKNOWN or WiiUseApi.WIIUSE_STACK_MS or + * WiiUseApi.WIIUSE_STACK_BLUESOLEIL. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack +(JNIEnv *env, jobject obj, jint bluetoothStackType) { + if (bluetoothStackType == 0) { + wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_UNKNOWN); + } else if (bluetoothStackType == 1) { + wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_MS); + } else if (bluetoothStackType == 2) { + wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_BLUESOLEIL); + } +} + +/** + * Get status and values from the wiimotes and send it through callbacks. + * @param wim the wiimote object to fill with the datas. + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll +(JNIEnv *env, jobject obj, jobject gath) { + + /* Variables Declarations */ + int i, a; + short leds = 0; + jclass cls = (*env)->GetObjectClass(env, gath); + jmethodID mid; + struct nunchuk_t* nc; + struct guitar_hero_3_t* gh; + struct classic_ctrl_t* cl; + //printf("avant poll, nbMaxwiimotes : %i \n",nbMaxWiimotes); + if (wiiuse_poll(wiimotes, nbMaxWiimotes)) { + /* + * This happens if something happened on any wiimote. + * So go through each one and check if anything happened. + */ + //printf("il y a des events\n"); + for (i=0; i < nbMaxWiimotes; ++i) { + //printf("recupe events wiimote : %i\n",nbMaxWiimotes); + switch (wiimotes[i]->event) { + case WIIUSE_EVENT: + /* a generic event occured */ + + //printf("Generic event\n"); + mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid, wiimotes[i]->btns, + wiimotes[i]->btns_released, wiimotes[i]->btns_held); + /* + * If IR tracking is enabled then print the coordinates + * on the virtual screen that the wiimote is pointing to. + * + * Also make sure that we see at least 1 dot. + */ + if (WIIUSE_USING_IR(wiimotes[i])) { + //printf("IR event\n"); + + WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wiimotes[i], &a); + + mid = (*env)->GetMethodID(env, cls, "prepareIRevent", "(IIFIIIIIISSSF)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, + wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z, + wiimotes[i]->ir.ax, wiimotes[i]->ir.ay, + wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1], + wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1], + wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect, + a , wiimotes[i]->ir.distance); + + mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent", + "(IISSS)V"); + if (mid == 0) { + return; + } + /* go through each of the 4 possible IR sources */ + for (a=0; a < 4; a++) { + /* check if the source is visible */ + if (wiimotes[i]->ir.dot[a].visible) { + (*env)->CallVoidMethod(env, gath, mid, + wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y, + wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry, + wiimotes[i]->ir.dot[a].size); + } + } + } + + /* Motion Sensing */ + if (WIIUSE_USING_ACC(wiimotes[i])) { + //printf("acc event\n"); + /* set orientation and gravity force */ + mid = (*env)->GetMethodID(env, cls, + "addMotionSensingValues", "(FIZFFFFFFFFFSSS)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, + wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold, + WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), wiimotes[i]->accel_calib.st_alpha, + wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw, + wiimotes[i]->orient.a_roll, wiimotes[i]->orient.a_pitch, + wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z, + wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z); + } + + /* Expansions support support*/ + if (WIIUSE_USING_EXP(wiimotes[i])) { + /* Nunchuk support */ + if (wiimotes[i]->exp.type == EXP_NUNCHUK) { + /* put nunchuk values in wiimote generic event */ + mid = (*env)->GetMethodID(env, cls, + "addNunchunkEventToPreparedWiimoteEvent", "(SSSFIZFFFFFFFFFSSSFFSSSSSS)V"); + if (mid == 0) { + return; + } + nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk; + + (*env)->CallVoidMethod(env, gath, mid, + /* buttons */ + nc->btns,nc->btns_released,nc->btns_held, + /* motion sensing */ + nc->orient_threshold,nc->accel_threshold, + WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING),nc->accel_calib.st_alpha, + nc->orient.roll, nc->orient.pitch, nc->orient.yaw, + nc->orient.a_roll, nc->orient.a_pitch, + nc->gforce.x, nc->gforce.y, nc->gforce.z, + nc->accel.x, nc->accel.y, nc->accel.z, + /* joystick */ + nc->js.ang,nc->js.mag, + nc->js.max.x,nc->js.max.y, + nc->js.min.x,nc->js.min.y, + nc->js.center.x,nc->js.center.y); + } + else if (wiimotes[i]->exp.type == EXP_GUITAR_HERO_3) { + /* put guitar hero values in wiimote generic event */ + mid = (*env)->GetMethodID(env, cls, + "addGuitarHeroEventToPreparedWiimoteEvent", "(SSSFFFSSSSSS)V"); + if (mid == 0) { + return; + } + gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3; + + (*env)->CallVoidMethod(env, gath, mid, + /* buttons */ + gh->btns,gh->btns_released,gh->btns_held, + /* whammy bar */ + gh->whammy_bar, + /* joystick */ + gh->js.ang,gh->js.mag, + gh->js.max.x,gh->js.max.y, + gh->js.min.x,gh->js.min.y, + gh->js.center.x,gh->js.center.y); + }if (wiimotes[i]->exp.type == EXP_CLASSIC) { + /* put classic controller values in wiimote generic event */ + mid = (*env)->GetMethodID(env, cls, + "addClassicControllerEventToPreparedWiimoteEvent", "(SSSFFFFSSSSSSFFSSSSSS)V"); + if (mid == 0) { + return; + } + cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic; + + (*env)->CallVoidMethod(env, gath, mid, + /* buttons */ + cl->btns,cl->btns_released,cl->btns_held, + /* shoulder buttons */ + cl->r_shoulder,cl->l_shoulder, + /* joystick left*/ + cl->ljs.ang,cl->ljs.mag, + cl->ljs.max.x,cl->ljs.max.y, + cl->ljs.min.x,cl->ljs.min.y, + cl->ljs.center.x,cl->ljs.center.y, + /* joystick right */ + cl->rjs.ang,cl->rjs.mag, + cl->rjs.max.x,cl->rjs.max.y, + cl->rjs.min.x,cl->rjs.min.y, + cl->rjs.center.x,cl->rjs.center.y); + } + } + + /* add generic event to java object used to gather events in c environment */ + mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent", + "()V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid); + break; + + case WIIUSE_DISCONNECT: + /* the wiimote disconnected */ + mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_UNEXPECTED_DISCONNECT: + /* the wimote disconnected */ + mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_NUNCHUK_INSERTED: + /* the nunchuk was just connected */ + mid = (*env)->GetMethodID(env, cls, "addNunchukInsertedEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_NUNCHUK_REMOVED: + /* the nunchuk disconnected */ + mid = (*env)->GetMethodID(env, cls, "addNunchukRemovedEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: + /* the guitar hero was just connected */ + mid = (*env)->GetMethodID(env, cls, "addGuitarHeroInsertedEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: + /* the guitar hero disconnected */ + mid = (*env)->GetMethodID(env, cls, "addGuitarHeroRemovedEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_CLASSIC_CTRL_INSERTED: + /* the classic controller was just connected */ + mid = (*env)->GetMethodID(env, cls, "addClassicControllerInsertedEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_CLASSIC_CTRL_REMOVED: + /* the classic controller disconnected */ + mid = (*env)->GetMethodID(env, cls, "addClassicControllerRemovedEvent", "(I)V"); + if (mid == 0) { + return; + } + (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); + break; + + case WIIUSE_STATUS: + /* a status event occured */ + mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)V"); + if (mid == 0) { + return; + } + /* LEDS */ + if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1; + if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2; + if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4; + if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8; + + (*env)->CallVoidMethod(env, gath, mid, + wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED), + wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]), + wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE), + WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS), + WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i])); + break; + + default: + break; + } + } + } +} \ No newline at end of file diff --git a/wiiusej_WiiUseApi.def b/wiiusej_WiiUseApi.def new file mode 100644 index 0000000..e7aebd3 --- /dev/null +++ b/wiiusej_WiiUseApi.def @@ -0,0 +1,34 @@ +EXPORTS +Java_wiiusej_WiiUseApi_connect +Java_wiiusej_WiiUseApi_find +Java_wiiusej_WiiUseApi_init +Java_wiiusej_WiiUseApi_closeConnection +Java_wiiusej_WiiUseApi_getUnId +Java_wiiusej_WiiUseApi_cleanUp +Java_wiiusej_WiiUseApi_activateRumble +Java_wiiusej_WiiUseApi_deactivateRumble +Java_wiiusej_WiiUseApi_activateIRTracking +Java_wiiusej_WiiUseApi_deactivateIRTracking +Java_wiiusej_WiiUseApi_activateMotionSensing +Java_wiiusej_WiiUseApi_deactivateMotionSensing +Java_wiiusej_WiiUseApi_setLeds +Java_wiiusej_WiiUseApi_setOrientThreshold +Java_wiiusej_WiiUseApi_setAccelThreshold +Java_wiiusej_WiiUseApi_setAlphaSmoothing +Java_wiiusej_WiiUseApi_reSync +Java_wiiusej_WiiUseApi_activateSmoothing +Java_wiiusej_WiiUseApi_deactivateSmoothing +Java_wiiusej_WiiUseApi_activateContinuous +Java_wiiusej_WiiUseApi_deactivateContinuous +Java_wiiusej_WiiUseApi_setScreenRatio43 +Java_wiiusej_WiiUseApi_setScreenRatio169 +Java_wiiusej_WiiUseApi_setSensorBarAboveScreen +Java_wiiusej_WiiUseApi_setSensorBarBelowScreen +Java_wiiusej_WiiUseApi_setVirtualScreenResolution +Java_wiiusej_WiiUseApi_getStatus +Java_wiiusej_WiiUseApi_setTimeout +Java_wiiusej_WiiUseApi_setIrSensitivity +Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold +Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold +Java_wiiusej_WiiUseApi_windowsSetBluetoothStack +Java_wiiusej_WiiUseApi_specialPoll diff --git a/wiiusej_WiiUseApi.h b/wiiusej_WiiUseApi.h new file mode 100644 index 0000000..031958b --- /dev/null +++ b/wiiusej_WiiUseApi.h @@ -0,0 +1,317 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class wiiusej_WiiUseApi */ + +#ifndef _Included_wiiusej_WiiUseApi +#define _Included_wiiusej_WiiUseApi +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: wiiusej_WiiUseApi + * Method: connect + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: find + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: closeConnection + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: getUnId + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: cleanUp + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp + (JNIEnv *, jobject); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateRumble + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateRumble + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateIRTracking + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateIRTracking + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateMotionSensing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateMotionSensing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setLeds + * Signature: (IZZZZ)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds + (JNIEnv *, jobject, jint, jboolean, jboolean, jboolean, jboolean); + +/* + * Class: wiiusej_WiiUseApi + * Method: setOrientThreshold + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: setAccelThreshold + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setAlphaSmoothing + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: reSync + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateSmoothing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateSmoothing + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateContinuous + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateContinuous + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setScreenRatio43 + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43 + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setScreenRatio169 + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169 + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSensorBarAboveScreen + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSensorBarBelowScreen + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setVirtualScreenResolution + * Signature: (III)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution + (JNIEnv *, jobject, jint, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: getStatus + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setTimeout + * Signature: (ISS)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout + (JNIEnv *, jobject, jint, jshort, jshort); + +/* + * Class: wiiusej_WiiUseApi + * Method: setIrSensitivity + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setNunchukOrientationThreshold + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: setNunchukAccelerationThreshold + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: windowsSetBluetoothStack + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: specialPoll + * Signature: (Lwiiusej/wiiusejevents/utils/EventsGatherer;)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll + (JNIEnv *, jobject, jobject); + +/* + * Class: wiiusej_WiiUseApi + * Method: activateSpeaker + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: deactivateSpeaker + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker + (JNIEnv *, jobject, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSpeakerVolume + * Signature: (IS)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume + (JNIEnv *, jobject, jint, jshort); + +/* + * Class: wiiusej_WiiUseApi + * Method: setSpeakerFrequency + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFrequency + (JNIEnv *, jobject, jint, jint); + +/* + * Class: wiiusej_WiiUseApi + * Method: streamSpeakerData + * Signature: (I[S)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData + (JNIEnv *, jobject, jint, jshortArray); + +#ifdef __cplusplus +} +#endif +#endif