WiiLAB - WiimoteLib
WiimoteLib is a .NET managed library for connecting to the Nintendo Wii Remote (Wiimote). The library was developed by
Brian Peek, who is continually updating the library with new additions and features.
There are a number of web pages dedicated to the WiimoteLib:
The version of WiimoteLib that we include and use in our project is v1.4.0 with a few custom additions listed below:
- We have reduced the delay time between the
WriteReport and WriteData methods
- Brain Peek implemented a series of
Thread.Sleep(100) commands in the WriteReport and WriteData methods that cause the method to delay 100 milliseconds after the report is sent. These were included because the Wiimote would enter an unresponsive state without the delay.
- We were experiencing noticeable holdups in programs that changed the Rumble and LED features of the Wiimote frequently. After running a series of tests on the delay length, we were able to lower it to as little as 1 millisecond without the Wiimote going into an unresponsive state.
- Since the actual cause of the unresponsive state is still unclear, we decided to reduce the sleep time to 10 milliseconds.
- We have not experienced any problems with the Wiimotes since this change was implemented.
- Updated the
Midpoint data type of the IRState to have the same structure as the other IR source data types.
- The Midpoint now has
Found, RawPosition, and Position fields similar to the other IR sources.
- We have also changed how the
Midpoint is calculated.
- Previously the Midpoint was calculated as the distance between the first two IR sources.
- We changed
Midpoint to be the center of the two most distinct IR sources.
- This is because we were encountering times when the Wiimote would discover more then two sources and then the source that was the second is lost. This caused the Wiimote to have source one and three (or four) as its only sources. The old
Midpoint would not have existed in these circumstances even though you would expect one to exist.
- We have also included a
ConnectionState field to the Wiimote class in WiimoteLib
- We were experiencing an unhandled IOException in the
OnRead method if the Wiimote manually disconnected from the computer (ie. removing the bluetooth adapter, turning the Wiimote off, etc). This error would cause MATLAB to crash.
- Our solution was to incorporate the
ConnectionState data member in the Wiimote class. It has three states, as of now. They are: Connected - The Wiimote is connected; NotConnected - The Wiimote is not connected but available for connection; ReadError - An Error was encountered, and the Wiimote needs to be reconnected.
- We updated the Wiimote class to set the
Connected and NotConnected properties accordingly and added another catch block in the OnRead method. This block catches the IOException, closes the Wiimote's file stream and sets the ConnectionState to ReadError.
- Now every call to the Wiimote checks this property to make sure the Wiimote is still connected before continuing.
We would like to thank Brian Peek and everyone who has helped him work on the WiimoteLib. Their work has been instrumental to the success of our project.
--
JordanBrindza - 22 Jul 2008