Ejemplo n.º 1
0
        //-----------------------------------------------------------------------
        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
            var 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 static List<GenericInput> GetNewInputDevices(IntPtr windowHandle, List<GenericInput> currentDevices)
        {
            List<GenericInput> newDevices = new List<GenericInput>();
            WiimoteCollection wiiMoteCollection = new WiimoteCollection();

            try
            {
                wiiMoteCollection.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException) { }
            catch (WiimoteException)
            {
                Console.WriteLine("Wiimote error");
            }

            foreach (Wiimote wiimote in wiiMoteCollection)
            {
                if (!CheckIfDeviceExists(wiimote, currentDevices))
                {
                    WiiMoteInput input = new WiiMoteInput(wiimote);
                    wiimote.SetLEDs(false, false, false, false);

                    newDevices.Add(input);
                }
            }

            return newDevices;
        }
Ejemplo n.º 3
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            UVfont      = Content.Load <SpriteFont>("SpriteFont1");

            Vector2 size = new Vector2(50, 50);

            texture = this.Content.Load <Texture2D>("crate");
            bar     = this.Content.Load <Texture2D>("bar");

            random = new Random();

            circle = Content.Load <Texture2D>("circle");

            cursorA = this.Content.Load <Texture2D>("crosshair");
            cursorB = this.Content.Load <Texture2D>("crosshair");

            // Floor
            floor          = new Floor(world, Content.Load <Texture2D>("floor"), new Vector2(GraphicsDevice.Viewport.Width, 100.0f), 10000010.0f);
            floor.Position = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height);

            leftWall          = new Wall(world, Content.Load <Texture2D>("wall"), new Vector2(100.0f, GraphicsDevice.Viewport.Height), 10000001.0f);
            leftWall.Position = new Vector2(0.0f, GraphicsDevice.Viewport.Height / 2);

            rightWall          = new Wall(world, Content.Load <Texture2D>("wall"), new Vector2(100.0f, GraphicsDevice.Viewport.Height), 10000001.0f);
            rightWall.Position = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height / 2);

            characterA          = new Character(world, this.Content.Load <Texture2D>("charRed"), new Vector2(20f, 60f), 101f);
            characterA.Position = new Vector2(150, 50);

            characterB          = new Character(world, this.Content.Load <Texture2D>("charBlue"), new Vector2(20f, 60f), 101f);
            characterB.Position = new Vector2(GraphicsDevice.Viewport.Width - 150, 50);

            //        characterC = new Character(world, this.Content.Load<Texture2D>("charRed"), new Vector2(20f, 60f), 101f);
            //        characterC.Position = new Vector2(350, 50);

            //        characterD = new Character(world, this.Content.Load<Texture2D>("charBlue"), new Vector2(20f, 60f), 101f);
            //        characterD.Position = new Vector2(GraphicsDevice.Viewport.Width - 350, 50);

            crateList = new List <DrawablePhysicsObject>();
            pointList = new List <Point>();
            bullets   = new List <Bullet>();
            star      = new Star(world, this.Content.Load <Texture2D>("star"), new Vector2(32f, 32f), 1001f);

            prevKeyboardState = Keyboard.GetState();

            wiimotes = new WiimoteCollection();
            wiimotes.FindAllWiimotes();

            foreach (Wiimote wm in wiimotes)
            {
                wm.Connect();
                wm.SetReportType(InputReport.IRExtensionAccel, true);
            }

            myWiimote1 = wiimotes[0];
            //       myWiimote2 = wiimotes[1];
            //      myWiimote3 = wiimotes[2];
            //      myWiimote4 = wiimotes[3];
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        public WiimoteLib()
        {
            // find all wiimotes connected to the system
            m_wiimoteCollection = new WiimoteCollection();

            try {
                m_wiimoteCollection.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException ex) {
                // this stops complaints about ex being unused, so we can look at it in debugger
                HoloDebug.Assert(ex == null);
            }
            catch (WiimoteException ex) {
                HoloDebug.Assert(ex == null);
            }
            catch (Exception ex) {
                HoloDebug.Assert(ex == null);
            }

            int index = 1;
            foreach (Wiimote wm in m_wiimoteCollection) {
                WiimoteController wi = new WiimoteController(wm);
                wm.Connect();
                wm.SetLEDs(index++);
                m_wiimotes.Add(wi);
            }
        }
Ejemplo n.º 6
0
        public int ConnectToWiiBoard()
        {
            int wiiConnectstatus = -1;
            WiimoteCollection wiimoteCollection = new WiimoteCollection();

            wiimoteCollection.FindAllWiimotes();
            try
            {
                foreach (Wiimote current in wiimoteCollection)
                {
                    current.Connect();
                    current.SetLEDs(true, false, false, false);
                    current.Disconnect();
                    wiiConnectstatus = 1; // connecté
                }
            }
            catch (Exception ex)
            {
                LOG.Warn(ex);
                wiiConnectstatus = 99;
            }

            // reinit wiiboard to null to force a search at next aquisition.
            wiiboard = null;
            return(wiiConnectstatus);
        }
