コード例 #1
0
        protected void ParseStatus(byte[] buff)
        {
            bool extensionConnected = (buff[3] & 0x02) != 0;

            _IsSpeakerEnabled = (buff[3] & 0x04) != 0;
            _IrSensorEnabled  = (buff[3] & 0x08) != 0;
            _Leds             =
                ((buff[3] & 0x10) == 0 ? WiimoteLeds.None : WiimoteLeds.Led1) |
                ((buff[3] & 0x20) == 0 ? WiimoteLeds.None : WiimoteLeds.Led2) |
                ((buff[3] & 0x40) == 0 ? WiimoteLeds.None : WiimoteLeds.Led3) |
                ((buff[3] & 0x80) == 0 ? WiimoteLeds.None : WiimoteLeds.Led4);

            BatteryLevel = buff[6];

            if (extensionConnected && _Extension == null)
            {
                InitializeExtension();
            }
            else if (_Extension != null && !extensionConnected)
            {
                ReportingMode = ReportingMode.None;
                if (ExtensionDetached != null)
                {
                    ExtensionDetached(this, new WiimoteExtensionEventArgs(_Extension));
                }
                _Extension = null;
            }
        }
コード例 #2
0
 static void wiimote_ExtensionAttached(object sender, WiimoteExtensionEventArgs e)
 {
     IWiimote wiimote = (IWiimote)sender;
     
     // We can retrieve the attached extension by doing the following:
     IWiimoteExtension extension = e.Extension;
     // The extension is also available through 'wiimote.Extension'.
     
     // Here we can check what type of extension the attached extension is.
     // In this example we will only cover the Nunchuk, but we can also check for other available extensions.
     if (extension is NunchukExtension)
     {
         wiimote.SetReportingMode(ReportingMode.ButtonsAccelerometer16Extension);
         Console.WriteLine("A nunchuk attached to the Wiimote.");
     }
     // A few 'dummy-extensions' are available to detect various undefined situations.
     else if (extension is InvalidExtension)
     {
         Console.WriteLine("An extension was partially connected or the extension was erroneous.");
     }
     
     // UnknownExtension is a dummy-extension that that the attached extension
     // is not supported by Wii Device Library (or any other extension that is registered in WiimoteExtensionRegistry).
     else if (extension is UnknownExtension)
     {
         Console.WriteLine("An extension was connected, but was not recognized by Wii Device Library.");
     }
     else
     {
         Console.WriteLine("An extension was connected, but was not recognized by this example.");
     }
     wiimote.SetReportingMode(wiimote.ReportingMode);
 }
コード例 #3
0
 static void wiimote_ExtensionDetached(object sender, WiimoteExtensionEventArgs e)
 {
     IWiimote wiimote = (IWiimote)sender;
     IWiimoteExtension extension = e.Extension;
     if (extension is NunchukExtension)
     {
         Console.WriteLine("A nunchuk was detached from the Wiimote.");
     }
     wiimote.SetReportingMode(wiimote.ReportingMode);
 }
コード例 #4
0
        protected void InitializeExtension()
        {
            try
            {
                WriteMemory(0x04a40040, 0); // Set the encryption-key to 0.
            }
            catch (TimeoutException)
            {
                if (IsConnected)
                {
                    throw;
                }
                return;
            }
            byte[] extensionTypeBytes = ReadMemory(0x04a400fe, 2);
            extensionTypeBytes[0] = (byte)((extensionTypeBytes[0] ^ 0x17) + 0x17 & 0xFF);
            extensionTypeBytes[1] = (byte)((extensionTypeBytes[1] ^ 0x17) + 0x17 & 0xFF);
            ushort            extensionType = (ushort)(extensionTypeBytes[1] << 8 | extensionTypeBytes[0]);
            IWiimoteExtension newExtension;

            switch (extensionType)
            {
            case 0x2e2e:
                newExtension = null;
                break;

            case 0xffff:
                newExtension = new InvalidExtension(this);
                break;

            default:
                IWiimoteExtensionFactory extensionFactory;
                if (WiimoteExtensionRegistry.TryGetValue(extensionType, out extensionFactory))
                {
                    newExtension = extensionFactory.Create(this);
                }
                else
                {
                    newExtension = new UnknownExtension(this);
                }
                break;
            }
            ReportingMode = ReportingMode.None;
            _Extension    = newExtension;
            if (_Extension != null)
            {
                if (ExtensionAttached != null)
                {
                    ExtensionAttached(this, new WiimoteExtensionEventArgs(_Extension));
                }
            }
        }
コード例 #5
0
        protected void DetachExtension()
        {
            if (Extension == null)
            {
                throw new InvalidOperationException("Can't detach extension: No extension is connected.");
            }

            ReportingMode = ReportingMode.None;
            _Extension.Detached();
            if (ExtensionDetached != null)
            {
                ExtensionDetached(this, new WiimoteExtensionEventArgs(_Extension));
            }
            _Extension = null;
        }
