예제 #1
0
 // Assignment constructor
 // Is passed a Wiimote object and assigns it to the instance in the WiimoteInfo class
 public WiimoteInfo(Wiimote wm)
     : this()
 {
     mWiimote = wm;
     wm.SetLEDs(true, false, false, false);//recentlly added for GTA video
     sp.Open();
 }
예제 #2
0
	// Use this for initialization
	void Start()
	{
        music.Play();
        cups = "UUUUUUUUUUUU";
        if (usingWiimote)
        {
            WiimoteManager.FindWiimotes();
            wiiController = WiimoteManager.Wiimotes[0];
            RumbleWii(true);
            iTween.ScaleBy(gameObject, iTween.Hash("time", 0.6f, "oncomplete", "RumbleWii", "oncompletetarget", gameObject, "oncompleteparams", false));
            wiiController.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL);
            wiiController.DeactivateWiiMotionPlus();
        }
        rayOn = true;
		playEnabled = true;
        throwSet = false;
        myBallPos = myBallVel = Vector3.zero;
        oldVecz = 0;
        newVecz = 0;
        leftRightMotion = 0;
		myPoints = 0;
        velocity = 0;
        finalVel = 0;
        fVelTime = 0;
        curCups = 0;

        //UnityEngine.VR.VRSettings.enabled = !UnityEngine.VR.VRSettings.enabled;
        EnablePlay();
    }
	void updateWiiMote ()
	{


		wiimote = WiimoteManager.Wiimotes [0];
		wiimote.SendDataReportMode (InputDataType.REPORT_BUTTONS_ACCEL);
	
		wiimote.SendPlayerLED (true, false, false, true);
		int ret;
		do {
			ret = wiimote.ReadWiimoteData ();
			oldAccelerations = accelerations;
			accelerations = getAccelerationVector ();

			velocity = calculateVelocity (oldAccelerations, accelerations);
			int direction = (isMoving (velocity)) ? (int)getDirection (velocity) : 5;
			Debug.Log (direction);
			if (wiimote.Button.a) {

			}
			if (wiimote.Button.b) {
				wiimote.Accel.CalibrateAccel (0);

			}
			if (wiimote.Button.minus) {
				//FinishedWithWiimotes();
			}
		} while (ret > 0);
	}
예제 #4
0
	void OnGUI() {
		GUI.Box(new Rect(0,0,300,Screen.height), "");

        GUILayout.BeginVertical(GUILayout.Width(300));
        GUILayout.Label("Wiimote Found: " + WiimoteManager.HasWiimote());
        if (GUILayout.Button("Find Wiimote"))
            WiimoteManager.FindWiimotes();

        if (GUILayout.Button("Cleanup"))
        {
            WiimoteManager.Cleanup(wiimote);
            wiimote = null;
        }

        GUILayout.Label("LED Test:");
        GUILayout.BeginHorizontal();
        for (int x = 0; x < 4;x++ )
            if (GUILayout.Button(""+x, GUILayout.Width(300/4)))
                wiimote.SendPlayerLED(x == 0, x == 1, x == 2, x == 3);
        GUILayout.EndHorizontal();

        if(wiimote != null && wiimote.Type == WiimoteType.PROCONTROLLER) {
        	float[] ls = wiimote.WiiUPro.GetLeftStick01();
        	float[] rs = wiimote.WiiUPro.GetRightStick01();
        	GUILayout.Label("LS: "+ls[0]+","+ls[1]);
        	GUILayout.Label("RS: "+rs[0]+","+rs[1]);
        }

        GUILayout.EndVertical();

        if (wiimote != null)
            windowRect = GUI.Window(0, windowRect, DataWindow, "Data");
	}
예제 #5
0
 void OnApplicationQuit()
 {
     if (wiimote != null) {
         WiimoteManager.Cleanup(wiimote);
         wiimote = null;
     }
 }
예제 #6
0
 void OnApplicationQuit()
 {
     if (wiimote != null)
     {
         WiimoteManager.Cleanup(wiimote);
         wiimote = null;
     }
 }
예제 #7
0
 void OnDestroy()
 {
     if (wiimote != null)
     {
         WiimoteManager.Cleanup(wiimote);
         wiimote = null;
     }
 }
예제 #8
0
 private void OnApplicationQuit()
 {
     if (wiimoteRed != null)
     {
         WiimoteManager.Cleanup(wiimoteRed);
         wiimoteRed = null;
     }
 }
예제 #9
0
 public void Reset()
 {
     if (WiimoteManager.HasWiimote())
     {
         WiimoteManager.Cleanup(_wiimote);
     }
     _wiimote = null;
 }
 private void OnApplicationQuit()
 {
     if (wiimoteBlue != null)
     {
         WiimoteManager.Cleanup(wiimoteBlue);
         wiimoteBlue = null;
     }
 }
