Delete wiimote related vendor files
This commit is contained in:
BIN
vendor/wiiscan/0.90/Debug/DelcomDLL.dll
vendored
BIN
vendor/wiiscan/0.90/Debug/DelcomDLL.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Debug/USBm.dll
vendored
BIN
vendor/wiiscan/0.90/Debug/USBm.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Debug/WiimoteLib.dll
vendored
BIN
vendor/wiiscan/0.90/Debug/WiimoteLib.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Debug/bdi.out
vendored
BIN
vendor/wiiscan/0.90/Debug/bdi.out
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Debug/wiimotelibpoll.exe
vendored
BIN
vendor/wiiscan/0.90/Debug/wiimotelibpoll.exe
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Debug/wiiscan.exe
vendored
BIN
vendor/wiiscan/0.90/Debug/wiiscan.exe
vendored
Binary file not shown.
81
vendor/wiiscan/0.90/Debug/wiiscan.ini
vendored
81
vendor/wiiscan/0.90/Debug/wiiscan.ini
vendored
@@ -1,81 +0,0 @@
|
||||
% Configfile_begin
|
||||
% config file for wiiscan
|
||||
|
||||
% all usb device ids, not used yet in the scanning
|
||||
all_usb_hubs=""
|
||||
|
||||
% single power controlling usb hub, only nessesary when powerering over usb, for automatic resetting. If not used, put ""
|
||||
% active_usb_hub="@PCI\VEN_8086&DEV_2934&SUBSYS_20F017AA&REV_03\3&B1BFB68&0&E8"
|
||||
active_usb_hub=""
|
||||
|
||||
% a list of allowed wiimotes in the form xx:xx:xx:xx:xx:xx, wildcard match is 00:00:00:00:00:00
|
||||
%allowed_wiimote_adr=00:00:00:00:00:00
|
||||
% my set of wiimotes
|
||||
allowed_wiimote_adr=00:19:?D:??:6?:?? 00:1F:C5:??:??:?? 00:17:AB:39:69:87
|
||||
|
||||
% launching exe file have a problem with spaces, hence renamed exe, replaced space with underscores
|
||||
% The original Johnny Chung Lee wb software version 0.3, downloaded from [http://johnnylee.net/projects/wii/]
|
||||
% may not work yet, missing library integration
|
||||
%whiteboard_software="d:/WiimoteWhiteboard/WiimoteWhiteboard_v0.3.exe"
|
||||
|
||||
% same stuff, but binary build from sources and redistributed in this package
|
||||
whiteboard_software="WiimoteWhiteboard.exe"
|
||||
|
||||
% Boon Jin's wb software version 0.6, does not work yet, missing library integration
|
||||
%whiteboard_software="d:/wsb/WiimoteSmoothboard.exe"
|
||||
|
||||
% wiiscan parameters
|
||||
%option_device="Nintendo RVL-CNT-01"
|
||||
|
||||
% number of bt scanning attempts in a autoscan, timout is increased for every scan as retryattempt*option_timeout
|
||||
option_scanretries=1
|
||||
|
||||
% long time (4000 and above, or increase option_scanretries) when matching name, short (1000-2000) when matching address
|
||||
option_timeout=4000
|
||||
|
||||
% wiimote scanning time, only applicable used for wiilib
|
||||
option_wiitimeout=1000
|
||||
|
||||
% delay bewteen powerdown/up, see man for details
|
||||
option_usbsleep=1000
|
||||
option_usbmsleep=1000
|
||||
%option_btsleep=2000
|
||||
|
||||
% start wb at successfull connect, 0 or 1
|
||||
option_startwhiteboard=1
|
||||
|
||||
% output verbose flag, 0 or 1
|
||||
option_debug=1
|
||||
|
||||
% logging output file, put nothing if no logging is wanted
|
||||
option_logfile=wiiscan_log.txt
|
||||
%option_logfile=
|
||||
|
||||
% wiimote connection library, use none, wiiuse, or wiimotelib
|
||||
option_wiilib=wiimotelib
|
||||
|
||||
% 0=no power cycle, 1=USB hub control, 2=USBm IO, 3=USB Devcon
|
||||
option_usbpowermode=3
|
||||
|
||||
% 0=remove if not connectable, 1=always remove, 2=never remove
|
||||
%option_forceremove=0
|
||||
|
||||
% bt radio to use, not working yet
|
||||
%option_btradio=00:50:B6:A0:48:8C
|
||||
|
||||
% wiiscantray options
|
||||
% number of connection attempts before autoscan i restarted
|
||||
option_tray_pool_retries=2
|
||||
|
||||
% retry sleep, keep it low (<1000) to catch an open connection
|
||||
option_tray_sleep_between_pool_retries=250
|
||||
|
||||
% sleep bewteen polls, when wiimote is succeful connected, keep it hight (>2000) to avoid to much CPU usage
|
||||
option_tray_sleep_between_pool_loops=2000
|
||||
|
||||
% final connection step reqires some sleep before windows PnP is ready
|
||||
option_sleep_before_final_connect=1500
|
||||
|
||||
% delay after launch of wb software, keep it at a medium value (2000-10000)
|
||||
option_sleep_after_startwhiteboard=4000
|
||||
% Configfile_end
|
||||
BIN
vendor/wiiscan/0.90/Debug/wiiuse.dll
vendored
BIN
vendor/wiiscan/0.90/Debug/wiiuse.dll
vendored
Binary file not shown.
57
vendor/wiiscan/0.90/Doc/CHANGEINGBTSTACK.rtf
vendored
57
vendor/wiiscan/0.90/Doc/CHANGEINGBTSTACK.rtf
vendored
@@ -1,57 +0,0 @@
|
||||
CHANGING the Widcomm BT stack to Microsoft BT stack
|
||||
|
||||
[From http://forum.eeeuser.com/viewtopic.php?id=38533]
|
||||
|
||||
After making my post in the 1000H post I thought it probably best If it here as I don't see why it wouldn't work on the 901 models either...
|
||||
|
||||
Basically it's all to just to change from using the Widcomm stack for using bluetooth connections to the built in Windows stack, it's fairly simple to do and should be a performance boost as Widcomm runs fairly sloppy.
|
||||
|
||||
basically if you follow a guide similar to this>>> http://www.x-setup.net/forum/showthread.php?p=4762
|
||||
|
||||
Open file 'C:\Windows\inf\bth.inf' in notepad, (The inf folder is hidden by default so using Explorer go to Folder Options and change it to show all hidden folders)
|
||||
|
||||
(A good time to back up the bth.inf file if your worried about editing stuff wrongly but it's only like 3 lines worth)
|
||||
|
||||
Now you should have the section like this...
|
||||
|
||||
[Manufacturer]
|
||||
%Microsoft%=Microsoft
|
||||
ALPS=ALPS, NT.5.1
|
||||
Belkin=Belkin, NT.5.1
|
||||
Brain Boxes=BrainBoxes, NT.5.1
|
||||
Broadcom=Broadcom, NT.5.1
|
||||
Cambridge Silicon Radio Ltd.=Cambridge, NT.5.1
|
||||
Dell=Dell, NT.5.1
|
||||
FIC=FIC, NT.5.1
|
||||
GVC=GVC, NT.5.1
|
||||
HP=HP, NT.5.1
|
||||
IBM=IBM, NT.5.1
|
||||
Microsoft=Microsoft, NT.5.1
|
||||
Motion Computing=MotionComputing, NT.5.1
|
||||
Silicon Wave=SiliconWave, NT.5.1
|
||||
Sony=Sony, NT.5.1
|
||||
TDK=TDK, NT.5.1
|
||||
TOSHIBA=Toshiba, NT.5.1
|
||||
Wistron NeWeb=Wistron, NT.5.1
|
||||
Zeevo=Zeevo, NT.5.1
|
||||
|
||||
Now add a line to the that section a line such as (without quotes of course): 'Azwave=Azwave, NT.5.1 '
|
||||
|
||||
There should then be sections below this one that starts with:
|
||||
|
||||
;------------- Device section - Start -----------------------
|
||||
|
||||
Then insert a section that looks like this (Please note that you can check that the Vid and Pid are the same as your card by using device manage and looking at the properties of the device, and then the details tab, if not edit the following values, keeping the same format):
|
||||
|
||||
[Azwave.NT.5.1]
|
||||
BT253= BthUsb, USB\Vid_0b05&Pid_b700
|
||||
|
||||
Then save and close the notepad.
|
||||
|
||||
Then just either do a 'I'll choose from a list of drivers install' or if you haven't installed the drivers yet do a disable and enable of the bluetooth and it should install it automatically. The driver won't be signed so continue with it anyways.
|
||||
|
||||
I've now tested it with receiving a file from a phone and as such it seems to work absolutely fine.
|
||||
|
||||
Updated due to my own incompetence, don't worry this fix still works great.
|
||||
|
||||
Last edited by Sly (2008-08-30 8:51:54 pm)
|
||||
59
vendor/wiiscan/0.90/Doc/CHANGELOG.rtf
vendored
59
vendor/wiiscan/0.90/Doc/CHANGELOG.rtf
vendored
@@ -1,59 +0,0 @@
|
||||
Copyright © 2008 MergeIt, Aps.
|
||||
License GPLv3+: GNU GPL version 3 or later <http:\/\/gnu.org/licenses/gpl.html>.
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
the above copyright notice appear in all copies and that both that copyright notice
|
||||
and this permission notice appear in supporting documentation.
|
||||
|
||||
WIISCAN:
|
||||
a connection utility for wii console remotes
|
||||
|
||||
VERSION:
|
||||
0.9
|
||||
|
||||
Added:
|
||||
|
||||
* wildcard matches on wiimote adr.
|
||||
|
||||
* changed wiiscantray to hook into wiimotelib poll (major change).
|
||||
|
||||
* allowed for seamless connection with wiiscantray.
|
||||
|
||||
* (numerious minor changes, fixes)
|
||||
|
||||
VERSION:
|
||||
0.8
|
||||
|
||||
Added:
|
||||
* Minor code refactoring.
|
||||
|
||||
* Configfile entries for all options. Change the order of parsing options, first look in configfile, then read the command line (that eventually overrules the configfile options).
|
||||
|
||||
* Modified wiiscan.ini file to be more versatile.
|
||||
|
||||
* Added logging class, rewritten logging method.
|
||||
|
||||
* Changed calls to System, to CreatProc, that do not display a console window (for win trayicon mode).
|
||||
|
||||
* Changed project settings, links with MT lib instead of MT DLL; fixes strange MS bug when not being able to find msvcp90.dll and friends.
|
||||
|
||||
* Added hardware support for USBmicro IO board; power-control now possible with this board instead of the USB controller.
|
||||
|
||||
* Added USBio up/down functionality.
|
||||
|
||||
* Added usbmsleep, postsleep after USBmicro up/down cycle.
|
||||
|
||||
Fixed:
|
||||
* Fix of defect "1: restart pop-up": the 'Change of system settings ... Do you want to reboot now?' popup, happens only when the program runs for longer than 19 seconds. Keeping the connection time within 19 sec seems to cure the problem, Adding a sleep at the end of the program, say Sleep(20000) will eventually bring up the dialog again. The dialog can anyway safely be ignored!
|
||||
|
||||
* Fix of defect "2: discoverable mode fast shutdown": Initialization of wiilib has been rewritten, making it recall the HID initialization routine. Code for testing the wiimote connection has also been introduced.
|
||||
|
||||
* Fixed defect "15: BluetoothFindFirstDevice() stalls".
|
||||
|
||||
VERSION:
|
||||
0.7
|
||||
|
||||
First published version.
|
||||
153
vendor/wiiscan/0.90/Doc/INSTALL.rtf
vendored
153
vendor/wiiscan/0.90/Doc/INSTALL.rtf
vendored
@@ -1,153 +0,0 @@
|
||||
INSTALLATION
|
||||
|
||||
Version: 0.9
|
||||
|
||||
Procedure for wiiscan or wiiscantray:
|
||||
|
||||
Prerequisites
|
||||
|
||||
1a: unzip the wiiscan zip file(s).
|
||||
|
||||
1b: if you are not running a Microsoft Bluetooth stack, then change it from Widcomm, Bluesoleil or whatever you are using. See the file CHANGINGBTSTACK.rtf.
|
||||
|
||||
Running
|
||||
|
||||
1a: GUI version, run "wiiscantray.exe" in bin/Release or bin/Debug directory.
|
||||
|
||||
1b: CLI version, run "wiiscan.exe" in bin/Release or bin/Debug directory from a command prompt.
|
||||
|
||||
User optimizations:
|
||||
|
||||
Tune scan speed by giving wiiscan your specific wiimote address. Run "wiiscan -s nintendo" from a prompt to find the address, or use the windows system setting.
|
||||
|
||||
Replace the "allowed_wiimote_adr=00:00:00:00:00:00" by our specific addres in the wiiscan.ini file, and lower the value of "option_timeout" to 1000 or 2000.
|
||||
|
||||
Avoid annoying baloon tips by running: "popup_disable.reg" found in src/wiiscan-0.9.zip, under Tools.
|
||||
|
||||
Avoid annoying crash reports from the Wiimote library by running: "no_error_report.reg" found the same place as above.
|
||||
|
||||
ENJOY
|
||||
Mar 26 2009
|
||||
|
||||
Carsten Frigaard,
|
||||
MergeIt ApS, Kongsvang Allé 37, DK-8000 Århus C, www.mergit.dk
|
||||
|
||||
|
||||
INSTALLATION
|
||||
|
||||
Version: 0.8
|
||||
|
||||
Procedure for wiiscan or wiiscantray:
|
||||
|
||||
Prerequisites
|
||||
|
||||
1a: unzip the wiiscan zip file (wiiscan-0.8.zip, wiiscantray-0.8.zip or wiiscan-0.8-release-1.0.zip)
|
||||
|
||||
1b: if you are not running a Microsoft Bluetooth stack, then change it from Widcomm, Bluesoleil or whatever you are using. See the file CHANGINGBTSTACK.rtf.
|
||||
|
||||
Testing the exe files
|
||||
|
||||
2: run the wiiscan.exe --- if it terminates with an error indicating that it can not run the executable, you will need to recompile the .exe from the source code, or install .NET framework 3.5 SP1. Otherwise goto 5.
|
||||
|
||||
Note: even though the executable is a primitive console app it apparently needs a .NET framework! You can install .NET framework 3.5 SP1 or just install the Visual Studio C++ Express compiler (that also installs the needed framework).
|
||||
|
||||
Rebuilding the source code
|
||||
|
||||
3a: Install VS express form http://www.microsoft.com/express/vc/ [version: Microsoft Visual C++ 2008 Express Edition with SP1 - ENU]
|
||||
|
||||
3b: Open the wiiscan.sln and rebuild the executable.
|
||||
|
||||
3c: Re-try to launch wiiscan.exe (as in 2).
|
||||
|
||||
Finding and testing the +5V power in the USB controllers [do this, only if USB Hub power control is needed, that is the case of no USBmicro device hardware]
|
||||
|
||||
4a: download free, but non-redistributable, device console program, devcon.exe, from http:support.microsoft.com/kb/311272
|
||||
|
||||
4b: unzip devcon.zip and copy devcon.exe (i386/devcon.exe) to path (say copy it into c:\WINDOWS\ directory)
|
||||
|
||||
4c: Some USB controllers cannot do a power-down; it seems that ICH7 controllers are not able to cut the power while ICH9 controllers can.
|
||||
|
||||
On an ASUS eee PC the controller version reads
|
||||
|
||||
"Intel(R) 82801G (ICH7 Family) USB Universal Host Controller"
|
||||
"Intel(R) 82801G (ICH7 Family) USB2 Enhanced Host Controller"
|
||||
|
||||
On a Lenovo R599 the controller version reads
|
||||
|
||||
"Intel(R) ICH9 Family USB Universal Host Controller"
|
||||
"Intel(R) ICH9 Family USB2 Enhanced Host Controller"
|
||||
|
||||
where only the later (ICH9) is usable for the wiimote auto-power procedure here. Check our system specification, before proceeding.
|
||||
|
||||
4d: Find the id of the USB hubs on the system, open "Control panel | System | Hardware | Device management" and look for USB-controllers.
|
||||
|
||||
Open the USB-controller tap and write down the address of all the USB Universal host controllers, and USB2 Enhanced host controllers.
|
||||
|
||||
The id of the controllers are found by right-clicking on the device, selecting "Properties | Details"
|
||||
|
||||
On my eee PC I have four Intel controllers
|
||||
|
||||
PCI\VEN_8086&DEV_27C8&SUBSYS_830F1043&REV_02\3&11583659&0&E8
|
||||
PCI\VEN_8086&DEV_27C9&SUBSYS_830F1043&REV_02\3&11583659&0&E9
|
||||
PCI\VEN_8086&DEV_27CA&SUBSYS_830F1043&REV_02\3&11583659&0&EA
|
||||
PCI\VEN_8086&DEV_27CB&SUBSYS_830F1043&REV_02\3&11583659&0&EB
|
||||
|
||||
and one USB2 controller
|
||||
|
||||
PCI\VEN_8086&DEV_27CC&SUBSYS_830F1043&REV_02\3&11583659&0&EF
|
||||
|
||||
Try to manually disable all the controllers bu
|
||||
|
||||
> devcon status "@PCI\VEN_8086&DEV_27C8&SUBSYS_830F1043&REV_02\3&11583659&0&E8"
|
||||
|
||||
or, if possible, you could use a pattern match to select all the devices...for my particular system the following expression works
|
||||
|
||||
> devcon status "@PCI\VEN_8086&DEV_27C*&SUBSYS_830F1043&REV_02\3&11583659&0&E*"
|
||||
|
||||
Then disable all devices
|
||||
|
||||
> devcon disable "@PCI\VEN_8086&DEV_27C*&SUBSYS_830F1043&REV_02\3&11583659&0&E*"
|
||||
|
||||
and check the result in the windows device manager (or manually disable all the USB controllers here)
|
||||
|
||||
Finally, pick an active controller and put its address into the wiiscan.ini file, for my particular setup the file then reads
|
||||
|
||||
% Configfile_begin
|
||||
% config file for wiiscan
|
||||
all_usb_hubs="@PCI\VEN_8086&DEV_27C*&SUBSYS_830F1043&REV_02\3&11583659&0&E*"
|
||||
active_usb_hub="@PCI\VEN_8086&DEV_27C8&SUBSYS_830F1043&REV_02\3&11583659&0&E8"
|
||||
allowed_wiimote_adr=00:00:00:00:00:00
|
||||
whiteboard_software="d:/WiimoteWhiteboard/WiimoteWhiteboard_v0.3.exe"
|
||||
% Configfile_end
|
||||
|
||||
It is not that important to choose a particular USB controller as the active one, important is that power is only cut to the USB when ALL controllers are disabled, and on when just a single controller is enabled.
|
||||
|
||||
Note: the use of other USB devices may be troublesome, when powering the wiimote over USB as here. It is not recommended to use USB devices together with this procedure!!
|
||||
|
||||
Add the addresses of your wiimotes to the .ini file
|
||||
|
||||
5: To enable faster an more robust connection, find and add all wiimote addresses to the .ini file in the form of a single address or a list, say
|
||||
|
||||
allowed_wiimote_adr=00:19:FD:CC:60:61 00:19:1D:D6:65:E5
|
||||
|
||||
Test an automated, unattended connection
|
||||
|
||||
6; Re-run the wiiscan.exe in a console. If it still fails try to give it a -v option for verbose output, tune the timing parameters (-b,-t,-u,-w), or mail all the results to me: carsten AT mergit.dk
|
||||
|
||||
Run the wiiscantray GUI version
|
||||
|
||||
7; Run wiiscantray.exe,
|
||||
|
||||
* click on "Rescan for wiimotes" to connect.
|
||||
|
||||
* click "Start whiteboard..." to start the whiteboard executable. Use the option "option_startwhiteboard=1" in the .ini file to start the software after a successful connection.
|
||||
|
||||
* click "Display log..." to show the log output, enable and control the log via the options "option_logfile=wiiscan_log.txt" and "option_debug=1
|
||||
|
||||
* use "Reset log..." to clear the log.
|
||||
|
||||
ENJOY
|
||||
Feb 12 2009
|
||||
|
||||
Carsten Frigaard,
|
||||
MergeIt ApS, Kongsvang Allé 37, DK-8000 Århus C, www.mergit.dk
|
||||
674
vendor/wiiscan/0.90/Doc/LICENSE.rtf
vendored
674
vendor/wiiscan/0.90/Doc/LICENSE.rtf
vendored
@@ -1,674 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
500
vendor/wiiscan/0.90/Doc/MANUAL_wiiscan.rtf
vendored
500
vendor/wiiscan/0.90/Doc/MANUAL_wiiscan.rtf
vendored
@@ -1,500 +0,0 @@
|
||||
|
||||
wiiscan(1) wiiscan(1)
|
||||
|
||||
|
||||
|
||||
[1mNAME[0m
|
||||
[4mwiiscan[24m - a connection utility for wii console remotes
|
||||
|
||||
|
||||
[1mSYNOPSIS[0m
|
||||
wiiscan <-a <device> | -c <device> | -d <device> | -r | -s | -usbup |
|
||||
-usbdown> > [-cf <file>] [-lf <file>] [-b <sleep>] [-t <sleep>] [-u
|
||||
<sleep>] [-p <sleep>] [-w <sleep>] [-q <usbradio>] [-f <removemode>]
|
||||
[-m <powermode>] [-l <wiilibrary>] [-wb] [-v]
|
||||
|
||||
|
||||
[1mOVERVIEW[0m
|
||||
[4mwiiscan[24m is a canvas function for a number of different scanning and
|
||||
connection utilities. It can detect build-in bluetooth radios, scan for
|
||||
nearby bluetooth devices, connect to a specific device and remove that
|
||||
device again from the hardware.
|
||||
|
||||
The main feature of [4mwiiscan[24m is to automatically connect to a wii remote
|
||||
(wiimote). This can be quiet cumbersome on a Windows system, and the
|
||||
nesseccary steps for doing a robust, working connection is done by
|
||||
|
||||
|
||||
[1mDelete wiimote hardware HID bluetooth entry:[0m
|
||||
delete old entries of the wiimote in the bluetooth hardware. On
|
||||
some windows system the wiimote is readily detected, after the
|
||||
first manually installation. Pressing the "1-2" makes the
|
||||
wiimote discoverable. On other systems (including mine), any
|
||||
attempt to connect to the wiimote, after one successful or un-
|
||||
successful connection attempt, will always fail! Removing the
|
||||
HID and wiimote registry entries before the next attempt cures
|
||||
this feature.
|
||||
|
||||
|
||||
[1mCycle USB bus:[0m
|
||||
the wiimote can be switched automatically to discoverable mode,
|
||||
if the power is briefly cut from the device. This can be done
|
||||
on a wiimote powered by the USB +5 volt (with a proper voltage
|
||||
regulator to bring it under +3 volt). This step hence turns the
|
||||
USB hub off, killing the power, and turns it on again. The
|
||||
"1-2" buttons on the wiimote must be pressed at all times, done
|
||||
by say some tape or gaffa!.
|
||||
|
||||
|
||||
[1mScan for wiimote:[0m
|
||||
now comes the main part of the connection; scanning for a
|
||||
wiimote. This includes bringing up the bluetooth radio device,
|
||||
initialize seek parameters, scanning and matching for a device
|
||||
name or address, connecting to a matched device, installing the
|
||||
HID interface (that was removed in the first step), and finally
|
||||
trying to open the wiimote and reading some data from it. All
|
||||
steps involve a time variable, meaning that say installing the
|
||||
HID causes some windows registry fiddling, that takes a rather
|
||||
variable amount of time, and the next step is critically depen‐
|
||||
dent on the former step to be finished. Hence a number of tun‐
|
||||
able waiting variable is introduced, Important is to being able
|
||||
to reach the final connection step before the wiimote goes out
|
||||
of the discoverable mode and automatically turns off.
|
||||
|
||||
|
||||
A note on USB voltage cycling:
|
||||
This software solution is able to restart the wiimote in dis‐
|
||||
coverable mode automatically. But this require that the wiimote
|
||||
is powered by a USB cable to the PC and that the "1-2" button
|
||||
combination is permanently pressed. Cycling the power for the
|
||||
wiimote with the "1-2" buttons pressed enables the discoverable
|
||||
mode, and the continuously pressing "1-2" does not interfere
|
||||
with wiimote operations hereafter.
|
||||
|
||||
So this is a non-intrusive fix to the so called "Ladder prob‐
|
||||
lem" (http:wyxs.net/web/wiimote/digital_whiteboard.html).
|
||||
|
||||
Power control over USB hubs is dependent on the particular hub
|
||||
devices, and disabling the power may not be possible for a sin‐
|
||||
gle USB port only. [4mwiiscan[24m uses a trick of disabling all USB
|
||||
hubs and then only enable and disable a singe hub.
|
||||
|
||||
Disabling all hubs is a precondition to running [4mwiiscan[24m and it
|
||||
can be accomblised by either going into "Control Panel | System
|
||||
| Hardware | Device manager", and manually disable all USB hubs
|
||||
or by using "devcon", say (careful, these commands applies only
|
||||
to my system)
|
||||
|
||||
devcon disable "@PCIN_8086&DEV_293*&SUB‐
|
||||
SYS_20F117AA&REV_033&B1BfB6*"
|
||||
|
||||
devcon disable "@PCIN_8086&DEV_293*&SUB‐
|
||||
SYS_20F017AA&REV_033&B1BfB6*"
|
||||
|
||||
being careful that the pattern matches only our USB hubs!. You
|
||||
can test this by
|
||||
|
||||
devcon status "@PCIN_8086&DEV_293*&SUB‐
|
||||
SYS_20F117AA&REV_033&B1BfB6*"
|
||||
|
||||
devcon status "@PCIN_8086&DEV_293*&SUB‐
|
||||
SYS_20F017AA&REV_033&B1BfB6*"
|
||||
|
||||
A single USB now may be enabled or disabled by
|
||||
|
||||
devcon disable @PCIN_8086*DEV_2934*SUBSYS_20F017AA*
|
||||
|
||||
again with the particular address for your system as a variable
|
||||
you need to lookup. The voltage on the USB bus can now be
|
||||
checked Using a voltmeter (see details in
|
||||
http:wyxs.net/web/wiimote/digital_whiteboard.html).
|
||||
|
||||
|
||||
NOTE: The configuration file of wiiscan contains the particular system
|
||||
dependent USB hub pattern matches.
|
||||
|
||||
|
||||
NOTE: be careful of connecting other devices to the USB bus, since the
|
||||
power cycle may cause severe interfere with the device.
|
||||
|
||||
|
||||
[1mDESCRIPTION[0m
|
||||
[1m-a <device>[0m
|
||||
auto-connect to a device.
|
||||
|
||||
|
||||
[1m-c <device>[0m
|
||||
connects to a device.
|
||||
|
||||
|
||||
[1m-d <device>[0m
|
||||
deletes a device, clears HID and bluetooth registry entries.
|
||||
|
||||
|
||||
[1m-r [22mlooks for active internal bluetooth radio devices.
|
||||
|
||||
|
||||
[1m-s [22mscans for external bluetooth devices.
|
||||
|
||||
|
||||
[1m-usbup [22mturn the USB hub on.
|
||||
|
||||
|
||||
[1m-usbdown[0m
|
||||
turn the USB hub off.
|
||||
|
||||
|
||||
Default mode: wiiscan -a " Nintendo RVL-CNT-01"
|
||||
|
||||
|
||||
Note: "nintendo" is a shortcut for "Nintendo RVL-CNT-01"
|
||||
|
||||
|
||||
[1mOPTIONS[0m
|
||||
[1m-cf <file>[0m
|
||||
load a specific configuration file.
|
||||
|
||||
|
||||
[1m-lf <file>[0m
|
||||
specify a distinct logfile.
|
||||
|
||||
|
||||
[1m-b <sleep>[0m
|
||||
auto-mode bluetooth connection sleep in milliseconds.
|
||||
|
||||
|
||||
[1m-t <sleep>[0m
|
||||
bluetooth scanning interval in milliseconds.
|
||||
|
||||
|
||||
[1m-u <sleep>[0m
|
||||
auto-mode USB connection sleep in milliseconds.
|
||||
|
||||
|
||||
[1m-p <sleep>[0m
|
||||
automode usbm post-connection sleep in milliseconds.
|
||||
|
||||
|
||||
[1m-w <sleep>[0m
|
||||
timeout for wiimote in milliseconds.
|
||||
|
||||
|
||||
[1m-q <usbradio>[0m
|
||||
use bluetooth radio with this address. Note, this functionality
|
||||
is not working yet.
|
||||
|
||||
|
||||
[1m-f <removemode>[0m
|
||||
pre-remove mode of device, 0=remove if not connectable,
|
||||
1=always remove, 2=never remove
|
||||
|
||||
|
||||
[1m-m <powermode>[0m
|
||||
choose USB powercycle mode, 0=no power cycle, 1=use USB hub,
|
||||
2=use USBm IO hardware, 3=use USB Delcon IO hardware.
|
||||
|
||||
|
||||
[1m-l <wiilibrary>[0m
|
||||
use specific wiimote library, lib can be one-of
|
||||
(wiiuse,wiimotelib).
|
||||
|
||||
|
||||
[1m-y [22mscan retries in automode.
|
||||
|
||||
|
||||
[1m-wb [22mstart whiteboard in auto-mode
|
||||
|
||||
|
||||
[1m-v [22menable extra debugging printouts
|
||||
|
||||
|
||||
[1mFILES[0m
|
||||
[4mwiiscan[24m looks for a file names wiiscan.ini when executing in the auto‐
|
||||
mode. See detail in the file.
|
||||
|
||||
[1mTIMING[0m
|
||||
Various timing parametes can be set on the command line or in the
|
||||
inifile. The process of connecting is
|
||||
|
||||
|
||||
1: USB power down
|
||||
|
||||
|
||||
2: Delete old HID entries
|
||||
|
||||
|
||||
3: Sleep at least option_usbsleep (from 1) before commencing
|
||||
|
||||
|
||||
4: USB power up
|
||||
|
||||
|
||||
5: Sleep at least option_usbmsleep (from 3) before commencing. Sleep is
|
||||
only nesseccary for USBmicro devices, since step 4 is much faster using
|
||||
this device compared to the USB hub.
|
||||
|
||||
|
||||
6: Find and wiimote and connect. Scan bluetooth the duration in
|
||||
option_timeout.
|
||||
|
||||
|
||||
7: Sleep option_btsleep before commencing; waiting for HID entries and
|
||||
new-hardware-found to finish in windows.
|
||||
|
||||
|
||||
8: Connect to the wiimote, Scan for wiimotes using the duration
|
||||
option_wiitimeout.
|
||||
|
||||
|
||||
[1mEXAMPLE[0m
|
||||
Scanning for devices nearby:
|
||||
|
||||
wiiscan -s
|
||||
|
||||
Auto-connect to a nintendo device, scan bluetooth for four seconds,
|
||||
verbose on, and enable start of whiteboard software after a successful
|
||||
connection
|
||||
|
||||
wiiscan -a nintendo -t 4000 -v -wb
|
||||
|
||||
Cycle USB bus voltage
|
||||
|
||||
wiiscan -usbdown
|
||||
|
||||
wiiscan -usbup
|
||||
|
||||
|
||||
[1mCOMPILING[0m
|
||||
The source code can be compiled with MS Visual C++ Express 2008
|
||||
(http:www.microsoft.com/express/vc/) or similar. It also needs wiiuse
|
||||
dlls (http:www.wiiuse.net/). If wiiuse is to be compiled by it self it
|
||||
needs Windows SDK and DDK, but running [4mwiiscan[24m with just the wiiuse
|
||||
binaries is the easiest option.
|
||||
|
||||
It does not work on Windows 2000, and has not been tried out on a Vista
|
||||
system.
|
||||
|
||||
|
||||
[1mTESTED SYSTEMS[0m
|
||||
The [4mwiiscan[24m has been tested on a Lenovo Thinkpad R500, XP professional
|
||||
(without build-in bluetooth) with a Trendnet TBW-102UB bluetooth don‐
|
||||
gle, and on a ASUS eeePC 1000H with XP home.
|
||||
|
||||
Only the MS bluetooth stack was tested.
|
||||
|
||||
|
||||
[1mLenovo setup[0m
|
||||
Windows XP professional, version 2002, SP2 USB dongle: Trendnet
|
||||
TBW-102UB bluetooth(Broadcom Ultimate Low Cost Bluetooth
|
||||
2.0+EDR USB), date 24-02-2004, driver 5.1.2535.0 Microsoft BT
|
||||
stack: date 03-08-2004, driver 5.1.2600.2180
|
||||
|
||||
|
||||
[1meee setup[0m
|
||||
Windows XP home, version 2002, SP3 USB dongle: buildin Azware
|
||||
BT252, date 13-04-2008, driver 5.1.2600.5512 Microsoft BT
|
||||
stack: date 13-04-2008, driver 5.1.2600.5512
|
||||
|
||||
|
||||
[1mBUGS[0m
|
||||
[1m1: restart pop-up (FIXED)[0m
|
||||
Installing new hardware causes windows to require restart. Hap‐
|
||||
pens once in a while, balloon pop-ups reports hardware, that
|
||||
where installed but not working properly. A restart pop-up
|
||||
wants to reboot the PC. Small fix: just delete the device and
|
||||
re-run "wiiscan -c nintendo".
|
||||
|
||||
FIX: the 'Change of systemsettings ... Do you want to reboot
|
||||
now?' popup, happens only when the program runs for longer than
|
||||
19 seconds. Keeping the connection time within 19 sec seems to
|
||||
cure the problem, Adding a sleep at the end of the program, say
|
||||
Sleep(20000) will eventually bring up the dialog again. The
|
||||
dialog can anyway safly be ignored!
|
||||
|
||||
|
||||
[1m2: discoverable mode fast shutdown (FIXED)[0m
|
||||
Sometimes the wiimote goes quickly out of discoverable mode, it
|
||||
takes it only about 3 seconds from turn-on to turn-off. This
|
||||
makes it hard to obtain a connection to it. Both my wiimotes
|
||||
does this once in a while, after failed connection attempts.
|
||||
|
||||
Pressing one button only "1" or "2" makes the wiimote blink for
|
||||
a short time, but it is not really discoverable.
|
||||
|
||||
FIX: Initialization of wiilib has been rewritten, making it
|
||||
recall the HID inialization routine. Code for testing the
|
||||
wiimote connection has also been introduced.
|
||||
|
||||
|
||||
[1m3: buttons not working (OPEN)[0m
|
||||
Pressing the 1-2 button combination sometimes fails to turn-on
|
||||
the wiimote, pressing sync or power makes it work again. The
|
||||
the "1-2 button freeze" happens after a failed connection
|
||||
attempt. See also bug-2.
|
||||
|
||||
|
||||
[1m4: radio null (OPEN)[0m
|
||||
Sometimes the BT radio fails to reinitialize after a USB
|
||||
down/up flip, this means that "RadioInfo(time‐
|
||||
out,true,dbg)"return NULL. Can be fixed by placing the blue‐
|
||||
tooth radio device on another bus than the USB.
|
||||
|
||||
|
||||
[1m5: keep blinking (OPEN)[0m
|
||||
Sometimes the wiimote is found and connected OK, but the LEDs
|
||||
keeps blinking (normal connect mode: LEDs are turned perma‐
|
||||
nently on). This does however not affect connectability, and
|
||||
the wiimote does not turn off again automatically.
|
||||
|
||||
|
||||
[1m6: failed to find wiimote (OPEN)[0m
|
||||
Wiimote failed to find devices. This may be a non-fatal error
|
||||
or an error caused by an undervolted wiimote. The
|
||||
"wiiuse_find(0x0,4,2/4/6)" keeps returning 0.
|
||||
|
||||
|
||||
[1m7: remove failed (OPEN)[0m
|
||||
Sometimes the remove steps fails, but this may be non-fatal
|
||||
|
||||
Removing device <Nintendo RVL-CNT-01>
|
||||
** error: failed to find device
|
||||
Done [FAILED]
|
||||
|
||||
|
||||
[1m8; balloon-tips (FIXED)[0m
|
||||
Balloon-tips are annoying when connecting new hardware. Small
|
||||
fix: do
|
||||
|
||||
Windows Registry Editor Version 5.00
|
||||
|
||||
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVer‐
|
||||
sion\Explorer1]
|
||||
"EnableBalloonTips"=dword:00000000
|
||||
|
||||
|
||||
[1m9: double delete (FIXED)[0m
|
||||
Double delete of nintendo device may cause BluetoothFindFirst‐
|
||||
Device() to return null Fixed by removing the throw, replacing
|
||||
it with a "if (hbf()==NULL) then return false"
|
||||
|
||||
|
||||
[1m10: BSoD (OPEN)[0m
|
||||
The "Blue Screen of Death" was encountered a number of times,
|
||||
indicating a errorneous device driver. The cause may be in the
|
||||
MS bluetooth stack or in the wiiuse lib. The BSoD mainly
|
||||
occured in the first phase of this project and havent been seen
|
||||
for a while with the current version (v0.7).
|
||||
|
||||
Only happens for MS bluetooth stack version "Microsoft BT
|
||||
stack: date 03-08-2004, driver 5.1.2600.2180" (Lenovo version).
|
||||
|
||||
|
||||
[1m11: New Hardware found wizard (OPEN)[0m
|
||||
Sometimes the wizard appears out of the blue, when deleting the
|
||||
HID entry and trying to reinstall it. It is the call Bluetooth‐
|
||||
SetServiceState(...) that messes the Window system up. Dis‐
|
||||
abling the wizard or disabling the Plug and play system do not
|
||||
seem to be an option, since the HID then newer get installed,
|
||||
and ends up in a failty state. A reboot of the system does not
|
||||
cure this defect.
|
||||
|
||||
|
||||
[1m12: Devcon hangs (FIXED)[0m
|
||||
The devcon commands sometimes hangs at the diable USB command.
|
||||
The state of the USB controllers, and BT devices are undefined
|
||||
(some BT devices disabled, others not) and manually trying to
|
||||
disable or enable the USB constroller fails. A status on the
|
||||
USB device gives a strange result.
|
||||
|
||||
FIX: reboot the machine.
|
||||
|
||||
|
||||
[1m13: Open Device fails to find a Nintendo (PARTLY FIXED)[0m
|
||||
When opening a named nintendo device, say 'Nintendo RVL-
|
||||
CNT-01', the bluetooth fails to get the name from the device.
|
||||
This results in an empty name, and hence matching on the name
|
||||
fails.
|
||||
|
||||
FIX: use a device adresss instead of a name. Put, say
|
||||
'allowed_wiimote_adr=00:19:FD:CC:60:61 00:19:1D:D6:65:E5' in
|
||||
the ini file.
|
||||
|
||||
|
||||
[1m14: Wiiscan fails to run (FIXED)[0m
|
||||
Running wiiscan in a dosbox makes it terminate immidiatly. Run‐
|
||||
ning the tray version, or under MS VS Express causes it to dis‐
|
||||
play an missing DLL dialog (msvcp90.dll and friends).
|
||||
|
||||
FIX: this is a MS bug, but can be fixed by setting the MT
|
||||
library in the project setting to use static libraries instead
|
||||
of dynamic DLLs.
|
||||
|
||||
|
||||
[1m15: BluetoothFindFirstDevice() stalls (FIXED)[0m
|
||||
The BluetoothFindFirstDevice() sometimes newer returns. Happens
|
||||
only for MS stack version "Microsoft BT stack: date 13-04-2008,
|
||||
driver 5.1.2600.5512" (eee stack).
|
||||
|
||||
Code stalls here:
|
||||
|
||||
DeviceAutoClose<HBLUETOOTH_DEVICE_FIND,BOOL> hbf(BluetoothFind‐
|
||||
FirstDevice(&bdsp,&bdi),&BluetoothFindDeviceClose);
|
||||
|
||||
FIX: start the BluetoothFindFirstDevice() function in a thread,
|
||||
terminate the thread if it has run for longer than, say 2+time‐
|
||||
out.
|
||||
|
||||
|
||||
[1m16: Wiimote drops connection after scanning (PARTLY FIXED)[0m
|
||||
If a connection attempt goes well until the last part, it is
|
||||
most likely due to low-power batteries. The final stage of con‐
|
||||
necting draw extra power, that might cause the wiimote to shut‐
|
||||
down.
|
||||
|
||||
|
||||
[1mSEE ALSO[0m
|
||||
[1mwiiuse [22mWiiuse 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.
|
||||
|
||||
Licensed under GNU GPLv3 and GNU LGPLv3 (non-commercial) by
|
||||
Michael Laforest,
|
||||
|
||||
(http:www.wiiuse.net/)
|
||||
|
||||
|
||||
[1mWiimote Whiteboard[0m
|
||||
|
||||
Whiteboard software by Johnny Chung Lee.
|
||||
|
||||
(http:www.cs.cmu.edu/~johnny/projects/wii/,
|
||||
http:www.wiimoteproject.com/)
|
||||
|
||||
|
||||
[1mdevcon(1)[0m
|
||||
|
||||
USB management software.
|
||||
|
||||
(http:support.microsoft.com/kb/311272)
|
||||
|
||||
|
||||
[1mVERSION[0m
|
||||
Version 0.9 NDEBUG
|
||||
|
||||
|
||||
[1mAUTHOR[0m
|
||||
Carsten Frigaard, Mergeit ApS, Kongsvang Allé 37, DK-8000 Århus C,
|
||||
www.mergit.dk
|
||||
|
||||
|
||||
[1mCOPYRIGHT[0m
|
||||
Copyright © 2009 MergeIt, Aps. License LGPL3 : GNU lesser GPL, version
|
||||
3, <http:www.gnu.org/licenses/lgpl.txt>. This is free software: you are
|
||||
free to change and redistribute it. There is NO WARRANTY, to the extent
|
||||
permitted by law.
|
||||
|
||||
|
||||
|
||||
26 Mar 2009 wiiscan(1)
|
||||
25
vendor/wiiscan/0.90/Doc/README.rtf
vendored
25
vendor/wiiscan/0.90/Doc/README.rtf
vendored
@@ -1,25 +0,0 @@
|
||||
Copyright © 2008 MergeIt, Aps.
|
||||
License GPLv3+: GNU GPL version 3 or later <http:\/\/gnu.org/licenses/gpl.html>.
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
the above copyright notice appear in all copies and that both that copyright notice
|
||||
and this permission notice appear in supporting documentation.
|
||||
|
||||
WIISCAN:
|
||||
a connection utility for wii console remotes
|
||||
|
||||
VERSION:
|
||||
0.9
|
||||
|
||||
INSTALL:
|
||||
just run Release/wiiscan or Release/wiiscantray
|
||||
|
||||
DOC:
|
||||
read wiiscan.1 ("man ./wiiscan.1" or "more wiiscan.1.txt")
|
||||
|
||||
NOTE:
|
||||
modify the Release/wiiscan.ini file according to the USB hub device remarks in the documentation before runnnig wiiscan!
|
||||
|
||||
30
vendor/wiiscan/0.90/Doc/README_FIRST.rtf
vendored
30
vendor/wiiscan/0.90/Doc/README_FIRST.rtf
vendored
@@ -1,30 +0,0 @@
|
||||
Copyright © 2008 MergeIt, Aps.
|
||||
License GPLv3+: GNU GPL version 3 or later <http:\/\/gnu.org/licenses/gpl.html>.
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
the above copyright notice appear in all copies and that both that copyright notice
|
||||
and this permission notice appear in supporting documentation.
|
||||
|
||||
WIISCAN:
|
||||
a connection utility for wii console remotes
|
||||
|
||||
VERSION:
|
||||
0.9
|
||||
|
||||
INSTALL:
|
||||
just run bin/Release/wiiscantray
|
||||
|
||||
PREREQUISITES:
|
||||
.NET framework 3.5
|
||||
Windows XP or above.
|
||||
Microsoft Bluetooth stack.
|
||||
|
||||
NOTE:
|
||||
1: Modify the Release/wiiscan.ini file according to the USB hub device remarks in
|
||||
the documentation before runnnig wiiscan!
|
||||
2: If you are running a non-Microsoft Bluetooth stack (like Widcomm ),
|
||||
you must follow the procedure found in the document doc/CHANGEINGBTSTACK.rtf
|
||||
|
||||
358
vendor/wiiscan/0.90/Doc/wiiscan.1
vendored
358
vendor/wiiscan/0.90/Doc/wiiscan.1
vendored
@@ -1,358 +0,0 @@
|
||||
|
||||
.TH wiiscan 1 "26 Mar 2009"
|
||||
|
||||
.SH NAME
|
||||
|
||||
\fIwiiscan\fP - a connection utility for wii console remotes
|
||||
|
||||
.SH SYNOPSIS
|
||||
|
||||
wiiscan <-a <device> | -c <device> | -d <device> | -r | -s | -usbup | -usbdown> > [-cf <file>] [-lf <file>] [-b <sleep>] [-t <sleep>] [-u <sleep>] [-p <sleep>] [-w <sleep>] [-q <usbradio>] [-f <removemode>] [-m <powermode>] [-l <wiilibrary>] [-wb] [-v]
|
||||
|
||||
.SH OVERVIEW
|
||||
|
||||
\fIwiiscan\fP is a canvas function for a number of different scanning and connection utilities. It can detect build-in bluetooth radios, scan for nearby bluetooth devices, connect to a specific device and remove that device again from the hardware.
|
||||
|
||||
The main feature of \fIwiiscan\fP is to automatically connect to a wii remote (wiimote). This can be quiet cumbersome on a Windows system, and the nesseccary steps for doing a robust, working connection is done by
|
||||
|
||||
.TP 8
|
||||
.B Delete wiimote hardware HID bluetooth entry:
|
||||
delete old entries of the wiimote in the bluetooth hardware. On some windows system the wiimote is readily detected, after the first manually installation. Pressing the "1-2" makes the wiimote discoverable. On other systems (including mine), any attempt to connect to the wiimote, after one successful or un-successful connection attempt, will always fail! Removing the HID and wiimote registry entries before the next attempt cures this feature.
|
||||
|
||||
.TP 8
|
||||
.B Cycle USB bus:
|
||||
the wiimote can be switched automatically to discoverable mode, if the power is briefly cut from the device. This can be done on a wiimote powered by the USB +5 volt (with a proper voltage regulator to bring it under +3 volt). This step hence turns the USB hub off, killing the power, and turns it on again. The "1-2" buttons on the wiimote must be pressed at all times, done by say some tape or gaffa!.
|
||||
|
||||
.TP 8
|
||||
.B Scan for wiimote:
|
||||
now comes the main part of the connection; scanning for a wiimote. This includes bringing up the bluetooth radio device, initialize seek parameters, scanning and matching for a device name or address, connecting to a matched device, installing the HID interface (that was removed in the first step), and finally trying to open the wiimote and reading some data from it. All steps involve a time variable, meaning that say installing the HID causes some windows registry fiddling, that takes a rather variable amount of time, and the next step is critically dependent on the former step to be finished. Hence a number of tunable waiting variable is introduced, Important is to being able to reach the final connection step before the wiimote goes out of the discoverable mode and automatically turns off.
|
||||
|
||||
.TP 8
|
||||
A note on USB voltage cycling:
|
||||
This software solution is able to restart the wiimote in discoverable mode automatically. But this require that the wiimote is powered by a USB cable to the PC and that the "1-2" button combination is permanently pressed. Cycling the power for the wiimote with the "1-2" buttons pressed enables the discoverable mode, and the continuously pressing "1-2" does not interfere with wiimote operations hereafter.
|
||||
|
||||
So this is a non-intrusive fix to the so called "Ladder problem" (http:\/\/wyxs.net/web/wiimote/digital_whiteboard.html).
|
||||
|
||||
Power control over USB hubs is dependent on the particular hub devices, and disabling the power may not be possible for a single USB port only. \fIwiiscan\fP uses a trick of disabling all USB hubs and then only enable and disable a singe hub.
|
||||
|
||||
Disabling all hubs is a precondition to running \fIwiiscan\fP and it can be accomblised by either going into "Control Panel | System | Hardware | Device manager", and manually disable all USB hubs or by using "devcon", say (careful, these commands applies only to my system)
|
||||
|
||||
devcon disable "@PCI\VEN_8086&DEV_293*&SUBSYS_20F117AA&REV_03\3&B1BfB6*"
|
||||
|
||||
devcon disable "@PCI\VEN_8086&DEV_293*&SUBSYS_20F017AA&REV_03\3&B1BfB6*"
|
||||
|
||||
being careful that the pattern matches only our USB hubs!. You can test this by
|
||||
|
||||
devcon status "@PCI\VEN_8086&DEV_293*&SUBSYS_20F117AA&REV_03\3&B1BfB6*"
|
||||
|
||||
devcon status "@PCI\VEN_8086&DEV_293*&SUBSYS_20F017AA&REV_03\3&B1BfB6*"
|
||||
|
||||
A single USB now may be enabled or disabled by
|
||||
|
||||
devcon disable @PCI\VEN_8086*DEV_2934*SUBSYS_20F017AA*
|
||||
|
||||
again with the particular address for your system as a variable you need to lookup. The voltage on the USB bus can now be checked Using a voltmeter (see details in http:\/\/wyxs.net/web/wiimote/digital_whiteboard.html).
|
||||
|
||||
.TP 8
|
||||
NOTE: The configuration file of wiiscan contains the particular system dependent USB hub pattern matches.
|
||||
|
||||
.TP 8
|
||||
NOTE: be careful of connecting other devices to the USB bus, since the power cycle may cause severe interfere with the device.
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
.TP 8
|
||||
.B -a <device>
|
||||
auto-connect to a device.
|
||||
|
||||
.TP 8
|
||||
.B -c <device>
|
||||
connects to a device.
|
||||
|
||||
.TP 8
|
||||
.B -d <device>
|
||||
deletes a device, clears HID and bluetooth registry entries.
|
||||
|
||||
.TP 8
|
||||
.B -r
|
||||
looks for active internal bluetooth radio devices.
|
||||
|
||||
.TP 8
|
||||
.B -s
|
||||
scans for external bluetooth devices.
|
||||
|
||||
.TP 8
|
||||
.B -usbup
|
||||
turn the USB hub on.
|
||||
|
||||
.TP 8
|
||||
.B -usbdown
|
||||
turn the USB hub off.
|
||||
|
||||
.TP 8
|
||||
Default mode: wiiscan -a " Nintendo RVL-CNT-01"
|
||||
|
||||
.TP 8
|
||||
Note: "nintendo" is a shortcut for "Nintendo RVL-CNT-01"
|
||||
|
||||
.SH OPTIONS
|
||||
|
||||
.TP 8
|
||||
.B -cf <file>
|
||||
load a specific configuration file.
|
||||
|
||||
.TP 8
|
||||
.B -lf <file>
|
||||
specify a distinct logfile.
|
||||
|
||||
.TP 8
|
||||
.B -b <sleep>
|
||||
auto-mode bluetooth connection sleep in milliseconds.
|
||||
|
||||
.TP 8
|
||||
.B -t <sleep>
|
||||
bluetooth scanning interval in milliseconds.
|
||||
|
||||
.TP 8
|
||||
.B -u <sleep>
|
||||
auto-mode USB connection sleep in milliseconds.
|
||||
|
||||
.TP 8
|
||||
.B -p <sleep>
|
||||
automode usbm post-connection sleep in milliseconds.
|
||||
|
||||
.TP 8
|
||||
.B -w <sleep>
|
||||
timeout for wiimote in milliseconds.
|
||||
|
||||
.TP 8
|
||||
.B -q <usbradio>
|
||||
use bluetooth radio with this address. Note, this functionality is not working yet.
|
||||
|
||||
.TP 8
|
||||
.B -f <removemode>
|
||||
pre-remove mode of device, 0=remove if not connectable, 1=always remove, 2=never remove
|
||||
|
||||
.TP 8
|
||||
.B -m <powermode>
|
||||
choose USB powercycle mode, 0=no power cycle, 1=use USB hub, 2=use USBm IO hardware, 3=use USB Delcon IO hardware.
|
||||
|
||||
.TP 8
|
||||
.B -l <wiilibrary>
|
||||
use specific wiimote library, lib can be one-of (wiiuse,wiimotelib).
|
||||
|
||||
.TP 8
|
||||
.B -y
|
||||
scan retries in automode.
|
||||
|
||||
.TP 8
|
||||
.B -wb
|
||||
start whiteboard in auto-mode
|
||||
|
||||
.TP 8
|
||||
.B -v
|
||||
enable extra debugging printouts
|
||||
|
||||
.SH FILES
|
||||
|
||||
\fIwiiscan\fP looks for a file names wiiscan.ini when executing in the automode. See detail in the file.
|
||||
.SH TIMING
|
||||
|
||||
Various timing parametes can be set on the command line or in the inifile. The process of connecting is
|
||||
|
||||
.TP 8
|
||||
1: USB power down
|
||||
|
||||
.TP 8
|
||||
2: Delete old HID entries
|
||||
|
||||
.TP 8
|
||||
3: Sleep at least option_usbsleep (from 1) before commencing
|
||||
|
||||
.TP 8
|
||||
4: USB power up
|
||||
|
||||
.TP 8
|
||||
5: Sleep at least option_usbmsleep (from 3) before commencing. Sleep is only nesseccary for USBmicro devices, since step 4 is much faster using this device compared to the USB hub.
|
||||
|
||||
.TP 8
|
||||
6: Find and wiimote and connect. Scan bluetooth the duration in option_timeout.
|
||||
|
||||
.TP 8
|
||||
7: Sleep option_btsleep before commencing; waiting for HID entries and new-hardware-found to finish in windows.
|
||||
|
||||
.TP 8
|
||||
8: Connect to the wiimote, Scan for wiimotes using the duration option_wiitimeout.
|
||||
|
||||
.SH EXAMPLE
|
||||
Scanning for devices nearby:
|
||||
|
||||
wiiscan -s
|
||||
|
||||
Auto-connect to a nintendo device, scan bluetooth for four seconds, verbose on, and enable start of whiteboard software after a successful connection
|
||||
|
||||
wiiscan -a nintendo -t 4000 -v -wb
|
||||
|
||||
Cycle USB bus voltage
|
||||
|
||||
wiiscan -usbdown
|
||||
|
||||
wiiscan -usbup
|
||||
|
||||
.SH COMPILING
|
||||
|
||||
The source code can be compiled with MS Visual C++ Express 2008 (http:\/\/www.microsoft.com/express/vc/) or similar. It also needs wiiuse dlls (http:\/\/www.wiiuse.net/). If wiiuse is to be compiled by it self it needs Windows SDK and DDK, but running \fIwiiscan\fP with just the wiiuse binaries is the easiest option.
|
||||
|
||||
It does not work on Windows 2000, and has not been tried out on a Vista system.
|
||||
|
||||
.SH TESTED SYSTEMS
|
||||
|
||||
The \fIwiiscan\fP has been tested on a Lenovo Thinkpad R500, XP professional (without build-in bluetooth) with a Trendnet TBW-102UB bluetooth dongle, and on a ASUS eeePC 1000H with XP home.
|
||||
|
||||
Only the MS bluetooth stack was tested.
|
||||
|
||||
.TP 8
|
||||
.B Lenovo setup
|
||||
Windows XP professional, version 2002, SP2
|
||||
USB dongle: Trendnet TBW-102UB bluetooth(Broadcom Ultimate Low Cost Bluetooth 2.0+EDR USB), date 24-02-2004, driver 5.1.2535.0
|
||||
Microsoft BT stack: date 03-08-2004, driver 5.1.2600.2180
|
||||
|
||||
.TP 8
|
||||
.B eee setup
|
||||
Windows XP home, version 2002, SP3
|
||||
USB dongle: buildin Azware BT252, date 13-04-2008, driver 5.1.2600.5512
|
||||
Microsoft BT stack: date 13-04-2008, driver 5.1.2600.5512
|
||||
|
||||
.SH BUGS
|
||||
|
||||
.TP 8
|
||||
.B 1: restart pop-up (FIXED)
|
||||
Installing new hardware causes windows to require restart. Happens once in a while, balloon pop-ups reports hardware, that where installed but not working properly. A restart pop-up wants to reboot the PC. Small fix: just delete the device and re-run "wiiscan -c nintendo".
|
||||
|
||||
FIX: the 'Change of systemsettings ... Do you want to reboot now?' popup, happens only when the program runs for longer than 19 seconds. Keeping the connection time within 19 sec seems to cure the problem, Adding a sleep at the end of the program, say Sleep(20000) will eventually bring up the dialog again. The dialog can anyway safly be ignored!
|
||||
|
||||
.TP 8
|
||||
.B 2: discoverable mode fast shutdown (FIXED)
|
||||
Sometimes the wiimote goes quickly out of discoverable mode, it takes it only about 3 seconds from turn-on to turn-off. This makes it hard to obtain a connection to it. Both my wiimotes does this once in a while, after failed connection attempts.
|
||||
|
||||
Pressing one button only "1" or "2" makes the wiimote blink for a short time, but it is not really discoverable.
|
||||
|
||||
FIX: Initialization of wiilib has been rewritten, making it recall the HID inialization routine. Code for testing the wiimote connection has also been introduced.
|
||||
|
||||
.TP 8
|
||||
.B 3: buttons not working (OPEN)
|
||||
Pressing the 1-2 button combination sometimes fails to turn-on the wiimote, pressing sync or power makes it work again. The the "1-2 button freeze" happens after a failed connection attempt. See also bug-2.
|
||||
|
||||
.TP 8
|
||||
.B 4: radio null (OPEN)
|
||||
Sometimes the BT radio fails to reinitialize after a USB down/up flip, this means that "RadioInfo(timeout,true,dbg)"return NULL. Can be fixed by placing the bluetooth radio device on another bus than the USB.
|
||||
|
||||
.TP 8
|
||||
.B 5: keep blinking (OPEN)
|
||||
Sometimes the wiimote is found and connected OK, but the LEDs keeps blinking (normal connect mode:
|
||||
LEDs are turned permanently on). This does however not affect connectability, and the wiimote does not turn off again automatically.
|
||||
|
||||
.TP 8
|
||||
.B 6: failed to find wiimote (OPEN)
|
||||
Wiimote failed to find devices. This may be a non-fatal error or an error caused by an undervolted wiimote. The "wiiuse_find(0x0,4,2/4/6)" keeps returning 0.
|
||||
|
||||
.TP 8
|
||||
.B 7: remove failed (OPEN)
|
||||
Sometimes the remove steps fails, but this may be non-fatal
|
||||
|
||||
Removing device <Nintendo RVL-CNT-01>
|
||||
** error: failed to find device
|
||||
Done [FAILED]
|
||||
|
||||
.TP 8
|
||||
.B 8; balloon-tips (FIXED)
|
||||
Balloon-tips are annoying when connecting new hardware. Small fix: do
|
||||
|
||||
Windows Registry Editor Version 5.00
|
||||
|
||||
[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\Advanced]
|
||||
"EnableBalloonTips"=dword:00000000
|
||||
|
||||
.TP 8
|
||||
.B 9: double delete (FIXED)
|
||||
Double delete of nintendo device may cause BluetoothFindFirstDevice() to return null Fixed by removing the throw, replacing it with a "if (hbf()==NULL) then return false"
|
||||
|
||||
.TP 8
|
||||
.B 10: BSoD (OPEN)
|
||||
The "Blue Screen of Death" was encountered a number of times, indicating a errorneous device driver. The cause may be in the MS bluetooth stack or in the wiiuse lib. The BSoD mainly occured in the first phase of this project and havent been seen for a while with the current version (v0.7).
|
||||
|
||||
Only happens for MS bluetooth stack version "Microsoft BT stack: date 03-08-2004, driver 5.1.2600.2180" (Lenovo version).
|
||||
|
||||
.TP 8
|
||||
.B 11: New Hardware found wizard (OPEN)
|
||||
Sometimes the wizard appears out of the blue, when deleting the HID entry and trying to reinstall it. It is the call BluetoothSetServiceState(...) that messes the Window system up. Disabling the wizard or disabling the Plug and play system do not seem to be an option, since the HID then newer get installed, and ends up in a failty state. A reboot of the system does not cure this defect.
|
||||
|
||||
.TP 8
|
||||
.B 12: Devcon hangs (FIXED)
|
||||
The devcon commands sometimes hangs at the diable USB command. The state of the USB controllers, and BT devices are undefined (some BT devices disabled, others not) and manually trying to disable or enable the USB constroller fails. A status on the USB device gives a strange result.
|
||||
|
||||
FIX: reboot the machine.
|
||||
|
||||
.TP 8
|
||||
.B 13: Open Device fails to find a Nintendo (PARTLY FIXED)
|
||||
When opening a named nintendo device, say 'Nintendo RVL-CNT-01', the bluetooth fails to get the name from the device. This results in an empty name, and hence matching on the name fails.
|
||||
|
||||
FIX: use a device adresss instead of a name. Put, say 'allowed_wiimote_adr=00:19:FD:CC:60:61 00:19:1D:D6:65:E5' in the ini file.
|
||||
|
||||
.TP 8
|
||||
.B 14: Wiiscan fails to run (FIXED)
|
||||
Running wiiscan in a dosbox makes it terminate immidiatly. Running the tray version, or under MS VS Express causes it to display an missing DLL dialog (msvcp90.dll and friends).
|
||||
|
||||
FIX: this is a MS bug, but can be fixed by setting the MT library in the project setting to use static libraries instead of dynamic DLLs.
|
||||
|
||||
.TP 8
|
||||
.B 15: BluetoothFindFirstDevice() stalls (FIXED)
|
||||
The BluetoothFindFirstDevice() sometimes newer returns. Happens only for MS stack version
|
||||
"Microsoft BT stack: date 13-04-2008, driver 5.1.2600.5512" (eee stack).
|
||||
|
||||
Code stalls here:
|
||||
|
||||
DeviceAutoClose<HBLUETOOTH_DEVICE_FIND,BOOL> hbf(BluetoothFindFirstDevice(&bdsp,&bdi),&BluetoothFindDeviceClose);
|
||||
|
||||
FIX: start the BluetoothFindFirstDevice() function in a thread, terminate the thread if it has run for longer than, say 2+timeout.
|
||||
|
||||
.TP 8
|
||||
.B 16: Wiimote drops connection after scanning (PARTLY FIXED)
|
||||
If a connection attempt goes well until the last part, it is most likely due to low-power batteries. The final stage of connecting draw extra power, that might cause the wiimote to shutdown.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
.TP 8
|
||||
.B wiiuse
|
||||
|
||||
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.
|
||||
|
||||
Licensed under GNU GPLv3 and GNU LGPLv3 (non-commercial) by Michael Laforest,
|
||||
|
||||
(http:\/\/www.wiiuse.net/)
|
||||
|
||||
.TP 8
|
||||
.B Wiimote Whiteboard
|
||||
|
||||
Whiteboard software by Johnny Chung Lee.
|
||||
|
||||
(http:\/\/www.cs.cmu.edu/~johnny/projects/wii/, http:\/\/www.wiimoteproject.com/)
|
||||
|
||||
.TP 8
|
||||
.B devcon(1)
|
||||
|
||||
USB management software.
|
||||
|
||||
(http:\/\/support.microsoft.com/kb/311272)
|
||||
|
||||
.SH VERSION
|
||||
|
||||
Version 0.9 NDEBUG
|
||||
|
||||
.SH AUTHOR
|
||||
|
||||
Carsten Frigaard, Mergeit ApS, Kongsvang Allé 37, DK-8000 Århus C, www.mergit.dk
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright © 2009 MergeIt, Aps. License LGPL3 : GNU lesser GPL, version 3, <http:www.gnu.org/licenses/lgpl.txt>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
|
||||
BIN
vendor/wiiscan/0.90/Lib/Debug/WiimoteLib.dll
vendored
BIN
vendor/wiiscan/0.90/Lib/Debug/WiimoteLib.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/Debug/WiimoteWhiteboard.exe
vendored
BIN
vendor/wiiscan/0.90/Lib/Debug/WiimoteWhiteboard.exe
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/Debug/wiimotelibpoll.exe
vendored
BIN
vendor/wiiscan/0.90/Lib/Debug/wiimotelibpoll.exe
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/DelcomDLL.dll
vendored
BIN
vendor/wiiscan/0.90/Lib/DelcomDLL.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/DelcomDLL.lib
vendored
BIN
vendor/wiiscan/0.90/Lib/DelcomDLL.lib
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/Release/WiimoteLib.dll
vendored
BIN
vendor/wiiscan/0.90/Lib/Release/WiimoteLib.dll
vendored
Binary file not shown.
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/Release/wiimotelibpoll.exe
vendored
BIN
vendor/wiiscan/0.90/Lib/Release/wiimotelibpoll.exe
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/USBm.dll
vendored
BIN
vendor/wiiscan/0.90/Lib/USBm.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/wiiuse.dll
vendored
BIN
vendor/wiiscan/0.90/Lib/wiiuse.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Lib/wiiuse.lib
vendored
BIN
vendor/wiiscan/0.90/Lib/wiiuse.lib
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Release/DelcomDLL.dll
vendored
BIN
vendor/wiiscan/0.90/Release/DelcomDLL.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Release/USBm.dll
vendored
BIN
vendor/wiiscan/0.90/Release/USBm.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Release/WiimoteLib.dll
vendored
BIN
vendor/wiiscan/0.90/Release/WiimoteLib.dll
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Release/wiimotelibpoll.exe
vendored
BIN
vendor/wiiscan/0.90/Release/wiimotelibpoll.exe
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Release/wiiscan.exe
vendored
BIN
vendor/wiiscan/0.90/Release/wiiscan.exe
vendored
Binary file not shown.
81
vendor/wiiscan/0.90/Release/wiiscan.ini
vendored
81
vendor/wiiscan/0.90/Release/wiiscan.ini
vendored
@@ -1,81 +0,0 @@
|
||||
% Configfile_begin
|
||||
% config file for wiiscan
|
||||
|
||||
% all usb device ids, not used yet in the scanning
|
||||
all_usb_hubs=""
|
||||
|
||||
% single power controlling usb hub, only nessesary when powerering over usb, for automatic resetting. If not used, put ""
|
||||
% active_usb_hub="@PCI\VEN_8086&DEV_2934&SUBSYS_20F017AA&REV_03\3&B1BFB68&0&E8"
|
||||
active_usb_hub=""
|
||||
|
||||
% a list of allowed wiimotes in the form xx:xx:xx:xx:xx:xx, wildcard match is 00:00:00:00:00:00
|
||||
%allowed_wiimote_adr=00:00:00:00:00:00
|
||||
% my set of wiimotes
|
||||
allowed_wiimote_adr=00:19:?D:??:6?:?? 00:1F:C5:??:??:?? 00:17:AB:39:69:87
|
||||
|
||||
% launching exe file have a problem with spaces, hence renamed exe, replaced space with underscores
|
||||
% The original Johnny Chung Lee wb software version 0.3, downloaded from [http://johnnylee.net/projects/wii/]
|
||||
% may not work yet, missing library integration
|
||||
%whiteboard_software="d:/WiimoteWhiteboard/WiimoteWhiteboard_v0.3.exe"
|
||||
|
||||
% same stuff, but binary build from sources and redistributed in this package
|
||||
whiteboard_software="WiimoteWhiteboard.exe"
|
||||
|
||||
% Boon Jin's wb software version 0.6, does not work yet, missing library integration
|
||||
%whiteboard_software="d:/wsb/WiimoteSmoothboard.exe"
|
||||
|
||||
% wiiscan parameters
|
||||
%option_device="Nintendo RVL-CNT-01"
|
||||
|
||||
% number of bt scanning attempts in a autoscan, timout is increased for every scan as retryattempt*option_timeout
|
||||
option_scanretries=1
|
||||
|
||||
% long time (4000 and above, or increase option_scanretries) when matching name, short (1000-2000) when matching address
|
||||
option_timeout=4000
|
||||
|
||||
% wiimote scanning time, only applicable used for wiilib
|
||||
option_wiitimeout=1000
|
||||
|
||||
% delay bewteen powerdown/up, see man for details
|
||||
option_usbsleep=1000
|
||||
option_usbmsleep=1000
|
||||
%option_btsleep=2000
|
||||
|
||||
% start wb at successfull connect, 0 or 1
|
||||
option_startwhiteboard=1
|
||||
|
||||
% output verbose flag, 0 or 1
|
||||
option_debug=1
|
||||
|
||||
% logging output file, put nothing if no logging is wanted
|
||||
option_logfile=wiiscan_log.txt
|
||||
%option_logfile=
|
||||
|
||||
% wiimote connection library, use none, wiiuse, or wiimotelib
|
||||
option_wiilib=wiimotelib
|
||||
|
||||
% 0=no power cycle, 1=USB hub control, 2=USBm IO, 3=USB Devcon
|
||||
option_usbpowermode=3
|
||||
|
||||
% 0=remove if not connectable, 1=always remove, 2=never remove
|
||||
%option_forceremove=0
|
||||
|
||||
% bt radio to use, not working yet
|
||||
%option_btradio=00:50:B6:A0:48:8C
|
||||
|
||||
% wiiscantray options
|
||||
% number of connection attempts before autoscan i restarted
|
||||
option_tray_pool_retries=2
|
||||
|
||||
% retry sleep, keep it low (<1000) to catch an open connection
|
||||
option_tray_sleep_between_pool_retries=250
|
||||
|
||||
% sleep bewteen polls, when wiimote is succeful connected, keep it hight (>2000) to avoid to much CPU usage
|
||||
option_tray_sleep_between_pool_loops=2000
|
||||
|
||||
% final connection step reqires some sleep before windows PnP is ready
|
||||
option_sleep_before_final_connect=1500
|
||||
|
||||
% delay after launch of wb software, keep it at a medium value (2000-10000)
|
||||
option_sleep_after_startwhiteboard=4000
|
||||
% Configfile_end
|
||||
BIN
vendor/wiiscan/0.90/Release/wiiuse.dll
vendored
BIN
vendor/wiiscan/0.90/Release/wiiuse.dll
vendored
Binary file not shown.
2
vendor/wiiscan/0.90/Tools/disable_all_usb.sh
vendored
2
vendor/wiiscan/0.90/Tools/disable_all_usb.sh
vendored
@@ -1,2 +0,0 @@
|
||||
devcon disable "@PCI\VEN_8086&DEV_293*&SUBSYS_20F117AA&REV_03\3&B1BfB6*"
|
||||
devcon disable "@PCI\VEN_8086&DEV_293*&SUBSYS_20F017AA&REV_03\3&B1BfB6*"
|
||||
2
vendor/wiiscan/0.90/Tools/enable_all_usb.sh
vendored
2
vendor/wiiscan/0.90/Tools/enable_all_usb.sh
vendored
@@ -1,2 +0,0 @@
|
||||
devcon enable "@PCI\VEN_8086&DEV_293*&SUBSYS_20F117AA&REV_03\3&B1BfB6*"
|
||||
devcon enable "@PCI\VEN_8086&DEV_293*&SUBSYS_20F017AA&REV_03\3&B1BfB6*"
|
||||
10
vendor/wiiscan/0.90/Tools/no_error_report.reg
vendored
10
vendor/wiiscan/0.90/Tools/no_error_report.reg
vendored
@@ -1,10 +0,0 @@
|
||||
REGEDIT4
|
||||
|
||||
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealth\ErrorReporting]
|
||||
"AllOrNone"=dword:00000001
|
||||
"IncludeMicrosoftApps"=dword:00000001
|
||||
"IncludeWindowsApps"=dword:00000001
|
||||
"IncludeKernelFaults"=dword:00000001
|
||||
"DoReport"=dword:00000000
|
||||
"ShowUI"=dword:00000000
|
||||
|
||||
BIN
vendor/wiiscan/0.90/Tools/popup_disable.reg
vendored
BIN
vendor/wiiscan/0.90/Tools/popup_disable.reg
vendored
Binary file not shown.
BIN
vendor/wiiscan/0.90/Tools/popup_enable.reg
vendored
BIN
vendor/wiiscan/0.90/Tools/popup_enable.reg
vendored
Binary file not shown.
49
vendor/wiiscan/0.90/Tools/wiitest.sh
vendored
49
vendor/wiiscan/0.90/Tools/wiitest.sh
vendored
@@ -1,49 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
MODE=Release
|
||||
if [ $# = 1 ]; then
|
||||
MODE=$1
|
||||
echo using mode $MODE
|
||||
fi
|
||||
|
||||
N=0
|
||||
F=0
|
||||
S=0
|
||||
N_MAX=1000000
|
||||
OUTFILE=$MODE/wiitest.out
|
||||
|
||||
echo "##" Testing wiiscan... "(N_MAX="$N_MAX",OUTFILE="$OUTFILE",mode="$MODE")" | tee $OUTFILE
|
||||
echo -n "## date " | tee -a $OUTFILE
|
||||
date | tee -a $OUTFILE
|
||||
|
||||
while [ $N -lt $N_MAX ]; do
|
||||
let N=N+1
|
||||
echo "##" Loop $N " " | tee -a $OUTFILE
|
||||
echo -n "## date " | tee -a $OUTFILE
|
||||
date | tee -a $OUTFILE
|
||||
|
||||
rm -f $OUTFILE.tmp 2>/dev/null
|
||||
|
||||
pushd $MODE ; wiiscan -f -v -lf ../$OUTFILE.tmp 2>&1 ; R1=$? ; popd
|
||||
# pushd $MODE ; wiiscan -v -d nintendo -lf ../$OUTFILE.tmp ; R2=$? ; popd
|
||||
R2=0;
|
||||
|
||||
cat $OUTFILE.tmp >> $OUTFILE
|
||||
|
||||
if [ $R1 = 0 ]; then
|
||||
let S=S+1
|
||||
echo "##" Test succes $S | tee -a $OUTFILE
|
||||
else
|
||||
let F=F+1
|
||||
echo "##" Test failed $F | tee -a $OUTFILE
|
||||
fi
|
||||
|
||||
STATUS=$(echo $S*100/$N | bc)
|
||||
echo "##" Status $S/$N = $STATUS "%" | tee -a $OUTFILE
|
||||
echo "## (result R1="$R1 " R2="$R2 " S="$S " F="$F " N="$N ")" | tee -a $OUTFILE
|
||||
|
||||
sleep 4
|
||||
done
|
||||
|
||||
echo done | tee -a $OUTFILE
|
||||
exit 0
|
||||
128
vendor/wiiscan/0.90/src/DelcomDLL.h
vendored
128
vendor/wiiscan/0.90/src/DelcomDLL.h
vendored
@@ -1,128 +0,0 @@
|
||||
// Delcom Engineering
|
||||
// DelcomDLL.h
|
||||
// Version 0.6
|
||||
// 02/11/07
|
||||
|
||||
#ifndef DELCOMDLL_HEADER
|
||||
#define DELCOMDLL_HEADER 1
|
||||
|
||||
|
||||
// defines
|
||||
#define OFF 0
|
||||
#define ON 1
|
||||
#define FLASH 2
|
||||
|
||||
#define USBIODS 1
|
||||
#define USBDELVI 2
|
||||
#define USBNDSPY 3
|
||||
|
||||
#define GREENLED 0
|
||||
#define REDLED 1
|
||||
#define BLUELED 2
|
||||
|
||||
#define MaxDeviceLen 512
|
||||
|
||||
// Typedef
|
||||
typedef struct _DeviceNameStruct{
|
||||
char DeviceName[MaxDeviceLen];
|
||||
} DeviceNameStruct, *pDeviceNameStruct;
|
||||
|
||||
|
||||
typedef unsigned long DWORD;
|
||||
typedef int BOOL;
|
||||
typedef unsigned char BYTE;
|
||||
typedef char CHAR;
|
||||
typedef unsigned short WORD;
|
||||
typedef void * HANDLE;
|
||||
typedef CHAR *LPSTR, *PSTR;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned int uint;
|
||||
|
||||
typedef struct _PacketStruct{
|
||||
uchar Recipient;
|
||||
uchar DeviceModel;
|
||||
uchar MajorCmd;
|
||||
uchar MinorCmd;
|
||||
uchar DataLSB;
|
||||
uchar DataMSB;
|
||||
short Length;
|
||||
uchar ExtData[8];
|
||||
} PacketStruct,*pPacketStruct;
|
||||
|
||||
|
||||
|
||||
|
||||
// DLL Generic Functions
|
||||
HANDLE DelcomGetDLLHandle(void);
|
||||
double __stdcall DelcomGetDLLVersion(void);
|
||||
DWORD __stdcall DelcomGetDLLDate(LPSTR);
|
||||
DWORD __stdcall DelcomVerboseControl( DWORD Mode, LPSTR Header );
|
||||
|
||||
DWORD __stdcall DelcomGetNthDevice(DWORD, DWORD, LPSTR);
|
||||
DWORD __stdcall DelcomScanDevices( DWORD, DeviceNameStruct[], DWORD );
|
||||
HANDLE __stdcall DelcomOpenDevice( LPSTR, DWORD);
|
||||
DWORD __stdcall DelcomCloseDevice(HANDLE);
|
||||
DWORD __stdcall DelcomGetDeviceCount( DWORD Type );
|
||||
|
||||
DWORD __stdcall DelcomReadDeviceVersion(HANDLE );
|
||||
DWORD __stdcall DelcomReadDeviceSerialNum(LPSTR, HANDLE );
|
||||
DWORD __stdcall DelcomSendPacket( HANDLE, pPacketStruct, pPacketStruct);
|
||||
|
||||
|
||||
// USBDELVI - Visual Indicator Functions
|
||||
DWORD __stdcall DelcomLEDControl( HANDLE hFile, DWORD Color, DWORD Mode );
|
||||
DWORD __stdcall DelcomEnableAutoConfirm(HANDLE hUsb, DWORD Mode);
|
||||
DWORD __stdcall DelcomEnableAutoClear(HANDLE hUsb, DWORD Mode);
|
||||
DWORD __stdcall DelcomBuzzer(HANDLE hUsb, uchar Mode, uchar Freq, uchar Repeat, uchar OnTime, uchar OffTime);
|
||||
DWORD __stdcall DelcomLoadInitialPhaseDelay(HANDLE hUsb, BYTE Color, BYTE Delay);
|
||||
DWORD __stdcall DelcomSyncLeds(HANDLE hUsb);
|
||||
DWORD __stdcall DelcomLoadPreScalar(HANDLE hUsb, BYTE PreScalar);
|
||||
DWORD __stdcall DelcomLoadLedFreqDuty(HANDLE hUsb, BYTE Color, BYTE Low, BYTE High);
|
||||
DWORD __stdcall DelcomGetButtonStatus(HANDLE hUsb );
|
||||
DWORD __stdcall DelcomReadVersionNumber(HANDLE hUsb );
|
||||
DWORD __stdcall DelcomReadSerialNumber(HANDLE hUsb );
|
||||
DWORD __stdcall DelcomLEDPower( HANDLE hUsb, DWORD Color, DWORD Power );
|
||||
|
||||
|
||||
|
||||
// USBIODS - USB IO Functions
|
||||
DWORD __stdcall DelcomWritePortPin(HANDLE hUsb, BYTE Port, BYTE Pin, BYTE Value );
|
||||
DWORD __stdcall DelcomWritePorts(HANDLE hUsb, BYTE Port0, BYTE Port1 );
|
||||
DWORD __stdcall DelcomReadPorts(HANDLE hUsb, BYTE* Port0, BYTE* Port1 );
|
||||
|
||||
DWORD __stdcall DelcomWrite64Bit(HANDLE hUsb, LPSTR DataExt );
|
||||
DWORD __stdcall DelcomRead64Bit(HANDLE hUsb, LPSTR DataExt );
|
||||
|
||||
DWORD __stdcall DelcomWriteI2C(HANDLE hUsb, BYTE CmdAdd, BYTE Length, LPSTR DataExt );
|
||||
DWORD __stdcall DelcomReadI2C(HANDLE hUsb, BYTE CmdAdd, BYTE Length, LPSTR DataExt );
|
||||
DWORD __stdcall DelcomSelReadI2C(HANDLE hUsb, BYTE SetAddCmd, BYTE Address, BYTE ReadCmd, BYTE Length, LPSTR DataExt );
|
||||
DWORD __stdcall DelcomWriteI2CEEPROM(HANDLE hUsb, DWORD Address, DWORD Length, BYTE CtrlCode, BYTE WriteDelay, LPSTR pData );
|
||||
DWORD __stdcall DelcomReadI2CEEPROM(HANDLE hUsb, DWORD Address, DWORD Length, BYTE CtrlCode, LPSTR pData );
|
||||
|
||||
|
||||
DWORD __stdcall DelcomRS232Ctrl(HANDLE hUsb, DWORD Mode, DWORD Value );
|
||||
DWORD __stdcall DelcomWriteRS232(HANDLE hUsb, DWORD Length, LPSTR DataExt );
|
||||
DWORD __stdcall DelcomReadRS232(HANDLE hUsb, LPSTR DataExt );
|
||||
|
||||
// SPI Commands
|
||||
DWORD __stdcall DelcomSPIWrite( HANDLE hUsb, DWORD ClockCount, LPSTR pData);
|
||||
DWORD __stdcall DelcomSPISetClock( HANDLE hUsb, DWORD ClockPeriod );
|
||||
DWORD __stdcall DelcomSPIRead(HANDLE hUsb, LPSTR pData);
|
||||
DWORD __stdcall DelcomSPIWr8Read64( HANDLE hUsb, DWORD WrData, DWORD ClockCount, LPSTR pData);
|
||||
|
||||
|
||||
|
||||
// USBNDSPY Functions
|
||||
DWORD __stdcall DelcomNumericMode(HANDLE hUsb, BYTE Mode, BYTE Rate );
|
||||
DWORD __stdcall DelcomNumericScanRate(HANDLE hUsb, BYTE ScanRate );
|
||||
DWORD __stdcall DelcomNumericSetup(HANDLE hUsb, BYTE Digits );
|
||||
DWORD __stdcall DelcomNumericRaw(HANDLE hUsb, LPSTR Str );
|
||||
DWORD __stdcall DelcomNumericInteger(HANDLE hUsb, DWORD Number, DWORD Base );
|
||||
DWORD __stdcall DelcomNumericHexaDecimal(HANDLE hUsb, DWORD Number, DWORD Base );
|
||||
DWORD __stdcall DelcomNumericDouble(HANDLE hUsb, double Number, DWORD Base );
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
143
vendor/wiiscan/0.90/src/args.h
vendored
143
vendor/wiiscan/0.90/src/args.h
vendored
@@ -1,143 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __ARGS_H__
|
||||
#define __ARGS_H__
|
||||
|
||||
class args{
|
||||
private:
|
||||
typedef vector<string> t_args;
|
||||
t_args m_args;
|
||||
|
||||
void Remove(t_args::iterator itt1,int n)
|
||||
{
|
||||
t_args args2;
|
||||
for(t_args::iterator itt2=m_args.begin();itt2!=m_args.end();++itt2) {
|
||||
if(itt2!=itt1) args2.push_back(*itt2);
|
||||
else {if (--n>0) ++itt1;}
|
||||
}
|
||||
m_args=args2;
|
||||
}
|
||||
|
||||
t_args::iterator Find(const string& v)
|
||||
{
|
||||
for(t_args::iterator itt=m_args.begin();itt!=m_args.end();++itt) {
|
||||
if (v==*itt) return itt;
|
||||
}
|
||||
return m_args.end();
|
||||
}
|
||||
|
||||
t_args::const_iterator Find(const string& v) const
|
||||
{
|
||||
for(t_args::const_iterator itt=m_args.begin();itt!=m_args.end();++itt) {
|
||||
if (v==*itt) return itt;
|
||||
}
|
||||
return m_args.end();
|
||||
}
|
||||
|
||||
public:
|
||||
args(const int argc,char **argv,const bool printargs=false)
|
||||
{
|
||||
for(int i=0;i<argc;++i) {m_args.push_back(argv[i]);}
|
||||
if (printargs) cout << "% Call args: " << *this << endl;
|
||||
}
|
||||
|
||||
string operator[](const size_t i) const
|
||||
{
|
||||
if(i>=size()) throw_("argument[] out of range");
|
||||
return m_args[i];
|
||||
}
|
||||
|
||||
size_t size() const {return m_args.size();}
|
||||
bool hasopt(const string& tag) const {return Find(tag)!=m_args.end();}
|
||||
template<class T> T Totype(const size_t i) const {return totype<T>((*this)[i]);}
|
||||
template<class T> T Tounit(const size_t i) const {
|
||||
const string& s=(*this)[i+1];
|
||||
#ifndef USE_UNITS
|
||||
// fake test of units, primitive test, must be one-of: kpc, per_kpc and msun1E10
|
||||
if (s!="kpc/h" && s!="h/kpc" && s!="msun1E10/h") throw_("bad unit=<" + s + ">, can only handle units of type: kpc/h, h/kpc, and msun1E10/h");
|
||||
#endif
|
||||
return totype<T>((*this)[i] + " " + s);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T parseval(const string& tag,const T& defaultval)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end() || itt+1==m_args.end()) return defaultval;
|
||||
|
||||
const T v=totype<T>(*(++itt));
|
||||
Remove(--itt,2);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
template<class T,class R>
|
||||
pair<T,R> parseval(const string& tag,const T& defaultval1,const R& defaultval2)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end() || itt+1==m_args.end() || itt+2==m_args.end()) return make_pair(defaultval1,defaultval2);
|
||||
|
||||
const T v1=totype<T>(*(++itt));
|
||||
const R v2=totype<R>(*(++itt));
|
||||
Remove(----itt,3);
|
||||
|
||||
return make_pair(v1,v2);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T parseunit(const string& tag,const T& defaultval)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end() || itt+2==m_args.end()) return defaultval;
|
||||
|
||||
const string s1=*(++itt);
|
||||
const string s2=*(++itt);
|
||||
const T v=totype<T>(s1 + " " + s2);
|
||||
Remove(----itt,3);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
bool parseopt(const string& tag)
|
||||
{
|
||||
t_args::iterator itt=Find(tag);
|
||||
if (itt==m_args.end()) return false;
|
||||
Remove(itt,1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int getoptindex(const string& tag) const
|
||||
{
|
||||
int n=0;
|
||||
for(t_args::const_iterator itt=m_args.begin();itt!=m_args.end();++itt,++n) {
|
||||
if (tag==*itt) {
|
||||
assert( n>=0 && size_t(n)<m_args.size());
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void remove(const size_t i,const size_t n=1)
|
||||
{
|
||||
if (i>m_args.size() || i+n>m_args.size()) throw_("out of range");
|
||||
m_args.erase(m_args.begin()+i,m_args.begin()+i+n);
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& s,const args& v)
|
||||
{
|
||||
for(t_args::const_iterator itt=v.m_args.begin();itt!=v.m_args.end();++itt){
|
||||
s << *itt << " ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __ARGS_H__
|
||||
143
vendor/wiiscan/0.90/src/configfile.h
vendored
143
vendor/wiiscan/0.90/src/configfile.h
vendored
@@ -1,143 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __CONFIGFILE_H__
|
||||
#define __CONFIGFILE_H__
|
||||
|
||||
class Configfile {
|
||||
private:
|
||||
typedef vector<string> t_value;
|
||||
t_value m_text;
|
||||
map<string,t_value> m_vals;
|
||||
string m_rem;
|
||||
string m_strip;
|
||||
string m_file;
|
||||
|
||||
void Load(istream &s)
|
||||
{
|
||||
if (!s) throw_("bad stream in configfile input operator");
|
||||
char buff[32*1024];
|
||||
bool ini=true;
|
||||
while(s.getline(buff,32*1024)) {
|
||||
const string b(strip(buff));
|
||||
if (ini && b!=m_rem + " Configfile_begin") throw_("bad stream in configfile input operator, missing begin tag");
|
||||
if (b==m_rem + " Configfile_end") return;
|
||||
const string t(strip(removerems(b,m_rem)));
|
||||
if (t.size()>0){
|
||||
m_text.push_back(t);
|
||||
const size_t n=t.find_first_of("=");
|
||||
istringstream s2(t.substr(0,n) + " " + (n==string::npos ? "" : t.substr(n+1)));
|
||||
string v,k;
|
||||
s2 >> k;
|
||||
while ((s2 >> v)) m_vals[k].push_back(v);
|
||||
}
|
||||
ini=false;
|
||||
}
|
||||
throw_("bad stream in configfile input operator, missing end tag");
|
||||
}
|
||||
|
||||
string Strip(const string& s) const
|
||||
{
|
||||
for(size_t i=0;i<m_strip.size();++i){
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
Configfile() : m_rem("%") {}
|
||||
|
||||
Configfile(const string& filename,const string rem="%") : m_rem(rem), m_file(filename)
|
||||
{
|
||||
ifstream s(filename.c_str());
|
||||
if (!s) throw_("File <" + filename + "> does not exist");
|
||||
Load(s);
|
||||
}
|
||||
|
||||
Configfile(istream& s,const string rem="%") : m_rem(rem)
|
||||
{
|
||||
if (!s) throw_("stream is invalid");
|
||||
Load(s);
|
||||
}
|
||||
|
||||
size_t size() const {return m_text.size();}
|
||||
const string& operator[](const size_t n) const {assert(n<m_text.size()); return m_text[n];}
|
||||
const t_value& operator()(const string& key) const {return Get(key);}
|
||||
bool hasEntry (const string& key) const {map<string,t_value >::const_iterator itt=m_vals.find(key); return itt!=m_vals.end();}
|
||||
void Save(const string& filename) {ofstream s(filename.c_str()); s << *this;}
|
||||
|
||||
bool operator==(const Configfile& c) const
|
||||
{
|
||||
if (m_text!=c.m_text) return false;
|
||||
else if (m_vals!=c.m_vals) return false;
|
||||
else if (m_rem!=c.m_rem) return false;
|
||||
else if (m_strip!=c.m_strip) return false;
|
||||
else if (m_file!=c.m_file) return false;
|
||||
return true;
|
||||
}
|
||||
bool operator!=(const Configfile& c) const {return !this->operator==(c);}
|
||||
|
||||
void Checkfilechange()
|
||||
{
|
||||
if (m_file.empty()) return;
|
||||
Configfile c(m_file);
|
||||
if (c!=*this) *this=c;
|
||||
}
|
||||
|
||||
const t_value& Get(const string& key) const
|
||||
{
|
||||
map<string,t_value >::const_iterator itt=m_vals.find(key);
|
||||
if (itt==m_vals.end()) throw_("No such entry, <" + key + ">, in configfile");
|
||||
return itt->second;
|
||||
}
|
||||
|
||||
template<class T> const T Get(const string& key,const bool fullline=false) const
|
||||
{
|
||||
const t_value& v=Get(key);
|
||||
assert( v.size()>0 );
|
||||
string s=v[0];
|
||||
if (fullline) for(size_t i=1;i<v.size();++i) s += " " + v[i];
|
||||
T t=totype<T>(s);
|
||||
return t;
|
||||
}
|
||||
|
||||
template<class T> const T Initialize(const string& key,const T valiueifnotfound,const bool fullline=false) const
|
||||
{
|
||||
if (!hasEntry(key)) return valiueifnotfound;
|
||||
else return Get<T>(key,fullline);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
pair<bool,T> GetConfig(const string& e) const
|
||||
{
|
||||
if (!hasEntry(e)) return make_pair(false,T());
|
||||
else return make_pair(true,Get<T>(e,true));
|
||||
}
|
||||
|
||||
template<class T> void Set(const string& key,const T& v)
|
||||
{
|
||||
t_value val;
|
||||
val.push_back(tostring(v));
|
||||
m_vals[key]=val;
|
||||
m_text.push_back(key + " " + val[0]);
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& s,const Configfile& x)
|
||||
{
|
||||
s << x.m_rem << " Configfile_begin\n";
|
||||
for(map<string,t_value>::const_iterator itt1=x.m_vals.begin();itt1!=x.m_vals.end();++itt1){
|
||||
s << "\t" << itt1->first << " = ";
|
||||
for(t_value::const_iterator itt2=itt1->second.begin();itt2!=itt1->second.end();++itt2) s << *itt2 << " ";
|
||||
s << "\n";
|
||||
}
|
||||
s << x.m_rem << " Configfile_end\n";
|
||||
// if (!s) throw_("bad stream in configfile output operator");, XXX throws in cout!?
|
||||
return s;
|
||||
}
|
||||
|
||||
friend istream& operator>>(istream& s,Configfile& x){x.Load(s); return s;}
|
||||
};
|
||||
#endif // __CONFIGFILE_H__
|
||||
197
vendor/wiiscan/0.90/src/exception.h
vendored
197
vendor/wiiscan/0.90/src/exception.h
vendored
@@ -1,197 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __EXCEPTION_H__
|
||||
#define __EXCEPTION_H__
|
||||
|
||||
// forward defs to funs.h
|
||||
string Getlocaltime();
|
||||
size_t GetThreadId();
|
||||
int Message(const string& title,const string& msg,const int type=0);
|
||||
|
||||
// simple class for debugging call stack
|
||||
#ifdef _DEBUG
|
||||
struct Stackinfo : public vector<string> {
|
||||
friend ostream& operator<<(ostream& s,const Stackinfo& x)
|
||||
{
|
||||
s << "Function stack {" << endl;
|
||||
for(int i=x.size();i>0;--i){
|
||||
const string& f=x[i-1];
|
||||
s << " [" << i-1 << "]: " << f << "(...)" << endl;
|
||||
}
|
||||
return s << "}" << endl;
|
||||
}
|
||||
};
|
||||
|
||||
class Funstack {
|
||||
private:
|
||||
const string m_f;
|
||||
static map<size_t,Stackinfo> m_s;
|
||||
|
||||
Funstack(const Funstack&);
|
||||
void operator=(const Funstack&);
|
||||
|
||||
public:
|
||||
Funstack(const string& f,const int line,const string& file) : m_f(f) {m_s[GetThreadId()].push_back(f);}
|
||||
~Funstack()
|
||||
{
|
||||
const size_t tid=GetThreadId();
|
||||
assert(m_s.find(tid)!=m_s.end());
|
||||
assert(m_s[tid].size()>0 && m_s[tid].back()==m_f);
|
||||
m_s[tid].pop_back();
|
||||
}
|
||||
|
||||
static const Stackinfo GetStack()
|
||||
{
|
||||
const size_t tid=GetThreadId();
|
||||
if (m_s.find(tid)==m_s.end()) return Stackinfo();
|
||||
else return m_s[tid];
|
||||
}
|
||||
};
|
||||
map<size_t,Stackinfo> Funstack::m_s; // initialize static var
|
||||
#define FUNSTACK Funstack __f_stack__(__FUNCTION__,__LINE__,__FILE__)
|
||||
#else
|
||||
#define FUNSTACK
|
||||
#define DUMPSTACK(s)
|
||||
struct Stackinfo {
|
||||
friend ostream& operator<<(ostream& s,const Stackinfo& x) {return s;}
|
||||
};
|
||||
class Funstack {
|
||||
public:
|
||||
static Stackinfo GetStack() {return Stackinfo();}
|
||||
};
|
||||
#endif
|
||||
|
||||
// tee like logger class
|
||||
class Logger
|
||||
{
|
||||
private:
|
||||
//ostream* m_log;
|
||||
string m_logfilename;
|
||||
ofstream m_logfile;
|
||||
ostream* m_log;
|
||||
const bool m_logstdout,m_logstderr;
|
||||
|
||||
Logger(const Logger&);
|
||||
void operator=(const Logger&);
|
||||
|
||||
public:
|
||||
Logger(ostream* log,const bool logstdout=true,const bool logstderr=false) : m_log(log), m_logstdout(logstdout), m_logstderr(logstderr) {}
|
||||
|
||||
void operator=(ostream* log){m_logfilename=""; m_logfile.close(); m_log=log;}
|
||||
void open(const string& logfilename,const ios_base::openmode mode)
|
||||
{
|
||||
m_log=0;
|
||||
if (m_logfile.is_open()) m_logfile.close();
|
||||
m_logfilename=logfilename;
|
||||
m_logfile.open(m_logfilename.c_str(),mode);
|
||||
if (!m_logfile) throw("cannot write to logfile <" + logfilename + ">"); // Exception uses logger class, so do not throw a nice Exception class here, use a plain throw
|
||||
m_log=&m_logfile;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
if (m_logfile.is_open()) m_logfile.close();
|
||||
m_logfile.open(m_logfilename.c_str());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
friend Logger& operator<<(Logger& log,const T& t)
|
||||
{
|
||||
if(log.m_logstdout) cout << t;
|
||||
if(log.m_logstderr) cerr << t;
|
||||
if(log.m_log!=0) (*(log.m_log)) << t;
|
||||
return log;
|
||||
}
|
||||
|
||||
// handle endl and like
|
||||
friend Logger& operator<<(Logger& log,std::ostream& (*fn)(std::ostream&))
|
||||
{
|
||||
if(log.m_logstdout) fn(cout);
|
||||
if(log.m_logstderr) fn(cerr);
|
||||
if(log.m_log!=0) fn(*(log.m_log));
|
||||
return log;
|
||||
}
|
||||
|
||||
void writelogheader(const string& msg)
|
||||
{
|
||||
if(m_log==0) return;
|
||||
else{
|
||||
(*m_log) << "********************************************************" << endl;
|
||||
(*m_log) << "** Logentry: " << msg << endl;
|
||||
(*m_log) << "** Time: " << Getlocaltime();
|
||||
(*m_log) << "********************************************************" << endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// static global logging, default standand out
|
||||
static Logger g_log(0,true,false);
|
||||
|
||||
class Exception{
|
||||
private:
|
||||
const string m_msg;
|
||||
const string m_file;
|
||||
const int m_line;
|
||||
const Stackinfo m_stack;
|
||||
|
||||
public:
|
||||
Exception(const string msg,const string file,const int line,const Stackinfo s) : m_msg(msg), m_file(file), m_line(line), m_stack(s) {}
|
||||
Exception(const char* msg,const string file,const int line,const Stackinfo s) : m_msg(msg), m_file(file), m_line(line), m_stack(s) {}
|
||||
|
||||
inline static string FormatCompilerMsg(const string& file,const int line,const bool warnonly=false)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return file + "(" + Exception::tostring(line) + ") : " + (warnonly ? "warning : " : "error : ");
|
||||
#else
|
||||
return file + ":" + Exception::tostring(line) + ": " + (warnonly ? "warning: " : "error: ");
|
||||
#endif
|
||||
}
|
||||
|
||||
inline static void throw_fun(const string& msg,const string& file,const int line)
|
||||
{
|
||||
const string msg2=Exception::FormatCompilerMsg(file,line) + "throwing exception: " + msg;
|
||||
g_log << msg2;
|
||||
#ifdef _WINDOWS_
|
||||
const string f=tostring(Funstack::GetStack());
|
||||
const string msg3=msg2 + (f.size()>0 ? "\n\n" : "") + f.substr(0,300) + (f.size()>300 ? "\n..." : "");
|
||||
Message("Exception encountered...",msg3,0);
|
||||
#endif
|
||||
throw Exception(msg,file,line,Funstack::GetStack());
|
||||
}
|
||||
|
||||
inline string Msg() const
|
||||
{
|
||||
return FormatCompilerMsg(m_file,m_line) + "Exception: " + m_msg;
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& os,const Exception& e)
|
||||
{
|
||||
return os << e.Msg() << endl << e.m_stack;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static string tostring(const T& x)
|
||||
{
|
||||
ostringstream os;
|
||||
os << x;
|
||||
return os.str();
|
||||
}
|
||||
};
|
||||
|
||||
#define throw_(msg) Exception::throw_fun(msg,__FILE__, __LINE__)
|
||||
#define warn_(msg) cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__,true) << msg << endl;
|
||||
|
||||
#define CATCH_ALL\
|
||||
catch(const char* s) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught exception chars: " << s;}\
|
||||
catch(const string& s) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught exception string: " << s;}\
|
||||
catch(const Exception& s){cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught Exception class: " << s;}\
|
||||
catch(...) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught unknown exception";}\
|
||||
cerr << "...aborting" << endl;
|
||||
|
||||
#endif // __EXCEPTION_H__
|
||||
208
vendor/wiiscan/0.90/src/file.h
vendored
208
vendor/wiiscan/0.90/src/file.h
vendored
@@ -1,208 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __FILE_H__
|
||||
#define __FILE_H__
|
||||
|
||||
inline bool FileExists(const std::string& f)
|
||||
{
|
||||
ifstream s(f.c_str());
|
||||
return (!s)==false;
|
||||
}
|
||||
|
||||
inline void AssertFileExists(const std::string& f)
|
||||
{
|
||||
if (!FileExists(f)) throw_("File <" + f + "> does not exist");
|
||||
}
|
||||
|
||||
inline size_t FileSize(const std::string& f)
|
||||
{
|
||||
AssertFileExists(f);
|
||||
ifstream s(f.c_str());
|
||||
if (!s) throw_("Stream is bad (file <" + f + ">)");
|
||||
s.seekg(0,ios::end);
|
||||
if (!s) throw_("Stream is bad (file <" + f + ">)");
|
||||
return s.tellg();
|
||||
}
|
||||
|
||||
inline void AssertFileNotEmpty(const std::string& f)
|
||||
{
|
||||
if (FileSize(f)==0) throw_("File <" + f + "> is empty");
|
||||
}
|
||||
|
||||
inline size_t FileTime(const string& file)
|
||||
{
|
||||
AssertFileExists(file);
|
||||
const string t=System("date -r " + file + " +%s",true,true); // seconds since 1970-01-01 00:00:00 UTC
|
||||
return totype<size_t>(t);
|
||||
// #include <sys/stat.h>
|
||||
// #include <unistd.h>
|
||||
// struct stat s;
|
||||
// int n=stat(file.c_str(),&s);
|
||||
// if (n!=0) throw_("cannot stat file <" + file + ">");
|
||||
// assert( sizeof(time_t)==sizeof(size_t) );
|
||||
// return s.st_mtime;
|
||||
}
|
||||
|
||||
inline bool isFileNewer(const string& file0,const string& file1)
|
||||
{
|
||||
return FileTime(file0)>FileTime(file1);
|
||||
}
|
||||
|
||||
inline bool DirExists(const std::string& f)
|
||||
{
|
||||
const string file=f + "/.dummy.txt";
|
||||
ofstream s(file.c_str());
|
||||
if(!s) return false;
|
||||
s << "testfile";
|
||||
if(!s) return false;
|
||||
s.close();
|
||||
return FileSize(file)==8;
|
||||
}
|
||||
|
||||
inline string MakeSuffix(const int n)
|
||||
{
|
||||
assert(n>=0);
|
||||
if (n<=9) return "00" + tostring(n);
|
||||
else if (n<=99) return "0" + tostring(n);
|
||||
else return tostring(n);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Readdata(const string& tok,istream& is,T& t)
|
||||
{
|
||||
if (!is) throw_("Stream is bad");
|
||||
is >> t;
|
||||
if (!is) throw_("Reading {" + tok + "} settings");
|
||||
}
|
||||
|
||||
inline string Readline(istream& is)
|
||||
{
|
||||
char buff[16*1024];
|
||||
is.getline(buff,16*1024);
|
||||
return string(buff);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T Readtyp(ifstream& s){
|
||||
T x;
|
||||
s.read(reinterpret_cast<char*>(&x),sizeof(x));
|
||||
if(!s) throw_("bad stream");
|
||||
return x;
|
||||
}
|
||||
|
||||
inline string Readstring(ifstream& s){
|
||||
char c=0;
|
||||
string t;
|
||||
do{
|
||||
c=Readtyp<char>(s);
|
||||
if(c!=0) t+=c;
|
||||
}
|
||||
while (c!=0);
|
||||
return t;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline vector<T> Readbin(std::ifstream& s,const int size)
|
||||
{
|
||||
if(!s) throw_("bad stream");
|
||||
vector<T> x(size);
|
||||
s.read(reinterpret_cast<char*>(&x.front()),x.size()*sizeof(T));
|
||||
if(!s) throw_( "bad write");
|
||||
return x;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Writetyp(ofstream& s,const T& x){
|
||||
s.write(reinterpret_cast<const char*>(&x),sizeof(x));
|
||||
if(!s) throw_( "bad stream");
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Writebin(std::ofstream& s,const std::vector<T>& x,const bool writetag)
|
||||
{
|
||||
if(!s) throw_("bad stream");
|
||||
const size_t sz=x.size()*sizeof(T);
|
||||
if(writetag){
|
||||
Writetyp(s,sz);
|
||||
}
|
||||
if(!s) throw_( "bad stream" );
|
||||
s.write(reinterpret_cast<const char*>(&x.front()),sz);
|
||||
if(!s) throw_( "bad write");
|
||||
if (writetag) Writetyp(s,sz);
|
||||
if(!s) throw_( "bad stream");
|
||||
}
|
||||
|
||||
template<class T,class R>
|
||||
inline void Writebin(std::ofstream& s,const std::map<T,R>& x,const bool writetag)
|
||||
{
|
||||
vector<T> t;
|
||||
vector<R> r;
|
||||
t.reserve(x.size());
|
||||
r.reserve(x.size());
|
||||
for(typename std::map<T,R>::const_iterator itt=x.begin();itt!=x.end();++itt){
|
||||
t.push_back(itt->first);
|
||||
r.push_back(itt->second);
|
||||
}
|
||||
if (writetag) {
|
||||
Writetyp(s,x.size());
|
||||
Writetyp(s,static_cast<unsigned int>(sizeof(T)));
|
||||
Writetyp(s,static_cast<unsigned int>(sizeof(R)));
|
||||
}
|
||||
Writebin(s,t,writetag);
|
||||
Writebin(s,r,writetag);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Readbin(std::ifstream& s,vector<T>& x)
|
||||
{
|
||||
if(!s) throw_("bad stream");
|
||||
const size_t sz=Readtyp<size_t>(s);
|
||||
if(!s) throw_( "bad stream" );
|
||||
if(sz%sizeof(T)!=0) throw_("bad size tag");
|
||||
x.resize(sz/sizeof(T));
|
||||
s.read(reinterpret_cast<char*>(&x.front()),sz);
|
||||
if(!s) throw_( "bad write");
|
||||
if (Readtyp<size_t>(s)!=sz) throw_("bad size tag");
|
||||
if(!s) throw_( "bad stream");
|
||||
}
|
||||
|
||||
template<class T,class R>
|
||||
inline void Readbin(std::ifstream& s,map<T,R>& x)
|
||||
{
|
||||
vector<T> t;
|
||||
vector<R> r;
|
||||
|
||||
const size_t sz=Readtyp<size_t>(s);
|
||||
const size_t szT=Readtyp<unsigned int>(s);
|
||||
const size_t szR=Readtyp<unsigned int>(s);
|
||||
|
||||
if (szT!=sizeof(T)) throw_("type T size mismatch in Readbin (map)");
|
||||
if (szR!=sizeof(R)) throw_("type R size mismatch in Readbin (map)");
|
||||
|
||||
Readbin(s,t);
|
||||
Readbin(s,r);
|
||||
if (t.size()!=r.size()) throw_("size mismatch in Readbin (map)");
|
||||
x.clear();
|
||||
for(size_t i=0;i<t.size();++i){
|
||||
x[t[i]]=r[i];
|
||||
}
|
||||
if (x.size()!=sz) throw_("map size mismatch in Readbin (map)");
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Writeascii(const string& filename,const std::vector<T>& x,const string& comment="",const char& newline='\n')
|
||||
{
|
||||
ofstream s(filename.c_str());
|
||||
if(!s) throw_("bad file <" + filename + ">");
|
||||
s << "% Writeascii: size=" << x.size() << " " << comment << "\n";
|
||||
for(size_t i=0;i<x.size();++i) s << x[i] << newline;
|
||||
if(!s) throw_( "bad writing to file <" + filename + ">");
|
||||
}
|
||||
|
||||
#endif // __FILE_H__
|
||||
413
vendor/wiiscan/0.90/src/funs.h
vendored
413
vendor/wiiscan/0.90/src/funs.h
vendored
@@ -1,413 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __FUNS_H__
|
||||
#define __FUNS_H__
|
||||
|
||||
#define Unimplemented throw_("Function unimplemented")
|
||||
#define Dontgethere throw_("Dontgethere")
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ON_DEBUG(a) a
|
||||
#else
|
||||
#define ON_DEBUG(a)
|
||||
#endif
|
||||
|
||||
#ifdef USE_FFTW
|
||||
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
|
||||
#endif
|
||||
|
||||
// Small template funs
|
||||
template<class T,class R> bool isinmap (const map<T,R>& m,const T& t) {return m.size()>=2 && m.begin()->first<=t && t<(--m.end())->first;}
|
||||
template<class T> const size_t getsteps(const T& r0,const T& r1,const T& rstep,const bool logarithmic) {size_t N=0; for(T r=r0;r<r1;logarithmic ? r*=rstep/T(1) : r+=rstep) ++N; return N;}
|
||||
|
||||
inline std::string Version(){return string("VERSION: ") + VERSION + "." + VERSION_REV;}
|
||||
|
||||
inline std::string Config()
|
||||
{
|
||||
std::string s;
|
||||
#ifdef NDEBUG
|
||||
s+="NDEBUG";
|
||||
#else
|
||||
#ifdef PROFILE
|
||||
s+="PROFILE";
|
||||
#else
|
||||
s+="DEBUG";
|
||||
#endif
|
||||
#endif
|
||||
#ifdef USE_UNITS
|
||||
s+= " USE_UNITS";
|
||||
#endif
|
||||
#ifdef USE_FLOAT_CHECKS
|
||||
s+= " USE_FLOAT_CHECKS";
|
||||
#endif
|
||||
#ifdef USE_FFTW_IC
|
||||
s+= " USE_FFTW_IC";
|
||||
#endif
|
||||
#ifdef USE_FFTW
|
||||
s+= " USE_FFTW";
|
||||
#endif
|
||||
#ifdef USE_MPI
|
||||
s+= " USE_MPI";
|
||||
#endif
|
||||
if (sizeof(void*)==4) s+=" 32BIT";
|
||||
else if (sizeof(void*)==8) s+=" 64BIT";
|
||||
else s+=" XXBIT";
|
||||
|
||||
const long one= 1;
|
||||
const int big=!(*(reinterpret_cast<const char *>(&one)));
|
||||
if (big) s+=" BIGENDIAN";
|
||||
else s+=" LITENDIAN";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
inline string FormatCompilerMsg(const string& file,const int line)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return file + ":" + line + ":";
|
||||
#else
|
||||
return file + "(" + line + ")";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
extern "C"{
|
||||
#ifdef _UNICODE
|
||||
#pragma message("ERROR: toolsfun cannot handle unicode...giving up compilation");
|
||||
ERROR_complier
|
||||
#endif
|
||||
|
||||
#ifdef _AFXDLL
|
||||
__declspec(dllimport) void* __stdcall GetCurrentThread();
|
||||
__declspec(dllimport) void* __stdcall GetCurrentThreadId();
|
||||
__declspec(dllimport) int __stdcall SetThreadPriority(void* hThread,int nPriority);
|
||||
#else
|
||||
//void* __stdcall GetCurrentThread();
|
||||
//void* __stdcall GetCurrentThreadId();
|
||||
//int __stdcall SetThreadPriority(void* hThread,int nPriority);
|
||||
__declspec(dllimport) void* __stdcall GetCurrentThread();
|
||||
__declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
|
||||
__declspec(dllimport) int __stdcall SetThreadPriority(void* hThread,int nPriority);
|
||||
__declspec(dllimport) int __stdcall GetThreadPriority(void* hThread);
|
||||
__declspec(dllimport) unsigned int __stdcall WinExec(const char* lpCmdLine,unsigned int uCmdShow);
|
||||
#ifndef _WINDOWS_
|
||||
__declspec(dllimport) unsigned int __stdcall MessageBox(void* hWnd,const char* lpText,const char* lpCaption,unsigned int Type);
|
||||
__declspec(dllimport) unsigned long __stdcall GetCurrentDirectory(unsigned long nBufferLength,char* lpBuffer);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
int nice(int inc);
|
||||
#endif
|
||||
|
||||
inline int Message(const string& title,const string& msg,const int type)
|
||||
{
|
||||
#ifdef WIN32
|
||||
// 0 = MB_OK
|
||||
// 1 = MB_OKCANCEL
|
||||
// 2 = MB_ABORTRETRYIGNORE
|
||||
// 3 = MB_YESNOCANCEL
|
||||
// 4 = MB_YESNO
|
||||
// 5 = MB_RETRYCANCEL
|
||||
// 6 = MB_CANCELTRYCONTINUE: if(WINVER >= 0x0500)
|
||||
const long hr=MessageBox(NULL,msg.c_str(),title.c_str(),type);
|
||||
#else
|
||||
Unimplemented;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
string GetCurrentDir()
|
||||
{
|
||||
#ifdef WIN32
|
||||
char buff[16*1024];
|
||||
if(GetCurrentDirectory(16*1024,buff)==0) throw_("GetCurrentDirectory() failed");
|
||||
return tostring(buff);
|
||||
#else
|
||||
Unimplemented;
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
inline void SetNiceLevel(const int level)
|
||||
{
|
||||
#ifdef WIN32
|
||||
// THREAD_PRIORITY_ABOVE_NORMAL 1 Priority 1 point above the priority class.
|
||||
// THREAD_PRIORITY_BELOW_NORMAL -1 Priority 1 point below the priority class.
|
||||
// THREAD_PRIORITY_HIGHEST 2 Priority 2 points above the priority class.
|
||||
// THREAD_PRIORITY_IDLE -15 Base priority of 1 for IDLE_PRIORITY_CLASS,...
|
||||
// THREAD_PRIORITY_LOWEST -2 Priority 2 points below the priority class.
|
||||
// THREAD_PRIORITY_NORMAL 0 Normal priority for the priority class.
|
||||
// THREAD_PRIORITY_TIME_CRITICAL 15 Base priority of 15 for IDLE_PRIORITY_CLASS,...
|
||||
if (level!=0 && level!=1 && level!=-1 && level!=2 && level!=-2 && level!=15 && level!=-15) throw_("wrong Win32 nice level, must be oneof -15,-2,-1,0,1,2,15");
|
||||
SetThreadPriority(GetCurrentThread(),-level);
|
||||
assert( GetThreadPriority(GetCurrentThread())==-level );
|
||||
#else
|
||||
const int n=nice(level);
|
||||
if (n<0) throw_("Could not set nice level");
|
||||
#endif
|
||||
}
|
||||
|
||||
inline size_t GetThreadId()
|
||||
{
|
||||
#ifdef WIN32
|
||||
assert( sizeof(size_t)==sizeof(unsigned long) );
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
// may be replaced by return 0; if phtread not found!
|
||||
assert( sizeof(size_t)==sizeof(pthread_t) );
|
||||
const pthread_t p=pthread_self();
|
||||
size_t q=0;
|
||||
memcpy(&q,&p,sizeof(q));
|
||||
return q;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TOOLSFUN_QUIET_WIN32_SYSTEM
|
||||
#ifdef WIN32
|
||||
// make a special non-console system call, instead of the standard system()
|
||||
// XXX SystemWin, does not wait for process to finish, CreatProc still create window
|
||||
|
||||
int SystemWin(const string& cmd)
|
||||
{
|
||||
//ShellExecute, CreateProcess, WinExec or system
|
||||
// HINSTANCE hi=ShellExecute(NULL,NULL,cmdx,"","",SW_SHOSNOACTIVATE);
|
||||
// if (reinterpret_cast<int>(hi)<32) MessageBox(NULL,(string("ShellExecute <") + cmd + "> failed").c_str(),"Error",0);
|
||||
|
||||
// const string cmd2="\\\"" + cmd + "\\\""; // fix problem with spaces in executable, not working yet
|
||||
unsigned int r=WinExec(cmd.c_str(),4);
|
||||
return r<32 ? -1 : 0;
|
||||
}
|
||||
|
||||
bool CreateProc(const string& cmd,const bool throwexception=true,const bool waitforprocesstofinish=true)
|
||||
{
|
||||
STARTUPINFO s;
|
||||
PROCESS_INFORMATION p;
|
||||
memset(&s,0,sizeof(s));
|
||||
memset(&p,0,sizeof(p));
|
||||
s.cb=sizeof(s);
|
||||
|
||||
// to avoid const cast of char* in CreateProcess
|
||||
char cmdx[16*1024];
|
||||
strcpy_s(cmdx,16*1024,cmd.c_str());
|
||||
|
||||
const int r=CreateProcess(0,cmdx,0,0,false,CREATE_DEFAULT_ERROR_MODE,0,0,&s,&p);
|
||||
if (r!=0) {if(waitforprocesstofinish) WaitForSingleObject(p.hProcess,INFINITE);}
|
||||
else {
|
||||
if (throwexception) throw_(string("CreateProcess() failed with return code <") + GetLastError() + ">");
|
||||
else return false;
|
||||
}
|
||||
|
||||
// Release handles
|
||||
assert(r!=0);
|
||||
CloseHandle(p.hProcess);
|
||||
CloseHandle(p.hThread);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline string System(const string& cmd,const bool throwexception=true,const bool captureoutput=false,int* pret=0)
|
||||
{
|
||||
if (!captureoutput){
|
||||
#ifdef TOOLSFUN_QUIET_WIN32_SYSTEM
|
||||
const int n=SystemWin(cmd);
|
||||
#else
|
||||
const int n=system(cmd.c_str());
|
||||
#endif
|
||||
if (n!=0 && throwexception) throw_(string("system command failed with code=") + n + " cmd=<" + cmd + ">");
|
||||
if (pret!=0) *pret=n;
|
||||
return "";
|
||||
} else {
|
||||
static size_t n=0;
|
||||
#ifdef WIN32
|
||||
const string rm="del ";
|
||||
char tmp[1024];
|
||||
if (tmpnam_s(tmp,1024)) throw_("error in creating win32 temp name");
|
||||
const string file(tmp);
|
||||
#else
|
||||
const string rm="rm ";
|
||||
const string file=tmpnam("tempfile");
|
||||
#endif
|
||||
ifstream s1(file.c_str());
|
||||
if(s1) {
|
||||
s1.close();
|
||||
System((rm + file).c_str(),true,false);
|
||||
}
|
||||
System(cmd + " > " + file,throwexception,false,pret);
|
||||
|
||||
string t;
|
||||
char buff[16*1024];
|
||||
ifstream s2(file.c_str());
|
||||
while(s2) {
|
||||
s2.getline(buff,16*1024);
|
||||
if (s2) t += buff;
|
||||
}
|
||||
s2.close();
|
||||
System((rm + file).c_str(),true,false);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
string Getlocaltime()
|
||||
{
|
||||
FUNSTACK;
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
struct tm timeinfo;
|
||||
localtime_s(&timeinfo,&rawtime);
|
||||
char buff[1024];
|
||||
asctime_s(buff,1014,&timeinfo);
|
||||
return string(buff);
|
||||
}
|
||||
|
||||
class timer
|
||||
{
|
||||
private:
|
||||
double m_t,m_cpu_t;
|
||||
double* m_addt;
|
||||
mutable double m_last_t,m_last_eta;
|
||||
|
||||
static double gettime()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return 1.0*clock()/CLOCKS_PER_SEC; // use low-res clock
|
||||
// FILETIME ft;
|
||||
// unsigned __int64 tmpres = 0;
|
||||
//
|
||||
// GetSystemTimeAsFileTime(&ft);
|
||||
//
|
||||
// tmpres |= ft.dwHighDateTime;
|
||||
// tmpres <<= 32;
|
||||
// tmpres |= ft.dwLowDateTime;
|
||||
//
|
||||
// converting file time to unix epoch
|
||||
// tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
||||
// tmpres /= 10; // convert into microseconds
|
||||
// tv->tv_sec = (long)(tmpres / 1000000UL);
|
||||
// tv->tv_usec = (long)(tmpres % 1000000UL);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return tv.tv_sec + static_cast<double>(tv.tv_usec)/1000000;
|
||||
#endif
|
||||
}
|
||||
|
||||
static double getcputime()
|
||||
{
|
||||
static const double f=1.0/CLOCKS_PER_SEC;
|
||||
return f*clock();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static double Remaining(const double t,const T& n,const T& N)
|
||||
{
|
||||
if (n>=N || N<=T(0)) throw_("value out of range in timer::Remaining, n>=N or N<=0, n=" + tostring(n) + " N=" + tostring(N));
|
||||
const double p=static_cast<double>(n/T(1)+1)/(N/T(1));
|
||||
const double p2=p>0 ? t/p : 0;
|
||||
return p2>t ? p2-t : 0;
|
||||
}
|
||||
|
||||
public:
|
||||
timer() : m_t(gettime()), m_cpu_t(getcputime()), m_addt(0), m_last_t(-1), m_last_eta(-1) {}
|
||||
timer(double& t) : m_t(gettime()), m_cpu_t(getcputime()), m_addt(&t), m_last_t(-1), m_last_eta(-1) {}
|
||||
~timer() {if (m_addt!=0) (*m_addt) += elapsed();}
|
||||
|
||||
void reset () {m_t=gettime(); m_cpu_t=getcputime(); m_last_t=-1; m_last_eta=-1;}
|
||||
double elapsed() const {return gettime()-m_t;}
|
||||
double cputime() const {return getcputime()-m_cpu_t;}
|
||||
|
||||
static string ToHMS(const double& t)
|
||||
{
|
||||
assert( t>=0 );
|
||||
const unsigned int it=static_cast<unsigned int>(t+.5);
|
||||
const unsigned int hours=it/(60*60);
|
||||
const unsigned int mins=(it-hours*60*60)/(60);
|
||||
const unsigned int secs=(it-hours*60*60-mins*60);
|
||||
assert( secs<60 && mins<60);
|
||||
return tostring(hours) + ":" + (mins<10 ? "0": "") + tostring(mins) + ":" + (secs<10 ? "0": "") + tostring(secs);
|
||||
}
|
||||
|
||||
template<class T> static inline int Topercent(const T x,const T N,const int decimals=-1)
|
||||
{
|
||||
assert(x<N && N!=T(0));
|
||||
float pf=static_cast<float>(x/T(1))/(N/T(1));
|
||||
if (decimals>0) pf=static_cast<int>(pf*decimals)/(1.0*decimals);
|
||||
return static_cast<int>(pf*100+.5);
|
||||
}
|
||||
|
||||
template<class T> void ToEta(const T& n,const T& N,ostream& s,const double timeprintsteps=30,const bool verboseprint=false) const
|
||||
{
|
||||
if (n>=N) return;
|
||||
assert( n<N );
|
||||
|
||||
const double t=gettime()-m_t;
|
||||
if (n==T(0)) {
|
||||
m_last_t=t;
|
||||
return;
|
||||
}
|
||||
|
||||
const double e=(t-m_last_t);
|
||||
if (e>timeprintsteps) {
|
||||
const double f=timeprintsteps*60;
|
||||
const double r=Remaining(t,n,N);
|
||||
if (m_last_eta<0 || r<f || (r>f && e>f) /*|| (m_last_eta>0 && r>1.2*m_last_eta) */ ){
|
||||
time_t tm;
|
||||
time(&tm);
|
||||
const string systime=ctime(&tm);
|
||||
if (m_last_eta<0) s << "Current system time: " << systime;
|
||||
tm += static_cast<time_t>(r);
|
||||
const string eta=ctime(&tm);
|
||||
const bool extraday=(eta.substr(0,3)!=systime.substr(0,3));
|
||||
const string eday=extraday ? " "+eta.substr(0,3)+" " : "";
|
||||
s << "Time [h:m:s]=" << ToHMS(t) << ", R=" << ToHMS(r) << ", ETA=" << eday << eta.substr(11,8);
|
||||
if(verboseprint) {
|
||||
const string t=", n/N=" + tostring(n) + "/" + tostring(N) + "=" + tostring(Topercent(n,N,10)) + " percent,";
|
||||
s << t;
|
||||
for(size_t i=t.size();i<42;++i) s << " ";
|
||||
s << " CPU=" << ToHMS(cputime());
|
||||
}
|
||||
s << endl;
|
||||
|
||||
m_last_t=t;
|
||||
m_last_eta=r;
|
||||
}
|
||||
}
|
||||
}
|
||||
friend ostream& operator<<(ostream& s,const timer x)
|
||||
{
|
||||
return s << "Time [h:m:s]= " << x.ToHMS(x.elapsed()) << " CPU=" << x.ToHMS(x.cputime());
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
int SwapEndian(void *data,const size_t size) {
|
||||
|
||||
short xs;
|
||||
long xl;
|
||||
|
||||
switch (size){
|
||||
case 2:
|
||||
xs = *(short *)data;
|
||||
*(short *)data = ( ((xs & 0x0000ff00) >> 8) | ((xs & 0x000000ff) << 8) );
|
||||
break;
|
||||
case 4:
|
||||
xl = *(long *)data;
|
||||
*(long *)data = ( ((xl & 0xff000000) >> 24) | ((xl & 0x00ff0000) >> 8) |
|
||||
((xl & 0x0000ff00) << 8) | ((xl & 0x000000ff) << 24) );
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // __FUNS_H__
|
||||
282
vendor/wiiscan/0.90/src/process.h
vendored
282
vendor/wiiscan/0.90/src/process.h
vendored
@@ -1,282 +0,0 @@
|
||||
#ifndef __PROCESS_H__
|
||||
#define __PROCESS_H__
|
||||
|
||||
#include <tlhelp32.h>
|
||||
|
||||
pair<HANDLE,PROCESSENTRY32> ProcessWalkInit()
|
||||
{
|
||||
// Take a snapshot of all processes in the system.
|
||||
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
||||
if( hProcessSnap == INVALID_HANDLE_VALUE ) throw_("CreateToolhelp32Snapshot() returned invalid handle");
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
PROCESSENTRY32 pe32;
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
// Retrieve information about the first process,
|
||||
// and exit if unsuccessful
|
||||
if(!Process32First(hProcessSnap,&pe32)) {
|
||||
CloseHandle(hProcessSnap); // clean the snapshot object
|
||||
throw_("Process32First"); // show cause of failure
|
||||
}
|
||||
|
||||
return make_pair(hProcessSnap,pe32);
|
||||
}
|
||||
|
||||
DWORD GetProcessID(const string& processname)
|
||||
{
|
||||
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
|
||||
HANDLE hProcessSnap=h.first;
|
||||
PROCESSENTRY32 pe32=h.second;
|
||||
|
||||
do {
|
||||
if (pe32.szExeFile==processname) {
|
||||
CloseHandle(hProcessSnap);
|
||||
return pe32.th32ProcessID;
|
||||
}
|
||||
} while( Process32Next(hProcessSnap,&pe32) );
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PROCESSENTRY32 GetProcessInfo(const DWORD id)
|
||||
{
|
||||
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
|
||||
HANDLE hProcessSnap=h.first;
|
||||
PROCESSENTRY32 pe32=h.second;
|
||||
|
||||
int n=0;
|
||||
do {
|
||||
if (pe32.th32ProcessID==id) {
|
||||
CloseHandle(hProcessSnap);
|
||||
return pe32;
|
||||
}
|
||||
} while( Process32Next(hProcessSnap,&pe32) );
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
ZeroMemory( &pe32, sizeof(pe32) );
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
return pe32;
|
||||
}
|
||||
|
||||
DWORD GetProcessCount(const string& processname)
|
||||
{
|
||||
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
|
||||
HANDLE hProcessSnap=h.first;
|
||||
PROCESSENTRY32 pe32=h.second;
|
||||
int n=0;
|
||||
do {
|
||||
if (pe32.szExeFile==processname) ++n;
|
||||
} while( Process32Next(hProcessSnap,&pe32) );
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
return n;
|
||||
}
|
||||
|
||||
bool KillProcessID(const DWORD id)
|
||||
{
|
||||
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, FALSE, id);
|
||||
if(hProcess==NULL) return false; // might have gone in the meantime, so no throw_("OpenProcess() got null handle");
|
||||
|
||||
const BOOL t=TerminateProcess(hProcess,-1);
|
||||
CloseHandle(hProcess);
|
||||
return t!=0;
|
||||
}
|
||||
|
||||
void KillAllProcesses(const string& exe)
|
||||
{
|
||||
// kill existing polls
|
||||
DWORD id=GetProcessID(exe);
|
||||
while(id!=0){
|
||||
KillProcessID(id);
|
||||
id=GetProcessID(exe);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#include <tchar.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
BOOL GetProcessList( );
|
||||
BOOL ListProcessModules( DWORD dwPID );
|
||||
BOOL ListProcessThreads( DWORD dwOwnerPID );
|
||||
void printError( TCHAR* msg );
|
||||
|
||||
FILE* log=fopen("d:\\plog.txt","w");
|
||||
|
||||
BOOL GetProcessList( )
|
||||
{
|
||||
HANDLE hProcessSnap;
|
||||
HANDLE hProcess;
|
||||
PROCESSENTRY32 pe32;
|
||||
DWORD dwPriorityClass;
|
||||
|
||||
// Take a snapshot of all processes in the system.
|
||||
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
|
||||
if( hProcessSnap == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
printError( TEXT("CreateToolhelp32Snapshot (of processes)") );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
pe32.dwSize = sizeof( PROCESSENTRY32 );
|
||||
|
||||
// Retrieve information about the first process,
|
||||
// and exit if unsuccessful
|
||||
if( !Process32First( hProcessSnap, &pe32 ) )
|
||||
{
|
||||
printError( TEXT("Process32First") ); // show cause of failure
|
||||
CloseHandle( hProcessSnap ); // clean the snapshot object
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Now walk the snapshot of processes, and
|
||||
// display information about each process in turn
|
||||
do
|
||||
{
|
||||
fprintf(log, "\n\n=====================================================" );
|
||||
fprintf(log, TEXT("\nPROCESS NAME: %s"), pe32.szExeFile );
|
||||
fprintf(log, "\n-----------------------------------------------------" );
|
||||
|
||||
// Retrieve the priority class.
|
||||
dwPriorityClass = 0;
|
||||
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
|
||||
if( hProcess == NULL )
|
||||
printError( TEXT("OpenProcess") );
|
||||
else
|
||||
{
|
||||
dwPriorityClass = GetPriorityClass( hProcess );
|
||||
if( !dwPriorityClass )
|
||||
printError( TEXT("GetPriorityClass") );
|
||||
CloseHandle( hProcess );
|
||||
}
|
||||
|
||||
fprintf(log, "\n Process ID = 0x%08X", pe32.th32ProcessID );
|
||||
fprintf(log, "\n Thread count = %d", pe32.cntThreads );
|
||||
fprintf(log, "\n Parent process ID = 0x%08X", pe32.th32ParentProcessID );
|
||||
fprintf(log, "\n Priority base = %d", pe32.pcPriClassBase );
|
||||
if( dwPriorityClass )
|
||||
fprintf(log, "\n Priority class = %d", dwPriorityClass );
|
||||
|
||||
// List the modules and threads associated with this process
|
||||
ListProcessModules( pe32.th32ProcessID );
|
||||
ListProcessThreads( pe32.th32ProcessID );
|
||||
|
||||
} while( Process32Next( hProcessSnap, &pe32 ) );
|
||||
|
||||
CloseHandle( hProcessSnap );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
BOOL ListProcessModules( DWORD dwPID )
|
||||
{
|
||||
HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
|
||||
MODULEENTRY32 me32;
|
||||
|
||||
// Take a snapshot of all modules in the specified process.
|
||||
hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID );
|
||||
if( hModuleSnap == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
printError( TEXT("CreateToolhelp32Snapshot (of modules)") );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
me32.dwSize = sizeof( MODULEENTRY32 );
|
||||
|
||||
// Retrieve information about the first module,
|
||||
// and exit if unsuccessful
|
||||
if( !Module32First( hModuleSnap, &me32 ) )
|
||||
{
|
||||
printError( TEXT("Module32First") ); // show cause of failure
|
||||
CloseHandle( hModuleSnap ); // clean the snapshot object
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Now walk the module list of the process,
|
||||
// and display information about each module
|
||||
do
|
||||
{
|
||||
fprintf(log, TEXT("\n\n MODULE NAME: %s"), me32.szModule );
|
||||
fprintf(log, TEXT("\n Executable = %s"), me32.szExePath );
|
||||
fprintf(log, "\n Process ID = 0x%08X", me32.th32ProcessID );
|
||||
fprintf(log, "\n Ref count (g) = 0x%04X", me32.GlblcntUsage );
|
||||
fprintf(log, "\n Ref count (p) = 0x%04X", me32.ProccntUsage );
|
||||
fprintf(log, "\n Base address = 0x%08X", (DWORD) me32.modBaseAddr );
|
||||
fprintf(log, "\n Base size = %d", me32.modBaseSize );
|
||||
|
||||
} while( Module32Next( hModuleSnap, &me32 ) );
|
||||
|
||||
CloseHandle( hModuleSnap );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
BOOL ListProcessThreads( DWORD dwOwnerPID )
|
||||
{
|
||||
HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
|
||||
THREADENTRY32 te32;
|
||||
|
||||
// Take a snapshot of all running threads
|
||||
hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
|
||||
if( hThreadSnap == INVALID_HANDLE_VALUE )
|
||||
return( FALSE );
|
||||
|
||||
// Fill in the size of the structure before using it.
|
||||
te32.dwSize = sizeof(THREADENTRY32);
|
||||
|
||||
// Retrieve information about the first thread,
|
||||
// and exit if unsuccessful
|
||||
if( !Thread32First( hThreadSnap, &te32 ) )
|
||||
{
|
||||
printError( TEXT("Thread32First") ); // show cause of failure
|
||||
CloseHandle( hThreadSnap ); // clean the snapshot object
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Now walk the thread list of the system,
|
||||
// and display information about each thread
|
||||
// associated with the specified process
|
||||
do
|
||||
{
|
||||
if( te32.th32OwnerProcessID == dwOwnerPID )
|
||||
{
|
||||
fprintf(log, "\n\n THREAD ID = 0x%08X", te32.th32ThreadID );
|
||||
fprintf(log, "\n Base priority = %d", te32.tpBasePri );
|
||||
fprintf(log, "\n Delta priority = %d", te32.tpDeltaPri );
|
||||
}
|
||||
} while( Thread32Next(hThreadSnap, &te32 ) );
|
||||
|
||||
CloseHandle( hThreadSnap );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
void printError( TCHAR* msg )
|
||||
{
|
||||
DWORD eNum;
|
||||
TCHAR sysMsg[256];
|
||||
TCHAR* p;
|
||||
|
||||
eNum = GetLastError( );
|
||||
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, eNum,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
||||
sysMsg, 256, NULL );
|
||||
|
||||
// Trim the end of the line and terminate it with a null
|
||||
p = sysMsg;
|
||||
while( ( *p > 31 ) || ( *p == 9 ) )
|
||||
++p;
|
||||
do { *p-- = 0; } while( ( p >= sysMsg ) &&
|
||||
( ( *p == '.' ) || ( *p < 33 ) ) );
|
||||
|
||||
// Display the message
|
||||
fprintf(log, TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // __PROCESS_H__
|
||||
95
vendor/wiiscan/0.90/src/reg.h
vendored
95
vendor/wiiscan/0.90/src/reg.h
vendored
@@ -1,95 +0,0 @@
|
||||
#ifndef __REGISTRY_H__
|
||||
#define __REGISTRY_H__
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WINDOWS
|
||||
|
||||
namespace Registry{
|
||||
void* StringtoRoot(const string& t)
|
||||
{
|
||||
if (t=="HKEY_CLASSES_ROOT") return HKEY_CLASSES_ROOT;
|
||||
else if (t=="HKEY_CURRENT_USER") return HKEY_CURRENT_USER;
|
||||
else if (t=="HKEY_LOCAL_MACHINE") return HKEY_LOCAL_MACHINE;
|
||||
else if (t=="HKEY_USERS") return HKEY_USERS;
|
||||
else {throw_("bad root path in registry"); return 0;}
|
||||
}
|
||||
|
||||
pair<void*,pair<string,string> > GetPath(const string& fullpath)
|
||||
{
|
||||
const int n=fullpath.find_first_of('\\');
|
||||
if (n==string::npos) throw_("mallformated registry entry");
|
||||
const string t=fullpath.substr(0,n);
|
||||
void* root=StringtoRoot(t);
|
||||
|
||||
const string r=fullpath.substr(n+1,-1);
|
||||
const int m=r.find_last_of('\\');
|
||||
if (m==string::npos) throw_("mallformated registry entry");
|
||||
|
||||
const string path=r.substr(0,m);
|
||||
const string key =r.substr(m+1,-1);
|
||||
|
||||
return make_pair(root,make_pair(path,key));
|
||||
}
|
||||
|
||||
bool hasKey(void* root,const string& path,const string& key,string* val=0)
|
||||
{
|
||||
assert( sizeof(void*)==sizeof(HKEY) && root!=0 );
|
||||
if (root!=HKEY_CLASSES_ROOT && root!=HKEY_CURRENT_USER && root!=HKEY_LOCAL_MACHINE && root!=HKEY_USERS) throw_("unknown root path in registry");
|
||||
|
||||
DWORD buffersize=1024*16;
|
||||
char buff[1024*16];
|
||||
buff[0]=0;
|
||||
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS!=RegOpenKeyEx(static_cast<HKEY>(root),path.c_str(),NULL,KEY_READ,&hKey)) return false;
|
||||
if (ERROR_SUCCESS!=RegQueryValueEx(hKey,key.c_str(),NULL,NULL,(LPBYTE)buff,&buffersize)) return false;
|
||||
if (ERROR_SUCCESS!=RegCloseKey(hKey)) return false;
|
||||
|
||||
if (val!=0) *val=buff;
|
||||
return true;
|
||||
}
|
||||
|
||||
string GetKey(void* root,const string& path,const string& key)
|
||||
{
|
||||
string val;
|
||||
if (!hasKey(root,path,key,&val)) throw_("could not read registry entry");
|
||||
return val;
|
||||
}
|
||||
|
||||
string GetKey(const string& fullpath)
|
||||
{
|
||||
const pair<void*,pair<string,string> > p=GetPath(fullpath);
|
||||
return GetKey(p.first,p.second.first,p.second.second);
|
||||
}
|
||||
|
||||
bool SetKey(void* root,const string& path,const string& key,const string& val)
|
||||
{
|
||||
assert( sizeof(void*)==sizeof(HKEY) && root!=0 );
|
||||
if (root!=HKEY_CLASSES_ROOT && root!=HKEY_CURRENT_USER && root!=HKEY_LOCAL_MACHINE && root!=HKEY_USERS) throw_("unknown root path in registry");
|
||||
if (val.size()+1>1024*16) throw_("lenght of value to long");
|
||||
|
||||
char buff[1024*16];
|
||||
size_t i;
|
||||
for(i=0;i<val.size();++i) buff[i]=val[i];
|
||||
buff[i]=0;
|
||||
const DWORD buffersize=i;
|
||||
|
||||
HKEY hKey;
|
||||
if (ERROR_SUCCESS!=RegCreateKeyEx(static_cast<HKEY>(root),path.c_str(),0,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL)) return false;
|
||||
if (ERROR_SUCCESS!=RegSetValueEx(hKey,key.c_str(),NULL,REG_SZ,(LPBYTE)buff,buffersize)) return false;
|
||||
if (ERROR_SUCCESS!=RegCloseKey(hKey)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetKey(const string& fullpath,const string& val)
|
||||
{
|
||||
const pair<void*,pair<string,string> > p=GetPath(fullpath);
|
||||
return SetKey(p.first,p.second.first,p.second.second,val);
|
||||
}
|
||||
|
||||
}; // namespace Registry
|
||||
|
||||
#endif // _WINDOWS
|
||||
#endif // WIN32
|
||||
#endif // __REGISTRY_H__
|
||||
284
vendor/wiiscan/0.90/src/stringfun.h
vendored
284
vendor/wiiscan/0.90/src/stringfun.h
vendored
@@ -1,284 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __STRINGFUN_H__
|
||||
#define __STRINGFUN_H__
|
||||
|
||||
struct outputoperator_tags
|
||||
{
|
||||
string preline,endline;
|
||||
int prewidth,postwidth,precision;
|
||||
bool maptags,printnumbers,serialize;
|
||||
|
||||
outputoperator_tags()
|
||||
: endline("\n"), prewidth(-1), postwidth(-1), precision(-1), maptags(false), printnumbers(false), serialize(false) {}
|
||||
};
|
||||
|
||||
static outputoperator_tags g_tags;
|
||||
|
||||
inline ostream& operator<<(ostream& os,const outputoperator_tags& x){
|
||||
g_tags=x;
|
||||
if (g_tags.precision>0) os.precision(g_tags.precision);
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string tostring(const T& x)
|
||||
{
|
||||
ostringstream os;
|
||||
outputoperator_tags t1=g_tags;
|
||||
g_tags=outputoperator_tags();
|
||||
g_tags.serialize=true;
|
||||
g_tags.endline="";
|
||||
os << x;
|
||||
g_tags=t1;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T totype(const string& s)
|
||||
{
|
||||
istringstream is(s);
|
||||
T x;
|
||||
is >> x;
|
||||
return x;
|
||||
}
|
||||
|
||||
inline string operator+ (const string& s,const char* c) {return s+string(c);}
|
||||
inline string operator+ (const string& s,const short& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const unsigned short& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const int& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const long& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const unsigned long& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const float& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const double& c) {return s+tostring(c);}
|
||||
inline string operator+ (const string& s,const long double& c) {return s+tostring(c);}
|
||||
inline string operator+ (const char* a ,const string& b) {return string(a)+b;}
|
||||
|
||||
#ifdef OS_Linux
|
||||
#ifdef __GCC_V4__
|
||||
// does not work under some compilers where size_t==unsigned int
|
||||
inline string operator+ (const string& s,const size_t& c) {return s+tostring(c);}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline string tostring(const int argc,char** argv)
|
||||
{
|
||||
string s;
|
||||
for(int i=0;i<argc;++i) s += string(argv[i]) + " ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string fwidth2(const T& x,const size_t wdt,const bool prefix)
|
||||
{
|
||||
string s=tostring(x);
|
||||
if(wdt>1024 || s.size()>=wdt) return s;
|
||||
size_t n=wdt-s.size();
|
||||
while(n>0) {
|
||||
if (prefix) s=' '+ s;
|
||||
else s+=' ';
|
||||
--n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string fwidth(const T& x,const size_t wdt=8,const size_t tailwdt=4)
|
||||
{
|
||||
string s=tostring(x);
|
||||
if(wdt>1024 || tailwdt>1024 || s.size()>wdt+tailwdt) return s;
|
||||
|
||||
const size_t m=min(s.find('.'),s.find(' '));
|
||||
if (m==string::npos) {
|
||||
s=fwidth2(s,wdt,true);
|
||||
return fwidth2(s,wdt+tailwdt,false);
|
||||
}
|
||||
else{
|
||||
if(wdt<m) {
|
||||
return s;
|
||||
}
|
||||
assert( wdt>=m );
|
||||
size_t n1=wdt-m;
|
||||
while(n1>0) {s= ' ' + s; --n1;}
|
||||
return fwidth2(s,wdt+tailwdt,false);
|
||||
}
|
||||
}
|
||||
|
||||
inline string strip(const string& s,const char ch=' ')
|
||||
{
|
||||
const size_t n=s.find_first_not_of(ch);
|
||||
const size_t m=s.find_last_not_of (ch);
|
||||
|
||||
if (n==string::npos || m==string::npos) return "";
|
||||
return s.substr(n,m-n+1);
|
||||
}
|
||||
|
||||
inline string replace(const string& s,const string& f,const string& r)
|
||||
{
|
||||
if (f.size()==0) return s;
|
||||
const size_t n=s.find(f);
|
||||
if (n==string::npos) return s;
|
||||
else return replace(s.substr(0,n) + r + s.substr(n+f.size()),f,r);
|
||||
}
|
||||
|
||||
inline string indent(const string& s,const string& indent)
|
||||
{
|
||||
string t,q=s;
|
||||
while(q.size()){
|
||||
const string::size_type n=q.find_first_of("\n");
|
||||
t += indent + q.substr(0,n) + "\n";
|
||||
if (n==string::npos) break;
|
||||
assert(n+1<=q.size());
|
||||
q = q.substr(n+1,q.size());
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
inline string removerems(const string& s,const string rem)
|
||||
{
|
||||
const size_t n=s.find_first_of(rem);
|
||||
return s.substr(0,n);
|
||||
}
|
||||
|
||||
inline string suffix(const int n)
|
||||
{
|
||||
assert(n>=0 && n<999);
|
||||
if (n<=9) return "00" + tostring(n);
|
||||
else if (n<=99) return "0" + tostring(n);
|
||||
else return tostring(n);
|
||||
}
|
||||
|
||||
string tail(const string& s,const string& delimiter)
|
||||
{
|
||||
const size_t n=s.find_last_of(delimiter);
|
||||
if (n==string::npos) return s;
|
||||
else return s.substr(n+delimiter.size(),-1);
|
||||
}
|
||||
|
||||
string tail(const string& s,const char c) {
|
||||
string t;
|
||||
t.resize(1);
|
||||
t[0]=c;
|
||||
return tail(s,t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ostream& operator<<(ostream& os,const pair<T*,int> x)
|
||||
{
|
||||
for(int i=0;i<x.second;++i) os << x.first[i] << " ";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline istream& operator>>(istream& is,pair<T*,int> x)
|
||||
{
|
||||
for(int i=0;i<x.second;++i) is >> x.first[i];
|
||||
return is;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ostream& operator<<(ostream& s,const vector<T>& x)
|
||||
{
|
||||
int i=0;
|
||||
if (g_tags.serialize) s << "vector: " << x.size() << " { ";
|
||||
for(typename vector<T>::const_iterator itt=x.begin();itt!=x.end();++itt) {
|
||||
s << g_tags.preline;
|
||||
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
|
||||
s << *itt << " " << g_tags.endline;
|
||||
}
|
||||
if (g_tags.serialize) s << "} ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline istream& operator>>(istream& s,vector<T>& x)
|
||||
{
|
||||
size_t n=0;
|
||||
string t;
|
||||
s >> t;
|
||||
if (t!="vector:") throw_("bad format in vector serialization stream, tag missing");
|
||||
s >> n >> t;
|
||||
if (t!="{") throw_("bad format in vector serialization stream, missing begin brace");
|
||||
x.resize(n);
|
||||
for(size_t i=0;i<n;++i) s >> x[i];
|
||||
s >> t;
|
||||
if (t!="}") throw_("bad format in vector serialization stream, missing end brace");
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ostream& operator<<(ostream& s,const list<T>& x)
|
||||
{
|
||||
if (g_tags.serialize) s << "list: " << x.size() << " { ";
|
||||
int i=0;
|
||||
for(typename list<T>::const_iterator itt=x.begin();itt!=x.end();++itt){
|
||||
s << g_tags.preline;
|
||||
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
|
||||
s << *itt << " " << g_tags.endline;
|
||||
}
|
||||
if (g_tags.serialize) s << "} ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline istream& operator>>(istream& s,list<T>& x)
|
||||
{
|
||||
size_t n=0;
|
||||
string t;
|
||||
s >> t;
|
||||
if (t!="list:") throw_("bad format in list serialization stream, tag missing");
|
||||
s >> n >> t;
|
||||
if (t!="{") throw_("bad format in list serialization stream, missing begin brace");
|
||||
for(size_t i=0;i<n;++i) {
|
||||
T y;
|
||||
s >> y;
|
||||
x.push_back(y);
|
||||
}
|
||||
s >> t;
|
||||
if (t!="}") throw_("bad format in list serialization stream, missing end brace");
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T,typename R>
|
||||
inline ostream& operator<<(ostream& s,const map<T,R>& x)
|
||||
{
|
||||
if (g_tags.serialize) s << "map: " << x.size() << " { ";
|
||||
int i=0;
|
||||
for(typename map<T,R>::const_iterator itt=x.begin();itt!=x.end();++itt) {
|
||||
s << g_tags.preline;
|
||||
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
|
||||
s << fwidth(itt->first,g_tags.prewidth,g_tags.postwidth) << (g_tags.maptags ? " |-> " : " ");
|
||||
s << fwidth(itt->second,g_tags.prewidth,g_tags.postwidth) << " " << g_tags.endline;
|
||||
}
|
||||
if (g_tags.serialize) s << "} ";
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T,typename R>
|
||||
inline istream& operator>>(istream& s,map<T,R>& x)
|
||||
{
|
||||
size_t n=0;
|
||||
string t;
|
||||
s >> t;
|
||||
if (t!="map:") throw_("bad format in map serialization stream, tag missing");
|
||||
s >> n >> t;
|
||||
if (t!="{") throw_("bad format in map serialization stream, missing begin brace");
|
||||
for(size_t i=0;i<n;++i) {
|
||||
T y;
|
||||
R z;
|
||||
s >> y >> z;
|
||||
if (x.find(y)!=x.end()) throw_("bad stream, key value no unique");
|
||||
x[y]=z;
|
||||
}
|
||||
s >> t;
|
||||
if (t!="}") throw_("bad format in map serialization stream, missing end brace");
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // __STRINGFUNS_H__
|
||||
52
vendor/wiiscan/0.90/src/templatefun.h
vendored
52
vendor/wiiscan/0.90/src/templatefun.h
vendored
@@ -1,52 +0,0 @@
|
||||
#ifndef __TEMPLATE_FUN__
|
||||
#define __TEMPLATE_FUN__
|
||||
|
||||
template<class T>
|
||||
class Autobool
|
||||
{
|
||||
private:
|
||||
volatile T* m_b;
|
||||
Autobool(const Autobool&);
|
||||
void operator=(const Autobool&);
|
||||
public:
|
||||
Autobool(volatile T* b) : m_b(b) {assert(m_b && *m_b==false); *m_b=true;}
|
||||
~Autobool() {assert(m_b && *m_b==true); *m_b=false; m_b=0;}
|
||||
};
|
||||
|
||||
template<class T,class R>
|
||||
class DeviceAutoClose
|
||||
{
|
||||
private:
|
||||
T m_dev;
|
||||
R (__stdcall *m_fun)(void *);
|
||||
bool m_init;
|
||||
|
||||
// private Copy CTOR and assignment operator
|
||||
DeviceAutoClose(const DeviceAutoClose<T,R>&);
|
||||
void operator=(const DeviceAutoClose<T,R>&);
|
||||
|
||||
public:
|
||||
DeviceAutoClose(T dev,R(__stdcall *fun)(void*)) : m_dev(dev), m_fun(fun), m_init(true)
|
||||
{
|
||||
FUNSTACK;
|
||||
assert(m_fun!=NULL);
|
||||
}
|
||||
~DeviceAutoClose()
|
||||
{
|
||||
FUNSTACK;
|
||||
assert(m_init);
|
||||
assert(m_fun!=NULL);
|
||||
if (m_dev!=NULL){
|
||||
R r=m_fun(m_dev);
|
||||
if (!r) throw_("DeviceClose() failed"); // throw in DTOR -> bad, bad!
|
||||
}
|
||||
m_dev=NULL;
|
||||
m_fun=NULL;
|
||||
m_init=false;
|
||||
}
|
||||
const T& operator()() const {FUNSTACK; assert(m_init); return m_dev;}
|
||||
T& operator()() {FUNSTACK; assert(m_init); return m_dev;}
|
||||
};
|
||||
|
||||
|
||||
#endif // __TEMPLATE_FUN__
|
||||
34
vendor/wiiscan/0.90/src/toolsfun.h
vendored
34
vendor/wiiscan/0.90/src/toolsfun.h
vendored
@@ -1,34 +0,0 @@
|
||||
// The code is copyrighted 2008 by Carsten Frigaard.
|
||||
// All rights placed in public domain under GNU licence V2, 2008
|
||||
//
|
||||
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
|
||||
// and its documentation for any purpose and without fee is hereby granted, provided that
|
||||
// the above copyright notice appear in all copies and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation.
|
||||
|
||||
#ifndef __TOOLSFUN_H__
|
||||
#define __TOOLSFUN__H__
|
||||
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "exception.h"
|
||||
#include "stringfun.h"
|
||||
#include "args.h"
|
||||
#include "funs.h"
|
||||
#include "file.h"
|
||||
#include "configfile.h"
|
||||
#include "templatefun.h"
|
||||
#include "reg.h"
|
||||
|
||||
#endif // __TOOLSFUN_H__
|
||||
204
vendor/wiiscan/0.90/src/usbm.h
vendored
204
vendor/wiiscan/0.90/src/usbm.h
vendored
@@ -1,204 +0,0 @@
|
||||
#ifndef __USBM_H__
|
||||
#define __USBM_H__
|
||||
|
||||
class USBio
|
||||
{
|
||||
private:
|
||||
HINSTANCE m_hDll;
|
||||
|
||||
// Discovery routine
|
||||
typedef int (__stdcall *USBm_FindDevices_type) ();
|
||||
|
||||
// Info about devices
|
||||
typedef int (__stdcall *USBm_NumberOfDevices_type) (void);
|
||||
typedef int (__stdcall *USBm_DeviceValid_type) (unsigned char);
|
||||
typedef int (__stdcall *USBm_DeviceVID_type) (unsigned char device);
|
||||
typedef int (__stdcall *USBm_DevicePID_type) (unsigned char device);
|
||||
typedef int (__stdcall *USBm_DeviceDID_type) (unsigned char device);
|
||||
typedef int (__stdcall *USBm_DeviceMfr_type) (unsigned char, char *);
|
||||
typedef int (__stdcall *USBm_DeviceProd_type) (unsigned char, char *);
|
||||
typedef int (__stdcall *USBm_DeviceSer_type) (unsigned char, char *);
|
||||
|
||||
// General U4xx functions
|
||||
typedef int (__stdcall *USBm_InitPorts_type) (unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteA_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteB_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteABit_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_WriteBBit_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_ReadA_type) (unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_ReadB_type) (unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_SetBit_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_ResetBit_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_DirectionA_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_DirectionB_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeWrite_type) (unsigned char, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeRead_type) (unsigned char, unsigned char *, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeWrite2_type) (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeRead2_type) (unsigned char, unsigned char *, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_StrobeWrites_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_StrobeReads_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_InitLCD_type) (unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_LCDCmd_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_LCDData_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_InitSPI_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_SPIMaster_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_SPISlaveWrite_type) (unsigned char, unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_SPISlaveRead_type) (unsigned char, unsigned char *, unsigned char *);
|
||||
typedef int (__stdcall *USBm_Stepper_type) (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_Reset1Wire_type) (unsigned char, unsigned char *);
|
||||
typedef int (__stdcall *USBm_Write1Wire_type) (unsigned char, unsigned char);
|
||||
typedef int (__stdcall *USBm_Read1Wire_type) (unsigned char, unsigned char *);
|
||||
|
||||
// DLL string info access
|
||||
typedef int (__stdcall *USBm_RecentError_type) (char *);
|
||||
typedef int (__stdcall *USBm_ClearRecentError_type) (void);
|
||||
typedef int (__stdcall *USBm_DebugString_type) (char *);
|
||||
typedef int (__stdcall *USBm_Copyright_type) (char *);
|
||||
typedef int (__stdcall *USBm_About_type) (char *);
|
||||
typedef int (__stdcall *USBm_Version_type) (char *);
|
||||
|
||||
public:
|
||||
USBio() : m_hDll(0)
|
||||
{
|
||||
m_hDll = LoadLibrary("USBm.dll");
|
||||
if (m_hDll==0) throw_("could not locate USBm.dll");
|
||||
|
||||
USBm_FindDevices = (USBm_FindDevices_type)GetProcAddress(m_hDll, "USBm_FindDevices");
|
||||
USBm_NumberOfDevices = (USBm_NumberOfDevices_type)GetProcAddress(m_hDll, "USBm_NumberOfDevices");
|
||||
USBm_DeviceValid = (USBm_DeviceValid_type)GetProcAddress(m_hDll, "USBm_DeviceValid");
|
||||
USBm_DeviceVID = (USBm_DeviceVID_type)GetProcAddress(m_hDll, "USBm_DeviceVID");
|
||||
USBm_DevicePID = (USBm_DevicePID_type)GetProcAddress(m_hDll, "USBm_DevicePID");
|
||||
USBm_DeviceDID = (USBm_DeviceDID_type)GetProcAddress(m_hDll, "USBm_DeviceDID");
|
||||
USBm_DeviceMfr = (USBm_DeviceMfr_type)GetProcAddress(m_hDll, "USBm_DeviceMfr");
|
||||
USBm_DeviceProd = (USBm_DeviceProd_type)GetProcAddress(m_hDll, "USBm_DeviceProd");
|
||||
USBm_DeviceSer = (USBm_DeviceSer_type)GetProcAddress(m_hDll, "USBm_DeviceSer");
|
||||
USBm_InitPorts = (USBm_InitPorts_type)GetProcAddress(m_hDll, "USBm_InitPorts");
|
||||
USBm_WriteA = (USBm_WriteA_type)GetProcAddress(m_hDll, "USBm_WriteA");
|
||||
USBm_WriteB = (USBm_WriteB_type)GetProcAddress(m_hDll, "USBm_WriteB");
|
||||
USBm_WriteABit = (USBm_WriteABit_type)GetProcAddress(m_hDll, "USBm_WriteABit");
|
||||
USBm_WriteBBit = (USBm_WriteBBit_type)GetProcAddress(m_hDll, "USBm_WriteBBit");
|
||||
USBm_ReadA = (USBm_ReadA_type)GetProcAddress(m_hDll, "USBm_ReadA");
|
||||
USBm_ReadB = (USBm_ReadB_type)GetProcAddress(m_hDll, "USBm_ReadB");
|
||||
USBm_SetBit = (USBm_SetBit_type)GetProcAddress(m_hDll, "USBm_SetBit");
|
||||
USBm_ResetBit = (USBm_ResetBit_type)GetProcAddress(m_hDll, "USBm_ResetBit");
|
||||
USBm_DirectionA = (USBm_DirectionA_type)GetProcAddress(m_hDll, "USBm_DirectionA");
|
||||
USBm_DirectionB = (USBm_DirectionB_type)GetProcAddress(m_hDll, "USBm_DirectionB");
|
||||
USBm_StrobeWrite = (USBm_StrobeWrite_type)GetProcAddress(m_hDll, "USBm_StrobeWrite");
|
||||
USBm_StrobeRead = (USBm_StrobeRead_type)GetProcAddress(m_hDll, "USBm_StrobeRead");
|
||||
USBm_StrobeWrite2 = (USBm_StrobeWrite2_type)GetProcAddress(m_hDll, "USBm_StrobeWrite2");
|
||||
USBm_StrobeRead2 = (USBm_StrobeRead2_type)GetProcAddress(m_hDll, "USBm_StrobeRead2");
|
||||
USBm_StrobeWrites = (USBm_StrobeWrites_type)GetProcAddress(m_hDll, "USBm_StrobeWrites");
|
||||
USBm_StrobeReads = (USBm_StrobeReads_type)GetProcAddress(m_hDll, "USBm_StrobeReads");
|
||||
USBm_InitLCD = (USBm_InitLCD_type)GetProcAddress(m_hDll, "USBm_InitLCD");
|
||||
USBm_LCDCmd = (USBm_LCDCmd_type)GetProcAddress(m_hDll, "USBm_LCDCmd");
|
||||
USBm_LCDData = (USBm_LCDData_type)GetProcAddress(m_hDll, "USBm_LCDData");
|
||||
USBm_InitSPI = (USBm_InitSPI_type)GetProcAddress(m_hDll, "USBm_InitSPI");
|
||||
USBm_SPIMaster = (USBm_SPIMaster_type)GetProcAddress(m_hDll, "USBm_SPIMaster");
|
||||
USBm_SPISlaveWrite = (USBm_SPISlaveWrite_type)GetProcAddress(m_hDll, "USBm_SPISlaveWrite");
|
||||
USBm_SPISlaveRead = (USBm_SPISlaveRead_type)GetProcAddress(m_hDll, "USBm_SPISlaveRead");
|
||||
USBm_Stepper = (USBm_Stepper_type)GetProcAddress(m_hDll, "USBm_Stepper");
|
||||
USBm_Reset1Wire = (USBm_Reset1Wire_type)GetProcAddress(m_hDll, "USBm_Reset1Wire");
|
||||
USBm_Write1Wire = (USBm_Write1Wire_type)GetProcAddress(m_hDll, "USBm_Write1Wire");
|
||||
USBm_Read1Wire = (USBm_Read1Wire_type)GetProcAddress(m_hDll, "USBm_Read1Wire");
|
||||
USBm_RecentError = (USBm_RecentError_type)GetProcAddress(m_hDll, "USBm_RecentError");
|
||||
USBm_ClearRecentError = (USBm_ClearRecentError_type)GetProcAddress(m_hDll, "USBm_ClearRecentError");
|
||||
USBm_DebugString = (USBm_DebugString_type)GetProcAddress(m_hDll, "USBm_DebugString");
|
||||
USBm_Copyright = (USBm_Copyright_type)GetProcAddress(m_hDll, "USBm_Copyright");
|
||||
USBm_About = (USBm_About_type)GetProcAddress(m_hDll, "USBm_About");
|
||||
USBm_Version = (USBm_Version_type)GetProcAddress(m_hDll, "USBm_Version");
|
||||
}
|
||||
|
||||
~USBio()
|
||||
{
|
||||
assert( m_hDll );
|
||||
// XXX FreeLibrary(m_hDll);
|
||||
m_hDll=0;
|
||||
}
|
||||
|
||||
int Devices() const
|
||||
{
|
||||
assert( m_hDll );
|
||||
unsigned char numdev=USBm_NumberOfDevices();
|
||||
return numdev;
|
||||
}
|
||||
|
||||
string version() const
|
||||
{
|
||||
assert( m_hDll );
|
||||
|
||||
string s;
|
||||
char textstr[300];
|
||||
const int d=Devices();
|
||||
|
||||
s = string(" USBm.dll version = ") + USBm_Version(textstr) + "\n";
|
||||
s += string(" USBm.dll version = ") + textstr + "\n";
|
||||
|
||||
USBm_Copyright(textstr);
|
||||
s += string(" Copyright = ") + textstr + "\n";
|
||||
|
||||
USBm_About(textstr);
|
||||
s += string(" About =") + textstr + "\n";
|
||||
s += string(" Number of devices = ") + d + "\n";
|
||||
|
||||
// Gather info from each discovered device
|
||||
for(int i=0;i<d;++i){
|
||||
s += string(" Device[") + i + "]:\n";
|
||||
s += string(" VID = ") + USBm_DeviceVID(i) + "\n";
|
||||
USBm_DeviceMfr(i,textstr);
|
||||
s += string(" Manuf = ") + textstr + "\n";
|
||||
s += string(" PID = ") + USBm_DevicePID(i) + "\n";
|
||||
USBm_DeviceProd(i,textstr);
|
||||
s += string(" Prod = ") + textstr + "\n";
|
||||
s += string(" DID = ") + USBm_DeviceDID(i) + "\n";
|
||||
USBm_DeviceSer(i,textstr);
|
||||
s += string(" Serial = ") + textstr + "\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
USBm_FindDevices_type USBm_FindDevices;
|
||||
USBm_NumberOfDevices_type USBm_NumberOfDevices;
|
||||
USBm_DeviceValid_type USBm_DeviceValid;
|
||||
USBm_DeviceVID_type USBm_DeviceVID;
|
||||
USBm_DevicePID_type USBm_DevicePID;
|
||||
USBm_DeviceDID_type USBm_DeviceDID;
|
||||
USBm_DeviceMfr_type USBm_DeviceMfr;
|
||||
USBm_DeviceProd_type USBm_DeviceProd;
|
||||
USBm_DeviceSer_type USBm_DeviceSer;
|
||||
USBm_InitPorts_type USBm_InitPorts;
|
||||
USBm_WriteA_type USBm_WriteA;
|
||||
USBm_WriteB_type USBm_WriteB;
|
||||
USBm_WriteABit_type USBm_WriteABit;
|
||||
USBm_WriteBBit_type USBm_WriteBBit;
|
||||
USBm_ReadA_type USBm_ReadA;
|
||||
USBm_ReadB_type USBm_ReadB;
|
||||
USBm_SetBit_type USBm_SetBit;
|
||||
USBm_ResetBit_type USBm_ResetBit;
|
||||
USBm_DirectionA_type USBm_DirectionA;
|
||||
USBm_DirectionB_type USBm_DirectionB;
|
||||
USBm_StrobeWrite_type USBm_StrobeWrite;
|
||||
USBm_StrobeRead_type USBm_StrobeRead;
|
||||
USBm_StrobeWrite2_type USBm_StrobeWrite2;
|
||||
USBm_StrobeRead2_type USBm_StrobeRead2;
|
||||
USBm_StrobeWrites_type USBm_StrobeWrites;
|
||||
USBm_StrobeReads_type USBm_StrobeReads;
|
||||
USBm_InitLCD_type USBm_InitLCD;
|
||||
USBm_LCDCmd_type USBm_LCDCmd;
|
||||
USBm_LCDData_type USBm_LCDData;
|
||||
USBm_InitSPI_type USBm_InitSPI;
|
||||
USBm_SPIMaster_type USBm_SPIMaster;
|
||||
USBm_SPISlaveWrite_type USBm_SPISlaveWrite;
|
||||
USBm_SPISlaveRead_type USBm_SPISlaveRead;
|
||||
USBm_Stepper_type USBm_Stepper;
|
||||
USBm_Reset1Wire_type USBm_Reset1Wire;
|
||||
USBm_Write1Wire_type USBm_Write1Wire;
|
||||
USBm_Read1Wire_type USBm_Read1Wire;
|
||||
USBm_RecentError_type USBm_RecentError;
|
||||
USBm_ClearRecentError_type USBm_ClearRecentError;
|
||||
USBm_DebugString_type USBm_DebugString;
|
||||
USBm_Copyright_type USBm_Copyright;
|
||||
USBm_About_type USBm_About;
|
||||
USBm_Version_type USBm_Version;
|
||||
};
|
||||
|
||||
#endif // __USBM_H__
|
||||
27
vendor/wiiscan/0.90/src/wiiscan.cpp
vendored
27
vendor/wiiscan/0.90/src/wiiscan.cpp
vendored
@@ -1,27 +0,0 @@
|
||||
// Copyright © 2009 MergeIt, Aps.
|
||||
//
|
||||
// License LGPLv3+: GNU lesser LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>.
|
||||
// This is free software: you are free to change and redistribute it.
|
||||
// There is NO WARRANTY, to the extent permitted by law.
|
||||
//
|
||||
// This file is part of wiiscan.
|
||||
//
|
||||
// wiiscan 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
|
||||
// any later version.
|
||||
//
|
||||
// wiiscan 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 wiiscan. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "wiiscan.h"
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
return Wiiscan::main(argc,argv);
|
||||
}
|
||||
1108
vendor/wiiscan/0.90/src/wiiscan.h
vendored
1108
vendor/wiiscan/0.90/src/wiiscan.h
vendored
File diff suppressed because it is too large
Load Diff
653
vendor/wiiscan/0.90/src/wiiuse.h
vendored
653
vendor/wiiscan/0.90/src/wiiuse.h
vendored
@@ -1,653 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief 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))
|
||||
|
||||
/**
|
||||
* @brief Return the IR sensitivity level.
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param lvl [out] Pointer to an int that will hold the level setting.
|
||||
* If no level is set 'lvl' will be set to 0.
|
||||
*/
|
||||
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
|
||||
do { \
|
||||
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
|
||||
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
|
||||
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
|
||||
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
|
||||
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
|
||||
else *lvl = 0; \
|
||||
} while (0)
|
||||
|
||||
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
|
||||
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
|
||||
#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
|
||||
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
|
||||
|
||||
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
|
||||
|
||||
/*
|
||||
* Largest known payload is 21 bytes.
|
||||
* Add 2 for the prefix and round up to a power of 2.
|
||||
*/
|
||||
#define MAX_PAYLOAD 32
|
||||
|
||||
/*
|
||||
* This is left over from an old hack, but it may actually
|
||||
* be a useful feature to keep so it wasn't removed.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
#define WIIMOTE_DEFAULT_TIMEOUT 10
|
||||
#define WIIMOTE_EXP_TIMEOUT 10
|
||||
#endif
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef char sbyte;
|
||||
|
||||
struct wiimote_t;
|
||||
struct vec3b_t;
|
||||
struct orient_t;
|
||||
struct gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Pointer to the filled data block.
|
||||
* @param len Length in bytes of the data block.
|
||||
*
|
||||
* @see wiiuse_init()
|
||||
*
|
||||
* A registered function of this type is called automatically by the wiiuse
|
||||
* library when the wiimote has returned the full data requested by a previous
|
||||
* call to wiiuse_read_data().
|
||||
*/
|
||||
typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
|
||||
|
||||
/**
|
||||
* @struct read_req_t
|
||||
* @brief Data read request structure.
|
||||
*/
|
||||
struct read_req_t {
|
||||
wiiuse_read_cb cb; /**< read data callback */
|
||||
byte* buf; /**< buffer where read data is written */
|
||||
unsigned int addr; /**< the offset that the read started at */
|
||||
unsigned short size; /**< the length of the data read */
|
||||
unsigned short wait; /**< num bytes still needed to finish read */
|
||||
byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */
|
||||
|
||||
struct read_req_t* next; /**< next read request in the queue */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec2b_t
|
||||
* @brief Unsigned x,y byte vector.
|
||||
*/
|
||||
typedef struct vec2b_t {
|
||||
byte x, y;
|
||||
} vec2b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3b_t
|
||||
* @brief Unsigned x,y,z byte vector.
|
||||
*/
|
||||
typedef struct vec3b_t {
|
||||
byte x, y, z;
|
||||
} vec3b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3f_t
|
||||
* @brief Signed x,y,z float struct.
|
||||
*/
|
||||
typedef struct vec3f_t {
|
||||
float x, y, z;
|
||||
} vec3f_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct orient_t
|
||||
* @brief Orientation struct.
|
||||
*
|
||||
* Yaw, pitch, and roll range from -180 to 180 degrees.
|
||||
*/
|
||||
typedef struct orient_t {
|
||||
float roll; /**< roll, this may be smoothed if enabled */
|
||||
float pitch; /**< pitch, this may be smoothed if enabled */
|
||||
float yaw;
|
||||
|
||||
float a_roll; /**< absolute roll, unsmoothed */
|
||||
float a_pitch; /**< absolute pitch, unsmoothed */
|
||||
} orient_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct gforce_t
|
||||
* @brief Gravity force struct.
|
||||
*/
|
||||
typedef struct gforce_t {
|
||||
float x, y, z;
|
||||
} gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct accel_t
|
||||
* @brief Accelerometer struct. For any device with an accelerometer.
|
||||
*/
|
||||
typedef struct accel_t {
|
||||
struct vec3b_t cal_zero; /**< zero calibration */
|
||||
struct vec3b_t cal_g; /**< 1g difference around 0cal */
|
||||
|
||||
float st_roll; /**< last smoothed roll value */
|
||||
float st_pitch; /**< last smoothed roll pitch */
|
||||
float st_alpha; /**< alpha value for smoothing [0-1] */
|
||||
} accel_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_dot_t
|
||||
* @brief A single IR source.
|
||||
*/
|
||||
typedef struct ir_dot_t {
|
||||
byte visible; /**< if the IR source is visible */
|
||||
|
||||
unsigned int x; /**< interpolated X coordinate */
|
||||
unsigned int y; /**< interpolated Y coordinate */
|
||||
|
||||
short rx; /**< raw X coordinate (0-1023) */
|
||||
short ry; /**< raw Y coordinate (0-767) */
|
||||
|
||||
byte order; /**< increasing order by x-axis value */
|
||||
|
||||
byte size; /**< size of the IR dot (0-15) */
|
||||
} ir_dot_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum aspect_t
|
||||
* @brief Screen aspect ratio.
|
||||
*/
|
||||
typedef enum aspect_t {
|
||||
WIIUSE_ASPECT_4_3,
|
||||
WIIUSE_ASPECT_16_9
|
||||
} aspect_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_t
|
||||
* @brief IR struct. Hold all data related to the IR tracking.
|
||||
*/
|
||||
typedef struct ir_t {
|
||||
struct ir_dot_t dot[4]; /**< IR dots */
|
||||
byte num_dots; /**< number of dots at this time */
|
||||
|
||||
enum aspect_t aspect; /**< aspect ratio of the screen */
|
||||
|
||||
enum ir_position_t pos; /**< IR sensor bar position */
|
||||
|
||||
unsigned int vres[2]; /**< IR virtual screen resolution */
|
||||
int offset[2]; /**< IR XY correction offset */
|
||||
int state; /**< keeps track of the IR state */
|
||||
|
||||
int ax; /**< absolute X coordinate */
|
||||
int ay; /**< absolute Y coordinate */
|
||||
|
||||
int x; /**< calculated X coordinate */
|
||||
int y; /**< calculated Y coordinate */
|
||||
|
||||
float distance; /**< pixel distance between first 2 dots*/
|
||||
float z; /**< calculated distance */
|
||||
} ir_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct joystick_t
|
||||
* @brief Joystick calibration structure.
|
||||
*
|
||||
* The angle \a ang is relative to the positive y-axis into quadrant I
|
||||
* and ranges from 0 to 360 degrees. So if the joystick is held straight
|
||||
* upwards then angle is 0 degrees. If it is held to the right it is 90,
|
||||
* down is 180, and left is 270.
|
||||
*
|
||||
* The magnitude \a mag is the distance from the center to where the
|
||||
* joystick is being held. The magnitude ranges from 0 to 1.
|
||||
* If the joystick is only slightly tilted from the center the magnitude
|
||||
* will be low, but if it is closer to the outter edge the value will
|
||||
* be higher.
|
||||
*/
|
||||
typedef struct joystick_t {
|
||||
struct vec2b_t max; /**< maximum joystick values */
|
||||
struct vec2b_t min; /**< minimum joystick values */
|
||||
struct vec2b_t center; /**< center joystick values */
|
||||
|
||||
float ang; /**< angle the joystick is being held */
|
||||
float mag; /**< magnitude of the joystick (range 0-1) */
|
||||
} joystick_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct nunchuk_t
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
typedef struct nunchuk_t {
|
||||
struct accel_t accel_calib; /**< nunchuk accelerometer calibration */
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
|
||||
int* flags; /**< options flag (points to wiimote_t.flags) */
|
||||
|
||||
byte btns; /**< what buttons have just been pressed */
|
||||
byte btns_held; /**< what buttons are being held down */
|
||||
byte btns_released; /**< what buttons were just released this */
|
||||
|
||||
float orient_threshold; /**< threshold for orient to generate an event */
|
||||
int accel_threshold; /**< threshold for accel to generate an event */
|
||||
|
||||
struct vec3b_t accel; /**< current raw acceleration data */
|
||||
struct orient_t orient; /**< current orientation on each axis */
|
||||
struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
} nunchuk_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct classic_ctrl_t
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
typedef struct classic_ctrl_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
float r_shoulder; /**< right shoulder button (range 0-1) */
|
||||
float l_shoulder; /**< left shoulder button (range 0-1) */
|
||||
|
||||
struct joystick_t ljs; /**< left joystick calibration */
|
||||
struct joystick_t rjs; /**< right joystick calibration */
|
||||
} classic_ctrl_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct guitar_hero_3_t
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
typedef struct guitar_hero_3_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
float whammy_bar; /**< whammy bar (range 0-1) */
|
||||
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
} guitar_hero_3_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct expansion_t
|
||||
* @brief Generic expansion device plugged into wiimote.
|
||||
*/
|
||||
typedef struct expansion_t {
|
||||
int type; /**< type of expansion attached */
|
||||
|
||||
union {
|
||||
struct nunchuk_t nunchuk;
|
||||
struct classic_ctrl_t classic;
|
||||
struct guitar_hero_3_t gh3;
|
||||
};
|
||||
} expansion_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum win32_bt_stack_t
|
||||
* @brief Available bluetooth stacks for Windows.
|
||||
*/
|
||||
typedef enum win_bt_stack_t {
|
||||
WIIUSE_STACK_UNKNOWN,
|
||||
WIIUSE_STACK_MS,
|
||||
WIIUSE_STACK_BLUESOLEIL
|
||||
} win_bt_stack_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct wiimote_state_t
|
||||
* @brief Significant data from the previous event.
|
||||
*/
|
||||
typedef struct wiimote_state_t {
|
||||
/* expansion_t */
|
||||
float exp_ljs_ang;
|
||||
float exp_rjs_ang;
|
||||
float exp_ljs_mag;
|
||||
float exp_rjs_mag;
|
||||
unsigned short exp_btns;
|
||||
struct orient_t exp_orient;
|
||||
struct vec3b_t exp_accel;
|
||||
float exp_r_shoulder;
|
||||
float exp_l_shoulder;
|
||||
|
||||
/* ir_t */
|
||||
int ir_ax;
|
||||
int ir_ay;
|
||||
float ir_distance;
|
||||
|
||||
struct orient_t orient;
|
||||
unsigned short btns;
|
||||
|
||||
struct vec3b_t accel;
|
||||
} wiimote_state_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum WIIUSE_EVENT_TYPE
|
||||
* @brief Events that wiiuse can generate from a poll.
|
||||
*/
|
||||
typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_NONE = 0,
|
||||
WIIUSE_EVENT,
|
||||
WIIUSE_STATUS,
|
||||
WIIUSE_CONNECT,
|
||||
WIIUSE_DISCONNECT,
|
||||
WIIUSE_UNEXPECTED_DISCONNECT,
|
||||
WIIUSE_READ_DATA,
|
||||
WIIUSE_NUNCHUK_INSERTED,
|
||||
WIIUSE_NUNCHUK_REMOVED,
|
||||
WIIUSE_CLASSIC_CTRL_INSERTED,
|
||||
WIIUSE_CLASSIC_CTRL_REMOVED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
|
||||
} WIIUSE_EVENT_TYPE;
|
||||
|
||||
/**
|
||||
* @struct wiimote_t
|
||||
* @brief Wiimote structure.
|
||||
*/
|
||||
typedef struct wiimote_t {
|
||||
WCONST int unid; /**< user specified id */
|
||||
|
||||
#ifndef WIN32
|
||||
WCONST bdaddr_t bdaddr; /**< bt address */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST int out_sock; /**< output socket */
|
||||
WCONST int in_sock; /**< input socket */
|
||||
#else
|
||||
WCONST HANDLE dev_handle; /**< HID handle */
|
||||
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
|
||||
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
|
||||
WCONST int timeout; /**< read timeout */
|
||||
WCONST byte normal_timeout; /**< normal timeout */
|
||||
WCONST byte exp_timeout; /**< timeout for expansion handshake */
|
||||
#endif
|
||||
|
||||
WCONST int state; /**< various state flags */
|
||||
WCONST byte leds; /**< currently lit leds */
|
||||
WCONST float battery_level; /**< battery level */
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
WCONST byte handshake_state; /**< the state of the connection handshake */
|
||||
|
||||
WCONST struct read_req_t* read_req; /**< list of data read requests */
|
||||
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
|
||||
WCONST struct expansion_t exp; /**< wiimote expansion device */
|
||||
|
||||
WCONST struct vec3b_t accel; /**< current raw acceleration data */
|
||||
WCONST struct orient_t orient; /**< current orientation on each axis */
|
||||
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
|
||||
WCONST struct ir_t ir; /**< IR data */
|
||||
|
||||
WCONST unsigned short btns; /**< what buttons have just been pressed */
|
||||
WCONST unsigned short btns_held; /**< what buttons are being held down */
|
||||
WCONST unsigned short btns_released; /**< what buttons were just released this */
|
||||
|
||||
WCONST float orient_threshold; /**< threshold for orient to generate an event */
|
||||
WCONST int accel_threshold; /**< threshold for accel to generate an event */
|
||||
|
||||
WCONST struct wiimote_state_t lstate; /**< last saved state */
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
|
||||
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
|
||||
} wiimote;
|
||||
|
||||
|
||||
/*****************************************
|
||||
*
|
||||
* Include API specific stuff
|
||||
*
|
||||
*****************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIIUSE_EXPORT_DECL __declspec(dllexport)
|
||||
#define WIIUSE_IMPORT_DECL __declspec(dllimport)
|
||||
#else
|
||||
#define WIIUSE_EXPORT_DECL
|
||||
#define WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_COMPILE_LIB
|
||||
#define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
|
||||
#else
|
||||
#define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* wiiuse.c */
|
||||
WIIUSE_EXPORT extern const char* wiiuse_version();
|
||||
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
/* connect.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
|
||||
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* WIIUSE_H_INCLUDED */
|
||||
|
||||
20
vendor/wiiscan/0.90/wiiscan.sln
vendored
20
vendor/wiiscan/0.90/wiiscan.sln
vendored
@@ -1,20 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual C++ Express 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wiiscan", "wiiscan.vcproj", "{6E522A84-9956-44F9-B30A-CF44F3CED276}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6E522A84-9956-44F9-B30A-CF44F3CED276}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{6E522A84-9956-44F9-B30A-CF44F3CED276}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{6E522A84-9956-44F9-B30A-CF44F3CED276}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{6E522A84-9956-44F9-B30A-CF44F3CED276}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
1662
vendor/wiiscan/0.90/wiiscan.test.h
vendored
1662
vendor/wiiscan/0.90/wiiscan.test.h
vendored
File diff suppressed because it is too large
Load Diff
243
vendor/wiiscan/0.90/wiiscan.vcproj
vendored
243
vendor/wiiscan/0.90/wiiscan.vcproj
vendored
@@ -1,243 +0,0 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Name="wiiscan"
|
||||
ProjectGUID="{6E522A84-9956-44F9-B30A-CF44F3CED276}"
|
||||
RootNamespace="wiiscan"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateManifest="false"
|
||||
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="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="false"
|
||||
FavorSizeOrSpeed="1"
|
||||
WholeProgramOptimization="true"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateManifest="false"
|
||||
GenerateDebugInformation="false"
|
||||
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="Headers"
|
||||
Filter="*.h"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\args.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\configfile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DelcomDLL.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\exception.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\file.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\funs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\stringfun.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\toolsfun.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\usbm.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\wiiscan.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\wiiuse.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\CHANGELOG"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\LICENSE"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\README"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\wiiscan.cpp"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
190
vendor/wiiuse/0.12/classic.c
vendored
190
vendor/wiiuse/0.12/classic.c
vendored
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "classic.h"
|
||||
|
||||
static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the classic controller.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @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 offset = 0;
|
||||
|
||||
cc->btns = 0;
|
||||
cc->btns_held = 0;
|
||||
cc->btns_released = 0;
|
||||
cc->r_shoulder = 0;
|
||||
cc->l_shoulder = 0;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
/* joystick stuff */
|
||||
cc->ljs.max.x = data[0 + offset] / 4;
|
||||
cc->ljs.min.x = data[1 + offset] / 4;
|
||||
cc->ljs.center.x = data[2 + offset] / 4;
|
||||
cc->ljs.max.y = data[3 + offset] / 4;
|
||||
cc->ljs.min.y = data[4 + offset] / 4;
|
||||
cc->ljs.center.y = data[5 + offset] / 4;
|
||||
|
||||
cc->rjs.max.x = data[6 + offset] / 8;
|
||||
cc->rjs.min.x = data[7 + offset] / 8;
|
||||
cc->rjs.center.x = data[8 + offset] / 8;
|
||||
cc->rjs.max.y = data[9 + offset] / 8;
|
||||
cc->rjs.min.y = data[10 + offset] / 8;
|
||||
cc->rjs.center.y = data[11 + offset] / 8;
|
||||
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_CLASSIC;
|
||||
|
||||
#ifdef WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The classic controller disconnected.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
*/
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc) {
|
||||
memset(cc, 0, sizeof(struct classic_ctrl_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle classic controller event.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg) {
|
||||
int i, lx, ly, rx, ry;
|
||||
byte l, r;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
classic_ctrl_pressed_buttons(cc, BIG_ENDIAN_SHORT(*(short*)(msg + 4)));
|
||||
|
||||
/* left/right buttons */
|
||||
l = (((msg[2] & 0x60) >> 2) | ((msg[3] & 0xE0) >> 5));
|
||||
r = (msg[3] & 0x1F);
|
||||
|
||||
/*
|
||||
* TODO - LR range hardcoded from 0x00 to 0x1F.
|
||||
* This is probably in the calibration somewhere.
|
||||
*/
|
||||
cc->r_shoulder = ((float)r / 0x1F);
|
||||
cc->l_shoulder = ((float)l / 0x1F);
|
||||
|
||||
/* calculate joystick orientation */
|
||||
lx = (msg[0] & 0x3F);
|
||||
ly = (msg[1] & 0x3F);
|
||||
rx = ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7);
|
||||
ry = (msg[2] & 0x1F);
|
||||
|
||||
calc_joystick_state(&cc->ljs, lx, ly);
|
||||
calc_joystick_state(&cc->rjs, rx, ry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & CLASSIC_CTRL_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
cc->btns_held = (now & cc->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
cc->btns_released = ((cc->btns | cc->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
cc->btns = now;
|
||||
}
|
||||
53
vendor/wiiuse/0.12/classic.h
vendored
53
vendor/wiiuse/0.12/classic.h
vendored
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
|
||||
#ifndef CLASSIC_H_INCLUDED
|
||||
#define CLASSIC_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len);
|
||||
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc);
|
||||
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CLASSIC_H_INCLUDED
|
||||
79
vendor/wiiuse/0.12/definitions.h
vendored
79
vendor/wiiuse/0.12/definitions.h
vendored
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief General definitions.
|
||||
*/
|
||||
|
||||
#ifndef DEFINITIONS_H_INCLUDED
|
||||
#define DEFINITIONS_H_INCLUDED
|
||||
|
||||
/* this is wiiuse - used to distinguish from third party programs using wiiuse.h */
|
||||
#include "os.h"
|
||||
|
||||
#define WIIMOTE_PI 3.14159265f
|
||||
|
||||
//#define WITH_WIIUSE_DEBUG
|
||||
|
||||
/* Error output macros */
|
||||
#define WIIUSE_ERROR(fmt, ...) fprintf(stderr, "[ERROR] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
/* Warning output macros */
|
||||
#define WIIUSE_WARNING(fmt, ...) fprintf(stderr, "[WARNING] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
/* 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)
|
||||
#else
|
||||
#define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
#else
|
||||
#define WIIUSE_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
/* Convert between radians and degrees */
|
||||
#define RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI)
|
||||
#define DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f))
|
||||
|
||||
/* Convert to big endian */
|
||||
#define BIG_ENDIAN_LONG(i) (htonl(i))
|
||||
#define BIG_ENDIAN_SHORT(i) (htons(i))
|
||||
|
||||
#define absf(x) ((x >= 0) ? (x) : (x * -1.0f))
|
||||
#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x)))
|
||||
|
||||
#endif // DEFINITIONS_H_INCLUDED
|
||||
228
vendor/wiiuse/0.12/dynamics.c
vendored
228
vendor/wiiuse/0.12/dynamics.c
vendored
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles the dynamics of the wiimote.
|
||||
*
|
||||
* The file includes functions that handle the dynamics
|
||||
* of the wiimote. Such dynamics include orientation and
|
||||
* motion sensing.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "ir.h"
|
||||
#include "dynamics.h"
|
||||
|
||||
/**
|
||||
* @brief Calculate the roll, pitch, yaw.
|
||||
*
|
||||
* @param ac An accelerometer (accel_t) structure.
|
||||
* @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data.
|
||||
* @param orient [out] Pointer to a orient_t structure that will hold the orientation data.
|
||||
* @param rorient [out] Pointer to a orient_t structure that will hold the non-smoothed orientation data.
|
||||
* @param smooth If smoothing should be performed on the angles calculated. 1 to enable, 0 to disable.
|
||||
*
|
||||
* Given the raw acceleration data from the accelerometer struct, calculate
|
||||
* the orientation of the device and set it in the \a orient parameter.
|
||||
*/
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth) {
|
||||
float xg, yg, zg;
|
||||
float x, y, z;
|
||||
|
||||
/*
|
||||
* roll - use atan(z / x) [ ranges from -180 to 180 ]
|
||||
* pitch - use atan(z / y) [ ranges from -180 to 180 ]
|
||||
* yaw - impossible to tell without IR
|
||||
*/
|
||||
|
||||
/* yaw - set to 0, IR will take care of it if it's enabled */
|
||||
orient->yaw = 0.0f;
|
||||
|
||||
/* find out how much it has to move to be 1g */
|
||||
xg = (float)ac->cal_g.x;
|
||||
yg = (float)ac->cal_g.y;
|
||||
zg = (float)ac->cal_g.z;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
x = ((float)accel->x - (float)ac->cal_zero.x) / xg;
|
||||
y = ((float)accel->y - (float)ac->cal_zero.y) / yg;
|
||||
z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
|
||||
/* make sure x,y,z are between -1 and 1 for the tan functions */
|
||||
if (x < -1.0f) x = -1.0f;
|
||||
else if (x > 1.0f) x = 1.0f;
|
||||
if (y < -1.0f) y = -1.0f;
|
||||
else if (y > 1.0f) y = 1.0f;
|
||||
if (z < -1.0f) z = -1.0f;
|
||||
else if (z > 1.0f) z = 1.0f;
|
||||
|
||||
/* if it is over 1g then it is probably accelerating and not reliable */
|
||||
if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) {
|
||||
/* roll */
|
||||
x = RAD_TO_DEGREE(atan2f(x, z));
|
||||
|
||||
orient->roll = x;
|
||||
orient->a_roll = x;
|
||||
}
|
||||
|
||||
if (abs(accel->y - ac->cal_zero.y) <= ac->cal_g.y) {
|
||||
/* pitch */
|
||||
y = RAD_TO_DEGREE(atan2f(y, z));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the gravity forces on each axis.
|
||||
*
|
||||
* @param ac An accelerometer (accel_t) structure.
|
||||
* @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data.
|
||||
* @param gforce [out] Pointer to a gforce_t structure that will hold the gravity force data.
|
||||
*/
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce) {
|
||||
float xg, yg, zg;
|
||||
|
||||
/* find out how much it has to move to be 1g */
|
||||
xg = (float)ac->cal_g.x;
|
||||
yg = (float)ac->cal_g.y;
|
||||
zg = (float)ac->cal_g.z;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
gforce->x = ((float)accel->x - (float)ac->cal_zero.x) / xg;
|
||||
gforce->y = ((float)accel->y - (float)ac->cal_zero.y) / yg;
|
||||
gforce->z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the angle and magnitude of a joystick.
|
||||
*
|
||||
* @param js [out] Pointer to a joystick_t structure.
|
||||
* @param x The raw x-axis value.
|
||||
* @param y The raw y-axis value.
|
||||
*/
|
||||
void calc_joystick_state(struct joystick_t* js, float x, float y) {
|
||||
float rx, ry, ang;
|
||||
|
||||
/*
|
||||
* Since the joystick center may not be exactly:
|
||||
* (min + max) / 2
|
||||
* Then the range from the min to the center and the center to the max
|
||||
* may be different.
|
||||
* Because of this, depending on if the current x or y value is greater
|
||||
* or less than the assoicated axis center value, it needs to be interpolated
|
||||
* between the center and the minimum or maxmimum rather than between
|
||||
* the minimum and maximum.
|
||||
*
|
||||
* So we have something like this:
|
||||
* (x min) [-1] ---------*------ [0] (x center) [0] -------- [1] (x max)
|
||||
* Where the * is the current x value.
|
||||
* The range is therefore -1 to 1, 0 being the exact center rather than
|
||||
* the middle of min and max.
|
||||
*/
|
||||
if (x == js->center.x)
|
||||
rx = 0;
|
||||
else if (x >= js->center.x)
|
||||
rx = ((float)(x - js->center.x) / (float)(js->max.x - js->center.x));
|
||||
else
|
||||
rx = ((float)(x - js->min.x) / (float)(js->center.x - js->min.x)) - 1.0f;
|
||||
|
||||
if (y == js->center.y)
|
||||
ry = 0;
|
||||
else if (y >= js->center.y)
|
||||
ry = ((float)(y - js->center.y) / (float)(js->max.y - js->center.y));
|
||||
else
|
||||
ry = ((float)(y - js->min.y) / (float)(js->center.y - js->min.y)) - 1.0f;
|
||||
|
||||
/* calculate the joystick angle and magnitude */
|
||||
ang = RAD_TO_DEGREE(atanf(ry / rx));
|
||||
ang -= 90.0f;
|
||||
if (rx < 0.0f)
|
||||
ang -= 180.0f;
|
||||
js->ang = absf(ang);
|
||||
js->mag = (float) sqrt((rx * rx) + (ry * ry));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/*
|
||||
* If the sign changes (which will happen if going from -180 to 180)
|
||||
* or from (-1 to 1) then don't smooth, just use the new angle.
|
||||
*/
|
||||
if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) {
|
||||
ac->st_roll = orient->roll;
|
||||
} else {
|
||||
orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll));
|
||||
ac->st_roll = orient->roll;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
case SMOOTH_PITCH:
|
||||
{
|
||||
if (isnan(ac->st_pitch) || isinf(ac->st_pitch))
|
||||
ac->st_pitch = 0.0f;
|
||||
|
||||
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
||||
ac->st_pitch = orient->pitch;
|
||||
} else {
|
||||
orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch));
|
||||
ac->st_pitch = orient->pitch;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
vendor/wiiuse/0.12/dynamics.h
vendored
56
vendor/wiiuse/0.12/dynamics.h
vendored
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles the dynamics of the wiimote.
|
||||
*
|
||||
* The file includes functions that handle the dynamics
|
||||
* of the wiimote. Such dynamics include orientation and
|
||||
* motion sensing.
|
||||
*/
|
||||
|
||||
#ifndef DYNAMICS_H_INCLUDED
|
||||
#define DYNAMICS_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth);
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce);
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DYNAMICS_H_INCLUDED
|
||||
878
vendor/wiiuse/0.12/events.c
vendored
878
vendor/wiiuse/0.12/events.c
vendored
@@ -1,878 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles 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
|
||||
#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);
|
||||
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 */
|
||||
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 */
|
||||
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid);
|
||||
perror("Error Details");
|
||||
|
||||
if (errno == ENOTCONN) {
|
||||
/* this can happen if the bluetooth dongle is disconnected */
|
||||
WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid);
|
||||
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);
|
||||
}
|
||||
|
||||
/* clear out any old read requests */
|
||||
clear_dirty_reads(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear out all old 'dirty' read requests.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void clear_dirty_reads(struct wiimote_t* wm) {
|
||||
struct read_req_t* req = wm->read_req;
|
||||
|
||||
while (req && req->dirty) {
|
||||
WIIUSE_DEBUG("Cleared old read request for address: %x", req->addr);
|
||||
|
||||
wm->read_req = req->next;
|
||||
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);
|
||||
|
||||
/* 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 (!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;
|
||||
free(req);
|
||||
} else {
|
||||
/*
|
||||
* This should generate an event.
|
||||
* We need to leave the event in the array so the client
|
||||
* can access it still. We'll flag is as being 'dirty'
|
||||
* and give the client one cycle to use it. Next event
|
||||
* we will remove it from the list.
|
||||
*/
|
||||
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 (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;
|
||||
}
|
||||
54
vendor/wiiuse/0.12/events.h
vendored
54
vendor/wiiuse/0.12/events.h
vendored
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles wiimote events.
|
||||
*
|
||||
* The file includes functions that handle the events
|
||||
* that are sent from the wiimote to us.
|
||||
*/
|
||||
|
||||
#ifndef EVENTS_H_INCLUDED
|
||||
#define EVENTS_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // EVENTS_H_INCLUDED
|
||||
172
vendor/wiiuse/0.12/guitar_hero_3.c
vendored
172
vendor/wiiuse/0.12/guitar_hero_3.c
vendored
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "guitar_hero_3.h"
|
||||
|
||||
static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the guitar.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @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 offset = 0;
|
||||
|
||||
/*
|
||||
* The good fellows that made the Guitar Hero 3 controller
|
||||
* failed to factory calibrate the devices. There is no
|
||||
* calibration data on the device.
|
||||
*/
|
||||
|
||||
gh3->btns = 0;
|
||||
gh3->btns_held = 0;
|
||||
gh3->btns_released = 0;
|
||||
gh3->whammy_bar = 0.0f;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* joystick stuff */
|
||||
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;
|
||||
gh3->js.min.x = GUITAR_HERO_3_JS_MIN_X;
|
||||
gh3->js.center.x = GUITAR_HERO_3_JS_CENTER_X;
|
||||
gh3->js.max.y = GUITAR_HERO_3_JS_MAX_Y;
|
||||
gh3->js.min.y = GUITAR_HERO_3_JS_MIN_Y;
|
||||
gh3->js.center.y = GUITAR_HERO_3_JS_CENTER_Y;
|
||||
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_GUITAR_HERO_3;
|
||||
|
||||
#ifdef WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The guitar disconnected.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
*/
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3) {
|
||||
memset(gh3, 0, sizeof(struct guitar_hero_3_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle guitar event.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
guitar_hero_3_pressed_buttons(gh3, BIG_ENDIAN_SHORT(*(short*)(msg + 4)));
|
||||
|
||||
/* whammy bar */
|
||||
gh3->whammy_bar = (msg[3] - GUITAR_HERO_3_WHAMMY_BAR_MIN) / (float)(GUITAR_HERO_3_WHAMMY_BAR_MAX - GUITAR_HERO_3_WHAMMY_BAR_MIN);
|
||||
|
||||
/* joy stick */
|
||||
calc_joystick_state(&gh3->js, msg[0], msg[1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & GUITAR_HERO_3_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
gh3->btns_held = (now & gh3->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
gh3->btns_released = ((gh3->btns | gh3->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
gh3->btns = now;
|
||||
}
|
||||
62
vendor/wiiuse/0.12/guitar_hero_3.h
vendored
62
vendor/wiiuse/0.12/guitar_hero_3.h
vendored
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
|
||||
#ifndef GUITAR_HERO_3_H_INCLUDED
|
||||
#define GUITAR_HERO_3_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define GUITAR_HERO_3_JS_MIN_X 0xC5
|
||||
#define GUITAR_HERO_3_JS_MAX_X 0xFC
|
||||
#define GUITAR_HERO_3_JS_CENTER_X 0xE0
|
||||
#define GUITAR_HERO_3_JS_MIN_Y 0xC5
|
||||
#define GUITAR_HERO_3_JS_MAX_Y 0xFA
|
||||
#define GUITAR_HERO_3_JS_CENTER_Y 0xE0
|
||||
#define GUITAR_HERO_3_WHAMMY_BAR_MIN 0xEF
|
||||
#define GUITAR_HERO_3_WHAMMY_BAR_MAX 0xFA
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len);
|
||||
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3);
|
||||
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GUITAR_HERO_3_H_INCLUDED
|
||||
119
vendor/wiiuse/0.12/io.c
vendored
119
vendor/wiiuse/0.12/io.c
vendored
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O (non-OS specific).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get initialization data from the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data unused
|
||||
* @param len unused
|
||||
*
|
||||
* When first called for a wiimote_t structure, a request
|
||||
* is sent to the wiimote for initialization information.
|
||||
* This includes factory set accelerometer data.
|
||||
* The handshake will be concluded when the wiimote responds
|
||||
* with this data.
|
||||
*/
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
if (!wm) return;
|
||||
|
||||
switch (wm->handshake_state) {
|
||||
case 0:
|
||||
{
|
||||
/* send request to wiimote for accelerometer calibration */
|
||||
byte* buf;
|
||||
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
buf = (byte*)malloc(sizeof(byte) * 8);
|
||||
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
|
||||
wm->handshake_state++;
|
||||
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
struct read_req_t* req = wm->read_req;
|
||||
struct accel_t* accel = &wm->accel_calib;
|
||||
|
||||
/* received read data */
|
||||
accel->cal_zero.x = req->buf[0];
|
||||
accel->cal_zero.y = req->buf[1];
|
||||
accel->cal_zero.z = req->buf[2];
|
||||
|
||||
accel->cal_g.x = req->buf[4] - accel->cal_zero.x;
|
||||
accel->cal_g.y = req->buf[5] - accel->cal_zero.y;
|
||||
accel->cal_g.z = req->buf[6] - accel->cal_zero.z;
|
||||
|
||||
/* done with the buffer */
|
||||
free(req->buf);
|
||||
|
||||
/* handshake is done */
|
||||
WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x",
|
||||
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
|
||||
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
|
||||
|
||||
|
||||
/* 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)) {
|
||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
vendor/wiiuse/0.12/io.h
vendored
56
vendor/wiiuse/0.12/io.h
vendored
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O.
|
||||
*/
|
||||
|
||||
#ifndef CONNECT_H_INCLUDED
|
||||
#define CONNECT_H_INCLUDED
|
||||
|
||||
#ifndef WIN32
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm);
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CONNECT_H_INCLUDED
|
||||
270
vendor/wiiuse/0.12/io_nix.c
vendored
270
vendor/wiiuse/0.12/io_nix.c
vendored
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for *nix.
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/hci_lib.h>
|
||||
#include <bluetooth/l2cap.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "io.h"
|
||||
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
|
||||
|
||||
/**
|
||||
* @brief Find a wiimote or wiimotes.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param max_wiimotes The number of wiimote structures in \a wm.
|
||||
* @param timeout The number of seconds before the search times out.
|
||||
*
|
||||
* @return The number of wiimotes found.
|
||||
*
|
||||
* @see wiimote_connect()
|
||||
*
|
||||
* This function will only look for wiimote devices. \n
|
||||
* When a device is found the address in the structures will be set. \n
|
||||
* You can then call wiimote_connect() to connect to the found \n
|
||||
* devices.
|
||||
*/
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
int device_id;
|
||||
int device_sock;
|
||||
int found_devices;
|
||||
int found_wiimotes;
|
||||
|
||||
/* reset all wiimote bluetooth device addresses */
|
||||
for (found_wiimotes = 0; found_wiimotes < max_wiimotes; ++found_wiimotes)
|
||||
wm[found_wiimotes]->bdaddr = *BDADDR_ANY;
|
||||
found_wiimotes = 0;
|
||||
|
||||
/* get the id of the first bluetooth device. */
|
||||
device_id = hci_get_route(NULL);
|
||||
if (device_id < 0) {
|
||||
perror("hci_get_route");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* create a socket to the device */
|
||||
device_sock = hci_open_dev(device_id);
|
||||
if (device_sock < 0) {
|
||||
perror("hci_open_dev");
|
||||
return 0;
|
||||
}
|
||||
|
||||
inquiry_info scan_info_arr[128];
|
||||
inquiry_info* scan_info = scan_info_arr;
|
||||
memset(&scan_info_arr, 0, sizeof(scan_info_arr));
|
||||
|
||||
/* scan for bluetooth devices for 'timeout' seconds */
|
||||
found_devices = hci_inquiry(device_id, timeout, 128, NULL, &scan_info, IREQ_CACHE_FLUSH);
|
||||
if (found_devices < 0) {
|
||||
perror("hci_inquiry");
|
||||
return 0;
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Found %i bluetooth device(s).", found_devices);
|
||||
|
||||
int i = 0;
|
||||
|
||||
/* display discovered devices */
|
||||
for (; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
|
||||
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2))
|
||||
{
|
||||
/* found a device */
|
||||
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);
|
||||
|
||||
WIIUSE_INFO("Found wiimote (%s) [id %i].", wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid);
|
||||
|
||||
wm[found_wiimotes]->bdaddr = scan_info[i].bdaddr;
|
||||
WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND);
|
||||
++found_wiimotes;
|
||||
}
|
||||
}
|
||||
|
||||
close(device_sock);
|
||||
return found_wiimotes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote or wiimotes once an address is known.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param wiimotes The number of wiimote structures in \a wm.
|
||||
*
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*
|
||||
* @see wiiuse_find()
|
||||
* @see wiiuse_connect_single()
|
||||
* @see wiiuse_disconnect()
|
||||
*
|
||||
* Connect to a number of wiimotes when the address is already set
|
||||
* in the wiimote_t structures. These addresses are normally set
|
||||
* by the wiiuse_find() function, but can also be set manually.
|
||||
*/
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND))
|
||||
/* if the device address is not set, skip it */
|
||||
continue;
|
||||
|
||||
if (wiiuse_connect_single(wm[i], NULL))
|
||||
++connected;
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote with a known address.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param address The address of the device to connect to.
|
||||
* If NULL, use the address in the struct set by wiiuse_find().
|
||||
*
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
|
||||
struct sockaddr_l2 addr;
|
||||
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
addr.l2_family = AF_BLUETOOTH;
|
||||
|
||||
if (address)
|
||||
/* use provided address */
|
||||
str2ba(address, &addr.l2_bdaddr);
|
||||
else
|
||||
/* use address of device discovered */
|
||||
addr.l2_bdaddr = wm->bdaddr;
|
||||
|
||||
/*
|
||||
* OUTPUT CHANNEL
|
||||
*/
|
||||
wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||
if (wm->out_sock == -1)
|
||||
return 0;
|
||||
|
||||
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
||||
|
||||
/* connect to wiimote */
|
||||
if (connect(wm->out_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
perror("connect() output sock");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* INPUT CHANNEL
|
||||
*/
|
||||
wm->in_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||
if (wm->in_sock == -1) {
|
||||
close(wm->out_sock);
|
||||
wm->out_sock = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr.l2_psm = htobs(WM_INPUT_CHANNEL);
|
||||
|
||||
/* connect to wiimote */
|
||||
if (connect(wm->in_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
perror("connect() interrupt sock");
|
||||
close(wm->out_sock);
|
||||
wm->out_sock = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm->unid);
|
||||
|
||||
/* do the handshake */
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disconnect a wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiiuse_connect()
|
||||
*
|
||||
* Note that this will not free the wiimote structure.
|
||||
*/
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
close(wm->out_sock);
|
||||
close(wm->in_sock);
|
||||
|
||||
wm->out_sock = -1;
|
||||
wm->in_sock = -1;
|
||||
wm->event = WIIUSE_NONE;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
/* not used */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
|
||||
return write(wm->out_sock, buf, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* ifndef WIN32 */
|
||||
247
vendor/wiiuse/0.12/io_win.c
vendored
247
vendor/wiiuse/0.12/io_win.c
vendored
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for Windows.
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
GUID device_id;
|
||||
HANDLE dev;
|
||||
HDEVINFO device_info;
|
||||
int i, index;
|
||||
DWORD len;
|
||||
SP_DEVICE_INTERFACE_DATA device_data;
|
||||
PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL;
|
||||
HIDD_ATTRIBUTES attr;
|
||||
int found = 0;
|
||||
|
||||
(void) timeout; // unused
|
||||
|
||||
device_data.cbSize = sizeof(device_data);
|
||||
index = 0;
|
||||
|
||||
/* get the device id */
|
||||
HidD_GetHidGuid(&device_id);
|
||||
|
||||
/* get all hid devices connected */
|
||||
device_info = SetupDiGetClassDevs(&device_id, NULL, NULL, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
|
||||
|
||||
for (;; ++index) {
|
||||
|
||||
if (detail_data) {
|
||||
free(detail_data);
|
||||
detail_data = NULL;
|
||||
}
|
||||
|
||||
/* query the next hid device info */
|
||||
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
|
||||
break;
|
||||
|
||||
/* get the size of the data block required */
|
||||
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
|
||||
detail_data = malloc(len);
|
||||
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
|
||||
/* query the data for this device */
|
||||
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
|
||||
continue;
|
||||
|
||||
/* open the device */
|
||||
dev = CreateFile(detail_data->DevicePath,
|
||||
(GENERIC_READ | GENERIC_WRITE),
|
||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
continue;
|
||||
|
||||
/* get device attributes */
|
||||
attr.Size = sizeof(attr);
|
||||
i = HidD_GetAttributes(dev, &attr);
|
||||
|
||||
if ((attr.VendorID == WM_VENDOR_ID) && (attr.ProductID == WM_PRODUCT_ID)) {
|
||||
/* this is a wiimote */
|
||||
wm[found]->dev_handle = dev;
|
||||
|
||||
wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, "");
|
||||
wm[found]->hid_overlap.Offset = 0;
|
||||
wm[found]->hid_overlap.OffsetHigh = 0;
|
||||
|
||||
WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_DEV_FOUND);
|
||||
WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED);
|
||||
|
||||
/* try to set the output report to see if the device is actually connected */
|
||||
if (!wiiuse_set_report_type(wm[found])) {
|
||||
WIIMOTE_DISABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* do the handshake */
|
||||
wiiuse_handshake(wm[found], NULL, 0);
|
||||
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
|
||||
|
||||
++found;
|
||||
if (found >= max_wiimotes)
|
||||
break;
|
||||
} else {
|
||||
/* not a wiimote */
|
||||
CloseHandle(dev);
|
||||
}
|
||||
}
|
||||
|
||||
if (detail_data)
|
||||
free(detail_data);
|
||||
|
||||
SetupDiDestroyDeviceInfoList(device_info);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED))
|
||||
++connected;
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
CloseHandle(wm->dev_handle);
|
||||
wm->dev_handle = 0;
|
||||
|
||||
ResetEvent(&wm->hid_overlap);
|
||||
|
||||
wm->event = WIIUSE_NONE;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
DWORD b, r;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) {
|
||||
/* partial read */
|
||||
b = GetLastError();
|
||||
|
||||
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) {
|
||||
/* remote disconnect */
|
||||
wiiuse_disconnected(wm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
CancelIo(wm->dev_handle);
|
||||
ResetEvent(wm->hid_overlap.hEvent);
|
||||
return 0;
|
||||
} else if (r == WAIT_FAILED) {
|
||||
WIIUSE_WARNING("A wait error occured on reading from wiimote %i.", wm->unid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0))
|
||||
return 0;
|
||||
}
|
||||
|
||||
ResetEvent(wm->hid_overlap.hEvent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
|
||||
DWORD bytes;
|
||||
int i;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
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;
|
||||
return i;
|
||||
}
|
||||
|
||||
if (i = HidD_SetOutputReport(wm->dev_handle, buf, len)) {
|
||||
wm->stack = WIIUSE_STACK_MS;
|
||||
return i;
|
||||
}
|
||||
|
||||
WIIUSE_ERROR("Unable to determine bluetooth stack type.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WIIUSE_STACK_MS:
|
||||
return HidD_SetOutputReport(wm->dev_handle, buf, len);
|
||||
|
||||
case WIIUSE_STACK_BLUESOLEIL:
|
||||
return WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* ifdef WIN32 */
|
||||
748
vendor/wiiuse/0.12/ir.c
vendored
748
vendor/wiiuse/0.12/ir.c
vendored
@@ -1,748 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles IR data.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "ir.h"
|
||||
|
||||
static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2);
|
||||
static void interpret_ir_data(struct wiimote_t* wm);
|
||||
static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang);
|
||||
static void get_ir_dot_avg(struct ir_dot_t* dot, int* x, int* y);
|
||||
static void reorder_ir_dots(struct ir_dot_t* dot);
|
||||
static float ir_distance(struct ir_dot_t* dot);
|
||||
static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y);
|
||||
static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int vy);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set if the wiimote should track IR targets.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
||||
byte buf;
|
||||
char* block1 = NULL;
|
||||
char* block2 = NULL;
|
||||
int ir_level;
|
||||
|
||||
if (!wm)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Wait for the handshake to finish first.
|
||||
* When it handshake finishes and sees that
|
||||
* IR is enabled, it will call this function
|
||||
* again to actually enable IR.
|
||||
*/
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE)) {
|
||||
WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes.");
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to make sure a sensitivity setting is selected.
|
||||
*/
|
||||
ir_level = get_ir_sens(wm, &block1, &block2);
|
||||
if (!ir_level) {
|
||||
WIIUSE_ERROR("No IR sensitivity setting selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
/* if already enabled then stop */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
return;
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
} else {
|
||||
/* if already disabled then stop */
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
return;
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
}
|
||||
|
||||
/* set camera 1 and 2 */
|
||||
buf = (status ? 0x04 : 0x00);
|
||||
wiiuse_send(wm, WM_CMD_IR, &buf, 1);
|
||||
wiiuse_send(wm, WM_CMD_IR_2, &buf, 1);
|
||||
|
||||
if (!status) {
|
||||
WIIUSE_DEBUG("Disabled IR cameras for wiimote id %i.", wm->unid);
|
||||
wiiuse_set_report_type(wm);
|
||||
return;
|
||||
}
|
||||
|
||||
/* enable IR, set sensitivity */
|
||||
buf = 0x08;
|
||||
wiiuse_write_data(wm, WM_REG_IR, &buf, 1);
|
||||
|
||||
/* wait for the wiimote to catch up */
|
||||
#ifndef WIN32
|
||||
usleep(50000);
|
||||
#else
|
||||
Sleep(50);
|
||||
#endif
|
||||
|
||||
/* write sensitivity blocks */
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (byte*)block1, 9);
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
||||
|
||||
/* set the IR mode */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
buf = WM_IR_TYPE_BASIC;
|
||||
else
|
||||
buf = WM_IR_TYPE_EXTENDED;
|
||||
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
||||
|
||||
#ifndef WIN32
|
||||
usleep(50000);
|
||||
#else
|
||||
Sleep(50);
|
||||
#endif
|
||||
|
||||
/* set the wiimote report type */
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
WIIUSE_DEBUG("Enabled IR camera for wiimote id %i (sensitivity level %i).", wm->unid, ir_level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the IR sensitivity settings.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param block1 [out] Pointer to where block1 will be set.
|
||||
* @param block2 [out] Pointer to where block2 will be set.
|
||||
*
|
||||
* @return Returns the sensitivity level.
|
||||
*/
|
||||
static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2) {
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL1)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL1;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL1;
|
||||
return 1;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL2)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL2;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL2;
|
||||
return 2;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL3)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL3;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL3;
|
||||
return 3;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL4)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL4;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL4;
|
||||
return 4;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL5)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL5;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL5;
|
||||
return 5;
|
||||
}
|
||||
|
||||
*block1 = NULL;
|
||||
*block2 = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the virtual screen resolution for IR tracking.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.vres[0] = (x-1);
|
||||
wm->ir.vres[1] = (y-1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the XY position for the IR cursor.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.pos = pos;
|
||||
|
||||
switch (pos) {
|
||||
|
||||
case WIIUSE_IR_ABOVE:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = WM_ASPECT_16_9_Y/2 - 70;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = WM_ASPECT_4_3_Y/2 - 100;
|
||||
|
||||
return;
|
||||
|
||||
case WIIUSE_IR_BELOW:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = -WM_ASPECT_16_9_Y/2 + 100;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = -WM_ASPECT_4_3_Y/2 + 70;
|
||||
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the aspect ratio of the TV/monitor.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3
|
||||
*/
|
||||
void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.aspect = aspect;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_4_3) {
|
||||
wm->ir.vres[0] = WM_ASPECT_4_3_X;
|
||||
wm->ir.vres[1] = WM_ASPECT_4_3_Y;
|
||||
} else {
|
||||
wm->ir.vres[0] = WM_ASPECT_16_9_X;
|
||||
wm->ir.vres[1] = WM_ASPECT_16_9_Y;
|
||||
}
|
||||
|
||||
/* reset the position offsets */
|
||||
wiiuse_set_ir_position(wm, wm->ir.pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the IR sensitivity.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param level 1-5, same as Wii system sensitivity setting.
|
||||
*
|
||||
* If the level is < 1, then level will be set to 1.
|
||||
* If the level is > 5, then level will be set to 5.
|
||||
*/
|
||||
void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) {
|
||||
char* block1 = NULL;
|
||||
char* block2 = NULL;
|
||||
|
||||
if (!wm) return;
|
||||
|
||||
if (level > 5) level = 5;
|
||||
if (level < 1) level = 1;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL2 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL3 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL4 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL5));
|
||||
|
||||
switch (level) {
|
||||
case 1:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL1);
|
||||
break;
|
||||
case 2:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL2);
|
||||
break;
|
||||
case 3:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL3);
|
||||
break;
|
||||
case 4:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL4);
|
||||
break;
|
||||
case 5:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL5);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
/* set the new sensitivity */
|
||||
get_ir_sens(wm, &block1, &block2);
|
||||
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (byte*)block1, 9);
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
||||
|
||||
WIIUSE_DEBUG("Set IR sensitivity to level %i (unid %i)", level, wm->unid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the data from the IR spots. Basic IR mode.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Data returned by the wiimote for the IR spots.
|
||||
*/
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
|
||||
dot[0].rx = 1023 - (data[0] | ((data[2] & 0x30) << 4));
|
||||
dot[0].ry = data[1] | ((data[2] & 0xC0) << 2);
|
||||
|
||||
dot[1].rx = 1023 - (data[3] | ((data[2] & 0x03) << 8));
|
||||
dot[1].ry = data[4] | ((data[2] & 0x0C) << 6);
|
||||
|
||||
dot[2].rx = 1023 - (data[5] | ((data[7] & 0x30) << 4));
|
||||
dot[2].ry = data[6] | ((data[7] & 0xC0) << 2);
|
||||
|
||||
dot[3].rx = 1023 - (data[8] | ((data[7] & 0x03) << 8));
|
||||
dot[3].ry = data[9] | ((data[7] & 0x0C) << 6);
|
||||
|
||||
/* set each IR spot to visible if spot is in range */
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].ry == 1023)
|
||||
dot[i].visible = 0;
|
||||
else {
|
||||
dot[i].visible = 1;
|
||||
dot[i].size = 0; /* since we don't know the size, set it as 0 */
|
||||
}
|
||||
}
|
||||
|
||||
interpret_ir_data(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the data from the IR spots. Extended IR mode.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Data returned by the wiimote for the IR spots.
|
||||
*/
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].rx = 1023 - (data[3*i] | ((data[(3*i)+2] & 0x30) << 4));
|
||||
dot[i].ry = data[(3*i)+1] | ((data[(3*i)+2] & 0xC0) << 2);
|
||||
|
||||
dot[i].size = data[(3*i)+2] & 0x0F;
|
||||
|
||||
/* if in range set to visible */
|
||||
if (dot[i].ry == 1023)
|
||||
dot[i].visible = 0;
|
||||
else
|
||||
dot[i].visible = 1;
|
||||
}
|
||||
|
||||
interpret_ir_data(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interpret IR data into more user friendly variables.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void interpret_ir_data(struct wiimote_t* wm) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
float roll = 0.0f;
|
||||
int last_num_dots = wm->ir.num_dots;
|
||||
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC))
|
||||
roll = wm->orient.roll;
|
||||
|
||||
/* count visible dots */
|
||||
wm->ir.num_dots = 0;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible)
|
||||
wm->ir.num_dots++;
|
||||
}
|
||||
|
||||
switch (wm->ir.num_dots) {
|
||||
case 0:
|
||||
{
|
||||
wm->ir.state = 0;
|
||||
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i)
|
||||
dot[i].order = 0;
|
||||
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
wm->ir.z = 0.0f;
|
||||
|
||||
return;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
if (wm->ir.state < 2) {
|
||||
/*
|
||||
* Only 1 known dot, so use just that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
wm->ir.x = dot[i].x;
|
||||
wm->ir.y = dot[i].y;
|
||||
|
||||
wm->ir.ax = wm->ir.x;
|
||||
wm->ir.ay = wm->ir.y;
|
||||
|
||||
/* can't calculate yaw because we don't have the distance */
|
||||
//wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Only see 1 dot but know theres 2.
|
||||
* Try to estimate where the other one
|
||||
* should be and use that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
int ox = 0;
|
||||
int x, y;
|
||||
|
||||
if (dot[i].order == 1)
|
||||
/* visible is the left dot - estimate where the right is */
|
||||
ox = dot[i].x + wm->ir.distance;
|
||||
else if (dot[i].order == 2)
|
||||
/* visible is the right dot - estimate where the left is */
|
||||
ox = dot[i].x - wm->ir.distance;
|
||||
|
||||
x = ((signed int)dot[i].x + ox) / 2;
|
||||
y = dot[i].y;
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
/*
|
||||
* Two (or more) dots known and seen.
|
||||
* Average them together to estimate the true location.
|
||||
*/
|
||||
int x, y;
|
||||
wm->ir.state = 2;
|
||||
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
/* if there is at least 1 new dot, reorder them all */
|
||||
if (wm->ir.num_dots > last_num_dots) {
|
||||
reorder_ir_dots(dot);
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
}
|
||||
|
||||
wm->ir.distance = ir_distance(dot);
|
||||
wm->ir.z = 1023 - wm->ir.distance;
|
||||
|
||||
get_ir_dot_avg(wm->ir.dot, &x, &y);
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int ir_level;
|
||||
WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level);
|
||||
WIIUSE_DEBUG("IR sensitivity: %i", ir_level);
|
||||
WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots);
|
||||
for (i = 0; i < 4; ++i)
|
||||
if (dot[i].visible)
|
||||
WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y);
|
||||
WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fix the rotation of the IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
* @param ang The roll angle to correct by (-180, 180)
|
||||
*
|
||||
* If there is roll then the dots are rotated
|
||||
* around the origin and give a false cursor
|
||||
* position. Correct for the roll.
|
||||
*
|
||||
* If the accelerometer is off then obviously
|
||||
* this will not do anything and the cursor
|
||||
* position may be inaccurate.
|
||||
*/
|
||||
static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) {
|
||||
float s, c;
|
||||
int x, y;
|
||||
int i;
|
||||
|
||||
if (!ang) {
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].x = dot[i].rx;
|
||||
dot[i].y = dot[i].ry;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
s = sin(DEGREE_TO_RAD(ang));
|
||||
c = cos(DEGREE_TO_RAD(ang));
|
||||
|
||||
/*
|
||||
* [ cos(theta) -sin(theta) ][ ir->rx ]
|
||||
* [ sin(theta) cos(theta) ][ ir->ry ]
|
||||
*/
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (!dot[i].visible)
|
||||
continue;
|
||||
|
||||
x = dot[i].rx - (1024/2);
|
||||
y = dot[i].ry - (768/2);
|
||||
|
||||
dot[i].x = (c * x) + (-s * y);
|
||||
dot[i].y = (s * x) + (c * y);
|
||||
|
||||
dot[i].x += (1024/2);
|
||||
dot[i].y += (768/2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Average IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
* @param x [out] Average X
|
||||
* @param y [out] Average Y
|
||||
*/
|
||||
static void get_ir_dot_avg(struct ir_dot_t* dot, int* x, int* y) {
|
||||
int vis = 0, i = 0;
|
||||
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
|
||||
for (; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
*x += dot[i].x;
|
||||
*y += dot[i].y;
|
||||
++vis;
|
||||
}
|
||||
}
|
||||
|
||||
*x /= vis;
|
||||
*y /= vis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reorder the IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
*/
|
||||
static void reorder_ir_dots(struct ir_dot_t* dot) {
|
||||
int i, j, order;
|
||||
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i)
|
||||
dot[i].order = 0;
|
||||
|
||||
for (order = 1; order < 5; ++order) {
|
||||
i = 0;
|
||||
|
||||
for (; !dot[i].visible || dot[i].order; ++i)
|
||||
if (i > 4)
|
||||
return;
|
||||
|
||||
for (j = 0; j < 4; ++j) {
|
||||
if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x))
|
||||
i = j;
|
||||
}
|
||||
|
||||
dot[i].order = order;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the distance between the first 2 visible IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
*/
|
||||
static float ir_distance(struct ir_dot_t* dot) {
|
||||
int i1, i2;
|
||||
int xd, yd;
|
||||
|
||||
for (i1 = 0; i1 < 4; ++i1)
|
||||
if (dot[i1].visible)
|
||||
break;
|
||||
if (i1 == 4)
|
||||
return 0.0f;
|
||||
|
||||
for (i2 = i1+1; i2 < 4; ++i2)
|
||||
if (dot[i2].visible)
|
||||
break;
|
||||
if (i2 == 4)
|
||||
return 0.0f;
|
||||
|
||||
xd = dot[i2].x - dot[i1].x;
|
||||
yd = dot[i2].y - dot[i1].y;
|
||||
|
||||
return sqrt(xd*xd + yd*yd);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Correct for the IR bounding box.
|
||||
*
|
||||
* @param x [out] The current X, it will be updated if valid.
|
||||
* @param y [out] The current Y, it will be updated if valid.
|
||||
* @param aspect Aspect ratio of the screen.
|
||||
* @param offset_x The X offset of the bounding box.
|
||||
* @param offset_y The Y offset of the bounding box.
|
||||
*
|
||||
* @return Returns 1 if the point is valid and was updated.
|
||||
*
|
||||
* Nintendo was smart with this bit. They sacrifice a little
|
||||
* precision for a big increase in usability.
|
||||
*/
|
||||
static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y) {
|
||||
int x0, y0;
|
||||
int xs, ys;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_16_9) {
|
||||
xs = WM_ASPECT_16_9_X;
|
||||
ys = WM_ASPECT_16_9_Y;
|
||||
} else {
|
||||
xs = WM_ASPECT_4_3_X;
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
x0 = ((1024 - xs) / 2) + offset_x;
|
||||
y0 = ((768 - ys) / 2) + offset_y;
|
||||
|
||||
if ((*x >= x0)
|
||||
&& (*x <= (x0 + xs))
|
||||
&& (*y >= y0)
|
||||
&& (*y <= (y0 + ys)))
|
||||
{
|
||||
*x -= offset_x;
|
||||
*y -= offset_y;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interpolate the point to the user defined virtual screen resolution.
|
||||
*/
|
||||
static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int vy) {
|
||||
int xs, ys;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_16_9) {
|
||||
xs = WM_ASPECT_16_9_X;
|
||||
ys = WM_ASPECT_16_9_Y;
|
||||
} else {
|
||||
xs = WM_ASPECT_4_3_X;
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
*x -= ((1024-xs)/2);
|
||||
*y -= ((768-ys)/2);
|
||||
|
||||
*x = (*x / (float)xs) * vx;
|
||||
*y = (*y / (float)ys) * vy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate yaw given the IR data.
|
||||
*
|
||||
* @param ir IR data structure.
|
||||
*/
|
||||
float calc_yaw(struct ir_t* ir) {
|
||||
float x;
|
||||
|
||||
x = ir->ax - 512;
|
||||
x = x * (ir->z / 1024.0f);
|
||||
|
||||
return RAD_TO_DEGREE( atanf(x / ir->z) );
|
||||
}
|
||||
56
vendor/wiiuse/0.12/ir.h
vendored
56
vendor/wiiuse/0.12/ir.h
vendored
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles IR data.
|
||||
*/
|
||||
|
||||
#ifndef IR_H_INCLUDED
|
||||
#define IR_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define WII_VRES_X 560
|
||||
#define WII_VRES_Y 340
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data);
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data);
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IR_H_INCLUDED
|
||||
|
||||
|
||||
210
vendor/wiiuse/0.12/nunchuk.c
vendored
210
vendor/wiiuse/0.12/nunchuk.c
vendored
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "nunchuk.h"
|
||||
|
||||
static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the nunchuk.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @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;
|
||||
|
||||
nc->btns = 0;
|
||||
nc->btns_held = 0;
|
||||
nc->btns_released = 0;
|
||||
|
||||
/* set the smoothing to the same as the wiimote */
|
||||
nc->flags = &wm->flags;
|
||||
nc->accel_calib.st_alpha = wm->accel_calib.st_alpha;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
nc->accel_calib.cal_zero.x = data[offset + 0];
|
||||
nc->accel_calib.cal_zero.y = data[offset + 1];
|
||||
nc->accel_calib.cal_zero.z = data[offset + 2];
|
||||
nc->accel_calib.cal_g.x = data[offset + 4];
|
||||
nc->accel_calib.cal_g.y = data[offset + 5];
|
||||
nc->accel_calib.cal_g.z = data[offset + 6];
|
||||
nc->js.max.x = data[offset + 8];
|
||||
nc->js.min.x = data[offset + 9];
|
||||
nc->js.center.x = data[offset + 10];
|
||||
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;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The nunchuk disconnected.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
*/
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc) {
|
||||
memset(nc, 0, sizeof(struct nunchuk_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle nunchuk event.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
/* get button states */
|
||||
nunchuk_pressed_buttons(nc, msg[5]);
|
||||
|
||||
/* calculate joystick state */
|
||||
calc_joystick_state(&nc->js, msg[0], msg[1]);
|
||||
|
||||
/* calculate orientation */
|
||||
nc->accel.x = msg[2];
|
||||
nc->accel.y = msg[3];
|
||||
nc->accel.z = msg[4];
|
||||
|
||||
calculate_orientation(&nc->accel_calib, &nc->accel, &nc->orient, NUNCHUK_IS_FLAG_SET(nc, WIIUSE_SMOOTHING));
|
||||
calculate_gforce(&nc->accel_calib, &nc->accel, &nc->gforce);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param nc Pointer to a nunchuk_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & NUNCHUK_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
nc->btns_held = (now & nc->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
nc->btns_released = ((nc->btns | nc->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
nc->btns = now;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the orientation event threshold for the nunchuk.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure with a nunchuk attached.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->exp.nunchuk.orient_threshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the accelerometer event threshold for the nunchuk.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure with a nunchuk attached.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->exp.nunchuk.accel_threshold = threshold;
|
||||
}
|
||||
53
vendor/wiiuse/0.12/nunchuk.h
vendored
53
vendor/wiiuse/0.12/nunchuk.h
vendored
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
|
||||
#ifndef NUNCHUK_H_INCLUDED
|
||||
#define NUNCHUK_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len);
|
||||
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc);
|
||||
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NUNCHUK_H_INCLUDED
|
||||
56
vendor/wiiuse/0.12/os.h
vendored
56
vendor/wiiuse/0.12/os.h
vendored
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Operating system related definitions.
|
||||
*
|
||||
* This file is an attempt to separate operating system
|
||||
* dependent functions and choose what should be used
|
||||
* at compile time.
|
||||
*/
|
||||
|
||||
#ifndef OS_H_INCLUDED
|
||||
#define OS_H_INCLUDED
|
||||
|
||||
#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 */
|
||||
#pragma warning(disable:4217)
|
||||
#else
|
||||
/* nix */
|
||||
#endif
|
||||
|
||||
|
||||
#endif // OS_H_INCLUDED
|
||||
764
vendor/wiiuse/0.12/wiiuse.c
vendored
764
vendor/wiiuse/0.12/wiiuse.c
vendored
@@ -1,764 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read data from the wiimote (event version).
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @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(struct wiimote_t* wm, byte* buffer, unsigned int addr, unsigned short len) {
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
if (!buffer || !len)
|
||||
return 0;
|
||||
|
||||
/* make this request structure */
|
||||
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
|
||||
req->cb = NULL;
|
||||
req->buf = buffer;
|
||||
req->addr = addr;
|
||||
req->size = len;
|
||||
req->wait = len;
|
||||
req->dirty = 0;
|
||||
req->next = NULL;
|
||||
|
||||
/* add this to the request list */
|
||||
if (!wm->read_req) {
|
||||
/* root node */
|
||||
wm->read_req = req;
|
||||
|
||||
WIIUSE_DEBUG("Data read request can be sent out immediately.");
|
||||
|
||||
/* send the request out immediately */
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
} else {
|
||||
struct read_req_t* nptr = wm->read_req;
|
||||
for (; nptr->next; nptr = nptr->next);
|
||||
nptr->next = req;
|
||||
|
||||
WIIUSE_DEBUG("Added pending data read request.");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send the next pending data read request to the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiiuse_read_data()
|
||||
*
|
||||
* This function is not part of the wiiuse API.
|
||||
*/
|
||||
void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) {
|
||||
byte buf[6];
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
if (!wm->read_req) return;
|
||||
|
||||
/* skip over dirty ones since they have already been read */
|
||||
req = wm->read_req;
|
||||
while (req && req->dirty)
|
||||
req = req->next;
|
||||
if (!req)
|
||||
return;
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(req->addr);
|
||||
|
||||
/* the length is in big endian */
|
||||
*(short*)(buf + 4) = BIG_ENDIAN_SHORT(req->size);
|
||||
|
||||
WIIUSE_DEBUG("Request read at address: 0x%x length: %i", req->addr, req->size);
|
||||
wiiuse_send(wm, WM_CMD_READ_DATA, buf, 6);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 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
|
||||
}
|
||||
653
vendor/wiiuse/0.12/wiiuse.h
vendored
653
vendor/wiiuse/0.12/wiiuse.h
vendored
@@ -1,653 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief 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))
|
||||
|
||||
/**
|
||||
* @brief Return the IR sensitivity level.
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param lvl [out] Pointer to an int that will hold the level setting.
|
||||
* If no level is set 'lvl' will be set to 0.
|
||||
*/
|
||||
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
|
||||
do { \
|
||||
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
|
||||
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
|
||||
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
|
||||
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
|
||||
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
|
||||
else *lvl = 0; \
|
||||
} while (0)
|
||||
|
||||
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
|
||||
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
|
||||
#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
|
||||
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
|
||||
|
||||
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
|
||||
|
||||
/*
|
||||
* Largest known payload is 21 bytes.
|
||||
* Add 2 for the prefix and round up to a power of 2.
|
||||
*/
|
||||
#define MAX_PAYLOAD 32
|
||||
|
||||
/*
|
||||
* This is left over from an old hack, but it may actually
|
||||
* be a useful feature to keep so it wasn't removed.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
#define WIIMOTE_DEFAULT_TIMEOUT 10
|
||||
#define WIIMOTE_EXP_TIMEOUT 10
|
||||
#endif
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef char sbyte;
|
||||
|
||||
struct wiimote_t;
|
||||
struct vec3b_t;
|
||||
struct orient_t;
|
||||
struct gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Pointer to the filled data block.
|
||||
* @param len Length in bytes of the data block.
|
||||
*
|
||||
* @see wiiuse_init()
|
||||
*
|
||||
* A registered function of this type is called automatically by the wiiuse
|
||||
* library when the wiimote has returned the full data requested by a previous
|
||||
* call to wiiuse_read_data().
|
||||
*/
|
||||
typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
|
||||
|
||||
/**
|
||||
* @struct read_req_t
|
||||
* @brief Data read request structure.
|
||||
*/
|
||||
struct read_req_t {
|
||||
wiiuse_read_cb cb; /**< read data callback */
|
||||
byte* buf; /**< buffer where read data is written */
|
||||
unsigned int addr; /**< the offset that the read started at */
|
||||
unsigned short size; /**< the length of the data read */
|
||||
unsigned short wait; /**< num bytes still needed to finish read */
|
||||
byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */
|
||||
|
||||
struct read_req_t* next; /**< next read request in the queue */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec2b_t
|
||||
* @brief Unsigned x,y byte vector.
|
||||
*/
|
||||
typedef struct vec2b_t {
|
||||
byte x, y;
|
||||
} vec2b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3b_t
|
||||
* @brief Unsigned x,y,z byte vector.
|
||||
*/
|
||||
typedef struct vec3b_t {
|
||||
byte x, y, z;
|
||||
} vec3b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3f_t
|
||||
* @brief Signed x,y,z float struct.
|
||||
*/
|
||||
typedef struct vec3f_t {
|
||||
float x, y, z;
|
||||
} vec3f_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct orient_t
|
||||
* @brief Orientation struct.
|
||||
*
|
||||
* Yaw, pitch, and roll range from -180 to 180 degrees.
|
||||
*/
|
||||
typedef struct orient_t {
|
||||
float roll; /**< roll, this may be smoothed if enabled */
|
||||
float pitch; /**< pitch, this may be smoothed if enabled */
|
||||
float yaw;
|
||||
|
||||
float a_roll; /**< absolute roll, unsmoothed */
|
||||
float a_pitch; /**< absolute pitch, unsmoothed */
|
||||
} orient_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct gforce_t
|
||||
* @brief Gravity force struct.
|
||||
*/
|
||||
typedef struct gforce_t {
|
||||
float x, y, z;
|
||||
} gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct accel_t
|
||||
* @brief Accelerometer struct. For any device with an accelerometer.
|
||||
*/
|
||||
typedef struct accel_t {
|
||||
struct vec3b_t cal_zero; /**< zero calibration */
|
||||
struct vec3b_t cal_g; /**< 1g difference around 0cal */
|
||||
|
||||
float st_roll; /**< last smoothed roll value */
|
||||
float st_pitch; /**< last smoothed roll pitch */
|
||||
float st_alpha; /**< alpha value for smoothing [0-1] */
|
||||
} accel_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_dot_t
|
||||
* @brief A single IR source.
|
||||
*/
|
||||
typedef struct ir_dot_t {
|
||||
byte visible; /**< if the IR source is visible */
|
||||
|
||||
unsigned int x; /**< interpolated X coordinate */
|
||||
unsigned int y; /**< interpolated Y coordinate */
|
||||
|
||||
short rx; /**< raw X coordinate (0-1023) */
|
||||
short ry; /**< raw Y coordinate (0-767) */
|
||||
|
||||
byte order; /**< increasing order by x-axis value */
|
||||
|
||||
byte size; /**< size of the IR dot (0-15) */
|
||||
} ir_dot_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum aspect_t
|
||||
* @brief Screen aspect ratio.
|
||||
*/
|
||||
typedef enum aspect_t {
|
||||
WIIUSE_ASPECT_4_3,
|
||||
WIIUSE_ASPECT_16_9
|
||||
} aspect_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_t
|
||||
* @brief IR struct. Hold all data related to the IR tracking.
|
||||
*/
|
||||
typedef struct ir_t {
|
||||
struct ir_dot_t dot[4]; /**< IR dots */
|
||||
byte num_dots; /**< number of dots at this time */
|
||||
|
||||
enum aspect_t aspect; /**< aspect ratio of the screen */
|
||||
|
||||
enum ir_position_t pos; /**< IR sensor bar position */
|
||||
|
||||
unsigned int vres[2]; /**< IR virtual screen resolution */
|
||||
int offset[2]; /**< IR XY correction offset */
|
||||
int state; /**< keeps track of the IR state */
|
||||
|
||||
int ax; /**< absolute X coordinate */
|
||||
int ay; /**< absolute Y coordinate */
|
||||
|
||||
int x; /**< calculated X coordinate */
|
||||
int y; /**< calculated Y coordinate */
|
||||
|
||||
float distance; /**< pixel distance between first 2 dots*/
|
||||
float z; /**< calculated distance */
|
||||
} ir_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct joystick_t
|
||||
* @brief Joystick calibration structure.
|
||||
*
|
||||
* The angle \a ang is relative to the positive y-axis into quadrant I
|
||||
* and ranges from 0 to 360 degrees. So if the joystick is held straight
|
||||
* upwards then angle is 0 degrees. If it is held to the right it is 90,
|
||||
* down is 180, and left is 270.
|
||||
*
|
||||
* The magnitude \a mag is the distance from the center to where the
|
||||
* joystick is being held. The magnitude ranges from 0 to 1.
|
||||
* If the joystick is only slightly tilted from the center the magnitude
|
||||
* will be low, but if it is closer to the outter edge the value will
|
||||
* be higher.
|
||||
*/
|
||||
typedef struct joystick_t {
|
||||
struct vec2b_t max; /**< maximum joystick values */
|
||||
struct vec2b_t min; /**< minimum joystick values */
|
||||
struct vec2b_t center; /**< center joystick values */
|
||||
|
||||
float ang; /**< angle the joystick is being held */
|
||||
float mag; /**< magnitude of the joystick (range 0-1) */
|
||||
} joystick_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct nunchuk_t
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
typedef struct nunchuk_t {
|
||||
struct accel_t accel_calib; /**< nunchuk accelerometer calibration */
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
|
||||
int* flags; /**< options flag (points to wiimote_t.flags) */
|
||||
|
||||
byte btns; /**< what buttons have just been pressed */
|
||||
byte btns_held; /**< what buttons are being held down */
|
||||
byte btns_released; /**< what buttons were just released this */
|
||||
|
||||
float orient_threshold; /**< threshold for orient to generate an event */
|
||||
int accel_threshold; /**< threshold for accel to generate an event */
|
||||
|
||||
struct vec3b_t accel; /**< current raw acceleration data */
|
||||
struct orient_t orient; /**< current orientation on each axis */
|
||||
struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
} nunchuk_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct classic_ctrl_t
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
typedef struct classic_ctrl_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
float r_shoulder; /**< right shoulder button (range 0-1) */
|
||||
float l_shoulder; /**< left shoulder button (range 0-1) */
|
||||
|
||||
struct joystick_t ljs; /**< left joystick calibration */
|
||||
struct joystick_t rjs; /**< right joystick calibration */
|
||||
} classic_ctrl_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct guitar_hero_3_t
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
typedef struct guitar_hero_3_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
float whammy_bar; /**< whammy bar (range 0-1) */
|
||||
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
} guitar_hero_3_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct expansion_t
|
||||
* @brief Generic expansion device plugged into wiimote.
|
||||
*/
|
||||
typedef struct expansion_t {
|
||||
int type; /**< type of expansion attached */
|
||||
|
||||
union {
|
||||
struct nunchuk_t nunchuk;
|
||||
struct classic_ctrl_t classic;
|
||||
struct guitar_hero_3_t gh3;
|
||||
};
|
||||
} expansion_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum win32_bt_stack_t
|
||||
* @brief Available bluetooth stacks for Windows.
|
||||
*/
|
||||
typedef enum win_bt_stack_t {
|
||||
WIIUSE_STACK_UNKNOWN,
|
||||
WIIUSE_STACK_MS,
|
||||
WIIUSE_STACK_BLUESOLEIL
|
||||
} win_bt_stack_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct wiimote_state_t
|
||||
* @brief Significant data from the previous event.
|
||||
*/
|
||||
typedef struct wiimote_state_t {
|
||||
/* expansion_t */
|
||||
float exp_ljs_ang;
|
||||
float exp_rjs_ang;
|
||||
float exp_ljs_mag;
|
||||
float exp_rjs_mag;
|
||||
unsigned short exp_btns;
|
||||
struct orient_t exp_orient;
|
||||
struct vec3b_t exp_accel;
|
||||
float exp_r_shoulder;
|
||||
float exp_l_shoulder;
|
||||
|
||||
/* ir_t */
|
||||
int ir_ax;
|
||||
int ir_ay;
|
||||
float ir_distance;
|
||||
|
||||
struct orient_t orient;
|
||||
unsigned short btns;
|
||||
|
||||
struct vec3b_t accel;
|
||||
} wiimote_state_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum WIIUSE_EVENT_TYPE
|
||||
* @brief Events that wiiuse can generate from a poll.
|
||||
*/
|
||||
typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_NONE = 0,
|
||||
WIIUSE_EVENT,
|
||||
WIIUSE_STATUS,
|
||||
WIIUSE_CONNECT,
|
||||
WIIUSE_DISCONNECT,
|
||||
WIIUSE_UNEXPECTED_DISCONNECT,
|
||||
WIIUSE_READ_DATA,
|
||||
WIIUSE_NUNCHUK_INSERTED,
|
||||
WIIUSE_NUNCHUK_REMOVED,
|
||||
WIIUSE_CLASSIC_CTRL_INSERTED,
|
||||
WIIUSE_CLASSIC_CTRL_REMOVED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
|
||||
} WIIUSE_EVENT_TYPE;
|
||||
|
||||
/**
|
||||
* @struct wiimote_t
|
||||
* @brief Wiimote structure.
|
||||
*/
|
||||
typedef struct wiimote_t {
|
||||
WCONST int unid; /**< user specified id */
|
||||
|
||||
#ifndef WIN32
|
||||
WCONST bdaddr_t bdaddr; /**< bt address */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST int out_sock; /**< output socket */
|
||||
WCONST int in_sock; /**< input socket */
|
||||
#else
|
||||
WCONST HANDLE dev_handle; /**< HID handle */
|
||||
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
|
||||
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
|
||||
WCONST int timeout; /**< read timeout */
|
||||
WCONST byte normal_timeout; /**< normal timeout */
|
||||
WCONST byte exp_timeout; /**< timeout for expansion handshake */
|
||||
#endif
|
||||
|
||||
WCONST int state; /**< various state flags */
|
||||
WCONST byte leds; /**< currently lit leds */
|
||||
WCONST float battery_level; /**< battery level */
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
WCONST byte handshake_state; /**< the state of the connection handshake */
|
||||
|
||||
WCONST struct read_req_t* read_req; /**< list of data read requests */
|
||||
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
|
||||
WCONST struct expansion_t exp; /**< wiimote expansion device */
|
||||
|
||||
WCONST struct vec3b_t accel; /**< current raw acceleration data */
|
||||
WCONST struct orient_t orient; /**< current orientation on each axis */
|
||||
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
|
||||
WCONST struct ir_t ir; /**< IR data */
|
||||
|
||||
WCONST unsigned short btns; /**< what buttons have just been pressed */
|
||||
WCONST unsigned short btns_held; /**< what buttons are being held down */
|
||||
WCONST unsigned short btns_released; /**< what buttons were just released this */
|
||||
|
||||
WCONST float orient_threshold; /**< threshold for orient to generate an event */
|
||||
WCONST int accel_threshold; /**< threshold for accel to generate an event */
|
||||
|
||||
WCONST struct wiimote_state_t lstate; /**< last saved state */
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
|
||||
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
|
||||
} wiimote;
|
||||
|
||||
|
||||
/*****************************************
|
||||
*
|
||||
* Include API specific stuff
|
||||
*
|
||||
*****************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIIUSE_EXPORT_DECL __declspec(dllexport)
|
||||
#define WIIUSE_IMPORT_DECL __declspec(dllimport)
|
||||
#else
|
||||
#define WIIUSE_EXPORT_DECL
|
||||
#define WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_COMPILE_LIB
|
||||
#define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
|
||||
#else
|
||||
#define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* wiiuse.c */
|
||||
WIIUSE_EXPORT extern const char* wiiuse_version();
|
||||
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
/* connect.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
|
||||
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* WIIUSE_H_INCLUDED */
|
||||
|
||||
226
vendor/wiiuse/0.12/wiiuse_internal.h
vendored
226
vendor/wiiuse/0.12/wiiuse_internal.h
vendored
@@ -1,226 +0,0 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief General internal wiiuse stuff.
|
||||
*
|
||||
* Since Wiiuse is a library, wiiuse.h is a duplicate
|
||||
* of the API header.
|
||||
*
|
||||
* The code that would normally go in that file, but
|
||||
* which is not needed by third party developers,
|
||||
* is put here.
|
||||
*
|
||||
* So wiiuse_internal.h is included by other files
|
||||
* internally, wiiuse.h is included only here.
|
||||
*/
|
||||
|
||||
#ifndef WIIUSE_INTERNAL_H_INCLUDED
|
||||
#define WIIUSE_INTERNAL_H_INCLUDED
|
||||
|
||||
#ifndef WIN32
|
||||
#include <arpa/inet.h> /* htons() */
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
/* wiiuse version */
|
||||
#define WIIUSE_VERSION "0.12"
|
||||
|
||||
/********************
|
||||
*
|
||||
* Wiimote internal codes
|
||||
*
|
||||
********************/
|
||||
|
||||
/* Communication channels */
|
||||
#define WM_OUTPUT_CHANNEL 0x11
|
||||
#define WM_INPUT_CHANNEL 0x13
|
||||
|
||||
#define WM_SET_REPORT 0x50
|
||||
|
||||
/* commands */
|
||||
#define WM_CMD_LED 0x11
|
||||
#define WM_CMD_REPORT_TYPE 0x12
|
||||
#define WM_CMD_RUMBLE 0x13
|
||||
#define WM_CMD_IR 0x13
|
||||
#define WM_CMD_CTRL_STATUS 0x15
|
||||
#define WM_CMD_WRITE_DATA 0x16
|
||||
#define WM_CMD_READ_DATA 0x17
|
||||
#define WM_CMD_IR_2 0x1A
|
||||
|
||||
/* input report ids */
|
||||
#define WM_RPT_CTRL_STATUS 0x20
|
||||
#define WM_RPT_READ 0x21
|
||||
#define WM_RPT_WRITE 0x22
|
||||
#define WM_RPT_BTN 0x30
|
||||
#define WM_RPT_BTN_ACC 0x31
|
||||
#define WM_RPT_BTN_ACC_IR 0x33
|
||||
#define WM_RPT_BTN_EXP 0x34
|
||||
#define WM_RPT_BTN_ACC_EXP 0x35
|
||||
#define WM_RPT_BTN_IR_EXP 0x36
|
||||
#define WM_RPT_BTN_ACC_IR_EXP 0x37
|
||||
|
||||
#define WM_BT_INPUT 0x01
|
||||
#define WM_BT_OUTPUT 0x02
|
||||
|
||||
/* Identify the wiimote device by its class */
|
||||
#define WM_DEV_CLASS_0 0x04
|
||||
#define WM_DEV_CLASS_1 0x25
|
||||
#define WM_DEV_CLASS_2 0x00
|
||||
#define WM_VENDOR_ID 0x057E
|
||||
#define WM_PRODUCT_ID 0x0306
|
||||
|
||||
/* controller status stuff */
|
||||
#define WM_MAX_BATTERY_CODE 0xC8
|
||||
|
||||
/* offsets in wiimote memory */
|
||||
#define WM_MEM_OFFSET_CALIBRATION 0x16
|
||||
#define WM_EXP_MEM_BASE 0x04A40000
|
||||
#define WM_EXP_MEM_ENABLE 0x04A40040
|
||||
#define WM_EXP_MEM_CALIBR 0x04A40020
|
||||
|
||||
#define WM_REG_IR 0x04B00030
|
||||
#define WM_REG_IR_BLOCK1 0x04B00000
|
||||
#define WM_REG_IR_BLOCK2 0x04B0001A
|
||||
#define WM_REG_IR_MODENUM 0x04B00033
|
||||
|
||||
/* ir block data */
|
||||
#define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
|
||||
#define WM_IR_BLOCK2_LEVEL1 "\xfd\x05"
|
||||
#define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
|
||||
#define WM_IR_BLOCK2_LEVEL2 "\xb3\x04"
|
||||
#define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
|
||||
#define WM_IR_BLOCK2_LEVEL3 "\x63\x03"
|
||||
#define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
|
||||
#define WM_IR_BLOCK2_LEVEL4 "\x35\x03"
|
||||
#define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
|
||||
#define WM_IR_BLOCK2_LEVEL5 "\x1f\x03"
|
||||
|
||||
#define WM_IR_TYPE_BASIC 0x01
|
||||
#define WM_IR_TYPE_EXTENDED 0x03
|
||||
|
||||
/* controller status flags for the first message byte */
|
||||
/* bit 1 is unknown */
|
||||
#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
|
||||
#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
|
||||
#define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_1 0x10
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_2 0x20
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_3 0x40
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_4 0x80
|
||||
|
||||
/* aspect ratio */
|
||||
#define WM_ASPECT_16_9_X 660
|
||||
#define WM_ASPECT_16_9_Y 370
|
||||
#define WM_ASPECT_4_3_X 560
|
||||
#define WM_ASPECT_4_3_Y 420
|
||||
|
||||
|
||||
/**
|
||||
* Expansion stuff
|
||||
*/
|
||||
|
||||
/* encrypted expansion id codes (located at 0x04A400FC) */
|
||||
#define EXP_ID_CODE_NUNCHUK 0x9A1EFEFE
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
|
||||
#define EXP_ID_CODE_GUITAR 0x9A1EFDFB
|
||||
|
||||
#define EXP_HANDSHAKE_LEN 224
|
||||
|
||||
/********************
|
||||
*
|
||||
* End Wiimote internal codes
|
||||
*
|
||||
********************/
|
||||
|
||||
/* wiimote state flags - (some duplicated in wiiuse.h)*/
|
||||
#define WIIMOTE_STATE_DEV_FOUND 0x0001
|
||||
#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_CONNECTED 0x0008
|
||||
#define WIIMOTE_STATE_RUMBLE 0x0010
|
||||
#define WIIMOTE_STATE_ACC 0x0020
|
||||
#define WIIMOTE_STATE_EXP 0x0040
|
||||
#define WIIMOTE_STATE_IR 0x0080
|
||||
#define WIIMOTE_STATE_SPEAKER 0x0100
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
|
||||
|
||||
#define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
|
||||
|
||||
/* macro to manage states */
|
||||
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
|
||||
#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
||||
|
||||
#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s))
|
||||
#define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
|
||||
|
||||
#define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
|
||||
|
||||
/* misc macros */
|
||||
#define WIIMOTE_ID(wm) (wm->unid)
|
||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
|
||||
/*
|
||||
* Smooth tilt calculations are computed with the
|
||||
* exponential moving average formula:
|
||||
* St = St_last + (alpha * (tilt - St_last))
|
||||
* alpha is between 0 and 1
|
||||
*/
|
||||
#define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f
|
||||
|
||||
#define SMOOTH_ROLL 0x01
|
||||
#define SMOOTH_PITCH 0x02
|
||||
|
||||
#include "wiiuse.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* not part of the api */
|
||||
int wiiuse_set_report_type(struct wiimote_t* wm);
|
||||
void wiiuse_send_next_pending_read_request(struct wiimote_t* wm);
|
||||
int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
|
||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WIIUSE_INTERNAL_H_INCLUDED */
|
||||
669
vendor/wiiusej/0.12b/c/wiiusej_WiiUseApi.c
vendored
669
vendor/wiiusej/0.12b/c/wiiusej_WiiUseApi.c
vendored
@@ -1,669 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
#include "wiiusej_WiiUseApi.h"
|
||||
#include "wiiuse.h"
|
||||
/*
|
||||
* These are some identifiers for wiimotes
|
||||
*
|
||||
* See below in main() for what they are used for.
|
||||
*/
|
||||
#define WIIMOTE_STATE_RUMBLE 0x0010
|
||||
#define WIIMOTE_STATE_CONNECTED 0x0008
|
||||
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
|
||||
#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
|
||||
#define WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wm, lvl) \
|
||||
do { \
|
||||
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
|
||||
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
|
||||
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
|
||||
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
|
||||
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
|
||||
else *lvl = 0; \
|
||||
} while (0)
|
||||
|
||||
/********************* VARIABLES DECLARATIONS *****************************/
|
||||
|
||||
/*
|
||||
* Make a temp array of wiimote ids.
|
||||
* Here I only anticipate connecting up to
|
||||
* two wiimotes. Each wiimote connected
|
||||
* will get one of these ids.
|
||||
*/
|
||||
static wiimote** wiimotes;
|
||||
static int nbMaxWiimotes;
|
||||
|
||||
/****************** GENERAL FUNCTIONS DEFINITIONS *************************/
|
||||
|
||||
/**
|
||||
* Connect to a wiimote or wiimotes once an address is known.
|
||||
* @param nbWiimotes The number of wiimotes.
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect
|
||||
(JNIEnv *env, jobject obj, jint nbWiimotes) {
|
||||
return wiiuse_connect(wiimotes, nbWiimotes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a wiimote or wiimotes.
|
||||
* @param nbMaxWiimotes The number of wiimotes.
|
||||
* @param timeout The number of seconds before the search times out.
|
||||
* @return The number of wiimotes found.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find
|
||||
(JNIEnv *env, jobject obj, jint nbMaxWiimotes, jint timeout) {
|
||||
return wiiuse_find(wiimotes, nbMaxWiimotes, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize an array of wiimote structures (for the C side of the library).
|
||||
* @param nbPossibleWiimotes size of the array.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init
|
||||
(JNIEnv *env, jobject obj, jint nbPossibleWiimotes) {
|
||||
wiimotes = wiiuse_init(nbPossibleWiimotes);
|
||||
nbMaxWiimotes = nbPossibleWiimotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close connection to the wiimote with the given id.
|
||||
*
|
||||
* @param id the id of the wiimote to disconnect.Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_disconnect(wiimotes[id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique id of a wiimote in the wiimotes array.
|
||||
* Please make sure you call an existing index with a
|
||||
* wiimote initialized at this index,
|
||||
* other wise you'll get a wrong value.
|
||||
* @param index index of the wiimote in the wiimotes array.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId
|
||||
(JNIEnv *env, jobject obj, jint index) {
|
||||
return wiimotes[index]->unid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown api.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp
|
||||
(JNIEnv *env, jobject obj) {
|
||||
wiiuse_cleanup(wiimotes, nbMaxWiimotes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate rumble for the wiimote with the given id.
|
||||
* @param id the id of the wiimote.Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_rumble(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate rumble for the wiimote with the given id.
|
||||
* @param id the id of the wiimote.Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_rumble(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate IR TRacking for the wiimote with the given id.
|
||||
* @param id the id of the wiimote.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_ir(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate IR TRacking for the wiimote with the given id.
|
||||
* @param id the id of the wiimote.Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_ir(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate Motion Sensing for the wiimote with the given id.
|
||||
* @param id the id of the wiimote.Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate Motion Sensing for the wiimote with the given id.
|
||||
* @param id the id of the wiimote.Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set wiimote leds status.
|
||||
* @param id the id of the wiimote concerned
|
||||
* @param led1 status of led1: True=ON, False=OFF
|
||||
* @param led2 status of led2: True=ON, False=OFF
|
||||
* @param led3 status of led3: True=ON, False=OFF
|
||||
* @param led4 status of led4: True=ON, False=OFF
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds
|
||||
(JNIEnv *env, jobject obj, jint id, jboolean led1, jboolean led2, jboolean led3, jboolean led4) {
|
||||
int leds = 0;
|
||||
|
||||
if (led1) leds |= WIIMOTE_LED_1;
|
||||
if (led2) leds |= WIIMOTE_LED_2;
|
||||
if (led3) leds |= WIIMOTE_LED_3;
|
||||
if (led4) leds |= WIIMOTE_LED_4;
|
||||
|
||||
wiiuse_set_leds(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), leds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how many degrees an angle must change to generate an event.
|
||||
* @param id id of the wiimote concerned
|
||||
* @param thresh minimum angle detected by an event
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold
|
||||
(JNIEnv *env, jobject obj, jint id, jfloat thresh) {
|
||||
wiiuse_set_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how much acceleration must change to generate an event.
|
||||
* @param id id of the wiimote concerned
|
||||
* @param val minimum value detected by an event
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold
|
||||
(JNIEnv *env, jobject obj, jint id, jint val) {
|
||||
wiiuse_set_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alpha smoothing parameter for the given id.
|
||||
* @param id id of the wiimote concerned
|
||||
* @param value alpha smoothing value
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing
|
||||
(JNIEnv *env, jobject obj, jint id, jfloat val) {
|
||||
wiiuse_set_smooth_alpha(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to resync with the wiimote by starting a new handshake.
|
||||
* @param id id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_resync(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the the accelerometers give smoother results.
|
||||
* This is set by default.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_SMOOTHING, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the the accelerometers give raw results.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0, WIIUSE_SMOOTHING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the wiimote generate an event each time we poll.
|
||||
* Not set by default.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_CONTINUOUS, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the wiimote generate an event only when there is one.
|
||||
* (default behavior)
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_flags(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0, WIIUSE_CONTINUOUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify wiiuse that your screen has an aspect ratio of 4/3.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_aspect_ratio(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_ASPECT_4_3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify wiiuse that your screen has an aspect ratio of 16/9.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_aspect_ratio(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_ASPECT_4_3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify wiiuse that the sensor bar is above your screen.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_ir_position(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_IR_ABOVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify wiiuse that the sensor bar is below your screen.
|
||||
* @param id the id of the wiimote concerned
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_set_ir_position(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), WIIUSE_IR_BELOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set virtual screen resolution. It is used to automatically
|
||||
* compute the position of a cursor on this virtual screen
|
||||
* using the sensor bar. These results come in the IREvent.
|
||||
* @param id the id of the wiimote concerned
|
||||
* @param x x resolution.
|
||||
* @param y y resolution.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution
|
||||
(JNIEnv *env, jobject obj, jint id, jint x, jint y) {
|
||||
wiiuse_set_ir_vres(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status from the wiimotes and send it through call backs.
|
||||
*
|
||||
* @param id the id of the wiimote. Must be 1 or 2.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_status(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the normal and expansion handshake timeouts.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param normalTimeout
|
||||
* The timeout in milliseconds for a normal read.
|
||||
* @param expansionTimeout
|
||||
* The timeout in millisecondsd to wait for an expansion
|
||||
* handshake.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout
|
||||
(JNIEnv *env, jobject obj, jint id, jshort normalTimeout, jshort expansionTimeout) {
|
||||
wiiuse_set_timeout(wiimotes, nbMaxWiimotes, normalTimeout, expansionTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IR sensitivity.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param level
|
||||
* 1-5, same as Wii system sensitivity setting. If the level is <
|
||||
* 1, then level will be set to 1. If the level is > 5, then
|
||||
* level will be set to 5.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity
|
||||
(JNIEnv *env, jobject obj, jint id, jint level) {
|
||||
wiiuse_set_ir_sensitivity(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how many degrees an angle must change to generate an event for the nunchuk.
|
||||
* @param id id of the wiimote concerned
|
||||
* @param thresh minimum angle detected by an event
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold
|
||||
(JNIEnv *env, jobject obj, jint id, jfloat thresh) {
|
||||
wiiuse_set_nunchuk_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how much acceleration must change to generate an event for the nunchuk.
|
||||
* @param id id of the wiimote concerned
|
||||
* @param val minimum value detected by an event
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold
|
||||
(JNIEnv *env, jobject obj, jint id, jint val) {
|
||||
wiiuse_set_nunchuk_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the bluetooth stack type.(useful only for windows)
|
||||
*
|
||||
* @param bluetoothStackType
|
||||
* must be WiiUseApi.WIIUSE_STACK_UNKNOWN or WiiUseApi.WIIUSE_STACK_MS or
|
||||
* WiiUseApi.WIIUSE_STACK_BLUESOLEIL.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack
|
||||
(JNIEnv *env, jobject obj, jint bluetoothStackType) {
|
||||
if (bluetoothStackType == 0) {
|
||||
wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_UNKNOWN);
|
||||
} else if (bluetoothStackType == 1) {
|
||||
wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_MS);
|
||||
} else if (bluetoothStackType == 2) {
|
||||
wiiuse_set_bluetooth_stack(wiimotes, nbMaxWiimotes, WIIUSE_STACK_BLUESOLEIL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status and values from the wiimotes and send it through callbacks.
|
||||
* @param wim the wiimote object to fill with the datas.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
(JNIEnv *env, jobject obj, jobject gath) {
|
||||
|
||||
/* Variables Declarations */
|
||||
int i;
|
||||
short leds = 0;
|
||||
jclass cls = (*env)->GetObjectClass(env, gath);
|
||||
jmethodID mid;
|
||||
printf("avant poll, nbMaxwiimotes : %i \n",nbMaxWiimotes);
|
||||
if (wiiuse_poll(wiimotes, nbMaxWiimotes)) {
|
||||
/*
|
||||
* This happens if something happened on any wiimote.
|
||||
* So go through each one and check if anything happened.
|
||||
*/
|
||||
printf("il y a des events\n");
|
||||
for (i=0; i < nbMaxWiimotes; ++i) {
|
||||
printf("recupe events wiimote : %i\n",nbMaxWiimotes);
|
||||
switch (wiimotes[i]->event) {
|
||||
case WIIUSE_EVENT:
|
||||
/* a generic event occured */
|
||||
|
||||
printf("Generic event\n");
|
||||
mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid, wiimotes[i]->btns,
|
||||
wiimotes[i]->btns_released, wiimotes[i]->btns_held);
|
||||
/*
|
||||
* If IR tracking is enabled then print the coordinates
|
||||
* on the virtual screen that the wiimote is pointing to.
|
||||
*
|
||||
* Also make sure that we see at least 1 dot.
|
||||
*/
|
||||
if (WIIUSE_USING_IR(wiimotes[i])) {
|
||||
printf("IR event\n");
|
||||
int a;
|
||||
WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wiimotes[i], &a);
|
||||
|
||||
mid = (*env)->GetMethodID(env, cls, "prepareIRevent",
|
||||
"(IIFIIIIIISSSF)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z,
|
||||
wiimotes[i]->ir.ax, wiimotes[i]->ir.ay,
|
||||
wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1],
|
||||
wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1],
|
||||
wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect,
|
||||
a , wiimotes[i]->ir.distance);
|
||||
|
||||
mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent",
|
||||
"(IISSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
/* go through each of the 4 possible IR sources */
|
||||
for (a=0; a < 4; a++) {
|
||||
/* check if the source is visible */
|
||||
if (wiimotes[i]->ir.dot[a].visible) {
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y,
|
||||
wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry,
|
||||
wiimotes[i]->ir.dot[a].size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Motion Sensing */
|
||||
if (WIIUSE_USING_ACC(wiimotes[i])) {
|
||||
printf("acc event\n");
|
||||
/* set orientation and gravity force */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addMotionSensingValues", "(FIZFFFFFFFFFSSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold,
|
||||
WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), wiimotes[i]->accel_calib.st_alpha,
|
||||
wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw,
|
||||
wiimotes[i]->orient.a_roll, wiimotes[i]->orient.a_pitch,
|
||||
wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z,
|
||||
wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z);
|
||||
}
|
||||
|
||||
/* Expansions support support*/
|
||||
if (WIIUSE_USING_EXP(wiimotes[i])) {
|
||||
/* Nunchuk support */
|
||||
if (wiimotes[i]->exp.type == EXP_NUNCHUK) {
|
||||
/* put nunchuk values in wiimote generic event */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addNunchunkEventToPreparedWiimoteEvent", "(SSSFIZFFFFFFFFFSSSFFSSSSSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk;
|
||||
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
/* buttons */
|
||||
nc->btns,nc->btns_released,nc->btns_held,
|
||||
/* motion sensing */
|
||||
nc->orient_threshold,nc->accel_threshold,
|
||||
WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING),nc->accel_calib.st_alpha,
|
||||
nc->orient.roll, nc->orient.pitch, nc->orient.yaw,
|
||||
nc->orient.a_roll, nc->orient.a_pitch,
|
||||
nc->gforce.x, nc->gforce.y, nc->gforce.z,
|
||||
nc->accel.x, nc->accel.y, nc->accel.z,
|
||||
/* joystick */
|
||||
nc->js.ang,nc->js.mag,
|
||||
nc->js.max.x,nc->js.max.y,
|
||||
nc->js.min.x,nc->js.min.y,
|
||||
nc->js.center.x,nc->js.center.y);
|
||||
}
|
||||
else if (wiimotes[i]->exp.type == EXP_GUITAR_HERO_3) {
|
||||
/* put guitar hero values in wiimote generic event */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addGuitarHeroEventToPreparedWiimoteEvent", "(SSSFFFSSSSSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
struct guitar_hero_3_t* gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3;
|
||||
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
/* buttons */
|
||||
gh->btns,gh->btns_released,gh->btns_held,
|
||||
/* whammy bar */
|
||||
gh->whammy_bar,
|
||||
/* joystick */
|
||||
gh->js.ang,gh->js.mag,
|
||||
gh->js.max.x,gh->js.max.y,
|
||||
gh->js.min.x,gh->js.min.y,
|
||||
gh->js.center.x,gh->js.center.y);
|
||||
}if (wiimotes[i]->exp.type == EXP_CLASSIC) {
|
||||
/* put classic controller values in wiimote generic event */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addClassicControllerEventToPreparedWiimoteEvent", "(SSSFFFFSSSSSSFFSSSSSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
struct classic_ctrl_t* cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic;
|
||||
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
/* buttons */
|
||||
cl->btns,cl->btns_released,cl->btns_held,
|
||||
/* shoulder buttons */
|
||||
cl->r_shoulder,cl->l_shoulder,
|
||||
/* joystick left*/
|
||||
cl->ljs.ang,cl->ljs.mag,
|
||||
cl->ljs.max.x,cl->ljs.max.y,
|
||||
cl->ljs.min.x,cl->ljs.min.y,
|
||||
cl->ljs.center.x,cl->ljs.center.y,
|
||||
/* joystick right */
|
||||
cl->rjs.ang,cl->rjs.mag,
|
||||
cl->rjs.max.x,cl->rjs.max.y,
|
||||
cl->rjs.min.x,cl->rjs.min.y,
|
||||
cl->rjs.center.x,cl->rjs.center.y);
|
||||
}
|
||||
}
|
||||
|
||||
/* add generic event to java object used to gather events in c environment */
|
||||
mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent",
|
||||
"()V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid);
|
||||
break;
|
||||
|
||||
case WIIUSE_DISCONNECT:
|
||||
/* the wiimote disconnected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_UNEXPECTED_DISCONNECT:
|
||||
/* the wimote disconnected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_INSERTED:
|
||||
/* the nunchuk was just connected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addNunchukInsertedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_REMOVED:
|
||||
/* the nunchuk disconnected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addNunchukRemovedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
|
||||
/* the guitar hero was just connected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addGuitarHeroInsertedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
|
||||
/* the guitar hero disconnected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addGuitarHeroRemovedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_CLASSIC_CTRL_INSERTED:
|
||||
/* the classic controller was just connected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addClassicControllerInsertedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_CLASSIC_CTRL_REMOVED:
|
||||
/* the classic controller disconnected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addClassicControllerRemovedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_STATUS:
|
||||
/* a status event occured */
|
||||
mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
/* LEDS */
|
||||
if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1;
|
||||
if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2;
|
||||
if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4;
|
||||
if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8;
|
||||
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED),
|
||||
wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]),
|
||||
wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE),
|
||||
WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS),
|
||||
WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i]));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
vendor/wiiusej/0.12b/c/wiiusej_WiiUseApi.def
vendored
34
vendor/wiiusej/0.12b/c/wiiusej_WiiUseApi.def
vendored
@@ -1,34 +0,0 @@
|
||||
EXPORTS
|
||||
Java_wiiusej_WiiUseApi_connect
|
||||
Java_wiiusej_WiiUseApi_find
|
||||
Java_wiiusej_WiiUseApi_init
|
||||
Java_wiiusej_WiiUseApi_closeConnection
|
||||
Java_wiiusej_WiiUseApi_getUnId
|
||||
Java_wiiusej_WiiUseApi_cleanUp
|
||||
Java_wiiusej_WiiUseApi_activateRumble
|
||||
Java_wiiusej_WiiUseApi_deactivateRumble
|
||||
Java_wiiusej_WiiUseApi_activateIRTracking
|
||||
Java_wiiusej_WiiUseApi_deactivateIRTracking
|
||||
Java_wiiusej_WiiUseApi_activateMotionSensing
|
||||
Java_wiiusej_WiiUseApi_deactivateMotionSensing
|
||||
Java_wiiusej_WiiUseApi_setLeds
|
||||
Java_wiiusej_WiiUseApi_setOrientThreshold
|
||||
Java_wiiusej_WiiUseApi_setAccelThreshold
|
||||
Java_wiiusej_WiiUseApi_setAlphaSmoothing
|
||||
Java_wiiusej_WiiUseApi_reSync
|
||||
Java_wiiusej_WiiUseApi_activateSmoothing
|
||||
Java_wiiusej_WiiUseApi_deactivateSmoothing
|
||||
Java_wiiusej_WiiUseApi_activateContinuous
|
||||
Java_wiiusej_WiiUseApi_deactivateContinuous
|
||||
Java_wiiusej_WiiUseApi_setScreenRatio43
|
||||
Java_wiiusej_WiiUseApi_setScreenRatio169
|
||||
Java_wiiusej_WiiUseApi_setSensorBarAboveScreen
|
||||
Java_wiiusej_WiiUseApi_setSensorBarBelowScreen
|
||||
Java_wiiusej_WiiUseApi_setVirtualScreenResolution
|
||||
Java_wiiusej_WiiUseApi_getStatus
|
||||
Java_wiiusej_WiiUseApi_setTimeout
|
||||
Java_wiiusej_WiiUseApi_setIrSensitivity
|
||||
Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold
|
||||
Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold
|
||||
Java_wiiusej_WiiUseApi_windowsSetBluetoothStack
|
||||
Java_wiiusej_WiiUseApi_specialPoll
|
||||
277
vendor/wiiusej/0.12b/c/wiiusej_WiiUseApi.h
vendored
277
vendor/wiiusej/0.12b/c/wiiusej_WiiUseApi.h
vendored
@@ -1,277 +0,0 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class wiiusej_WiiUseApi */
|
||||
|
||||
#ifndef _Included_wiiusej_WiiUseApi
|
||||
#define _Included_wiiusej_WiiUseApi
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: connect
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: find
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: init
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: closeConnection
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: getUnId
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_getUnId
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: cleanUp
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_cleanUp
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: activateRumble
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: deactivateRumble
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: activateIRTracking
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: deactivateIRTracking
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: activateMotionSensing
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: deactivateMotionSensing
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setLeds
|
||||
* Signature: (IZZZZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds
|
||||
(JNIEnv *, jobject, jint, jboolean, jboolean, jboolean, jboolean);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setOrientThreshold
|
||||
* Signature: (IF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold
|
||||
(JNIEnv *, jobject, jint, jfloat);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setAccelThreshold
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setAlphaSmoothing
|
||||
* Signature: (IF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAlphaSmoothing
|
||||
(JNIEnv *, jobject, jint, jfloat);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: reSync
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: activateSmoothing
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: deactivateSmoothing
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: activateContinuous
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: deactivateContinuous
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setScreenRatio43
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio43
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setScreenRatio169
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setScreenRatio169
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setSensorBarAboveScreen
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarAboveScreen
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setSensorBarBelowScreen
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSensorBarBelowScreen
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setVirtualScreenResolution
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution
|
||||
(JNIEnv *, jobject, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: getStatus
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setTimeout
|
||||
* Signature: (ISS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout
|
||||
(JNIEnv *, jobject, jint, jshort, jshort);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setIrSensitivity
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setNunchukOrientationThreshold
|
||||
* Signature: (IF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold
|
||||
(JNIEnv *, jobject, jint, jfloat);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setNunchukAccelerationThreshold
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: windowsSetBluetoothStack
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: specialPoll
|
||||
* Signature: (Lwiiusej/wiiusejevents/utils/EventsGatherer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
351
vendor/wiiusej/0.12b/java/wiiusej/WiiUseApi.java
vendored
351
vendor/wiiusej/0.12b/java/wiiusej/WiiUseApi.java
vendored
@@ -1,351 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej;
|
||||
|
||||
import wiiusej.wiiusejevents.utils.EventsGatherer;
|
||||
|
||||
/**
|
||||
* Singleton used to manipulate WiiUse Api.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class WiiUseApi {
|
||||
|
||||
static {
|
||||
System.loadLibrary("WiiuseJ");
|
||||
}
|
||||
|
||||
private static WiiUseApi instance = new WiiUseApi();
|
||||
|
||||
/**
|
||||
* Get the only instance of WiiUseApi.
|
||||
*
|
||||
* @return the only instace of WiiUseApi.
|
||||
*/
|
||||
protected static WiiUseApi getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a wiimote or wiimotes once an address is known.
|
||||
*
|
||||
* @param nbWiimotes
|
||||
* The number of wiimotes.
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*/
|
||||
synchronized native int connect(int nbWiimotes);
|
||||
|
||||
/**
|
||||
* Find a wiimote or wiimotes.
|
||||
*
|
||||
* @param nbMaxWiimotes
|
||||
* The number of wiimotes.
|
||||
* @param timeout
|
||||
* The number of seconds before the search times out.
|
||||
* @return The number of wiimotes found.
|
||||
*/
|
||||
synchronized native int find(int nbMaxWiimotes, int timeout);
|
||||
|
||||
/**
|
||||
* Initialize an array of wiimote structures (for the C side of the
|
||||
* library).
|
||||
*
|
||||
* @param nbPossibleWiimotes
|
||||
* size of the array.
|
||||
*/
|
||||
synchronized native void init(int nbPossibleWiimotes);
|
||||
|
||||
/**
|
||||
* Close connection to the wiimote with the given id.
|
||||
*
|
||||
*/
|
||||
synchronized native void closeConnection(int id);
|
||||
|
||||
/**
|
||||
* Get unique id of a wiimote in the wiimotes array. Please make sure you
|
||||
* call an existing index with a wiimote initialized at this index, other
|
||||
* wise you'll get a wrong value.
|
||||
*
|
||||
* @param index
|
||||
* index of the wiimote in the wiimotes array.
|
||||
* @return the unid of the wiimote, or a wrong value if the index was false.
|
||||
*
|
||||
*/
|
||||
synchronized native int getUnId(int index);
|
||||
|
||||
/**
|
||||
* CleanUp Wiiuse API.
|
||||
*/
|
||||
synchronized native void cleanUp();
|
||||
|
||||
/**
|
||||
* Activate rumble on the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote.
|
||||
*/
|
||||
synchronized native void activateRumble(int id);
|
||||
|
||||
/**
|
||||
* Deactivate rumble on the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote.
|
||||
*/
|
||||
synchronized native void deactivateRumble(int id);
|
||||
|
||||
/**
|
||||
* Activate IR Tracking on the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote.
|
||||
*/
|
||||
synchronized native void activateIRTracking(int id);
|
||||
|
||||
/**
|
||||
* Deactivate IR Tracking on the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote.
|
||||
*/
|
||||
synchronized native void deactivateIRTracking(int id);
|
||||
|
||||
/**
|
||||
* Activate motion sensing on the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote.
|
||||
*/
|
||||
synchronized native void activateMotionSensing(int id);
|
||||
|
||||
/**
|
||||
* Deactivate motion sensing on the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote.
|
||||
*/
|
||||
synchronized native void deactivateMotionSensing(int id);
|
||||
|
||||
/**
|
||||
* Set wiimote leds status.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param led1
|
||||
* status of led1: True=ON, False=OFF.
|
||||
* @param led2
|
||||
* status of led2: True=ON, False=OFF.
|
||||
* @param led3
|
||||
* status of led3: True=ON, False=OFF.
|
||||
* @param led4
|
||||
* status of led4: True=ON, False=OFF.
|
||||
*/
|
||||
synchronized native void setLeds(int id, boolean led1, boolean led2,
|
||||
boolean led3, boolean led4);
|
||||
|
||||
/**
|
||||
* Set how many degrees an angle must change to generate an event.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
* @param angle
|
||||
* minimum angle detected by an event.
|
||||
*/
|
||||
synchronized native void setOrientThreshold(int id, float angle);
|
||||
|
||||
/**
|
||||
* Set how much acceleration must change to generate an event.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
* @param value
|
||||
* minimum value detected by an event.
|
||||
*/
|
||||
synchronized native void setAccelThreshold(int id, int value);
|
||||
|
||||
/**
|
||||
* Set alpha smoothing parameter for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
* @param value
|
||||
* alpha smoothing value.
|
||||
*/
|
||||
synchronized native void setAlphaSmoothing(int id, float value);
|
||||
|
||||
/**
|
||||
* Try to resync with the wiimote by starting a new handshake.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void reSync(int id);
|
||||
|
||||
/**
|
||||
* Make the the accelerometers give smoother results. This is set by
|
||||
* default.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void activateSmoothing(int id);
|
||||
|
||||
/**
|
||||
* Make the the accelerometers give raw results.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void deactivateSmoothing(int id);
|
||||
|
||||
/**
|
||||
* Make the wiimote generate an event each time we poll. Not set by default.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void activateContinuous(int id);
|
||||
|
||||
/**
|
||||
* Make the wiimote generate an event only when there is one.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void deactivateContinuous(int id);
|
||||
|
||||
/**
|
||||
* Notify wiiuse that your screen has an aspect ratio of 4/3.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote of which we want the status.
|
||||
*/
|
||||
synchronized native void setScreenRatio43(int id);
|
||||
|
||||
/**
|
||||
* Notify wiiuse that your screen has an aspect ratio of 16/9.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote of which we want the status.
|
||||
*/
|
||||
synchronized native void setScreenRatio169(int id);
|
||||
|
||||
/**
|
||||
* Notify wiiuse that the sensor bar is above your screen.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote of which we want the status.
|
||||
*/
|
||||
synchronized native void setSensorBarAboveScreen(int id);
|
||||
|
||||
/**
|
||||
* Notify wiiuse that the sensor bar is below your screen.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote of which we want the status.
|
||||
*/
|
||||
synchronized native void setSensorBarBelowScreen(int id);
|
||||
|
||||
/**
|
||||
* Set virtual screen resolution. It is used to automatically compute the
|
||||
* position of a cursor on this virtual screen using the sensor bar. These
|
||||
* results come in the IREvent.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote of which we want the status.
|
||||
* @param x
|
||||
* x resolution.
|
||||
* @param y
|
||||
* y resolution.
|
||||
*/
|
||||
synchronized native void setVirtualScreenResolution(int id, int x, int y);
|
||||
|
||||
/**
|
||||
* Get status and values from the wiimotes and send it through callbacks.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote of which we want the status.
|
||||
*/
|
||||
synchronized native void getStatus(int id);
|
||||
|
||||
/**
|
||||
* Set the normal and expansion handshake timeouts.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param normalTimeout
|
||||
* The timeout in milliseconds for a normal read.
|
||||
* @param expansionTimeout
|
||||
* The timeout in millisecondsd to wait for an expansion
|
||||
* handshake.
|
||||
*/
|
||||
synchronized native void setTimeout(int id, short normalTimeout,
|
||||
short expansionTimeout);
|
||||
|
||||
/**
|
||||
* Set the IR sensitivity.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param level
|
||||
* 1-5, same as Wii system sensitivity setting. If the level is <
|
||||
* 1, then level will be set to 1. If the level is > 5, then
|
||||
* level will be set to 5.
|
||||
*/
|
||||
synchronized native void setIrSensitivity(int id, int level);
|
||||
|
||||
/**
|
||||
* Set how many degrees an angle must change to generate an event for the
|
||||
* nunchuk.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
* @param angle
|
||||
* minimum angle detected by an event.
|
||||
*/
|
||||
synchronized native void setNunchukOrientationThreshold(int id, float angle);
|
||||
|
||||
/**
|
||||
* Set how much acceleration must change to generate an event for the
|
||||
* nunchuk.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
* @param value
|
||||
* minimum value detected by an event.
|
||||
*/
|
||||
synchronized native void setNunchukAccelerationThreshold(int id, int value);
|
||||
|
||||
/**
|
||||
* Force the bluetooth stack type.(useful only for windows)
|
||||
*
|
||||
* @param bluetoothStackType
|
||||
* must be WiiUseApi.WIIUSE_STACK_UNKNOWN or
|
||||
* WiiUseApi.WIIUSE_STACK_MS or
|
||||
* WiiUseApi.WIIUSE_STACK_BLUESOLEIL.
|
||||
*/
|
||||
native void windowsSetBluetoothStack(int bluetoothStackType);
|
||||
|
||||
/**
|
||||
* Check for new Events and Get it.
|
||||
*
|
||||
* @param gath
|
||||
* the object where we store all the new events.
|
||||
*/
|
||||
native void specialPoll(EventsGatherer gath);
|
||||
|
||||
}
|
||||
@@ -1,664 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.swing.event.EventListenerList;
|
||||
|
||||
import wiiusej.wiiusejevents.utils.EventsGatherer;
|
||||
import wiiusej.wiiusejevents.utils.WiiUseApiListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
|
||||
|
||||
/**
|
||||
* Class that manages the use of Wiiuse API.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class WiiUseApiManager extends Thread {
|
||||
|
||||
private static WiiUseApiManager instance = new WiiUseApiManager();
|
||||
|
||||
private final EventListenerList listeners = new EventListenerList();
|
||||
|
||||
private Semaphore semaphore = new Semaphore(0);
|
||||
|
||||
private Wiimote[] wiimotes;
|
||||
|
||||
private WiiUseApi wiiuse = WiiUseApi.getInstance();
|
||||
|
||||
private int connected = -1;
|
||||
|
||||
private AtomicBoolean running = new AtomicBoolean(false);
|
||||
|
||||
private boolean leave = false;
|
||||
|
||||
public static int WIIUSE_STACK_UNKNOWN = 0;
|
||||
public static int WIIUSE_STACK_MS = 1;
|
||||
public static int WIIUSE_STACK_BLUESOLEIL = 2;
|
||||
|
||||
public static WiiUseApiManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wiimotes. Load library if necessary. Connect to wiimotes if
|
||||
* necessary. Start polling if necessary. Return an array with the connected
|
||||
* wiimotes.
|
||||
*
|
||||
* @param nb
|
||||
* try to connect nb wiimotes.
|
||||
* @param rumble
|
||||
* make the connected wiimotes rumble.
|
||||
*
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
public static Wiimote[] getWiimotes(int nb, boolean rumble) {
|
||||
return getWiimotesPrivate(nb, rumble, false, WIIUSE_STACK_UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wiimotes. Load library if necessary. Connect to wiimotes if
|
||||
* necessary. Start polling if necessary. Return an array with the connected
|
||||
* wiimotes.
|
||||
*
|
||||
* @param nb
|
||||
* try to connect nb wiimotes.
|
||||
* @param rumble
|
||||
* make the connected wiimotes rumble.*
|
||||
* @param stackType
|
||||
* the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or
|
||||
* WiiUseApiManager.WIIUSE_STACK_MS or
|
||||
* WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
|
||||
*
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
public static Wiimote[] getWiimotes(int nb, boolean rumble, int stackType) {
|
||||
return getWiimotesPrivate(nb, rumble, true, stackType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wiimotes. Load library if necessary. Connect to wiimotes if
|
||||
* necessary. Start polling if necessary. Return an array with the connected
|
||||
* wiimotes.
|
||||
*
|
||||
* @param nb
|
||||
* try to connect nb wiimotes.
|
||||
* @param rumble
|
||||
* make the connected wiimotes rumble.*
|
||||
* @param forceStackType
|
||||
* true if we want to force the stack type.
|
||||
* @param stackType
|
||||
* the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or
|
||||
* WiiUseApiManager.WIIUSE_STACK_MS or
|
||||
* WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
|
||||
*
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
private synchronized static Wiimote[] getWiimotesPrivate(int nb,
|
||||
boolean rumble, boolean forceStackType, int stackType) {
|
||||
WiiUseApiManager manager = getInstance();
|
||||
|
||||
if (manager.leave)
|
||||
return null;// wiiusej definitively stopped
|
||||
|
||||
if (manager.connected <= 0 && !manager.running.get()) {
|
||||
// connect wiimotes.
|
||||
int nbWiimotes = manager.connectWiimotes(nb, rumble,
|
||||
forceStackType, stackType);
|
||||
manager.wiimotes = new Wiimote[nbWiimotes];
|
||||
for (int i = 0; i < nbWiimotes; i++) {
|
||||
Wiimote wim = new Wiimote(WiiUseApi.getInstance().getUnId(i),
|
||||
manager);
|
||||
manager.wiimotes[i] = wim;
|
||||
manager.addWiiUseApiListener(wim);
|
||||
}
|
||||
// Set leds on wiimote
|
||||
for (Wiimote wiimote : manager.wiimotes) {
|
||||
int id = wiimote.getId();
|
||||
if (id % 4 == 0) {
|
||||
wiimote.setLeds(true, true, true, true);
|
||||
} else if (id % 4 == 1) {
|
||||
wiimote.setLeds(true, false, false, false);
|
||||
} else if (id % 4 == 2) {
|
||||
wiimote.setLeds(true, true, false, false);
|
||||
} else if (id % 4 == 3) {
|
||||
wiimote.setLeds(true, true, true, false);
|
||||
}
|
||||
}
|
||||
// make the connected wiimotes rumble
|
||||
if (rumble) {
|
||||
for (Wiimote wiimote : manager.wiimotes) {
|
||||
wiimote.activateRumble();
|
||||
}
|
||||
try {
|
||||
sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
for (Wiimote wiimote : manager.wiimotes) {
|
||||
wiimote.deactivateRumble();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (manager.connected == 0) {// no wiimote connected
|
||||
// return empty array
|
||||
return new Wiimote[0];
|
||||
}
|
||||
|
||||
if (!manager.isAlive())// start wiiuseJ polling
|
||||
manager.start();
|
||||
|
||||
manager.semaphore.release(1);
|
||||
|
||||
return manager.wiimotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect wiimote and get the number of wiimotes connected. Supposed to be
|
||||
* used once.
|
||||
*
|
||||
* @param nb
|
||||
* try to connect nb wiimotes
|
||||
* @param rumble
|
||||
* make the connected wiimotes rumble
|
||||
* @param forceStackType
|
||||
* true if we want to force the stack type.
|
||||
* @param stackType
|
||||
* the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or
|
||||
* WiiUseApiManager.WIIUSE_STACK_MS or
|
||||
* WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
|
||||
* @return 0 if nothing connected or the number of wiimotes connected.
|
||||
*/
|
||||
private int connectWiimotes(int nb, boolean rumble, boolean forceStackType,
|
||||
int stackType) {
|
||||
if (connected <= 0) {
|
||||
int nbWiimotesFound;
|
||||
wiiuse.init(nb);
|
||||
// force bluetooth stack type ?
|
||||
if (forceStackType)
|
||||
setBlueToothstackType(stackType);
|
||||
nbWiimotesFound = wiiuse.find(nb, 3);
|
||||
connected = wiiuse.connect(nbWiimotesFound);
|
||||
return connected;
|
||||
} else {// library not loaded, no wiimotes connected
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the thread to close a connection.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote to disconnect.
|
||||
*/
|
||||
protected void closeConnection(int id) {
|
||||
int index = 0;
|
||||
boolean found = false;
|
||||
while (index < wiimotes.length && !found) {
|
||||
if (wiimotes[index]!=null && wiimotes[index].getId() == id) {// we have a wiimote with this
|
||||
// id
|
||||
// remove the wiimote
|
||||
removeWiiUseApiListener(wiimotes[index]);
|
||||
wiimotes[index] = null;
|
||||
connected--;
|
||||
if (connected == 0) {// stop this thread if there is
|
||||
// no more wiimotes connected.
|
||||
// stop thread
|
||||
running.set(false);
|
||||
}
|
||||
/* Close connection in wiiuse */
|
||||
wiiuse.closeConnection(index);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of wiimotes connected.
|
||||
*
|
||||
* @return the number of wiimotes connected.
|
||||
*/
|
||||
public static int getNbConnectedWiimotes() {
|
||||
return getInstance().connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop thread and shutdown wiiuse Api.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
WiiUseApiManager manager = getInstance();
|
||||
int pastConnected = manager.connected;
|
||||
if (manager.connected > 0) {
|
||||
for (Wiimote wim : manager.wiimotes) {
|
||||
if (wim != null)
|
||||
wim.disconnect();
|
||||
}
|
||||
}
|
||||
manager.running.set(false);
|
||||
if (pastConnected > 0) {
|
||||
manager.wiiuse.cleanUp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop wiiuseJ definitively for this program. It finishes Wiiusej thread
|
||||
* and shutdown wiiuse API.
|
||||
*/
|
||||
public static void definitiveShutdown() {
|
||||
getInstance().leave = true;
|
||||
shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the rumble for the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void activateRumble(int id) {
|
||||
wiiuse.activateRumble(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate the rumble for the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void deactivateRumble(int id) {
|
||||
wiiuse.deactivateRumble(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate IR Tracking for the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void activateIRTRacking(int id) {
|
||||
wiiuse.activateIRTracking(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate IR Tracking for the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void deactivateIRTRacking(int id) {
|
||||
wiiuse.deactivateIRTracking(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate motion sensing for the wiimote with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void activateMotionSensing(int id) {
|
||||
wiiuse.activateMotionSensing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate motion sensing for the wiimoter with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void deactivateMotionSensing(int id) {
|
||||
wiiuse.deactivateMotionSensing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate smoothing the wiimotes with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void activateSmoothing(int id) {
|
||||
wiiuse.activateSmoothing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate smoothing the wiimotes with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void deactivateSmoothing(int id) {
|
||||
wiiuse.deactivateSmoothing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate continuous for the wiimotes with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void activateContinuous(int id) {
|
||||
wiiuse.activateContinuous(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate continuous for the wiimotes with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void deactivateContinuous(int id) {
|
||||
wiiuse.deactivateContinuous(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set leds for the wiimotes with the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* @param l1
|
||||
* status of led1. True : ON, False : OFF.
|
||||
* @param l2
|
||||
* status of led2. True : ON, False : OFF.
|
||||
* @param l3
|
||||
* status of led3. True : ON, False : OFF.
|
||||
* @param l4
|
||||
* status of led4. True : ON, False : OFF.
|
||||
*/
|
||||
protected void setLeds(int id, boolean l1, boolean l2, boolean l3,
|
||||
boolean l4) {
|
||||
wiiuse.setLeds(id, l1, l2, l3, l4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the orientation threshold for the given id. (minimum angle between
|
||||
* two events)
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold in degrees.
|
||||
*/
|
||||
protected void setOrientationThreshold(int id, float th) {
|
||||
wiiuse.setOrientThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the acceleration threshold for the given id. (minimum angle between
|
||||
* two events)
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold.
|
||||
*/
|
||||
protected void setAccelerationThreshold(int id, int th) {
|
||||
wiiuse.setAccelThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alpha smoothing for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold.
|
||||
*/
|
||||
protected void setAlphaSmoothing(int id, float th) {
|
||||
wiiuse.setAlphaSmoothing(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to resync with the wiimote by starting a new handshake.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void reSync(int id) {
|
||||
wiiuse.reSync(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set screen aspect ratio to 4/3 for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void setScreenAspectRatio43(int id) {
|
||||
wiiuse.setScreenRatio43(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set screen aspect ratio to 16/9 for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void setScreenAspectRatio169(int id) {
|
||||
wiiuse.setScreenRatio169(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sensor bar to be above the screen.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void setSensorBarAboveScreen(int id) {
|
||||
wiiuse.setSensorBarAboveScreen(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sensor bar to be below the screen.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void setSensorBarBelowScreen(int id) {
|
||||
wiiuse.setSensorBarBelowScreen(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set virtual resolution. It is used to automatically compute the position
|
||||
* of a cursor on this virtual screen using the sensor bar. These results
|
||||
* come in the IREvent.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param x
|
||||
* x resolution.
|
||||
* @param y
|
||||
* y resolution.
|
||||
*/
|
||||
protected void setVirtualResolution(int id, int x, int y) {
|
||||
wiiuse.setVirtualScreenResolution(id, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Status for the wiimote for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
*/
|
||||
protected void getStatus(int id) {
|
||||
wiiuse.getStatus(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the normal and expansion handshake timeouts.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param normalTimeout
|
||||
* The timeout in milliseconds for a normal read.
|
||||
* @param expansionTimeout
|
||||
* The timeout in millisecondsd to wait for an expansion
|
||||
* handshake.
|
||||
*/
|
||||
protected void setTimeout(int id, short normalTimeout,
|
||||
short expansionTimeout) {
|
||||
wiiuse.setTimeout(id, normalTimeout, expansionTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IR sensitivity.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
* @param level
|
||||
* 1-5, same as Wii system sensitivity setting. If the level is <
|
||||
* 1, then level will be set to 1. If the level is > 5, then
|
||||
* level will be set to 5.
|
||||
*/
|
||||
protected void setIrSensitivity(int id, int level) {
|
||||
wiiuse.setIrSensitivity(id, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nunchuk orientation threshold for the given id. (minimum angle
|
||||
* between two events)
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold in degrees.
|
||||
*/
|
||||
protected void setNunchukOrientationThreshold(int id, float th) {
|
||||
wiiuse.setNunchukOrientationThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nunchuk acceleration threshold for the given id. (minimum angle
|
||||
* between two events)
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold.
|
||||
*/
|
||||
protected void setNunchukAccelerationThreshold(int id, int th) {
|
||||
wiiuse.setNunchukAccelerationThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the bluetooth stack type.(useful only for windows)
|
||||
*
|
||||
* @param type
|
||||
* must be WIIUSE_STACK_UNKNOWN or WIIUSE_STACK_MS or
|
||||
* WIIUSE_STACK_BLUESOLEIL.
|
||||
*/
|
||||
private void setBlueToothstackType(int type) {
|
||||
wiiuse.windowsSetBluetoothStack(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (!leave) {
|
||||
try {
|
||||
semaphore.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (connected > 0) {
|
||||
running.set(true);
|
||||
|
||||
EventsGatherer gather = new EventsGatherer(connected);
|
||||
|
||||
// Start polling and tell the observers when there are Wiimote
|
||||
// events
|
||||
while (running.get() && connected > 0) {
|
||||
|
||||
/* Polling */
|
||||
wiiuse.specialPoll(gather);
|
||||
|
||||
/* deal with events gathered in Wiiuse API */
|
||||
for (WiiUseApiEvent evt : gather.getEvents()) {
|
||||
if (evt.getWiimoteId() != -1) {// event filled
|
||||
// there is an event notify observers
|
||||
notifyWiiUseApiListener(evt);
|
||||
if (evt.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
|
||||
// check if it was a disconnection
|
||||
// in this case disconnect the wiimote
|
||||
closeConnection(evt.getWiimoteId());
|
||||
}
|
||||
} else {
|
||||
System.out
|
||||
.println("There is an event with id == -1 ??? there is a problem !!! : "
|
||||
+ evt);
|
||||
}
|
||||
}
|
||||
gather.clearEvents();
|
||||
}
|
||||
}/* else {
|
||||
if (connected <= 0) {
|
||||
System.out.println("No wiimotes connected !");
|
||||
}
|
||||
}*/
|
||||
}// end while true
|
||||
}
|
||||
|
||||
/**
|
||||
* Add WiiUseApiListener to the listeners list.
|
||||
*
|
||||
* @param listener
|
||||
* a WiiUseApiListener
|
||||
*/
|
||||
protected void addWiiUseApiListener(WiiUseApiListener listener) {
|
||||
listeners.add(WiiUseApiListener.class, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove WiiUseApiListener from the listeners list.
|
||||
*
|
||||
* @param listener
|
||||
* a WiiUseApiListener
|
||||
*/
|
||||
protected void removeWiiUseApiListener(WiiUseApiListener listener) {
|
||||
listeners.remove(WiiUseApiListener.class, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of WiiUseApiListeners.
|
||||
*
|
||||
* @return the list of WiiUseApiListeners.
|
||||
*/
|
||||
protected WiiUseApiListener[] getWiiUseApiListeners() {
|
||||
return listeners.getListeners(WiiUseApiListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiiUseApiListeners that an event occured.
|
||||
*
|
||||
* @param evt
|
||||
* GenericEvent occured
|
||||
*/
|
||||
private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
|
||||
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
||||
listener.onWiiUseApiEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the garbage collector at the end.
|
||||
*/
|
||||
protected void finalize() throws Throwable {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
495
vendor/wiiusej/0.12b/java/wiiusej/Wiimote.java
vendored
495
vendor/wiiusej/0.12b/java/wiiusej/Wiimote.java
vendored
@@ -1,495 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej;
|
||||
|
||||
import javax.swing.event.EventListenerList;
|
||||
|
||||
import wiiusej.wiiusejevents.utils.WiiUseApiListener;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.WiimoteEvent;
|
||||
|
||||
/**
|
||||
* Class that represents a wiimote. You can register as an observer of this
|
||||
* wiimote to listen events from it. You manage it.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class Wiimote implements WiiUseApiListener {
|
||||
|
||||
private int id = -1;// wiimote id
|
||||
|
||||
private EventListenerList listeners = new EventListenerList();
|
||||
|
||||
private WiiUseApiManager manager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param idd
|
||||
* id of the wiimote
|
||||
* @param manager
|
||||
* manager wo built it.
|
||||
*/
|
||||
public Wiimote(int idd, WiiUseApiManager manager) {
|
||||
id = idd;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique id of the wiimote.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect this wiimote.
|
||||
*/
|
||||
public void disconnect() {
|
||||
deactivateIRTRacking();
|
||||
deactivateMotionSensing();
|
||||
deactivateRumble();
|
||||
manager.closeConnection(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the rumble.
|
||||
*/
|
||||
public void activateRumble() {
|
||||
manager.activateRumble(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate the rumble.
|
||||
*/
|
||||
public void deactivateRumble() {
|
||||
manager.deactivateRumble(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate IR Tracking.
|
||||
*/
|
||||
public void activateIRTRacking() {
|
||||
manager.activateIRTRacking(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate IR Tracking.
|
||||
*/
|
||||
public void deactivateIRTRacking() {
|
||||
manager.deactivateIRTRacking(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate motion sensing.
|
||||
*/
|
||||
public void activateMotionSensing() {
|
||||
manager.activateMotionSensing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate motion sensing.
|
||||
*/
|
||||
public void deactivateMotionSensing() {
|
||||
manager.deactivateMotionSensing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate smoothing.
|
||||
*/
|
||||
public void activateSmoothing() {
|
||||
manager.activateSmoothing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate smoothing.
|
||||
*/
|
||||
public void deactivateSmoothing() {
|
||||
manager.deactivateSmoothing(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate continuous.
|
||||
*/
|
||||
public void activateContinuous() {
|
||||
manager.activateContinuous(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate continuous.
|
||||
*/
|
||||
public void deactivateContinuous() {
|
||||
manager.deactivateContinuous(id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set leds status.
|
||||
*
|
||||
* @param l1
|
||||
* status of led1. True : ON, False : OFF
|
||||
* @param l2
|
||||
* status of led2. True : ON, False : OFF
|
||||
* @param l3
|
||||
* status of led3. True : ON, False : OFF
|
||||
* @param l4
|
||||
* status of led4. True : ON, False : OFF
|
||||
*/
|
||||
public void setLeds(boolean l1, boolean l2, boolean l3, boolean l4) {
|
||||
manager.setLeds(id, l1, l2, l3, l4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the orientation threshold (minimum angle between two degrees with
|
||||
* accelerometer).
|
||||
*
|
||||
* @param th
|
||||
* threshold in degrees
|
||||
*/
|
||||
public void setOrientationThreshold(float th) {
|
||||
manager.setOrientationThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the acceleration threshold(minimum angle between two degrees with
|
||||
* accelerometer).
|
||||
*
|
||||
* @param th
|
||||
* threshold
|
||||
*/
|
||||
public void setAccelerationThreshold(int th) {
|
||||
manager.setAccelerationThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alpha smoothing value.
|
||||
*
|
||||
* @param th
|
||||
* threshold
|
||||
*/
|
||||
public void setAlphaSmoothingValue(float th) {
|
||||
manager.setAlphaSmoothing(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the screen aspect ratio to be considered as 4/3.
|
||||
*/
|
||||
public void setScreenAspectRatio43() {
|
||||
manager.setScreenAspectRatio43(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the screen aspect ratio to be considered as 16/9.
|
||||
*/
|
||||
public void setScreenAspectRatio169() {
|
||||
manager.setScreenAspectRatio169(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sensor bar to be considered above the screen.
|
||||
*/
|
||||
public void setSensorBarAboveScreen() {
|
||||
manager.setSensorBarAboveScreen(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sensor bar to be considered below the screen.
|
||||
*/
|
||||
public void setSensorBarBelowScreen() {
|
||||
manager.setSensorBarBelowScreen(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the screen resolution of the you are pointing at with your wiimote.
|
||||
*
|
||||
* @param x
|
||||
* x resolution.
|
||||
* @param y
|
||||
* y resolution.
|
||||
*/
|
||||
public void setVirtualResolution(int x, int y) {
|
||||
manager.setVirtualResolution(id, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nunchuk orientation threshold for the given id. (minimum angle
|
||||
* between two events)
|
||||
*
|
||||
* @param th
|
||||
* threshold in degrees.
|
||||
*/
|
||||
public void setNunchukOrientationThreshold(float th) {
|
||||
manager.setNunchukOrientationThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nunchuk acceleration threshold for the given id. (minimum angle
|
||||
* between two events)
|
||||
*
|
||||
* @param th
|
||||
* threshold.
|
||||
*/
|
||||
public void setNunchukAccelerationThreshold(int th) {
|
||||
manager.setNunchukAccelerationThreshold(id, th);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to resync the wiimote by starting a new handshake.
|
||||
*/
|
||||
public void reSync() {
|
||||
manager.reSync(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask for the status of the wiimote. The result will be received in a
|
||||
* status event object. Implements onStatusEvent on wiimote listener to get
|
||||
* it.
|
||||
*/
|
||||
public void getStatus() {
|
||||
manager.getStatus(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the normal and expansion handshake timeouts for this wiimote. Normal
|
||||
* time out is for classic polling. The expansion timeout is used when an
|
||||
* expansion is detected until the expansion successfully handshakes.
|
||||
*
|
||||
* @param normalTimeout
|
||||
* The timeout in milliseconds for a normal read.
|
||||
* @param expansionTimeout
|
||||
* The timeout in millisecondsd to wait for an expansion
|
||||
* handshake.
|
||||
*/
|
||||
public void setTimeout(short normalTimeout, short expansionTimeout) {
|
||||
manager.setTimeout(id, normalTimeout, expansionTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IR sensitivity.
|
||||
*
|
||||
* @param level
|
||||
* 1-5, same as Wii system sensitivity setting. If the level is <
|
||||
* 1, then level will be set to 1. If the level is > 5, then
|
||||
* level will be set to 5.
|
||||
*/
|
||||
public void setIrSensitivity(int level) {
|
||||
manager.setIrSensitivity(id, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called when a WiiUseApiEvent occurs.
|
||||
*
|
||||
* @param e
|
||||
* the WiiUseApiEvent.
|
||||
*/
|
||||
public void onWiiUseApiEvent(WiiUseApiEvent e) {
|
||||
if (e.getWiimoteId() == id) {
|
||||
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT) {
|
||||
notifyWiiMoteEventListeners((WiimoteEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT) {
|
||||
notifyStatusEventListeners((StatusEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
|
||||
notifyDisconnectionEventListeners((DisconnectionEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED) {
|
||||
notifyNunchukInsertedEventListeners((NunchukInsertedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED) {
|
||||
notifyNunchukRemovedEventListeners((NunchukRemovedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED) {
|
||||
notifyGuitarHeroInsertedEventListeners((GuitarHeroInsertedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED) {
|
||||
notifyGuitarHeroRemovedEventListeners((GuitarHeroRemovedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED) {
|
||||
notifyClassicControllerInsertedEventListeners((ClassicControllerInsertedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED) {
|
||||
notifyClassicControllerRemovedEventListeners((ClassicControllerRemovedEvent) e);
|
||||
}
|
||||
/*
|
||||
* events not managed yet || e.getEventType() == WIIUSE_READ_DATA
|
||||
* WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED || e.getEventType() ==
|
||||
* WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED || e.getEventType() ==
|
||||
* WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED ||
|
||||
* e.getEventType() ==
|
||||
* WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a WiimoteListener to the listeners list.
|
||||
*
|
||||
* @param listener
|
||||
* a WiimoteListener
|
||||
*/
|
||||
public void addWiiMoteEventListeners(WiimoteListener listener) {
|
||||
listeners.add(WiimoteListener.class, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a WiimoteListener from the listeners list.
|
||||
*
|
||||
* @param listener
|
||||
* a WiimoteListener
|
||||
*/
|
||||
public void removeWiiMoteEventListeners(WiimoteListener listener) {
|
||||
listeners.remove(WiimoteListener.class, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of WiimoteListener.
|
||||
*
|
||||
* @return the list of WiimoteListener.
|
||||
*/
|
||||
public WiimoteListener[] getWiiMoteEventListeners() {
|
||||
return listeners.getListeners(WiimoteListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListeners that an event occured. Notify in first the
|
||||
* listeners for Buttons Events. In second the listeners for IR Events. In
|
||||
* third the listeners for Motion sensing events.
|
||||
*
|
||||
* @param evt
|
||||
* GenericEvent occured
|
||||
*/
|
||||
private void notifyWiiMoteEventListeners(WiimoteEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onButtonsEvent(evt.getButtonsEvent());
|
||||
if (evt.isThereIrEvent()) {
|
||||
listener.onIrEvent(evt.getIREvent());
|
||||
}
|
||||
if (evt.isThereMotionSensingEvent()) {
|
||||
listener.onMotionSensingEvent(evt.getMotionSensingEvent());
|
||||
}
|
||||
if (evt.isThereExpansionEvent()) {
|
||||
listener.onExpansionEvent(evt.getExpansionEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a status event occured.
|
||||
*
|
||||
* @param evt
|
||||
* status event occured
|
||||
*/
|
||||
private void notifyStatusEventListeners(StatusEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onStatusEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a disconnection event occured.
|
||||
*
|
||||
* @param evt
|
||||
* disconnection event occured
|
||||
*/
|
||||
private void notifyDisconnectionEventListeners(DisconnectionEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onDisconnectionEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a NunchukInserted Event occured.
|
||||
*
|
||||
* @param evt
|
||||
* NunchukInserted Event occured
|
||||
*/
|
||||
private void notifyNunchukInsertedEventListeners(NunchukInsertedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onNunchukInsertedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a NunchukRemoved Event occured.
|
||||
*
|
||||
* @param evt
|
||||
* NunchukRemoved Event occured
|
||||
*/
|
||||
private void notifyNunchukRemovedEventListeners(NunchukRemovedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onNunchukRemovedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a GuitarHeroInserted Event occured.
|
||||
*
|
||||
* @param evt
|
||||
* GuitarHeroInserted Event occured
|
||||
*/
|
||||
private void notifyGuitarHeroInsertedEventListeners(GuitarHeroInsertedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onGuitarHeroInsertedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a GuitarHeroRemoved Event occured.
|
||||
*
|
||||
* @param evt
|
||||
* GuitarHeroRemoved Event occured
|
||||
*/
|
||||
private void notifyGuitarHeroRemovedEventListeners(GuitarHeroRemovedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onGuitarHeroRemovedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a ClassicControllerInserted Event occured.
|
||||
*
|
||||
* @param evt
|
||||
* ClassicControllerInserted Event occured
|
||||
*/
|
||||
private void notifyClassicControllerInsertedEventListeners(ClassicControllerInsertedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onClassicControllerInsertedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that a ClassicControllerRemoved Event occured.
|
||||
*
|
||||
* @param evt
|
||||
* ClassicControllerRemoved Event occured
|
||||
*/
|
||||
private void notifyClassicControllerRemovedEventListeners(ClassicControllerRemovedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onClassicControllerRemovedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wiimote with ID : " + id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.test;
|
||||
|
||||
import wiiusej.WiiUseApiManager;
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.utils.ClassicControllerButtonsEventPanel;
|
||||
import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This frame is used to display events from a classic controller.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class ClassicControllerGuiTest extends javax.swing.JFrame implements WiimoteListener {
|
||||
|
||||
private Wiimote wiimote;
|
||||
private static int MAX_SHOULDER = 100;
|
||||
|
||||
/** Creates new form ClassicControllerGuiTest */
|
||||
public ClassicControllerGuiTest(Wiimote wiimote) {
|
||||
initComponents();
|
||||
this.wiimote = wiimote;
|
||||
registerListeners();
|
||||
leftShoulderBar.setMaximum(MAX_SHOULDER);
|
||||
rightShoulderBar.setMaximum(MAX_SHOULDER);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
wiimote.addWiiMoteEventListeners(this);
|
||||
wiimote.addWiiMoteEventListeners((ClassicControllerButtonsEventPanel) classicControllerPanel);
|
||||
}
|
||||
|
||||
public void unRegisterListeners() {
|
||||
wiimote.removeWiiMoteEventListeners(this);
|
||||
wiimote.removeWiiMoteEventListeners((ClassicControllerButtonsEventPanel) classicControllerPanel);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
shouldersPanel = new javax.swing.JPanel();
|
||||
leftShoulderBar = new javax.swing.JProgressBar();
|
||||
rightShoulderBar = new javax.swing.JProgressBar();
|
||||
classicControllerPanel = new wiiusej.utils.ClassicControllerButtonsEventPanel();
|
||||
|
||||
setTitle("WiiuseJ Classic Controller Test GUI");
|
||||
setResizable(false);
|
||||
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
|
||||
|
||||
shouldersPanel.setMaximumSize(new java.awt.Dimension(350, 16));
|
||||
shouldersPanel.setMinimumSize(new java.awt.Dimension(350, 16));
|
||||
shouldersPanel.setPreferredSize(new java.awt.Dimension(350, 16));
|
||||
shouldersPanel.setLayout(new javax.swing.BoxLayout(shouldersPanel, javax.swing.BoxLayout.LINE_AXIS));
|
||||
shouldersPanel.add(leftShoulderBar);
|
||||
shouldersPanel.add(rightShoulderBar);
|
||||
|
||||
getContentPane().add(shouldersPanel);
|
||||
|
||||
classicControllerPanel.setMaximumSize(new java.awt.Dimension(350, 182));
|
||||
classicControllerPanel.setMinimumSize(new java.awt.Dimension(350, 182));
|
||||
|
||||
javax.swing.GroupLayout classicControllerPanelLayout = new javax.swing.GroupLayout(classicControllerPanel);
|
||||
classicControllerPanel.setLayout(classicControllerPanelLayout);
|
||||
classicControllerPanelLayout.setHorizontalGroup(
|
||||
classicControllerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 350, Short.MAX_VALUE)
|
||||
);
|
||||
classicControllerPanelLayout.setVerticalGroup(
|
||||
classicControllerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 182, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
getContentPane().add(classicControllerPanel);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
if (arg0 instanceof ClassicControllerEvent) {
|
||||
ClassicControllerEvent classicController = (ClassicControllerEvent) arg0;
|
||||
float leftShoulder = classicController.getLeftShoulder();
|
||||
float rightShoulder = classicController.getRightShoulder();
|
||||
leftShoulderBar.setValue(Math.round(leftShoulder * MAX_SHOULDER));
|
||||
rightShoulderBar.setValue(Math.round(rightShoulder * MAX_SHOULDER));
|
||||
}
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
|
||||
ClassicControllerGuiTest gui = null;
|
||||
if (wiimotes.length > 0) {
|
||||
gui = new ClassicControllerGuiTest(wiimotes[0]);
|
||||
}
|
||||
gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE);
|
||||
gui.setVisible(true);
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel classicControllerPanel;
|
||||
private javax.swing.JProgressBar leftShoulderBar;
|
||||
private javax.swing.JProgressBar rightShoulderBar;
|
||||
private javax.swing.JPanel shouldersPanel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.test;
|
||||
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import wiiusej.WiiUseApiManager;
|
||||
|
||||
/**
|
||||
* This class is used to close wiiusej cleanly.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class CloseGuiTestCleanly implements WindowListener {
|
||||
|
||||
public void windowOpened(WindowEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void windowClosing(WindowEvent e) {
|
||||
WiiUseApiManager.definitiveShutdown();
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void windowIconified(WindowEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* GuitarHeroGUITest.java
|
||||
*
|
||||
* Created on 12 juin 2008, 23:10
|
||||
*/
|
||||
package wiiusej.test;
|
||||
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This frame is used to display events from a Guitar Hero 3.
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GuitarHero3GuiTest extends javax.swing.JFrame implements WiimoteListener {
|
||||
|
||||
private Wiimote wiimote;
|
||||
private static int MAX_WHAMMY_BAR = 100;
|
||||
|
||||
/** Creates new form GuitarHeroGUITest */
|
||||
public GuitarHero3GuiTest(Wiimote wiimote) {
|
||||
initComponents();
|
||||
this.wiimote = wiimote;
|
||||
whammyProgressBar.setMaximum(MAX_WHAMMY_BAR);
|
||||
registerListeners();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
wiimote.addWiiMoteEventListeners(this);
|
||||
//register panel buttons
|
||||
wiimote.addWiiMoteEventListeners(guitarHero3ButtonsEventPanel);
|
||||
//register joystick panel
|
||||
wiimote.addWiiMoteEventListeners(guitarHero3JoystickPanel);
|
||||
}
|
||||
|
||||
public void unRegisterListeners() {
|
||||
wiimote.removeWiiMoteEventListeners(this);
|
||||
wiimote.removeWiiMoteEventListeners(guitarHero3ButtonsEventPanel);
|
||||
wiimote.removeWiiMoteEventListeners(guitarHero3JoystickPanel);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
buttonsEventPanel = new javax.swing.JPanel();
|
||||
guitarHero3ButtonsEventPanel = new wiiusej.utils.GuitarHero3ButtonsEventPanel();
|
||||
bottomPanel = new javax.swing.JPanel();
|
||||
guitarHero3JoystickPanel = new wiiusej.utils.GuitarHeroJoystickEventPanel();
|
||||
whammyProgressBar = new javax.swing.JProgressBar();
|
||||
|
||||
setTitle("WiiuseJ Guitar Hero 3 Test GUI");
|
||||
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
|
||||
|
||||
buttonsEventPanel.setBackground(new java.awt.Color(0, 0, 0));
|
||||
|
||||
javax.swing.GroupLayout buttonsEventPanelLayout = new javax.swing.GroupLayout(buttonsEventPanel);
|
||||
buttonsEventPanel.setLayout(buttonsEventPanelLayout);
|
||||
buttonsEventPanelLayout.setHorizontalGroup(
|
||||
buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 526, Short.MAX_VALUE)
|
||||
.addGroup(buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(buttonsEventPanelLayout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(guitarHero3ButtonsEventPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
);
|
||||
buttonsEventPanelLayout.setVerticalGroup(
|
||||
buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 96, Short.MAX_VALUE)
|
||||
.addGroup(buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(buttonsEventPanelLayout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(guitarHero3ButtonsEventPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
);
|
||||
|
||||
getContentPane().add(buttonsEventPanel);
|
||||
|
||||
bottomPanel.setBackground(new java.awt.Color(0, 0, 0));
|
||||
bottomPanel.setLayout(new javax.swing.BoxLayout(bottomPanel, javax.swing.BoxLayout.X_AXIS));
|
||||
bottomPanel.add(guitarHero3JoystickPanel);
|
||||
|
||||
whammyProgressBar.setBackground(new java.awt.Color(255, 255, 255));
|
||||
whammyProgressBar.setForeground(new java.awt.Color(255, 0, 255));
|
||||
bottomPanel.add(whammyProgressBar);
|
||||
|
||||
getContentPane().add(bottomPanel);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
if (arg0 instanceof GuitarHeroEvent) {
|
||||
GuitarHeroEvent guitar = (GuitarHeroEvent) arg0;
|
||||
//move progress bar for whammy bar
|
||||
whammyProgressBar.setValue(Math.round(MAX_WHAMMY_BAR*guitar.getWhammyBar()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel bottomPanel;
|
||||
private javax.swing.JPanel buttonsEventPanel;
|
||||
private wiiusej.utils.GuitarHero3ButtonsEventPanel guitarHero3ButtonsEventPanel;
|
||||
private wiiusej.utils.GuitarHeroJoystickEventPanel guitarHero3JoystickPanel;
|
||||
private javax.swing.JProgressBar whammyProgressBar;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
45
vendor/wiiusej/0.12b/java/wiiusej/test/Main.java
vendored
45
vendor/wiiusej/0.12b/java/wiiusej/test/Main.java
vendored
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.test;
|
||||
|
||||
import wiiusej.WiiUseApiManager;
|
||||
import wiiusej.Wiimote;
|
||||
|
||||
/**
|
||||
* Main Class to launch WiiuseJ GUI Test.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
|
||||
WiiuseJGuiTest gui = null;
|
||||
if (wiimotes.length > 0) {
|
||||
gui = new WiiuseJGuiTest(wiimotes[0]);
|
||||
} else {
|
||||
gui = new WiiuseJGuiTest();
|
||||
}
|
||||
gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE);
|
||||
gui.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,450 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.test;
|
||||
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.utils.AccelerationExpansionEventPanel;
|
||||
import wiiusej.utils.AccelerationPanel;
|
||||
import wiiusej.utils.GForceExpansionEventPanel;
|
||||
import wiiusej.utils.GForcePanel;
|
||||
import wiiusej.utils.NunchukJoystickEventPanel;
|
||||
import wiiusej.utils.OrientationExpansionEventPanel;
|
||||
import wiiusej.utils.OrientationPanel;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukButtonsEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This frame is used to display events from a nunchuk.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class NunchukGuiTest extends javax.swing.JFrame implements
|
||||
WiimoteListener {
|
||||
|
||||
private Wiimote wiimote;
|
||||
private boolean isThresholdsRequested = true;
|
||||
|
||||
/** Creates new form NunchukGuiTest */
|
||||
public NunchukGuiTest(Wiimote wiimote) {
|
||||
initComponents();
|
||||
this.wiimote = wiimote;
|
||||
registerListeners();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
wiimote.addWiiMoteEventListeners(this);
|
||||
wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel);
|
||||
wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel);
|
||||
wiimote
|
||||
.addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
|
||||
wiimote
|
||||
.addWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
|
||||
}
|
||||
|
||||
public void unRegisterListeners() {
|
||||
wiimote
|
||||
.removeWiiMoteEventListeners((OrientationPanel) orientationPanel);
|
||||
wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel);
|
||||
wiimote
|
||||
.removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
|
||||
wiimote
|
||||
.removeWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
|
||||
wiimote.removeWiiMoteEventListeners(this);
|
||||
}
|
||||
|
||||
public void requestThresholdsUpdate() {
|
||||
isThresholdsRequested = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
topPanels = new javax.swing.JPanel();
|
||||
joystickEventsPanel = new NunchukJoystickEventPanel();
|
||||
motionSensingEventsPanel = new javax.swing.JPanel();
|
||||
motionSensingEventsTabbedPanels = new javax.swing.JTabbedPane();
|
||||
rawAccelerationPanel = new AccelerationExpansionEventPanel();
|
||||
orientationPanel = new OrientationExpansionEventPanel();
|
||||
gForcePanel = new GForceExpansionEventPanel();
|
||||
setNunchukValuesPanel = new javax.swing.JPanel();
|
||||
nunchukButtonsEventPanel = new javax.swing.JPanel();
|
||||
cButton = new javax.swing.JButton();
|
||||
zButton = new javax.swing.JButton();
|
||||
nunchukOrientationPanel = new javax.swing.JPanel();
|
||||
nunchukOrientationTextField = new javax.swing.JTextField();
|
||||
nunchukOrientationButton = new javax.swing.JButton();
|
||||
nunchukAccelerationPanel = new javax.swing.JPanel();
|
||||
nunchukAccelerationTextField = new javax.swing.JTextField();
|
||||
nunchukAccelerationButton = new javax.swing.JButton();
|
||||
messagePanel = new javax.swing.JPanel();
|
||||
messageText = new javax.swing.JLabel();
|
||||
|
||||
setTitle("WiiuseJ Nunchuk Test GUI");
|
||||
setMinimumSize(new java.awt.Dimension(400, 400));
|
||||
getContentPane().setLayout(
|
||||
new javax.swing.BoxLayout(getContentPane(),
|
||||
javax.swing.BoxLayout.Y_AXIS));
|
||||
|
||||
topPanels.setMinimumSize(new java.awt.Dimension(400, 200));
|
||||
topPanels.setPreferredSize(new java.awt.Dimension(400, 200));
|
||||
topPanels.setLayout(new javax.swing.BoxLayout(topPanels,
|
||||
javax.swing.BoxLayout.LINE_AXIS));
|
||||
|
||||
joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0));
|
||||
joystickEventsPanel.setBorder(javax.swing.BorderFactory
|
||||
.createTitledBorder(new javax.swing.border.LineBorder(
|
||||
new java.awt.Color(51, 153, 0), 2, true),
|
||||
"Joystick View",
|
||||
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
|
||||
javax.swing.border.TitledBorder.DEFAULT_POSITION,
|
||||
new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(
|
||||
204, 102, 0)));
|
||||
joystickEventsPanel.setToolTipText("JoystickEvent");
|
||||
joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200));
|
||||
|
||||
javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout(
|
||||
joystickEventsPanel);
|
||||
joystickEventsPanel.setLayout(joystickEventsPanelLayout);
|
||||
joystickEventsPanelLayout.setHorizontalGroup(joystickEventsPanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 601, Short.MAX_VALUE));
|
||||
joystickEventsPanelLayout.setVerticalGroup(joystickEventsPanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 174, Short.MAX_VALUE));
|
||||
|
||||
topPanels.add(joystickEventsPanel);
|
||||
joystickEventsPanel.getAccessibleContext()
|
||||
.setAccessibleName("Joystick");
|
||||
|
||||
motionSensingEventsPanel
|
||||
.setMinimumSize(new java.awt.Dimension(200, 200));
|
||||
|
||||
rawAccelerationPanel.setToolTipText("Nunchuk MotionSensingEvent");
|
||||
|
||||
javax.swing.GroupLayout rawAccelerationPanelLayout = new javax.swing.GroupLayout(
|
||||
rawAccelerationPanel);
|
||||
rawAccelerationPanel.setLayout(rawAccelerationPanelLayout);
|
||||
rawAccelerationPanelLayout
|
||||
.setHorizontalGroup(rawAccelerationPanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 597, Short.MAX_VALUE));
|
||||
rawAccelerationPanelLayout.setVerticalGroup(rawAccelerationPanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 175, Short.MAX_VALUE));
|
||||
|
||||
motionSensingEventsTabbedPanels.addTab("RawAcceleration",
|
||||
rawAccelerationPanel);
|
||||
|
||||
javax.swing.GroupLayout orientationPanelLayout = new javax.swing.GroupLayout(
|
||||
orientationPanel);
|
||||
orientationPanel.setLayout(orientationPanelLayout);
|
||||
orientationPanelLayout.setHorizontalGroup(orientationPanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 597, Short.MAX_VALUE));
|
||||
orientationPanelLayout.setVerticalGroup(orientationPanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 175, Short.MAX_VALUE));
|
||||
|
||||
motionSensingEventsTabbedPanels.addTab("Orientation", orientationPanel);
|
||||
|
||||
javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(
|
||||
gForcePanel);
|
||||
gForcePanel.setLayout(gForcePanelLayout);
|
||||
gForcePanelLayout.setHorizontalGroup(gForcePanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 597, Short.MAX_VALUE));
|
||||
gForcePanelLayout.setVerticalGroup(gForcePanelLayout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 175, Short.MAX_VALUE));
|
||||
|
||||
motionSensingEventsTabbedPanels.addTab("GForce", gForcePanel);
|
||||
|
||||
javax.swing.GroupLayout motionSensingEventsPanelLayout = new javax.swing.GroupLayout(
|
||||
motionSensingEventsPanel);
|
||||
motionSensingEventsPanel.setLayout(motionSensingEventsPanelLayout);
|
||||
motionSensingEventsPanelLayout
|
||||
.setHorizontalGroup(motionSensingEventsPanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(motionSensingEventsTabbedPanels,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE, 602,
|
||||
Short.MAX_VALUE));
|
||||
motionSensingEventsPanelLayout
|
||||
.setVerticalGroup(motionSensingEventsPanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(motionSensingEventsTabbedPanels,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE, 200,
|
||||
Short.MAX_VALUE));
|
||||
|
||||
topPanels.add(motionSensingEventsPanel);
|
||||
|
||||
getContentPane().add(topPanels);
|
||||
|
||||
setNunchukValuesPanel.setMinimumSize(new java.awt.Dimension(400, 200));
|
||||
setNunchukValuesPanel
|
||||
.setPreferredSize(new java.awt.Dimension(400, 200));
|
||||
setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout(
|
||||
setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS));
|
||||
|
||||
nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent");
|
||||
nunchukButtonsEventPanel
|
||||
.setMinimumSize(new java.awt.Dimension(100, 100));
|
||||
nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100,
|
||||
100));
|
||||
nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout(
|
||||
nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS));
|
||||
|
||||
cButton.setText("C");
|
||||
cButton.setMaximumSize(new java.awt.Dimension(50, 50));
|
||||
cButton.setMinimumSize(new java.awt.Dimension(50, 50));
|
||||
cButton.setPreferredSize(new java.awt.Dimension(50, 50));
|
||||
nunchukButtonsEventPanel.add(cButton);
|
||||
|
||||
zButton.setText("Z");
|
||||
zButton.setMaximumSize(new java.awt.Dimension(50, 50));
|
||||
zButton.setMinimumSize(new java.awt.Dimension(50, 50));
|
||||
zButton.setPreferredSize(new java.awt.Dimension(50, 50));
|
||||
nunchukButtonsEventPanel.add(zButton);
|
||||
|
||||
setNunchukValuesPanel.add(nunchukButtonsEventPanel);
|
||||
|
||||
nunchukOrientationTextField.setPreferredSize(new java.awt.Dimension(60,
|
||||
20));
|
||||
nunchukOrientationPanel.add(nunchukOrientationTextField);
|
||||
|
||||
nunchukOrientationButton.setText("Set Orientation Threshold");
|
||||
nunchukOrientationButton
|
||||
.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mousePressed(java.awt.event.MouseEvent evt) {
|
||||
nunchukOrientationButtonMousePressed(evt);
|
||||
}
|
||||
});
|
||||
nunchukOrientationPanel.add(nunchukOrientationButton);
|
||||
|
||||
setNunchukValuesPanel.add(nunchukOrientationPanel);
|
||||
|
||||
nunchukAccelerationTextField.setPreferredSize(new java.awt.Dimension(
|
||||
60, 20));
|
||||
nunchukAccelerationPanel.add(nunchukAccelerationTextField);
|
||||
|
||||
nunchukAccelerationButton.setText("Set Acceleration Threshold");
|
||||
nunchukAccelerationButton
|
||||
.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mousePressed(java.awt.event.MouseEvent evt) {
|
||||
nunchukAccelerationButtonMousePressed(evt);
|
||||
}
|
||||
});
|
||||
nunchukAccelerationPanel.add(nunchukAccelerationButton);
|
||||
|
||||
setNunchukValuesPanel.add(nunchukAccelerationPanel);
|
||||
|
||||
messageText.setText("Message:");
|
||||
|
||||
javax.swing.GroupLayout messagePanelLayout = new javax.swing.GroupLayout(
|
||||
messagePanel);
|
||||
messagePanel.setLayout(messagePanelLayout);
|
||||
messagePanelLayout
|
||||
.setHorizontalGroup(messagePanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 1216, Short.MAX_VALUE)
|
||||
.addGroup(
|
||||
messagePanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(
|
||||
messagePanelLayout
|
||||
.createSequentialGroup()
|
||||
.addGap(0, 0,
|
||||
Short.MAX_VALUE)
|
||||
.addComponent(
|
||||
messageText)
|
||||
.addGap(0, 0,
|
||||
Short.MAX_VALUE))));
|
||||
messagePanelLayout
|
||||
.setVerticalGroup(messagePanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 34, Short.MAX_VALUE)
|
||||
.addGroup(
|
||||
messagePanelLayout
|
||||
.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(
|
||||
messagePanelLayout
|
||||
.createSequentialGroup()
|
||||
.addGap(0, 0,
|
||||
Short.MAX_VALUE)
|
||||
.addComponent(
|
||||
messageText)
|
||||
.addGap(0, 0,
|
||||
Short.MAX_VALUE))));
|
||||
|
||||
setNunchukValuesPanel.add(messagePanel);
|
||||
|
||||
getContentPane().add(setNunchukValuesPanel);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void nunchukOrientationButtonMousePressed(
|
||||
java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukOrientationButtonMousePressed
|
||||
try {
|
||||
float nb = Float.parseFloat(nunchukOrientationTextField.getText());
|
||||
wiimote.setNunchukOrientationThreshold(nb);
|
||||
messageText.setText("Nunchuk orientation threshold set to " + nb);
|
||||
} catch (NumberFormatException e) {
|
||||
messageText
|
||||
.setText("Number is not an integer, nunchuk orientation threshold not set !");
|
||||
}
|
||||
}// GEN-LAST:event_nunchukOrientationButtonMousePressed
|
||||
|
||||
private void nunchukAccelerationButtonMousePressed(
|
||||
java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukAccelerationButtonMousePressed
|
||||
try {
|
||||
int nb = Integer.parseInt(nunchukAccelerationTextField.getText());
|
||||
wiimote.setNunchukAccelerationThreshold(nb);
|
||||
messageText.setText("Nunchuk acceleration threshold set to " + nb);
|
||||
} catch (NumberFormatException e) {
|
||||
messageText
|
||||
.setText("Number is not an integer, nunchuk acceleration threshold not set !");
|
||||
}
|
||||
}// GEN-LAST:event_nunchukAccelerationButtonMousePressed
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
if (arg0 instanceof NunchukEvent) {
|
||||
NunchukEvent nunchuk = (NunchukEvent) arg0;
|
||||
NunchukButtonsEvent buttons = nunchuk.getButtonsEvent();
|
||||
|
||||
//C button
|
||||
if (buttons.isButtonCJustPressed()) {
|
||||
cButton.setEnabled(false);
|
||||
}else if (buttons.isButtonCJustReleased()) {
|
||||
cButton.setEnabled(true);
|
||||
}
|
||||
|
||||
//Z button
|
||||
if(buttons.isButtonZJustPressed()) {
|
||||
zButton.setEnabled(false);
|
||||
}else if (buttons.isButtonZJustReleased()) {
|
||||
zButton.setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
if (isThresholdsRequested) {
|
||||
MotionSensingEvent evt = nunchuk.getNunchukMotionSensingEvent();
|
||||
nunchukAccelerationTextField.setText(evt
|
||||
.getAccelerationThreshold()
|
||||
+ "");
|
||||
nunchukOrientationTextField.setText(evt
|
||||
.getOrientationThreshold()
|
||||
+ "");
|
||||
isThresholdsRequested = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton cButton;
|
||||
private javax.swing.JPanel gForcePanel;
|
||||
private javax.swing.JPanel joystickEventsPanel;
|
||||
private javax.swing.JPanel messagePanel;
|
||||
private javax.swing.JLabel messageText;
|
||||
private javax.swing.JPanel motionSensingEventsPanel;
|
||||
private javax.swing.JTabbedPane motionSensingEventsTabbedPanels;
|
||||
private javax.swing.JButton nunchukAccelerationButton;
|
||||
private javax.swing.JPanel nunchukAccelerationPanel;
|
||||
private javax.swing.JTextField nunchukAccelerationTextField;
|
||||
private javax.swing.JPanel nunchukButtonsEventPanel;
|
||||
private javax.swing.JButton nunchukOrientationButton;
|
||||
private javax.swing.JPanel nunchukOrientationPanel;
|
||||
private javax.swing.JTextField nunchukOrientationTextField;
|
||||
private javax.swing.JPanel orientationPanel;
|
||||
private javax.swing.JPanel rawAccelerationPanel;
|
||||
private javax.swing.JPanel setNunchukValuesPanel;
|
||||
private javax.swing.JPanel topPanels;
|
||||
private javax.swing.JButton zButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
389
vendor/wiiusej/0.12b/java/wiiusej/test/Tests.java
vendored
389
vendor/wiiusej/0.12b/java/wiiusej/test/Tests.java
vendored
@@ -1,389 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.test;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
import wiiusej.WiiUseApiManager;
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.values.IRSource;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This class used to test WiiuseJ in text mode.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class Tests implements WiimoteListener {
|
||||
|
||||
Robot robot;
|
||||
|
||||
private static int DISPLAY_EACH_VALUE = 1;
|
||||
private static int DUMP = 2;
|
||||
private static int MOVE_MOUSE = 3;
|
||||
private static int TEST_LEDS = 5;
|
||||
|
||||
private Wiimote wiimote;
|
||||
|
||||
int dump = DISPLAY_EACH_VALUE;
|
||||
|
||||
public Tests(Wiimote wim) {
|
||||
wiimote = wim;
|
||||
wiimote.addWiiMoteEventListeners(this);
|
||||
try {
|
||||
robot = new Robot();
|
||||
} catch (AWTException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent e) {
|
||||
if (dump == DISPLAY_EACH_VALUE) {
|
||||
// System.out.println("*********** WIIMOTE ID : "+
|
||||
// e.getWiimoteId() + " **************");
|
||||
/* button ONE */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("button one pressed");
|
||||
}
|
||||
if (e.isButtonOneHeld()) {
|
||||
System.out.println("button one held");
|
||||
}
|
||||
if (e.isButtonOneJustReleased()) {
|
||||
System.out.println("button one released");
|
||||
}
|
||||
|
||||
/* button TWO */
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("button two pressed");
|
||||
}
|
||||
if (e.isButtonTwoHeld()) {
|
||||
System.out.println("button two held");
|
||||
}
|
||||
if (e.isButtonTwoJustReleased()) {
|
||||
System.out.println("button two released");
|
||||
}
|
||||
|
||||
/* button A */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("button A pressed");
|
||||
}
|
||||
if (e.isButtonAHeld()) {
|
||||
System.out.println("button A held");
|
||||
}
|
||||
if (e.isButtonAJustReleased()) {
|
||||
System.out.println("button A released");
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("button B pressed");
|
||||
}
|
||||
if (e.isButtonBHeld()) {
|
||||
System.out.println("button B held");
|
||||
}
|
||||
if (e.isButtonBJustReleased()) {
|
||||
System.out.println("button B released");
|
||||
}
|
||||
|
||||
/* button LEFT */
|
||||
if (e.isButtonLeftJustPressed()) {
|
||||
System.out.println("button Left pressed");
|
||||
}
|
||||
if (e.isButtonLeftHeld()) {
|
||||
System.out.println("button Left held");
|
||||
}
|
||||
if (e.isButtonLeftJustReleased()) {
|
||||
System.out.println("button Left released");
|
||||
}
|
||||
|
||||
/* button RIGHT */
|
||||
if (e.isButtonRightJustPressed()) {
|
||||
System.out.println("button Right pressed");
|
||||
}
|
||||
if (e.isButtonRightHeld()) {
|
||||
System.out.println("button Right held");
|
||||
}
|
||||
if (e.isButtonRightJustReleased()) {
|
||||
System.out.println("button Right released");
|
||||
}
|
||||
|
||||
/* button UP */
|
||||
if (e.isButtonUpJustPressed()) {
|
||||
System.out.println("button UP pressed");
|
||||
}
|
||||
if (e.isButtonUpHeld()) {
|
||||
System.out.println("button UP held");
|
||||
}
|
||||
if (e.isButtonUpJustReleased()) {
|
||||
System.out.println("button UP released");
|
||||
}
|
||||
|
||||
/* button DOWN */
|
||||
if (e.isButtonDownJustPressed()) {
|
||||
System.out.println("button DOWN pressed");
|
||||
}
|
||||
if (e.isButtonDownHeld()) {
|
||||
System.out.println("button DOWN held");
|
||||
}
|
||||
if (e.isButtonDownJustReleased()) {
|
||||
System.out.println("button DOWN released");
|
||||
}
|
||||
|
||||
/* button MINUS */
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("button MINUS pressed");
|
||||
}
|
||||
if (e.isButtonMinusHeld()) {
|
||||
System.out.println("button MINUS held");
|
||||
}
|
||||
if (e.isButtonMinusJustReleased()) {
|
||||
System.out.println("button MINUS released");
|
||||
}
|
||||
|
||||
/* button PLUS */
|
||||
if (e.isButtonPlusJustPressed()) {
|
||||
System.out.println("button PLUS pressed");
|
||||
}
|
||||
if (e.isButtonPlusHeld()) {
|
||||
System.out.println("button PLUS held");
|
||||
}
|
||||
if (e.isButtonPlusJustReleased()) {
|
||||
System.out.println("button PLUS released");
|
||||
}
|
||||
|
||||
/* button HOME */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("button HOME pressed");
|
||||
}
|
||||
if (e.isButtonHomeHeld()) {
|
||||
System.out.println("button HOME held");
|
||||
}
|
||||
if (e.isButtonHomeJustReleased()) {
|
||||
System.out.println("button HOME released");
|
||||
}
|
||||
|
||||
/* get status */
|
||||
if (e.isButtonUpJustPressed()) {
|
||||
wiimote.getStatus();
|
||||
}
|
||||
|
||||
/* Activate rumble */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("Rumble Activated");
|
||||
wiimote.activateRumble();
|
||||
}
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("Rumble Deactivated");
|
||||
wiimote.deactivateRumble();
|
||||
}
|
||||
|
||||
/* Activate IR Tracking */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("IR Activated");
|
||||
wiimote.activateIRTRacking();
|
||||
}
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("IR Deactivated");
|
||||
wiimote.deactivateIRTRacking();
|
||||
}
|
||||
|
||||
/* Activate Motion sensing */
|
||||
if (e.isButtonPlusJustPressed()) {
|
||||
System.out.println("Motion sensing Activated");
|
||||
wiimote.activateMotionSensing();
|
||||
}
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("Motion sensing Deactivated");
|
||||
wiimote.deactivateMotionSensing();
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
wiimote.disconnect();
|
||||
WiiUseApiManager.definitiveShutdown();
|
||||
}
|
||||
|
||||
} else if (dump == DUMP) {
|
||||
System.out.println(e);
|
||||
/* Activate all */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("IR, rumble and motion sensing Activated");
|
||||
wiimote.activateIRTRacking();
|
||||
wiimote.activateMotionSensing();
|
||||
wiimote.activateRumble();
|
||||
}
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("IR, rumble and motion sensing Deactivated");
|
||||
wiimote.deactivateIRTRacking();
|
||||
wiimote.deactivateMotionSensing();
|
||||
wiimote.deactivateRumble();
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
wiimote.disconnect();
|
||||
}
|
||||
} else if (dump == MOVE_MOUSE) {
|
||||
/* Activate IR Tracking */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("IR Activated");
|
||||
wiimote.activateIRTRacking();
|
||||
}
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("IR Deactivated");
|
||||
wiimote.deactivateIRTRacking();
|
||||
}
|
||||
|
||||
/* button A */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
}
|
||||
if (e.isButtonAJustReleased()) {
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (e.isButtonBJustPressed()) {
|
||||
robot.mousePress(InputEvent.BUTTON2_MASK);
|
||||
}
|
||||
if (e.isButtonBJustReleased()) {
|
||||
robot.mouseRelease(InputEvent.BUTTON2_MASK);
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
wiimote.disconnect();
|
||||
}
|
||||
} else if (dump == TEST_LEDS) {
|
||||
wiimote.activateMotionSensing();
|
||||
if (e.isButtonUpJustPressed()) {
|
||||
wiimote.setLeds(true, false, false, false);
|
||||
}
|
||||
if (e.isButtonDownJustPressed()) {
|
||||
wiimote.setLeds(false, true, false, false);
|
||||
}
|
||||
if (e.isButtonLeftJustPressed()) {
|
||||
wiimote.setLeds(false, false, true, false);
|
||||
}
|
||||
if (e.isButtonRightJustPressed()) {
|
||||
wiimote.setLeds(false, false, false, true);
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
wiimote.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent e) {
|
||||
if (dump == MOVE_MOUSE) {
|
||||
IRSource[] list = e.getIRPoints();
|
||||
if (list.length > 0) {
|
||||
int x1 = (int) list[0].getX();
|
||||
int y1 = (int) list[0].getY();
|
||||
|
||||
int mousex = (int) Math.round(((double) x1 / 1024.0) * 1280.0);
|
||||
int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0);
|
||||
robot.mouseMove(mousex, mousey);
|
||||
}
|
||||
} else {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent e) {
|
||||
/* display motion sensing */
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent e) {
|
||||
// Display status variables
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent e) {
|
||||
System.out.println(" wiimote " + e.getWiimoteId()
|
||||
+ "has been disconnected !!");
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
|
||||
if (wiimotes.length > 0) {
|
||||
System.out.println(wiimotes[0]);
|
||||
new Tests(wiimotes[0]);
|
||||
} else {
|
||||
System.out.println("No wiimotes found !!!");
|
||||
}
|
||||
|
||||
// java.util.Timer timer = new java.util.Timer();
|
||||
// timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Acceleration in a MotionSensingEvent from an expansion.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class AccelerationExpansionEventPanel extends AccelerationPanel {
|
||||
|
||||
@Override
|
||||
public RawAcceleration getRawAccelerationValue(GenericEvent e) {
|
||||
if (e instanceof NunchukEvent) {
|
||||
return ((NunchukEvent) e).getNunchukMotionSensingEvent()
|
||||
.getRawAcceleration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,303 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to watch raw acceleration values from a
|
||||
* MotionSensingEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class AccelerationPanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Color xColor = Color.RED;
|
||||
private Color yColor = Color.GREEN;
|
||||
private Color zColor = Color.BLUE;
|
||||
private Color backgroundColor = Color.WHITE;
|
||||
private Color lineColor = Color.BLACK;
|
||||
private ArrayList<RawAcceleration> values = new ArrayList<RawAcceleration>();
|
||||
|
||||
/** Creates new form AccelerationPanel */
|
||||
public AccelerationPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to choose the colors used by the AccelerationPanel.
|
||||
*
|
||||
* @param bgColor
|
||||
* background color.
|
||||
* @param xColor
|
||||
* x color.
|
||||
* @param yColor
|
||||
* y color.
|
||||
* @param zColor
|
||||
* z color.
|
||||
* @param lColor
|
||||
* line color.
|
||||
*/
|
||||
public AccelerationPanel(Color bgColor, Color xColor, Color yColor,
|
||||
Color zColor, Color lColor) {
|
||||
backgroundColor = bgColor;
|
||||
this.xColor = xColor;
|
||||
this.yColor = yColor;
|
||||
this.zColor = zColor;
|
||||
lineColor = lColor;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw medium line
|
||||
int yLine = getHeight() - 25;
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yLine, getWidth(), yLine);
|
||||
|
||||
RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]);
|
||||
|
||||
double unit = yLine / 255.0;
|
||||
int previousX = 0;
|
||||
int previousY = 0;
|
||||
int previousZ = 0;
|
||||
// draw curves
|
||||
for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
|
||||
RawAcceleration acceleration = valuesArray[i];
|
||||
// draw X
|
||||
g2.setPaint(xColor);
|
||||
int yDelta = (int) Math.round(unit * acceleration.getX());
|
||||
int y = -1 * yDelta + yLine;
|
||||
g2.drawLine(i - 1, previousX, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousX = y;
|
||||
// draw Y
|
||||
g2.setPaint(yColor);
|
||||
yDelta = (int) Math.round(unit * acceleration.getY());
|
||||
y = -1 * yDelta + yLine;
|
||||
g2.drawLine(i - 1, previousY, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousY = y;
|
||||
// draw Z
|
||||
g2.setPaint(zColor);
|
||||
yDelta = (int) Math.round(unit * acceleration.getZ());
|
||||
y = -1 * yDelta + yLine;
|
||||
g2.drawLine(i - 1, previousZ, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousZ = y;
|
||||
}
|
||||
|
||||
// draw legend
|
||||
g2.setPaint(xColor);
|
||||
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
|
||||
g2.setPaint(yColor);
|
||||
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
|
||||
g2.setPaint(zColor);
|
||||
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawString("X", 30, getHeight() - 5);
|
||||
g2.drawString("Y", 85, getHeight() - 5);
|
||||
g2.drawString("Z", 145, getHeight() - 5);
|
||||
g2.drawString("0", 2, yLine - 5);
|
||||
g2.drawString("255", 2, 15);
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// Clear points.
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
private void draw(GenericEvent arg0) {
|
||||
if (values.size() >= getWidth()) {
|
||||
// if there are as many values as pixels in the width
|
||||
// clear points
|
||||
values.clear();
|
||||
}
|
||||
RawAcceleration rawAcceleration = getRawAccelerationValue(arg0);
|
||||
if (rawAcceleration != null)
|
||||
values.add(rawAcceleration);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public abstract RawAcceleration getRawAccelerationValue(GenericEvent e);
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getLineColor() {
|
||||
return lineColor;
|
||||
}
|
||||
|
||||
public Color getXColor() {
|
||||
return xColor;
|
||||
}
|
||||
|
||||
public Color getYColor() {
|
||||
return yColor;
|
||||
}
|
||||
|
||||
public Color getZColor() {
|
||||
return zColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setLineColor(Color lineColor) {
|
||||
this.lineColor = lineColor;
|
||||
}
|
||||
|
||||
public void setXColor(Color xColor) {
|
||||
this.xColor = xColor;
|
||||
}
|
||||
|
||||
public void setYColor(Color yColor) {
|
||||
this.yColor = yColor;
|
||||
}
|
||||
|
||||
public void setZColor(Color zColor) {
|
||||
this.zColor = zColor;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Acceleration in a MotionSensingEvent from a wiimote.
|
||||
* @author guiguito
|
||||
*/
|
||||
public class AccelerationWiimoteEventPanel extends AccelerationPanel {
|
||||
|
||||
@Override
|
||||
public RawAcceleration getRawAccelerationValue(GenericEvent e) {
|
||||
if (e instanceof MotionSensingEvent) {
|
||||
return ((MotionSensingEvent) e).getRawAcceleration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,382 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to see what buttons are pressed on the wiimote. It
|
||||
* displays the result of last ButtonsEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class ButtonsEventPanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Image wiimoteImage;// image for double buffering
|
||||
private WiimoteButtonsEvent buttons;
|
||||
private Color pressedColor = Color.RED;
|
||||
private Color heldColor = Color.ORANGE;
|
||||
private Color releasedColor = Color.YELLOW;
|
||||
private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13);
|
||||
|
||||
/**
|
||||
* Default constructor. Red : button just pressed. Orange : button held.
|
||||
* Yellow : button just released.
|
||||
*/
|
||||
public ButtonsEventPanel() {
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
java.net.URL url = ButtonsEventPanel.class
|
||||
.getResource("/img/wiimote.png");
|
||||
wiimoteImage = toolkit.createImage(url);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to set colors and shape used.
|
||||
*
|
||||
* @param pressColor
|
||||
* color of a button just pressed.
|
||||
* @param hColor
|
||||
* color of a button held.
|
||||
* @param relColor
|
||||
* color of a button just released.
|
||||
* @param sh
|
||||
* shape draw on the buttons.
|
||||
*/
|
||||
public ButtonsEventPanel(Color pressColor, Color hColor, Color relColor,
|
||||
Shape sh) {
|
||||
pressedColor = pressColor;
|
||||
heldColor = hColor;
|
||||
releasedColor = relColor;
|
||||
shape = sh;
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
wiimoteImage = toolkit.createImage("img\\wiimote.png");
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
// offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw buttons pushed
|
||||
g2.drawImage(wiimoteImage, 0, 0, this);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
if (buttons != null) {
|
||||
/* button ONE */
|
||||
if (buttons.isButtonOneJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 353);
|
||||
}
|
||||
if (buttons.isButtonOneHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 353);
|
||||
}
|
||||
if (buttons.isButtonOneJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 353);
|
||||
}
|
||||
|
||||
/* button TWO */
|
||||
if (buttons.isButtonTwoJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 395);
|
||||
}
|
||||
if (buttons.isButtonTwoHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 395);
|
||||
}
|
||||
if (buttons.isButtonTwoJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 395);
|
||||
}
|
||||
|
||||
/* button A */
|
||||
if (buttons.isButtonAJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 150);
|
||||
}
|
||||
if (buttons.isButtonAHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 150);
|
||||
}
|
||||
if (buttons.isButtonAJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 150);
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (buttons.isButtonBJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 16, 149);
|
||||
}
|
||||
if (buttons.isButtonBHeld()) {
|
||||
drawFunction(g2, heldColor, 16, 149);
|
||||
}
|
||||
if (buttons.isButtonBJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 16, 149);
|
||||
}
|
||||
|
||||
/* button LEFT */
|
||||
if (buttons.isButtonLeftJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 33, 77);
|
||||
}
|
||||
if (buttons.isButtonLeftHeld()) {
|
||||
drawFunction(g2, heldColor, 33, 77);
|
||||
}
|
||||
if (buttons.isButtonLeftJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 33, 77);
|
||||
}
|
||||
|
||||
/* button RIGHT */
|
||||
if (buttons.isButtonRightJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 73, 77);
|
||||
}
|
||||
if (buttons.isButtonRightHeld()) {
|
||||
drawFunction(g2, heldColor, 73, 77);
|
||||
}
|
||||
if (buttons.isButtonRightJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 73, 77);
|
||||
}
|
||||
|
||||
/* button UP */
|
||||
if (buttons.isButtonUpJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 54, 60);
|
||||
}
|
||||
if (buttons.isButtonUpHeld()) {
|
||||
drawFunction(g2, heldColor, 54, 60);
|
||||
}
|
||||
if (buttons.isButtonUpJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 54, 60);
|
||||
}
|
||||
|
||||
/* button DOWN */
|
||||
if (buttons.isButtonDownJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 54, 97);
|
||||
}
|
||||
if (buttons.isButtonDownHeld()) {
|
||||
drawFunction(g2, heldColor, 54, 97);
|
||||
}
|
||||
if (buttons.isButtonDownJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 54, 97);
|
||||
}
|
||||
|
||||
/* button MINUS */
|
||||
if (buttons.isButtonMinusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 20, 230);
|
||||
}
|
||||
if (buttons.isButtonMinusHeld()) {
|
||||
drawFunction(g2, heldColor, 20, 230);
|
||||
}
|
||||
if (buttons.isButtonMinusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 20, 230);
|
||||
}
|
||||
|
||||
/* button PLUS */
|
||||
if (buttons.isButtonPlusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 86, 230);
|
||||
}
|
||||
if (buttons.isButtonPlusHeld()) {
|
||||
drawFunction(g2, heldColor, 86, 230);
|
||||
}
|
||||
if (buttons.isButtonPlusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 86, 230);
|
||||
}
|
||||
|
||||
/* button HOME */
|
||||
if (buttons.isButtonHomeJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 230);
|
||||
}
|
||||
if (buttons.isButtonHomeHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 230);
|
||||
}
|
||||
if (buttons.isButtonHomeJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 230);
|
||||
}
|
||||
|
||||
buttons = null;
|
||||
}
|
||||
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to factorize code.
|
||||
*
|
||||
* @param g2
|
||||
* where to draw a shape.
|
||||
* @param col
|
||||
* color to use.
|
||||
* @param x
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates.
|
||||
*/
|
||||
private void drawFunction(Graphics2D g2, Color col, int x, int y) {
|
||||
g2.setPaint(col);
|
||||
g2.translate(x, y);
|
||||
g2.draw(shape);
|
||||
g2.fill(shape);
|
||||
g2.setTransform(new AffineTransform());
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
|
||||
buttons = arg0;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
clearView();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public Color getHeldColor() {
|
||||
return heldColor;
|
||||
}
|
||||
|
||||
public Color getPressedColor() {
|
||||
return pressedColor;
|
||||
}
|
||||
|
||||
public Color getReleasedColor() {
|
||||
return releasedColor;
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setHeldColor(Color heldColor) {
|
||||
this.heldColor = heldColor;
|
||||
}
|
||||
|
||||
public void setPressedColor(Color pressedColor) {
|
||||
this.pressedColor = pressedColor;
|
||||
}
|
||||
|
||||
public void setReleasedColor(Color releasedColor) {
|
||||
this.releasedColor = releasedColor;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
buttons = null;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -1,500 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import wiiusej.wiiusejevents.physicalevents.ClassicControllerButtonsEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to display what happens on the classic controller.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class ClassicControllerButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Image wiimoteImage;// image for double buffering
|
||||
private ClassicControllerEvent event;
|
||||
private Color pressedColor = Color.RED;
|
||||
private Color heldColor = Color.ORANGE;
|
||||
private Color releasedColor = Color.YELLOW;
|
||||
private Color joystickColor = Color.PINK;
|
||||
private Color shoulderColor = Color.BLUE;
|
||||
private Shape shapeJoystick = new java.awt.geom.Ellipse2D.Double(0, 0, 15, 15);
|
||||
private Shape shapeButton = new java.awt.geom.Ellipse2D.Double(0, 0, 20, 20);
|
||||
private static int xAmplitude = 20;
|
||||
private static int yAmplitude = 20;
|
||||
|
||||
/**
|
||||
* Default constructor. Red : button just pressed. Orange : button held.
|
||||
* Yellow : button just released.
|
||||
*/
|
||||
public ClassicControllerButtonsEventPanel() {
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
java.net.URL url = ButtonsEventPanel.class.getResource("/img/classiccontroller.png");
|
||||
wiimoteImage = toolkit.createImage(url);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to set colors and shape used.
|
||||
*
|
||||
* @param pressColor
|
||||
* color of a button just pressed.
|
||||
* @param hColor
|
||||
* color of a button held.
|
||||
* @param relColor
|
||||
* color of a button just released.
|
||||
* @param jsColor
|
||||
* color of the joysticks.
|
||||
* @param shouldColor
|
||||
* color of the shoulders.
|
||||
* @param js
|
||||
* shape drawn on the joysticks.
|
||||
* @param sh
|
||||
* shape drawn on the buttons.
|
||||
*/
|
||||
public ClassicControllerButtonsEventPanel(Color pressColor, Color hColor, Color relColor,
|
||||
Color jsColor, Color shouldColor, Shape js, Shape sh) {
|
||||
pressedColor = pressColor;
|
||||
heldColor = hColor;
|
||||
releasedColor = relColor;
|
||||
shapeButton = sh;
|
||||
shapeJoystick = js;
|
||||
joystickColor = jsColor;
|
||||
shoulderColor = shouldColor;
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
wiimoteImage = toolkit.createImage("img\\wiimote.png");
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
// offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
//draw classic controller
|
||||
g2.drawImage(wiimoteImage, 0, 0, this);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
if (event != null) {
|
||||
// draw buttons pushed
|
||||
ClassicControllerButtonsEvent buttons = event.getButtonsEvent();
|
||||
|
||||
/* button A */
|
||||
if (buttons.isButtonAJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 304, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonAHeld()) {
|
||||
drawFunction(g2, heldColor, 304, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonAJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 304, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (buttons.isButtonBJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 269, 98, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonBHeld()) {
|
||||
drawFunction(g2, heldColor, 269, 98, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonBJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 269, 98, shapeButton);
|
||||
}
|
||||
|
||||
/* button Down */
|
||||
if (buttons.isButtonDownJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 60, 97, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonDownHeld()) {
|
||||
drawFunction(g2, heldColor, 60, 97, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonDownJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 60, 97, shapeButton);
|
||||
}
|
||||
|
||||
/* button FullLeft */
|
||||
if (buttons.isButtonFullLeftJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 55, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullLeftHeld()) {
|
||||
drawFunction(g2, heldColor, 55, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullLeftJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 55, 4, shapeButton);
|
||||
}
|
||||
|
||||
/* button FullRight */
|
||||
if (buttons.isButtonFullRightJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 276, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullRightHeld()) {
|
||||
drawFunction(g2, heldColor, 276, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullRightJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 276, 4, shapeButton);
|
||||
}
|
||||
|
||||
/* button Home */
|
||||
if (buttons.isButtonHomeJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 166, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonHomeHeld()) {
|
||||
drawFunction(g2, heldColor, 166, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonHomeJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 166, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button Left */
|
||||
if (buttons.isButtonLeftJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 34, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonLeftHeld()) {
|
||||
drawFunction(g2, heldColor, 34, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonLeftJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 34, 75, shapeButton);
|
||||
}
|
||||
|
||||
/* button Minus */
|
||||
if (buttons.isButtonMinusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 140, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonMinusHeld()) {
|
||||
drawFunction(g2, heldColor, 140, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonMinusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 140, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button Plus */
|
||||
if (buttons.isButtonPlusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 191, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonPlusHeld()) {
|
||||
drawFunction(g2, heldColor, 191, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonPlusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 191, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button Right */
|
||||
if (buttons.isButtonRightJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 86, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonRightHeld()) {
|
||||
drawFunction(g2, heldColor, 86, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonRightJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 86, 353, shapeButton);
|
||||
}
|
||||
|
||||
/* button Up */
|
||||
if (buttons.isButtonUpJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 60, 50, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonUpHeld()) {
|
||||
drawFunction(g2, heldColor, 60, 50, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonUpJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 60, 50, shapeButton);
|
||||
}
|
||||
|
||||
/* button X */
|
||||
if (buttons.isButtonXJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 271, 53, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonXHeld()) {
|
||||
drawFunction(g2, heldColor, 271, 53, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonXJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 271, 53, shapeButton);
|
||||
}
|
||||
|
||||
/* button Y */
|
||||
if (buttons.isButtonYJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 237, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonYHeld()) {
|
||||
drawFunction(g2, heldColor, 237, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonYJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 237, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button ZL */
|
||||
if (buttons.isButtonZLJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 123, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZLHeld()) {
|
||||
drawFunction(g2, heldColor, 123, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZLJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 123, 4, shapeButton);
|
||||
}
|
||||
|
||||
/* button ZR */
|
||||
if (buttons.isButtonZRJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 208, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZRHeld()) {
|
||||
drawFunction(g2, heldColor, 208, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZRJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 208, 4, shapeButton);
|
||||
}
|
||||
|
||||
//joysticks
|
||||
int halfWidth = (int) Math.round(shapeJoystick.getBounds().getWidth() / 2);
|
||||
int halfHeight = (int) Math.round(shapeJoystick.getBounds().getHeight() / 2);
|
||||
|
||||
// left joystick
|
||||
JoystickEvent jl = event.getClassicControllerLeftJoystickEvent();
|
||||
int xCenter1 = 121;
|
||||
int yCenter1 = 125;
|
||||
|
||||
double xAng1 = Math.sin(jl.getAngle() * Math.PI / 180.0) * jl.getMagnitude();
|
||||
double yAng1 = Math.cos(jl.getAngle() * Math.PI / 180.0) * jl.getMagnitude();
|
||||
|
||||
int xShift1 = (int) Math.round(xAng1 * xAmplitude);
|
||||
int yShift1 = (int) Math.round(yAng1 * yAmplitude);
|
||||
int x1 = xCenter1 + xShift1 - halfWidth;
|
||||
int y1 = yCenter1 - yShift1 - halfHeight;
|
||||
// draw shape
|
||||
drawFunction(g2, joystickColor, x1, y1, shapeJoystick);
|
||||
|
||||
//Right joystick
|
||||
JoystickEvent jr = event.getClassicControllerRightJoystickEvent();
|
||||
int xCenter2 = 213;
|
||||
int yCenter2 = 125;
|
||||
|
||||
double xAng2 = Math.sin(jr.getAngle() * Math.PI / 180.0) * jr.getMagnitude();
|
||||
double yAng2 = Math.cos(jr.getAngle() * Math.PI / 180.0) * jr.getMagnitude();
|
||||
|
||||
int xShift2 = (int) Math.round(xAng2 * xAmplitude);
|
||||
int yShift2 = (int) Math.round(yAng2 * yAmplitude);
|
||||
int x2 = xCenter2 + xShift2 - halfWidth;
|
||||
int y2 = yCenter2 - yShift2 - halfHeight;
|
||||
// draw shape
|
||||
drawFunction(g2, joystickColor, x2, y2, shapeJoystick);
|
||||
|
||||
event = null;
|
||||
}
|
||||
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to factorize code.
|
||||
*
|
||||
* @param g2
|
||||
* where to draw a shape.
|
||||
* @param col
|
||||
* color to use.
|
||||
* @param x
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates.
|
||||
* @param sh
|
||||
* shape to draw.
|
||||
*/
|
||||
private void drawFunction(Graphics2D g2, Color col, int x, int y, Shape sh) {
|
||||
g2.setPaint(col);
|
||||
g2.translate(x, y);
|
||||
g2.draw(sh);
|
||||
g2.fill(sh);
|
||||
g2.setTransform(new AffineTransform());
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
if (arg0 instanceof ClassicControllerEvent) {
|
||||
event = (ClassicControllerEvent) arg0;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
|
||||
clearView();
|
||||
}
|
||||
|
||||
public Color getHeldColor() {
|
||||
return heldColor;
|
||||
}
|
||||
|
||||
public Color getJoystickColor() {
|
||||
return joystickColor;
|
||||
}
|
||||
|
||||
public Color getPressedColor() {
|
||||
return pressedColor;
|
||||
}
|
||||
|
||||
public Color getReleasedColor() {
|
||||
return releasedColor;
|
||||
}
|
||||
|
||||
public Color getShoulderColor() {
|
||||
return shoulderColor;
|
||||
}
|
||||
|
||||
public Shape getShapeButton() {
|
||||
return shapeButton;
|
||||
}
|
||||
|
||||
public Shape getShapeJoystick() {
|
||||
return shapeJoystick;
|
||||
}
|
||||
|
||||
public void setHeldColor(Color heldColor) {
|
||||
this.heldColor = heldColor;
|
||||
}
|
||||
|
||||
public void setJoystickColor(Color joystickColor) {
|
||||
this.joystickColor = joystickColor;
|
||||
}
|
||||
|
||||
public void setPressedColor(Color pressedColor) {
|
||||
this.pressedColor = pressedColor;
|
||||
}
|
||||
|
||||
public void setReleasedColor(Color releasedColor) {
|
||||
this.releasedColor = releasedColor;
|
||||
}
|
||||
|
||||
public void setShoulderColor(Color shoulderColor) {
|
||||
this.shoulderColor = shoulderColor;
|
||||
}
|
||||
|
||||
public void setShapeButton(Shape shapeButton) {
|
||||
this.shapeButton = shapeButton;
|
||||
}
|
||||
|
||||
public void setShapeJoystick(Shape shapeJoystick) {
|
||||
this.shapeJoystick = shapeJoystick;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
event = null;
|
||||
repaint();
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
|
||||
/**
|
||||
* Panel to display GForce in a MotionSensingEvent from an expansion.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GForceExpansionEventPanel extends GForcePanel{
|
||||
|
||||
@Override
|
||||
public GForce getGForceValue(GenericEvent e) {
|
||||
if (e instanceof NunchukEvent){
|
||||
return ((NunchukEvent)e).getNunchukMotionSensingEvent().getGforce();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,304 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to watch gravity force values from a MotionSensingEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class GForcePanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Color xColor = Color.RED;
|
||||
private Color yColor = Color.GREEN;
|
||||
private Color zColor = Color.BLUE;
|
||||
private Color backgroundColor = Color.WHITE;
|
||||
private Color lineColor = Color.BLACK;
|
||||
private ArrayList<GForce> values = new ArrayList<GForce>();
|
||||
|
||||
/**
|
||||
* Default constructor of the AccelerationPanel.
|
||||
*/
|
||||
public GForcePanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to choose the colors used by the AccelerationPanel.
|
||||
*
|
||||
* @param bgColor
|
||||
* background color.
|
||||
* @param xxColor
|
||||
* color of the acceleration on X axis.
|
||||
* @param yyColor
|
||||
* color of the acceleration on Y axis.
|
||||
* @param zzColor
|
||||
* color of the acceleration on Z axis.
|
||||
* @param lColor
|
||||
* line color.
|
||||
*/
|
||||
public GForcePanel(Color bgColor, Color xxColor, Color yyColor,
|
||||
Color zzColor, Color lColor) {
|
||||
backgroundColor = bgColor;
|
||||
xColor = xxColor;
|
||||
yColor = yyColor;
|
||||
zColor = zzColor;
|
||||
lineColor = lColor;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
|
||||
GForce[] valuesArray = values.toArray(new GForce[0]);
|
||||
double unit = yMiddleFloat / 5.0;
|
||||
int previousX = 0;
|
||||
int previousY = 0;
|
||||
int previousZ = 0;
|
||||
// draw curves
|
||||
for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
|
||||
GForce gforce = valuesArray[i];
|
||||
// draw X
|
||||
g2.setPaint(xColor);
|
||||
int yDelta = (int) Math.round(unit * gforce.getX());
|
||||
int y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousX, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousX = y;
|
||||
// draw Y
|
||||
g2.setPaint(yColor);
|
||||
yDelta = (int) Math.round(unit * gforce.getY());
|
||||
y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousY, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousY = y;
|
||||
// draw Z
|
||||
g2.setPaint(zColor);
|
||||
yDelta = (int) Math.round(unit * gforce.getZ());
|
||||
y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousZ, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousZ = y;
|
||||
}
|
||||
|
||||
// draw legend
|
||||
g2.setPaint(xColor);
|
||||
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
|
||||
g2.setPaint(yColor);
|
||||
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
|
||||
g2.setPaint(zColor);
|
||||
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawString("X", 30, getHeight() - 5);
|
||||
g2.drawString("Y", 85, getHeight() - 5);
|
||||
g2.drawString("Z", 145, getHeight() - 5);
|
||||
g2.drawString("0", 2, yMiddle - 5);
|
||||
g2.drawString("5", 2, 10);
|
||||
g2.drawString("-5", 2, getHeight() - 15);
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// Clear points.
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
private void draw(GenericEvent arg0) {
|
||||
if (values.size() >= getWidth()) {
|
||||
// if there are as many values as pixels in the width
|
||||
// clear points
|
||||
values.clear();
|
||||
}
|
||||
GForce gforce = getGForceValue(arg0);
|
||||
if (gforce != null)
|
||||
values.add(gforce);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public abstract GForce getGForceValue(GenericEvent e);
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getLineColor() {
|
||||
return lineColor;
|
||||
}
|
||||
|
||||
public Color getXColor() {
|
||||
return xColor;
|
||||
}
|
||||
|
||||
public Color getYColor() {
|
||||
return yColor;
|
||||
}
|
||||
|
||||
public Color getZColor() {
|
||||
return zColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setLineColor(Color lineColor) {
|
||||
this.lineColor = lineColor;
|
||||
}
|
||||
|
||||
public void setXColor(Color xColor) {
|
||||
this.xColor = xColor;
|
||||
}
|
||||
|
||||
public void setYColor(Color yColor) {
|
||||
this.yColor = yColor;
|
||||
}
|
||||
|
||||
public void setZColor(Color zColor) {
|
||||
this.zColor = zColor;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
/**
|
||||
* Panel to display GForce in a MotionSensingEvent from a wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GForceWiimoteEventPanel extends GForcePanel {
|
||||
|
||||
@Override
|
||||
public GForce getGForceValue(GenericEvent e) {
|
||||
if (e instanceof MotionSensingEvent) {
|
||||
return ((MotionSensingEvent) e).getGforce();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user