PDA

View Full Version : Using the Nintendo Wii Wiimote Remote from Girder



NJKen
August 5th, 2008, 06:42 PM
You can now use your Wiimotes from Girder using a modified version of GenericHID!

I'm hoping that someone in the Girder community with more Lua experience will be able to figure out how to write data to these devices so that we'll have access to the Wiimote's more interesting functions. I'd love to carry my Wiimote with me into another room and then have it's speaker beep me when Girder wants to notify me. I've tried the "Transport Send" action but it doesn't appear to work in my Vista Ultimate x64 environment. As an example, I expect that sending the following hex sequence should activate the rumble: "111301"

---

Required Software and Hardware:

•One or more Nintendo Wii Wiimotes (wireless remote controls)

•Functional Bluetooth hardware and driver software

•Girder 5.x

•The included WiimoteHID.lua file.

---

What You'll Be Able To Do With Your Wiimote and Girder:

•You can trigger 11 unique Girder events wirelessly from each Wiimote.

•You can connect multiple Wiimotes which can either trigger common or separate events.

•Theoretically connect up to the Bluetooth piconet maximum of 7 Wiimotes.

---

Note: Do not plug in a Nunchuck or other accessory or else you'll be forced to turn off and reconnect your Wiimote. This quirk can be corrected once we're able to write to the Wiimotes.

---

Installation:
•The included file WiimoteHID.lua should be placed in the following folder (or modified if you have an alternate default directory)
C:\Program Files\Promixis\Girder5\luascript\Classes\Transport

•You'll need to setup and "pair" each Wiimote with your Bluetooth hardware. This varies depending on the type of Bluetooth software (also called "stack") you have installed. First, check for a Bluetooth icon in your Control Panel or in your system tray. You'll need to tell the Bluetooth software to search for new devices while HOLDING DOWN the 1 and 2 buttons. This method is preferred to holding down the little red button within the battery compartment. Continue to hold down 1 and 2 while answering all of the software prompts. If asked, do NOT assign a password to this connection. The blue LEDs on the Wiimote will NOT stop flashing once this is successful so the only way you know it worked is if the software says "connected" or if Girder is able to connect.

•Activate a connection to the Wiimote from Girder. The "Wiimote Sample Actions.gml" file has a scripting action named "Start Wiimote" which will allow Girder to begin generating events for each button you press on your Wiimote. There is a "GirderOpen" event tied to this action which is disabled by default but can be used to attempt to make this connection each time Girder starts. You can create your own scripting action by copy-and-pasting the following code:

local WiimoteHID = require('Classes.Transport.WiimoteHID')
Wiimote1 = WiimoteHID:New( { VendorID = 1406, ProductID = 774, Index = 0, EventDevice=18, EventPrefix = 'Wiimote1:', Debug = 0 })

•Your Wiimote should stay connected for up to a half hour when idle or longer depending on your Bluetooth software. We'll be able to extend this once we can write to the device from Girder.

•Depending on your Bluetooth Stack you may need to re-connect the Wiimote each time you turn it on unless your Bluetooth Stack can be configured to automatically pair with the Wiimote. I have found that my Bluetooth stack remembers by Wiimotes and allows Girder to pretend to connect to them when they might not actually be on.

---

What You CAN'T Do:
•The power button can't be used to trigger Girder - it only controls the power state of the Wiimote.

•You can't use the rumble feature, make sound come out of the speaker, or use the Wiimote as a pointer. I look forward to the day when we'll be able to make the Wiimote make a short rumble with each button-press to provide some "force feedback".

•You can't change the player LED's on the Wiimote from within Girder. (Yes, I know the flashing can get annoying, but we can fix this as soon as someone can figure out a way to write to a HID device through Lua.)

•You can't read the state from accessory devices such as the Nunchuck, Classic Controller, Wii Guitar, or the Wii Balance Board. Doing this requires that we first write to the Wiimote.

•The keydown, keyup, and repeat modifiers are not yet supported.

