Esempio n. 1
0
    public IAsyncResult BeginGetFrame(EyeIndex eyeId, AsyncCallback callback)
    {
        if (m_state == SensoNetworkState.SENSO_DISCONNECTED)
        {
            doConnect();
        }
        if (m_state != SensoNetworkState.SENSO_CONNECTED || IsReceiving)
        {
            return(null);
        }
        var m_frameResult = new FrameGetResult(callback);
        var outBuf        = BitConverter.GetBytes((Int32)eyeId);

        //var writeCB = new AsyncCallback(OnWriteResult);
        IsReceiving = true;
        try {
            m_stream.Write(outBuf, 0, 4);
            DoRead(m_stream, m_frameResult);
        }
        catch (Exception ex)
        {
            Disconnect();
        }
        return(m_frameResult);
    }
Esempio n. 2
0
    private void UpdateEyeOpenness(EyeIndex eyeIndex)
    {
        var anotherEye = eyeIndex == EyeIndex.RIGHT ? EyeIndex.LEFT : EyeIndex.RIGHT;

        SRanipal_Eye_v2.GetEyeOpenness(eyeIndex, out var currentOpenness);

        // 指定の目をつむっているとき
        if (currentOpenness < BlinkThreshold)
        {
            // 目を閉じてる経過時間を加算
            _closingTime[eyeIndex] += Time.deltaTime;

            // 前回の入力では空いてるとき (目をつむった瞬間)
            if (!_isClosing[eyeIndex])
            {
                // OnWink(eyeIndex);

                _closingTime[eyeIndex] = 0;

                //これはこのif文の最後でやる
                _isClosing[eyeIndex] = true;
            }
        }
        // 指定の目が空いているとき
        else
        {
            _closingTime[eyeIndex] = 0;
            _isClosing[eyeIndex]   = false;
        }

        _prevEyeOpenness[eyeIndex] = currentOpenness;
    }
Esempio n. 3
0
 /// <summary>
 /// Gets the openness value of an eye when enable eye callback function.
 /// </summary>
 /// <param name="eye">The index of an eye.</param>
 /// <param name="openness">The openness value of an eye, clamped between 0 (fully closed) and 1 (fully open). </param>
 /// <param name="eye_data">ViveSR.anipal.Eye.EyeData_v2. </param>
 /// <returns>Indicates whether the openness value received is valid.</returns>
 public static bool GetEyeOpenness(EyeIndex eye, out float openness, EyeData_v2 eye_data)
 {
     if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING)
     {
         SingleEyeData eyeData = eye == EyeIndex.LEFT ? eye_data.verbose_data.left : eye_data.verbose_data.right;
         bool          valid   = eyeData.GetValidity(SingleEyeDataValidity.SINGLE_EYE_DATA_EYE_OPENNESS_VALIDITY);
         openness = valid ? eyeData.eye_openness : 0;
     }
     else
     {
         // If not support eye tracking, set default to open.
         openness = 1;
     }
     return(true);
 }
Esempio n. 4
0
                /// <summary>
                /// Gets the 2D position of a selected pupil when enable eye callback function.
                /// </summary>
                /// <param name="eye">The index of an eye.</param>
                /// <param name="postion">The 2D position of a selected pupil clamped between -1 and 1.
                /// Position (0, 0) indicates that the pupil is looking forward;
                /// position (1, 1) up-rightward; and
                /// position (-1, -1) left-downward.</param>
                /// <param name="eye_data">ViveSR.anipal.Eye.EyeData. </param>
                /// <returns></returns>
                public static bool GetPupilPosition(EyeIndex eye, out Vector2 postion, EyeData eye_data)
                {
                    bool valid = false;

                    if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING)
                    {
                        SingleEyeData eyeData = eye == EyeIndex.LEFT ? eye_data.verbose_data.left : eye_data.verbose_data.right;
                        valid   = eyeData.GetValidity(SingleEyeDataValidity.SINGLE_EYE_DATA_PUPIL_POSITION_IN_SENSOR_AREA_VALIDITY);
                        postion = valid ? postion = new Vector2(eyeData.pupil_position_in_sensor_area.x * 2 - 1,
                                                                eyeData.pupil_position_in_sensor_area.y * -2 + 1) : Vector2.zero;
                    }
                    else
                    {
                        // If not support eye tracking, set default in middle.
                        postion = Vector2.zero;
                        valid   = true;
                    }
                    return(valid);
                }
Esempio n. 5
0
        // Update is called once per frame
        void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
            {
                return;
            }

            if (eye == Eye.left)
            {
                eyeName  = "Left : ";
                eyeIndex = EyeIndex.LEFT;
            }
            else
            {
                eyeName  = "Right : ";
                eyeIndex = EyeIndex.RIGHT;
            }
            SRanipal_Eye.GetEyeOpenness(eyeIndex, out openness);

            this.GetComponent <Text>().text = eyeName + openness.ToString("0.000");
        }
Esempio n. 6
0
    public UInt16[] GetFrame(EyeIndex eyeId, ref Byte[] frameBytes)
    {
        UInt16[] dim = { 0, 0 };
        int      sz;

        if (m_state == SensoNetworkState.SENSO_DISCONNECTED)
        {
            doConnect();
            return(dim);
        }
        if (m_state != SensoNetworkState.SENSO_CONNECTED)
        {
            return(dim);
        }
        var outBuf = BitConverter.GetBytes((Int32)eyeId);

        try
        {
            m_stream.Write(outBuf, 0, 4);
            m_stream.Read(frameBytes, 0, 4);
            dim[0] = BitConverter.ToUInt16(frameBytes, 0);
            dim[1] = BitConverter.ToUInt16(frameBytes, 2);
            sz     = dim[0] * dim[1] * 4;
            int readSz = 0;
            while (readSz < sz)
            {
                readSz += m_stream.Read(frameBytes, readSz, sz - readSz);
            }
        }
        catch (Exception ex)
        {
            Debug.LogError("Read stream error: " + ex.Message);
            Disconnect();
            dim[0] = 0; dim[1] = 0;
            return(dim);
        }
        return(dim);
    }
Esempio n. 7
0
    private void OnWink(EyeIndex eyeIndex)
    {
        Debug.Log("Wink! : " + eyeIndex.ToString());

        var lookingNode = MyUtility.GetLookingNode(out var hit);

        if (lookingNode)
        {
            if (lookingNode.CompareTag("Node/Resource"))
            {
                var resourceNode = lookingNode.GetComponent <ResourceNode>();
                if (eyeIndex == EyeIndex.LEFT)
                {
                    resourceNode.InstantiateLinkedNodes(SystemManager.Instance.LinkedNodeLimit);
                }

                if (eyeIndex == EyeIndex.RIGHT)
                {
                    resourceNode.InstantiateStatsNodes();
                }
            }
        }
    }
Esempio n. 8
0
 /// <summary>
 /// Gets the 2D position of a selected pupil.
 /// </summary>
 /// <param name="eye">The index of an eye.</param>
 /// <param name="postion">The 2D position of a selected pupil clamped between -1 and 1.
 /// Position (0, 0) indicates that the pupil is looking forward;
 /// position (1, 1) up-rightward; and
 /// position (-1, -1) left-downward.</param>
 /// <returns></returns>
 public static bool GetPupilPosition(EyeIndex eye, out Vector2 postion)
 {
     UpdateData();
     return(GetPupilPosition(eye, out postion, EyeData_));
 }
Esempio n. 9
0
 /// <summary>
 /// Gets the openness value of an eye.
 /// </summary>
 /// <param name="eye">The index of an eye.</param>
 /// <param name="openness">The openness value of an eye, clamped between 0 (fully closed) and 1 (fully open). </param>
 /// <returns>Indicates whether the openness value received is valid.</returns>
 public static bool GetEyeOpenness(EyeIndex eye, out float openness)
 {
     UpdateData();
     return(GetEyeOpenness(eye, out openness, EyeData_));
 }