|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionMost of you are familiar to the Nintendo Wii, and if you know the wii you probably know the wiimote (The Wii remote). The Wiimote is one of the most interactive gaming remotes I have put my hands on. After snooping around the net it turned out that using Bluetooth and the wiimote library you can connect the wii to your PC as an HID and send/receive messages form and to the wiimote. In this project we will connect the wiimote and then take control of the Windows Media Player, so the wiimote is going to be controlling the Windows Media Player (WMP) as a simple Bluetooth remote. BackgroundYou will have to know how to use C#.NET, we will be using libraries (WiimoteLib) and a Library i created to control the Windows Media Player. It would be good if you know how to basicly connect the wiimote to the PC using bluetooth (It was tested using BlueSoleil application) Using the codeLets start off talking about the Structure of the application. Its made up of 3 Parts, 3 Projects within one solution. Part One, WiimoteLib
To connect to the laptop you should do the following. When using BlueSoliel turn on bluetooth on the laptop, Now connecting the wii thru the application you should use, Now we need an event handler for when the wiimote changes its state, and changing its state here is like changing the Button States, //...Form Load Function... wm.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged); //... void wm_OnWiimoteChanged(object sender, WiimoteChangedEventArgs args) //Function fires on wiimote change state change { } Now within the event handling we check the wiimote state from the properties within Part Two, WMPControlYJWWMPControlYJW is the Windows Media Player Controler class, or we can call it the automater, This was the tricky part, Now how to use the Class: Part Three, The GUI, The MedianWhat does the Median mean? Its the application that picks up the wiimote state change and sends it to the WMPControlYJW //Create Wiimote instance and WMPYjw Control private Wiimote wm = new Wiimote(); private WMPYJW wmp = new WMPYJW(); // //Bools to track previous state of buttons private bool ButtonA = false; private bool ButtonB = false; private bool ButtonUp = false; private bool ButtonDown = false; private bool ButtonPlus = false; private bool ButtonMinus = false; private bool Button1 = false; private bool ButtonRight = false; //// The first 2 lines of code are creating instances of both libraries, Wiimote and WMPControlYJW. private void Form1_Load(object sender, EventArgs e) { wmp.ConnectWMP(); // Connect to the Open Windows Media Player wm.Connect(); //Connect to Wiimote wm.SetReportType(Wiimote.InputReport.ButtonsAccel,true); //Set Needed tracking of wii wm.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged); // Set event for Wiimote change }
void wm_OnWiimoteChanged(object sender, WiimoteChangedEventArgs args) //Function fires on wiimote change state change { #region Automate Play on WiiA if (wm.WiimoteState.ButtonState.A && ButtonA != true) //Checks to prevent multi-firing { wmp.Play(); // Send play command thru WMPControlYJW ButtonA = true; //To prevent Multi-Firing } if (ButtonA == true && wm.WiimoteState.ButtonState.A != true)//To prevent Multi-Firing { ButtonA = false;//To prevent Multi-Firing } #endregion #region Automate Stop on WiiB if (wm.WiimoteState.ButtonState.B && ButtonB != true) { wmp.Stop();// Send Stop command thru WMPControlYJW ButtonB = true; } if (ButtonB == true && wm.WiimoteState.ButtonState.B != true) { ButtonB = false; } #endregion #region Automate Next on WiiUp if (wm.WiimoteState.ButtonState.Up && ButtonUp != true) { wmp.Next();// Send Next command thru WMPControlYJW ButtonUp = true; } if (ButtonUp == true && wm.WiimoteState.ButtonState.Up != true) { ButtonUp = false; } #endregion #region Automate Previous on WiiDown if (wm.WiimoteState.ButtonState.Down && ButtonDown != true) { wmp.Previous();// Send Previous command thru WMPControlYJW ButtonDown = true; } if (ButtonDown == true && wm.WiimoteState.ButtonState.Down != true) { ButtonDown = false; } #endregion #region Automate Volume Up on WiiPlus if (wm.WiimoteState.ButtonState.Plus && ButtonPlus != true) { wmp.Volume_Up();// Send Volume Up command thru WMPControlYJW ButtonPlus = true; } if (ButtonPlus == true && wm.WiimoteState.ButtonState.Plus != true) { ButtonPlus = false; } #endregion #region Automate Volume Down on WiiMinus if (wm.WiimoteState.ButtonState.Minus && ButtonMinus != true) { wmp.Volume_Down();// Send Volume Down command thru WMPControlYJW ButtonMinus = true; } if (ButtonMinus == true && wm.WiimoteState.ButtonState.Minus != true) { ButtonMinus = false; } #endregion #region Automate Volume Mute on WiiMute if (wm.WiimoteState.ButtonState.One && Button1 != true) { wmp.Mute();// Send Mute command thru WMPControlYJW Button1 = true; } if (Button1 == true && wm.WiimoteState.ButtonState.One != true) { Button1 = false; } #endregion #region Automate Fast Forward on WiiMute if (wm.WiimoteState.ButtonState.Right && ButtonRight != true) { wmp.Fast_Forward();// Send Mute command thru WMPControlYJW // Still Causing Trouble ButtonRight = true; } if (ButtonRight == true && wm.WiimoteState.ButtonState.Right != true) { ButtonRight = false; } #endregion } The previous code is how the wii change is handled. It is commented and pretty straight Forward. Points of InterestWithin this project we have seen how to basicly use Wiimote with .NET. Created By: Yousef Jamal Wadi -German Jordanian University -Conputer Eng. Software Systems
|
|||||||||||||||||||||||||||||||||||||||||||||||