コード例 #1
0
ファイル: ThalmicHub.cs プロジェクト: kaivan29/MyoHero
    void Awake()
    {
        // Ensure that there is only one ThalmicHub.
        if (_instance != null) {
            Destroy (this.gameObject);
            return;
        } else {
            _instance = this;
        }

        // Do not destroy this game object. This will ensure that it remains active even when
        // switching scenes.
        DontDestroyOnLoad(this);

        for (int i = 0; i < transform.childCount; ++i) {
            Transform child = transform.GetChild (i);

            var myo = child.gameObject.GetComponent<ThalmicMyo> ();
            if (myo != null) {
                _myos.Add(myo);
            }
        }

        if (_myos.Count < 1) {
            string errorMessage = "The ThalmicHub's GameObject must have at least one child with a ThalmicMyo component.";
        }

        createHub ();
    }
コード例 #2
0
ファイル: ridder.cs プロジェクト: Zehuayu/Myo_Unity_Project
 private void OnTriggerEnter2D(Collider2D collsion)    //OnCollisionEnter2D(Collision2D collision)
 {
     if (collsion.gameObject.tag == "background")
     {
         //game over
         ThalmicHub hub = ThalmicHub.instance;
         Destroy(hub);
         Application.LoadLevel(Application.loadedLevel);
         //wSceneManager.LoadScene(0);
     }
 }
コード例 #3
0
    // Extend the unlock if ThalmcHub's locking policy is standard, and notifies the given myo that a user action was
    // recognized.
    void ExtendUnlockAndNotifyUserAction(ThalmicMyo myo)
    {
        ThalmicHub hub = ThalmicHub.instance;

        if (hub.lockingPolicy == LockingPolicy.Standard)
        {
            myo.Unlock(UnlockType.Timed);
        }

        myo.NotifyUserAction();
    }
コード例 #4
0
    void Update()
    {
        ThalmicHub hub = ThalmicHub.instance;

        computing.Compute();

        if (Input.GetKeyDown("q"))
        {
            hub.ResetHub();
        }

        if (Input.GetKeyDown("f"))
        {
            fast = !fast;
        }

        if (GuiDisplay.startButton || Input.GetKeyDown("space"))
        {
            startSession.Session();
        }

        if (GuiDisplay.stopButton || Input.GetKeyDown("s"))
        {
            stopSession.Session();
        }

        if (GuiDisplay.testButton || Input.GetKeyDown("t"))
        {
            StartCoroutine(testSession.Session());
        }

        if (Input.GetKeyDown("p"))
        {
            pauseSession.Pause();
        }

        if (Input.GetKeyDown("m"))
        {
            pauseSession.UnPause();
        }

        /* Update timer */
        if (startTimer)
        {
            time += Time.deltaTime;
        }

        /* Update time left to play a chord */
        if (testingState)
        {
            timingLeft -= Time.deltaTime;
        }
    }
コード例 #5
0
ファイル: GameControl.cs プロジェクト: CSUMBmWall/VRBilliards
 // Myo game object to connect with.
 // This object must have a ThalmicMyo script attached.
 void Update()
 {
     SoundManager.getInstance().updateSoundManager();
     if (Input.GetKey("escape"))
         Application.Quit();
     thalmicMyo = myo.GetComponent<ThalmicMyo> ();
     hub = ThalmicHub.instance;
     if (Input.GetKeyDown("q"))
     {
         hub.ResetHub();
     }
     //if (
 }
コード例 #6
0
    public void OnLock(string message)
    {
        ThalmicMyo targetMyo = GetMyo("test");

        if (targetMyo != null)
        {
            if (ThalmicHub.DidUnlockDevice != null)
            {
                ThalmicHub.DidUnlockDevice(targetMyo);
            }
            targetMyo._myoUnlocked = false;
        }
    }
コード例 #7
0
    void Start()
    {
        hub            = ThalmicHub.instance;
        thalmicMyo     = myo.GetComponent <ThalmicMyo> ();
        isPaused       = false;
        onTime         = true;
        didRitual      = false;
        isDying        = false;
        Time.timeScale = 1f;
        uiGameOver.SetActive(false);

        lastPose = Pose.Unknown;
    }
コード例 #8
0
    void Update()
    {
        ThalmicHub hub = ThalmicHub.instance;

        if (string.IsNullOrEmpty(_key))
        {
            _key = Input.inputString;
        }
        // if the new input is not empty then it must be a new key
        if (!string.IsNullOrEmpty(Input.inputString))
        {
            _key = Input.inputString;
        }
    }
コード例 #9
0
    public void OnArmUnsync(string message)
    {
        ThalmicMyo targetMyo = GetMyo("test");

        if (targetMyo != null)
        {
            if (ThalmicHub.DidUnsyncArm != null)
            {
                ThalmicHub.DidUnsyncArm(targetMyo);
            }

            targetMyo._myoArmSynced = false;
        }
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        hub = ThalmicHub.instance;

        if(thalmicMyo != null && thalmicMyo.pose.ToString() == "Fist"){
            if(player == null){
                player = GameObject.FindGameObjectWithTag("Player");
            }
                player.animation.Play("punch_hi_left");
        }

        if (Input.GetKeyDown ("q")) {
            hub.ResetHub();
        }
    }
コード例 #11
0
    // Extend the unlock if ThalmcHub's locking policy is standard, and notifies the given myo that a user action was
    // recognized.
    void ExtendUnlockAndNotifyUserAction(ThalmicMyo myo)
    {
        ThalmicHub hub = ThalmicHub.instance;

        if (hub.lockingPolicy == LockingPolicy.Standard)
        {
            myo.Unlock(UnlockType.Timed);
        }

        if (!OnPlayer)
        {
            Debug.Log("colourboxevent");
            myo.NotifyUserAction();
        }
    }
コード例 #12
0
    public void OnArmSync(string message)
    {
        ThalmicMyo targetMyo = GetMyo("test");

        if (targetMyo != null)
        {
            if (ThalmicHub.DidSyncArm != null)
            {
                ThalmicHub.DidSyncArm(targetMyo);
            }

            targetMyo._myoXDirection = Thalmic.Myo.XDirection.TowardWrist;
            targetMyo._myoArmSynced  = true;
        }
    }
コード例 #13
0
        /*  Function: Update
         *
         * Get Inputs to control falling star
         *
         * Inputs:
         *
         * Keyboard.
         * Left - Q
         * Right - D
         *
         * MyoArm Band.
         * Left - WaveIn
         * Right - WaveOut
         */
        void FixedUpdate()
        {
        #if UNITY_STANDALONE || UNITY_EDITOR || UNITY_ANDROID || WIN64 || WIN32
            ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();
        #endif

            // Keyboard Input
            if (Input.GetKey(KeyCode.Q) && rb2D.velocity.x >= -MaxSpeed)
            {
                rb2D.AddForce(Vector2.left * MoveSpeed);
            }
            if (Input.GetKey(KeyCode.D) && rb2D.velocity.x <= MaxSpeed)
            {
                rb2D.AddForce(Vector2.right * MoveSpeed);
            }


        #if UNITY_STANDALONE || UNITY_EDITOR || UNITY_ANDROID || WIN64 || WIN32
            //Myo armband Input
            if (thalmicMyo.pose == Pose.WaveIn)
            {
                Debug.Log("Biceps");
                rb2D.AddForce(Vector2.left * MoveSpeed);
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                Debug.Log("Triceps");
                rb2D.AddForce(Vector2.right * MoveSpeed);
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }


            // Extend the unlock if ThalmcHub's locking policy is standard, and notifies the given myo that a user action was
            // recognized.
            void ExtendUnlockAndNotifyUserAction(ThalmicMyo myo)
            {
                ThalmicHub hub = ThalmicHub.instance;

                if (hub.lockingPolicy == LockingPolicy.Standard)
                {
                    myo.Unlock(UnlockType.Timed);
                }

                myo.NotifyUserAction();
            }
        #endif
        }