Ejemplo n.º 7
0
        public override IObservable <WiimoteState> Generate()
        {
            return(Observable.Defer(() =>
            {
                var index = Index;
                if (index < 0 || index > 4)
                {
                    throw new InvalidOperationException("Wiimote index must be between zero and three.");
                }

                var wiimotes = new WiimoteCollection();
                wiimotes.FindAllWiimotes();
                if (index >= wiimotes.Count)
                {
                    throw new InvalidOperationException("No Wiimote with the specified index found.");
                }

                var wiimote = wiimotes[index];
                wiimote.Connect();
                wiimote.SetLEDs(index);
                wiimote.SetReportType(ReportType, Sensitivity, Continuous);
                return Observable.FromEventPattern <WiimoteChangedEventArgs>(
                    handler => wiimote.WiimoteChanged += handler,
                    handler => wiimote.WiimoteChanged -= handler)
                .Select(evt => evt.EventArgs.WiimoteState)
                .Finally(() =>
                {
                    wiimote.SetLEDs(0);
                    wiimote.Disconnect();
                    wiimote.Dispose();
                });
            }));
        }
Ejemplo n.º 8
0
        private void AddWiimoteDevices()
        {
            WiimoteCollection wiiMoteCollection = new WiimoteCollection();

            try
            {
                wiiMoteCollection.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException) { }
            catch (WiimoteException)
            {
                Console.WriteLine("Wiimote error");
            }

            foreach (Wiimote wiimote in wiiMoteCollection)
            {
                if (!CheckIfWiimoteInputDeviceExists(wiimote))
                {
                    WiimoteInput input = new WiimoteInput(wiimote);
                    AddInputDevice(input);
                    input.InitCurrentlyInvokedInput();

                    wiimote.SetLEDs(false, false, false, false);

                    InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
                }
            }
        }
Ejemplo n.º 9
0
        public static List <GenericInput> GetNewInputDevices(IntPtr windowHandle, List <GenericInput> currentDevices)
        {
            List <GenericInput> newDevices        = new List <GenericInput>();
            WiimoteCollection   wiiMoteCollection = new WiimoteCollection();

            try
            {
                wiiMoteCollection.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException) { }
            catch (WiimoteException)
            {
                Console.WriteLine("Wiimote error");
            }

            foreach (Wiimote wiimote in wiiMoteCollection)
            {
                if (!CheckIfDeviceExists(wiimote, currentDevices))
                {
                    WiiMoteInput input = new WiiMoteInput(wiimote);
                    wiimote.SetLEDs(false, false, false, false);

                    newDevices.Add(input);
                }
            }

            return(newDevices);
        }
Ejemplo n.º 10
0
        private Wiimote InitWiimote(int wiimoteIndex)
        {
            WiimoteCollection wiimoteCollection = new WiimoteCollection();
            Wiimote           wiimote;

            try
            {
                wiimoteCollection.FindAllWiimotes();
                wiimote = wiimoteCollection.ElementAt <Wiimote>(wiimoteIndex);
            }
            catch
            {
                wiimote = null;
            }

            if (wiimote != null)
            {
                try
                {
                    wiimote.Connect();
                    wiimote.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                    wiimote.SetLEDs(wiimoteIndex + 1);
                }
                catch
                {
                    wiimote = null;
                }
            }

            return(wiimote);
        }
Ejemplo n.º 11
0
        private void findAll()
        {
            var collection = new WiimoteCollection();

            collection.FindAllWiimotes();
            Wiimote = collection[0];
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Verifies that Balance board is connected, then initializes board object
        /// </summary>
        private static void connectBoard()
        {
            try
            {
                // Initialize Board Varibles
                wiiDevice = new Wiimote();
                var deviceCollection = new WiimoteCollection();

                // Verify board is connected. If not, repeat until board is connected.
                do
                {
                    try
                    {
                        Console.WriteLine("Searching for connected board...");
                        deviceCollection.FindAllWiimotes();
                        Console.WriteLine("Board Found!");
                    }
                    catch
                    {
                        Console.WriteLine("No boards are connected...");
                        Thread.Sleep(1000);
                    }
                }while (deviceCollection.Count < 1);

                // Set wiiDevice variable
                wiiDevice = deviceCollection[0];
                wiiDevice.Connect();
                wiiDevice.SetReportType(InputReport.IRAccel, false);
                wiiDevice.SetLEDs(true, false, false, false);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message, "Error");
            }
        }
