From: <an...@us...> - 2007-12-04 03:33:46
|
Revision: 1120 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1120&view=rev Author: and-81 Date: 2007-12-03 19:33:40 -0800 (Mon, 03 Dec 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/Wii Remote Receiver/Wii Remote Receiver.cs Property Changed: ---------------- trunk/plugins/IR Server Suite/IR Server Plugins/Wii Remote Receiver/ trunk/plugins/IR Server Suite/IR Server Plugins/WiimoteLib/ Property changes on: trunk/plugins/IR Server Suite/IR Server Plugins/Wii Remote Receiver ___________________________________________________________________ Name: svn:ignore + bin obj Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Wii Remote Receiver/Wii Remote Receiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Wii Remote Receiver/Wii Remote Receiver.cs 2007-12-04 00:45:02 UTC (rev 1119) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Wii Remote Receiver/Wii Remote Receiver.cs 2007-12-04 03:33:40 UTC (rev 1120) @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Drawing; +using System.Windows.Forms; using IRServerPluginInterface; @@ -15,20 +16,16 @@ public class WiiRemoteReceiver : IRServerPluginBase, IRemoteReceiver { - #region Delegates + #region Variables - delegate void UpdateWiimoteStateDelegate(WiimoteChangedEventArgs args); - delegate void UpdateExtensionChangedDelegate(WiimoteExtensionChangedEventArgs args); + RemoteHandler _remoteButtonHandler; - #endregion Delegates + Wiimote _wiimote; - #region Variables + WiimoteState _previousState; - RemoteHandler _remoteButtonHandler; - - Wiimote wm; - Bitmap b; - Graphics g; + int screenWidth = Screen.PrimaryScreen.WorkingArea.Width; + int screenHeight = Screen.PrimaryScreen.WorkingArea.Height; #endregion Variables @@ -72,19 +69,16 @@ /// <returns>true if successful, otherwise false.</returns> public override bool Start() { - wm = new Wiimote(); + _wiimote = new Wiimote(); - wm.WiimoteChanged += new WiimoteChangedEventHandler(wm_WiimoteChanged); - wm.WiimoteExtensionChanged += new WiimoteExtensionChangedEventHandler(wm_WiimoteExtensionChanged); + _wiimote.WiimoteChanged += new WiimoteChangedEventHandler(WiimoteChanged); + _wiimote.WiimoteExtensionChanged += new WiimoteExtensionChangedEventHandler(WiimoteExtensionChanged); - b = new Bitmap(256, 192, PixelFormat.Format24bppRgb); + _wiimote.Connect(); + _wiimote.SetReportType(Wiimote.InputReport.IRAccel, true); + _wiimote.SetLEDs(false, true, true, false); + _wiimote.SetRumble(false); - g = Graphics.FromImage(b); - - wm.Connect(); - wm.SetReportType(Wiimote.InputReport.IRAccel, true); - wm.SetLEDs(false, true, true, false); - return true; } /// <summary> @@ -106,10 +100,12 @@ /// </summary> public override void Stop() { - if (wm == null) + if (_wiimote == null) return; - wm.Disconnect(); + _wiimote.SetLEDs(false, false, false, false); + _wiimote.SetRumble(false); + _wiimote.Disconnect(); } /// <summary> @@ -121,120 +117,136 @@ get { return _remoteButtonHandler; } set { _remoteButtonHandler = value; } } + + void WiimoteChanged(object sender, WiimoteChangedEventArgs args) + { + WiimoteState ws = args.WiimoteState; + if (_previousState != null) + { + if (ws.ButtonState.A && !_previousState.ButtonState.A) RemoteCallback("Wiimote_Button:A"); + if (ws.ButtonState.B && !_previousState.ButtonState.B) RemoteCallback("Wiimote_Button:B"); + if (ws.ButtonState.Home && !_previousState.ButtonState.Home) RemoteCallback("Wiimote_Button:Home"); + if (ws.ButtonState.Minus && !_previousState.ButtonState.Minus) RemoteCallback("Wiimote_Button:Minus"); + if (ws.ButtonState.One && !_previousState.ButtonState.One) RemoteCallback("Wiimote_Button:One"); + if (ws.ButtonState.Plus && !_previousState.ButtonState.Plus) RemoteCallback("Wiimote_Button:Plus"); + if (ws.ButtonState.Two && !_previousState.ButtonState.Two) RemoteCallback("Wiimote_Button:Two"); + if (ws.ButtonState.Down && !_previousState.ButtonState.Down) RemoteCallback("Wiimote_Pad:Down"); + if (ws.ButtonState.Left && !_previousState.ButtonState.Left) RemoteCallback("Wiimote_Pad:Left"); + if (ws.ButtonState.Right && !_previousState.ButtonState.Right) RemoteCallback("Wiimote_Pad:Right"); + if (ws.ButtonState.Up && !_previousState.ButtonState.Up) RemoteCallback("Wiimote_Pad:Up"); - private void UpdateExtensionChanged(WiimoteExtensionChangedEventArgs args) - { - chkExtension.Text = args.ExtensionType.ToString(); - chkExtension.Checked = args.Inserted; + if (ws.ExtensionType == ExtensionType.Nunchuk) + { + if (ws.NunchukState.C && !_previousState.NunchukState.C) RemoteCallback("WiimoteNunchuk_Button:C"); + if (ws.NunchukState.Z && !_previousState.NunchukState.Z) RemoteCallback("WiimoteNunchuk_Button:Z"); + } - if (args.Inserted) - wm.SetReportType(Wiimote.InputReport.IRExtensionAccel, true); - else - wm.SetReportType(Wiimote.InputReport.IRAccel, true); - } + if (ws.ExtensionType == ExtensionType.ClassicController) + { + if (ws.ClassicControllerState.ButtonState.A && !_previousState.ClassicControllerState.ButtonState.A) RemoteCallback("WiimoteClassic_Button:A"); + if (ws.ClassicControllerState.ButtonState.B && !_previousState.ClassicControllerState.ButtonState.B) RemoteCallback("WiimoteClassic_Button:B"); + if (ws.ClassicControllerState.ButtonState.Home && !_previousState.ClassicControllerState.ButtonState.Home) RemoteCallback("WiimoteClassic_Button:Home"); + if (ws.ClassicControllerState.ButtonState.Minus && !_previousState.ClassicControllerState.ButtonState.Minus) RemoteCallback("WiimoteClassic_Button:Minus"); + if (ws.ClassicControllerState.ButtonState.Plus && !_previousState.ClassicControllerState.ButtonState.Plus) RemoteCallback("WiimoteClassic_Button:Plus"); + if (ws.ClassicControllerState.ButtonState.X && !_previousState.ClassicControllerState.ButtonState.X) RemoteCallback("WiimoteClassic_Button:X"); + if (ws.ClassicControllerState.ButtonState.Y && !_previousState.ClassicControllerState.ButtonState.Y) RemoteCallback("WiimoteClassic_Button:Y"); + if (ws.ClassicControllerState.ButtonState.TriggerL && !_previousState.ClassicControllerState.ButtonState.TriggerL) RemoteCallback("WiimoteClassic_Button:TriggerL"); + if (ws.ClassicControllerState.ButtonState.TriggerR && !_previousState.ClassicControllerState.ButtonState.TriggerR) RemoteCallback("WiimoteClassic_Button:TriggerR"); + if (ws.ClassicControllerState.ButtonState.ZL && !_previousState.ClassicControllerState.ButtonState.ZL) RemoteCallback("WiimoteClassic_Button:ZL"); + if (ws.ClassicControllerState.ButtonState.ZR && !_previousState.ClassicControllerState.ButtonState.ZR) RemoteCallback("WiimoteClassic_Button:ZR"); - private void UpdateWiimoteState(WiimoteChangedEventArgs args) - { - WiimoteState ws = args.WiimoteState; + if (ws.ClassicControllerState.ButtonState.Down && !_previousState.ClassicControllerState.ButtonState.Down) RemoteCallback("WiimoteClassic_Pad:Down"); + if (ws.ClassicControllerState.ButtonState.Left && !_previousState.ClassicControllerState.ButtonState.Left) RemoteCallback("WiimoteClassic_Pad:Left"); + if (ws.ClassicControllerState.ButtonState.Right && !_previousState.ClassicControllerState.ButtonState.Right) RemoteCallback("WiimoteClassic_Pad:Right"); + if (ws.ClassicControllerState.ButtonState.Up && !_previousState.ClassicControllerState.ButtonState.Up) RemoteCallback("WiimoteClassic_Pad:Up"); + } - clbButtons.SetItemChecked(0, ws.ButtonState.A); - clbButtons.SetItemChecked(1, ws.ButtonState.B); - clbButtons.SetItemChecked(2, ws.ButtonState.Minus); - clbButtons.SetItemChecked(3, ws.ButtonState.Home); - clbButtons.SetItemChecked(4, ws.ButtonState.Plus); - clbButtons.SetItemChecked(5, ws.ButtonState.One); - clbButtons.SetItemChecked(6, ws.ButtonState.Two); - clbButtons.SetItemChecked(7, ws.ButtonState.Up); - clbButtons.SetItemChecked(8, ws.ButtonState.Down); - clbButtons.SetItemChecked(9, ws.ButtonState.Left); - clbButtons.SetItemChecked(10, ws.ButtonState.Right); - clbButtons.SetItemChecked(11, ws.NunchukState.C); - clbButtons.SetItemChecked(12, ws.NunchukState.Z); + if (ws.IRState.Found1 && ws.IRState.Found2) + { + int x = (int)(screenWidth - (ws.IRState.X1 + ws.IRState.X2) / 2 * screenWidth); + int y = (int)((ws.IRState.Y1 + ws.IRState.Y2) / 2 * screenHeight); - lblX.Text = ws.AccelState.X.ToString(); - lblY.Text = ws.AccelState.Y.ToString(); - lblZ.Text = ws.AccelState.Z.ToString(); + Cursor.Position = new Point(x, y); - if (ws.ExtensionType == ExtensionType.Nunchuk) - { - lblChukX.Text = ws.NunchukState.AccelState.X.ToString(); - lblChukY.Text = ws.NunchukState.AccelState.Y.ToString(); - lblChukZ.Text = ws.NunchukState.AccelState.Z.ToString(); + int prevX = (int)(screenWidth - (_previousState.IRState.X1 + _previousState.IRState.X2) / 2 * screenWidth); + int prevY = (int)((_previousState.IRState.Y1 + _previousState.IRState.Y2) / 2 * screenHeight); - lblChukJoyX.Text = ws.NunchukState.X.ToString(); - lblChukJoyY.Text = ws.NunchukState.Y.ToString(); - } + int deltaX = x - prevX; + int deltaY = y - prevY; - if (ws.ExtensionType == ExtensionType.ClassicController) - { - clbCCButtons.SetItemChecked(0, ws.ClassicControllerState.ButtonState.A); - clbCCButtons.SetItemChecked(1, ws.ClassicControllerState.ButtonState.B); - clbCCButtons.SetItemChecked(2, ws.ClassicControllerState.ButtonState.X); - clbCCButtons.SetItemChecked(3, ws.ClassicControllerState.ButtonState.Y); - clbCCButtons.SetItemChecked(4, ws.ClassicControllerState.ButtonState.Minus); - clbCCButtons.SetItemChecked(5, ws.ClassicControllerState.ButtonState.Home); - clbCCButtons.SetItemChecked(6, ws.ClassicControllerState.ButtonState.Plus); - clbCCButtons.SetItemChecked(7, ws.ClassicControllerState.ButtonState.Up); - clbCCButtons.SetItemChecked(8, ws.ClassicControllerState.ButtonState.Down); - clbCCButtons.SetItemChecked(9, ws.ClassicControllerState.ButtonState.Left); - clbCCButtons.SetItemChecked(10, ws.ClassicControllerState.ButtonState.Right); - clbCCButtons.SetItemChecked(11, ws.ClassicControllerState.ButtonState.ZL); - clbCCButtons.SetItemChecked(12, ws.ClassicControllerState.ButtonState.ZR); - clbCCButtons.SetItemChecked(13, ws.ClassicControllerState.ButtonState.TriggerL); - clbCCButtons.SetItemChecked(14, ws.ClassicControllerState.ButtonState.TriggerR); + Trace.WriteLine("DeltaX: " + deltaX.ToString() + " DeltaY: " + deltaY.ToString()); - lblXL.Text = ws.ClassicControllerState.XL.ToString(); - lblYL.Text = ws.ClassicControllerState.YL.ToString(); - lblXR.Text = ws.ClassicControllerState.XR.ToString(); - lblYR.Text = ws.ClassicControllerState.YR.ToString(); - - lblTriggerL.Text = ws.ClassicControllerState.TriggerL.ToString(); - lblTriggerR.Text = ws.ClassicControllerState.TriggerR.ToString(); + } } + else + _previousState = new WiimoteState(); + + //_previousState.AccelCalibrationInfo.X0 = ws.AccelCalibrationInfo.X0; + //_previousState.AccelCalibrationInfo.XG = ws.AccelCalibrationInfo.XG; + //_previousState.AccelCalibrationInfo.Y0 = ws.AccelCalibrationInfo.Y0; + //_previousState.AccelCalibrationInfo.YG = ws.AccelCalibrationInfo.YG; + //_previousState.AccelCalibrationInfo.Z0 = ws.AccelCalibrationInfo.Z0; + //_previousState.AccelCalibrationInfo.ZG = ws.AccelCalibrationInfo.ZG; - if (ws.IRState.Found1) - { - lblIR1.Text = ws.IRState.X1.ToString() + ", " + ws.IRState.Y1.ToString() + ", " + ws.IRState.Size1; - lblIR1Raw.Text = ws.IRState.RawX1.ToString() + ", " + ws.IRState.RawY1.ToString(); - } - if (ws.IRState.Found2) - { - lblIR2.Text = ws.IRState.X2.ToString() + ", " + ws.IRState.Y2.ToString() + ", " + ws.IRState.Size2; - lblIR2Raw.Text = ws.IRState.RawX2.ToString() + ", " + ws.IRState.RawY2.ToString(); - } + //_previousState.AccelState.RawX = ws.AccelState.RawX; + //_previousState.AccelState.RawY = ws.AccelState.RawY; + //_previousState.AccelState.RawZ = ws.AccelState.RawZ; + //_previousState.AccelState.X = ws.AccelState.X; + //_previousState.AccelState.Y = ws.AccelState.Y; + //_previousState.AccelState.Z = ws.AccelState.Z; - chkFound1.Checked = ws.IRState.Found1; - chkFound2.Checked = ws.IRState.Found2; + //_previousState.Battery = ws.Battery; - pbBattery.Value = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery); - float f = (((100.0f * 48.0f * (float)(ws.Battery / 48.0f))) / 192.0f); - lblBattery.Text = f.ToString("F"); + _previousState.ButtonState.A = ws.ButtonState.A; + _previousState.ButtonState.B = ws.ButtonState.B; + _previousState.ButtonState.Down = ws.ButtonState.Down; + _previousState.ButtonState.Home = ws.ButtonState.Home; + _previousState.ButtonState.Left = ws.ButtonState.Left; + _previousState.ButtonState.Minus = ws.ButtonState.Minus; + _previousState.ButtonState.One = ws.ButtonState.One; + _previousState.ButtonState.Plus = ws.ButtonState.Plus; + _previousState.ButtonState.Right = ws.ButtonState.Right; + _previousState.ButtonState.Two = ws.ButtonState.Two; + _previousState.ButtonState.Up = ws.ButtonState.Up; - g.Clear(Color.Black); - if (ws.IRState.Found1) - g.DrawEllipse(new Pen(Color.Red), (int)(ws.IRState.RawX1 / 4), (int)(ws.IRState.RawY1 / 4), ws.IRState.Size1 + 1, ws.IRState.Size1 + 1); - if (ws.IRState.Found2) - g.DrawEllipse(new Pen(Color.Blue), (int)(ws.IRState.RawX2 / 4), (int)(ws.IRState.RawY2 / 4), ws.IRState.Size2 + 1, ws.IRState.Size2 + 1); - if (ws.IRState.Found1 && ws.IRState.Found2) - g.DrawEllipse(new Pen(Color.Green), (int)(ws.IRState.RawMidX / 4), (int)(ws.IRState.RawMidY / 4), 2, 2); - pbIR.Image = b; - } + _previousState.Extension = ws.Extension; + _previousState.ExtensionType = ws.ExtensionType; + + _previousState.IRState.Found1 = ws.IRState.Found1; + _previousState.IRState.Found2 = ws.IRState.Found2; + _previousState.IRState.MidX = ws.IRState.MidX; + _previousState.IRState.MidY = ws.IRState.MidY; + _previousState.IRState.Mode = ws.IRState.Mode; + _previousState.IRState.RawMidX = ws.IRState.RawMidX; + _previousState.IRState.RawMidY = ws.IRState.RawMidY; + _previousState.IRState.RawX1 = ws.IRState.RawX1; + _previousState.IRState.RawX2 = ws.IRState.RawX2; + _previousState.IRState.RawY1 = ws.IRState.RawY1; + _previousState.IRState.RawY2 = ws.IRState.RawY2; + _previousState.IRState.Size1 = ws.IRState.Size1; + _previousState.IRState.Size2 = ws.IRState.Size2; + _previousState.IRState.X1 = ws.IRState.X1; + _previousState.IRState.X2 = ws.IRState.X2; + _previousState.IRState.Y1 = ws.IRState.Y1; + _previousState.IRState.Y2 = ws.IRState.Y2; - private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) - { - BeginInvoke(new UpdateWiimoteStateDelegate(UpdateWiimoteState), args); + _previousState.NunchukState.C = ws.NunchukState.C; + _previousState.NunchukState.Z = ws.NunchukState.Z; + } - private void wm_WiimoteExtensionChanged(object sender, WiimoteExtensionChangedEventArgs args) + void WiimoteExtensionChanged(object sender, WiimoteExtensionChangedEventArgs args) { - BeginInvoke(new UpdateExtensionChangedDelegate(UpdateExtensionChanged), args); + if (args.Inserted) + _wiimote.SetReportType(Wiimote.InputReport.IRExtensionAccel, true); + else + _wiimote.SetReportType(Wiimote.InputReport.IRAccel, true); } + - - #endregion Implementation } Property changes on: trunk/plugins/IR Server Suite/IR Server Plugins/WiimoteLib ___________________________________________________________________ Name: svn:ignore + bin obj This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |