Пример #1
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++;
            }
        }
Пример #2
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();
        }
Пример #3
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++);
            }
        }
Пример #5
0
        void wm_WiimoteExtensionChanged(object sender, WiimoteExtensionChangedEventArgs e)
        {
            // Encontrar el controlador para este Wiimote
            WiimoteInfo wi = mWiimoteMap[((Wiimote)sender).ID];

            wi.UpdateExtension(e);

            if (e.Inserted)
            {
                ((Wiimote)sender).SetReportType(InputReport.IRExtensionAccel, true);
            }
            else
            {
                ((Wiimote)sender).SetReportType(InputReport.IRAccel, true);
            }
        }
Пример #6
0
        //wiimoteのステータスが変わったのを検知して起動するイベント
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            //表示系(Form)の情報更新
            WiimoteInfo wi = mWiimoteMap[((Wiimote)sender).ID];

            wi.UpdateState(e);

            //WiimoteStateの値を取得
            wiimoteState = e.WiimoteState;

            switch (wiimoteState.ExtensionType)
            {
            //接続相手がbalanceboardであれば
            case ExtensionType.BalanceBoard:

                //デバッグ表示用
                //重さ(Kg)
                string weight = wiimoteState.BalanceBoardState.WeightKg + "kg";
                //重心のX座標
                string posX = "X:" +
                              wiimoteState.BalanceBoardState.CenterOfGravity.X;
                //重心のY座標
                string posY = "Y:" +
                              wiimoteState.BalanceBoardState.CenterOfGravity.Y;

                //送信用データリストを更新する
                //ここで横流しするデータを更新している
                WiimoteMessage message = new WiimoteMessage();                                                          //データ用意
                message.index   = wi.index;
                message.weight  = wiimoteState.BalanceBoardState.WeightKg;
                message.copPosX = wiimoteState.BalanceBoardState.CenterOfGravity.X;
                message.copPosY = wiimoteState.BalanceBoardState.CenterOfGravity.Y;

                message.loadTopRight    = wiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
                message.loadTopLeft     = wiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
                message.loadBottomRight = wiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;
                message.loadBottomLeft  = wiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;

                server.UpdateMessage(wi.index, message);                                                                //更新

                break;
            }
        }
Пример #7
0
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            WiimoteInfo wi = mWiimoteMap[((Wiimote)sender).ID];

            wi.UpdateState(e);
        }
Пример #8
0
        //wiimoteのステータスが変わったのを検知して起動するイベント
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            //表示系(Form)の情報更新
            WiimoteInfo wi = mWiimoteMap[((Wiimote)sender).ID];

            wi.UpdateState(e);

            //WiimoteStateの値を取得
            wiimoteState = e.WiimoteState;

            //デバッグ表示用

            //string xacc = wiimoteState.AccelState.Values.X + "kg";

            //string yacc = "X:" +
            //wiimoteState.AccelState.Values.Y;

            //string zacc = "Y:" +
            //wiimoteState.AccelState.Values.Z;

            //送信用データリストを更新する
            //ここで横流しするデータを更新している

            /*WiimoteMessage message = new WiimoteMessage();                                                      //データ用意
             * message.index = wi.index;
             * message.xacc = wiimoteState.AccelState.Values.X;
             * message.yacc = wiimoteState.AccelState.Values.Y;
             * message.zacc = wiimoteState.AccelState.Values.Z;
             * message.up = wiimoteState.ButtonState.Up;
             * message.down = wiimoteState.ButtonState.Down;
             * message.right = wiimoteState.ButtonState.Right;
             * message.left = wiimoteState.ButtonState.Left;
             * message.a = wiimoteState.ButtonState.A;
             * message.b = wiimoteState.ButtonState.B;
             * message.home = wiimoteState.ButtonState.Home;
             *
             * server.UpdateMessage(wi.index, message);
             */


            switch (wiimoteState.ExtensionType)
            {
            //接続相手がbalanceboardであれば
            case ExtensionType.MotionPlus:



                //デバッグ表示用
                //重さ(Kg)
                //string weight = wiimoteState.BalanceBoardState.WeightKg + "kg";
                //重心のX座標
                //string posX = "X:" +
                //  wiimoteState.BalanceBoardState.CenterOfGravity.X;
                //重心のY座標
                //string posY = "Y:" +
                //    wiimoteState.BalanceBoardState.CenterOfGravity.Y;

                //送信用データリストを更新する
                //ここで横流しするデータを更新している
                WiimoteMessage message = new WiimoteMessage();
                message.index = wi.index;
                message.xacc  = wiimoteState.AccelState.Values.X;
                message.yacc  = wiimoteState.AccelState.Values.Y;
                message.zacc  = wiimoteState.AccelState.Values.Z;
                message.yaw   = wiimoteState.MotionPlusState.RawValues.X;
                message.pitch = wiimoteState.MotionPlusState.RawValues.Z;
                message.roll  = wiimoteState.MotionPlusState.RawValues.Y;
                message.up    = wiimoteState.ButtonState.Up;
                message.down  = wiimoteState.ButtonState.Down;
                message.right = wiimoteState.ButtonState.Right;
                message.left  = wiimoteState.ButtonState.Left;
                message.a     = wiimoteState.ButtonState.A;
                message.b     = wiimoteState.ButtonState.B;
                message.home  = wiimoteState.ButtonState.Home;


                server.UpdateMessage(wi.index, message);                  //更新



                break;
            }
        }