-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiimoteInfo.cs
369 lines (313 loc) · 20.2 KB
/
WiimoteInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
//////////////////////////////////////////////////////////////////////////////////
// MultipleWiimoteForm.cs
// Managed Wiimote Library Tester
// Written by Brian Peek (http://www.brianpeek.com/)
// for MSDN's Coding4Fun (http://msdn.microsoft.com/coding4fun/)
// Visit http://blogs.msdn.com/coding4fun/archive/2007/03/14/1879033.aspx
// and http://www.codeplex.com/WiimoteLib
// for more information
//////////////////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Net.Sockets;
using WiimoteLib;
namespace WiimoteTest
{
public partial class WiimoteInfo : UserControl
{
private delegate void UpdateWiimoteStateDelegate(WiimoteChangedEventArgs args);
private delegate void UpdateExtensionChangedDelegate(WiimoteExtensionChangedEventArgs args);
private String lastMessageSent;
private Bitmap b = new Bitmap(256, 192, PixelFormat.Format24bppRgb);
private Graphics g;
private Wiimote mWiimote;
public WiimoteInfo()
{
InitializeComponent();
g = Graphics.FromImage(b);
lastMessageSent = "512,384,512,384";
}
public WiimoteInfo(Wiimote wm) : this()
{
mWiimote = wm;
}
public void UpdateState(WiimoteChangedEventArgs args)
{
BeginInvoke(new UpdateWiimoteStateDelegate(UpdateWiimoteChanged), args);
}
public void UpdateExtension(WiimoteExtensionChangedEventArgs args)
{
BeginInvoke(new UpdateExtensionChangedDelegate(UpdateExtensionChanged), args);
}
private void chkLED_CheckedChanged(object sender, EventArgs e)
{
mWiimote.SetLEDs(chkLED1.Checked, chkLED2.Checked, chkLED3.Checked, chkLED4.Checked);
}
private void chkRumble_CheckedChanged(object sender, EventArgs e)
{
mWiimote.SetRumble(chkRumble.Checked);
}
private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
{
WiimoteState ws = args.WiimoteState;
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);
lblAccel.Text = ws.AccelState.Values.ToString();
chkLED1.Checked = ws.LEDState.LED1;
chkLED2.Checked = ws.LEDState.LED2;
chkLED3.Checked = ws.LEDState.LED3;
chkLED4.Checked = ws.LEDState.LED4;
switch(ws.ExtensionType)
{
case ExtensionType.Nunchuk:
lblChuk.Text = ws.NunchukState.AccelState.Values.ToString();
lblChukJoy.Text = ws.NunchukState.Joystick.ToString();
//System.Console.WriteLine(ws.NunchukState.AccelState.Values.ToString()); GET nunchuk accel
//System.Console.WriteLine(ws.NunchukState.Joystick.ToString()); GET nunchuk joy
chkC.Checked = ws.NunchukState.C;
chkZ.Checked = ws.NunchukState.Z;
//AsynchronousClient.Send(StateObject.workSocket, ws.NunchukState.Joystick.ToString() + '\n');
break;
case 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);
lblCCJoy1.Text = ws.ClassicControllerState.JoystickL.ToString();
lblCCJoy2.Text = ws.ClassicControllerState.JoystickR.ToString();
lblTriggerL.Text = ws.ClassicControllerState.TriggerL.ToString();
lblTriggerR.Text = ws.ClassicControllerState.TriggerR.ToString();
break;
case ExtensionType.Guitar:
clbGuitarButtons.SetItemChecked(0, ws.GuitarState.FretButtonState.Green);
clbGuitarButtons.SetItemChecked(1, ws.GuitarState.FretButtonState.Red);
clbGuitarButtons.SetItemChecked(2, ws.GuitarState.FretButtonState.Yellow);
clbGuitarButtons.SetItemChecked(3, ws.GuitarState.FretButtonState.Blue);
clbGuitarButtons.SetItemChecked(4, ws.GuitarState.FretButtonState.Orange);
clbGuitarButtons.SetItemChecked(5, ws.GuitarState.ButtonState.Minus);
clbGuitarButtons.SetItemChecked(6, ws.GuitarState.ButtonState.Plus);
clbGuitarButtons.SetItemChecked(7, ws.GuitarState.ButtonState.StrumUp);
clbGuitarButtons.SetItemChecked(8, ws.GuitarState.ButtonState.StrumDown);
clbTouchbar.SetItemChecked(0, ws.GuitarState.TouchbarState.Green);
clbTouchbar.SetItemChecked(1, ws.GuitarState.TouchbarState.Red);
clbTouchbar.SetItemChecked(2, ws.GuitarState.TouchbarState.Yellow);
clbTouchbar.SetItemChecked(3, ws.GuitarState.TouchbarState.Blue);
clbTouchbar.SetItemChecked(4, ws.GuitarState.TouchbarState.Orange);
lblGuitarJoy.Text = ws.GuitarState.Joystick.ToString();
lblGuitarWhammy.Text = ws.GuitarState.WhammyBar.ToString();
lblGuitarType.Text = ws.GuitarState.GuitarType.ToString();
break;
case ExtensionType.Drums:
clbDrums.SetItemChecked(0, ws.DrumsState.Red);
clbDrums.SetItemChecked(1, ws.DrumsState.Blue);
clbDrums.SetItemChecked(2, ws.DrumsState.Green);
clbDrums.SetItemChecked(3, ws.DrumsState.Yellow);
clbDrums.SetItemChecked(4, ws.DrumsState.Orange);
clbDrums.SetItemChecked(5, ws.DrumsState.Pedal);
clbDrums.SetItemChecked(6, ws.DrumsState.Minus);
clbDrums.SetItemChecked(7, ws.DrumsState.Plus);
lbDrumVelocity.Items.Clear();
lbDrumVelocity.Items.Add(ws.DrumsState.RedVelocity);
lbDrumVelocity.Items.Add(ws.DrumsState.BlueVelocity);
lbDrumVelocity.Items.Add(ws.DrumsState.GreenVelocity);
lbDrumVelocity.Items.Add(ws.DrumsState.YellowVelocity);
lbDrumVelocity.Items.Add(ws.DrumsState.OrangeVelocity);
lbDrumVelocity.Items.Add(ws.DrumsState.PedalVelocity);
lblDrumJoy.Text = ws.DrumsState.Joystick.ToString();
break;
case ExtensionType.BalanceBoard:
if(chkLbs.Checked)
{
lblBBTL.Text = ws.BalanceBoardState.SensorValuesLb.TopLeft.ToString();
lblBBTR.Text = ws.BalanceBoardState.SensorValuesLb.TopRight.ToString();
lblBBBL.Text = ws.BalanceBoardState.SensorValuesLb.BottomLeft.ToString();
lblBBBR.Text = ws.BalanceBoardState.SensorValuesLb.BottomRight.ToString();
lblBBTotal.Text = ws.BalanceBoardState.WeightLb.ToString();
}
else
{
lblBBTL.Text = ws.BalanceBoardState.SensorValuesKg.TopLeft.ToString();
lblBBTR.Text = ws.BalanceBoardState.SensorValuesKg.TopRight.ToString();
lblBBBL.Text = ws.BalanceBoardState.SensorValuesKg.BottomLeft.ToString();
lblBBBR.Text = ws.BalanceBoardState.SensorValuesKg.BottomRight.ToString();
lblBBTotal.Text = ws.BalanceBoardState.WeightKg.ToString();
}
lblCOG.Text = ws.BalanceBoardState.CenterOfGravity.ToString();
break;
}
g.Clear(Color.Black);
/*
String firstCoordinate = UpdateIR(ws.IRState.IRSensors[0], lblIR1, lblIR1Raw, chkFound1, Color.Red);
String secondCoordinate = UpdateIR(ws.IRState.IRSensors[1], lblIR1, lblIR1Raw, chkFound2, Color.Blue);
UpdateIR(ws.IRState.IRSensors[2], lblIR3, lblIR3Raw, chkFound3, Color.Yellow);
UpdateIR(ws.IRState.IRSensors[3], lblIR4, lblIR4Raw, chkFound4, Color.Orange);
String message = firstCoordinate + "," + secondCoordinate;
/*
String message = firstCoordinate + "," + secondCoordinate;
//UpdateIR(ws.IRState.IRSensors[1], lblIR2, lblIR2Raw, chkFound2, Color.Blue);
if (firstCoordinate != null && secondCoordinate != null && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[1].RawPosition.X) > 30)
AsynchronousClient.Send(StateObject.workSocket, message + "\n");
System.Console.WriteLine(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[1].RawPosition.X);
UpdateIR(ws.IRState.IRSensors[2], lblIR3, lblIR3Raw, chkFound3, Color.Yellow);
UpdateIR(ws.IRState.IRSensors[3], lblIR4, lblIR4Raw, chkFound4, Color.Orange);
if(ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
g.DrawEllipse(new Pen(Color.Green), (int)(ws.IRState.RawMidpoint.X / 4), (int)(ws.IRState.RawMidpoint.Y / 4), 2, 2);
*/
//if(ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[1].RawPosition.X) > 100)
// AsynchronousClient.Send(StateObject.workSocket, message + "\n");
/*
if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[2].Found)
AsynchronousClient.Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[0], ws.IRState.IRSensors[1], ws.IRState.IRSensors[2]) + "\n");
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[3].Found)
AsynchronousClient.Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[1], ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]) + "\n");
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[2].Found && ws.IRState.IRSensors[3].Found)
AsynchronousClient.Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[0], ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]) + "\n");
else if (ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[2].Found && ws.IRState.IRSensors[3].Found)
AsynchronousClient.Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[1], ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]) + "\n");
else if(ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[1].RawPosition.X) > 100)
AsynchronousClient.Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[0], ws.IRState.IRSensors[1]));
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[2].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[2].RawPosition.X) > 100)
AsynchronousClient.Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[0], ws.IRState.IRSensors[2]));
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[3].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[3].RawPosition.X) > 100)
AsynchronousClient.Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[0], ws.IRState.IRSensors[3]));
else if (ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[2].Found && Math.Abs(ws.IRState.IRSensors[1].RawPosition.X - ws.IRState.IRSensors[2].RawPosition.X) > 100)
AsynchronousClient.Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[1], ws.IRState.IRSensors[2]));
else if (ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[3].Found && Math.Abs(ws.IRState.IRSensors[1].RawPosition.X - ws.IRState.IRSensors[3].RawPosition.X) > 100)
AsynchronousClient.Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[1], ws.IRState.IRSensors[3]));
else if (ws.IRState.IRSensors[2].Found && ws.IRState.IRSensors[3].Found && Math.Abs(ws.IRState.IRSensors[2].RawPosition.X - ws.IRState.IRSensors[3].RawPosition.X) > 100)
AsynchronousClient.Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]));
*/
if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[2].Found)
Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[0], ws.IRState.IRSensors[1], ws.IRState.IRSensors[2]) + "\n");
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[3].Found)
Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[1], ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]) + "\n");
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[2].Found && ws.IRState.IRSensors[3].Found)
Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[0], ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]) + "\n");
else if (ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[2].Found && ws.IRState.IRSensors[3].Found)
Send(StateObject.workSocket, calculateMaxDist(ws.IRState.IRSensors[1], ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]) + "\n");
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[1].RawPosition.X) > 100)
Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[0], ws.IRState.IRSensors[1]));
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[2].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[2].RawPosition.X) > 100)
Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[0], ws.IRState.IRSensors[2]));
else if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[3].Found && Math.Abs(ws.IRState.IRSensors[0].RawPosition.X - ws.IRState.IRSensors[3].RawPosition.X) > 100)
Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[0], ws.IRState.IRSensors[3]));
else if (ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[2].Found && Math.Abs(ws.IRState.IRSensors[1].RawPosition.X - ws.IRState.IRSensors[2].RawPosition.X) > 100)
Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[1], ws.IRState.IRSensors[2]));
else if (ws.IRState.IRSensors[1].Found && ws.IRState.IRSensors[3].Found && Math.Abs(ws.IRState.IRSensors[1].RawPosition.X - ws.IRState.IRSensors[3].RawPosition.X) > 100)
Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[1], ws.IRState.IRSensors[3]));
else if (ws.IRState.IRSensors[2].Found && ws.IRState.IRSensors[3].Found && Math.Abs(ws.IRState.IRSensors[2].RawPosition.X - ws.IRState.IRSensors[3].RawPosition.X) > 100)
Send(StateObject.workSocket, getTwoPoints(ws.IRState.IRSensors[2], ws.IRState.IRSensors[3]));
pbIR.Image = b;
pbBattery.Value = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery);
lblBattery.Text = ws.Battery.ToString();
lblDevicePath.Text = "Device Path: " + mWiimote.HIDDevicePath;
}
private String UpdateIR(IRSensor irSensor, Label lblNorm, Label lblRaw, CheckBox chkFound, Color color)
{
chkFound.Checked = irSensor.Found;
if(irSensor.Found)
{
//AsynchronousClient.Send(StateObject.workSocket, irSensor.RawPosition.X.ToString() + ',');
//AsynchronousClient.Send(StateObject.workSocket, "69" + '\n');
//System.Console.WriteLine(irSensor + irSensor.RawPosition.ToString());
lblNorm.Text = irSensor.Position.ToString() + ", " + irSensor.Size;
lblRaw.Text = irSensor.RawPosition.ToString();
g.DrawEllipse(new Pen(color), (int)(irSensor.RawPosition.X / 4), (int)(irSensor.RawPosition.Y / 4),
irSensor.Size+1, irSensor.Size+1);
return irSensor.RawPosition.X.ToString() + "," + irSensor.RawPosition.Y.ToString();
}
return null;
}
private String calculateMaxDist(IRSensor first, IRSensor second, IRSensor third)
{
int firstX = first.RawPosition.X;
int secondX = second.RawPosition.X;
int thirdX = third.RawPosition.X;
int firstY = first.RawPosition.Y;
int secondY = second.RawPosition.Y;
int thirdY = third.RawPosition.Y;
g.DrawEllipse(new Pen(Color.Red), (int)(first.RawPosition.X / 4), (int)(first.RawPosition.Y / 4),
first.Size + 1, first.Size + 1);
g.DrawEllipse(new Pen(Color.Blue), (int)(second.RawPosition.X / 4), (int)(second.RawPosition.Y / 4),
second.Size + 1, second.Size + 1);
g.DrawEllipse(new Pen(Color.Yellow), (int)(third.RawPosition.X / 4), (int)(third.RawPosition.Y / 4),
third.Size + 1, third.Size + 1);
double firstSecondDist = Math.Sqrt(Math.Pow((firstX - secondX), 2) + (Math.Pow((firstY - secondY), 2)));
double secondThirdDist = Math.Sqrt(Math.Pow((secondX - thirdX), 2) + (Math.Pow((secondY - thirdY), 2)));
double firstThirdDist = Math.Sqrt(Math.Pow((firstX - thirdX), 2) + (Math.Pow((firstY - thirdY), 2)));
if (firstSecondDist > secondThirdDist && firstSecondDist > firstThirdDist)
return firstX.ToString() + "," + firstY.ToString() + "," + secondX.ToString() + "," + secondY.ToString();
if(secondThirdDist > firstSecondDist && secondThirdDist > firstThirdDist)
return secondX.ToString() + "," + secondY.ToString() + "," + thirdX.ToString() + "," + thirdY.ToString();
//firstThirdDist is largest
return firstX.ToString() + "," + firstY.ToString() + "," + thirdX.ToString() + "," + thirdY.ToString();
}
private String getTwoPoints(IRSensor first, IRSensor second)
{
g.DrawEllipse(new Pen(Color.Red), (int)(first.RawPosition.X / 4), (int)(first.RawPosition.Y / 4),
first.Size + 1, first.Size + 1);
g.DrawEllipse(new Pen(Color.Blue), (int)(second.RawPosition.X / 4), (int)(second.RawPosition.Y / 4),
second.Size + 1, second.Size + 1);
return first.RawPosition.X.ToString() + "," + first.RawPosition.Y.ToString() + "," + second.RawPosition.X.ToString() + "," + second.RawPosition.Y.ToString() + '\n';
}
private void Send(Socket client, String message)
{
String[] messageArgs = message.Split(',');
int inX1 = Convert.ToInt16(messageArgs[0]);
int inY1 = Convert.ToInt16(messageArgs[1]);
int inX2 = Convert.ToInt16(messageArgs[2]);
int inY2 = Convert.ToInt16(messageArgs[3]);
String[]oldArgs = lastMessageSent.Split(',');
int oldX1 = Convert.ToInt16(oldArgs[0]);
int oldY1 = Convert.ToInt16(oldArgs[1]);
int oldX2 = Convert.ToInt16(oldArgs[2]);
int oldY2 = Convert.ToInt16(oldArgs[3]);
if (inX1 > inX2)
message = Swap(inX1, inY1, inX2, inY2);
if (Math.Abs(inX1 - oldX1) + Math.Abs(inX2 - oldX2) + Math.Abs(inY1 - oldY1) + Math.Abs(inY2 - oldY2) < 1500)
{
AsynchronousClient.Send(StateObject.workSocket, message);
lastMessageSent = message;
}
else
{
AsynchronousClient.Send(StateObject.workSocket, lastMessageSent);
}
}
private void UpdateExtensionChanged(WiimoteExtensionChangedEventArgs args)
{
chkExtension.Text = args.ExtensionType.ToString();
chkExtension.Checked = args.Inserted;
}
private String Swap(int X1, int Y1, int X2, int Y2)
{
return X2.ToString() + ',' + Y2.ToString() + ',' + X1.ToString() + ',' + Y1.ToString() + '\n';
}
public Wiimote Wiimote
{
set { mWiimote = value; }
}
}
}