Пример #1
0
        private bool irDetected = false;                                                             // 赤外線を検出しているか

        private void ConnectWiimote()
        {
            // Bluetooth 認識
            var btutil = new BTUtil();

            btutil.ShowDialog();
            if (btutil.userClosed)
            {
                Debug.WriteLine("Exit -> BTUtil User Closed.");

                notifyIcon.Visible = false;
                Environment.Exit(0);
            }

            // Wiimote接続
            mWiimote = new Wiimote();

            try
            {
                mWiimote.WiimoteChanged          += (s, args) => UpdateState(args);
                mWiimote.WiimoteExtensionChanged += (s, args) => UpdateExtension(args);
                mWiimote.Connect();
                mWiimote.SetReportType(InputReport.IRExtensionAccel, true);
                mWiimote.SetLEDs(true, false, false, false);

                mWiimote.SetRumble(true);
                System.Threading.Thread.Sleep(200);
                mWiimote.SetRumble(false);
            }
            catch (Exception ex)
            {
                string msg;

                switch (ex)
                {
                case WiimoteNotFoundException _:
                    msg = "Wiiリモコンを認識できませんでした。";
                    break;

                case WiimoteException _:
                    msg = "Wiiリモコンに何らかのエラーが発生しました。";
                    break;

                default:
                    msg = "予期せぬエラーが発生しました。";
                    break;
                }

                MessageBox.Show(
                    msg,
                    "エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                Environment.Exit(1);
            }
        }
Пример #2
0
        private void 終了QToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mWiimote.SetLEDs(false, false, false, false);

            if (終了時に切断ToolStripMenuItem.Checked)
            {
                this.Text = "Wiimote PPT - 切断中...";
                mWiimote.Disconnect();
                var count = 0;
                while (count >= 30)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(100);
                }
                var btutil = new BTUtil();
                btutil.disconnectWiimote();
            }

            notifyIcon.Visible = false;
            Environment.Exit(0);
        }