コード例 #6
0
        void Wiimote_ExtensionAttached(object sender, WiimoteExtensionEventArgs e)
        {
            IWiimoteExtension wiimoteExtension = Wiimote.Extension;

            Invoke(new Action <IWiimoteExtension>(delegate(IWiimoteExtension extension)
            {
                Control extensionControl = null;
                if (extension is NunchukExtension)
                {
                    NunchukUserControl nunchukUC = new NunchukUserControl();
                    nunchukUC.Nunchuk            = (NunchukExtension)extension;
                    extensionControl             = nunchukUC;
                }
                else if (extension is ClassicControllerExtension)
                {
                    ClassicControllerUserControl classicControllerUC = new ClassicControllerUserControl();
                    classicControllerUC.ClassicController            = (ClassicControllerExtension)extension;
                    extensionControl = classicControllerUC;
                }
                else if (extension is GuitarExtension)
                {
                    GuitarUserControl guitarUC = new GuitarUserControl();
                    guitarUC.Guitar            = (GuitarExtension)extension;
                    extensionControl           = guitarUC;
                }

                ExtensionControl = (IExtensionControl)extensionControl;
                if (extensionControl != null)
                {
                    extensionBox.Height = extensionControl.Height + 50;
                    extensionBox.Text   = extension.GetType().Name;
                    extensionBox.Controls.Add(extensionControl);
                    extensionControl.Dock = DockStyle.Fill;
                    this.Height           = extensionBox.Top + extensionBox.Height;
                }
                reportingmodeBox.SelectedItem = Wiimote.ReportingMode;
            }), wiimoteExtension);
        }
コード例 #7
0
 public WiimoteExtensionEventArgs(IWiimoteExtension extension)
 {
     _Extension = extension;
 }
コード例 #8
0
 public WiimoteExtensionEventArgs(IWiimoteExtension extension)
 {
     _Extension = extension;
 }
コード例 #9
0
        protected void ParseStatus(byte[] buff)
        {
            bool extensionConnected = (buff[3] & 0x02) != 0;

            _IsSpeakerEnabled = (buff[3] & 0x04) != 0;
            _IrSensorEnabled = (buff[3] & 0x08) != 0;
            _Leds =
                ((buff[3] & 0x10) == 0 ? WiimoteLeds.None : WiimoteLeds.Led1) |
                ((buff[3] & 0x20) == 0 ? WiimoteLeds.None : WiimoteLeds.Led2) |
                ((buff[3] & 0x40) == 0 ? WiimoteLeds.None : WiimoteLeds.Led3) |
                ((buff[3] & 0x80) == 0 ? WiimoteLeds.None : WiimoteLeds.Led4);

            BatteryLevel = buff[6];

            if (extensionConnected && _Extension == null)
                InitializeExtension();
            else if (_Extension != null && !extensionConnected)
            {
                ReportingMode = ReportingMode.None;
                if(ExtensionDetached != null)
                    ExtensionDetached(this, new WiimoteExtensionEventArgs(_Extension));
                _Extension = null;
            }
        }
コード例 #10
0
 protected void InitializeExtension()
 {
     try
     {
         WriteMemory(0x04a40040, 0); // Set the encryption-key to 0.
     }
     catch (TimeoutException)
     {
         if (IsConnected)
             throw;
         return;
     }
     byte[] extensionTypeBytes = ReadMemory(0x04a400fe, 2);
     extensionTypeBytes[0] = (byte)((extensionTypeBytes[0] ^ 0x17) + 0x17 & 0xFF);
     extensionTypeBytes[1] = (byte)((extensionTypeBytes[1] ^ 0x17) + 0x17 & 0xFF);
     ushort extensionType = (ushort)(extensionTypeBytes[1] << 8 | extensionTypeBytes[0]);
     IWiimoteExtension newExtension;
     switch (extensionType)
     {
         case 0x2e2e:
             newExtension = null;
             break;
         case 0xffff:
             newExtension = new InvalidExtension(this);
             break;
         default:
             IWiimoteExtensionFactory extensionFactory;
             if (WiimoteExtensionRegistry.TryGetValue(extensionType, out extensionFactory))
                 newExtension = extensionFactory.Create(this);
             else
                 newExtension = new UnknownExtension(this);
             break;
     }
     ReportingMode = ReportingMode.None;
     _Extension = newExtension;
     if(_Extension != null)
     {
         if(ExtensionAttached != null)
             ExtensionAttached(this, new WiimoteExtensionEventArgs(_Extension));
     }
 }
コード例 #11
0
        protected void DetachExtension()
        {
            if (Extension == null)
                throw new InvalidOperationException("Can't detach extension: No extension is connected.");

            ReportingMode = ReportingMode.None;
            _Extension.Detached();
            if(ExtensionDetached != null)
                ExtensionDetached(this, new WiimoteExtensionEventArgs(_Extension));
            _Extension = null;
        }