private void Form1_Load(object sender, EventArgs e) { bool isOk = true; //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); //fired when the extension is attached on unplugged wm.WiimoteExtensionChanged += new WiimoteExtensionChangedEventHandler(wm_OnWiimoteExtensionChanged); try { //--- connect to wii remote wm.Connect(); //--- 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); } catch (Exception x) { MessageBox.Show("Exception: " + x.Message); this.Close(); isOk = false; } // 20200214 js added if (isOk) { loadCalibrationData(); } }
private void Form1_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; l = new Lab(); pelota = l.p[1]; pcbPelota.Location = pelota.p; try { wm = new Wiimote(); } catch (System.IO.IOException ioe) { Console.WriteLine("No es posible ejecutar la aplicación: " + ioe.Message); } try { wm.Connect(); wm.SetReportType(InputReport.IRAccel, true); wm.WiimoteChanged += new System.EventHandler <WiimoteChangedEventArgs>(wm_WiimoteChanged); } catch (Exception wnfe) { Console.WriteLine("No es posible ejecutar la aplicación: " + wnfe.Message); } }
public WiimoteFunctionality(Action <int> SolicitudCambioNúmeroPosActual, Action <string> MoverSeleccion, Action <string> MostrarMensaje, Action BorrarNumero, Action DeshacerMovimiento) { wm = new Wiimote(); this.MostrarMensaje = MostrarMensaje; this.SolicitudCambioNúmeroPosActual = SolicitudCambioNúmeroPosActual; this.MoverSeleccion = MoverSeleccion; this.BorrarNumero = BorrarNumero; this.DeshacerMovimiento = DeshacerMovimiento; gestureCapturer = new GestureCapturer(); gestureRecognizer = new GestureRecognizer(); CargarGestos(); wm.WiimoteChanged += Wm_WiimoteChanged; try { wm.Connect(); } catch (Exception) { MostrarMensaje("El dispositivo Wiimote no está conectado. ¿Quieres seguir jugando sin él?"); } wm.SetReportType(InputReport.ButtonsAccel, true); gestureCapturer.GestureCaptured += GestureCapturer_GestureCaptured; gestureRecognizer.GestureRecognized += GestureRecognizer_GestureRecognized; }
private void connectbutton_Click(object sender, EventArgs e) { bool success = false; try { mWiimote.Connect(); mWiimote.SetReportType(InputReport.IRAccel, true); success = true; } catch { MessageBox.Show("Exception thrown by Connect() method."); } if (success) { if (mWiimote.WiimoteState.LEDState.LED1) { mWiimote.SetLEDs(false, true, false, false); } else { mWiimote.SetLEDs(true, false, false, false); } this.connectbutton.Enabled = false; this.disconnectbutton.Enabled = true; } }
public WiimoteInput(Wiimote wiimote) : base() { wiimote.Connect(); wiimote.WiimoteChanged += wiimote_WiimoteChanged; wiimote.WiimoteExtensionChanged += wiimote_WiimoteExtensionChanged; if (wiimote.WiimoteState.ExtensionType != ExtensionType.BalanceBoard) { wiimote.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true); } this.wiimote = wiimote; List <String> validAxes = new List <String>(); foreach (Axis axis in Enum.GetValues(typeof(Axis))) { validAxes.Add(axis.ToString()); } List <String> validButtons = new List <String>(); foreach (Button button in Enum.GetValues(typeof(Button))) { validButtons.Add(button.ToString()); } CreateMapping(validButtons, validAxes); }
internal static bool Initialize() { if (!ConfigManager.sWiimote) { return(false); } try { Wiimote = new Wiimote(); Wiimote.Connect(); } catch { NotificationManager.ShowMessage( "Could not find Wiimote. Please check connection then reenable in options.", Color.Red, 8000); ConfigManager.sWiimote.Value = false; Disconnect(); return(false); } NotificationManager.ShowMessage("Found Wiimote!", Color.YellowGreen, 6000); Wiimote.SetLEDs(true, true, true, true); return(true); }
/// <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; } }
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; } }
public Form1() { // Get a console interface. AllocConsole(); // All the rest of this is from the wiimotelib examples. InitializeComponent(); // setup the event to handle state changes wm.WiimoteChanged += wm_WiimoteChanged; // setup the event to handle insertion/removal of extensions wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged; // connect to the Wiimote wm.Connect(); // set the report type to return the IR sensor and accelerometer data (buttons always come back) // set the report type to return the IR sensor and accelerometer data (buttons always come back) wm.SetReportType(InputReport.ButtonsExtension, true); //wm.SetReportType(Wiimote.InputReport.IRAccel, true); if (wm.WiimoteState.ExtensionType == ExtensionType.Drums) { Console.WriteLine("Drums"); } }
private void Form1_Load(object sender, EventArgs e) { mWiimote = new Wiimote(); try { // Wiiリモコンへの接続 mWiimote.WiimoteChanged += (s, args) => UpdateState(args); mWiimote.WiimoteExtensionChanged += (s, args) => UpdateExtension(args); mWiimote.Connect(); mWiimote.SetReportType(InputReport.IRExtensionAccel, true); mWiimote.SetLEDs(false, true, true, false); } 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); } // 初期化 for (int i = 0; i < 3; i++) { axis_history.Add(new Queue <float>()); } this.Size = new System.Drawing.Size(560, 400); }
Wiimote connectController(Wiimote wiiDeviceInc) { try { // Find all connected Wii devices. var deviceCollection = new WiimoteCollection(); deviceCollection.FindAllWiimotes(); //printMsg("Device count: "+deviceCollection.Count.ToString()); Wiimote wiiDevice = deviceCollection[0]; // Device type can only be found after connection, so prompt for multiple devices. // 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); return(wiiDevice); } catch (Exception ex) { //ex.StackTrace(); return(null); } }
//----------------------------------------------------------------------- public override Action Start() { // This method is called just before script starts // Find and connect to all Wiimotes. Wiimotes must have been // previously attached via a bluetooth manager WiimoteCollection motes = new WiimoteCollection(); motes.FindAllWiimotes(); if (motes.Count > 0) { Buttons = new WiimoteLib.ButtonState[motes.Count]; // Connect and start each wiimote for (int i = 0; i < motes.Count; i++) { Wiimote wii = motes.ElementAt(i); wii.Connect(); // set the wiimote leds to the wiimote number wii.SetLEDs(i + 1); // set the wiimote leds to the wiimote number Buttons[i] = wii.WiimoteState.ButtonState; wii.WiimoteChanged += OnWiimoteChanged; // set the event handler wii.SetReportType(InputReport.Buttons, false); // start the data callbacks } Motes = motes; } else { throw new Exception("No Wiimotes found"); } return(null); }
public void Enable() { wm.Connect(); wm.SetReportType(InputReport.IRAccel, true); wm.GetStatus(); wm.SetLEDs(true, false, false, false); }
void dispatcharTimer11_Tick(object sender, EventArgs e) { cdtime++; countdown.Content = (3 - cdtime).ToString(); if (cdtime == 3) //スタート押されてると { countdown.Content = ""; dispatcharTimer11.Stop(); wiimote.Connect(); startbutton.Content = "ストップ"; game = true; dispatcharTimer.Start(); } }
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, 0xffffff, .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); int step = m_dwWidth / numGridlines; gridBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 4 * (numGridlines + 2), dev, 0, CustomVertex.PositionColored.Format, Pool.Managed); CustomVertex.PositionColored[] verts2; verts2 = (CustomVertex.PositionColored[])gridBuffer.Lock(0, 0); // Lock the buffer (which will return our structs) int vertIndex = 0; int gridColor = 0x666666; for (int i = 0; i <= numGridlines * 2; i += 2) { verts2[vertIndex].Position = new Vector3((i * step / 2.0f) / m_dwWidth, 0.0f, 0.0f); verts2[vertIndex].Color = gridColor; vertIndex++; verts2[vertIndex].Position = new Vector3((i * step / 2.0f) / m_dwWidth, 1.0f, 0.0f); verts2[vertIndex].Color = gridColor; vertIndex++; } for (int i = 0; i <= numGridlines * 2; i += 2) { verts2[vertIndex].Position = new Vector3(0.0f, (i * step / 2.0f) / m_dwWidth, 0.0f); verts2[vertIndex].Color = gridColor; vertIndex++; verts2[vertIndex].Position = new Vector3(1.0f, (i * step / 2.0f) / m_dwWidth, 0.0f); verts2[vertIndex].Color = gridColor; vertIndex++; } gridBuffer.Unlock(); if (doWiimote) { try { 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> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { var wiimote = new Wiimote(); wiimote.Connect(); this.InitializeComponent(); this.Suspending += OnSuspending; }
public bool ConnectWiimote() { try { wm.Connect(); } catch { return(false); } wm.SetReportType(InputReport.IRAccel, true); wm.SetLEDs(false, true, true, false); return(true); }
private bool irDetected = false; // 赤外線を検出しているか private void ConnectWiimote() { // Bluetooth 認識 var btutil = new BTUtil(); btutil.ShowDialog(); if (btutil.userClosed) { Debug.WriteLine("Exit -> BTUtil User Closed."); notifyIcon.Visible = false; Environment.Exit(0); } // Wiimote接続 mWiimote = new Wiimote(); try { mWiimote.WiimoteChanged += (s, args) => UpdateState(args); mWiimote.WiimoteExtensionChanged += (s, args) => UpdateExtension(args); mWiimote.Connect(); mWiimote.SetReportType(InputReport.IRExtensionAccel, true); mWiimote.SetLEDs(true, false, false, false); mWiimote.SetRumble(true); System.Threading.Thread.Sleep(200); mWiimote.SetRumble(false); } catch (Exception ex) { string msg; switch (ex) { case WiimoteNotFoundException _: msg = "Wiiリモコンを認識できませんでした。"; break; case WiimoteException _: msg = "Wiiリモコンに何らかのエラーが発生しました。"; break; default: msg = "予期せぬエラーが発生しました。"; break; } MessageBox.Show( msg, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error ); Environment.Exit(1); } }
private void button1_Click(object sender, RoutedEventArgs e) { wm.Connect(); wm.WiimoteChanged += wm_WiimoteChanged; wm.SetReportType(InputReport.IRExtensionAccel, true); wm.InitializeMotionPlus(); wm.SetLEDs(1); this.Hide(); }
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); } }
// ------------------------------------------------------------------------------------------ // ------------------------------ Form Events ------------------------------ // ------------------------------------------------------------------------------------------ private void Form1_Load(object sender, EventArgs e) { // スクリーンの大きさ取得 foreach (var s in Screen.AllScreens) { if (s.Bounds.X < 0) { MinXY.X += s.Bounds.X; } if (s.Bounds.Y < 0) { MinXY.Y += s.Bounds.Y; } if (s.Bounds.X > 0) { MaxXY.X += s.Bounds.X; } if (s.Bounds.Y > 0) { MaxXY.Y += s.Bounds.Y; } } MaxXY.X += Screen.PrimaryScreen.Bounds.Width; MaxXY.Y += Screen.PrimaryScreen.Bounds.Height; // カーソルの取得と通知テキスト設定 CursorPoint = Cursor.Position; notifyIcon1.Text = "Wiimote Mouse : Disabled"; // Wiimote接続 mWiimote = new Wiimote(); try { mWiimote.WiimoteChanged += (s, args) => UpdateState(args); mWiimote.WiimoteExtensionChanged += (s, args) => UpdateExtension(args); mWiimote.Connect(); mWiimote.SetReportType(InputReport.IRExtensionAccel, true); mWiimote.SetLEDs(true, false, false, true); } catch (WiimoteNotFoundException ex) { MessageBox.Show(ex.Message, "Wiimote not found error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } catch (WiimoteException ex) { MessageBox.Show(ex.Message, "Wiimote error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } catch (Exception ex) { MessageBox.Show(ex.Message, "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } }
private void Form1_Load(object sender, EventArgs e) { wiimoteInfo1.Wiimote = wm; wm.WiimoteChanged += wm_WiimoteChanged; wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged; wm.Connect(); wm.SetReportType(InputReport.IRAccel, true); wm.SetLEDs(false, true, true, false); }
private void StartButton_Click(object sender, RoutedEventArgs e) { if (prototypesList.Count > 0) { if (mode == Mode.TRAINING) { gestureRecognizer.Clear(); RecogGesture.Text = prototypesList[currentIndexGesture]; wm.WiimoteChanged += Wm_WiimoteChanged; wm.Connect(); wm.SetReportType(InputReport.ButtonsAccel, true); EnableAllOptions(false); gestureCapturer.GestureCaptured += GestureCapturer_GestureCaptured; } else if (mode == Mode.RECOGNIZER) { if (StartButton.Content.ToString() == "Start") { wm.WiimoteChanged += Wm_WiimoteChanged; wm.Connect(); wm.SetReportType(InputReport.ButtonsAccel, true); gestureCapturer.GestureCaptured += GestureCapturer_GestureCaptured1; gestureRecognizer.GestureRecognized += GestureRecognizer_GestureRecognized; EnableAllOptions(false); StartButton.IsEnabled = true; StartButton.Content = "Stop"; } else { wm.WiimoteChanged -= Wm_WiimoteChanged; gestureCapturer.GestureCaptured -= GestureCapturer_GestureCaptured1; EnableAllOptions(true); StartButton.Content = "Start"; } } } else { MessageBox.Show("No se ha introducido ningún gesto"); } }
public SingleWiimote() { this.InitializeComponent(); mWiimote = new Wiimote(); mWiimote.Connect(); mWiimote.WiimoteChanged += wm_WiimoteChanged; mWiimote.WiimoteExtensionChanged += wm_WiimoteExtensionChanged; mWiimote.SetReportType(InputReport.IRAccel, true); mWiimote.SetLEDs(false, true, true, false); }
void InitWiiStuff() { var wm = new Wiimote(); var wm2 = new Wiimote(); wm.WiimoteChanged += wm_WiimoteChanged; wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged; wm.Connect(); wm.SetReportType(WiimoteLib.InputReport.ButtonsAccel, true); }
private void button1_Click(object sender, EventArgs e) { try { wm.Connect(); wm.SetReportType(InputReport.IRAccel, true); } catch { MessageBox.Show("Exception thrown by Connect() method."); } }
private void frmMain_Load(object sender, EventArgs e) { /****************************************************************** * PreCondition: Form loading * PostCondition: The original position of the ball will be recorded * Description: This function tracks the original ball position * (the center of the field) and original paddle * positions for use in resetting the game * Algorithm: Record the original positions of the ball and the * two player paddles * Dynamically add the AI victory label * Try to connect to the Wii Remote via: * Use the alternate polling method * Attempt to establish a connection * Note successful connection * Turn on the Player 1 LED * Catch any exception thrown by the Remote and: * Display a MessageBox that the device could * not be connected *****************************************************************/ //Record the original Ball and Paddle coordinates OriginalBallX = pbxBall.Location.X; OriginalBallY = pbxBall.Location.Y; OriginalPaddle1Y = pbxPlayer1Paddle.Location.Y; OriginalPaddle2Y = pbxPlayer2Paddle.Location.Y; //Dynamically add a label for victories against the AI AIWins.Parent = this; AIWins.Show(); AIWins.Left = 250; AIWins.Top = 37; AIWins.TextAlign = ContentAlignment.MiddleCenter; AIWins.Text = "Wins VS AI:"; AIWins.Visible = true; try { //Connect to the Wii Remote Remote.AltWriteMethod = true; Remote.Connect(); WiiRemotePresent = true; //Light up the player 1 LED so the player knows the device is ready Remote.SetLEDs(true, false, false, false); } catch { //Inform the user that no Wii Remote was found MessageBox.Show("Unable to connect to the Wii Remote. Is one on?", "Wii Remote Connection Error.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void StartDesktop() { try { wiimote.Connect(); wiimote.SetReportType(Wiimote.InputReport.IRAccel, true); wiimote.SetLEDs(true, false, false, false); } catch (System.Exception x) { throw new UserTerminatedException("WiimoteLib.dll:" + x.Message + "\nWiimoteIRDetector: Failed while trying to connect to Wiimote."); } }
private void InitWiimote(Wiimote wiimote) { wiimote.Connect(); wiimote.WiimoteChanged += wiimote_WiimoteChanged; wiimote.WiimoteExtensionChanged += wiimote_WiimoteExtensionChanged; if (wiimote.WiimoteState.ExtensionType != ExtensionType.BalanceBoard) { wiimote.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true); } this.wiimote = wiimote; }