public SetLEDs ( bool led1, bool led2, bool led3, bool led4 ) : void | ||
led1 | bool | LED 1 |
led2 | bool | LED 2 |
led3 | bool | LED 3 |
led4 | bool | LED 4 |
Результат | void |
public override void Load() { IsEnabled = true; try { _wiimote = new Wiimote(); _wiimote.Connect(); _wiimote.InitializeMotionPlus(); _wiimote.WiimoteChanged += wiimote_WiimoteChanged; _wiimote.SetRumble(true); _wiimote.SetLEDs(true, false, false, true); Thread.Sleep(40); _wiimote.SetRumble(false); RawPosition = new Vector3D(); } catch (Exception exc) { Logger.Instance.Error(exc.Message, exc); try { _wiimote.SetLEDs(false, false, false, false); } catch (Exception exception) { Logger.Instance.Error(exception.Message, exception); } IsEnabled = false; } }
/// <summary> /// Service Start /// </summary> protected override void Start() { base.Start(); // setup internal notifications when we receive a OnWiimoteChanged event Activate(Arbiter.Receive(true, _internalStateChangedPort, InternalWiimoteChangedHandler)); // hookup event handlers _wm.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged); _wm.OnWiimoteExtensionChanged += new WiimoteExtensionChanged(wm_OnWiimoteExtensionChanged); // connect to wiimote and setup standard params _wm.Connect(); _wm.SetReportType(Wiimote.InputReport.IRAccel, true); _wm.SetLEDs(false, true, false, true); }
} // SetVibration #endregion #region Disconnect /// <summary> /// Disconnect the wiimote /// </summary> public void Disconnect() { if (wiimote != null) { wiimote.SetRumble(false); wiimote.SetLEDs(0); //wiimote.Disconnect(); // I have problems with this method. } } // Disconnect
/// <summary>Creates a 800x600 window with the specified title.</summary> public Game() : base(800, 600, GraphicsMode.Default, "OpenTK Quick Start Sample") { VSync = VSyncMode.On; _wm = new Wiimote(); _wm.WiimoteChanged += wm_WiimoteChanged; _wm.Connect(); _wm.SetReportType(InputReport.IRAccel, true); _wm.SetLEDs(false, true, true, false); }
} // Wiimote /// <summary> /// Assign the wiimoteLib object to the correct Wiimote object. /// </summary> private void AssignWiimote(WiimoteLib.Wiimote _wiimote) { wiimote = _wiimote; // Init the IR camera if (wiimote.WiimoteState.ExtensionType != ExtensionType.BalanceBoard) { wiimote.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true); } // Display the player number using the wiimote's lights wiimote.SetLEDs(playerIndex); isConnected = true; } // AssignWiimote
private void button_Connect_Click(object sender, EventArgs e) { try { // Find all connected Wii devices. var deviceCollection = new WiimoteCollection(); deviceCollection.FindAllWiimotes(); for (int i = 0; i < deviceCollection.Count; i++) { wiiDevice = deviceCollection[i]; // Device type can only be found after connection, so prompt for multiple devices. if (deviceCollection.Count > 1) { var devicePathId = new Regex("e_pid&.*?&(.*?)&").Match(wiiDevice.HIDDevicePath).Groups[1].Value.ToUpper(); var response = MessageBox.Show("Connect to HID " + devicePathId + " device " + (i + 1) + " of " + deviceCollection.Count + " ?", "Multiple Wii Devices Found", MessageBoxButtons.YesNoCancel); if (response == DialogResult.Cancel) return; if (response == DialogResult.No) continue; } // Setup update handlers. wiiDevice.WiimoteChanged += wiiDevice_WiimoteChanged; wiiDevice.WiimoteExtensionChanged += wiiDevice_WiimoteExtensionChanged; // Connect and send a request to verify it worked. wiiDevice.Connect(); wiiDevice.SetReportType(InputReport.IRAccel, false); // FALSE = DEVICE ONLY SENDS UPDATES WHEN VALUES CHANGE! wiiDevice.SetLEDs(true, false, false, false); // Enable processing of updates. infoUpdateTimer.Enabled = true; // Prevent connect being pressed more than once. button_Connect.Enabled = false; //button_BluetoothAddDevice.Enabled = false; break; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Form1() { InitializeComponent(); //soundplayer Stream str = JetFighter2D.Resource2.Lost_Woods_Dubstep_Remix___Ephixa_Download_at_www; sp = new SoundPlayer(str); wm = new Wiimote(); wm.Connect(); wm.SetLEDs(true, false, true, false); wm.SetReportType(InputReport.Buttons, true); //connect Wiimote GV.wm.Connect(); GV.wm.SetLEDs(true, false, true, false); GV.wm.WiimoteChanged += new EventHandler<WiimoteChangedEventArgs>(Wiimote_changed); }
public WiiMotePlayer(LevelChangedEventArgs eventArgs, int id) : base(eventArgs, id, false) { while (true) { try { _wiimote = new Wiimote(); _wiimote.Connect(); break; } catch (WiimoteNotFoundException) { MessageBox.Show("Please ensure a wiimote is paired to your computer via Bluetooth, then press OK to try again"); } } _wiimote.SetLEDs(id + 1); }
private void Form1_Load(object sender, EventArgs e) { wm = wms[0]; if (wms.Count > 1) { checkBox3.Checked = true; remote2 = wms[1]; remote2.WiimoteChanged += new WiimoteChangedEventHandler(remote2_OnWiimoteChanged); } lblBattery2.Text = "---"; //add event listeners to changes in the wiiremote //fired for every input report - usually 100 times per second if acclerometer is enabled wm.WiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged); try { //connect to wii remote ////set what features you want to enable for the remote, look at Wiimote.InputReport for options wm.SetReportType(Wiimote.InputReport.IRAccel, true); //set wiiremote LEDs with this enumerated ID wm.SetLEDs(true, false, false, false); if (wms.Count > 1) { ////set what features you want to enable for the remote, look at Wiimote.InputReport for options remote2.SetReportType(Wiimote.InputReport.IRAccel, true); //set wiiremote LEDs with this enumerated ID remote2.SetLEDs(false, true, false, false); //fired when the extension is attached on unplugged remote2.WiimoteExtensionChanged += new WiimoteExtensionChangedEventHandler(wm_OnWiimoteExtensionChanged); } } catch (Exception x) { MessageBox.Show("Exception: " + x.Message); //this.Close(); } loadCalibrationData(); done = new bool[Form2.NUMBOXES]; for (int i = 0; i < Form2.NUMBOXES - 1; i++) done[i] = false; }
void MainWindowLoaded(object sender, System.Windows.RoutedEventArgs e) { try { wm = new Wiimote(); wm.WiimoteChanged += OnWiimoteChanged; wm.Connect(); wm.SetReportType(InputReport.IRAccel, true); wm.SetLEDs(false, false, false, false); } catch { wm = null; } }
static void ConnectWiimote() { wiimote = new Wiimote(); wiimote.Connect(); wiimote.SetLEDs(1); }
private void teardownWiimoteConnection(Wiimote pDevice) { if (pDevice != null) { pDeviceMutex.WaitOne(); pDevice.WiimoteChanged -= this.wiimoteChangedEventHandler; pDevice.WiimoteExtensionChanged -= this.wiimoteExtensionChangedEventHandler; int wiimoteid; if (pWiimoteMap.Keys.Contains(pDevice.HIDDevicePath)) { wiimoteid = this.pWiimoteMap[pDevice.HIDDevicePath].Status.ID; this.pWiimoteMap[pDevice.HIDDevicePath].Teardown(); this.pWiimoteMap.Remove(pDevice.HIDDevicePath); } else { wiimoteid = this.pWiimoteMap.Count + 1; } pDeviceMutex.ReleaseMutex(); pDevice.SetReportType(InputReport.Status, false); pDevice.SetRumble(false); pDevice.SetLEDs(true, true, true, true); // Close the connection and dispose of the device. pDevice.Disconnect(); pDevice.Dispose(); OnDisconnect(wiimoteid, this.pWiimoteMap.Count); } }
private void connectWiimote(Wiimote wiimote) { Console.WriteLine("Trying to connect " + wiimote.HIDDevicePath); // Try to establish a connection, enable the IR reader and flag some LEDs. wiimote.Connect(); wiimote.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true); new Timer(new TimerCallback(connectRumble), wiimote, 0, Timeout.Infinite); int id = this.getFirstFreeId(); wiimote.SetLEDs(id == 1, id == 2, id == 3, id == 4); WiimoteControl control = new WiimoteControl(id, wiimote); pDeviceMutex.WaitOne(); //Don't mess with the list of wiimotes if it is enumerating in an update pWiimoteMap[wiimote.HIDDevicePath] = control; pDeviceMutex.ReleaseMutex(); // Hook up device event handlers. wiimote.WiimoteChanged += this.wiimoteChangedEventHandler; wiimote.WiimoteExtensionChanged += this.wiimoteExtensionChangedEventHandler; OnConnect(id, this.pWiimoteMap.Count); }
public void OnCreateDevice(object sender, EventArgs e) { Device dev = (Device)sender; textSprite = new Sprite(dev); statsFont = ResourceCache.GetGlobalInstance().CreateFont(dev, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch, "Arial"); //init cursors mouseCursor = new CrosshairCursor(dev, 0x00ff00, .04f); wiiCursor1 = new CrosshairCursor(dev, 0x00ff00, .04f); wiiCursor2 = new CrosshairCursor(dev, 0x0000ff, .04f); wiiCursor3 = new CrosshairCursor(dev, 0xff0000, .04f); wiiCursor4 = new CrosshairCursor(dev, 0xffff00, .04f); CreateGridGeometry(dev); CreateBackgroundGeometry(dev); CreateTargetGeometry(dev); InitTargets(); LoadTexture(); LoadBackground(); if (doWiimote) { try { if (doWiimote2) { showMouseCursor = true; remote2 = new Wiimote(); remote2.Connect(); remote2.SetReportType(Wiimote.InputReport.IRAccel, true); remote2.GetBatteryLevel(); remote2.SetLEDs(true, true, false, false); remote2.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged2); } remote = new Wiimote(); remote.Connect(); remote.SetReportType(Wiimote.InputReport.IRAccel, true); remote.GetBatteryLevel(); remote.SetLEDs(true, false, false, false); remote.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged); } catch (Exception x) { MessageBox.Show("Cannot find a wii remote: " + x.Message); doWiimote = false; } } }
/// <summary> /// Initialize the wiimote and nunchuk if it plugged /// </summary> public bool Initialize() { if (_wiimote == null) { try { _wiimote = new Wiimote(); _wiimote.WiimoteChanged += wiimote_WiimoteChanged; _wiimote.WiimoteExtensionChanged += wiimote_WiimoteExtensionChanged; _wiimote.Connect(); _wiimote.SetReportType(InputReport.IRAccel, true); _wiimote.SetLEDs(true, false, false, true); IsAvailable = true; } catch (Exception ex) { Console.Error.WriteLine(ex.Message); _wiimote = null; IsAvailable = false; } } return IsAvailable; }
/// <summary> /// Start the IR Server plugin. /// </summary> public override void Start() { LoadSettings(); _wiimote = new Wiimote(); try { _wiimote.WiimoteChanged += WiimoteChanged; _wiimote.WiimoteExtensionChanged += WiimoteExtensionChanged; _wiimote.Connect(); _wiimote.SetReportType(InputReport.IRAccel, true); _wiimote.SetLEDs(_led1, _led2, _led3, _led4); _wiimote.SetRumble(false); } catch { throw; } finally { _wiimote.Dispose(); _wiimote = null; } }
//will try to connect to a second wiimote if checked private void checkBox3_CheckedChanged(object sender, EventArgs e) { secondwiimote = checkBox3.Checked; if (checkBox3.Checked) { wms = Wiimote.GetConnectedWiimotes(); if (wms.Count > 1) { remote2 = wms[1]; remote2.WiimoteChanged += new WiimoteChangedEventHandler(remote2_OnWiimoteChanged); remote2.SetReportType(Wiimote.InputReport.IRAccel, true); remote2.SetLEDs(false, true, false, false); } else { MessageBox.Show("There is no second Wiimote connected"); checkBox3.Checked = false; } } if (!checkBox3.Checked) { if (wms.Count > 1) { remote2.SetLEDs(true, true, true, true); remote2.Disconnect(); } lblBattery2.Text = "---"; pbBattery2.Value = 0; } }
private void seachWiimote() { // find all wiimotes connected to the system WiimoteCollection wiimoteCollection = new WiimoteCollection(); //while (canSearch) //{ try { wiimoteCollection.FindAllWiimotes(); } catch (WiimoteNotFoundException ex) { //MessageBox.Show(ex.Message, "Wiimote not found error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (WiimoteException ex) { //MessageBox.Show(ex.Message, "Wiimote error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { //MessageBox.Show(ex.Message, "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (wiimoteCollection.Count == 1) { Connected = true; wiimote = wiimoteCollection[0]; // connect it and set it up as always wiimote.WiimoteChanged += wiimoteChanged; wiimote.WiimoteExtensionChanged += wiimoteExtensionChanged; wiimote.Connect(); if (wiimote.WiimoteState.ExtensionType != ExtensionType.BalanceBoard) wiimote.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true); wiimote.SetLEDs(false, true, true, false); } else { Connected = false; } //} }