•Only individual button-presses will generate events. Pressing multiple buttons at the same time may generate multiple events for each of the keys pressed. If you need to support multiple simultaneous button-presses read the comments in the following section.

---

Simultaneous Button-Presses:
•Properly handling multiple simultaneous button-presses will require additional programming. However, I've provided a simple work-around if you are willing to accept one catch. Setup the Wiimote connection using the option "Raw = 1" as shown in the following commands:

-- Instruct Girder to send "Raw" events instead of "Formatted" ones
local WiimoteHID = require('Classes.Transport.WiimoteHID')
Wiimote1 = WiimoteHID:New( { VendorID = 1406, ProductID = 774, Index = 0, EventDevice=18, EventPrefix = 'Wiimote1:', Debug = 0, Raw = 1 })

This Raw mode generates different events which expose the actual hex values reported by the device. The problem with this work-around is that pressing "A" and "B" at the same time will likely generate both an "A" event and an "A+B" event because one of the buttons was pressed a split second before the pair was pressed. If you must use this mode you should ignore the individual button presses or devise another way to work around this.

---

I hope you enjoy using your Wiimote from within Girder! Please post your experiences in the thread that this file originated from.

---

See the Wiimote Read Me.txt file for links to additional resources.

---

Revision: 08/05/08

Ron
August 5th, 2008, 07:11 PM
Very cool!! I'll see what I can do about the writing to HID trouble.

Ron
August 12th, 2008, 06:48 PM
Got this working here. Very cool. I'm going to try and find a bit of time tomorrow to figure out how to get the writing to work.

flyvans.com
August 12th, 2008, 08:28 PM
another big example why a decent HID plugin would come in handy!

also, detecting simultaneous button presses in lua is a pain, needs a lot of forks if it has to be programmed individually, it practically craves for a plugin!

was away for 2 weeks of holidays, so hadn't tried much more, but i've got yet to see the sidewinder usb joystick to get to work. let alone the other usb device i am eventually using to replace the sidewinder button presses, which for now is solely for development.

also remapping possibilities would be nice.

thanks for pushing in that direction.

bernie

Ron
August 13th, 2008, 10:35 AM
Got the writing to the wiimote to work. The HID driver needed to be able to use SetOutputReport, which is does not.

Place 0transport.dll in the plugins directory and the wiimotehid.lua into the luascript/class/transport directory.

to write use



Wiimote1:Write("11F0")
-- turn all LED's on.


If for some reason your Bluetooth stack cannot use the SetOutputReport then change line 170 of WiimoteHID.lua to



self.Transport.TransportStream:UseSetReport(false)

ph0n33z
August 14th, 2008, 02:11 PM
What is the range on the bluetooth dongles that you guys are using on your pcs for this?

Ron: since you have enabled writing to the wiimote, does that now allow all of the functionality that was previously unavailable (rumble, speaker, LEDs, Gyro) to be utilized?

Ron
August 14th, 2008, 06:28 PM
I am using a Kensington K33348B adapter. On Vista 64 it works OK, not brilliant. I didn't test range.

Yep we can now write to the device and read, giving us full access to the remote. (as far as the API is known that is.)

NJKen
August 14th, 2008, 08:32 PM
THANKS Ron! I tested your code and I was able to successfully toggle the rumble and the LEDs. In a couple weeks when my schedule clears up, I'll add support for some of the other features. This is exciting!

I'm using external Bluetooth hardware from Belkin. Internally it is using a "Cambridge Silicon Radio" as reported by my Bluesoleil Bluetooth stack.

I tested the range and found no noticeable delay anywhere inside my house. I went outside and started to see delays as I approached the street. My Bluetooth hardware is attached to a USB extension and placed above the level of my monitors to reduce interference and increase range.

ph0n33z: The previously unavailable functionality (rumble, speaker, LEDs, etc) isn't enabled by the software download within this post - just the ability to send commands to the Wiimote. As an example, Ron provided a code sample for turning on a player LED. Before you'll be able to use some of these advanced functions, further code will have to be written to enable Lua/Girder to properly handle the Wiimote. This is an experimental (alpha) project.