コード例 #14
0
    //private InputMapping;
    // Use this for initialization
    void Start()
    {
        hub = ThalmicHub.instance;
        //myo = GameObject.FindGameObjectWithTag("Player");
        if (myo == null) {
            myo = this.gameObject;
        }

        // Access the ThalmicMyo script attached to the Myo object.
        thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        if (thalmicMyo.isPaired) {
            thalmicMyo.Vibrate(Thalmic.Myo.VibrationType.Short);
        }
        Debug.Log (thalmicMyo);
        Debug.Log (myo);
    }
コード例 #15
0
ファイル: Startup.cs プロジェクト: nhrade/BrickHack-Myo-Thing
    // Use this for initialization
    void Start()
    {
        ThalmicHub hub         = ThalmicHub.instance;
        ThalmicMyo myoInstance = myo.GetComponent <ThalmicMyo>();

        if (!hub.hubInitialized)
        {
            Debug.Log("Cannot connect Myo Connect.");
        }
        else if (!myoInstance.isPaired)
        {
            Debug.Log("Myo is not paired.");
        }
        else if (!myoInstance.armSynced)
        {
            Debug.Log("Myo not synced.");
        }
    }
コード例 #16
0
    // Update is called once per frame
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();



        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;


            if (thalmicMyo.pose == Pose.WaveIn)
            {
                motor.motorSpeed = motor.motorSpeed + 500;
                right.motor      = motor;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                motor.motorSpeed = motor.motorSpeed - 500;
                left.motor       = motor;
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.Fist)
            {
                rg.AddTorque(-rotation * 10 * Time.deltaTime);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                rg.AddTorque(rotation * 10 * Time.deltaTime);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                ThalmicHub hub = ThalmicHub.instance;
                Destroy(hub);
                Application.LoadLevel(Application.loadedLevel);
            }
        }
    }
コード例 #17
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        }
        else if (health > 0)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Point hand to center of screen and open fingers\n" +
                      "Block incoming blocks to the music" +
                      "\nCombo: " + combo +
                      "\nHealth: " + health
                      );
            if (health <= 0)
            {
                Debug.Log("YOU DIED");
                new WaitForSeconds(2);
                Application.LoadLevel("End Screen");
            }
        }
    }
コード例 #18
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize  = 15;
        GUI.skin.label.fontStyle = FontStyle.Bold;
        GUI.color = Color.black;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        }
        else
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Fingers spread: From grip to idle\n" +
                      "Fist + Push: Cylindrical\n" +
                      "Wave in  + Push: Rotate wrist left\n" +
                      "Wave out + Push: Rotate wrist right\n" +
                      "Fist + Lift: Point\n" +
                      "WaveIn + Lift: 1-finger pinch\n" +
                      "WaveOut + Lift: 2-finger pinch\n"
                      );
        }
    }
コード例 #19
0
    void didUnlockDevice(string eventData)
    {
        if (eventData == null || eventData.Length == 0)
        {
            return;
        }

        var dict = Json.Deserialize(eventData) as Dictionary <string, object>;

        string     myoIdentifier = (string)dict["myoIdentifier"];
        ThalmicMyo targetMyo     = GetMyo(myoIdentifier);

        if (targetMyo != null)
        {
            if (ThalmicHub.DidUnlockDevice != null)
            {
                ThalmicHub.DidUnlockDevice(targetMyo);
            }
            targetMyo._myoUnlocked = true;
        }
    }
コード例 #20
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        ThalmicHub hub = ThalmicHub.instance;
        //Debug.Log (hub._myos.Count);

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        }
        else
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Fist: Vibrate Myo armband\n" +
                      "Wave in: Set box material to blue\n" +
                      "Wave out: Set box material to green\n" +
                      "Thumb to pinky: Reset box material\n" +
                      "Fingers spread: Set forward direction"
                      );
        }
    }
コード例 #21
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Bluetooth Dongle unavailable. Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.isTrained)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Myo has not been trained. Please wear Myo with the USB port facing your elbow and run the trainer."
                      );
        }
        else
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Wear Myo with the USB port facing your elbow\n\n" +
                      "Fist: Vibrate Myo armband\n" +
                      "Wave in: Set box material to blue\n" +
                      "Wave out: Set box material to green\n" +
                      "Twist in: Reset box material\n" +
                      "Fingers spread: Set forward direction"
                      );
        }
    }
コード例 #22
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        }
        else
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Fist: Zoom out\n" +
                      "Wave in: Rotate left\n" +
                      "Wave out: Rotate Right\n" +
                      "Double tap: Change direction of rotation\n" +
                      "Fingers spread: Zoom in/n"
                      );
        }
    }
コード例 #23
0
    void didUnsyncArmEvent(string eventData)
    {
        if (eventData == null || eventData.Length == 0)
        {
            return;
        }

        var        dict          = Json.Deserialize(eventData) as Dictionary <string, object>;
        string     myoIdentifier = (string)dict["myoIdentifier"];
        ThalmicMyo targetMyo     = GetMyo(myoIdentifier);
        int        armXDirection = (int)((long)(dict["armXDirection"]));

        if (targetMyo != null)
        {
            if (ThalmicHub.DidUnsyncArm != null)
            {
                ThalmicHub.DidUnsyncArm(targetMyo);
            }

            targetMyo._myoArmSynced = false;
        }
    }
コード例 #24
0
    void didReceivePoseChange(string param)
    {
        Pose receivedPose = Pose.Unknown;

        for (int i = (int)Pose.Rest; i <= (int)Pose.Unknown; i++)
        {
            Pose currPose = (Pose)i;
            if (currPose.ToString().Equals(param))
            {
                receivedPose = currPose;
                break;
            }
        }
        //Update all myos for now because we don't have the myo id
        foreach (ThalmicMyo myo in ThalmicHub.instance._myos)
        {
            if (ThalmicHub.DidReceivePoseChange != null)
            {
                ThalmicHub.DidReceivePoseChange(null, receivedPose);
            }
            myo._myoPose = receivedPose;
        }
    }
コード例 #25
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.armRecognized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        }
        else
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Fist: Shoot Space Craft Gun\n" +
                      "Thumb to pinky: Reset Game\n" +
                      "Fingers spread: Set forward direction"
                      );
        }
    }
コード例 #26
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        }
        else if (!thalmicMyo.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        }
        else if (!thalmicMyo.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        }
        else
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Fist: Ativate Hand\n" +
                      "Spread Deactivae\n" +
                      "Doble tap finger to calibrate"
                      );
        }
    }
コード例 #27
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        if (!hub.hubInitialized) {
            GUI.Label(new Rect (12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        } else if (!thalmicMyo.isPaired) {
            GUI.Label(new Rect (12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        } else if (!thalmicMyo.armSynced) {
            GUI.Label(new Rect (12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        } else {
            myoIsPaired = true;
            /*
            GUI.Label (new Rect (12, 8, Screen.width, Screen.height),

                       "Fist: Vibrate Myo armband\n" +
                       "Wave in: Set box material to blue\n" +
                       "Wave out: Set box material to green\n" +
                       "Double tap: Reset box material\n" +
                       "Fingers spread: Set forward direction"
                       );
            */
        }
    }
コード例 #28
0
    void Awake()
    {
        // Ensure that there is only one ThalmicHub.
        if (_instance != null) {
        //#if UNITY_EDITOR
        //            EditorUtility.DisplayDialog("Can only have one ThalmicHub",
        //                                        "Your scene contains more than one ThalmicHub. Remove all but one ThalmicHub.",
        //                                        "OK");
        //#endif
            //Destroy (this.gameObject);
            return;
        } else {
            _instance = this;
        }

        // Do not destroy this game object. This will ensure that it remains active even when
        // switching scenes.
        DontDestroyOnLoad(this);

        for (int i = 0; i < transform.childCount; ++i) {
            Transform child = transform.GetChild (i);

            var myo = child.gameObject.GetComponent<ThalmicMyo> ();
            if (myo != null) {
                _myos.Add(myo);
            }
        }

        if (_myos.Count < 1) {
            string errorMessage = "The ThalmicHub's GameObject must have at least one child with a ThalmicMyo component.";
        #if UNITY_EDITOR
            EditorUtility.DisplayDialog ("Thalmic Hub has no Myo children", errorMessage, "OK");
        #else
            throw new UnityException (errorMessage);
        #endif
        }

        #if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var unityActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
        var applicationContext = unityActivity.Call<AndroidJavaObject>("getApplicationContext");

        // Need to pass the Android Application Context to the Myo Android plugin before initializing the Hub.
        AndroidJavaClass nativeEventsClass = new AndroidJavaClass("com.thalmic.myo.NativeEvents");
        nativeEventsClass.CallStatic("setApplicationContext", applicationContext);

        // The Hub needs to be initialized on the Android UI thread.
        unityActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
            createHub ();
        }));
        #else
        createHub ();
        #endif
    }
コード例 #29
0
    public void OnPose(string message)
    {
        Pose receivedPose = Pose.Unknown;

        Debug.Log("Unknown Pose: " + receivedPose);

        switch (message)
        {
        case "REST":
            receivedPose = Pose.Rest;
            break;

        case "FIST":
            receivedPose = Pose.Fist;
            break;

        case "WAVE_IN":
            receivedPose = Pose.WaveIn;
            break;

        case "WAVE_OUT":
            receivedPose = Pose.WaveOut;
            break;

        case "FINGERS_SPREAD":
            receivedPose = Pose.FingersSpread;
            break;

        case "DOUBLE_TAP":
            receivedPose = Pose.DoubleTap;
            break;

        case "UNKNOWN":
            receivedPose = Pose.Unknown;
            break;

        default:
            break;
        }

        //receivedPose = (Pose)System.Enum.Parse(typeof(Pose), message, true);
        Debug.Log("Gefiltert Pose: " + receivedPose);

        /*for (int i = (int)Pose.Rest; i <= (int)Pose.Unknown; i++)
         * {
         *  Pose currPose = (Pose)i;
         *  if (currPose.ToString().Equals(message))
         *  {
         *      receivedPose = currPose;
         *      Debug.Log("Gefiltert Pose: " + receivedPose);
         *      break;
         *  }
         * }*/
        //Update all myos for now because we don't have the myo id
        if (ThalmicHub.DidReceivePoseChange != null)
        {
            ThalmicHub.DidReceivePoseChange(null, receivedPose);
            Debug.Log("DidReceive Pose: ");
        }
        ThalmicMyo targetMyo = GetMyo("test");

        targetMyo._myoPose = receivedPose;

        /*foreach (ThalmicMyo myo in ThalmicHub.instance._myos)
         * {
         *  if (ThalmicHub.DidReceivePoseChange != null)
         *  {
         *      ThalmicHub.DidReceivePoseChange(null, receivedPose);
         *      Debug.Log("DidReceive Pose: ");
         *  }
         *  myo._myoPose = receivedPose;
         *  Debug.Log("In der Myo Pose: " + myo._myoPose);
         * }*/
    }
コード例 #30
0
ファイル: ThalmicHub.cs プロジェクト: st3veV/myo-unity
    void Awake()
    {
        // Ensure that there is only one ThalmicHub.
        if (_instance != null) {
        #if UNITY_EDITOR
            EditorUtility.DisplayDialog("Can only have one ThalmicHub",
                                        "Your scene contains more than one ThalmicHub. Remove all but one ThalmicHub.",
                                        "OK");
        #endif
            Destroy (this.gameObject);
            return;
        } else {
            _instance = this;
        }

        // Do not destroy this game object. This will ensure that it remains active even when
        // switching scenes.
        DontDestroyOnLoad(this);

        for (int i = 0; i < transform.childCount; ++i) {
            Transform child = transform.GetChild (i);

            var myo = child.gameObject.GetComponent<ThalmicMyo> ();
            if (myo != null) {
                _myos.Add(myo);
            }
        }

        if (_myos.Count < 1) {
            string errorMessage = "The ThalmicHub's GameObject must have at least one child with a ThalmicMyo component.";
        #if UNITY_EDITOR
            EditorUtility.DisplayDialog ("Thalmic Hub has no Myo children", errorMessage, "OK");
        #else
            throw new UnityException (errorMessage);
        #endif
        }

        #if !UNITY_ANDROID || UNITY_EDITOR
        createHub();
        #endif
    }
コード例 #31
0
    void OnGUI()
    {
        GUI.skin.label.fontSize  = 20;
        GUI.skin.label.fontStyle = FontStyle.Bold;
        GUI.color = Color.red;

        ThalmicHub hub        = ThalmicHub.instance;
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (_key == "t")
        {
            if (thalmicMyo.pose == Pose.Fist)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: Push\n" +
                          "EMG input: Fist"
                          );
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: Push\n" +
                          "EMG input: Wave In"
                          );
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: Push\n" +
                          "EMG input: Wave Out"
                          );
            }
        }
        else if (_key == "y")
        {
            if (thalmicMyo.pose == Pose.Fist)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: Lift\n" +
                          "EMG input: Fist"
                          );
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: Lift\n" +
                          "EMG input: Wave In"
                          );
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: Lift\n" +
                          "EMG input: Wave Out"
                          );
            }
        }
        else if (_key == "u")
        {
            if (thalmicMyo.pose == Pose.Fist)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: U (rotate)\n" +
                          "EMG input: Fist"
                          );
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: U (rotate)\n" +
                          "EMG input: Wave In"
                          );
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                GUI.Label(new Rect(625, 0, Screen.width, Screen.height),
                          "EEG input: U (rotate)\n" +
                          "EMG input: Wave Out"
                          );
            }
        }
    }
コード例 #32
0
    void Start()
    {
#if UNITY_ANDROID
        ThalmicHub.AttachByMacAddress();
#endif
    }
コード例 #33
0
    // Update is called once per frame
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.Fist)
            {
                // Vibrate the Myo armband when a fist is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // down move
                gm.Move(MoveDirection.Down);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                // Vibrate the Myo armband when a FingersSpread is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // up move
                gm.Move(MoveDirection.Up);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                // Vibrate the Myo armband when a WaveIn is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // left move
                gm.Move(MoveDirection.Left);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                // Vibrate the Myo armband when a WaveOut is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // right move
                gm.Move(MoveDirection.Right);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                // Vibrate the Myo armband when a DoubleTap is made.
                thalmicMyo.Vibrate(VibrationType.Medium);
                // Restart Game
                // disable current hub,
                ThalmicHub hub = ThalmicHub.instance;
                DestroyImmediate(hub);
                gm.NewGameButtonHandler();
                //ExtendUnlockAndNotifyUserAction (thalmicMyo);
            }
        }
    }
コード例 #34
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 48;

        ThalmicHub hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo1 = myo1.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
            timeForInstructions = 13f;
        }
        else if (!thalmicMyo1.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
            timeForInstructions = 13f;
        }
        else if (!thalmicMyo1.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
            timeForInstructions = 13f;
        }

        // Access the ThalmicMyo script attached to the Myo object.
        ThalmicMyo thalmicMyo2 = myo2.GetComponent <ThalmicMyo> ();

        if (!hub.hubInitialized)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
            timeForInstructions = 13f;
        }
        else if (!thalmicMyo2.isPaired)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
            timeForInstructions = 13f;
        }
        else if (!thalmicMyo2.armSynced)
        {
            GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
            timeForInstructions = 13f;
        }
        else
        {
            if (timeForInstructions > 0)
            {
                GUI.Label(new Rect(12, 8, Screen.width, Screen.height),
                          "Right Hand: Wave in to fly inwards" +
                          "\nWave out to fly outwards" +
                          "\nArm up/down to raise/lower volume" +
                          "\nLeft Hand: Arm up/down to raise/lower pitch" +
                          "\nEscape Key: ");
            }
        }


        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