Ejemplo n.º 13
0
        //プログラムロード時に走るコード
        private void MultipleWiimoteForm_Load(object sender, EventArgs e)
        {
            // find all wiimotes connected to the system
            mWC = new WiimoteCollection();
            int index = 0;

            Console.WriteLine("MultipleWiimoteForm_Load()");

            try
            {
                Console.WriteLine("mWC.FindAllWiimotes()...");
                mWC.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);
            }

            //発見した子機の数だけイベントハンドラを登録/通信接続
            foreach (Wiimote wm in mWC)
            {
                // create a new tab
                TabPage tp = new TabPage("Wiimote " + index);
                tabWiimotes.TabPages.Add(tp);

                // create a new user control
                WiimoteInfo wi = new WiimoteInfo(wm);
                wi.index = index;                       ///コントローラ番号を付記
                tp.Controls.Add(wi);

                //サーバで送信するコントローラの情報枠を増やす
                server.AddController();

                // setup the map from this wiimote's ID to that control
                mWiimoteMap[wm.ID] = wi;

                // connect it and set it up as always
                wm.WiimoteChanged          += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

                wm.Connect();
                if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                {
                    wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                }

                //LEDをつける(コントローラ)
                wm.SetLEDs(index + 1);
                index++;
            }
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        private void MultipleWiimoteForm_Load(object sender, EventArgs e)
        {
            // find all wiimotes connected to the system
            mWC = new WiimoteCollection();
            int index = 1;

            try
            {
                mWC.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);
            }

            int count = 0;

            foreach (Wiimote wm in mWC)
            {
                // create a new tab
                TabPage tp = new TabPage("Wiimote " + index);
                tabWiimotes.TabPages.Add(tp);

                // create a new user control
                WiimoteInfo wi = new WiimoteInfo(wm);
                tp.Controls.Add(wi);

                wInfo[count++] = wi;

                // setup the map from this wiimote's ID to that control
                mWiimoteMap[wm.ID] = wi;

                // connect it and set it up as always
                wm.WiimoteChanged          += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

                wm.Connect();
                if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                {
                    wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                }

                wm.SetLEDs(index++);
                wm.InitializeMotionPlus();
            }

            startVJoy();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Retrieves Wii remotes from System memory.
        /// </summary>
        public void retrieveWiimotesToMemory()
        {
            try {
                mWiimotes.FindAllWiimotes();
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 17
0
        public TrollServer(WiiServerApp m)
        {
            main = m;
            PushMessage("Welcome to the TrollDom WiiMote server!");

            // Create a collection of Wiimote devices
            collection = new WiimoteCollection();

            collection.FindAllWiimotes();
            PushMessage("Found " + collection.Count + " Wiimote" + ((collection.Count > 1) ? "s" : ""));

            // Connect to all the controllers
            foreach (Wiimote wiiMote in collection)
            {
                vecList.Add(new List <Vector3>());
                for (int j = 0; j < vecAmount; j++)
                {
                    vecList[vecList.Count - 1].Add(new Vector3(0, 0, 0));
                }
                curVec.Add(0);

                capturingList.Add(false);
                gestureList.Add(new List <Vector3>());
                wiiMote.Connect();
                wiiMote.SetReportType(InputReport.ExtensionAccel, true);
                //wiiMote.PlayAudioFile("C:\\snd\\mariekSound.yadpcm");
                //wiiMote.PlayTone(0x10, 0x40, 0xC3, 1);
                wiiMote.SetLEDs(true, false, false, false);
            }

            PushMessage("Waiting for client..");

            // Create the gesture recognition instance
            gesture = new GestureRecognition();

            // Create the server
            ipep    = new IPEndPoint(IPAddress.Any, port);
            newsock = new UdpClient(ipep);

            // Set the last capture update ticks to current time
            lastUpdate = DateTime.Now.Ticks;

            // Setup the capture and server threads
            workerThread = new Thread(mainLoopCaller);
            workerThread.Start();

            // Amount of ticks for every capture update (10k ticks in a millisecond)
            sampInterval = 10000000 / updateFreq;

            captureThread = new Thread(captureLoop);
            captureThread.Start();
        }
Ejemplo n.º 18
0
        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);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializing a wiimote
        /// </summary>
        void wiiRemoteInit()
        {
            disconnectWiimote();

            message.Label = "Connecting...";
            mWC           = new WiimoteCollection();

            try
            {
                //Search wiimote
                mWC.FindAllWiimotes();

                //Connect the wiimote
                int index = 1;
                foreach (Wiimote wm in mWC)
                {
                    wm.Disconnect();
                    wm.WiimoteChanged += new EventHandler <WiimoteChangedEventArgs>(wm_WiimoteChanged);
                    wm.Connect();
                    wm.SetLEDs(index++);
                    refreshBattery(wm.WiimoteState);
                }

                connectWiimoteButton.Checked = true;
            }
            catch (WiimoteNotFoundException)
            {
                //MessageBox.Show(ex.Message, "Wiimote not found error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                message.Label = "Wiimote not found";
                connectWiimoteButton.Checked = false;
                return;
            }
            catch (WiimoteException)
            {
                //MessageBox.Show(ex.Message, "Wiimote error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                message.Label = "Wiimote not found";
                connectWiimoteButton.Checked = false;
                return;
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message, "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                message.Label = "Unknown error";
                connectWiimoteButton.Checked = false;
                return;
            }

            Globals.ThisAddIn.Application.SlideShowBegin += new EApplication_SlideShowBeginEventHandler(Application_SlideShowBegin);
            Globals.ThisAddIn.Application.SlideShowEnd   += new EApplication_SlideShowEndEventHandler(Application_SlideShowEnd);
        }
Ejemplo n.º 20
0
        private void MultipleWiimoteForm_Load(object sender, EventArgs e)
        {
            // Encontrar Wiimotes conectados.
            mWC = new WiimoteCollection();
            int index = 1;

            try
            {
                mWC.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Wiimote no encontrado", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (WiimoteException ex)
            {
                MessageBox.Show(ex.Message, "Error de Wiimote", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Desconocido", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            foreach (Wiimote wm in mWC)
            {
                // Crear nueva pestaña
                TabPage tp = new TabPage("Wiimote " + index);
                tabWiimotes.TabPages.Add(tp);

                // Crear nuevo control de usuario
                WiimoteInfo wi = new WiimoteInfo(wm);
                tp.Controls.Add(wi);


                mWiimoteMap[wm.ID] = wi;

                // Conectar Wiimote y mantenerlo conectado.
                wm.WiimoteChanged          += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

                wm.Connect();
                if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                {
                    wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                }

                wm.SetLEDs(index++);
            }
        }
        private void MultipleWiimoteForm_Load(object sender, EventArgs e)
        {
            // find all wiimotes connected to the system
            mWC = new WiimoteCollection();
            int index = 1;

            try
            {
                mWC.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);
            }

            foreach(Wiimote wm in mWC)
            {
                // create a new tab
                TabPage tp = new TabPage("Wiimote " + index);
                tabWiimotes.TabPages.Add(tp);

                // create a new user control
                WiimoteInfo wi = new WiimoteInfo(wm);
                tp.Controls.Add(wi);

                // setup the map from this wiimote's ID to that control
                mWiimoteMap[wm.ID] = wi;

                // connect it and set it up as always
                wm.WiimoteChanged += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

                wm.Connect();

                if(wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                    wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);

                wm.SetLEDs(index++);
            }
        }
Ejemplo n.º 22
0
        public void SearchWiiBoard()
        {
            Console.WriteLine("searching...");
            WiimoteCollection wiimoteCollection = new WiimoteCollection();

            try
            {
                wiimoteCollection.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException ex)
            {
                LOG.Error("Wiimote not found error", ex);
                return;
            }
            catch (WiimoteException ex)
            {
                LOG.Error("Wiimote error", ex);
                return;
            }
            catch (Exception ex)
            {
                LOG.Error("Unknown error", ex);
                return;
            }

            Console.WriteLine("found " + wiimoteCollection.ToList().Count);
            foreach (Wiimote current in wiimoteCollection)
            {
                try
                {
                    current.Connect();
                    current.SetLEDs(true, false, false, false);
                    var founded = current.WiimoteState.ExtensionType == ExtensionType.BalanceBoard;
                    current.Disconnect();
                    if (founded)
                    {
                        Console.WriteLine("Hola");
                        wiiboard = current;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    LOG.Error(string.Format("Error durring access to Wiimote {0}.", current.HIDDevicePath), ex);
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Initialization of all active Wiimotes.
        /// </summary>
        public static void InitWiimotes()
        {
            try
            {
                // Find all wiimotes connected to the system
                WiimoteCollection wiimoteCollection = new WiimoteCollection();
                wiimoteCollection.FindAllWiimotes();

                // For each Wiimote founded
                int index = 1;
                foreach (WiimoteLib.Wiimote wiimote in wiimoteCollection)
                {
                    // Connect to Wiimote
                    bool error = false;
                    try
                    {
                        wiimote.Connect();
                    }
                    catch (WiimoteException)
                    {
                        error = true;
                    }
                    if (!error) // If the connection was a success
                    {
                        switch (index)
                        {
                        case 1: wiimotePlayerOne.AssignWiimote(wiimote);   break;

                        case 2: wiimotePlayerTwo.AssignWiimote(wiimote);   break;

                        case 3: wiimotePlayerThree.AssignWiimote(wiimote); break;

                        case 4: wiimotePlayerFour.AssignWiimote(wiimote);  break;
                        }
                        index++;
                    }
                }
            }
            catch
            {
                // If it can't connect to any Wiimote we do nothing.
                // All problems with connections need to be address outside the application.
            }
            // Creates the texture
            wiimoteSensorsTexture = new Texture("WiimoteSensors");
        } // Wiimote
        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;
            }
            //}
        }
Ejemplo n.º 25
0
        public MainPage()
        {
            mWC = new WiimoteCollection();
            try
            {
                mWC.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException ex)
            {
                throw new Exception("Wiimote not found", ex);
                //MessageBox.Show(ex.Message, "Wiimote not found error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (WiimoteException ex)
            {
                throw new Exception("Wiimote error", ex);
                //MessageBox.Show(ex.Message, "Wiimote error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                throw new Exception("Unknown error", ex);
                //MessageBox.Show(ex.Message, "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.InitializeComponent();
            int index = 1;


            if (mWC.Count > 0)
            {
                this.Frame.Navigate(typeof(SingleWiimote), mWC[0]);
            }
            //            foreach (Wiimote wm in mWC)
            //            {
            //                // create a new tab
            //                PivotItem tp = new PivotItem();
            //                tp.Header = "Wiimote " + index;
            //                tabWiimotes.Items.Add(tp);
            //
            //                // create a new user control
            //                SingleWiimote wi = new SingleWiimote(wm);
            //                tp.Content = wi;
            //
            //                // setup the map from this wiimote's ID to that control
            //                mWiimoteMap[wm.ID] = wi;
            //            }
        }
Ejemplo n.º 26
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            try
            {
                deviceCollection.FindAllWiimotes();
                wiiDevice = deviceCollection[0];
                wiiDevice.Connect();
                wiiDevice.SetLEDs(true, true, true, true);
                wiiDevice.WiimoteChanged += wiiDevice_WiimoteChanged;

                softLabel.Text = "Board Connected.\nReady to report values.";
            }
            catch
            {
                softLabel.Text = "No device found in HID list. Please use the 'Initialize' button below and click the red 'SYNC' button on the bottom of the balance board.";
            }
        }
Ejemplo n.º 27
0
        public void _setConnection()
        {
            WiimoteCollection dvcCol = new WiimoteCollection();

            dvcCol.FindAllWiimotes();
            wiiDevice = dvcCol[0];
            wiiDevice.WiimoteChanged += wiiDevice_WiimoteChanged;
            wiiDevice.Connect();
            wiiDevice.SetReportType(InputReport.IRAccel, false);
            wiiDevice.SetLEDs(true, false, false, false);
            UpdateTimer.Enabled = true;

            initLT = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
            initRT = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
            initLB = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;
            initRB = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            
            base.Initialize();
			
            mWC = new WiimoteCollection();
			
            int index = 1;
            
            try
            {
                mWC.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException ex)
            {
                error =  "Wiimote not found error";
            }
            catch (WiimoteException ex)
            {
                 error =  "Wiimote error";
            }
            catch (Exception ex)
            {
                 error =  "Unknown error";
            }

            foreach (Wiimote wm in mWC)
            {
                wm.Connect();
                wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                wm.SetLEDs(index);
                index++;
            }

            if (index > 0)
            {
                point = new Point3F[index - 1];
                buttonsPressed = new string[index - 1];
                IRStatus = new string[index - 1];
                punten = new Vector2[index - 1];
            }
        }
Ejemplo n.º 29
0
        public void StartTracking()
        {
            // find all wiimotes connected to the system
            mWC = new WiimoteCollection();
            int index = 1;

            try
            {
                mWC.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);
            }

            foreach (Wiimote wm in mWC)
            {
                wm.WiimoteChanged          += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

                wm.Connect();
                if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                {
                    wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                }

                wm.SetLEDs(index++);
            }

            // Init Mouse tracker, too
            gmh = new GlobalMouseHandler();
            gmh.TheMouseMoved += new MouseMovedEvent(gmh_TheMouseMoved);
            Application.AddMessageFilter(gmh);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Renvoie une BalanceBoard
        /// </summary>
        /// <returns></returns>
        private static BalanceBoard GetDevice()
        {
            // On cherche tous les appareils Wii.
            var devices = new WiimoteCollection();

            devices.FindAllWiimotes();
            foreach (var device in devices)
            {
                // On vérifie que l'appareil est bien une board.
                device.Connect(); // On a besoin de connecter le device pour savoir quel est son ExtensionType.
                if (device.WiimoteState.ExtensionType == ExtensionType.BalanceBoard)
                {
                    var board = new BalanceBoard(device);
                    board.Connect();
                    return(board);
                }
                device.Disconnect();
            }
            return(null);
        }
Ejemplo n.º 31
0
        private void InitializeWiiMotes()
        {
            // find all wiimotes connected to the system
            mWC = new WiimoteCollection();
            int index = 1;

            try
            {
                mWC.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException ex)
            {
            }
            catch (WiimoteException ex)
            {
            }
            catch (Exception ex)
            {
            }

            foreach (Wiimote wm in mWC)
            {
                // connect it and set it up as always
                wm.WiimoteChanged          += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;
                try
                {
                    wm.Connect();
                    if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                    {
                        wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);
                    }

                    wm.SetLEDs(index++);
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 32
0
        public bool CheckConnection()
        {
            WiimoteCollection wmc = new WiimoteCollection();
            bool connected = true ;

            foreach(Wiimote wm in wmList)
            {
                wmc.Add(wm);

                try
                {
                    wmc.FindAllWiimotes();
                    wm.Connect();
                }
                catch (WiimoteNotFoundException e)
                {
                    connected = false;
                    System.Windows.Forms.MessageBox.Show(e.Message);
                }
            }

            return connected;
        }
Ejemplo n.º 33
0
 public void Connect()
 {
     weights = new List<float>();
     controllers = new WiimoteCollection();
     while (controllers.Count == 0)
     {
         try
         {
             controllers.FindAllWiimotes();
         }
         catch (WiimoteNotFoundException ex)
         {
             //Swallow ad keep trying
         }
         Thread.Sleep(50);
     }
     foreach (var c in controllers)
     {
         c.WiimoteChanged += stateChange;
         c.Connect();
         c.SetLEDs(1);
     }
 }
Ejemplo n.º 34
0
        private void ConnectWiiBalanceBoard()
        {
            try
            {
                // Find all connected Wii devices.
                var deviceCollection = new WiimoteCollection();
                deviceCollection.FindAllWiimotes();

                for (int i = 0; i < deviceCollection.Count; i++)
                {
                    wiiDevice = deviceCollection[i];

                    // 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);

                    ZeroCalibration();

                    // Enable processing of updates.
                    infoUpdateTimer.Enabled = true;

                    // Prevent connect being pressed more than once.
                    _canConnectWBB = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 35
0
        private void connect()
        {
            try
            {
                this.Dispatcher.Invoke(() =>
                {
                    ConnectionText.Text = "Attempting new Connection\n";
                });
                using (var btClient = new BluetoothClient())
                {
                    var btIgnored = 0;

                    // Find remembered bluetooth devices.
                    this.Dispatcher.Invoke(() =>
                    {
                        ConnectionText.Text += "Removing existing bluetooth devices...\n";
                    });

                    if (true)//checkBox_RemoveExisting.Checked
                    {
                        var btExistingList = btClient.DiscoverDevices(255, false, true, false);

                        foreach (var btItem in btExistingList)
                        {
                            if (!btItem.DeviceName.Contains("Nintendo"))
                            {
                                continue;
                            }

                            BluetoothSecurity.RemoveDevice(btItem.DeviceAddress);
                            btItem.SetServiceState(BluetoothService.HumanInterfaceDevice, false);
                        }
                    }

                    // Find unknown bluetooth devices.
                    this.Dispatcher.Invoke(() =>
                    {
                        ConnectionText.Text += "Searching for bluetooth devices...\nPress the red sync button now to sync!\n";
                    });

                    var btDiscoveredList = btClient.DiscoverDevices(255, false, false, true);

                    foreach (var btItem in btDiscoveredList)
                    {
                        // Just in-case any non Wii devices are waiting to be paired.

                        if (true && !btItem.DeviceName.Contains("Nintendo")) //!checkBox_SkipNameCheck.Checked
                        {
                            btIgnored += 1;
                            continue;
                        }


                        this.Dispatcher.Invoke(() =>
                        {
                            ConnectionText.Text += "Adding: " + btItem.DeviceName + " ( " + btItem.DeviceAddress + " )\n";
                        });


                        // Install as a HID device and allow some time for it to finish.

                        btItem.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
                    }

                    // Allow slow computers to finish installation before connecting.

                    System.Threading.Thread.Sleep(4000);

                    // Connect and send a command, otherwise they sleep and the device disappears.

                    try
                    {
                        if (btDiscoveredList.Length > btIgnored)
                        {
                            var deviceCollection = new WiimoteCollection();
                            deviceCollection.FindAllWiimotes();

                            foreach (var wiiDevice in deviceCollection)
                            {
                                wiiDevice.Connect();
                                wiiDevice.SetLEDs(true, false, false, false);
                                wiiDevice.Disconnect();
                            }
                            this.Dispatcher.Invoke(() =>
                            {
                                ConnectionText.Text += "Finished - You can now close this window.\n";
                            });
                        }
                        else
                        {
                            this.Dispatcher.Invoke(() =>
                            {
                                ConnectionText.Text += "Finished - No board(s) found. Please try again.\n";
                            });
                        }
                    }
                    catch (Exception) { }
                }
            }
            catch (Exception ex)
            {
                this.Dispatcher.Invoke(() =>
                {
                    ConnectionText.Text += "Error: " + ex.Message + "\n";
                });
            }
        }
Ejemplo n.º 36
0
        public void StartTracking()
        {
            // find all wiimotes connected to the system
            mWC = new WiimoteCollection();
            int index = 1;

            try
            {
                mWC.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException)
            {
                //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);
            }

            foreach (Wiimote wm in mWC)
            {
                wm.WiimoteChanged += wm_WiimoteChanged;
                wm.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;

                wm.Connect();
                if (wm.WiimoteState.ExtensionType != ExtensionType.BalanceBoard)
                    wm.SetReportType(InputReport.IRExtensionAccel, IRSensitivity.Maximum, true);

                wm.SetLEDs(index++);
            }

            // Init Mouse tracker, too
            gmh = new GlobalMouseHandler();
            gmh.TheMouseMoved += new MouseMovedEvent(gmh_TheMouseMoved);
            Application.AddMessageFilter(gmh);
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Recherche et active tous les appareils Wii voulant se synchroniser.
        /// </summary>
        /// <param name="removeExisting">Défaut: true; Supprime les appareils Wii connus</param>
        public static void DiscoverWiiDevices(bool removeExisting = true)
        {
            using (var bluetoothClient = new BluetoothClient()) {
                // Par défaut, on souhaite supprimer, les appareils Wii de notre listes d'appareils bluetooth.
                // Sinon, on peut pas recommencer une sync avec une wiimote/board/etc..
                // Du coup on les cherches tous et on les deletes.
                if (removeExisting)
                {
                    // On cherche tous les appareils bluetooth connus.
                    var bluetoothExistingList = bluetoothClient.DiscoverDevices(255, false, true, false);
                    foreach (var item in bluetoothExistingList)
                    {
                        // Si l'appareil ne contient pas Nintendo dans son nom, on le zappe.
                        if (!item.DeviceName.Contains("Nintendo"))
                        {
                            continue;
                        }
                        // Si c'est un appareil Nintendo, on le delete.
                        BluetoothSecurity.RemoveDevice(item.DeviceAddress);
                        item.SetServiceState(BluetoothService.HumanInterfaceDevice, false);
                    }
                }

                // On cherche tous les appareils bluetooth inconnus.
                var bluetoothDiscoveredList = bluetoothClient.DiscoverDevices(255, false, false, true);
                // Une variable utilisée pour filtrer les appareils en cours de synchro, qui ne sont pas de Nintendo
                var bluetoothIgnored = 0;
                foreach (var item in bluetoothDiscoveredList)
                {
                    // Au cas où un appareil ne venant pas de la Wii serait en cours de synchro.
                    if (!item.DeviceName.Contains("Nintendo"))
                    {
                        bluetoothIgnored += 1; // On augmente notre compteur et on ne fait rien avec l'appareil trouvé.
                        continue;
                    }

                    // SYNC PERMANTE ICI, SI JAMAIS ON EN A VRAIMENT BESOIN.

                    // On a trouvé un appareil venant de la Wii, on l'installe comme appareil HID, et on lui laisse un peu de temps pour finir tous ça.
                    item.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
                }
                // Au cas où le pc est un peu long, on lui laisse le temps de finir l'installation avant de se connecter.
                // Valeur arbitraire.
                System.Threading.Thread.Sleep(5000);

                // On se connecte à chaque appareils une fois pour ne pas qu'ils partent en sommeil et disparaissent.
                if (bluetoothDiscoveredList.Length > bluetoothIgnored)
                {
                    // On cherche tous les appareils Wii.
                    var devices = new WiimoteCollection();
                    devices.FindAllWiimotes();

                    foreach (var wiiDevice in devices)
                    {
                        // On se connecte, set une led allumée/éteinte, et se déconnecte.
                        wiiDevice.Connect();
                        wiiDevice.SetLEDs(true, false, false, false);
                        wiiDevice.SetLEDs(false, false, false, false);
                        wiiDevice.Disconnect();
                    }
                }
            }
        }
Ejemplo n.º 38
0
        private void button_DeviceSearch_Click(object sender, EventArgs e)
        {
            ((Button)sender).Enabled = false;

            try
            {
                using (var btClient = new BluetoothClient())
                {
                    // PROBLEM:
                    // false false true: finds only unknown devices, which excludes existing but broken device entries.
                    // false true  true: finds broken entries, but even if powered off, so pairing attempts then crash.
                    // WORK-AROUND:
                    // Remove existing entries first, then find powered on entries.

                    var btIgnored = 0;

                    // Find remembered bluetooth devices.

                    label_Status.Text = "Removing existing bluetooth devices...";
                    label_Status.Refresh();

                    if (checkBox_RemoveExisting.Checked)
                    {
                        var btExistingList = btClient.DiscoverDevices(255, false, true, false);

                        foreach (var btItem in btExistingList)
                        {
                            if (!btItem.DeviceName.Contains("Nintendo"))
                            {
                                continue;
                            }

                            BluetoothSecurity.RemoveDevice(btItem.DeviceAddress);
                            btItem.SetServiceState(BluetoothService.HumanInterfaceDevice, false);
                        }
                    }

                    // Find unknown bluetooth devices.

                    label_Status.Text = "Searching for bluetooth devices...";
                    label_Status.Refresh();

                    var btDiscoveredList = btClient.DiscoverDevices(255, false, false, true);

                    foreach (var btItem in btDiscoveredList)
                    {
                        // Just in-case any non Wii devices are waiting to be paired.

                        if (!checkBox_SkipNameCheck.Checked && !btItem.DeviceName.Contains("Nintendo"))
                        {
                            btIgnored += 1;
                            continue;
                        }

                        label_Status.Text = "Adding: " + btItem.DeviceName + " ( " + btItem.DeviceAddress + " )";
                        label_Status.Refresh();

                        // Send special pin for permanent sync.

                        if (checkBox_PermanentSync.Checked)
                        {
                            // Sync button requires host address, holding 1+2 buttons requires device address.

                            var btPin = AddressToWiiPin(BluetoothRadio.PrimaryRadio.LocalAddress.ToString());

                            // Pin needs to be added before doing the pair request.

                            new BluetoothWin32Authentication(btItem.DeviceAddress, btPin);

                            // Null forces legacy pin request instead of SSP authentication.

                            BluetoothSecurity.PairRequest(btItem.DeviceAddress, null);
                        }

                        // Install as a HID device and allow some time for it to finish.

                        btItem.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
                    }

                    // Allow slow computers to finish installation before connecting.

                    System.Threading.Thread.Sleep(4000);

                    // Connect and send a command, otherwise they sleep and the device disappears.

                    try
                    {
                        if (btDiscoveredList.Length > btIgnored)
                        {
                            var deviceCollection = new WiimoteCollection();
                            deviceCollection.FindAllWiimotes();

                            foreach (var wiiDevice in deviceCollection)
                            {
                                wiiDevice.Connect();
                                wiiDevice.SetLEDs(true, false, false, false);
                                wiiDevice.Disconnect();
                            }
                        }
                    }
                    catch (Exception) { }

                    // Status report.

                    label_Status.Text = "Finished - You can now close this window. Found: " + btDiscoveredList.Length + " Ignored: " + btIgnored;
                    label_Status.Refresh();
                }
            }
            catch (Exception ex)
            {
                label_Status.Text = "Error: " + ex.Message;
            }

            ((Button)sender).Enabled = true;
        }
Ejemplo n.º 39
0
 /// <summary>
 /// Static constructor
 /// </summary>
 static Wiimote()
 {
     sWiimotes = new WiimoteCollection();
     sWiimotes.FindAllWiimotes();
 }
Ejemplo n.º 40
0
	}//eof




    /// <summary>
    /// This is the method that actually does the work.
    /// </summary>
	protected override void SolveInstance(IGH_DataAccess DA)
	{
        string message = "";
        bool start = false;
        if (!DA.GetData(0, ref start)) return;

        if (start)
        {
            if (!startedBefore)
            {
                //start wii connection
                wiiCollection = new WiimoteCollection();
                wiiObjList = new List<WiiObj>();

                try
                {
                    wiiCollection.FindAllWiimotes();
                    startedBefore = true;

                    foreach (Wiimote wiimote in wiiCollection)
                    {
                        wiiObjList.Add(new WiiObj(wiimote));
                    }
                }
                catch (WiimoteNotFoundException ex)
                {
                    System.Console.Write("Wiimote not found error");
                    message = "Error: " + ex.Message;
                }
                catch (WiimoteException ex)
                {
                    System.Console.Write("Wiimote error");
                    message = "Error: " + ex.Message;
                }
                catch (Exception ex)
                {
                    System.Console.Write("Unknown error");
                    message = "Error: " + ex.Message;
                }
            }
        }
        else
        {
            if(startedBefore)
            {
                //disconnect from wii
                startedBefore = false;

                foreach (WiiObj o in wiiObjList)
                    o.disconnect();
            }
        }


        //put latest status in output
        if(startedBefore)
        {
            DA.SetDataList(0, wiiObjList);
            message = "Connected!";
        }

        DA.SetData(1, message);
	}//eof
Ejemplo n.º 41
0
        //-----------------------------------------------------------------------
        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;
        }
Ejemplo n.º 42
0
        private void AddWiimoteDevices()
        {
            WiimoteCollection wiiMoteCollection = new WiimoteCollection();

            try
            {
                wiiMoteCollection.FindAllWiimotes();
            }
            catch (WiimoteNotFoundException) { }
            catch (WiimoteException)
            {
                Console.WriteLine("Wiimote error");
            }

            foreach (Wiimote wiimote in wiiMoteCollection)
            {
                if (!CheckIfWiimoteInputDeviceExists(wiimote))
                {
                    WiimoteInput input = new WiimoteInput(wiimote);
                    AddInputDevice(input);
                    input.InitCurrentlyInvokedInput();

                    wiimote.SetLEDs(false, false, false, false);

                    InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
                }
            }
        }