Beispiel #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);
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        //costruttore quando si usa una sola balanceboard
        //public Menu(Engine game, Wiimote balanceBoard)
        //    : base(game)
        //{
        //    this.Enabled = false;
        //    this.Visible = false;
        //    this.balanceBoard = balanceBoard;
        //    this.game = game;
        //}

        //costrutture da usare quando ci sono più balanceboards
        public Menu(Engine game, WiimoteCollection balanceBoards) : base(game)
        {
            this.Enabled       = false;
            this.Visible       = false;
            this.balanceBoards = balanceBoards;
            this.game          = game;
        }
Beispiel #4
0
        /// <summary>
        /// Construct a new wiimote provider.
        /// </summary>
        public MultiWiiPointerProvider()
        {
            this.pWC = new WiimoteCollection();

            this.wiimoteChangedEventHandler          = new EventHandler <WiimoteChangedEventArgs>(handleWiimoteChanged);
            this.wiimoteExtensionChangedEventHandler = new EventHandler <WiimoteExtensionChangedEventArgs>(handleWiimoteExtensionChanged);

            wiimoteConnectorTimer = new Timer(wiimoteConnectorTimer_Elapsed, null, Timeout.Infinite, CONNECTION_THREAD_SLEEP);

            wiimoteHandlerThread              = new Thread(WiimoteHandlerWorker);
            wiimoteHandlerThread.Priority     = ThreadPriority.Highest;
            wiimoteHandlerThread.IsBackground = true;
            wiimoteHandlerThread.Start();

            /*
             * this.mouseMode = this.keyMapper.KeyMap.Pointer.ToLower() == "mouse";
             * this.showPointer = Settings.Default.pointer_moveCursor;
             * if (this.showPointer && !this.mouseMode)
             * {
             *  this.duoTouch.enableHover();
             * }
             * else
             * {
             *  this.duoTouch.disableHover();
             * }
             */
        }
Beispiel #5
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");
            }
        }
        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);
        }
Beispiel #7
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);
            }
        }
        private int WIIMOTE_SIGNIFICANT_DISCONNECT_TIMEOUT = Settings.Default.autoDisconnectTimeout; //If we haven't recieved significant input from a wiimote in 60 seconds we will put it to sleep

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Construct a new wiimote provider.
        /// </summary>
        public MultiWiiPointerProvider()
        {
            this.pWC = new WiimoteCollection();

            this.wiimoteChangedEventHandler = new EventHandler<WiimoteChangedEventArgs>(handleWiimoteChanged);
            this.wiimoteExtensionChangedEventHandler = new EventHandler<WiimoteExtensionChangedEventArgs>(handleWiimoteExtensionChanged);

            wiimoteConnectorTimer = new Timer(wiimoteConnectorTimer_Elapsed, null, Timeout.Infinite, CONNECTION_THREAD_SLEEP);

            wiimoteHandlerThread = new Thread(WiimoteHandlerWorker);
            wiimoteHandlerThread.Priority = ThreadPriority.Highest;
            wiimoteHandlerThread.IsBackground = true;
            wiimoteHandlerThread.Start();

            /*
            this.mouseMode = this.keyMapper.KeyMap.Pointer.ToLower() == "mouse";
            this.showPointer = Settings.Default.pointer_moveCursor;
            if (this.showPointer && !this.mouseMode)
            {
                this.duoTouch.enableHover();
            }
            else
            {
                this.duoTouch.disableHover();
            }
            */
        }
Beispiel #9
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);
            }
        }
Beispiel #10
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();
                });
            }));
        }
        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;
        }
Beispiel #12
0
        private void findAll()
        {
            var collection = new WiimoteCollection();

            collection.FindAllWiimotes();
            Wiimote = collection[0];
        }
Beispiel #13
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);
        }
Beispiel #14
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);
        }
Beispiel #15
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];
        }
        //プログラムロード時に走るコード
        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++;
            }
        }
Beispiel #17
0
 //costruttore quando si usa una sola balanceboard
 //public Menu(Engine game, Wiimote balanceBoard)
 //    : base(game)
 //{
 //    this.Enabled = false;
 //    this.Visible = false;
 //    this.balanceBoard = balanceBoard;
 //    this.game = game;
 //}
 //costrutture da usare quando ci sono più balanceboards
 public Menu(Engine game, WiimoteCollection balanceBoards)
     : base(game)
 {
     this.Enabled = false;
     this.Visible = false;
     this.balanceBoards = balanceBoards;
     this.game = game;
 }
Beispiel #18
0
 public frmSplash(WiimoteCollection mWC, bool isStartup)
 {
     this.InitializeComponent();
     this._mWC = mWC;
     this.findAllWiiMotes();
     this.tsProgbar.Maximum = this._mWC.Count;
     this._isStartUp        = isStartup;
 }
 public WiiBoardService()
 {
     WiiBoardServiceState = WiiBoardServiceState.Unknown;
     _offsetRecord        = new List <float>();
     _measureRecord       = new List <float>();
     _foundDebice         = false;
     IsInitialized        = false;
     WiimoteCollection    = new WiimoteCollection();
 }