コード例 #35
0
    // Update is called once per frame.
    void Update()
    {
        ThalmicHub hub        = ThalmicHub.instance;
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        bool updateReference = false;

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);
                FindObjectOfType <Tetramino>().RotateClockwise();
                LockingPolicyTime(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);

                //transform.position += new UnityEngine.Vector3(-1, 0, 0);


                FindObjectOfType <Tetramino>().MoveLeftOnce();

                LockingPolicyTime(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);

                //transform.position += new UnityEngine.Vector3(1, 0, 0);


                FindObjectOfType <Tetramino>().MoveRightOnce();

                LockingPolicyTime(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.Fist)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);
                FindObjectOfType <Tetramino>().RotateCounterClockwise();
                LockingPolicyTime(thalmicMyo);
            }


            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);
                FindObjectOfType <Tetramino>().SpeedUp();
                LockingPolicyTime(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.Unknown)
            {
                thalmicMyo.Vibrate(VibrationType.Long);
                updateReference = true;
                LockingPolicyTime(thalmicMyo);
            }
        }

        if (Input.GetKeyDown("r"))
        {
            updateReference = true;
        }

        if (updateReference)
        {
            //_antiYaw = Quaternion.FromToRotation(
            //new Vector3(myo.transform.forward.x, 0, myo.transform.forward.z),
            //new Vector3(0, 0, 1)

            //);
            //Vector3 referenceZeroRoll = computeZeroRollVector(myo.transform.forward);
            //_referenceRoll = rollFromZero(referenceZeroRoll, myo.transform.forward, myo.transform.up);
        }

        //Vector3 zeroRoll = computeZeroRollVector(myo.transform.forward);
        //float roll = rollFromZero(zeroRoll, myo.transform.forward, myo.transform.up);

        //float relativeRoll = normalizeAngle(roll - _referenceRoll);

        //// antiRoll represents a rotation about the myo Armband's forward axis adjusting for reference roll.
        //Quaternion antiRoll = Quaternion.AngleAxis(relativeRoll, myo.transform.forward);

        //// Here the anti-roll and yaw rotations are applied to the myo Armband's forward direction to yield
        //// the orientation of the joint.
        //transform.rotation = _antiYaw * antiRoll * Quaternion.LookRotation(myo.transform.forward);

        //if (thalmicMyo.xDirection == Thalmic.Myo.XDirection.TowardWrist)
        //{
        //    // Mirror the rotation around the XZ plane in Unity's coordinate system (XY plane in Myo's coordinate
        //    // system). This makes the rotation reflect the arm's orientation, rather than that of the Myo armband.
        //    transform.rotation = new Quaternion(transform.localRotation.x,
        //                                        -transform.localRotation.y,
        //                                        transform.localRotation.z,
        //                                        -transform.localRotation.w);
        //}
    }
コード例 #36
0
 void Start()
 {
     lastPose   = Pose.Unknown;
     thalmicMyo = myo.GetComponent <ThalmicMyo> ();
     hub        = ThalmicHub.instance;
 }