예제 #11
0
 /// <summary>
 /// Default constructor setting all calibrations to their defaults.
 /// </summary>
 public CalibrationStorage()
 {
     ProCalibration        = Calibrations.Defaults.ProControllerDefault;
     WiimoteCalibration    = Calibrations.Defaults.WiimoteDefault;
     NunchukCalibration    = Calibrations.Defaults.NunchukDefault;
     ClassicCalibration    = Calibrations.Defaults.ClassicControllerDefault;
     ClassicProCalibration = Calibrations.Defaults.ClassicControllerProDefault;
 }
예제 #12
0
 public Buzzer(string GroupName, Color Color, int Index, Wiimote Wiimote)
 {
     this.GroupName    = GroupName;
     this.Color        = Color;
     this.Index        = Index;
     this.Wiimote      = Wiimote;
     this.BuzzedNumber = 0;
 }
예제 #13
0
 private void OnApplicationQuit()
 {
     if (!(InputManager.inputs && InputManager.inputs.enabled) && wiimote != null)
     {
         WiimoteManager.Cleanup(wiimote);
         wiimote = null;
     }
 }
예제 #14
0
        public float GetWeight(Wiimote board)
        {
            var weight           = board.WiimoteState.BalanceBoardState.WeightKg;
            var calibratedWeight = weight - calibration;

            Debug.WriteLine(string.Format("Weight {0}kg (uncalibrated {1}kg)", calibratedWeight, weight));
            return(calibratedWeight);
        }
예제 #15
0
파일: WiiTest.cs 프로젝트: misoten8/Mock
    // 更新処理
    void Update()
    {
        // 接続されていなかったら終了
        if (!WiimoteManager.HasWiimote())
        {
            return;
        }

        // 1Pに保存
        wm = WiimoteManager.Wiimotes[0];
        //int ret;
        //do
        //{
        //	// リモコンの情報を更新
        //	ret = wm.ReadWiimoteData();

        //	if (ret > 0 && wm.current_ext == ExtensionController.MOTIONPLUS)
        //	{
        //		Vector3 offset = new Vector3(-wm.MotionPlus.PitchSpeed,
        //										wm.MotionPlus.YawSpeed,
        //										wm.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote)
        //		wmpOffset += offset;

        //		//wmModel.rot.Rotate(offset, Space.Self);
        //	}
        //} while (ret > 0);

        // ボタン降下情報
        //wmModel.a.enabled = wm.Button.a;
        //wmModel.b.enabled = wm.Button.b;
        //wmModel.one.enabled = wm.Button.one;
        //wmModel.two.enabled = wm.Button.two;
        //wmModel.d_up.enabled = wm.Button.d_up;
        //wmModel.d_down.enabled = wm.Button.d_down;
        //wmModel.d_left.enabled = wm.Button.d_left;
        //wmModel.d_right.enabled = wm.Button.d_right;
        //wmModel.plus.enabled = wm.Button.plus;
        //wmModel.minus.enabled = wm.Button.minus;
        //wmModel.home.enabled = wm.Button.home;

        // 加速度取得
        //Debug.Log(wmAccel =wm.Accel.GetAccelVector());

        // 振っているか判定
        //wmSwing = wm.Accel.GetSwing();

        // Wiiリモコンプラスでなければモデルは回転しない
        if (wm.current_ext != ExtensionController.MOTIONPLUS)
        {
            //wmModel.rot.localRotation = initialRotation;
        }

        // モーションプラスがアクティブになっていければ終了
        if (!wm.wmp_attached)
        {
            return;
        }
    }
예제 #16
0
    // Update is called once per frame
    void Update()
    {
        controlWii = GetComponent <CollisionHands>().controlWii;
        if (collision.TouchingFurniture() && collision.isGrabbed && controlWii != null)
        {
            int ret;
            do
            {
                ret = controlWii.ReadWiimoteData();

                if (ret > 0 && controlWii.current_ext == ExtensionController.MOTIONPLUS)
                {
                    Vector3 offset = new Vector3(-controlWii.MotionPlus.PitchSpeed,
                                                 controlWii.MotionPlus.YawSpeed,
                                                 controlWii.MotionPlus.RollSpeed) / 95f;    // Divide by 95Hz (average updates per second from wiimote)
                                                                                            //wmpOffset += offset;

                    //model.rot.Rotate(offset, Space.Self);
                }
            } while (ret > 0);
            NunchuckData data = controlWii.Nunchuck;
            if (data.c && !data.z)
            {
                transform.parent = GameObject.FindGameObjectWithTag("vista").transform;
                Vector3 acc = GetAccelVector();
                transform.position   = new Vector3(transform.parent.position.x, transform.parent.position.y, transform.parent.position.z);
                transform.localScale = scale.actualScale / 3;
                if (acc.y >= -0.2f)
                {
                    transform.Rotate(new Vector3(0, 0, 10));
                }
                else if (acc.y <= -0.7f)
                {
                    transform.Rotate(new Vector3(0, 0, -10));
                }
                else if (data.stick[0] - 125 > 10)
                {
                    transform.Rotate(0, 10, 0);
                }
                else if (data.stick[0] - 125 < -10)
                {
                    transform.Rotate(0, -10, 0);
                }
                else if (data.stick[1] - 130 > 10)
                {
                    transform.Rotate(10, 0, 0);
                }
                else if (data.stick[1] - 130 < -10)
                {
                    transform.Rotate(-10, 0, 0);
                }
                else
                {
                    transform.localScale = scale.actualScale;
                }
            }
        }
    }
