Advertisement
Guest User

Wiimotelib Disconnect Event

a guest
Mar 15th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. --- Wiimote.cs-revBASE.svn000.tmp.cs    Fri Mar 15 21:18:19 2013
  2. +++ Wiimote.cs  Fri Mar 15 21:03:20 2013
  3. @@ -33,6 +33,11 @@
  4.         /// </summary>
  5.         public event EventHandler<WiimoteExtensionChangedEventArgs> WiimoteExtensionChanged;
  6.  
  7. +        /// <summary>
  8. +        /// Event raised when a Wiimote is disconnected.
  9. +        /// </summary>
  10. +        public event EventHandler<EventArgs> WiimoteDisconnect;
  11. +
  12.         // VID = Nintendo, PID = Wiimote
  13.         private const int VID = 0x057e;
  14.         private const int PID = 0x0306;
  15. @@ -307,26 +312,30 @@
  16.             // grab the byte buffer
  17.             byte[] buff = (byte[])ar.AsyncState;
  18.  
  19. -           try
  20. -           {
  21. -               // end the current read
  22. -               mStream.EndRead(ar);
  23. +            try {
  24. +                // end the current read
  25. +                mStream.EndRead(ar);
  26.  
  27. -               // parse it
  28. -               if(ParseInputReport(buff))
  29. -               {
  30. -                   // post an event
  31. -                   if(WiimoteChanged != null)
  32. -                       WiimoteChanged(this, new WiimoteChangedEventArgs(mWiimoteState));
  33. -               }
  34. +                // parse it
  35. +                if (ParseInputReport(buff)) {
  36. +                    // post an event
  37. +                    if (WiimoteChanged != null)
  38. +                        WiimoteChanged(this, new WiimoteChangedEventArgs(mWiimoteState));
  39. +                }
  40.  
  41. -               // start reading again
  42. -               BeginAsyncRead();
  43. -           }
  44. -           catch(OperationCanceledException)
  45. -           {
  46. -               Debug.WriteLine("OperationCanceledException");
  47. -           }
  48. +                // start reading again
  49. +                BeginAsyncRead();
  50. +            }
  51. +            catch (IOException) {
  52. +                Debug.WriteLine("IOException");
  53. +
  54. +                if (WiimoteDisconnect != null) {
  55. +                    WiimoteDisconnect(this, new EventArgs());
  56. +                }
  57. +            }
  58. +            catch (OperationCanceledException) {
  59. +                Debug.WriteLine("OperationCanceledException");
  60. +            }
  61.         }
  62.  
  63.         /// <summary>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement