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);
	}
示例#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 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);
	}
示例#4
0
 /// <summary>
 /// Initiate the Wiimotes
 /// </summary>
 void InitWiimotes()
 {
     WiimoteManager.FindWiimotes();
     foreach (WiimoteApi.Wiimote remote in WiimoteManager.Wiimotes)
     {
         wiimote = remote;
         wiimote.SendPlayerLED(false, false, false, false);
     }
     //If there's no Wiimote detected
     if (wiimote == null)
     {
         isWiimote = false;
         return;
     }
     wiimote.SendDataReportMode(InputDataType.REPORT_BUTTONS_ACCEL_EXT16);
     isWiimote = true;
 }
示例#5
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();
            }

        }
    }
示例#6
0
        private static bool _FindWiimotes(WiimoteType type)
        {
            //if (hidapi_wiimote != IntPtr.Zero)
            //    HIDapi.hid_close(hidapi_wiimote);

            ushort vendor = 0;
            ushort product = 0;

            if (type == WiimoteType.WIIMOTE)
            {
                vendor = vendor_id_wiimote;
                product = product_id_wiimote;
            }
            else if (type == WiimoteType.WIIMOTEPLUS || type == WiimoteType.PROCONTROLLER)
            {
                vendor = vendor_id_wiimote;
                product = product_id_wiimoteplus;
            }

            IntPtr ptr = HIDapi.hid_enumerate(vendor, product);
            IntPtr cur_ptr = ptr;

            if (ptr == IntPtr.Zero)
                return false;

            hid_device_info enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));

            bool found = false;

            while (cur_ptr != IntPtr.Zero)
            {
                Wiimote remote = null;
                bool fin = false;
                foreach (Wiimote r in Wiimotes)
                {
                    if (fin)
                        continue;

                    if (r.hidapi_path.Equals(enumerate.path))
                    {
                        remote = r;
                        fin = true;
                    }
                }
                if (remote == null)
                {
                    IntPtr handle = HIDapi.hid_open_path(enumerate.path);

                    WiimoteType trueType = type;

                    // Wii U Pro Controllers have the same identifiers as the newer Wii Remote Plus except for product
                    // string (WHY nintendo...)
                    if (enumerate.product_string.EndsWith("UC"))
                        trueType = WiimoteType.PROCONTROLLER;

                    remote = new Wiimote(handle, enumerate.path, trueType);

                    if (Debug_Messages)
                        Debug.Log("Found New Remote: " + remote.hidapi_path);

                    Wiimotes.Add(remote);

                    remote.SendDataReportMode(InputDataType.REPORT_BUTTONS);
                    remote.SendStatusInfoRequest();
                }

                cur_ptr = enumerate.next;
                if (cur_ptr != IntPtr.Zero)
                    enumerate = (hid_device_info)Marshal.PtrToStructure(cur_ptr, typeof(hid_device_info));
            }

            HIDapi.hid_free_enumeration(ptr);

            return found;
        }
    private static bool _FindWiimotes(WiimoteType type)
    {
        //if (hidapi_wiimote != IntPtr.Zero)
        //    HIDapi.hid_close(hidapi_wiimote);

        ushort vendor = 0;
        ushort product = 0;

        if(type == WiimoteType.WIIMOTE) {
            vendor = vendor_id_wiimote;
            product = product_id_wiimote;
        } else if(type == WiimoteType.WIIMOTEPLUS || type == WiimoteType.PROCONTROLLER) {
            vendor = vendor_id_wiimote;
            product = product_id_wiimoteplus;
        }

        IntPtr ptr = HIDapi.hid_enumerate(vendor, product);
        IntPtr cur_ptr = ptr;

        if (ptr == IntPtr.Zero)
            return false;

        hid_device_info enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));

        bool found = false;

        while(cur_ptr != IntPtr.Zero)
        {
            Wiimote remote = null;
            bool fin = false;
            foreach (Wiimote r in Wiimotes)
            {
                if (fin)
                    continue;

                if (r.hidapi_path.Equals(enumerate.path))
                {
                    remote = r;
                    fin = true;
                }
            }
            if (remote == null)
            {
                IntPtr handle = HIDapi.hid_open_path(enumerate.path);

                WiimoteType trueType = type;

                // Wii U Pro Controllers have the same identifiers as the newer Wii Remote Plus except for product
                // string (WHY nintendo...)
                if(enumerate.product_string.EndsWith("UC"))
                    trueType = WiimoteType.PROCONTROLLER;

                remote = new Wiimote(handle, enumerate.path, trueType);

                if (Debug_Messages)
                    Debug.Log("Found New Remote: " + remote.hidapi_path);

                Wiimotes.Add(remote);

                remote.SendDataReportMode(InputDataType.REPORT_BUTTONS);
                remote.SendStatusInfoRequest();
            }

            cur_ptr = enumerate.next;
            if(cur_ptr != IntPtr.Zero)
                enumerate = (hid_device_info)Marshal.PtrToStructure(cur_ptr, typeof(hid_device_info));
        }

        HIDapi.hid_free_enumeration(ptr);

        return found;
    }
    public override void Start() {
      base.Start();
      #if UP_USE_WII_INPUT_MANAGER
      WiimoteManager.FindWiimotes(); // Poll native bluetooth drivers to find Wiimotes

      foreach(Wiimote r in WiimoteManager.Wiimotes) {
        remote = r;
        remote.SendPlayerLED(true, false, false, true);
        remote.SendDataReportMode(InputDataType.REPORT_BUTTONS);
      }
      #endif
    }