예제 #17
0
 void SetWiimoteLeds(Wiimote remote, int i)
 {
     remote.SendPlayerLED(
         ledsList[i % ledsList.Length][0],
         ledsList[i % ledsList.Length][1],
         ledsList[i % ledsList.Length][2],
         ledsList[i % ledsList.Length][3]
         );
 }
    private void CollectWiimoteData(Wiimote wiimote)
    {
        int ret;

        do
        {
            ret = wiimote.ReadWiimoteData();
        } while (ret > 0);
    }
예제 #19
0
        private void reportingmodeBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ReportingMode selectedReportingMode = (ReportingMode)reportingmodeBox.SelectedItem;

            if (Wiimote.ReportingMode != selectedReportingMode && selectedReportingMode != ReportingMode.None)
            {
                Wiimote.SetReportingMode(selectedReportingMode);
            }
        }
예제 #20
0
파일: Form1.cs 프로젝트: oyakodon/Wiimote
        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);
            }
        }
예제 #21
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);
            }
        }
예제 #22
0
 public void QuitGame()
 {
     if (wiiRemote != null)
     {
         WiimoteManager.Cleanup(wiiRemote);
         wiiRemote = null;
     }
     Application.Quit();
 }
예제 #23
0
    void SearchAndInitialize()
    {
        WiimoteManager.FindWiimotes();

        wiimote = WiimoteManager.Wiimotes[0];
        wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL);
        wiimote.SetupIRCamera(IRDataType.EXTENDED);
        wiimote.SendPlayerLED(true, true, true, true);
    }
예제 #24
0
 internal static void Disconnect()
 {
     if (Wiimote != null)
     {
         Wiimote.SetLEDs(false, false, false, false);
         Wiimote.Disconnect();
         Wiimote = null;
     }
 }
예제 #25
0
        private void connectRumble(object device)
        {
            Wiimote wiimote = (Wiimote)device;

            Thread.Sleep(CONNECT_RUMBLE_TIME);
            wiimote.SetRumble(true);
            Thread.Sleep(CONNECT_RUMBLE_TIME);
            wiimote.SetRumble(false);
        }
예제 #26
0
    private void Update()
    {
        wiimote = InputManager.wiimote;
        if (wiimote == null)
        {
            foreach (Button type in buttonTypes)
            {
                buttonDown[type]     = false;
                buttonDownFlag[type] = false;
                buttonUp[type]       = false;
                buttonUpFlag[type]   = false;
            }
            return;
        }

        foreach (Button type in buttonTypes)
        {
            // Button pressed
            if (GetCorrespondingWiimoteButton(type))
            {
                // Down - check
                if (!buttonDownFlag[type])
                {
                    buttonDown[type]     = true;
                    buttonDownFlag[type] = true;
                }
                else
                {
                    buttonDown[type] = false;
                }

                // Up - set false
                buttonUp[type]     = false;
                buttonUpFlag[type] = false;

                // Button not pressed
            }
            else
            {
                // Down - set false
                buttonDown[type]     = false;
                buttonDownFlag[type] = false;

                // Up - check
                if (!buttonUpFlag[type])
                {
                    buttonUp[type]     = true;
                    buttonUpFlag[type] = true;
                }
                else
                {
                    buttonUp[type] = false;
                }
            }
        }
    }