Beispiel #20
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);
            }
        }
Beispiel #21
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();
        }
Beispiel #22
0
 //overloading, metodo da usare con più balanceboards
 public PlayScreen(Game game, WiimoteCollection balanceBoards)
     : base(game)
 {
     currLevel          = 0;
     usingBalanceBoards = true;
     this.Enabled       = false;
     this.Visible       = false;
     stage = new Model[3];
     this.balanceBoards = balanceBoards;
 }
Beispiel #23
0
 public frmMDIMain()
 {
     this.InitializeComponent();
     this.mWiimoteMap   = new Dictionary <Guid, frmDataWindow>();
     this.mWC           = new WiimoteCollection();
     this.updateClosing = false;
     this.dataToSave    = false;
     this.dataToDisplay = false;
     this.showSplash(true);
 }
Beispiel #24
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();
        }
Beispiel #25
0
 //-----------------------------------------------------------------------
 public override void Stop()
 {
     if (Motes != null)
     {
         for (int i = 0; i < Motes.Count; i++)
         {
             Wiimote wii = Motes.ElementAt(i);
             wii.SetLEDs(false, false, false, false);
             wii.Disconnect();
         }
         Motes = null;
     }
 }
Beispiel #26
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);
            }
        }
Beispiel #27
0
        /// <summary>
        /// Construct a new wiimote provider.
        /// </summary>
        public MultiWiiPointerProvider()
        {
            this.pWC = new WiimoteCollection();

            this.wiimoteChangedEventHandler          = new EventHandler <WiimoteChangedEventArgs>(handleWiimoteChanged);
            this.wiimoteExtensionChangedEventHandler = new EventHandler <WiimoteExtensionChangedEventArgs>(handleWiimoteExtensionChanged);

            wiimoteConnectorTimer = new Timer(wiimoteConnectorTimer_Elapsed, null, Timeout.Infinite, CONNECTION_THREAD_SLEEP);

            wiimoteHandlerThread              = new Thread(WiimoteHandlerWorker);
            wiimoteHandlerThread.Priority     = ThreadPriority.Highest;
            wiimoteHandlerThread.IsBackground = true;
            wiimoteHandlerThread.Start();
        }
Beispiel #28
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);
        }
Beispiel #29
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++);
            }
        }
        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);
                }
            }
        }
Beispiel #32
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;
        }
        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;
            }
            //}
        }
Beispiel #34
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
Beispiel #35
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;
            //            }
        }
Beispiel #36
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];
            }
        }
Beispiel #37
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);
        }
Beispiel #38
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);
        }
Beispiel #39
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);
     }
 }
Beispiel #40
0
        public Engine()
        {
            graphics = new GraphicsDeviceManager(this);
            balanceBoard = new Wiimote();
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1000;
            graphics.ToggleFullScreen();

            Content.RootDirectory = "Content";
            usingBalanceBoard = false;
            balanceBoards = new WiimoteCollection();
            //old
            //level = new PlayScreen(this,balanceBoard);
            level = new PlayScreen(this, balanceBoards);
            //old
            //menu = new Menu(this, balanceBoard);
            menu = new Menu(this, balanceBoards);
            saveScore = new SaveScore(this);
            this.Components.Add(menu);
            this.Components.Add(saveScore);
            this.Components.Add(level);
            status = 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;
        }
Beispiel #42
0
 /// <summary>
 /// Static constructor
 /// </summary>
 static Wiimote()
 {
     sWiimotes = new WiimoteCollection();
     sWiimotes.FindAllWiimotes();
 }
Beispiel #43
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);
        }
 public void Initialise(Viewer viewer)
 {
     // Mandatory initialization of Reference
     Reference = viewer.Reference;
     wiiCollection = new WiimoteCollection();
 }
Beispiel #45
0
 //overloading, metodo da usare con più balanceboards
 public PlayScreen(Game game, WiimoteCollection balanceBoards)
     : base(game)
 {
     currLevel = 0;
     usingBalanceBoards = true;
     this.Enabled = false;
     this.Visible = false;
     stage = new Model[3];
     this.balanceBoards = balanceBoards;
 }
Beispiel #46
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;
        }
Beispiel #47
0
        //-----------------------------------------------------------------------
        public override void Stop()
        {
            if (Motes != null) {

            for (int i=0; i<Motes.Count; i++) {
               Wiimote wii = Motes.ElementAt(i);
               wii.SetLEDs(false, false, false, false);
               wii.Disconnect();
            }
            Motes = null;
             }
        }
        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);
                }
            }
        }
        // Defining containers for the accelerometer , IR positions ; Might not be necessary since the Wiimote is sending info through it's Events to the Service listeners.


        // Structures to hold the x , y , and sensor size 


        public WiimoteHandler()
        {
            this.mWiimotes = new WiimoteCollection();
            aggregators = new WiimoteSampleAggregator[2];
            coordinateSet = new WiimoteCoordinate[2];
        }