aboutsummaryrefslogtreecommitdiff
path: root/tools/EventClients
diff options
context:
space:
mode:
authorCory Fields <theuni-nospam-@xbmc.org>2011-01-04 12:39:23 -0500
committerCory Fields <theuni-nospam-@xbmc.org>2011-01-04 12:39:23 -0500
commita9839fa95cb9711efe465ca8e137c34247238485 (patch)
tree0bb8dc55aa317c9cc9191ea85e8298c2da90b06b /tools/EventClients
parent07db21c48d60933b45c702d333572ed8f4629fdc (diff)
Fix CRLF
Diffstat (limited to 'tools/EventClients')
-rw-r--r--tools/EventClients/Clients/J2ME Client/src/XBMCRemote.jad16
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/CHANGELOG416
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/README310
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsp222
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsw58
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/sdl.c80
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsp212
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsw58
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/classic.c50
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/definitions.h18
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/dynamics.c14
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.c1646
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.h2
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/guitar_hero_3.c48
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io.c28
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io_win.c30
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsp382
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsw58
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/nunchuk.c64
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/os.h8
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.c1406
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.h1228
-rw-r--r--tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse_internal.h10
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.cpp344
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.h92
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.cpp318
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.vcproj416
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/stdafx.cpp16
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/stdafx.h30
-rw-r--r--tools/EventClients/Clients/Xbox360 Controller/targetver.h26
-rw-r--r--tools/EventClients/examples/c#/XBMCDemoClient1.cs62
-rw-r--r--tools/EventClients/lib/c#/EventClient.cs1110
32 files changed, 4389 insertions, 4389 deletions
diff --git a/tools/EventClients/Clients/J2ME Client/src/XBMCRemote.jad b/tools/EventClients/Clients/J2ME Client/src/XBMCRemote.jad
index bd283d8903..e40999eef6 100644
--- a/tools/EventClients/Clients/J2ME Client/src/XBMCRemote.jad
+++ b/tools/EventClients/Clients/J2ME Client/src/XBMCRemote.jad
@@ -1,9 +1,9 @@
-MIDlet-1: MainScreen, , MainScreen
-MIDlet-Icon: icon.png
-MIDlet-Jar-Size: 12153
-MIDlet-Jar-URL: XBMC Remote.jar
-MIDlet-Name: XBMC Remote
-MIDlet-Vendor: team-xbmc
-MIDlet-Version: 0.1
-MicroEdition-Configuration: CLDC-1.0
+MIDlet-1: MainScreen, , MainScreen
+MIDlet-Icon: icon.png
+MIDlet-Jar-Size: 12153
+MIDlet-Jar-URL: XBMC Remote.jar
+MIDlet-Name: XBMC Remote
+MIDlet-Vendor: team-xbmc
+MIDlet-Version: 0.1
+MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/CHANGELOG b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/CHANGELOG
index ccb831af97..5e2d5a2b6e 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/CHANGELOG
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/CHANGELOG
@@ -1,208 +1,208 @@
----------------------------
--
-- CHANGE LOG - Wiiuse
--
----------------------------
-
-http://wiiuse.net/
-http://wiiuse.sourceforge.net/
-http://sourceforge.net/projects/wiiuse/
-
----------------------------
-v0.12 -- 2 Apr 2008
----------------------------
-
- Added:
- - API function wiiuse_set_ir_sensitivity()
- - Macro WIIUSE_GET_IR_SENSITIVITY()
- - Event type WIIUSE_READ_DATA
- - Event type WIIUSE_UNEXPECTED_DISCONNECT
-
- Fixed:
- - [Linux] Ability to try to select() nothing
- - [Linux] Changed Makefile to include debug output when compiling in debug mode
-
- Changed:
- - wiiuse_set_nunchuk_orient_threshold() now takes a wiimote_t pointer
- - wiiuse_set_nunchuk_accel_threshold() now takes a wiimote_t pointer
- - wiiuse_read_data() generates an event WIIUSE_READ_DATA rather than executing a callback
-
----------------------------
-v0.11 -- 25 Feb 2008
----------------------------
-
- Added:
- - API function wiiuse_set_nunchuk_orient_threshold()
- - API function wiiuse_set_nunchuk_accel_threshold()
- - Event type WIIUSE_NUNCHUK_INSERTED
- - Event type WIIUSE_NUNCHUK_REMOVED
- - Event type WIIUSE_CLASSIC_CTRL_INSERTED
- - Event type WIIUSE_CLASSIC_CTRL_REMOVED
- - Event type WIIUSE_GUITAR_HERO_3_CTRL_INSERTED
- - Event type WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
-
- Fixed:
- - Added some missing function prototypes to wiiuse.h
- - [Linux] Fixed Makefile to link libmath and libbluetooth
- - Status event is set when a status report comes in
- - Orientation threshold not being saved in lstate
-
----------------------------
-v0.10 -- 11 Feb 2008
----------------------------
-
- Added:
- - Real dynamic linking (by noisehole)
- - Changed from callback to SDL style
- - Guitar Hero 3 controller support
- - API function wiiuse_set_accel_threshold()
- - API function wiiuse_version()
- - Macro WIIUSE_USING_SPEAKER()
- - Macro WIIUSE_IS_LED_SET(wm, num)
- - wiiuse_init() now autogenerates unids
- - orient_t::a_roll/a_pitch
- - wiiuse_resync()
- - wiiuse_cleanup()
- - wiiuse_set_timeout()
-
- Fixed:
- - [Windows] Fixed bug where it did not detect expansions on startup
- - Renamed INFO/WARNING/DEBUG macros to WIIUSE_* (by noisehole)
- - Updated Makefiles (by noisehole)
- - Fixed incorrect roll/pitch when smoothing was enabled
- - Fixed nunchuk and classic controller flooding events when significant changes occured
- - Fixed bug where IR was not correct on roll if IR was enabled before handshake
-
- Removed:
- - wiiuse_startup(), no longer needed
-
----------------------------
-v0.9 -- 3 Nov 2007
----------------------------
-
- Fixed:
- - Can now use include/wiiuse.h in C++ projects.
- - HOME button works again.
- - IR now functions after expansion is connected or removed.
-
----------------------------
-v0.8 -- 27 Oct 2007
----------------------------
-
- - Bumped API version to 8
- - Exported all API functions for usage with non-C/C++ languages.
- - Changed event callback to only trigger if a significant state change occurs.
-
- Added:
- - wiimote_t::lstate structure
-
- Fixed:
- - Bug 1820140 - Buffer overflow in io_nix.c. Thanks proppy.
-
----------------------------
-v0.7 -- 19 Oct 2007
----------------------------
-
- - Bumped API version to 7
- - Renamed Linux build from wii.so to wiiuse.so
- - Changed version representation from float to const char*.
-
- Added:
- - [Windows] BlueSoleil support.
- - [Windows] Bluetooth stack auto-detection (WinXP SP2, Bluesoleil, Widdcomm tested).
- - [Windows] API function wiiuse_set_bluetooth_stack().
- - Calculates yaw if IR tracking is enabled.
-
- Fixed:
- - [Windows] Problem where a connection is made to a wiimote that does not exist.
- - [Windows] Issue that occured while using multiple wiimotes.
-
----------------------------
-v0.6 -- 16 Oct 2007
----------------------------
-
- - Bumped API version to 0.6.
- - Ported to Microsoft Windows.
- - Improved IR tracking.
- - Default IR virtual screen resolutions changed depending on 16:9 or 4:3.
-
- Added:
- - src/msvc/ and api/msvc/ - Microsoft Visual C++ 6.0 project files.
-
----------------------------
-v0.5 -- 13 Oct 2007
----------------------------
-
- - Bumped API version to 0.5.
- - Greatly improved IR tracking.
- - Renamed function wiiuse_set_ir_correction() to wiiuse_set_ir_position().
-
- Added:
- - API function wiiuse_set_aspect_ratio()
-
- Fixed:
- - When rolling around 180 degree rotation smoothing would not be seemless.
-
----------------------------
-v0.4 -- 08 Oct 2007
----------------------------
-
- - Bumped API version to 0.4.
- - Greatly improved classic controller joystick functionality.
- - Changed all functions named wiimote_*() to wiiuse_*()
- - Renamed many macros from WIIMOTE_* to WIIUSE_*
-
- Added:
- - IR support
- - New WIIMOTE_CONTINUOUS flag to set continuous reporting
- - Macro IS_JUST_PRESSED()
- - Macro WIIUSE_USING_ACC()
- - Macro WIIUSE_USING_EXP()
- - Macro WIIUSE_USING_IR()
- - API function wiiuse_set_ir()
- - API function wiiuse_set_ir_vres()
- - API function wiiuse_set_ir_correction()
-
- - gfx/ - A small OpenGL example that renders IR data
-
- Fixed:
- - Sometimes classic controller would only report infinite angle and magnitude for joysticks.
-
----------------------------
-v0.3 -- 10 Sept 2007
----------------------------
-
- - Moved license to GPLv3.
- - Bumped API version to 0.3.
-
- Added:
- - Support for Classic Controller
- - Smoothing for roll and pitch values of the wiimote and nunchuk.
-
- - API: wiimote_set_flags() to set or disable wiimote options.
- - API: wiimote_set_smooth_alpha() to set smoothing alpha value.
-
- Fixed:
- - When the wiimote accelerates the roll or pitch is unreliable and was set to 0.
- It now remains at previous tilt value.
- - If no event callback was specified then no events would be processed internally.
-
----------------------------
-v0.2 -- 25 Aug 2007
----------------------------
-
- - Bumped API version to 0.2.
-
- Added:
- - Nunchuk support.
- - Ability to write to flash memory.
-
- Fixed:
- - Roll and pitch rotation now ranges from -180 to 180 degrees (previously -90 to 90).
- - Bug when reading data from flash memory would read wrong address.
-
----------------------------
-v0.1 -- 23 Feb 2007
----------------------------
-
- - Initial release
+---------------------------
+-
+- CHANGE LOG - Wiiuse
+-
+---------------------------
+
+http://wiiuse.net/
+http://wiiuse.sourceforge.net/
+http://sourceforge.net/projects/wiiuse/
+
+---------------------------
+v0.12 -- 2 Apr 2008
+---------------------------
+
+ Added:
+ - API function wiiuse_set_ir_sensitivity()
+ - Macro WIIUSE_GET_IR_SENSITIVITY()
+ - Event type WIIUSE_READ_DATA
+ - Event type WIIUSE_UNEXPECTED_DISCONNECT
+
+ Fixed:
+ - [Linux] Ability to try to select() nothing
+ - [Linux] Changed Makefile to include debug output when compiling in debug mode
+
+ Changed:
+ - wiiuse_set_nunchuk_orient_threshold() now takes a wiimote_t pointer
+ - wiiuse_set_nunchuk_accel_threshold() now takes a wiimote_t pointer
+ - wiiuse_read_data() generates an event WIIUSE_READ_DATA rather than executing a callback
+
+---------------------------
+v0.11 -- 25 Feb 2008
+---------------------------
+
+ Added:
+ - API function wiiuse_set_nunchuk_orient_threshold()
+ - API function wiiuse_set_nunchuk_accel_threshold()
+ - Event type WIIUSE_NUNCHUK_INSERTED
+ - Event type WIIUSE_NUNCHUK_REMOVED
+ - Event type WIIUSE_CLASSIC_CTRL_INSERTED
+ - Event type WIIUSE_CLASSIC_CTRL_REMOVED
+ - Event type WIIUSE_GUITAR_HERO_3_CTRL_INSERTED
+ - Event type WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
+
+ Fixed:
+ - Added some missing function prototypes to wiiuse.h
+ - [Linux] Fixed Makefile to link libmath and libbluetooth
+ - Status event is set when a status report comes in
+ - Orientation threshold not being saved in lstate
+
+---------------------------
+v0.10 -- 11 Feb 2008
+---------------------------
+
+ Added:
+ - Real dynamic linking (by noisehole)
+ - Changed from callback to SDL style
+ - Guitar Hero 3 controller support
+ - API function wiiuse_set_accel_threshold()
+ - API function wiiuse_version()
+ - Macro WIIUSE_USING_SPEAKER()
+ - Macro WIIUSE_IS_LED_SET(wm, num)
+ - wiiuse_init() now autogenerates unids
+ - orient_t::a_roll/a_pitch
+ - wiiuse_resync()
+ - wiiuse_cleanup()
+ - wiiuse_set_timeout()
+
+ Fixed:
+ - [Windows] Fixed bug where it did not detect expansions on startup
+ - Renamed INFO/WARNING/DEBUG macros to WIIUSE_* (by noisehole)
+ - Updated Makefiles (by noisehole)
+ - Fixed incorrect roll/pitch when smoothing was enabled
+ - Fixed nunchuk and classic controller flooding events when significant changes occured
+ - Fixed bug where IR was not correct on roll if IR was enabled before handshake
+
+ Removed:
+ - wiiuse_startup(), no longer needed
+
+---------------------------
+v0.9 -- 3 Nov 2007
+---------------------------
+
+ Fixed:
+ - Can now use include/wiiuse.h in C++ projects.
+ - HOME button works again.
+ - IR now functions after expansion is connected or removed.
+
+---------------------------
+v0.8 -- 27 Oct 2007
+---------------------------
+
+ - Bumped API version to 8
+ - Exported all API functions for usage with non-C/C++ languages.
+ - Changed event callback to only trigger if a significant state change occurs.
+
+ Added:
+ - wiimote_t::lstate structure
+
+ Fixed:
+ - Bug 1820140 - Buffer overflow in io_nix.c. Thanks proppy.
+
+---------------------------
+v0.7 -- 19 Oct 2007
+---------------------------
+
+ - Bumped API version to 7
+ - Renamed Linux build from wii.so to wiiuse.so
+ - Changed version representation from float to const char*.
+
+ Added:
+ - [Windows] BlueSoleil support.
+ - [Windows] Bluetooth stack auto-detection (WinXP SP2, Bluesoleil, Widdcomm tested).
+ - [Windows] API function wiiuse_set_bluetooth_stack().
+ - Calculates yaw if IR tracking is enabled.
+
+ Fixed:
+ - [Windows] Problem where a connection is made to a wiimote that does not exist.
+ - [Windows] Issue that occured while using multiple wiimotes.
+
+---------------------------
+v0.6 -- 16 Oct 2007
+---------------------------
+
+ - Bumped API version to 0.6.
+ - Ported to Microsoft Windows.
+ - Improved IR tracking.
+ - Default IR virtual screen resolutions changed depending on 16:9 or 4:3.
+
+ Added:
+ - src/msvc/ and api/msvc/ - Microsoft Visual C++ 6.0 project files.
+
+---------------------------
+v0.5 -- 13 Oct 2007
+---------------------------
+
+ - Bumped API version to 0.5.
+ - Greatly improved IR tracking.
+ - Renamed function wiiuse_set_ir_correction() to wiiuse_set_ir_position().
+
+ Added:
+ - API function wiiuse_set_aspect_ratio()
+
+ Fixed:
+ - When rolling around 180 degree rotation smoothing would not be seemless.
+
+---------------------------
+v0.4 -- 08 Oct 2007
+---------------------------
+
+ - Bumped API version to 0.4.
+ - Greatly improved classic controller joystick functionality.
+ - Changed all functions named wiimote_*() to wiiuse_*()
+ - Renamed many macros from WIIMOTE_* to WIIUSE_*
+
+ Added:
+ - IR support
+ - New WIIMOTE_CONTINUOUS flag to set continuous reporting
+ - Macro IS_JUST_PRESSED()
+ - Macro WIIUSE_USING_ACC()
+ - Macro WIIUSE_USING_EXP()
+ - Macro WIIUSE_USING_IR()
+ - API function wiiuse_set_ir()
+ - API function wiiuse_set_ir_vres()
+ - API function wiiuse_set_ir_correction()
+
+ - gfx/ - A small OpenGL example that renders IR data
+
+ Fixed:
+ - Sometimes classic controller would only report infinite angle and magnitude for joysticks.
+
+---------------------------
+v0.3 -- 10 Sept 2007
+---------------------------
+
+ - Moved license to GPLv3.
+ - Bumped API version to 0.3.
+
+ Added:
+ - Support for Classic Controller
+ - Smoothing for roll and pitch values of the wiimote and nunchuk.
+
+ - API: wiimote_set_flags() to set or disable wiimote options.
+ - API: wiimote_set_smooth_alpha() to set smoothing alpha value.
+
+ Fixed:
+ - When the wiimote accelerates the roll or pitch is unreliable and was set to 0.
+ It now remains at previous tilt value.
+ - If no event callback was specified then no events would be processed internally.
+
+---------------------------
+v0.2 -- 25 Aug 2007
+---------------------------
+
+ - Bumped API version to 0.2.
+
+ Added:
+ - Nunchuk support.
+ - Ability to write to flash memory.
+
+ Fixed:
+ - Roll and pitch rotation now ranges from -180 to 180 degrees (previously -90 to 90).
+ - Bug when reading data from flash memory would read wrong address.
+
+---------------------------
+v0.1 -- 23 Feb 2007
+---------------------------
+
+ - Initial release
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/README b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/README
index 12d9f71517..b06bb9620f 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/README
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/README
@@ -1,155 +1,155 @@
----------------------------
--
-- README - Wiiuse
--
----------------------------
-
-http://wiiuse.net/
-http://wiiuse.sourceforge.net/
-http://sourceforge.net/projects/wiiuse/
-
----------------------------
-
-ABOUT
-
- Wiiuse is a library written in C that connects with several Nintendo Wii remotes.
- Supports motion sensing, IR tracking, nunchuk, classic controller, and the Guitar Hero 3 controller.
- Single threaded and nonblocking makes a light weight and clean API.
-
- Distributed under the GPL and LGPL.
-
-
-AUTHORS
-
- Michael Laforest < para >
- Email: < thepara (--AT--) g m a i l [--DOT--] com >
-
- The following people have contributed patches to wiiuse:
- - dhewg
-
-
-LICENSE
-
- There are two licenses for wiiuse. Please read them carefully before choosing which one
- you use. You may of course at any time switch the license you are currently using to
- the other.
-
- Briefly, the license options are:
-
- a) GNU LGPL (modified for non-commercial usage only)
- b) GNU GPL
-
- PLEASE READ THE LICENSES!
-
-
-ACKNOWLEDGEMENTS
-
- http://wiibrew.org/
- This site and their users have contributed an immense amount of information
- about the wiimote and its technical details. I could not have written this program
- without the vast amounts of reverse engineered information that was researched by them.
-
- Nintendo
- Of course Nintendo for designing and manufacturing the Wii and Wii remote.
-
- BlueZ
- Easy and intuitive bluetooth stack for Linux.
-
- Thanks to Brent for letting me borrow his Guitar Hero 3 controller.
-
-
-DISCLAIMER AND WARNINGS
-
- I am in no way responsible for any damages or effects, intended or not, caused by this program.
-
- *** WARNING *** WARNING *** WARNING ***
-
- Be aware that writing to memory may damage or destroy your wiimote or expansions.
-
- *** WARNING *** WARNING *** WARNING ***
-
- This program was written using reverse engineered specifications available from wiibrew.org.
- Therefore the operation of this program may not be entirely correct.
- Results obtained by using this program may vary.
-
-
-AUDIENCE
-
- This project is intended for developers who wish to include support for the Nintendo Wii remote
- with their third party application. Please be aware that by using this software you are bound
- to the terms of the GNU GPL.
-
-
-PLATFORMS AND DEPENDENCIES
-
- Wiiuse currently operates on both Linux and Windows.
- You will need:
-
- For Linux:
- - The kernel must support bluetooth
- - The BlueZ bluetooth drivers must be installed
-
- For Windows:
- - Bluetooth driver (tested with Microsoft's stack with Windows XP SP2)
- - If compiling, Microsoft Windows Driver Development Kit (DDK)
-
-
-COMPILING
-
- Linux:
- You need SDL and OpenGL installed to compile the SDL example.
-
- # make [target]
-
- If 'target' is omitted then everything is compiled.
-
- Where 'target' can be any of the following:
-
- - wiiuse
- Compiles libwiiuse.so
-
- - ex
- Compiles wiiuse-example
-
- - sdl-ex
- Compiles wiiuse-sdl
-
- Become root.
-
- # make install
-
- The above command will only install the binaries that you
- selected to compile.
-
- wiiuse.so is installed to /usr/lib
- wiiuse-example and wiiuse-sdl are installed to /usr/bin
-
- Windows:
- A Microsoft Visual C++ 6.0 project file has been included.
-
- You need the install the Windows DDK (driver development kit)
- to compile wiiuse. Make sure you include the inc/ and lib/
- directories from the DDK in your IDE include and library paths.
- You can download this from here:
- http://www.microsoft.com/whdc/devtools/ddk/default.mspx
-
- You need to link the following libraries (already set in the
- included project file):
- - Ws2_32.lib
- - hid.lib
- - setupapi.lib
-
-
-USING THE LIBRARY IN A THIRD PARTY APPLICATION
-
- To use the library in your own program you must first compile wiiuse as a module.
- Include include/wiiuse.h in any file that uses wiiuse.
-
- For Linux you must link wiiuse.so ( -lwiiuse ).
- For Windows you must link wiiuse.lib. When your program runs it will need wiiuse.dll.
-
-
-BUGS
-
- On Windows using more than one wiimote (usually more than two wiimotes) may cause
- significant latency.
+---------------------------
+-
+- README - Wiiuse
+-
+---------------------------
+
+http://wiiuse.net/
+http://wiiuse.sourceforge.net/
+http://sourceforge.net/projects/wiiuse/
+
+---------------------------
+
+ABOUT
+
+ Wiiuse is a library written in C that connects with several Nintendo Wii remotes.
+ Supports motion sensing, IR tracking, nunchuk, classic controller, and the Guitar Hero 3 controller.
+ Single threaded and nonblocking makes a light weight and clean API.
+
+ Distributed under the GPL and LGPL.
+
+
+AUTHORS
+
+ Michael Laforest < para >
+ Email: < thepara (--AT--) g m a i l [--DOT--] com >
+
+ The following people have contributed patches to wiiuse:
+ - dhewg
+
+
+LICENSE
+
+ There are two licenses for wiiuse. Please read them carefully before choosing which one
+ you use. You may of course at any time switch the license you are currently using to
+ the other.
+
+ Briefly, the license options are:
+
+ a) GNU LGPL (modified for non-commercial usage only)
+ b) GNU GPL
+
+ PLEASE READ THE LICENSES!
+
+
+ACKNOWLEDGEMENTS
+
+ http://wiibrew.org/
+ This site and their users have contributed an immense amount of information
+ about the wiimote and its technical details. I could not have written this program
+ without the vast amounts of reverse engineered information that was researched by them.
+
+ Nintendo
+ Of course Nintendo for designing and manufacturing the Wii and Wii remote.
+
+ BlueZ
+ Easy and intuitive bluetooth stack for Linux.
+
+ Thanks to Brent for letting me borrow his Guitar Hero 3 controller.
+
+
+DISCLAIMER AND WARNINGS
+
+ I am in no way responsible for any damages or effects, intended or not, caused by this program.
+
+ *** WARNING *** WARNING *** WARNING ***
+
+ Be aware that writing to memory may damage or destroy your wiimote or expansions.
+
+ *** WARNING *** WARNING *** WARNING ***
+
+ This program was written using reverse engineered specifications available from wiibrew.org.
+ Therefore the operation of this program may not be entirely correct.
+ Results obtained by using this program may vary.
+
+
+AUDIENCE
+
+ This project is intended for developers who wish to include support for the Nintendo Wii remote
+ with their third party application. Please be aware that by using this software you are bound
+ to the terms of the GNU GPL.
+
+
+PLATFORMS AND DEPENDENCIES
+
+ Wiiuse currently operates on both Linux and Windows.
+ You will need:
+
+ For Linux:
+ - The kernel must support bluetooth
+ - The BlueZ bluetooth drivers must be installed
+
+ For Windows:
+ - Bluetooth driver (tested with Microsoft's stack with Windows XP SP2)
+ - If compiling, Microsoft Windows Driver Development Kit (DDK)
+
+
+COMPILING
+
+ Linux:
+ You need SDL and OpenGL installed to compile the SDL example.
+
+ # make [target]
+
+ If 'target' is omitted then everything is compiled.
+
+ Where 'target' can be any of the following:
+
+ - wiiuse
+ Compiles libwiiuse.so
+
+ - ex
+ Compiles wiiuse-example
+
+ - sdl-ex
+ Compiles wiiuse-sdl
+
+ Become root.
+
+ # make install
+
+ The above command will only install the binaries that you
+ selected to compile.
+
+ wiiuse.so is installed to /usr/lib
+ wiiuse-example and wiiuse-sdl are installed to /usr/bin
+
+ Windows:
+ A Microsoft Visual C++ 6.0 project file has been included.
+
+ You need the install the Windows DDK (driver development kit)
+ to compile wiiuse. Make sure you include the inc/ and lib/
+ directories from the DDK in your IDE include and library paths.
+ You can download this from here:
+ http://www.microsoft.com/whdc/devtools/ddk/default.mspx
+
+ You need to link the following libraries (already set in the
+ included project file):
+ - Ws2_32.lib
+ - hid.lib
+ - setupapi.lib
+
+
+USING THE LIBRARY IN A THIRD PARTY APPLICATION
+
+ To use the library in your own program you must first compile wiiuse as a module.
+ Include include/wiiuse.h in any file that uses wiiuse.
+
+ For Linux you must link wiiuse.so ( -lwiiuse ).
+ For Windows you must link wiiuse.lib. When your program runs it will need wiiuse.dll.
+
+
+BUGS
+
+ On Windows using more than one wiimote (usually more than two wiimotes) may cause
+ significant latency.
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsp b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsp
index 23c4a24c2a..007d6764b8 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsp
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsp
@@ -1,111 +1,111 @@
-# Microsoft Developer Studio Project File - Name="wiiusesdl" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Application" 0x0101
-
-CFG=wiiusesdl - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "wiiusesdl.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "wiiusesdl.mak" CFG="wiiusesdl - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "wiiusesdl - Win32 Release" (based on "Win32 (x86) Application")
-!MESSAGE "wiiusesdl - Win32 Debug" (based on "Win32 (x86) Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "wiiusesdl - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "..\..\src" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib sdl.lib opengl32.lib glu32.lib wiiuse.lib /nologo /subsystem:windows /machine:I386
-
-!ELSEIF "$(CFG)" == "wiiusesdl - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\src" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib sdl.lib opengl32.lib glu32.lib wiiuse.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "wiiusesdl - Win32 Release"
-# Name "wiiusesdl - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\sdl.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\..\src\wiiuse.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
+# Microsoft Developer Studio Project File - Name="wiiusesdl" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=wiiusesdl - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "wiiusesdl.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "wiiusesdl.mak" CFG="wiiusesdl - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "wiiusesdl - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "wiiusesdl - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "wiiusesdl - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "..\..\src" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib sdl.lib opengl32.lib glu32.lib wiiuse.lib /nologo /subsystem:windows /machine:I386
+
+!ELSEIF "$(CFG)" == "wiiusesdl - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\src" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib sdl.lib opengl32.lib glu32.lib wiiuse.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "wiiusesdl - Win32 Release"
+# Name "wiiusesdl - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\sdl.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\..\src\wiiuse.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsw b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsw
index 630b942593..ee501ff095 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsw
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/msvc/wiiusesdl.dsw
@@ -1,29 +1,29 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "wiiusesdl"=".\wiiusesdl.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "wiiusesdl"=".\wiiusesdl.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/sdl.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/sdl.c
index 0c0cdfb993..378611c7c8 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/sdl.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example-sdl/sdl.c
@@ -52,14 +52,14 @@ wiimote** wiimotes = NULL;
int last_dots[4][2] = {{0}};
int xcoord = 0;
-int ycoord = 0;
-
-#ifdef WIN32
+int ycoord = 0;
+
+#ifdef WIN32
DWORD last_render;
#else
struct timeval last_render;
- int last_sec = 0;
- int fps = 0;
+ int last_sec = 0;
+ int fps = 0;
#endif
enum render_mode_t {
@@ -122,8 +122,8 @@ void handle_event(struct wiimote_t* wm) {
wiiuse_set_ir(wm, 1);
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
wiiuse_set_ir(wm, 0);
-
- if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
+
+ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
wiiuse_toggle_rumble(wm);
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
@@ -158,8 +158,8 @@ int can_render() {
/* quick fps limit to ~60fps -- not too fancy, could be better */
#ifdef WIN32
if (GetTickCount() < (last_render + 16))
- return 0;
- last_render = GetTickCount();
+ return 0;
+ last_render = GetTickCount();
return 1;
#else
struct timeval now;
@@ -201,23 +201,23 @@ void display() {
float size = 5;
if (!can_render())
- return;
+ return;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ glLoadIdentity();
if (render_mode == IR) {
/* draw the IR stuff */
-
+
glDisable(GL_LIGHTING);
- glBegin(GL_TRIANGLES);
- /* green center */
- glColor3f(0.0, 1.0, 0.0);
- DRAW_TRIANGLE(width/2, height/2, 0, size);
- glEnd();
-
+ glBegin(GL_TRIANGLES);
+ /* green center */
+ glColor3f(0.0, 1.0, 0.0);
+ DRAW_TRIANGLE(width/2, height/2, 0, size);
+ glEnd();
+
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
glBegin(GL_TRIANGLES);
/* red ir */
@@ -255,7 +255,7 @@ void display() {
glutSolidTeapot(1);
- }
+ }
SDL_GL_SwapBuffers();
}
@@ -284,8 +284,8 @@ void set_material(struct material_t* mptr) {
}
-void resize_window(GLint new_width, GLint new_height) {
- int wm;
+void resize_window(GLint new_width, GLint new_height) {
+ int wm;
width = new_width;
height = new_height;
@@ -310,8 +310,8 @@ void resize_window(GLint new_width, GLint new_height) {
width = new_width;
height = new_height;
-
- for (wm = 0; wm < MAX_WIIMOTES; ++wm)
+
+ for (wm = 0; wm < MAX_WIIMOTES; ++wm)
wiiuse_set_ir_vres(wiimotes[wm], width, height);
}
@@ -320,7 +320,7 @@ int main(int argc, char** argv) {
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#endif
- int found, connected;
+ int found, connected;
int wm;
//printf("wiiuse version = %s\n", wiiuse_version());
@@ -337,7 +337,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return 0;
}
wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1 | WIIMOTE_LED_4);
- wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4);
+ wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4);
wiiuse_rumble(wiimotes[0], 1);
#ifndef WIN32
@@ -347,29 +347,29 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
#endif
wiiuse_rumble(wiimotes[0], 0);
-
- /* enable IR and motion sensing for all wiimotes */
- for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
+
+ /* enable IR and motion sensing for all wiimotes */
+ for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
wiiuse_motion_sensing(wiimotes[wm], 1);
- wiiuse_set_ir(wiimotes[wm], 1);
- }
+ wiiuse_set_ir(wiimotes[wm], 1);
+ }
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Failed to initialize SDL: %s\n", SDL_GetError());
return 0;
}
- SDL_WM_SetCaption("wiiuse SDL IR Example", "wiiuse SDL IR Example");
-
+ SDL_WM_SetCaption("wiiuse SDL IR Example", "wiiuse SDL IR Example");
+
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
/* set window size */
width = wiimotes[0]->ir.vres[0];
height = wiimotes[0]->ir.vres[1];
- SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
-
- for (wm = 0; wm < MAX_WIIMOTES; ++wm)
+ SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
+
+ for (wm = 0; wm < MAX_WIIMOTES; ++wm)
wiiuse_set_ir_vres(wiimotes[wm], width, height);
/* set OpenGL stuff */
@@ -385,15 +385,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
/* set the size of the window */
resize_window(width, height);
- display();
-
- #ifdef WIN32
+ display();
+
+ #ifdef WIN32
last_render = GetTickCount();
#endif
while (1) {
SDL_Event event;
-
+
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_VIDEORESIZE:
@@ -434,6 +434,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
}
- display();
+ display();
}
}
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsp b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsp
index 9e9b34faa8..2329dbc24b 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsp
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsp
@@ -1,106 +1,106 @@
-# Microsoft Developer Studio Project File - Name="wiiuseexample" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=wiiuseexample - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "wiiuseexample.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "wiiuseexample.mak" CFG="wiiuseexample - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "wiiuseexample - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "wiiuseexample - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "wiiuseexample - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "..\..\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib wiiuse.lib /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "wiiuseexample - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "wiiuseexample - Win32 Release"
-# Name "wiiuseexample - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\example.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\..\src\wiiuse.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
+# Microsoft Developer Studio Project File - Name="wiiuseexample" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=wiiuseexample - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "wiiuseexample.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "wiiuseexample.mak" CFG="wiiuseexample - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "wiiuseexample - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "wiiuseexample - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "wiiuseexample - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "..\..\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib wiiuse.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "wiiuseexample - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "wiiuseexample - Win32 Release"
+# Name "wiiuseexample - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\example.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\..\src\wiiuse.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsw b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsw
index e31f8f5615..88298b6c33 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsw
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/example/msvc/wiiuseexample.dsw
@@ -1,29 +1,29 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "wiiuseexample"=".\wiiuseexample.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "wiiuseexample"=".\wiiuseexample.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/classic.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/classic.c
index 1d2c3ab275..1d3abaa33f 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/classic.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/classic.c
@@ -57,7 +57,7 @@ static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now);
* @return Returns 1 if handshake was successful, 0 if not.
*/
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) {
- int i;
+ int i;
int offset = 0;
cc->btns = 0;
@@ -69,30 +69,30 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
/* decrypt data */
for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17;
-
- if (data[offset] == 0xFF) {
- /*
- * Sometimes the data returned here is not correct.
- * This might happen because the wiimote is lagging
- * behind our initialization sequence.
- * To fix this just request the handshake again.
- *
- * Other times it's just the first 16 bytes are 0xFF,
- * but since the next 16 bytes are the same, just use
- * those.
- */
- if (data[offset + 16] == 0xFF) {
- /* get the calibration data */
- byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
-
- WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again.");
- wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
-
- return 0;
- } else
- offset += 16;
- }
-
+
+ if (data[offset] == 0xFF) {
+ /*
+ * Sometimes the data returned here is not correct.
+ * This might happen because the wiimote is lagging
+ * behind our initialization sequence.
+ * To fix this just request the handshake again.
+ *
+ * Other times it's just the first 16 bytes are 0xFF,
+ * but since the next 16 bytes are the same, just use
+ * those.
+ */
+ if (data[offset + 16] == 0xFF) {
+ /* get the calibration data */
+ byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
+
+ WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again.");
+ wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
+
+ return 0;
+ } else
+ offset += 16;
+ }
+
/* joystick stuff */
cc->ljs.max.x = data[0 + offset] / 4;
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/definitions.h b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/definitions.h
index 5a8da85def..13ca132581 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/definitions.h
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/definitions.h
@@ -50,16 +50,16 @@
/* Information output macros */
#define WIIUSE_INFO(fmt, ...) fprintf(stderr, "[INFO] " fmt "\n", ##__VA_ARGS__)
-#ifdef WITH_WIIUSE_DEBUG
- #ifdef WIN32
- #define WIIUSE_DEBUG(fmt, ...) do { \
- char* file = __FILE__; \
- int i = strlen(file) - 1; \
- for (; i && (file[i] != '\\'); --i); \
- fprintf(stderr, "[DEBUG] %s:%i: " fmt "\n", file+i+1, __LINE__, ##__VA_ARGS__); \
- } while (0)
+#ifdef WITH_WIIUSE_DEBUG
+ #ifdef WIN32
+ #define WIIUSE_DEBUG(fmt, ...) do { \
+ char* file = __FILE__; \
+ int i = strlen(file) - 1; \
+ for (; i && (file[i] != '\\'); --i); \
+ fprintf(stderr, "[DEBUG] %s:%i: " fmt "\n", file+i+1, __LINE__, ##__VA_ARGS__); \
+ } while (0)
#else
- #define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__)
+ #define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__)
#endif
#else
#define WIIUSE_DEBUG(fmt, ...)
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/dynamics.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/dynamics.c
index 53612a6b90..b6baa72828 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/dynamics.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/dynamics.c
@@ -107,12 +107,12 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
orient->pitch = y;
orient->a_pitch = y;
}
-
- /* smooth the angles if enabled */
- if (smooth) {
- apply_smoothing(ac, orient, SMOOTH_ROLL);
- apply_smoothing(ac, orient, SMOOTH_PITCH);
- }
+
+ /* smooth the angles if enabled */
+ if (smooth) {
+ apply_smoothing(ac, orient, SMOOTH_ROLL);
+ apply_smoothing(ac, orient, SMOOTH_PITCH);
+ }
}
@@ -191,7 +191,7 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) {
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
switch (type) {
case SMOOTH_ROLL:
- {
+ {
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */
if (isnan(ac->st_roll) || isinf(ac->st_roll))
ac->st_roll = 0.0f;
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.c
index 6668eda5c8..578ee3f08b 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.c
@@ -1,146 +1,146 @@
-/*
- * 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 wiimote events.
- *
- * The file includes functions that handle the events
- * that are sent from the wiimote to us.
- */
-
-#include <stdio.h>
-
-#ifndef WIN32
- #include <sys/time.h>
- #include <unistd.h>
+/*
+ * 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 wiimote events.
+ *
+ * The file includes functions that handle the events
+ * that are sent from the wiimote to us.
+ */
+
+#include <stdio.h>
+
+#ifndef WIN32
+ #include <sys/time.h>
+ #include <unistd.h>
#include <errno.h>
-#else
+#else
#include <winsock2.h>
-#endif
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <math.h>
-
-#include "definitions.h"
-#include "io.h"
-#include "wiiuse_internal.h"
-#include "dynamics.h"
-#include "ir.h"
-#include "nunchuk.h"
-#include "classic.h"
-#include "guitar_hero_3.h"
-#include "events.h"
-
-static void idle_cycle(struct wiimote_t* wm);
+#endif
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "definitions.h"
+#include "io.h"
+#include "wiiuse_internal.h"
+#include "dynamics.h"
+#include "ir.h"
+#include "nunchuk.h"
+#include "classic.h"
+#include "guitar_hero_3.h"
+#include "events.h"
+
+static void idle_cycle(struct wiimote_t* wm);
static void clear_dirty_reads(struct wiimote_t* wm);
-static void propagate_event(struct wiimote_t* wm, byte event, byte* msg);
-static void event_data_read(struct wiimote_t* wm, byte* msg);
-static void event_status(struct wiimote_t* wm, byte* msg);
-static void handle_expansion(struct wiimote_t* wm, byte* msg);
-
-static void save_state(struct wiimote_t* wm);
-static int state_changed(struct wiimote_t* wm);
-
-/**
- * @brief Poll the wiimotes for any events.
- *
- * @param wm An array of pointers to wiimote_t structures.
- * @param wiimotes The number of wiimote_t structures in the \a wm array.
- *
- * @return Returns number of wiimotes that an event has occured on.
- *
- * It is necessary to poll the wiimote devices for events
- * that occur. If an event occurs on a particular wiimote,
- * the event variable will be set.
- */
-int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
- int evnt = 0;
-
- #ifndef WIN32
- /*
- * *nix
- */
- struct timeval tv;
- fd_set fds;
- int r;
- int i;
- int highest_fd = -1;
-
- if (!wm) return 0;
-
- /* block select() for 1/2000th of a second */
- tv.tv_sec = 0;
- tv.tv_usec = 500;
-
- FD_ZERO(&fds);
-
- for (i = 0; i < wiimotes; ++i) {
- /* only poll it if it is connected */
- if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
- FD_SET(wm[i]->in_sock, &fds);
-
- /* find the highest fd of the connected wiimotes */
- if (wm[i]->in_sock > highest_fd)
- highest_fd = wm[i]->in_sock;
- }
-
- wm[i]->event = WIIUSE_NONE;
- }
-
- if (highest_fd == -1)
- /* nothing to poll */
- return 0;
-
- if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
- WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
- perror("Error Details");
- return 0;
- }
-
- /* check each socket for an event */
- for (i = 0; i < wiimotes; ++i) {
- /* if this wiimote is not connected, skip it */
- if (!WIIMOTE_IS_CONNECTED(wm[i]))
- continue;
-
- if (FD_ISSET(wm[i]->in_sock, &fds)) {
- /* clear out the event buffer */
+static void propagate_event(struct wiimote_t* wm, byte event, byte* msg);
+static void event_data_read(struct wiimote_t* wm, byte* msg);
+static void event_status(struct wiimote_t* wm, byte* msg);
+static void handle_expansion(struct wiimote_t* wm, byte* msg);
+
+static void save_state(struct wiimote_t* wm);
+static int state_changed(struct wiimote_t* wm);
+
+/**
+ * @brief Poll the wiimotes for any events.
+ *
+ * @param wm An array of pointers to wiimote_t structures.
+ * @param wiimotes The number of wiimote_t structures in the \a wm array.
+ *
+ * @return Returns number of wiimotes that an event has occured on.
+ *
+ * It is necessary to poll the wiimote devices for events
+ * that occur. If an event occurs on a particular wiimote,
+ * the event variable will be set.
+ */
+int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
+ int evnt = 0;
+
+ #ifndef WIN32
+ /*
+ * *nix
+ */
+ struct timeval tv;
+ fd_set fds;
+ int r;
+ int i;
+ int highest_fd = -1;
+
+ if (!wm) return 0;
+
+ /* block select() for 1/2000th of a second */
+ tv.tv_sec = 0;
+ tv.tv_usec = 500;
+
+ FD_ZERO(&fds);
+
+ for (i = 0; i < wiimotes; ++i) {
+ /* only poll it if it is connected */
+ if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
+ FD_SET(wm[i]->in_sock, &fds);
+
+ /* find the highest fd of the connected wiimotes */
+ if (wm[i]->in_sock > highest_fd)
+ highest_fd = wm[i]->in_sock;
+ }
+
+ wm[i]->event = WIIUSE_NONE;
+ }
+
+ if (highest_fd == -1)
+ /* nothing to poll */
+ return 0;
+
+ if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
+ WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
+ perror("Error Details");
+ return 0;
+ }
+
+ /* check each socket for an event */
+ for (i = 0; i < wiimotes; ++i) {
+ /* if this wiimote is not connected, skip it */
+ if (!WIIMOTE_IS_CONNECTED(wm[i]))
+ continue;
+
+ if (FD_ISSET(wm[i]->in_sock, &fds)) {
+ /* clear out the event buffer */
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
/* clear out any old read requests */
- clear_dirty_reads(wm[i]);
-
- /* read the pending message into the buffer */
- r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf));
- if (r == -1) {
- /* error reading data */
+ clear_dirty_reads(wm[i]);
+
+ /* read the pending message into the buffer */
+ r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf));
+ if (r == -1) {
+ /* error reading data */
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid);
perror("Error Details");
@@ -150,72 +150,72 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
wiiuse_disconnect(wm[i]);
wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT;
}
-
- continue;
- }
- if (!r) {
- /* remote disconnect */
- wiiuse_disconnected(wm[i]);
- evnt = 1;
- continue;
- }
-
- /* propagate the event */
- propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
- evnt += (wm[i]->event != WIIUSE_NONE);
- } else {
- idle_cycle(wm[i]);
- }
- }
- #else
- /*
- * Windows
- */
- int i;
-
- if (!wm) return 0;
-
- for (i = 0; i < wiimotes; ++i) {
- wm[i]->event = WIIUSE_NONE;
-
- if (wiiuse_io_read(wm[i])) {
- /* propagate the event */
- propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1);
- evnt += (wm[i]->event != WIIUSE_NONE);
-
- /* clear out the event buffer */
- memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
- } else {
- idle_cycle(wm[i]);
- }
- }
- #endif
-
- return evnt;
-}
-
-
-/**
- * @brief Called on a cycle where no significant change occurs.
- *
- * @param wm Pointer to a wiimote_t structure.
- */
-static void idle_cycle(struct wiimote_t* wm) {
- /*
- * Smooth the angles.
- *
- * This is done to make sure that on every cycle the orientation
- * angles are smoothed. Normally when an event occurs the angles
- * are updated and smoothed, but if no packet comes in then the
- * angles remain the same. This means the angle wiiuse reports
- * is still an old value. Smoothing needs to be applied in this
- * case in order for the angle it reports to converge to the true
- * angle of the device.
- */
- if (WIIUSE_USING_ACC(wm) && WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)) {
- apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_ROLL);
- apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_PITCH);
- }
+
+ continue;
+ }
+ if (!r) {
+ /* remote disconnect */
+ wiiuse_disconnected(wm[i]);
+ evnt = 1;
+ continue;
+ }
+
+ /* propagate the event */
+ propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
+ evnt += (wm[i]->event != WIIUSE_NONE);
+ } else {
+ idle_cycle(wm[i]);
+ }
+ }
+ #else
+ /*
+ * Windows
+ */
+ int i;
+
+ if (!wm) return 0;
+
+ for (i = 0; i < wiimotes; ++i) {
+ wm[i]->event = WIIUSE_NONE;
+
+ if (wiiuse_io_read(wm[i])) {
+ /* propagate the event */
+ propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1);
+ evnt += (wm[i]->event != WIIUSE_NONE);
+
+ /* clear out the event buffer */
+ memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
+ } else {
+ idle_cycle(wm[i]);
+ }
+ }
+ #endif
+
+ return evnt;
+}
+
+
+/**
+ * @brief Called on a cycle where no significant change occurs.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ */
+static void idle_cycle(struct wiimote_t* wm) {
+ /*
+ * Smooth the angles.
+ *
+ * This is done to make sure that on every cycle the orientation
+ * angles are smoothed. Normally when an event occurs the angles
+ * are updated and smoothed, but if no packet comes in then the
+ * angles remain the same. This means the angle wiiuse reports
+ * is still an old value. Smoothing needs to be applied in this
+ * case in order for the angle it reports to converge to the true
+ * angle of the device.
+ */
+ if (WIIUSE_USING_ACC(wm) && WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)) {
+ apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_ROLL);
+ apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_PITCH);
+ }
/* clear out any old read requests */
clear_dirty_reads(wm);
@@ -237,264 +237,264 @@ static void clear_dirty_reads(struct wiimote_t* wm) {
free(req);
req = wm->read_req;
}
-}
-
-
-/**
- * @brief Analyze the event that occured on a wiimote.
- *
- * @param wm An array of pointers to wiimote_t structures.
- * @param event The event that occured.
- * @param msg The message specified in the event packet.
- *
- * Pass the event to the registered event callback.
- */
-static void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
- save_state(wm);
-
- switch (event) {
- case WM_RPT_BTN:
- {
- /* button */
- wiiuse_pressed_buttons(wm, msg);
- break;
- }
- case WM_RPT_BTN_ACC:
- {
- /* button - motion */
- wiiuse_pressed_buttons(wm, msg);
-
- wm->accel.x = msg[2];
- wm->accel.y = msg[3];
- wm->accel.z = msg[4];
-
- /* calculate the remote orientation */
- calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
-
- /* calculate the gforces on each axis */
- calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
-
- break;
- }
- case WM_RPT_READ:
- {
- /* data read */
- event_data_read(wm, msg);
-
- /* yeah buttons may be pressed, but this wasn't an "event" */
- return;
- }
- case WM_RPT_CTRL_STATUS:
- {
- /* controller status */
- event_status(wm, msg);
-
- /* don't execute the event callback */
- return;
- }
- case WM_RPT_BTN_EXP:
- {
- /* button - expansion */
- wiiuse_pressed_buttons(wm, msg);
- handle_expansion(wm, msg+2);
-
- break;
- }
- case WM_RPT_BTN_ACC_EXP:
- {
- /* button - motion - expansion */
- wiiuse_pressed_buttons(wm, msg);
-
- wm->accel.x = msg[2];
- wm->accel.y = msg[3];
- wm->accel.z = msg[4];
-
- calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
- calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
-
- handle_expansion(wm, msg+5);
-
- break;
- }
- case WM_RPT_BTN_ACC_IR:
- {
- /* button - motion - ir */
- wiiuse_pressed_buttons(wm, msg);
-
- wm->accel.x = msg[2];
- wm->accel.y = msg[3];
- wm->accel.z = msg[4];
-
- calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
- calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
-
- /* ir */
- calculate_extended_ir(wm, msg+5);
-
- break;
- }
- case WM_RPT_BTN_IR_EXP:
- {
- /* button - ir - expansion */
- wiiuse_pressed_buttons(wm, msg);
- handle_expansion(wm, msg+12);
-
- /* ir */
- calculate_basic_ir(wm, msg+2);
-
- break;
- }
- case WM_RPT_BTN_ACC_IR_EXP:
- {
- /* button - motion - ir - expansion */
- wiiuse_pressed_buttons(wm, msg);
-
- wm->accel.x = msg[2];
- wm->accel.y = msg[3];
- wm->accel.z = msg[4];
-
- calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
- calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
-
- handle_expansion(wm, msg+15);
-
- /* ir */
- calculate_basic_ir(wm, msg+5);
-
- break;
- }
- case WM_RPT_WRITE:
- {
- /* write feedback - safe to skip */
- break;
- }
- default:
- {
- WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
- return;
- }
- }
-
- /* was there an event? */
- if (state_changed(wm))
- wm->event = WIIUSE_EVENT;
-}
-
-
-/**
- * @brief Find what buttons are pressed.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param msg The message specified in the event packet.
- */
-void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg) {
- short now;
-
- /* convert to big endian */
- now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL;
-
- /* pressed now & were pressed, then held */
- wm->btns_held = (now & wm->btns);
-
- /* were pressed or were held & not pressed now, then released */
- wm->btns_released = ((wm->btns | wm->btns_held) & ~now);
-
- /* buttons pressed now */
- wm->btns = now;
-}
-
-
-/**
- * @brief Received a data packet from a read request.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param msg The message specified in the event packet.
- *
- * Data from the wiimote comes in packets. If the requested
- * data segment size is bigger than one packet can hold then
- * several packets will be received. These packets are first
- * reassembled into one, then the registered callback function
- * that handles data reads is invoked.
- */
-static void event_data_read(struct wiimote_t* wm, byte* msg) {
- /* we must always assume the packet received is from the most recent request */
- byte err;
- byte len;
- unsigned short offset;
- struct read_req_t* req = wm->read_req;
-
- wiiuse_pressed_buttons(wm, msg);
+}
+
+
+/**
+ * @brief Analyze the event that occured on a wiimote.
+ *
+ * @param wm An array of pointers to wiimote_t structures.
+ * @param event The event that occured.
+ * @param msg The message specified in the event packet.
+ *
+ * Pass the event to the registered event callback.
+ */
+static void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
+ save_state(wm);
+
+ switch (event) {
+ case WM_RPT_BTN:
+ {
+ /* button */
+ wiiuse_pressed_buttons(wm, msg);
+ break;
+ }
+ case WM_RPT_BTN_ACC:
+ {
+ /* button - motion */
+ wiiuse_pressed_buttons(wm, msg);
+
+ wm->accel.x = msg[2];
+ wm->accel.y = msg[3];
+ wm->accel.z = msg[4];
+
+ /* calculate the remote orientation */
+ calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
+
+ /* calculate the gforces on each axis */
+ calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
+
+ break;
+ }
+ case WM_RPT_READ:
+ {
+ /* data read */
+ event_data_read(wm, msg);
+
+ /* yeah buttons may be pressed, but this wasn't an "event" */
+ return;
+ }
+ case WM_RPT_CTRL_STATUS:
+ {
+ /* controller status */
+ event_status(wm, msg);
+
+ /* don't execute the event callback */
+ return;
+ }
+ case WM_RPT_BTN_EXP:
+ {
+ /* button - expansion */
+ wiiuse_pressed_buttons(wm, msg);
+ handle_expansion(wm, msg+2);
+
+ break;
+ }
+ case WM_RPT_BTN_ACC_EXP:
+ {
+ /* button - motion - expansion */
+ wiiuse_pressed_buttons(wm, msg);
+
+ wm->accel.x = msg[2];
+ wm->accel.y = msg[3];
+ wm->accel.z = msg[4];
+
+ calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
+ calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
+
+ handle_expansion(wm, msg+5);
+
+ break;
+ }
+ case WM_RPT_BTN_ACC_IR:
+ {
+ /* button - motion - ir */
+ wiiuse_pressed_buttons(wm, msg);
+
+ wm->accel.x = msg[2];
+ wm->accel.y = msg[3];
+ wm->accel.z = msg[4];
+
+ calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
+ calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
+
+ /* ir */
+ calculate_extended_ir(wm, msg+5);
+
+ break;
+ }
+ case WM_RPT_BTN_IR_EXP:
+ {
+ /* button - ir - expansion */
+ wiiuse_pressed_buttons(wm, msg);
+ handle_expansion(wm, msg+12);
+
+ /* ir */
+ calculate_basic_ir(wm, msg+2);
+
+ break;
+ }
+ case WM_RPT_BTN_ACC_IR_EXP:
+ {
+ /* button - motion - ir - expansion */
+ wiiuse_pressed_buttons(wm, msg);
+
+ wm->accel.x = msg[2];
+ wm->accel.y = msg[3];
+ wm->accel.z = msg[4];
+
+ calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
+ calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
+
+ handle_expansion(wm, msg+15);
+
+ /* ir */
+ calculate_basic_ir(wm, msg+5);
+
+ break;
+ }
+ case WM_RPT_WRITE:
+ {
+ /* write feedback - safe to skip */
+ break;
+ }
+ default:
+ {
+ WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
+ return;
+ }
+ }
+
+ /* was there an event? */
+ if (state_changed(wm))
+ wm->event = WIIUSE_EVENT;
+}
+
+
+/**
+ * @brief Find what buttons are pressed.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param msg The message specified in the event packet.
+ */
+void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg) {
+ short now;
+
+ /* convert to big endian */
+ now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL;
+
+ /* pressed now & were pressed, then held */
+ wm->btns_held = (now & wm->btns);
+
+ /* were pressed or were held & not pressed now, then released */
+ wm->btns_released = ((wm->btns | wm->btns_held) & ~now);
+
+ /* buttons pressed now */
+ wm->btns = now;
+}
+
+
+/**
+ * @brief Received a data packet from a read request.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param msg The message specified in the event packet.
+ *
+ * Data from the wiimote comes in packets. If the requested
+ * data segment size is bigger than one packet can hold then
+ * several packets will be received. These packets are first
+ * reassembled into one, then the registered callback function
+ * that handles data reads is invoked.
+ */
+static void event_data_read(struct wiimote_t* wm, byte* msg) {
+ /* we must always assume the packet received is from the most recent request */
+ byte err;
+ byte len;
+ unsigned short offset;
+ struct read_req_t* req = wm->read_req;
+
+ wiiuse_pressed_buttons(wm, msg);
/* find the next non-dirty request */
while (req && req->dirty)
req = req->next;
-
- /* if we don't have a request out then we didn't ask for this packet */
- if (!req) {
- WIIUSE_WARNING("Received data packet when no request was made.");
- return;
- }
-
- err = msg[2] & 0x0F;
-
- if (err == 0x08)
- WIIUSE_WARNING("Unable to read data - address does not exist.");
- else if (err == 0x07)
- WIIUSE_WARNING("Unable to read data - address is for write-only registers.");
- else if (err)
- WIIUSE_WARNING("Unable to read data - unknown error code %x.", err);
-
- if (err) {
- /* this request errored out, so skip it and go to the next one */
-
- /* delete this request */
- wm->read_req = req->next;
- free(req);
-
- /* if another request exists send it to the wiimote */
- if (wm->read_req)
- wiiuse_send_next_pending_read_request(wm);
-
- return;
- }
-
- len = ((msg[2] & 0xF0) >> 4) + 1;
- offset = BIG_ENDIAN_SHORT(*(unsigned short*)(msg + 3));
- req->addr = (req->addr & 0xFFFF);
-
- req->wait -= len;
- if (req->wait >= req->size)
- /* this should never happen */
- req->wait = 0;
-
- WIIUSE_DEBUG("Received read packet:");
- WIIUSE_DEBUG(" Packet read offset: %i bytes", offset);
- WIIUSE_DEBUG(" Request read offset: %i bytes", req->addr);
- WIIUSE_DEBUG(" Read offset into buf: %i bytes", offset - req->addr);
- WIIUSE_DEBUG(" Read data size: %i bytes", len);
- WIIUSE_DEBUG(" Still need: %i bytes", req->wait);
-
- /* reconstruct this part of the data */
- memcpy((req->buf + offset - req->addr), (msg + 5), len);
-
- #ifdef WITH_WIIUSE_DEBUG
- {
- int i = 0;
- printf("Read: ");
- for (; i < req->size - req->wait; ++i)
- printf("%x ", req->buf[i]);
- printf("\n");
- }
- #endif
-
- /* if all data has been received, execute the read event callback or generate event */
+
+ /* if we don't have a request out then we didn't ask for this packet */
+ if (!req) {
+ WIIUSE_WARNING("Received data packet when no request was made.");
+ return;
+ }
+
+ err = msg[2] & 0x0F;
+
+ if (err == 0x08)
+ WIIUSE_WARNING("Unable to read data - address does not exist.");
+ else if (err == 0x07)
+ WIIUSE_WARNING("Unable to read data - address is for write-only registers.");
+ else if (err)
+ WIIUSE_WARNING("Unable to read data - unknown error code %x.", err);
+
+ if (err) {
+ /* this request errored out, so skip it and go to the next one */
+
+ /* delete this request */
+ wm->read_req = req->next;
+ free(req);
+
+ /* if another request exists send it to the wiimote */
+ if (wm->read_req)
+ wiiuse_send_next_pending_read_request(wm);
+
+ return;
+ }
+
+ len = ((msg[2] & 0xF0) >> 4) + 1;
+ offset = BIG_ENDIAN_SHORT(*(unsigned short*)(msg + 3));
+ req->addr = (req->addr & 0xFFFF);
+
+ req->wait -= len;
+ if (req->wait >= req->size)
+ /* this should never happen */
+ req->wait = 0;
+
+ WIIUSE_DEBUG("Received read packet:");
+ WIIUSE_DEBUG(" Packet read offset: %i bytes", offset);
+ WIIUSE_DEBUG(" Request read offset: %i bytes", req->addr);
+ WIIUSE_DEBUG(" Read offset into buf: %i bytes", offset - req->addr);
+ WIIUSE_DEBUG(" Read data size: %i bytes", len);
+ WIIUSE_DEBUG(" Still need: %i bytes", req->wait);
+
+ /* reconstruct this part of the data */
+ memcpy((req->buf + offset - req->addr), (msg + 5), len);
+
+ #ifdef WITH_WIIUSE_DEBUG
+ {
+ int i = 0;
+ printf("Read: ");
+ for (; i < req->size - req->wait; ++i)
+ printf("%x ", req->buf[i]);
+ printf("\n");
+ }
+ #endif
+
+ /* if all data has been received, execute the read event callback or generate event */
if (!req->wait) {
if (req->cb) {
- /* this was a callback, so invoke it now */
- req->cb(wm, req->buf, req->size);
-
- /* delete this request */
- wm->read_req = req->next;
+ /* this was a callback, so invoke it now */
+ req->cb(wm, req->buf, req->size);
+
+ /* delete this request */
+ wm->read_req = req->next;
free(req);
} else {
/*
@@ -506,373 +506,373 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
*/
wm->event = WIIUSE_READ_DATA;
req->dirty = 1;
- }
-
- /* if another request exists send it to the wiimote */
- if (wm->read_req)
- wiiuse_send_next_pending_read_request(wm);
- }
-}
-
-
-/**
- * @brief Read the controller status.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param msg The message specified in the event packet.
- *
- * Read the controller status and execute the registered status callback.
- */
-static void event_status(struct wiimote_t* wm, byte* msg) {
- int led[4] = {0};
- int attachment = 0;
- int ir = 0;
- int exp_changed = 0;
-
- /*
- * An event occured.
- * This event can be overwritten by a more specific
- * event type during a handshake or expansion removal.
- */
- wm->event = WIIUSE_STATUS;
-
- wiiuse_pressed_buttons(wm, msg);
-
- /* find what LEDs are lit */
- if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1;
- if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1;
- if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1;
- if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1;
-
- /* is an attachment connected to the expansion port? */
- if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT)
- attachment = 1;
-
- /* is the speaker enabled? */
- if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED)
- WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
-
- /* is IR sensing enabled? */
- if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED)
- ir = 1;
-
- /* find the battery level and normalize between 0 and 1 */
- wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
-
- /* expansion port */
- if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
- /* send the initialization code for the attachment */
- handshake_expansion(wm, NULL, 0);
- exp_changed = 1;
- } else if (!attachment && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
- /* attachment removed */
- disable_expansion(wm);
- exp_changed = 1;
- }
-
- #ifdef WIN32
- if (!attachment) {
- WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
- wm->timeout = wm->normal_timeout;
- }
- #endif
-
- /*
- * From now on the remote will only send status packets.
- * We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
- * reenable other incoming reports.
- */
- if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
- /*
- * Since the expansion status changed IR needs to
- * be reset for the new IR report mode.
- */
- WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
- wiiuse_set_ir(wm, 1);
- } else
- wiiuse_set_report_type(wm);
-}
-
-
-/**
- * @brief Handle data from the expansion.
- *
- * @param wm A pointer to a wiimote_t structure.
- * @param msg The message specified in the event packet for the expansion.
- */
-static void handle_expansion(struct wiimote_t* wm, byte* msg) {
- switch (wm->exp.type) {
- case EXP_NUNCHUK:
- nunchuk_event(&wm->exp.nunchuk, msg);
- break;
- case EXP_CLASSIC:
- classic_ctrl_event(&wm->exp.classic, msg);
- break;
- case EXP_GUITAR_HERO_3:
- guitar_hero_3_event(&wm->exp.gh3, msg);
- break;
- default:
- break;
- }
-}
-
-
-/**
- * @brief Handle the handshake data from the expansion device.
- *
- * @param wm A pointer to a wiimote_t structure.
- * @param data The data read in from the device.
- * @param len The length of the data block, in bytes.
- *
- * Tries to determine what kind of expansion was attached
- * and invoke the correct handshake function.
- *
- * If the data is NULL then this function will try to start
- * a handshake with the expansion.
- */
-void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) {
- int id;
-
- if (!data) {
- byte* handshake_buf;
- byte buf = 0x00;
-
- if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
- disable_expansion(wm);
-
- /* increase the timeout until the handshake completes */
- #ifdef WIN32
- WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout);
- wm->timeout = wm->exp_timeout;
- #endif
-
- wiiuse_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1);
-
- /* get the calibration data */
- handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
- wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
-
- /* tell the wiimote to send expansion data */
- WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
-
- return;
- }
-
- id = BIG_ENDIAN_LONG(*(int*)(data + 220));
-
- /* call the corresponding handshake function for this expansion */
- switch (id) {
- case EXP_ID_CODE_NUNCHUK:
- {
- if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len))
- wm->event = WIIUSE_NUNCHUK_INSERTED;
- break;
- }
- case EXP_ID_CODE_CLASSIC_CONTROLLER:
+ }
+
+ /* if another request exists send it to the wiimote */
+ if (wm->read_req)
+ wiiuse_send_next_pending_read_request(wm);
+ }
+}
+
+
+/**
+ * @brief Read the controller status.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param msg The message specified in the event packet.
+ *
+ * Read the controller status and execute the registered status callback.
+ */
+static void event_status(struct wiimote_t* wm, byte* msg) {
+ int led[4] = {0};
+ int attachment = 0;
+ int ir = 0;
+ int exp_changed = 0;
+
+ /*
+ * An event occured.
+ * This event can be overwritten by a more specific
+ * event type during a handshake or expansion removal.
+ */
+ wm->event = WIIUSE_STATUS;
+
+ wiiuse_pressed_buttons(wm, msg);
+
+ /* find what LEDs are lit */
+ if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1;
+ if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1;
+ if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1;
+ if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1;
+
+ /* is an attachment connected to the expansion port? */
+ if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT)
+ attachment = 1;
+
+ /* is the speaker enabled? */
+ if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED)
+ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
+
+ /* is IR sensing enabled? */
+ if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED)
+ ir = 1;
+
+ /* find the battery level and normalize between 0 and 1 */
+ wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
+
+ /* expansion port */
+ if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
+ /* send the initialization code for the attachment */
+ handshake_expansion(wm, NULL, 0);
+ exp_changed = 1;
+ } else if (!attachment && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
+ /* attachment removed */
+ disable_expansion(wm);
+ exp_changed = 1;
+ }
+
+ #ifdef WIN32
+ if (!attachment) {
+ WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
+ wm->timeout = wm->normal_timeout;
+ }
+ #endif
+
+ /*
+ * From now on the remote will only send status packets.
+ * We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
+ * reenable other incoming reports.
+ */
+ if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
+ /*
+ * Since the expansion status changed IR needs to
+ * be reset for the new IR report mode.
+ */
+ WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
+ wiiuse_set_ir(wm, 1);
+ } else
+ wiiuse_set_report_type(wm);
+}
+
+
+/**
+ * @brief Handle data from the expansion.
+ *
+ * @param wm A pointer to a wiimote_t structure.
+ * @param msg The message specified in the event packet for the expansion.
+ */
+static void handle_expansion(struct wiimote_t* wm, byte* msg) {
+ switch (wm->exp.type) {
+ case EXP_NUNCHUK:
+ nunchuk_event(&wm->exp.nunchuk, msg);
+ break;
+ case EXP_CLASSIC:
+ classic_ctrl_event(&wm->exp.classic, msg);
+ break;
+ case EXP_GUITAR_HERO_3:
+ guitar_hero_3_event(&wm->exp.gh3, msg);
+ break;
+ default:
+ break;
+ }
+}
+
+
+/**
+ * @brief Handle the handshake data from the expansion device.
+ *
+ * @param wm A pointer to a wiimote_t structure.
+ * @param data The data read in from the device.
+ * @param len The length of the data block, in bytes.
+ *
+ * Tries to determine what kind of expansion was attached
+ * and invoke the correct handshake function.
+ *
+ * If the data is NULL then this function will try to start
+ * a handshake with the expansion.
+ */
+void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) {
+ int id;
+
+ if (!data) {
+ byte* handshake_buf;
+ byte buf = 0x00;
+
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
+ disable_expansion(wm);
+
+ /* increase the timeout until the handshake completes */
+ #ifdef WIN32
+ WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout);
+ wm->timeout = wm->exp_timeout;
+ #endif
+
+ wiiuse_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1);
+
+ /* get the calibration data */
+ handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
+ wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
+
+ /* tell the wiimote to send expansion data */
+ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
+
+ return;
+ }
+
+ id = BIG_ENDIAN_LONG(*(int*)(data + 220));
+
+ /* call the corresponding handshake function for this expansion */
+ switch (id) {
+ case EXP_ID_CODE_NUNCHUK:
{
- if (classic_ctrl_handshake(wm, &wm->exp.classic, data, len))
+ if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len))
+ wm->event = WIIUSE_NUNCHUK_INSERTED;
+ break;
+ }
+ case EXP_ID_CODE_CLASSIC_CONTROLLER:
+ {
+ if (classic_ctrl_handshake(wm, &wm->exp.classic, data, len))
wm->event = WIIUSE_CLASSIC_CTRL_INSERTED;
- break;
- }
- case EXP_ID_CODE_GUITAR:
- {
- if (guitar_hero_3_handshake(wm, &wm->exp.gh3, data, len))
- wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED;
- break;
- }
- default:
- {
- WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id);
- break;
- }
- }
-
- free(data);
-}
-
-
-
-/**
- * @brief Disable the expansion device if it was enabled.
- *
- * @param wm A pointer to a wiimote_t structure.
- * @param data The data read in from the device.
- * @param len The length of the data block, in bytes.
- *
- * If the data is NULL then this function will try to start
- * a handshake with the expansion.
- */
-void disable_expansion(struct wiimote_t* wm) {
- if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
- return;
-
- /* tell the assoicated module the expansion was removed */
- switch (wm->exp.type) {
- case EXP_NUNCHUK:
- nunchuk_disconnected(&wm->exp.nunchuk);
- wm->event = WIIUSE_NUNCHUK_REMOVED;
- break;
- case EXP_CLASSIC:
- classic_ctrl_disconnected(&wm->exp.classic);
- wm->event = WIIUSE_CLASSIC_CTRL_REMOVED;
- break;
- case EXP_GUITAR_HERO_3:
- guitar_hero_3_disconnected(&wm->exp.gh3);
- wm->event = WIIUSE_GUITAR_HERO_3_CTRL_REMOVED;
- break;
- default:
- break;
- }
-
- WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
- wm->exp.type = EXP_NONE;
-}
-
-
-/**
- * @brief Save important state data.
- * @param wm A pointer to a wiimote_t structure.
- */
-static void save_state(struct wiimote_t* wm) {
- /* wiimote */
- wm->lstate.btns = wm->btns;
- wm->lstate.accel = wm->accel;
-
- /* ir */
- if (WIIUSE_USING_IR(wm)) {
- wm->lstate.ir_ax = wm->ir.ax;
- wm->lstate.ir_ay = wm->ir.ay;
- wm->lstate.ir_distance = wm->ir.distance;
- }
-
- /* expansion */
- switch (wm->exp.type) {
- case EXP_NUNCHUK:
- wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang;
- wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag;
- wm->lstate.exp_btns = wm->exp.nunchuk.btns;
- wm->lstate.exp_accel = wm->exp.nunchuk.accel;
- break;
-
- case EXP_CLASSIC:
- wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
- wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
- wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
- wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag;
- wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder;
- wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder;
- wm->lstate.exp_btns = wm->exp.classic.btns;
- break;
-
- case EXP_GUITAR_HERO_3:
- wm->lstate.exp_ljs_ang = wm->exp.gh3.js.ang;
- wm->lstate.exp_ljs_mag = wm->exp.gh3.js.mag;
- wm->lstate.exp_r_shoulder = wm->exp.gh3.whammy_bar;
- wm->lstate.exp_btns = wm->exp.gh3.btns;
- break;
-
- case EXP_NONE:
- break;
- }
-}
-
-
-/**
- * @brief Determine if the current state differs significantly from the previous.
- * @param wm A pointer to a wiimote_t structure.
- * @return 1 if a significant change occured, 0 if not.
- */
-static int state_changed(struct wiimote_t* wm) {
- #define STATE_CHANGED(a, b) if (a != b) return 1
-
- #define CROSS_THRESH(last, now, thresh) \
- do { \
- if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
- if ((diff_f(last.roll, now.roll) >= thresh) || \
- (diff_f(last.pitch, now.pitch) >= thresh) || \
- (diff_f(last.yaw, now.yaw) >= thresh)) \
- { \
- last = now; \
- return 1; \
- } \
- } else { \
- if (last.roll != now.roll) return 1; \
- if (last.pitch != now.pitch) return 1; \
- if (last.yaw != now.yaw) return 1; \
- } \
- } while (0)
-
- #define CROSS_THRESH_XYZ(last, now, thresh) \
- do { \
- if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
- if ((diff_f(last.x, now.x) >= thresh) || \
- (diff_f(last.y, now.y) >= thresh) || \
- (diff_f(last.z, now.z) >= thresh)) \
- { \
- last = now; \
- return 1; \
- } \
- } else { \
- if (last.x != now.x) return 1; \
- if (last.y != now.y) return 1; \
- if (last.z != now.z) return 1; \
- } \
- } while (0)
-
- /* ir */
- if (WIIUSE_USING_IR(wm)) {
- STATE_CHANGED(wm->lstate.ir_ax, wm->ir.ax);
- STATE_CHANGED(wm->lstate.ir_ay, wm->ir.ay);
- STATE_CHANGED(wm->lstate.ir_distance, wm->ir.distance);
- }
-
- /* accelerometer */
- if (WIIUSE_USING_ACC(wm)) {
- /* raw accelerometer */
- CROSS_THRESH_XYZ(wm->lstate.accel, wm->accel, wm->accel_threshold);
-
- /* orientation */
- CROSS_THRESH(wm->lstate.orient, wm->orient, wm->orient_threshold);
- }
-
- /* expansion */
- switch (wm->exp.type) {
- case EXP_NUNCHUK:
- {
- STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
- STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
- STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
-
- CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
- CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
- break;
- }
- case EXP_CLASSIC:
- {
- STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
- STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
- STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
- STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag);
- STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
- STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
- STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
- break;
- }
- case EXP_GUITAR_HERO_3:
- {
- STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
- STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
- STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
- STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
- break;
- }
- case EXP_NONE:
- {
- break;
- }
- }
-
- STATE_CHANGED(wm->lstate.btns, wm->btns);
-
- return 0;
-}
+ break;
+ }
+ case EXP_ID_CODE_GUITAR:
+ {
+ if (guitar_hero_3_handshake(wm, &wm->exp.gh3, data, len))
+ wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED;
+ break;
+ }
+ default:
+ {
+ WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id);
+ break;
+ }
+ }
+
+ free(data);
+}
+
+
+
+/**
+ * @brief Disable the expansion device if it was enabled.
+ *
+ * @param wm A pointer to a wiimote_t structure.
+ * @param data The data read in from the device.
+ * @param len The length of the data block, in bytes.
+ *
+ * If the data is NULL then this function will try to start
+ * a handshake with the expansion.
+ */
+void disable_expansion(struct wiimote_t* wm) {
+ if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
+ return;
+
+ /* tell the assoicated module the expansion was removed */
+ switch (wm->exp.type) {
+ case EXP_NUNCHUK:
+ nunchuk_disconnected(&wm->exp.nunchuk);
+ wm->event = WIIUSE_NUNCHUK_REMOVED;
+ break;
+ case EXP_CLASSIC:
+ classic_ctrl_disconnected(&wm->exp.classic);
+ wm->event = WIIUSE_CLASSIC_CTRL_REMOVED;
+ break;
+ case EXP_GUITAR_HERO_3:
+ guitar_hero_3_disconnected(&wm->exp.gh3);
+ wm->event = WIIUSE_GUITAR_HERO_3_CTRL_REMOVED;
+ break;
+ default:
+ break;
+ }
+
+ WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
+ wm->exp.type = EXP_NONE;
+}
+
+
+/**
+ * @brief Save important state data.
+ * @param wm A pointer to a wiimote_t structure.
+ */
+static void save_state(struct wiimote_t* wm) {
+ /* wiimote */
+ wm->lstate.btns = wm->btns;
+ wm->lstate.accel = wm->accel;
+
+ /* ir */
+ if (WIIUSE_USING_IR(wm)) {
+ wm->lstate.ir_ax = wm->ir.ax;
+ wm->lstate.ir_ay = wm->ir.ay;
+ wm->lstate.ir_distance = wm->ir.distance;
+ }
+
+ /* expansion */
+ switch (wm->exp.type) {
+ case EXP_NUNCHUK:
+ wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang;
+ wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag;
+ wm->lstate.exp_btns = wm->exp.nunchuk.btns;
+ wm->lstate.exp_accel = wm->exp.nunchuk.accel;
+ break;
+
+ case EXP_CLASSIC:
+ wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
+ wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
+ wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
+ wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag;
+ wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder;
+ wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder;
+ wm->lstate.exp_btns = wm->exp.classic.btns;
+ break;
+
+ case EXP_GUITAR_HERO_3:
+ wm->lstate.exp_ljs_ang = wm->exp.gh3.js.ang;
+ wm->lstate.exp_ljs_mag = wm->exp.gh3.js.mag;
+ wm->lstate.exp_r_shoulder = wm->exp.gh3.whammy_bar;
+ wm->lstate.exp_btns = wm->exp.gh3.btns;
+ break;
+
+ case EXP_NONE:
+ break;
+ }
+}
+
+
+/**
+ * @brief Determine if the current state differs significantly from the previous.
+ * @param wm A pointer to a wiimote_t structure.
+ * @return 1 if a significant change occured, 0 if not.
+ */
+static int state_changed(struct wiimote_t* wm) {
+ #define STATE_CHANGED(a, b) if (a != b) return 1
+
+ #define CROSS_THRESH(last, now, thresh) \
+ do { \
+ if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
+ if ((diff_f(last.roll, now.roll) >= thresh) || \
+ (diff_f(last.pitch, now.pitch) >= thresh) || \
+ (diff_f(last.yaw, now.yaw) >= thresh)) \
+ { \
+ last = now; \
+ return 1; \
+ } \
+ } else { \
+ if (last.roll != now.roll) return 1; \
+ if (last.pitch != now.pitch) return 1; \
+ if (last.yaw != now.yaw) return 1; \
+ } \
+ } while (0)
+
+ #define CROSS_THRESH_XYZ(last, now, thresh) \
+ do { \
+ if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
+ if ((diff_f(last.x, now.x) >= thresh) || \
+ (diff_f(last.y, now.y) >= thresh) || \
+ (diff_f(last.z, now.z) >= thresh)) \
+ { \
+ last = now; \
+ return 1; \
+ } \
+ } else { \
+ if (last.x != now.x) return 1; \
+ if (last.y != now.y) return 1; \
+ if (last.z != now.z) return 1; \
+ } \
+ } while (0)
+
+ /* ir */
+ if (WIIUSE_USING_IR(wm)) {
+ STATE_CHANGED(wm->lstate.ir_ax, wm->ir.ax);
+ STATE_CHANGED(wm->lstate.ir_ay, wm->ir.ay);
+ STATE_CHANGED(wm->lstate.ir_distance, wm->ir.distance);
+ }
+
+ /* accelerometer */
+ if (WIIUSE_USING_ACC(wm)) {
+ /* raw accelerometer */
+ CROSS_THRESH_XYZ(wm->lstate.accel, wm->accel, wm->accel_threshold);
+
+ /* orientation */
+ CROSS_THRESH(wm->lstate.orient, wm->orient, wm->orient_threshold);
+ }
+
+ /* expansion */
+ switch (wm->exp.type) {
+ case EXP_NUNCHUK:
+ {
+ STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
+ STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
+ STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
+
+ CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
+ CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
+ break;
+ }
+ case EXP_CLASSIC:
+ {
+ STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
+ STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
+ STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
+ STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag);
+ STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
+ STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
+ STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
+ break;
+ }
+ case EXP_GUITAR_HERO_3:
+ {
+ STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
+ STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
+ STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
+ STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
+ break;
+ }
+ case EXP_NONE:
+ {
+ break;
+ }
+ }
+
+ STATE_CHANGED(wm->lstate.btns, wm->btns);
+
+ return 0;
+}
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.h b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.h
index 5e9b955c55..12fa74281d 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.h
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/events.h
@@ -44,7 +44,7 @@ extern "C" {
void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg);
void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len);
-void disable_expansion(struct wiimote_t* wm);
+void disable_expansion(struct wiimote_t* wm);
#ifdef __cplusplus
}
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/guitar_hero_3.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/guitar_hero_3.c
index 5837dc016f..29c58af10b 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/guitar_hero_3.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/guitar_hero_3.c
@@ -57,7 +57,7 @@ static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now
* @return Returns 1 if handshake was successful, 0 if not.
*/
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len) {
- int i;
+ int i;
int offset = 0;
/*
@@ -74,29 +74,29 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
/* decrypt data */
for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17;
-
- if (data[offset] == 0xFF) {
- /*
- * Sometimes the data returned here is not correct.
- * This might happen because the wiimote is lagging
- * behind our initialization sequence.
- * To fix this just request the handshake again.
- *
- * Other times it's just the first 16 bytes are 0xFF,
- * but since the next 16 bytes are the same, just use
- * those.
- */
- if (data[offset + 16] == 0xFF) {
- /* get the calibration data */
- byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
-
- WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again.");
- wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
-
- return 0;
- } else
- offset += 16;
- }
+
+ if (data[offset] == 0xFF) {
+ /*
+ * Sometimes the data returned here is not correct.
+ * This might happen because the wiimote is lagging
+ * behind our initialization sequence.
+ * To fix this just request the handshake again.
+ *
+ * Other times it's just the first 16 bytes are 0xFF,
+ * but since the next 16 bytes are the same, just use
+ * those.
+ */
+ if (data[offset + 16] == 0xFF) {
+ /* get the calibration data */
+ byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
+
+ WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again.");
+ wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
+
+ return 0;
+ } else
+ offset += 16;
+ }
/* joystick stuff */
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io.c
index ae420b9ef3..65b362770a 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io.c
@@ -59,8 +59,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
case 0:
{
/* send request to wiimote for accelerometer calibration */
- byte* buf;
-
+ byte* buf;
+
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
@@ -68,8 +68,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
wm->handshake_state++;
- wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
-
+ wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
+
break;
}
case 1:
@@ -94,23 +94,23 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
-
- /* request the status of the wiimote to see if there is an expansion */
- wiiuse_status(wm);
-
+
+ /* request the status of the wiimote to see if there is an expansion */
+ wiiuse_status(wm);
+
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
- wm->handshake_state++;
-
- /* now enable IR if it was set before the handshake completed */
- if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
+ wm->handshake_state++;
+
+ /* now enable IR if it was set before the handshake completed */
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1);
- }
+ }
break;
- }
+ }
default:
{
break;
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io_win.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io_win.c
index 17fac360d3..85ddd109cd 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io_win.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/io_win.c
@@ -32,14 +32,14 @@
*/
#ifdef WIN32
-
+
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <hidsdi.h>
#include <setupapi.h>
-
+
#include "definitions.h"
#include "wiiuse_internal.h"
#include "io.h"
@@ -176,8 +176,8 @@ int wiiuse_io_read(struct wiimote_t* wm) {
if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) {
/* partial read */
- b = GetLastError();
-
+ b = GetLastError();
+
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) {
/* remote disconnect */
wiiuse_disconnected(wm);
@@ -186,11 +186,11 @@ int wiiuse_io_read(struct wiimote_t* wm) {
r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout);
if (r == WAIT_TIMEOUT) {
- /* timeout - cancel and continue */
-
- if (*wm->event_buf)
- WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
-
+ /* timeout - cancel and continue */
+
+ if (*wm->event_buf)
+ WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
+
CancelIo(wm->dev_handle);
ResetEvent(wm->hid_overlap.hEvent);
return 0;
@@ -203,25 +203,25 @@ int wiiuse_io_read(struct wiimote_t* wm) {
return 0;
}
- ResetEvent(wm->hid_overlap.hEvent);
+ ResetEvent(wm->hid_overlap.hEvent);
return 1;
}
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
DWORD bytes;
- int i;
-
+ int i;
+
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
- return 0;
-
+ return 0;
+
switch (wm->stack) {
case WIIUSE_STACK_UNKNOWN:
{
/* try to auto-detect the stack type */
if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) {
/* bluesoleil will always return 1 here, even if it's not connected */
- wm->stack = WIIUSE_STACK_BLUESOLEIL;
+ wm->stack = WIIUSE_STACK_BLUESOLEIL;
return i;
}
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsp b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsp
index dd66ae7078..d51562a704 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsp
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsp
@@ -1,191 +1,191 @@
-# Microsoft Developer Studio Project File - Name="wiiuse" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=wiiuse - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "wiiuse.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "wiiuse.mak" CFG="wiiuse - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "wiiuse - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "wiiuse - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "wiiuse - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib hid.lib setupapi.lib /nologo /dll /machine:I386
-
-!ELSEIF "$(CFG)" == "wiiuse - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /D "WITH_WIIUSE_DEBUG" /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib hid.lib setupapi.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "wiiuse - Win32 Release"
-# Name "wiiuse - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\classic.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\dynamics.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\events.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\guitar_hero_3.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\io.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\io_nix.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\io_win.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\ir.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\nunchuk.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\wiiuse.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\classic.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\definitions.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\dynamics.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\events.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\guitar_hero_3.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\io.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\ir.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\nunchuk.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\os.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\wiiuse.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\wiiuse_internal.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# Begin Source File
-
-SOURCE=..\..\CHANGELOG
-# End Source File
-# End Group
-# End Target
-# End Project
+# Microsoft Developer Studio Project File - Name="wiiuse" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=wiiuse - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "wiiuse.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "wiiuse.mak" CFG="wiiuse - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "wiiuse - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "wiiuse - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "wiiuse - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib hid.lib setupapi.lib /nologo /dll /machine:I386
+
+!ELSEIF "$(CFG)" == "wiiuse - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIIUSE_EXPORTS" /D "WITH_WIIUSE_DEBUG" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib hid.lib setupapi.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "wiiuse - Win32 Release"
+# Name "wiiuse - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\classic.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\dynamics.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\events.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\guitar_hero_3.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\io.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\io_nix.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\io_win.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\ir.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\nunchuk.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\wiiuse.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\classic.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\definitions.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\dynamics.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\events.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\guitar_hero_3.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\io.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\ir.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\nunchuk.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\os.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\wiiuse.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\wiiuse_internal.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=..\..\CHANGELOG
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsw b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsw
index 5d662bf0ea..198322544e 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsw
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/msvc/wiiuse.dsw
@@ -1,29 +1,29 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "wiiuse"=".\wiiuse.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "wiiuse"=".\wiiuse.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/nunchuk.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/nunchuk.c
index 48dbe6a089..fd763bcb9b 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/nunchuk.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/nunchuk.c
@@ -53,9 +53,9 @@ static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
* @return Returns 1 if handshake was successful, 0 if not.
*/
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) {
- int i;
- int offset = 0;
-
+ int i;
+ int offset = 0;
+
nc->btns = 0;
nc->btns_held = 0;
nc->btns_released = 0;
@@ -66,29 +66,29 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
/* decrypt data */
for (i = 0; i < len; ++i)
- data[i] = (data[i] ^ 0x17) + 0x17;
-
- if (data[offset] == 0xFF) {
- /*
- * Sometimes the data returned here is not correct.
- * This might happen because the wiimote is lagging
- * behind our initialization sequence.
- * To fix this just request the handshake again.
- *
- * Other times it's just the first 16 bytes are 0xFF,
- * but since the next 16 bytes are the same, just use
- * those.
- */
- if (data[offset + 16] == 0xFF) {
- /* get the calibration data */
- byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
-
- WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again.");
- wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
-
- return 0;
- } else
- offset += 16;
+ data[i] = (data[i] ^ 0x17) + 0x17;
+
+ if (data[offset] == 0xFF) {
+ /*
+ * Sometimes the data returned here is not correct.
+ * This might happen because the wiimote is lagging
+ * behind our initialization sequence.
+ * To fix this just request the handshake again.
+ *
+ * Other times it's just the first 16 bytes are 0xFF,
+ * but since the next 16 bytes are the same, just use
+ * those.
+ */
+ if (data[offset + 16] == 0xFF) {
+ /* get the calibration data */
+ byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
+
+ WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again.");
+ wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
+
+ return 0;
+ } else
+ offset += 16;
}
nc->accel_calib.cal_zero.x = data[offset + 0];
@@ -103,16 +103,16 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
nc->js.max.y = data[offset + 11];
nc->js.min.y = data[offset + 12];
nc->js.center.y = data[offset + 13];
-
+
/* default the thresholds to the same as the wiimote */
nc->orient_threshold = wm->orient_threshold;
nc->accel_threshold = wm->accel_threshold;
- /* handshake done */
- wm->exp.type = EXP_NUNCHUK;
-
- #ifdef WIN32
- wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
+ /* handshake done */
+ wm->exp.type = EXP_NUNCHUK;
+
+ #ifdef WIN32
+ wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif
return 1;
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/os.h b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/os.h
index 53b80f557c..79d4ce6edf 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/os.h
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/os.h
@@ -39,14 +39,14 @@
#ifndef OS_H_INCLUDED
#define OS_H_INCLUDED
-#ifdef WIN32
+#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 */
- #pragma warning(disable:4273) /* inconsistent dll linkage */
+ /* disable warnings I don't care about */
+ #pragma warning(disable:4244) /* possible loss of data conversion */
+ #pragma warning(disable:4273) /* inconsistent dll linkage */
#pragma warning(disable:4217)
#else
/* nix */
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.c b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.c
index 8d4b763864..cdd31a68fb 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.c
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.c
@@ -1,390 +1,390 @@
-/*
- * 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 General wiimote operations.
- *
- * The file includes functions that handle general
- * tasks. Most of these are functions that are part
- * of the API.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifndef WIN32
- #include <unistd.h>
-#else
- #include <Winsock2.h>
-#endif
-
-#include "definitions.h"
-#include "wiiuse_internal.h"
-#include "events.h"
-#include "io.h"
-
-static int g_banner = 0;
-
-/**
- * @breif Returns the version of the library.
- */
-const char* wiiuse_version() {
- return WIIUSE_VERSION;
-}
-
-
-/**
- * @brief Clean up wiimote_t array created by wiiuse_init()
- */
-void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) {
- int i = 0;
-
- if (!wm)
- return;
-
- WIIUSE_INFO("wiiuse clean up...");
-
- for (; i < wiimotes; ++i) {
- wiiuse_disconnect(wm[i]);
- free(wm[i]);
- }
-
- free(wm);
-
- return;
-}
-
-
-/**
- * @brief Initialize an array of wiimote structures.
- *
- * @param wiimotes Number of wiimote_t structures to create.
- *
- * @return An array of initialized wiimote_t structures.
- *
- * @see wiiuse_connect()
- *
- * The array returned by this function can be passed to various
- * functions, including wiiuse_connect().
- */
-struct wiimote_t** wiiuse_init(int wiimotes) {
- int i = 0;
- struct wiimote_t** wm = NULL;
-
- /*
- * Please do not remove this banner.
- * GPL asks that you please leave output credits intact.
- * Thank you.
- *
- * This banner is only displayed once so that if you need
- * to call this function again it won't be intrusive.
- */
- if (!g_banner) {
- printf( "wiiuse v" WIIUSE_VERSION " loaded.\n"
- " By: Michael Laforest <thepara[at]gmail{dot}com>\n"
- " http://wiiuse.net http://wiiuse.sf.net\n");
- g_banner = 1;
- }
-
- if (!wiimotes)
- return NULL;
-
- wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
-
- for (i = 0; i < wiimotes; ++i) {
- wm[i] = malloc(sizeof(struct wiimote_t));
- memset(wm[i], 0, sizeof(struct wiimote_t));
-
- wm[i]->unid = i+1;
-
- #ifndef WIN32
- wm[i]->bdaddr = *BDADDR_ANY;
- wm[i]->out_sock = -1;
- wm[i]->in_sock = -1;
- #else
- wm[i]->dev_handle = 0;
- wm[i]->stack = WIIUSE_STACK_UNKNOWN;
- wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
- wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
- wm[i]->timeout = wm[i]->normal_timeout;
- #endif
-
- wm[i]->state = WIIMOTE_INIT_STATES;
- wm[i]->flags = WIIUSE_INIT_FLAGS;
-
- wm[i]->event = WIIUSE_NONE;
-
- wm[i]->exp.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;
-}
-
-
-/**
- * @brief The wiimote disconnected.
- *
- * @param wm Pointer to a wiimote_t structure.
- */
-void wiiuse_disconnected(struct wiimote_t* wm) {
- if (!wm) return;
-
- WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid);
-
- /* disable the connected flag */
- WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
-
- /* reset a bunch of stuff */
- #ifndef WIN32
- wm->out_sock = -1;
- wm->in_sock = -1;
- #else
- wm->dev_handle = 0;
- #endif
-
- 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));
-
- wm->event = WIIUSE_DISCONNECT;
-}
-
-
-/**
- * @brief Enable or disable the rumble.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param status 1 to enable, 0 to disable.
- */
-void wiiuse_rumble(struct wiimote_t* wm, int status) {
- byte buf;
-
- if (!wm || !WIIMOTE_IS_CONNECTED(wm))
- return;
-
- /* make sure to keep the current lit leds */
- buf = wm->leds;
-
- if (status) {
- WIIUSE_DEBUG("Starting rumble...");
- WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
- buf |= 0x01;
- } else {
- WIIUSE_DEBUG("Stopping rumble...");
- WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
- }
-
- /* preserve IR state */
- if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
- buf |= 0x04;
-
- wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1);
-}
-
-
-/**
- * @brief Toggle the state of the rumble.
- *
- * @param wm Pointer to a wiimote_t structure.
- */
-void wiiuse_toggle_rumble(struct wiimote_t* wm) {
- if (!wm) return;
-
- wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE));
-}
-
-
-/**
- * @brief Set the enabled LEDs.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param leds What LEDs to enable.
- *
- * \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4.
- */
-void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
- byte buf;
-
- if (!wm || !WIIMOTE_IS_CONNECTED(wm))
- return;
-
- /* remove the lower 4 bits because they control rumble */
- wm->leds = (leds & 0xF0);
-
- /* make sure if the rumble is on that we keep it on */
- if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
- wm->leds |= 0x01;
-
- buf = wm->leds;
-
- wiiuse_send(wm, WM_CMD_LED, &buf, 1);
-}
-
-
-/**
- * @brief Set if the wiimote should report motion sensing.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param status 1 to enable, 0 to disable.
- *
- * Since reporting motion sensing sends a lot of data,
- * the wiimote saves power by not transmitting it
- * by default.
- */
-void wiiuse_motion_sensing(struct wiimote_t* wm, int status) {
- if (status)
- WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC);
- else
- WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
-
- wiiuse_set_report_type(wm);
-}
-
-
-/**
- * @brief Set the report type based on the current wiimote state.
- *
- * @param wm Pointer to a wiimote_t structure.
- *
- * @return The report type sent.
- *
- * The wiimote reports formatted packets depending on the
- * report type that was last requested. This function will
- * update the type of report that should be sent based on
- * the current state of the device.
- */
-int wiiuse_set_report_type(struct wiimote_t* wm) {
- byte buf[2];
- int motion, exp, ir;
-
- if (!wm || !WIIMOTE_IS_CONNECTED(wm))
- return 0;
-
- buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */
- buf[1] = 0x00;
-
- /* if rumble is enabled, make sure we keep it */
- if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
- buf[0] |= 0x01;
-
- motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC);
- exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
- ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
-
- if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP;
- else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP;
- else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR;
- else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP;
- else if (ir) buf[1] = WM_RPT_BTN_ACC_IR;
- else if (exp) buf[1] = WM_RPT_BTN_EXP;
- else if (motion) buf[1] = WM_RPT_BTN_ACC;
- else buf[1] = WM_RPT_BTN;
-
- WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
-
- exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2);
- if (exp <= 0)
- return exp;
-
- return buf[1];
-}
-
-
-/**
- * @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;
+/*
+ * 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 General wiimote operations.
+ *
+ * The file includes functions that handle general
+ * tasks. Most of these are functions that are part
+ * of the API.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef WIN32
+ #include <unistd.h>
+#else
+ #include <Winsock2.h>
+#endif
+
+#include "definitions.h"
+#include "wiiuse_internal.h"
+#include "events.h"
+#include "io.h"
+
+static int g_banner = 0;
+
+/**
+ * @breif Returns the version of the library.
+ */
+const char* wiiuse_version() {
+ return WIIUSE_VERSION;
+}
+
+
+/**
+ * @brief Clean up wiimote_t array created by wiiuse_init()
+ */
+void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) {
+ int i = 0;
+
+ if (!wm)
+ return;
+
+ WIIUSE_INFO("wiiuse clean up...");
+
+ for (; i < wiimotes; ++i) {
+ wiiuse_disconnect(wm[i]);
+ free(wm[i]);
+ }
+
+ free(wm);
+
+ return;
+}
+
+
+/**
+ * @brief Initialize an array of wiimote structures.
+ *
+ * @param wiimotes Number of wiimote_t structures to create.
+ *
+ * @return An array of initialized wiimote_t structures.
+ *
+ * @see wiiuse_connect()
+ *
+ * The array returned by this function can be passed to various
+ * functions, including wiiuse_connect().
+ */
+struct wiimote_t** wiiuse_init(int wiimotes) {
+ int i = 0;
+ struct wiimote_t** wm = NULL;
+
+ /*
+ * Please do not remove this banner.
+ * GPL asks that you please leave output credits intact.
+ * Thank you.
+ *
+ * This banner is only displayed once so that if you need
+ * to call this function again it won't be intrusive.
+ */
+ if (!g_banner) {
+ printf( "wiiuse v" WIIUSE_VERSION " loaded.\n"
+ " By: Michael Laforest <thepara[at]gmail{dot}com>\n"
+ " http://wiiuse.net http://wiiuse.sf.net\n");
+ g_banner = 1;
+ }
+
+ if (!wiimotes)
+ return NULL;
+
+ wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
+
+ for (i = 0; i < wiimotes; ++i) {
+ wm[i] = malloc(sizeof(struct wiimote_t));
+ memset(wm[i], 0, sizeof(struct wiimote_t));
+
+ wm[i]->unid = i+1;
+
+ #ifndef WIN32
+ wm[i]->bdaddr = *BDADDR_ANY;
+ wm[i]->out_sock = -1;
+ wm[i]->in_sock = -1;
+ #else
+ wm[i]->dev_handle = 0;
+ wm[i]->stack = WIIUSE_STACK_UNKNOWN;
+ wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
+ wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
+ wm[i]->timeout = wm[i]->normal_timeout;
+ #endif
+
+ wm[i]->state = WIIMOTE_INIT_STATES;
+ wm[i]->flags = WIIUSE_INIT_FLAGS;
+
+ wm[i]->event = WIIUSE_NONE;
+
+ wm[i]->exp.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;
+}
+
+
+/**
+ * @brief The wiimote disconnected.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ */
+void wiiuse_disconnected(struct wiimote_t* wm) {
+ if (!wm) return;
+
+ WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid);
+
+ /* disable the connected flag */
+ WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
+
+ /* reset a bunch of stuff */
+ #ifndef WIN32
+ wm->out_sock = -1;
+ wm->in_sock = -1;
+ #else
+ wm->dev_handle = 0;
+ #endif
+
+ 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));
+
+ wm->event = WIIUSE_DISCONNECT;
+}
+
+
+/**
+ * @brief Enable or disable the rumble.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param status 1 to enable, 0 to disable.
+ */
+void wiiuse_rumble(struct wiimote_t* wm, int status) {
+ byte buf;
+
+ if (!wm || !WIIMOTE_IS_CONNECTED(wm))
+ return;
+
+ /* make sure to keep the current lit leds */
+ buf = wm->leds;
+
+ if (status) {
+ WIIUSE_DEBUG("Starting rumble...");
+ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
+ buf |= 0x01;
+ } else {
+ WIIUSE_DEBUG("Stopping rumble...");
+ WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
+ }
+
+ /* preserve IR state */
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
+ buf |= 0x04;
+
+ wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1);
+}
+
+
+/**
+ * @brief Toggle the state of the rumble.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ */
+void wiiuse_toggle_rumble(struct wiimote_t* wm) {
+ if (!wm) return;
+
+ wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE));
+}
+
+
+/**
+ * @brief Set the enabled LEDs.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param leds What LEDs to enable.
+ *
+ * \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4.
+ */
+void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
+ byte buf;
+
+ if (!wm || !WIIMOTE_IS_CONNECTED(wm))
+ return;
+
+ /* remove the lower 4 bits because they control rumble */
+ wm->leds = (leds & 0xF0);
+
+ /* make sure if the rumble is on that we keep it on */
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
+ wm->leds |= 0x01;
+
+ buf = wm->leds;
+
+ wiiuse_send(wm, WM_CMD_LED, &buf, 1);
+}
+
+
+/**
+ * @brief Set if the wiimote should report motion sensing.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param status 1 to enable, 0 to disable.
+ *
+ * Since reporting motion sensing sends a lot of data,
+ * the wiimote saves power by not transmitting it
+ * by default.
+ */
+void wiiuse_motion_sensing(struct wiimote_t* wm, int status) {
+ if (status)
+ WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC);
+ else
+ WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
+
+ wiiuse_set_report_type(wm);
+}
+
+
+/**
+ * @brief Set the report type based on the current wiimote state.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ *
+ * @return The report type sent.
+ *
+ * The wiimote reports formatted packets depending on the
+ * report type that was last requested. This function will
+ * update the type of report that should be sent based on
+ * the current state of the device.
+ */
+int wiiuse_set_report_type(struct wiimote_t* wm) {
+ byte buf[2];
+ int motion, exp, ir;
+
+ if (!wm || !WIIMOTE_IS_CONNECTED(wm))
+ return 0;
+
+ buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */
+ buf[1] = 0x00;
+
+ /* if rumble is enabled, make sure we keep it */
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
+ buf[0] |= 0x01;
+
+ motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC);
+ exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
+ ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
+
+ if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP;
+ else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP;
+ else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR;
+ else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP;
+ else if (ir) buf[1] = WM_RPT_BTN_ACC_IR;
+ else if (exp) buf[1] = WM_RPT_BTN_EXP;
+ else if (motion) buf[1] = WM_RPT_BTN_ACC;
+ else buf[1] = WM_RPT_BTN;
+
+ WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
+
+ exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2);
+ if (exp <= 0)
+ return exp;
+
+ return buf[1];
+}
+
+
+/**
+ * @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;
-}
-
-
+ 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 Read data from the wiimote (event version).
*
@@ -440,325 +440,325 @@ int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int addr, unsi
}
-/**
- * @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;
-
+/**
+ * @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 Request the wiimote controller status.
- *
- * @param wm Pointer to a wiimote_t structure.
- *
- * Controller status includes: battery level, LED status, expansions
- */
-void wiiuse_status(struct wiimote_t* wm) {
- byte buf = 0;
-
- if (!wm || !WIIMOTE_IS_CONNECTED(wm))
- return;
-
- WIIUSE_DEBUG("Requested wiimote status.");
-
- wiiuse_send(wm, WM_CMD_CTRL_STATUS, &buf, 1);
-}
-
-
-/**
- * @brief Find a wiimote_t structure by its unique identifier.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param wiimotes The number of wiimote_t structures in \a wm.
- * @param unid The unique identifier to search for.
- *
- * @return Pointer to a wiimote_t structure, or NULL if not found.
- */
-struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) {
- int i = 0;
-
- for (; i < wiimotes; ++i) {
- if (wm[i]->unid == unid)
- return wm[i];
- }
-
- return NULL;
-}
-
-
-/**
- * @brief Write data to the wiimote.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param addr The address to write to.
- * @param data The data to be written to the memory location.
- * @param len The length of the block to be written.
- */
-int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len) {
- byte buf[21] = {0}; /* the payload is always 23 */
-
- if (!wm || !WIIMOTE_IS_CONNECTED(wm))
- return 0;
- if (!data || !len)
- return 0;
-
- WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr);
-
- #ifdef WITH_WIIUSE_DEBUG
- {
- int i = 0;
- printf("Write data is: ");
- for (; i < len; ++i)
- printf("%x ", data[i]);
- printf("\n");
- }
- #endif
-
- /* the offset is in big endian */
- *(int*)(buf) = BIG_ENDIAN_LONG(addr);
-
- /* length */
- *(byte*)(buf + 4) = len;
-
- /* data */
- memcpy(buf + 5, data, len);
-
- wiiuse_send(wm, WM_CMD_WRITE_DATA, buf, 21);
- return 1;
-}
-
-
-/**
- * @brief Send a packet to the wiimote.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h
- * @param msg The payload.
- * @param len Length of the payload in bytes.
- *
- * This function should replace any write()s directly to the wiimote device.
- */
-int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
- byte buf[32]; /* no payload is better than this */
- int rumble = 0;
-
- #ifndef WIN32
- buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
- buf[1] = report_type;
- #else
- buf[0] = report_type;
- #endif
-
- switch (report_type) {
- case WM_CMD_LED:
- case WM_CMD_RUMBLE:
- case WM_CMD_CTRL_STATUS:
- {
- /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
- if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
- rumble = 1;
- break;
- }
- default:
- break;
- }
-
- #ifndef WIN32
- memcpy(buf+2, msg, len);
- if (rumble)
- buf[2] |= 0x01;
- #else
- memcpy(buf+1, msg, len);
- if (rumble)
- buf[1] |= 0x01;
- #endif
-
- #ifdef WITH_WIIUSE_DEBUG
- {
- int x = 2;
- printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
- #ifndef WIN32
- for (; x < len+2; ++x)
- #else
- for (; x < len+1; ++x)
- #endif
- printf("%.2x ", buf[x]);
- printf("\n");
- }
- #endif
-
- #ifndef WIN32
- return wiiuse_io_write(wm, buf, len+2);
- #else
- return wiiuse_io_write(wm, buf, len+1);
- #endif
-}
-
-
-/**
- * @brief Set flags for the specified wiimote.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param enable Flags to enable.
- * @param disable Flags to disable.
- *
- * @return The flags set after 'enable' and 'disable' have been applied.
- *
- * The values 'enable' and 'disable' may be any flags OR'ed together.
- * Flags are defined in wiiuse.h.
- */
-int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
- if (!wm) return 0;
-
- /* remove mutually exclusive flags */
- enable &= ~disable;
- disable &= ~enable;
-
- wm->flags |= enable;
- wm->flags &= ~disable;
-
- return wm->flags;
-}
-
-
-/**
- * @brief Set the wiimote smoothing alpha value.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param alpha The alpha value to set. Between 0 and 1.
- *
- * @return Returns the old alpha value.
- *
- * The alpha value is between 0 and 1 and is used in an exponential
- * smoothing algorithm.
- *
- * Smoothing is only performed if the WIIMOTE_USE_SMOOTHING is set.
- */
-float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
- float old;
-
- if (!wm) return 0.0f;
-
- old = wm->accel_calib.st_alpha;
-
- wm->accel_calib.st_alpha = alpha;
-
- /* if there is a nunchuk set that too */
- if (wm->exp.type == EXP_NUNCHUK)
- wm->exp.nunchuk.accel_calib.st_alpha = alpha;
-
- return old;
-}
-
-
-/**
- * @brief Set the bluetooth stack type to use.
- *
- * @param wm Array of wiimote_t structures.
- * @param wiimotes Number of objects in the wm array.
- * @param type The type of bluetooth stack to use.
- */
-void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type) {
- #ifdef WIN32
- int i;
-
- if (!wm) return;
-
- for (i = 0; i < wiimotes; ++i)
- wm[i]->stack = type;
- #endif
-}
-
-
-/**
- * @brief Set the orientation event threshold.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param threshold The decimal place that should be considered a significant change.
- *
- * If threshold is 0.01, and any angle changes by 0.01 then a significant change
- * has occured and the event callback will be invoked. If threshold is 1 then
- * the angle has to change by a full degree to generate an event.
- */
-void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
- if (!wm) return;
-
- wm->orient_threshold = threshold;
-}
-
-
-/**
- * @brief Set the accelerometer event threshold.
- *
- * @param wm Pointer to a wiimote_t structure.
- * @param threshold The decimal place that should be considered a significant change.
- */
-void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
- if (!wm) return;
-
- wm->accel_threshold = threshold;
-}
-
-
-/**
- * @brief Try to resync with the wiimote by starting a new handshake.
- *
- * @param wm Pointer to a wiimote_t structure.
- */
-void wiiuse_resync(struct wiimote_t* wm) {
- if (!wm) return;
-
- wm->handshake_state = 0;
- wiiuse_handshake(wm, NULL, 0);
-}
-
-
-/**
- * @brief Set the normal and expansion handshake timeouts.
- *
- * @param wm Array of wiimote_t structures.
- * @param wiimotes Number of objects in the wm array.
- * @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) {
- #ifdef WIN32
- int i;
-
- if (!wm) return;
-
- for (i = 0; i < wiimotes; ++i) {
- wm[i]->normal_timeout = normal_timeout;
- wm[i]->exp_timeout = exp_timeout;
- }
- #endif
-}
+ 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 Request the wiimote controller status.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ *
+ * Controller status includes: battery level, LED status, expansions
+ */
+void wiiuse_status(struct wiimote_t* wm) {
+ byte buf = 0;
+
+ if (!wm || !WIIMOTE_IS_CONNECTED(wm))
+ return;
+
+ WIIUSE_DEBUG("Requested wiimote status.");
+
+ wiiuse_send(wm, WM_CMD_CTRL_STATUS, &buf, 1);
+}
+
+
+/**
+ * @brief Find a wiimote_t structure by its unique identifier.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param wiimotes The number of wiimote_t structures in \a wm.
+ * @param unid The unique identifier to search for.
+ *
+ * @return Pointer to a wiimote_t structure, or NULL if not found.
+ */
+struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) {
+ int i = 0;
+
+ for (; i < wiimotes; ++i) {
+ if (wm[i]->unid == unid)
+ return wm[i];
+ }
+
+ return NULL;
+}
+
+
+/**
+ * @brief Write data to the wiimote.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param addr The address to write to.
+ * @param data The data to be written to the memory location.
+ * @param len The length of the block to be written.
+ */
+int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len) {
+ byte buf[21] = {0}; /* the payload is always 23 */
+
+ if (!wm || !WIIMOTE_IS_CONNECTED(wm))
+ return 0;
+ if (!data || !len)
+ return 0;
+
+ WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr);
+
+ #ifdef WITH_WIIUSE_DEBUG
+ {
+ int i = 0;
+ printf("Write data is: ");
+ for (; i < len; ++i)
+ printf("%x ", data[i]);
+ printf("\n");
+ }
+ #endif
+
+ /* the offset is in big endian */
+ *(int*)(buf) = BIG_ENDIAN_LONG(addr);
+
+ /* length */
+ *(byte*)(buf + 4) = len;
+
+ /* data */
+ memcpy(buf + 5, data, len);
+
+ wiiuse_send(wm, WM_CMD_WRITE_DATA, buf, 21);
+ return 1;
+}
+
+
+/**
+ * @brief Send a packet to the wiimote.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h
+ * @param msg The payload.
+ * @param len Length of the payload in bytes.
+ *
+ * This function should replace any write()s directly to the wiimote device.
+ */
+int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
+ byte buf[32]; /* no payload is better than this */
+ int rumble = 0;
+
+ #ifndef WIN32
+ buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
+ buf[1] = report_type;
+ #else
+ buf[0] = report_type;
+ #endif
+
+ switch (report_type) {
+ case WM_CMD_LED:
+ case WM_CMD_RUMBLE:
+ case WM_CMD_CTRL_STATUS:
+ {
+ /* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
+ rumble = 1;
+ break;
+ }
+ default:
+ break;
+ }
+
+ #ifndef WIN32
+ memcpy(buf+2, msg, len);
+ if (rumble)
+ buf[2] |= 0x01;
+ #else
+ memcpy(buf+1, msg, len);
+ if (rumble)
+ buf[1] |= 0x01;
+ #endif
+
+ #ifdef WITH_WIIUSE_DEBUG
+ {
+ int x = 2;
+ printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
+ #ifndef WIN32
+ for (; x < len+2; ++x)
+ #else
+ for (; x < len+1; ++x)
+ #endif
+ printf("%.2x ", buf[x]);
+ printf("\n");
+ }
+ #endif
+
+ #ifndef WIN32
+ return wiiuse_io_write(wm, buf, len+2);
+ #else
+ return wiiuse_io_write(wm, buf, len+1);
+ #endif
+}
+
+
+/**
+ * @brief Set flags for the specified wiimote.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param enable Flags to enable.
+ * @param disable Flags to disable.
+ *
+ * @return The flags set after 'enable' and 'disable' have been applied.
+ *
+ * The values 'enable' and 'disable' may be any flags OR'ed together.
+ * Flags are defined in wiiuse.h.
+ */
+int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
+ if (!wm) return 0;
+
+ /* remove mutually exclusive flags */
+ enable &= ~disable;
+ disable &= ~enable;
+
+ wm->flags |= enable;
+ wm->flags &= ~disable;
+
+ return wm->flags;
+}
+
+
+/**
+ * @brief Set the wiimote smoothing alpha value.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param alpha The alpha value to set. Between 0 and 1.
+ *
+ * @return Returns the old alpha value.
+ *
+ * The alpha value is between 0 and 1 and is used in an exponential
+ * smoothing algorithm.
+ *
+ * Smoothing is only performed if the WIIMOTE_USE_SMOOTHING is set.
+ */
+float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
+ float old;
+
+ if (!wm) return 0.0f;
+
+ old = wm->accel_calib.st_alpha;
+
+ wm->accel_calib.st_alpha = alpha;
+
+ /* if there is a nunchuk set that too */
+ if (wm->exp.type == EXP_NUNCHUK)
+ wm->exp.nunchuk.accel_calib.st_alpha = alpha;
+
+ return old;
+}
+
+
+/**
+ * @brief Set the bluetooth stack type to use.
+ *
+ * @param wm Array of wiimote_t structures.
+ * @param wiimotes Number of objects in the wm array.
+ * @param type The type of bluetooth stack to use.
+ */
+void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type) {
+ #ifdef WIN32
+ int i;
+
+ if (!wm) return;
+
+ for (i = 0; i < wiimotes; ++i)
+ wm[i]->stack = type;
+ #endif
+}
+
+
+/**
+ * @brief Set the orientation event threshold.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param threshold The decimal place that should be considered a significant change.
+ *
+ * If threshold is 0.01, and any angle changes by 0.01 then a significant change
+ * has occured and the event callback will be invoked. If threshold is 1 then
+ * the angle has to change by a full degree to generate an event.
+ */
+void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
+ if (!wm) return;
+
+ wm->orient_threshold = threshold;
+}
+
+
+/**
+ * @brief Set the accelerometer event threshold.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ * @param threshold The decimal place that should be considered a significant change.
+ */
+void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
+ if (!wm) return;
+
+ wm->accel_threshold = threshold;
+}
+
+
+/**
+ * @brief Try to resync with the wiimote by starting a new handshake.
+ *
+ * @param wm Pointer to a wiimote_t structure.
+ */
+void wiiuse_resync(struct wiimote_t* wm) {
+ if (!wm) return;
+
+ wm->handshake_state = 0;
+ wiiuse_handshake(wm, NULL, 0);
+}
+
+
+/**
+ * @brief Set the normal and expansion handshake timeouts.
+ *
+ * @param wm Array of wiimote_t structures.
+ * @param wiimotes Number of objects in the wm array.
+ * @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) {
+ #ifdef WIN32
+ int i;
+
+ if (!wm) return;
+
+ for (i = 0; i < wiimotes; ++i) {
+ wm[i]->normal_timeout = normal_timeout;
+ wm[i]->exp_timeout = exp_timeout;
+ }
+ #endif
+}
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.h b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.h
index 9dff81c8e4..b84c35f2b6 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.h
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse.h
@@ -1,173 +1,173 @@
-/*
- * 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 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 <windows.h>
-#else
- /* nix */
- #include <bluetooth/bluetooth.h>
-#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.
- */
+/*
+ * 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 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 <windows.h>
+#else
+ /* nix */
+ #include <bluetooth/bluetooth.h>
+#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))
/**
@@ -185,469 +185,469 @@ typedef enum ir_position_t {
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 */
+
+#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 */
+ 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 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,
+ 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_CONNECT,
WIIUSE_DISCONNECT,
WIIUSE_UNEXPECTED_DISCONNECT,
WIIUSE_READ_DATA,
- WIIUSE_NUNCHUK_INSERTED,
+ 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 */
-
+} 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);
+ 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 */
-
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* WIIUSE_H_INCLUDED */
+
diff --git a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse_internal.h b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse_internal.h
index 1b2f423862..a7fe30a578 100644
--- a/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse_internal.h
+++ b/tools/EventClients/Clients/WiiRemote/wiiuse_v0.12/src/wiiuse_internal.h
@@ -153,8 +153,8 @@
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
#define EXP_ID_CODE_GUITAR 0x9A1EFDFB
-#define EXP_HANDSHAKE_LEN 224
-
+#define EXP_HANDSHAKE_LEN 224
+
/********************
*
* End Wiimote internal codes
@@ -205,10 +205,10 @@
#define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f
#define SMOOTH_ROLL 0x01
-#define SMOOTH_PITCH 0x02
-
+#define SMOOTH_PITCH 0x02
+
#include "wiiuse.h"
-
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.cpp b/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.cpp
index ded67759cc..42acd8c2f1 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.cpp
+++ b/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.cpp
@@ -1,172 +1,172 @@
-/*
- * Copyright (C) 2009-2010 Team XBMC
- *
- * 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 2 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "StdAfx.h"
-#include "Xbox360Controller.h"
-
-
-Xbox360Controller::Xbox360Controller(int num)
-{
- this->num = num;
- for (int i = 0; i < 14; i++)
- {
- button_down[i] = false;
- button_released[i] = false;
- button_pressed[i] = false;
- }
-}
-
-XINPUT_STATE Xbox360Controller::getState()
-{
- // Zeroise the state
- ZeroMemory(&state, sizeof(XINPUT_STATE));
-
- // Get the state
- XInputGetState(num, &state);
-
- return state;
-}
-
-void Xbox360Controller::updateButton(int num, int button)
-{
- if (state.Gamepad.wButtons & button)
- {
- if (!button_down[num])
- {
- button_pressed[num] = true;
- }
- button_down[num] = true;
- } else
- {
- if (button_down[num])
- {
- button_released[num] = true;
- }
- button_down[num] = false;
- }
-}
-
-bool Xbox360Controller::buttonPressed(int num)
-{
- return button_pressed[num];
-}
-
-bool Xbox360Controller::buttonReleased(int num)
-{
- return button_released[num];
-}
-
-void Xbox360Controller::updateState()
-{
- for (int i = 0; i < 14; i++)
- {
- button_released[i] = false;
- button_pressed[i] = false;
- }
- if (isConnected())
- {
- XINPUT_STATE s = getState();
- updateButton(0, XINPUT_GAMEPAD_A);
- updateButton(1, XINPUT_GAMEPAD_B);
- updateButton(2, XINPUT_GAMEPAD_X);
- updateButton(3, XINPUT_GAMEPAD_Y);
- updateButton(4, XINPUT_GAMEPAD_DPAD_UP);
- updateButton(5, XINPUT_GAMEPAD_DPAD_DOWN);
- updateButton(6, XINPUT_GAMEPAD_DPAD_LEFT);
- updateButton(7, XINPUT_GAMEPAD_DPAD_RIGHT);
- updateButton(8, XINPUT_GAMEPAD_START);
- updateButton(9, XINPUT_GAMEPAD_BACK);
- updateButton(10, XINPUT_GAMEPAD_LEFT_THUMB);
- updateButton(11, XINPUT_GAMEPAD_RIGHT_THUMB);
- updateButton(12, XINPUT_GAMEPAD_LEFT_SHOULDER);
- updateButton(13, XINPUT_GAMEPAD_RIGHT_SHOULDER);
- }
-}
-
-bool Xbox360Controller::isConnected()
-{
- // Zeroise the state
- ZeroMemory(&state, sizeof(XINPUT_STATE));
-
- // Get the state
- DWORD Result = XInputGetState(num, &state);
-
- if(Result == ERROR_SUCCESS)
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
-
-bool Xbox360Controller::triggerMoved(int num)
-{
- if (num == 0)
- return (state.Gamepad.bRightTrigger &&
- state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD);
- return (state.Gamepad.bLeftTrigger &&
- state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD);
-}
-
-BYTE Xbox360Controller::getTrigger(int num)
-{
- if (num == 0)
- return state.Gamepad.bRightTrigger;
- return state.Gamepad.bLeftTrigger;
-}
-
-bool Xbox360Controller::thumbMoved(int num)
-{
- switch(num)
- {
- case 0:
- return !(state.Gamepad.sThumbLX < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
- state.Gamepad.sThumbLX > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
- case 1:
- return !(state.Gamepad.sThumbLY < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
- state.Gamepad.sThumbLY > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
- case 2:
- return !(state.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
- state.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
- case 3:
- return !(state.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
- state.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
- }
-
- return false;
-}
-SHORT Xbox360Controller::getThumb(int num)
-{
- switch (num)
- {
- case 0:
- return state.Gamepad.sThumbLX;
- case 1:
- return state.Gamepad.sThumbLY;
- case 2:
- return state.Gamepad.sThumbRX;
- case 3:
- return state.Gamepad.sThumbRY;
- }
-
- return 0;
-}
-
+/*
+ * Copyright (C) 2009-2010 Team XBMC
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "StdAfx.h"
+#include "Xbox360Controller.h"
+
+
+Xbox360Controller::Xbox360Controller(int num)
+{
+ this->num = num;
+ for (int i = 0; i < 14; i++)
+ {
+ button_down[i] = false;
+ button_released[i] = false;
+ button_pressed[i] = false;
+ }
+}
+
+XINPUT_STATE Xbox360Controller::getState()
+{
+ // Zeroise the state
+ ZeroMemory(&state, sizeof(XINPUT_STATE));
+
+ // Get the state
+ XInputGetState(num, &state);
+
+ return state;
+}
+
+void Xbox360Controller::updateButton(int num, int button)
+{
+ if (state.Gamepad.wButtons & button)
+ {
+ if (!button_down[num])
+ {
+ button_pressed[num] = true;
+ }
+ button_down[num] = true;
+ } else
+ {
+ if (button_down[num])
+ {
+ button_released[num] = true;
+ }
+ button_down[num] = false;
+ }
+}
+
+bool Xbox360Controller::buttonPressed(int num)
+{
+ return button_pressed[num];
+}
+
+bool Xbox360Controller::buttonReleased(int num)
+{
+ return button_released[num];
+}
+
+void Xbox360Controller::updateState()
+{
+ for (int i = 0; i < 14; i++)
+ {
+ button_released[i] = false;
+ button_pressed[i] = false;
+ }
+ if (isConnected())
+ {
+ XINPUT_STATE s = getState();
+ updateButton(0, XINPUT_GAMEPAD_A);
+ updateButton(1, XINPUT_GAMEPAD_B);
+ updateButton(2, XINPUT_GAMEPAD_X);
+ updateButton(3, XINPUT_GAMEPAD_Y);
+ updateButton(4, XINPUT_GAMEPAD_DPAD_UP);
+ updateButton(5, XINPUT_GAMEPAD_DPAD_DOWN);
+ updateButton(6, XINPUT_GAMEPAD_DPAD_LEFT);
+ updateButton(7, XINPUT_GAMEPAD_DPAD_RIGHT);
+ updateButton(8, XINPUT_GAMEPAD_START);
+ updateButton(9, XINPUT_GAMEPAD_BACK);
+ updateButton(10, XINPUT_GAMEPAD_LEFT_THUMB);
+ updateButton(11, XINPUT_GAMEPAD_RIGHT_THUMB);
+ updateButton(12, XINPUT_GAMEPAD_LEFT_SHOULDER);
+ updateButton(13, XINPUT_GAMEPAD_RIGHT_SHOULDER);
+ }
+}
+
+bool Xbox360Controller::isConnected()
+{
+ // Zeroise the state
+ ZeroMemory(&state, sizeof(XINPUT_STATE));
+
+ // Get the state
+ DWORD Result = XInputGetState(num, &state);
+
+ if(Result == ERROR_SUCCESS)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+
+bool Xbox360Controller::triggerMoved(int num)
+{
+ if (num == 0)
+ return (state.Gamepad.bRightTrigger &&
+ state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD);
+ return (state.Gamepad.bLeftTrigger &&
+ state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD);
+}
+
+BYTE Xbox360Controller::getTrigger(int num)
+{
+ if (num == 0)
+ return state.Gamepad.bRightTrigger;
+ return state.Gamepad.bLeftTrigger;
+}
+
+bool Xbox360Controller::thumbMoved(int num)
+{
+ switch(num)
+ {
+ case 0:
+ return !(state.Gamepad.sThumbLX < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
+ state.Gamepad.sThumbLX > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
+ case 1:
+ return !(state.Gamepad.sThumbLY < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
+ state.Gamepad.sThumbLY > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE);
+ case 2:
+ return !(state.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
+ state.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
+ case 3:
+ return !(state.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
+ state.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);
+ }
+
+ return false;
+}
+SHORT Xbox360Controller::getThumb(int num)
+{
+ switch (num)
+ {
+ case 0:
+ return state.Gamepad.sThumbLX;
+ case 1:
+ return state.Gamepad.sThumbLY;
+ case 2:
+ return state.Gamepad.sThumbRX;
+ case 3:
+ return state.Gamepad.sThumbRY;
+ }
+
+ return 0;
+}
+
diff --git a/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.h b/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.h
index a56c7922f2..450f7a00e2 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.h
+++ b/tools/EventClients/Clients/Xbox360 Controller/Xbox360Controller.h
@@ -1,46 +1,46 @@
-#pragma once
-/*
- * Copyright (C) 2009-2010 Team XBMC
- *
- * 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 2 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <windows.h>
-#include <XInput.h> // Defines XBOX controller API
-#pragma comment(lib, "XInput.lib") // Library containing necessary 360
- // functions
-
-class Xbox360Controller
-{
-private:
- XINPUT_STATE state;
- int num;
- bool button_down[14];
- bool button_pressed[14];
- bool button_released[14];
-
- XINPUT_STATE getState();
- void updateButton(int num, int button);
-public:
- Xbox360Controller(int num);
- void updateState();
- bool isConnected();
- bool buttonPressed(int num);
- bool buttonReleased(int num);
- bool thumbMoved(int num);
- SHORT getThumb(int num);
- bool triggerMoved(int num);
- BYTE getTrigger(int num);
-};
+#pragma once
+/*
+ * Copyright (C) 2009-2010 Team XBMC
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <windows.h>
+#include <XInput.h> // Defines XBOX controller API
+#pragma comment(lib, "XInput.lib") // Library containing necessary 360
+ // functions
+
+class Xbox360Controller
+{
+private:
+ XINPUT_STATE state;
+ int num;
+ bool button_down[14];
+ bool button_pressed[14];
+ bool button_released[14];
+
+ XINPUT_STATE getState();
+ void updateButton(int num, int button);
+public:
+ Xbox360Controller(int num);
+ void updateState();
+ bool isConnected();
+ bool buttonPressed(int num);
+ bool buttonReleased(int num);
+ bool thumbMoved(int num);
+ SHORT getThumb(int num);
+ bool triggerMoved(int num);
+ BYTE getTrigger(int num);
+};
diff --git a/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.cpp b/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.cpp
index f5da789c58..13f1d7afca 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.cpp
+++ b/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.cpp
@@ -1,159 +1,159 @@
-/*
- * Copyright (C) 2009-2010 Team XBMC
- *
- * 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 2 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-// Xbox360EventClient.cpp : Defines the entry point for the console application.
-//
-
-#include "stdafx.h"
-#include "Xbox360Controller.h"
-#include "../../lib/c++/xbmcclient.h"
-#pragma comment(lib, "wsock32.lib") // needed for xmbclient.h?
-
-// You can have up to 4 xbox360 controllers on a system
-#define MAX_NUM_CONTROLLERS 4
-
-// global variable :(
-// needed for exit event handler
-CXBMCClient *client;
-
-BOOL exitHandler( DWORD ctrlType )
-{
- // TODO: Send BYE Packet
- delete client;
-
- WSACleanup();
-
- return FALSE;
-}
-
-void checkTrigger(Xbox360Controller &cont, CXBMCClient *client, int num, const char* name)
-{
- if (cont.triggerMoved(num))
- {
- client->SendButton(name, "XG", 0x20, cont.getTrigger(num) * 128);
- }
-}
-
-void checkThumb(Xbox360Controller &cont, CXBMCClient *client, int num,
- const char* leftname, const char* rightname)
-{
- if (cont.thumbMoved(num))
- {
- if (cont.getThumb(num) < 0)
- {
- client->SendButton(leftname, "XG", 0x20, -cont.getThumb(num));
- }
- else
- {
- client->SendButton(rightname, "XG", 0x20, cont.getThumb(num));
- }
- }
-}
-
-void checkButton(Xbox360Controller &cont, CXBMCClient *client, int num, const char* name)
-{
- if (cont.buttonPressed(num))
- {
- client->SendButton(name, "XG", 0x02);
- }
- else if (cont.buttonReleased(num))
- {
- client->SendButton(name, "XG", 0x04);
- }
-}
-
-void checkAll(Xbox360Controller &cont)
-{
- if (cont.isConnected())
- {
- cont.updateState();
- checkButton(cont, client, 0, "a");
- checkButton(cont, client, 1, "b");
- checkButton(cont, client, 2, "x");
- checkButton(cont, client, 3, "y");
- checkButton(cont, client, 4, "dpadup");
- checkButton(cont, client, 5, "dpaddown");
- checkButton(cont, client, 6, "dpadleft");
- checkButton(cont, client, 7, "dpadright");
- checkButton(cont, client, 8, "start");
- checkButton(cont, client, 9, "back");
- checkButton(cont, client, 10, "leftthumbbutton");
- checkButton(cont, client, 11, "rightthumbbutton");
- checkButton(cont, client, 12, "white");
- checkButton(cont, client, 13, "black");
- checkTrigger(cont, client, 0, "rightanalogtrigger");
- checkTrigger(cont, client, 1, "leftanalogtrigger");
- checkThumb(cont, client, 0, "leftthumbstickleft", "leftthumbstickright");
- checkThumb(cont, client, 1, "leftthumbstickdown", "leftthumbstickup");
- checkThumb(cont, client, 2, "rightthumbstickleft", "rightthumbstickright");
- checkThumb(cont, client, 3, "rightthumbstickdown", "rightthumbstickup");
- }
-}
-
-int main(int argc, char* argv[])
-{
- char *host = "localhost";
- char *port = "9777";
- Xbox360Controller *controllers[MAX_NUM_CONTROLLERS];
- int i;
-
- // Get access to all potential controllers
- for ( i = 0; i < MAX_NUM_CONTROLLERS; i++)
- {
- controllers[i] = new Xbox360Controller(i);
- }
-
- // Start Winsock stuff
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2, 2), &wsaData);
-
- if ( argc > 3 )
- {
- printf("USAGE: %s [HOST [PORT]]\n\nThe event client connects to the XBMC EventServer at HOST:PORT.\
- Default value for HOST is localhost, default value for port is 9777.\n", argv[0]);
- return -1;
- }
-
- if ( argc > 1 )
- {
- host = argv[1];
- }
-
- if ( argc > 2 )
- {
- port = argv[2];
- }
-
- client = new CXBMCClient(host, atoi(port));
-
- SetConsoleCtrlHandler( (PHANDLER_ROUTINE) exitHandler, TRUE);
-
- client->SendHELO("Xbox 360 Controller", 0);
-
- while(true)
- {
- // Check each controller for activity
- for ( i = 0; i < MAX_NUM_CONTROLLERS; i++ )
- {
- checkAll(*controllers[i]);
- }
- Sleep(10);
- }
-
- return 0;
-}
+/*
+ * Copyright (C) 2009-2010 Team XBMC
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// Xbox360EventClient.cpp : Defines the entry point for the console application.
+//
+
+#include "stdafx.h"
+#include "Xbox360Controller.h"
+#include "../../lib/c++/xbmcclient.h"
+#pragma comment(lib, "wsock32.lib") // needed for xmbclient.h?
+
+// You can have up to 4 xbox360 controllers on a system
+#define MAX_NUM_CONTROLLERS 4
+
+// global variable :(
+// needed for exit event handler
+CXBMCClient *client;
+
+BOOL exitHandler( DWORD ctrlType )
+{
+ // TODO: Send BYE Packet
+ delete client;
+
+ WSACleanup();
+
+ return FALSE;
+}
+
+void checkTrigger(Xbox360Controller &cont, CXBMCClient *client, int num, const char* name)
+{
+ if (cont.triggerMoved(num))
+ {
+ client->SendButton(name, "XG", 0x20, cont.getTrigger(num) * 128);
+ }
+}
+
+void checkThumb(Xbox360Controller &cont, CXBMCClient *client, int num,
+ const char* leftname, const char* rightname)
+{
+ if (cont.thumbMoved(num))
+ {
+ if (cont.getThumb(num) < 0)
+ {
+ client->SendButton(leftname, "XG", 0x20, -cont.getThumb(num));
+ }
+ else
+ {
+ client->SendButton(rightname, "XG", 0x20, cont.getThumb(num));
+ }
+ }
+}
+
+void checkButton(Xbox360Controller &cont, CXBMCClient *client, int num, const char* name)
+{
+ if (cont.buttonPressed(num))
+ {
+ client->SendButton(name, "XG", 0x02);
+ }
+ else if (cont.buttonReleased(num))
+ {
+ client->SendButton(name, "XG", 0x04);
+ }
+}
+
+void checkAll(Xbox360Controller &cont)
+{
+ if (cont.isConnected())
+ {
+ cont.updateState();
+ checkButton(cont, client, 0, "a");
+ checkButton(cont, client, 1, "b");
+ checkButton(cont, client, 2, "x");
+ checkButton(cont, client, 3, "y");
+ checkButton(cont, client, 4, "dpadup");
+ checkButton(cont, client, 5, "dpaddown");
+ checkButton(cont, client, 6, "dpadleft");
+ checkButton(cont, client, 7, "dpadright");
+ checkButton(cont, client, 8, "start");
+ checkButton(cont, client, 9, "back");
+ checkButton(cont, client, 10, "leftthumbbutton");
+ checkButton(cont, client, 11, "rightthumbbutton");
+ checkButton(cont, client, 12, "white");
+ checkButton(cont, client, 13, "black");
+ checkTrigger(cont, client, 0, "rightanalogtrigger");
+ checkTrigger(cont, client, 1, "leftanalogtrigger");
+ checkThumb(cont, client, 0, "leftthumbstickleft", "leftthumbstickright");
+ checkThumb(cont, client, 1, "leftthumbstickdown", "leftthumbstickup");
+ checkThumb(cont, client, 2, "rightthumbstickleft", "rightthumbstickright");
+ checkThumb(cont, client, 3, "rightthumbstickdown", "rightthumbstickup");
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ char *host = "localhost";
+ char *port = "9777";
+ Xbox360Controller *controllers[MAX_NUM_CONTROLLERS];
+ int i;
+
+ // Get access to all potential controllers
+ for ( i = 0; i < MAX_NUM_CONTROLLERS; i++)
+ {
+ controllers[i] = new Xbox360Controller(i);
+ }
+
+ // Start Winsock stuff
+ WSADATA wsaData;
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
+
+ if ( argc > 3 )
+ {
+ printf("USAGE: %s [HOST [PORT]]\n\nThe event client connects to the XBMC EventServer at HOST:PORT.\
+ Default value for HOST is localhost, default value for port is 9777.\n", argv[0]);
+ return -1;
+ }
+
+ if ( argc > 1 )
+ {
+ host = argv[1];
+ }
+
+ if ( argc > 2 )
+ {
+ port = argv[2];
+ }
+
+ client = new CXBMCClient(host, atoi(port));
+
+ SetConsoleCtrlHandler( (PHANDLER_ROUTINE) exitHandler, TRUE);
+
+ client->SendHELO("Xbox 360 Controller", 0);
+
+ while(true)
+ {
+ // Check each controller for activity
+ for ( i = 0; i < MAX_NUM_CONTROLLERS; i++ )
+ {
+ checkAll(*controllers[i]);
+ }
+ Sleep(10);
+ }
+
+ return 0;
+}
diff --git a/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.vcproj b/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.vcproj
index 4e6f8c558e..3a5a8b6562 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.vcproj
+++ b/tools/EventClients/Clients/Xbox360 Controller/Xbox360EventClient.vcproj
@@ -1,208 +1,208 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="9,00"
- Name="Xbox360EventClient"
- ProjectGUID="{19E7A234-4F29-4828-BBC7-E3564AB57EF0}"
- Keyword="Win32Proj"
- TargetFrameworkVersion="0"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- LinkIncremental="2"
- GenerateDebugInformation="true"
- SubSystem="1"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;"
- RuntimeLibrary="2"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- LinkIncremental="2"
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc;xsd"
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
- >
- <File
- RelativePath=".\stdafx.h"
- >
- </File>
- <File
- RelativePath=".\targetver.h"
- >
- </File>
- <File
- RelativePath=".\Xbox360Controller.h"
- >
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
- >
- </Filter>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
- >
- <File
- RelativePath=".\stdafx.cpp"
- >
- </File>
- <File
- RelativePath=".\Xbox360Controller.cpp"
- >
- </File>
- <File
- RelativePath=".\Xbox360EventClient.cpp"
- >
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="UTF-8"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="Xbox360EventClient"
+ ProjectGUID="{19E7A234-4F29-4828-BBC7-E3564AB57EF0}"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="0"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\stdafx.h"
+ >
+ </File>
+ <File
+ RelativePath=".\targetver.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Xbox360Controller.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\stdafx.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Xbox360Controller.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Xbox360EventClient.cpp"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/tools/EventClients/Clients/Xbox360 Controller/stdafx.cpp b/tools/EventClients/Clients/Xbox360 Controller/stdafx.cpp
index 81d9f220d5..648e7e6843 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/stdafx.cpp
+++ b/tools/EventClients/Clients/Xbox360 Controller/stdafx.cpp
@@ -1,8 +1,8 @@
-// stdafx.cpp : source file that includes just the standard includes
-// Xbox360EventClient.pch will be the pre-compiled header
-// stdafx.obj will contain the pre-compiled type information
-
-#include "stdafx.h"
-
-// TODO: reference any additional headers you need in STDAFX.H
-// and not in this file
+// stdafx.cpp : source file that includes just the standard includes
+// Xbox360EventClient.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/tools/EventClients/Clients/Xbox360 Controller/stdafx.h b/tools/EventClients/Clients/Xbox360 Controller/stdafx.h
index 47a0d0252b..b005a839de 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/stdafx.h
+++ b/tools/EventClients/Clients/Xbox360 Controller/stdafx.h
@@ -1,15 +1,15 @@
-// stdafx.h : include file for standard system include files,
-// or project specific include files that are used frequently, but
-// are changed infrequently
-//
-
-#pragma once
-
-#include "targetver.h"
-
-#include <stdio.h>
-#include <tchar.h>
-
-
-
-// TODO: reference additional headers your program requires here
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include "targetver.h"
+
+#include <stdio.h>
+#include <tchar.h>
+
+
+
+// TODO: reference additional headers your program requires here
diff --git a/tools/EventClients/Clients/Xbox360 Controller/targetver.h b/tools/EventClients/Clients/Xbox360 Controller/targetver.h
index a38195a4ef..6fe8eb79e1 100644
--- a/tools/EventClients/Clients/Xbox360 Controller/targetver.h
+++ b/tools/EventClients/Clients/Xbox360 Controller/targetver.h
@@ -1,13 +1,13 @@
-#pragma once
-
-// The following macros define the minimum required platform. The minimum required platform
-// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
-// your application. The macros work by enabling all features available on platform versions up to and
-// including the version specified.
-
-// Modify the following defines if you have to target a platform prior to the ones specified below.
-// Refer to MSDN for the latest info on corresponding values for different platforms.
-#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
-#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
-#endif
-
+#pragma once
+
+// The following macros define the minimum required platform. The minimum required platform
+// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
+// your application. The macros work by enabling all features available on platform versions up to and
+// including the version specified.
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
+#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
diff --git a/tools/EventClients/examples/c#/XBMCDemoClient1.cs b/tools/EventClients/examples/c#/XBMCDemoClient1.cs
index 849cc36c07..ca1f80c35c 100644
--- a/tools/EventClients/examples/c#/XBMCDemoClient1.cs
+++ b/tools/EventClients/examples/c#/XBMCDemoClient1.cs
@@ -1,35 +1,35 @@
-using System;
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Windows.Forms;
-using XBMC;
-
-namespace XBMCEventClientDemo
-{
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
+using XBMC;
+
+namespace XBMCEventClientDemo
+{
+ static class Program
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
{
EventClient eventClient = new EventClient();
- eventClient.Connect("127.0.0.1", 9777);
- eventClient.SendHelo("XBMC Client Demo", IconType.ICON_PNG, "icon.png");
- System.Threading.Thread.Sleep(1000);
- eventClient.SendNotification("XBMC Client Demo", "Notification Message", IconType.ICON_PNG, "/usr/share/xbmc/media/icon.png");
- System.Threading.Thread.Sleep(1000);
- eventClient.SendButton("dpadup", "XG", ButtonFlagsType.BTN_DOWN | ButtonFlagsType.BTN_NO_REPEAT, 0);
- System.Threading.Thread.Sleep(1000);
- eventClient.SendPing();
- System.Threading.Thread.Sleep(1000);
- eventClient.SendMouse(32768, 32768);
- System.Threading.Thread.Sleep(1000);
- eventClient.SendLog(LogTypeEnum.LOGERROR, "Example error log message from XBMC Client Demo");
- System.Threading.Thread.Sleep(1000);
- eventClient.SendAction("Mute");
- System.Threading.Thread.Sleep(1000);
- eventClient.SendBye();
- }
- }
+ eventClient.Connect("127.0.0.1", 9777);
+ eventClient.SendHelo("XBMC Client Demo", IconType.ICON_PNG, "icon.png");
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendNotification("XBMC Client Demo", "Notification Message", IconType.ICON_PNG, "/usr/share/xbmc/media/icon.png");
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendButton("dpadup", "XG", ButtonFlagsType.BTN_DOWN | ButtonFlagsType.BTN_NO_REPEAT, 0);
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendPing();
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendMouse(32768, 32768);
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendLog(LogTypeEnum.LOGERROR, "Example error log message from XBMC Client Demo");
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendAction("Mute");
+ System.Threading.Thread.Sleep(1000);
+ eventClient.SendBye();
+ }
+ }
}
diff --git a/tools/EventClients/lib/c#/EventClient.cs b/tools/EventClients/lib/c#/EventClient.cs
index 8d9f21b501..f726b222e6 100644
--- a/tools/EventClients/lib/c#/EventClient.cs
+++ b/tools/EventClients/lib/c#/EventClient.cs
@@ -1,555 +1,555 @@
-/*
- * Copyright (C) 2008-2009 Team XBMC http://www.xbmc.org
- *
- * 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 2 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Sockets;
-
-namespace XBMC
-{
-
- public enum IconType
- {
- ICON_NONE = 0x00,
- ICON_JPEG = 0x01,
- ICON_PNG = 0x02,
- ICON_GIF = 0x03
- }
-
- public enum ButtonFlagsType
- {
- BTN_USE_NAME = 0x01,
- BTN_DOWN = 0x02,
- BTN_UP = 0x04,
- BTN_USE_AMOUNT = 0x08,
- BTN_QUEUE = 0x10,
- BTN_NO_REPEAT = 0x20,
- BTN_VKEY = 0x40,
- BTN_AXIS = 0x80
- }
-
- public enum MouseFlagsType
- {
- MS_ABSOLUTE = 0x01
- }
-
- public enum LogTypeEnum
- {
- LOGDEBUG = 0,
- LOGINFO = 1,
- LOGNOTICE = 2,
- LOGWARNING = 3,
- LOGERROR = 4,
- LOGSEVERE = 5,
- LOGFATAL = 6,
- LOGNONE = 7
- }
-
- public enum ActionType
- {
- ACTION_EXECBUILTIN = 0x01,
- ACTION_BUTTON = 0x02
- }
-
- public class EventClient
- {
-
- /************************************************************************/
- /* Written by Peter Tribe aka EqUiNox (TeamBlackbolt) */
- /* Based upon XBMC's xbmcclient.cpp class */
- /************************************************************************/
-
- private enum PacketType
- {
- PT_HELO = 0x01,
- PT_BYE = 0x02,
- PT_BUTTON = 0x03,
- PT_MOUSE = 0x04,
- PT_PING = 0x05,
- PT_BROADCAST = 0x06, //Currently not implemented
- PT_NOTIFICATION = 0x07,
- PT_BLOB = 0x08,
- PT_LOG = 0x09,
- PT_ACTION = 0x0A,
- PT_DEBUG = 0xFF //Currently not implemented
- }
-
- private const int STD_PORT = 9777;
- private const int MAX_PACKET_SIZE = 1024;
- private const int HEADER_SIZE = 32;
- private const int MAX_PAYLOAD_SIZE = MAX_PACKET_SIZE - HEADER_SIZE;
- private const byte MAJOR_VERSION = 2;
- private const byte MINOR_VERSION = 0;
-
- private uint uniqueToken;
- private Socket socket;
-
- public bool Connect(string Address)
- {
- return Connect(Address, STD_PORT, (uint)System.DateTime.Now.TimeOfDay.Milliseconds);
- }
-
- public bool Connect(string Address, int Port)
- {
- return Connect(Address, Port, (uint)System.DateTime.Now.TimeOfDay.Milliseconds);
- }
-
-
- public bool Connect(string Address, int Port, uint UID)
- {
- try
- {
- if (socket != null) Disconnect();
- uniqueToken = UID;
- socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
-
-// For compilation with .net framework 1.0 or 1.1
-// define the FRAMEWORK_1_x conditional compilation constant in the project
-// or add /define:FRAMEWORK_1_x to the csc.exe command line
-#if FRAMEWORK_1_x
- socket.Connect(Dns.GetHostByName(Address).AddressList[0].ToString(), Port);
-#else
- socket.Connect(Address, Port);
-#endif
- return true;
- }
- catch
- {
- return false;
- }
- }
-
- public bool Connected
- {
- get
- {
- if (socket == null) return false;
- return socket.Connected;
- }
- }
-
- public void Disconnect()
- {
- try
- {
- if (socket != null)
- {
- socket.Shutdown(SocketShutdown.Both);
- socket.Close();
- socket = null;
- }
- }
- catch
- {
- }
- }
-
- private byte[] Header(PacketType PacketType, int NumberOfPackets, int CurrentPacket, int PayloadSize)
- {
-
- byte[] header = new byte[HEADER_SIZE];
-
- header[0] = (byte)'X';
- header[1] = (byte)'B';
- header[2] = (byte)'M';
- header[3] = (byte)'C';
-
- header[4] = MAJOR_VERSION;
- header[5] = MINOR_VERSION;
-
- if (CurrentPacket == 1)
- {
- header[6] = (byte)(((ushort)PacketType & 0xff00) >> 8);
- header[7] = (byte)((ushort)PacketType & 0x00ff);
- }
- else
- {
- header[6] = (byte)(((ushort)PacketType.PT_BLOB & 0xff00) >> 8);
- header[7] = (byte)((ushort)PacketType.PT_BLOB & 0x00ff);
- }
-
- header[8] = (byte)((CurrentPacket & 0xff000000) >> 24);
- header[9] = (byte)((CurrentPacket & 0x00ff0000) >> 16);
- header[10] = (byte)((CurrentPacket & 0x0000ff00) >> 8);
- header[11] = (byte)(CurrentPacket & 0x000000ff);
-
- header[12] = (byte)((NumberOfPackets & 0xff000000) >> 24);
- header[13] = (byte)((NumberOfPackets & 0x00ff0000) >> 16);
- header[14] = (byte)((NumberOfPackets & 0x0000ff00) >> 8);
- header[15] = (byte)(NumberOfPackets & 0x000000ff);
-
- header[16] = (byte)((PayloadSize & 0xff00) >> 8);
- header[17] = (byte)(PayloadSize & 0x00ff);
-
- header[18] = (byte)((uniqueToken & 0xff000000) >> 24);
- header[19] = (byte)((uniqueToken & 0x00ff0000) >> 16);
- header[20] = (byte)((uniqueToken & 0x0000ff00) >> 8);
- header[21] = (byte)(uniqueToken & 0x000000ff);
-
- return header;
-
- }
-
- private bool Send(PacketType PacketType, byte[] Payload)
- {
- try
- {
-
- bool successfull = true;
- int packetCount = (Payload.Length / MAX_PAYLOAD_SIZE) + 1;
- int bytesToSend = 0;
- int bytesSent = 0;
- int bytesLeft = Payload.Length;
-
- for (int Package = 1; Package <= packetCount; Package++)
- {
-
- if (bytesLeft > MAX_PAYLOAD_SIZE)
- {
- bytesToSend = MAX_PAYLOAD_SIZE;
- bytesLeft -= bytesToSend;
- }
- else
- {
- bytesToSend = bytesLeft;
- bytesLeft = 0;
- }
-
- byte[] header = Header(PacketType, packetCount, Package, bytesToSend);
- byte[] packet = new byte[MAX_PACKET_SIZE];
-
- Array.Copy(header, 0, packet, 0, header.Length);
- Array.Copy(Payload, bytesSent, packet, header.Length, bytesToSend);
-
- int sendSize = socket.Send(packet, header.Length + bytesToSend, SocketFlags.None);
-
- if (sendSize != (header.Length + bytesToSend))
- {
- successfull = false;
- break;
- }
-
- bytesSent += bytesToSend;
-
- }
-
- return successfull;
-
- }
- catch
- {
-
- return false;
-
- }
-
- }
-
- /************************************************************************/
- /* SendHelo - Payload format */
- /* %s - device name (max 128 chars) */
- /* %c - icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF ) */
- /* %s - my port ( 0=>not listening ) */
- /* %d - reserved1 ( 0 ) */
- /* %d - reserved2 ( 0 ) */
- /* XX - imagedata ( can span multiple packets ) */
- /************************************************************************/
- public bool SendHelo(string DevName, IconType IconType, string IconFile)
- {
-
- byte[] icon = new byte[0];
- if (IconType != IconType.ICON_NONE)
- icon = File.ReadAllBytes(IconFile);
-
- byte[] payload = new byte[DevName.Length + 12 + icon.Length];
-
- int offset = 0;
-
- for (int i = 0; i < DevName.Length; i++)
- payload[offset++] = (byte)DevName[i];
- payload[offset++] = (byte)'\0';
-
- payload[offset++] = (byte)IconType;
-
- payload[offset++] = (byte)0;
- payload[offset++] = (byte)'\0';
-
- for (int i = 0; i < 8; i++)
- payload[offset++] = (byte)0;
-
- Array.Copy(icon, 0, payload, DevName.Length + 12, icon.Length);
-
- return Send(PacketType.PT_HELO, payload);
-
- }
-
- public bool SendHelo(string DevName)
- {
- return SendHelo(DevName, IconType.ICON_NONE, "");
- }
-
- /************************************************************************/
- /* SendNotification - Payload format */
- /* %s - caption */
- /* %s - message */
- /* %c - icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF ) */
- /* %d - reserved ( 0 ) */
- /* XX - imagedata ( can span multiple packets ) */
- /************************************************************************/
- public bool SendNotification(string Caption, string Message, IconType IconType, string IconFile)
- {
-
- byte[] icon = new byte[0];
- if (IconType != IconType.ICON_NONE)
- icon = File.ReadAllBytes(IconFile);
-
- byte[] payload = new byte[Caption.Length + Message.Length + 7 + icon.Length];
-
- int offset = 0;
-
- for (int i = 0; i < Caption.Length; i++)
- payload[offset++] = (byte)Caption[i];
- payload[offset++] = (byte)'\0';
-
- for (int i = 0; i < Message.Length; i++)
- payload[offset++] = (byte)Message[i];
- payload[offset++] = (byte)'\0';
-
- payload[offset++] = (byte)IconType;
-
- for (int i = 0; i < 4; i++)
- payload[offset++] = (byte)0;
-
- Array.Copy(icon, 0, payload, Caption.Length + Message.Length + 7, icon.Length);
-
- return Send(PacketType.PT_NOTIFICATION, payload);
-
- }
-
- public bool SendNotification(string Caption, string Message)
- {
- return SendNotification(Caption, Message, IconType.ICON_NONE, "");
- }
-
- /************************************************************************/
- /* SendButton - Payload format */
- /* %i - button code */
- /* %i - flags 0x01 => use button map/name instead of code */
- /* 0x02 => btn down */
- /* 0x04 => btn up */
- /* 0x08 => use amount */
- /* 0x10 => queue event */
- /* 0x20 => do not repeat */
- /* 0x40 => virtual key */
- /* 0x80 => axis key */
- /* %i - amount ( 0 => 65k maps to -1 => 1 ) */
- /* %s - device map (case sensitive and required if flags & 0x01) */
- /* "KB" - Standard keyboard map */
- /* "XG" - Xbox Gamepad */
- /* "R1" - Xbox Remote */
- /* "R2" - Xbox Universal Remote */
- /* "LI:devicename" - valid LIRC device map where 'devicename' */
- /* is the actual name of the LIRC device */
- /* "JS<num>:joyname" - valid Joystick device map where */
- /* 'joyname' is the name specified in */
- /* the keymap. JS only supports button code */
- /* and not button name currently (!0x01). */
- /* %s - button name (required if flags & 0x01) */
- /************************************************************************/
- private bool SendButton(string Button, ushort ButtonCode, string DeviceMap, ButtonFlagsType Flags, short Amount)
- {
-
- if (Button.Length != 0)
- {
- if ((Flags & ButtonFlagsType.BTN_USE_NAME) == 0)
- Flags |= ButtonFlagsType.BTN_USE_NAME;
- ButtonCode = 0;
- }
- else
- Button = "";
-
- if (Amount > 0)
- {
- if ((Flags & ButtonFlagsType.BTN_USE_AMOUNT) == 0)
- Flags |= ButtonFlagsType.BTN_USE_AMOUNT;
- }
-
- if ((Flags & ButtonFlagsType.BTN_DOWN) == 0 && (Flags & ButtonFlagsType.BTN_UP) == 0)
- Flags |= ButtonFlagsType.BTN_DOWN;
-
- byte[] payload = new byte[Button.Length + DeviceMap.Length + 8];
-
- int offset = 0;
-
- payload[offset++] = (byte)((ButtonCode & 0xff00) >> 8);
- payload[offset++] = (byte)(ButtonCode & 0x00ff);
-
- payload[offset++] = (byte)(((ushort)Flags & 0xff00) >> 8);
- payload[offset++] = (byte)((ushort)Flags & 0x00ff);
-
- payload[offset++] = (byte)((Amount & 0xff00) >> 8);
- payload[offset++] = (byte)(Amount & 0x00ff);
-
- for (int i = 0; i < DeviceMap.Length; i++)
- payload[offset++] = (byte)DeviceMap[i];
- payload[offset++] = (byte)'\0';
-
- for (int i = 0; i < Button.Length; i++)
- payload[offset++] = (byte)Button[i];
- payload[offset++] = (byte)'\0';
-
- return Send(PacketType.PT_BUTTON, payload);
-
- }
-
- public bool SendButton(string Button, string DeviceMap, ButtonFlagsType Flags, short Amount)
- {
- return SendButton(Button, 0, DeviceMap, Flags, Amount);
- }
-
- public bool SendButton(string Button, string DeviceMap, ButtonFlagsType Flags)
- {
- return SendButton(Button, 0, DeviceMap, Flags, 0);
- }
-
- public bool SendButton(ushort ButtonCode, string DeviceMap, ButtonFlagsType Flags, short Amount)
- {
- return SendButton("", ButtonCode, DeviceMap, Flags, Amount);
- }
-
- public bool SendButton(ushort ButtonCode, string DeviceMap, ButtonFlagsType Flags)
- {
- return SendButton("", ButtonCode, DeviceMap, Flags, 0);
- }
-
- public bool SendButton(ushort ButtonCode, ButtonFlagsType Flags, short Amount)
- {
- return SendButton("", ButtonCode, "", Flags, Amount);
- }
-
- public bool SendButton(ushort ButtonCode, ButtonFlagsType Flags)
- {
- return SendButton("", ButtonCode, "", Flags, 0);
- }
-
- public bool SendButton()
- {
- return SendButton("", 0, "", ButtonFlagsType.BTN_UP, 0);
- }
-
- /************************************************************************/
- /* SendPing - No payload */
- /************************************************************************/
- public bool SendPing()
- {
- byte[] payload = new byte[0];
- return Send(PacketType.PT_PING, payload);
- }
-
- /************************************************************************/
- /* SendBye - No payload */
- /************************************************************************/
- public bool SendBye()
- {
- byte[] payload = new byte[0];
- return Send(PacketType.PT_BYE, payload);
- }
-
- /************************************************************************/
- /* SendMouse - Payload format */
- /* %c - flags */
- /* - 0x01 absolute position */
- /* %i - mousex (0-65535 => maps to screen width) */
- /* %i - mousey (0-65535 => maps to screen height) */
- /************************************************************************/
- public bool SendMouse(ushort X, ushort Y, MouseFlagsType Flags)
- {
-
- byte[] payload = new byte[9];
-
- int offset = 0;
-
- payload[offset++] = (byte)Flags;
-
- payload[offset++] = (byte)((X & 0xff00) >> 8);
- payload[offset++] = (byte)(X & 0x00ff);
-
- payload[offset++] = (byte)((Y & 0xff00) >> 8);
- payload[offset++] = (byte)(Y & 0x00ff);
-
- return Send(PacketType.PT_MOUSE, payload);
-
- }
-
- public bool SendMouse(ushort X, ushort Y)
- {
- return SendMouse(X, Y, MouseFlagsType.MS_ABSOLUTE);
- }
-
- /************************************************************************/
- /* SendLog - Payload format */
- /* %c - log type */
- /* %s - message */
- /************************************************************************/
- public bool SendLog(LogTypeEnum LogLevel, string Message)
- {
-
- byte[] payload = new byte[Message.Length + 2];
-
- int offset = 0;
-
- payload[offset++] = (byte)LogLevel;
-
- for (int i = 0; i < Message.Length; i++)
- payload[offset++] = (byte)Message[i];
- payload[offset++] = (byte)'\0';
-
- return Send(PacketType.PT_LOG, payload);
-
- }
-
- /************************************************************************/
- /* SendAction - Payload format */
- /* %c - action type */
- /* %s - action message */
- /************************************************************************/
- public bool SendAction(ActionType Action, string Message)
- {
-
- byte[] payload = new byte[Message.Length + 2];
-
- int offset = 0;
-
- payload[offset++] = (byte)Action;
-
- for (int i = 0; i < Message.Length; i++)
- payload[offset++] = (byte)Message[i];
- payload[offset++] = (byte)'\0';
-
- return Send(PacketType.PT_ACTION, payload);
-
- }
-
- public bool SendAction(string Message)
- {
- return SendAction(ActionType.ACTION_EXECBUILTIN, Message);
- }
-
- }
-}
+/*
+ * Copyright (C) 2008-2009 Team XBMC http://www.xbmc.org
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+
+namespace XBMC
+{
+
+ public enum IconType
+ {
+ ICON_NONE = 0x00,
+ ICON_JPEG = 0x01,
+ ICON_PNG = 0x02,
+ ICON_GIF = 0x03
+ }
+
+ public enum ButtonFlagsType
+ {
+ BTN_USE_NAME = 0x01,
+ BTN_DOWN = 0x02,
+ BTN_UP = 0x04,
+ BTN_USE_AMOUNT = 0x08,
+ BTN_QUEUE = 0x10,
+ BTN_NO_REPEAT = 0x20,
+ BTN_VKEY = 0x40,
+ BTN_AXIS = 0x80
+ }
+
+ public enum MouseFlagsType
+ {
+ MS_ABSOLUTE = 0x01
+ }
+
+ public enum LogTypeEnum
+ {
+ LOGDEBUG = 0,
+ LOGINFO = 1,
+ LOGNOTICE = 2,
+ LOGWARNING = 3,
+ LOGERROR = 4,
+ LOGSEVERE = 5,
+ LOGFATAL = 6,
+ LOGNONE = 7
+ }
+
+ public enum ActionType
+ {
+ ACTION_EXECBUILTIN = 0x01,
+ ACTION_BUTTON = 0x02
+ }
+
+ public class EventClient
+ {
+
+ /************************************************************************/
+ /* Written by Peter Tribe aka EqUiNox (TeamBlackbolt) */
+ /* Based upon XBMC's xbmcclient.cpp class */
+ /************************************************************************/
+
+ private enum PacketType
+ {
+ PT_HELO = 0x01,
+ PT_BYE = 0x02,
+ PT_BUTTON = 0x03,
+ PT_MOUSE = 0x04,
+ PT_PING = 0x05,
+ PT_BROADCAST = 0x06, //Currently not implemented
+ PT_NOTIFICATION = 0x07,
+ PT_BLOB = 0x08,
+ PT_LOG = 0x09,
+ PT_ACTION = 0x0A,
+ PT_DEBUG = 0xFF //Currently not implemented
+ }
+
+ private const int STD_PORT = 9777;
+ private const int MAX_PACKET_SIZE = 1024;
+ private const int HEADER_SIZE = 32;
+ private const int MAX_PAYLOAD_SIZE = MAX_PACKET_SIZE - HEADER_SIZE;
+ private const byte MAJOR_VERSION = 2;
+ private const byte MINOR_VERSION = 0;
+
+ private uint uniqueToken;
+ private Socket socket;
+
+ public bool Connect(string Address)
+ {
+ return Connect(Address, STD_PORT, (uint)System.DateTime.Now.TimeOfDay.Milliseconds);
+ }
+
+ public bool Connect(string Address, int Port)
+ {
+ return Connect(Address, Port, (uint)System.DateTime.Now.TimeOfDay.Milliseconds);
+ }
+
+
+ public bool Connect(string Address, int Port, uint UID)
+ {
+ try
+ {
+ if (socket != null) Disconnect();
+ uniqueToken = UID;
+ socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
+
+// For compilation with .net framework 1.0 or 1.1
+// define the FRAMEWORK_1_x conditional compilation constant in the project
+// or add /define:FRAMEWORK_1_x to the csc.exe command line
+#if FRAMEWORK_1_x
+ socket.Connect(Dns.GetHostByName(Address).AddressList[0].ToString(), Port);
+#else
+ socket.Connect(Address, Port);
+#endif
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ public bool Connected
+ {
+ get
+ {
+ if (socket == null) return false;
+ return socket.Connected;
+ }
+ }
+
+ public void Disconnect()
+ {
+ try
+ {
+ if (socket != null)
+ {
+ socket.Shutdown(SocketShutdown.Both);
+ socket.Close();
+ socket = null;
+ }
+ }
+ catch
+ {
+ }
+ }
+
+ private byte[] Header(PacketType PacketType, int NumberOfPackets, int CurrentPacket, int PayloadSize)
+ {
+
+ byte[] header = new byte[HEADER_SIZE];
+
+ header[0] = (byte)'X';
+ header[1] = (byte)'B';
+ header[2] = (byte)'M';
+ header[3] = (byte)'C';
+
+ header[4] = MAJOR_VERSION;
+ header[5] = MINOR_VERSION;
+
+ if (CurrentPacket == 1)
+ {
+ header[6] = (byte)(((ushort)PacketType & 0xff00) >> 8);
+ header[7] = (byte)((ushort)PacketType & 0x00ff);
+ }
+ else
+ {
+ header[6] = (byte)(((ushort)PacketType.PT_BLOB & 0xff00) >> 8);
+ header[7] = (byte)((ushort)PacketType.PT_BLOB & 0x00ff);
+ }
+
+ header[8] = (byte)((CurrentPacket & 0xff000000) >> 24);
+ header[9] = (byte)((CurrentPacket & 0x00ff0000) >> 16);
+ header[10] = (byte)((CurrentPacket & 0x0000ff00) >> 8);
+ header[11] = (byte)(CurrentPacket & 0x000000ff);
+
+ header[12] = (byte)((NumberOfPackets & 0xff000000) >> 24);
+ header[13] = (byte)((NumberOfPackets & 0x00ff0000) >> 16);
+ header[14] = (byte)((NumberOfPackets & 0x0000ff00) >> 8);
+ header[15] = (byte)(NumberOfPackets & 0x000000ff);
+
+ header[16] = (byte)((PayloadSize & 0xff00) >> 8);
+ header[17] = (byte)(PayloadSize & 0x00ff);
+
+ header[18] = (byte)((uniqueToken & 0xff000000) >> 24);
+ header[19] = (byte)((uniqueToken & 0x00ff0000) >> 16);
+ header[20] = (byte)((uniqueToken & 0x0000ff00) >> 8);
+ header[21] = (byte)(uniqueToken & 0x000000ff);
+
+ return header;
+
+ }
+
+ private bool Send(PacketType PacketType, byte[] Payload)
+ {
+ try
+ {
+
+ bool successfull = true;
+ int packetCount = (Payload.Length / MAX_PAYLOAD_SIZE) + 1;
+ int bytesToSend = 0;
+ int bytesSent = 0;
+ int bytesLeft = Payload.Length;
+
+ for (int Package = 1; Package <= packetCount; Package++)
+ {
+
+ if (bytesLeft > MAX_PAYLOAD_SIZE)
+ {
+ bytesToSend = MAX_PAYLOAD_SIZE;
+ bytesLeft -= bytesToSend;
+ }
+ else
+ {
+ bytesToSend = bytesLeft;
+ bytesLeft = 0;
+ }
+
+ byte[] header = Header(PacketType, packetCount, Package, bytesToSend);
+ byte[] packet = new byte[MAX_PACKET_SIZE];
+
+ Array.Copy(header, 0, packet, 0, header.Length);
+ Array.Copy(Payload, bytesSent, packet, header.Length, bytesToSend);
+
+ int sendSize = socket.Send(packet, header.Length + bytesToSend, SocketFlags.None);
+
+ if (sendSize != (header.Length + bytesToSend))
+ {
+ successfull = false;
+ break;
+ }
+
+ bytesSent += bytesToSend;
+
+ }
+
+ return successfull;
+
+ }
+ catch
+ {
+
+ return false;
+
+ }
+
+ }
+
+ /************************************************************************/
+ /* SendHelo - Payload format */
+ /* %s - device name (max 128 chars) */
+ /* %c - icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF ) */
+ /* %s - my port ( 0=>not listening ) */
+ /* %d - reserved1 ( 0 ) */
+ /* %d - reserved2 ( 0 ) */
+ /* XX - imagedata ( can span multiple packets ) */
+ /************************************************************************/
+ public bool SendHelo(string DevName, IconType IconType, string IconFile)
+ {
+
+ byte[] icon = new byte[0];
+ if (IconType != IconType.ICON_NONE)
+ icon = File.ReadAllBytes(IconFile);
+
+ byte[] payload = new byte[DevName.Length + 12 + icon.Length];
+
+ int offset = 0;
+
+ for (int i = 0; i < DevName.Length; i++)
+ payload[offset++] = (byte)DevName[i];
+ payload[offset++] = (byte)'\0';
+
+ payload[offset++] = (byte)IconType;
+
+ payload[offset++] = (byte)0;
+ payload[offset++] = (byte)'\0';
+
+ for (int i = 0; i < 8; i++)
+ payload[offset++] = (byte)0;
+
+ Array.Copy(icon, 0, payload, DevName.Length + 12, icon.Length);
+
+ return Send(PacketType.PT_HELO, payload);
+
+ }
+
+ public bool SendHelo(string DevName)
+ {
+ return SendHelo(DevName, IconType.ICON_NONE, "");
+ }
+
+ /************************************************************************/
+ /* SendNotification - Payload format */
+ /* %s - caption */
+ /* %s - message */
+ /* %c - icontype ( 0=>NOICON, 1=>JPEG , 2=>PNG , 3=>GIF ) */
+ /* %d - reserved ( 0 ) */
+ /* XX - imagedata ( can span multiple packets ) */
+ /************************************************************************/
+ public bool SendNotification(string Caption, string Message, IconType IconType, string IconFile)
+ {
+
+ byte[] icon = new byte[0];
+ if (IconType != IconType.ICON_NONE)
+ icon = File.ReadAllBytes(IconFile);
+
+ byte[] payload = new byte[Caption.Length + Message.Length + 7 + icon.Length];
+
+ int offset = 0;
+
+ for (int i = 0; i < Caption.Length; i++)
+ payload[offset++] = (byte)Caption[i];
+ payload[offset++] = (byte)'\0';
+
+ for (int i = 0; i < Message.Length; i++)
+ payload[offset++] = (byte)Message[i];
+ payload[offset++] = (byte)'\0';
+
+ payload[offset++] = (byte)IconType;
+
+ for (int i = 0; i < 4; i++)
+ payload[offset++] = (byte)0;
+
+ Array.Copy(icon, 0, payload, Caption.Length + Message.Length + 7, icon.Length);
+
+ return Send(PacketType.PT_NOTIFICATION, payload);
+
+ }
+
+ public bool SendNotification(string Caption, string Message)
+ {
+ return SendNotification(Caption, Message, IconType.ICON_NONE, "");
+ }
+
+ /************************************************************************/
+ /* SendButton - Payload format */
+ /* %i - button code */
+ /* %i - flags 0x01 => use button map/name instead of code */
+ /* 0x02 => btn down */
+ /* 0x04 => btn up */
+ /* 0x08 => use amount */
+ /* 0x10 => queue event */
+ /* 0x20 => do not repeat */
+ /* 0x40 => virtual key */
+ /* 0x80 => axis key */
+ /* %i - amount ( 0 => 65k maps to -1 => 1 ) */
+ /* %s - device map (case sensitive and required if flags & 0x01) */
+ /* "KB" - Standard keyboard map */
+ /* "XG" - Xbox Gamepad */
+ /* "R1" - Xbox Remote */
+ /* "R2" - Xbox Universal Remote */
+ /* "LI:devicename" - valid LIRC device map where 'devicename' */
+ /* is the actual name of the LIRC device */
+ /* "JS<num>:joyname" - valid Joystick device map where */
+ /* 'joyname' is the name specified in */
+ /* the keymap. JS only supports button code */
+ /* and not button name currently (!0x01). */
+ /* %s - button name (required if flags & 0x01) */
+ /************************************************************************/
+ private bool SendButton(string Button, ushort ButtonCode, string DeviceMap, ButtonFlagsType Flags, short Amount)
+ {
+
+ if (Button.Length != 0)
+ {
+ if ((Flags & ButtonFlagsType.BTN_USE_NAME) == 0)
+ Flags |= ButtonFlagsType.BTN_USE_NAME;
+ ButtonCode = 0;
+ }
+ else
+ Button = "";
+
+ if (Amount > 0)
+ {
+ if ((Flags & ButtonFlagsType.BTN_USE_AMOUNT) == 0)
+ Flags |= ButtonFlagsType.BTN_USE_AMOUNT;
+ }
+
+ if ((Flags & ButtonFlagsType.BTN_DOWN) == 0 && (Flags & ButtonFlagsType.BTN_UP) == 0)
+ Flags |= ButtonFlagsType.BTN_DOWN;
+
+ byte[] payload = new byte[Button.Length + DeviceMap.Length + 8];
+
+ int offset = 0;
+
+ payload[offset++] = (byte)((ButtonCode & 0xff00) >> 8);
+ payload[offset++] = (byte)(ButtonCode & 0x00ff);
+
+ payload[offset++] = (byte)(((ushort)Flags & 0xff00) >> 8);
+ payload[offset++] = (byte)((ushort)Flags & 0x00ff);
+
+ payload[offset++] = (byte)((Amount & 0xff00) >> 8);
+ payload[offset++] = (byte)(Amount & 0x00ff);
+
+ for (int i = 0; i < DeviceMap.Length; i++)
+ payload[offset++] = (byte)DeviceMap[i];
+ payload[offset++] = (byte)'\0';
+
+ for (int i = 0; i < Button.Length; i++)
+ payload[offset++] = (byte)Button[i];
+ payload[offset++] = (byte)'\0';
+
+ return Send(PacketType.PT_BUTTON, payload);
+
+ }
+
+ public bool SendButton(string Button, string DeviceMap, ButtonFlagsType Flags, short Amount)
+ {
+ return SendButton(Button, 0, DeviceMap, Flags, Amount);
+ }
+
+ public bool SendButton(string Button, string DeviceMap, ButtonFlagsType Flags)
+ {
+ return SendButton(Button, 0, DeviceMap, Flags, 0);
+ }
+
+ public bool SendButton(ushort ButtonCode, string DeviceMap, ButtonFlagsType Flags, short Amount)
+ {
+ return SendButton("", ButtonCode, DeviceMap, Flags, Amount);
+ }
+
+ public bool SendButton(ushort ButtonCode, string DeviceMap, ButtonFlagsType Flags)
+ {
+ return SendButton("", ButtonCode, DeviceMap, Flags, 0);
+ }
+
+ public bool SendButton(ushort ButtonCode, ButtonFlagsType Flags, short Amount)
+ {
+ return SendButton("", ButtonCode, "", Flags, Amount);
+ }
+
+ public bool SendButton(ushort ButtonCode, ButtonFlagsType Flags)
+ {
+ return SendButton("", ButtonCode, "", Flags, 0);
+ }
+
+ public bool SendButton()
+ {
+ return SendButton("", 0, "", ButtonFlagsType.BTN_UP, 0);
+ }
+
+ /************************************************************************/
+ /* SendPing - No payload */
+ /************************************************************************/
+ public bool SendPing()
+ {
+ byte[] payload = new byte[0];
+ return Send(PacketType.PT_PING, payload);
+ }
+
+ /************************************************************************/
+ /* SendBye - No payload */
+ /************************************************************************/
+ public bool SendBye()
+ {
+ byte[] payload = new byte[0];
+ return Send(PacketType.PT_BYE, payload);
+ }
+
+ /************************************************************************/
+ /* SendMouse - Payload format */
+ /* %c - flags */
+ /* - 0x01 absolute position */
+ /* %i - mousex (0-65535 => maps to screen width) */
+ /* %i - mousey (0-65535 => maps to screen height) */
+ /************************************************************************/
+ public bool SendMouse(ushort X, ushort Y, MouseFlagsType Flags)
+ {
+
+ byte[] payload = new byte[9];
+
+ int offset = 0;
+
+ payload[offset++] = (byte)Flags;
+
+ payload[offset++] = (byte)((X & 0xff00) >> 8);
+ payload[offset++] = (byte)(X & 0x00ff);
+
+ payload[offset++] = (byte)((Y & 0xff00) >> 8);
+ payload[offset++] = (byte)(Y & 0x00ff);
+
+ return Send(PacketType.PT_MOUSE, payload);
+
+ }
+
+ public bool SendMouse(ushort X, ushort Y)
+ {
+ return SendMouse(X, Y, MouseFlagsType.MS_ABSOLUTE);
+ }
+
+ /************************************************************************/
+ /* SendLog - Payload format */
+ /* %c - log type */
+ /* %s - message */
+ /************************************************************************/
+ public bool SendLog(LogTypeEnum LogLevel, string Message)
+ {
+
+ byte[] payload = new byte[Message.Length + 2];
+
+ int offset = 0;
+
+ payload[offset++] = (byte)LogLevel;
+
+ for (int i = 0; i < Message.Length; i++)
+ payload[offset++] = (byte)Message[i];
+ payload[offset++] = (byte)'\0';
+
+ return Send(PacketType.PT_LOG, payload);
+
+ }
+
+ /************************************************************************/
+ /* SendAction - Payload format */
+ /* %c - action type */
+ /* %s - action message */
+ /************************************************************************/
+ public bool SendAction(ActionType Action, string Message)
+ {
+
+ byte[] payload = new byte[Message.Length + 2];
+
+ int offset = 0;
+
+ payload[offset++] = (byte)Action;
+
+ for (int i = 0; i < Message.Length; i++)
+ payload[offset++] = (byte)Message[i];
+ payload[offset++] = (byte)'\0';
+
+ return Send(PacketType.PT_ACTION, payload);
+
+ }
+
+ public bool SendAction(string Message)
+ {
+ return SendAction(ActionType.ACTION_EXECBUILTIN, Message);
+ }
+
+ }
+}