예제 #27
0
        // ------------------------------------------------------------------------------------------
        // ------------------------------           Form Events          ------------------------------
        // ------------------------------------------------------------------------------------------
        private void Form1_Load(object sender, EventArgs e)
        {
            // スクリーンの大きさ取得
            foreach (var s in Screen.AllScreens)
            {
                if (s.Bounds.X < 0)
                {
                    MinXY.X += s.Bounds.X;
                }
                if (s.Bounds.Y < 0)
                {
                    MinXY.Y += s.Bounds.Y;
                }
                if (s.Bounds.X > 0)
                {
                    MaxXY.X += s.Bounds.X;
                }
                if (s.Bounds.Y > 0)
                {
                    MaxXY.Y += s.Bounds.Y;
                }
            }
            MaxXY.X += Screen.PrimaryScreen.Bounds.Width;
            MaxXY.Y += Screen.PrimaryScreen.Bounds.Height;

            // カーソルの取得と通知テキスト設定
            CursorPoint      = Cursor.Position;
            notifyIcon1.Text = "Wiimote Mouse : Disabled";

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

            try
            {
                mWiimote.WiimoteChanged          += (s, args) => UpdateState(args);
                mWiimote.WiimoteExtensionChanged += (s, args) => UpdateExtension(args);
                mWiimote.Connect();
                mWiimote.SetReportType(InputReport.IRExtensionAccel, true);
                mWiimote.SetLEDs(true, false, false, true);
            }
            catch (WiimoteNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Wiimote not found error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }
            catch (WiimoteException ex)
            {
                MessageBox.Show(ex.Message, "Wiimote error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unknown error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }
        }
예제 #28
0
    public void InitWiimotes()
    {
        WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes

        if (WiimoteManager.HasWiimote())
          _wiimote = WiimoteManager.Wiimotes[0];

        Debug.Log(_wiimote);
        if (_wiimote != null) _wiimote.SendPlayerLED(true, false, false, false);
    }
예제 #29
0
    // Use this for initialization
    void Start()
    {
        WiimoteManager.FindWiimotes();
        wiimote = WiimoteManager.Wiimotes[0];
        wiimote.RequestIdentifyWiiMotionPlus();
        wiimote.ActivateWiiMotionPlus();
        wiimote.SetupIRCamera(IRDataType.BASIC);

        pivot = transform.parent;
    }
예제 #30
0
 void InitWiimotes()
 {
     WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes
     foreach (Wiimote remote in WiimoteManager.Wiimotes)
     {
         remote.SendPlayerLED(true, false, false, true);
         remote.SetupIRCamera(IRDataType.BASIC);     // Basic IR dot position data
         wiimote = remote;
     }
 }
예제 #31
0
 void InitWiimotes()
 {
     WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes
     foreach (Wiimote remote in WiimoteManager.Wiimotes)
     {
         // Do stuff.
         Debug.Log("Found Wiimote");
         this.remote = remote;
     }
 }
예제 #32
0
 void InitWiimotes()
 {
     WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes
     foreach (Wiimote remote in WiimoteManager.Wiimotes)
     {
         // Do stuff.
         Debug.Log("Found Wiimote");
         this.remote = remote;
     }
 }
예제 #33
0
 public SingleWiimote()
 {
     this.InitializeComponent();
     mWiimote = new Wiimote();
     mWiimote.Connect();
     mWiimote.WiimoteChanged          += wm_WiimoteChanged;
     mWiimote.WiimoteExtensionChanged += wm_WiimoteExtensionChanged;
     mWiimote.SetReportType(InputReport.IRAccel, true);
     mWiimote.SetLEDs(false, true, true, false);
 }
예제 #34
0
    // Use this for initialization
    void Start()
    {
        // Hiermit kann man evtl. die beschleunigung etwas besser anpassen, damit das
        // Gefühl etwas besser wird beim fahren. Einfach in Doku nachlesen für genauere Infos.
        // m_Wheels[0].ConfigureVehicleSubsteps(criticalSpeed, stepsBelow, stepsAbove);

        rb        = this.gameObject.GetComponent <Rigidbody>();
        wiiDaten  = GetComponent <wiiKalibrierung>();
        wiiRemote = wiiDaten.wiiRemote;
    }
예제 #35
0
 // Update is called once per frame
 void Update()
 {
     if (receiver.wiimotes.ContainsKey(1))
     {
         Wiimote mymote = receiver.wiimotes[1];
         transform.rotation = initPosition;
         //float zTilt = ((mymote.BALANCE_TOPRIGHT + mymote.BALANCE_BOTTOMRIGHT)-(mymote.BALANCE_TOPLEFT + mymote.BALANCE_BOTTOMLEFT)) *20;
         //float xTilt = ((mymote.BALANCE_BOTTOMLEFT + mymote.BALANCE_BOTTOMRIGHT)-(mymote.BALANCE_TOPLEFT + mymote.BALANCE_TOPRIGHT)) *20;
         transform.Rotate(-mymote.MOTION_ANGLE_PITCH, (mymote.BUTTON_A * 50 - mymote.BUTTON_B * 50), -mymote.MOTION_ANGLE_ROLL);
     }
 }
예제 #36
0
 protected static bool CheckIfDeviceExists(Wiimote wiimote, List <GenericInput> currentDevices)
 {
     for (int i = 0; i < currentDevices.Count; i++)
     {
         if (wiimote.HIDDevicePath.ToString() == currentDevices[i].DeviceInstanceId)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #37
0
    void MainMenu()
    {
        WiimoteManager.FindWiimotes();
        controlWii = WiimoteManager.Wiimotes[0];
        //controlWii = transform.parent.GetComponent<MoveCamera>().controlWii;
        controlWii.SetupIRCamera(IRDataType.BASIC);
        if (controlWii != null)
        {
            int ret;
            do
            {
                ret = controlWii.ReadWiimoteData();

                if (ret > 0 && controlWii.current_ext == ExtensionController.MOTIONPLUS)
                {
                    Vector3 offset = new Vector3(-controlWii.MotionPlus.PitchSpeed,
                                                 controlWii.MotionPlus.YawSpeed,
                                                 controlWii.MotionPlus.RollSpeed) / 95f;    // Divide by 95Hz (average updates per second from wiimote)
                                                                                            //wmpOffset += offset;

                    //model.rot.Rotate(offset, Space.Self);
                }
            } while (ret > 0);

            NunchuckData data = controlWii.Nunchuck;

            if (data.c && data.z && created == false)
            {
                menu.transform.parent.GetComponent <MoveCamera>().enabled = false;
                CreateMenu();
                created = true;
            }
            else if (data.z && !data.c && created == true)
            {
                DestroyMenu();
                Destroy(GameObject.FindGameObjectWithTag("selection"));
                menu.transform.parent.GetComponent <MoveCamera>().enabled = true;
                created    = false;
                controlWii = null;
            }
            if (created == true)
            {
                int i = 0;
                while (i < opts.Length)
                {
                    if (opts[i].tag == "active")
                    {
                        activeOpt = opts[i];
                    }
                    i++;
                }
            }
        }
    }
예제 #38
0
    public void FinishedWithWiimotes()
    {
        /*foreach (Wiimote remote in WiimoteManager.Wiimotes) {
          WiimoteManager.Cleanup (remote);
        }*/

        if (WiimoteManager.HasWiimote())
        {
          WiimoteManager.Wiimotes[0].SendPlayerLED(false, false, false, false);
          WiimoteManager.Cleanup(WiimoteManager.Wiimotes[0]);
        }

        _wiimote = null;
    }
예제 #39
0
	void Update () {
		if (!WiimoteManager.HasWiimote()) { return; }

		bool n = wiimote == null;
        wiimote = WiimoteManager.Wiimotes[0];
        if(n && wiimote != null) {
        	wiimote.SendPlayerLED(true, false, false, false);
        	wiimote.SendDataReportMode(InputDataType.REPORT_EXT21);
        }

        int ret;
        do
        {
            ret = wiimote.ReadWiimoteData();
        } while (ret > 0);
	}
예제 #40
0
        private void AddNewWiimote(Wiimote NewWiimote)
        {
            if (AvailableIndices.Count == 0)
            {
                NewWiimote.Disconnect();
            }

            NewWiimote.WiimoteDisconnected += OnWiimoteDisconnected;
            NewWiimote.ButtonPressed += OnButtonPressed;

            int WiimoteIndex = AvailableIndices[0];
            AvailableIndices.RemoveAt(0);

            Wiimote.WiimoteLED LED = Wiimote.WiimoteLED.ALL;

            switch (WiimoteIndex)
            {
                case 0:
                    LED = Wiimote.WiimoteLED.LED1;
                    break;
                case 1:
                    LED = Wiimote.WiimoteLED.LED2;
                    break;
                case 2:
                    LED = Wiimote.WiimoteLED.LED3;
                    break;
                case 3:
                    LED = Wiimote.WiimoteLED.LED4;
                    break;
            }

            NewWiimote.SetLED(LED);
            RumbleWiimote(NewWiimote);

            Buzzer.Add(new Buzzer("Team " + (WiimoteIndex + 1), BuzzerColors[WiimoteIndex], WiimoteIndex, NewWiimote));
            Buzzer.Sort();
            BuzzerPanel.Items.Refresh();
        }
예제 #41
0
    void InitWiimotes()
    {
        WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes
        foreach (Wiimote remote in WiimoteManager.Wiimotes)
        {
            Debug.Log("Found Wiimote");
            playerCount++;
            if (playerCount == 1)
            {
                speedMote = remote;
                speedMote.SendPlayerLED(true, false, false, false);
                speedMote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL);
            }
            else
            {
                steering = remote;
                steering.SendPlayerLED(false, true, false, false);
                steering.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16);
                steering.RequestIdentifyWiiMotionPlus();
            }

        }
    }
예제 #42
0
    void Update()
    {
        if (!WiimoteManager.HasWiimote()) { return; }

        wiimote = WiimoteManager.Wiimotes[0];

        int ret;
        do
        {
            ret = wiimote.ReadWiimoteData();

            if (ret > 0 && wiimote.current_ext == ExtensionController.MOTIONPLUS) {
                Vector3 offset = new Vector3(  -wiimote.MotionPlus.PitchSpeed,
                                                wiimote.MotionPlus.YawSpeed,
                                                wiimote.MotionPlus.RollSpeed) / 95f; // Divide by 95Hz (average updates per second from wiimote)
                wmpOffset += offset;

                model.rot.Rotate(offset, Space.Self);
            }
        } while (ret > 0);

        model.a.enabled = wiimote.Button.a;
        model.b.enabled = wiimote.Button.b;
        model.one.enabled = wiimote.Button.one;
        model.two.enabled = wiimote.Button.two;
        model.d_up.enabled = wiimote.Button.d_up;
        model.d_down.enabled = wiimote.Button.d_down;
        model.d_left.enabled = wiimote.Button.d_left;
        model.d_right.enabled = wiimote.Button.d_right;
        model.plus.enabled = wiimote.Button.plus;
        model.minus.enabled = wiimote.Button.minus;
        model.home.enabled = wiimote.Button.home;

        if (wiimote.current_ext != ExtensionController.MOTIONPLUS)
            model.rot.localRotation = initial_rotation;

        if (ir_dots.Length < 4) return;

        float[,] ir = wiimote.Ir.GetProbableSensorBarIR();
        for (int i = 0; i < 2; i++)
        {
            float x = (float)ir[i, 0] / 1023f;
            float y = (float)ir[i, 1] / 767f;
            if (x == -1 || y == -1) {
                ir_dots[i].anchorMin = new Vector2(0, 0);
                ir_dots[i].anchorMax = new Vector2(0, 0);
            }

            ir_dots[i].anchorMin = new Vector2(x, y);
            ir_dots[i].anchorMax = new Vector2(x, y);

            if (ir[i, 2] != -1)
            {
                int index = (int)ir[i,2];
                float xmin = (float)wiimote.Ir.ir[index,3] / 127f;
                float ymin = (float)wiimote.Ir.ir[index,4] / 127f;
                float xmax = (float)wiimote.Ir.ir[index,5] / 127f;
                float ymax = (float)wiimote.Ir.ir[index,6] / 127f;
                ir_bb[i].anchorMin = new Vector2(xmin, ymin);
                ir_bb[i].anchorMax = new Vector2(xmax, ymax);
            }
        }

        float[] pointer = wiimote.Ir.GetPointingPosition();
        ir_pointer.anchorMin = new Vector2(pointer[0], pointer[1]);
        ir_pointer.anchorMax = new Vector2(pointer[0], pointer[1]);
    }
예제 #43
0
        private void Buzz(Wiimote BuzzedWiimote)
        {
            Buzzer Buzzed = GetBuzzer(BuzzedWiimote);

            if(Buzzed == null)
            {
                return;
            }

            if(BuzzedList.Contains(Buzzed))
            {
                return;
            }

            if(BuzzedList.Count == 0)
            {
                System.Media.SystemSounds.Beep.Play();

                // First one
                RumbleWiimote(BuzzedWiimote);

                // Start Reset Timer
                if(TimedBuzzerReset)
                {
                    BuzzerResetTask = Task.Factory.StartNew(new Action(() => { BuzzedResetTimer(); }));
                }
            }

            BuzzedList.Add(Buzzed);
            Buzzed.BuzzedNumber = BuzzedList.Count;
        }
예제 #44
0
        private void RemoveWiimote(Wiimote DisconnectedWiimote)
        {
            Buzzer BuzzerToRemove = GetBuzzer(DisconnectedWiimote);

            if(BuzzerToRemove == null)
            {
                return;
            }

            Buzzer.Remove(BuzzerToRemove);
            BuzzerPanel.Items.Refresh();

            AvailableIndices.Add(BuzzerToRemove.Index);
            AvailableIndices.Sort();
        }
        public override void checkWiimoteState(Wiimote wiimote1, Wiimote wiimote2)
        {
            try
            {
                wiimote1.WiimoteCurrentState = WiimoteState.wiimoteGoodStateState;
                wiimote2.WiimoteCurrentState = WiimoteState.wiimoteGoodStateState;
                //Thread.Sleep(Configuration.getConfiguration().WaitTimeCheckConnection);

                //string checkWiimoteStateMessage = CHECK_WIIMOTE_STATE_METHOD_NAME + ";";
                //string returnString = m_CommandPipe.sendMessage(checkWiimoteStateMessage);
                //if (returnString.Length < 4)
                //    return;

                //string[] returnValues = returnString.Split(',');

                //mSpaceSensorMain.CheckState();

                //wiimote1.WiimoteCurrentState = (WiimoteState)Convert.ToInt32(returnValues[0]);
                //wiimote1.BatteryLevel = Convert.ToInt32(returnValues[1]);
                //wiimote2.WiimoteCurrentState = (WiimoteState)Convert.ToInt32(returnValues[2]);
                //wiimote2.BatteryLevel = Convert.ToInt32(returnValues[3]);

            }
            catch (Exception ex)
            {
                throw new WiimoteCommunicationException(ex);
            }
        }
예제 #46
0
 public ButtonData(Wiimote Owner) : base(Owner) { }
예제 #47
0
        private Buzzer GetBuzzer(Wiimote Wiimote)
        {
            foreach (Buzzer Tmp in Buzzer)
            {
                if (Tmp.Wiimote == Wiimote)
                {
                    return Tmp;
                }
            }

            return null;
        }
예제 #48
0
 private void RumbleWiimote(Wiimote Wiimote)
 {
     Task.Factory.StartNew(() => { Wiimote.RumbleBriefly(); });
 }
예제 #49
0
 private void OnNewWiimoteFound(object sender, Wiimote e)
 {
     Application.Current.Dispatcher.Invoke(new Action(() => { AddNewWiimote(e); }));       
 }
예제 #50
0
    void OnGUI()
    {
        GUI.Box(new Rect(0,0,320,Screen.height), "");

        GUILayout.BeginVertical(GUILayout.Width(300));
        GUILayout.Label("Wiimote Found: " + WiimoteManager.HasWiimote());
        if (GUILayout.Button("Find Wiimote"))
            WiimoteManager.FindWiimotes();

        if (GUILayout.Button("Cleanup"))
        {
            WiimoteManager.Cleanup(wiimote);
            wiimote = null;
        }

        if (wiimote == null)
            return;

        GUILayout.Label("Extension: " + wiimote.current_ext.ToString());

        GUILayout.Label("LED Test:");
        GUILayout.BeginHorizontal();
        for (int x = 0; x < 4;x++ )
            if (GUILayout.Button(""+x, GUILayout.Width(300/4)))
                wiimote.SendPlayerLED(x == 0, x == 1, x == 2, x == 3);
        GUILayout.EndHorizontal();

        GUILayout.Label("Set Report:");
        GUILayout.BeginHorizontal();
        if(GUILayout.Button("But/Acc", GUILayout.Width(300/4)))
            wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL);
        if(GUILayout.Button("But/Ext8", GUILayout.Width(300/4)))
            wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_EXT8);
        if(GUILayout.Button("B/A/Ext16", GUILayout.Width(300/4)))
            wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16);
        if(GUILayout.Button("Ext21", GUILayout.Width(300/4)))
            wiimote.SendDataReportMode(InputDataType.REPORT_EXT21);
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Request Status Report"))
            wiimote.SendStatusInfoRequest();

        GUILayout.Label("IR Setup Sequence:");
        GUILayout.BeginHorizontal();
        if(GUILayout.Button("Basic", GUILayout.Width(100)))
            wiimote.SetupIRCamera(IRDataType.BASIC);
        if(GUILayout.Button("Extended", GUILayout.Width(100)))
            wiimote.SetupIRCamera(IRDataType.EXTENDED);
        if(GUILayout.Button("Full", GUILayout.Width(100)))
            wiimote.SetupIRCamera(IRDataType.FULL);
        GUILayout.EndHorizontal();

        GUILayout.Label("WMP Attached: " + wiimote.wmp_attached);
        if (GUILayout.Button("Request Identify WMP"))
            wiimote.RequestIdentifyWiiMotionPlus();
        if ((wiimote.wmp_attached || wiimote.Type == WiimoteType.PROCONTROLLER) && GUILayout.Button("Activate WMP"))
            wiimote.ActivateWiiMotionPlus();
        if ((wiimote.current_ext == ExtensionController.MOTIONPLUS ||
            wiimote.current_ext == ExtensionController.MOTIONPLUS_CLASSIC ||
            wiimote.current_ext == ExtensionController.MOTIONPLUS_NUNCHUCK) && GUILayout.Button("Deactivate WMP"))
            wiimote.DeactivateWiiMotionPlus();

        GUILayout.Label("Calibrate Accelerometer");
        GUILayout.BeginHorizontal();
        for (int x = 0; x < 3; x++)
        {
            AccelCalibrationStep step = (AccelCalibrationStep)x;
            if (GUILayout.Button(step.ToString(), GUILayout.Width(100)))
                wiimote.Accel.CalibrateAccel(step);
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Print Calibration Data"))
        {
            StringBuilder str = new StringBuilder();
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    str.Append(wiimote.Accel.accel_calib[y, x]).Append(" ");
                }
                str.Append("\n");
            }
            Debug.Log(str.ToString());
        }

        if (wiimote != null && wiimote.current_ext != ExtensionController.NONE)
        {
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            GUIStyle bold = new GUIStyle(GUI.skin.button);
            bold.fontStyle = FontStyle.Bold;
            if (wiimote.current_ext == ExtensionController.NUNCHUCK) {
                GUILayout.Label("Nunchuck:", bold);
                NunchuckData data = wiimote.Nunchuck;
                GUILayout.Label("Stick: " + data.stick[0] + ", " + data.stick[1]);
                GUILayout.Label("C: " + data.c);
                GUILayout.Label("Z: " + data.z);
            } else if (wiimote.current_ext == ExtensionController.CLASSIC) {
                GUILayout.Label("Classic Controller:", bold);
                ClassicControllerData data = wiimote.ClassicController;
                GUILayout.Label("Stick Left: " + data.lstick[0] + ", " + data.lstick[1]);
                GUILayout.Label("Stick Right: " + data.rstick[0] + ", " + data.rstick[1]);
                GUILayout.Label("Trigger Left: " + data.ltrigger_range);
                GUILayout.Label("Trigger Right: " + data.rtrigger_range);
                GUILayout.Label("Trigger Left Button: " + data.ltrigger_switch);
                GUILayout.Label("Trigger Right Button: " + data.rtrigger_switch);
                GUILayout.Label("A: " + data.a);
                GUILayout.Label("B: " + data.b);
                GUILayout.Label("X: " + data.x);
                GUILayout.Label("Y: " + data.y);
                GUILayout.Label("Plus: " + data.plus);
                GUILayout.Label("Minus: " + data.minus);
                GUILayout.Label("Home: " + data.home);
                GUILayout.Label("ZL: " + data.zl);
                GUILayout.Label("ZR: " + data.zr);
                GUILayout.Label("D-Up: " + data.dpad_up);
                GUILayout.Label("D-Down: " + data.dpad_down);
                GUILayout.Label("D-Left: " + data.dpad_left);
                GUILayout.Label("D-Right: " + data.dpad_right);
            }
            else if (wiimote.current_ext == ExtensionController.MOTIONPLUS)
            {
                GUILayout.Label("Wii Motion Plus:", bold);
                MotionPlusData data = wiimote.MotionPlus;
                GUILayout.Label("Pitch Speed: " + data.PitchSpeed);
                GUILayout.Label("Yaw Speed: " + data.YawSpeed);
                GUILayout.Label("Roll Speed: " + data.RollSpeed);
                GUILayout.Label("Pitch Slow: " + data.PitchSlow);
                GUILayout.Label("Yaw Slow: " + data.YawSlow);
                GUILayout.Label("Roll Slow: " + data.RollSlow);
                if (GUILayout.Button("Zero Out WMP"))
                {
                    data.SetZeroValues();
                    model.rot.rotation = Quaternion.FromToRotation(model.rot.rotation*GetAccelVector(), Vector3.up) * model.rot.rotation;
                    model.rot.rotation = Quaternion.FromToRotation(model.rot.forward, Vector3.forward) * model.rot.rotation;
                }
                if(GUILayout.Button("Reset Offset"))
                    wmpOffset = Vector3.zero;
                GUILayout.Label("Offset: " + wmpOffset.ToString());
            }
            else if (wiimote.current_ext == ExtensionController.WIIU_PRO)
            {
                GUILayout.Label("Wii U Pro Controller:", bold);
                WiiUProData data = wiimote.WiiUPro;
                GUILayout.Label("Stick Left: "+data.lstick[0]+", "+data.lstick[1]);
                GUILayout.Label("Stick Right: "+data.rstick[0]+", "+data.rstick[1]);
                GUILayout.Label("A: "+data.a);
                GUILayout.Label("B: "+data.b);
                GUILayout.Label("X: "+data.x);
                GUILayout.Label("Y: "+data.y);

                GUILayout.Label("D-Up: "   +data.dpad_up);
                GUILayout.Label("D-Down: " +data.dpad_down);
                GUILayout.Label("D-Left: " +data.dpad_left);
                GUILayout.Label("D-Right: "+data.dpad_right);

                GUILayout.Label("Plus: "+data.plus);
                GUILayout.Label("Minus: "+data.minus);
                GUILayout.Label("Home: "+data.home);

                GUILayout.Label("L: "+data.l);
                GUILayout.Label("R: "+data.r);
                GUILayout.Label("ZL: "+data.zl);
                GUILayout.Label("ZR: "+data.zr);
            }
            else if (wiimote.current_ext == ExtensionController.GUITAR) {
                GUILayout.Label ("Guitar", bold);
                GuitarData data = wiimote.Guitar;
                float[] stick = data.GetStick01 ();
                GUILayout.Label ("Stick: " + stick [0] + ", " + stick [1]);
                GUILayout.Label ("Slider: " + (data.has_slider ? Convert.ToString (data.GetSlider01 ()) : "unsupported"));
                GUILayout.Label ("Green: " + data.green);
                GUILayout.Label ("Red: " + data.red);
                GUILayout.Label ("Yellow: " + data.yellow);
                GUILayout.Label ("Blue: " + data.blue);
                GUILayout.Label ("Orange: " + data.orange);
                GUILayout.Label ("Strum Up: " + data.strum_up);
                GUILayout.Label ("Strum Down: " + data.strum_down);
                GUILayout.Label ("Minus: " + data.minus);
                GUILayout.Label ("Plus: " + data.plus);
                GUILayout.Label ("Whammy: " + data.GetWhammy01());
            }
            GUILayout.EndScrollView();
        } else {
            scrollPosition = Vector2.zero;
        }
        GUILayout.EndVertical();
    }
예제 #51
0
 public MotionPlusData(Wiimote Owner) : base(Owner) { }