Ejemplo n.º 1
0
        public int GetJSON(ESensoPositionType hand, ESensoFingerType finger, ref Byte[] buf, ref int bufOffset)
        {
            var str = String.Format("{{\"dst\":\"{0}\",\"type\":\"vibration\",\"data\":{{\"type\":{1},\"dur\":{2},\"str\":{3}}}}}\n", (hand == ESensoPositionType.RightHand ? "rh" : "lh"), (int)finger, m_duration, m_strength);

            changed = false;
            return(Encoding.ASCII.GetBytes(str, 0, str.Length, buf, bufOffset));
        }
Ejemplo n.º 2
0
    ///
    /// @brief Send vibrating command to the server
    ///
    public void VibrateFinger(ESensoPositionType handType, ESensoFingerType fingerType, ushort duration, byte strength)
    {
        int handMult = handType == ESensoPositionType.RightHand ? 0 : 1;
        int ind      = handMult * 5 + (int)fingerType;

        lock (vibroLock)
            vibroPackets[ind].Change(duration, strength);
    }
Ejemplo n.º 3
0
    /// Events
    public void fingerPinch(ESensoPositionType handType, ESensoFingerType finger1Type, ESensoFingerType finger2Type, bool stop = false)
    {
        SensoHand aHand = null;

        foreach (var hand in sensoHands)
        {
            if (hand.HandType == handType)
            {
                aHand = hand;
                break;
            }
        }

        if (aHand != null)
        {
            aHand.TriggerPinch(finger1Type, finger2Type, stop);
        }
    }
Ejemplo n.º 4
0
    ///
    /// @brief Parses JSON packet received from server
    ///
    private ESensoPositionType processJsonStr(string jsonPacket)
    {
        ESensoPositionType receivedType = ESensoPositionType.Unknown;
        JSONNode           parsedData   = null;

        try {
            parsedData = JSON.Parse(jsonPacket);
        } catch (Exception ex) {
            Debug.LogError("packet " + jsonPacket + " parse error: " + ex.Message);
        }
        if (parsedData != null)
        {
            if (parsedData["type"].Value.Equals("position"))
            {
                var dataNode = parsedData["data"];
                receivedType = getPositionFromString(dataNode["type"].Value);
                try {
                    handSamples[(int)receivedType].parseJSONNode(dataNode);
                } catch (Exception ex) {
                    receivedType = ESensoPositionType.Unknown;
                    Debug.LogError(ex.Message);
                }
            }
            else if (parsedData["type"].Value.Equals("gesture"))
            {
                SensoHandGesture aGesture = new SensoHandGesture(parsedData["data"]);
                gestures.AddLast(aGesture);
                ++GesturesCount;
            }
            else if (parsedData["type"].Value.Equals("battery"))
            {
                var dataNode = parsedData["data"];
                int ind      = (int)getPositionFromString(dataNode["type"].Value);
                batteryValues[ind] = dataNode["level"].AsInt;
            }
            else
            {
                Debug.Log("Received unknown type: " + parsedData["type"]);
            }
        }
        return(receivedType);
    }
Ejemplo n.º 5
0
    private void netSendVibro(ref Byte[] buf, ref int offset)
    {
        ESensoPositionType hand   = ESensoPositionType.Unknown;
        ESensoFingerType   finger = ESensoFingerType.Thumb;

        lock (vibroLock) {
            for (int i = 0; i < 10; ++i)
            {
                if (i % 5 == 0)
                {
                    ++hand;
                    finger = ESensoFingerType.Thumb;
                }
                if (vibroPackets[i].changed)
                {
                    offset += vibroPackets[i].GetJSON(hand, finger, ref buf, ref offset);
                }
                ++finger;
            }
        }
    }
Ejemplo n.º 6
0
 public int GetBatteryValue(ESensoPositionType handType)
 {
     return(batteryValues[(int)handType]);
 }
Ejemplo n.º 7
0
 ///
 /// @brief Returns current sample of the specified hand
 ///
 public SensoHandData GetSample(ESensoPositionType handType)
 {
     return(handSamples[(int)handType]);
 }
Ejemplo n.º 8
0
 ///
 /// @brief Returns current battery value for the glove
 ///
 public int GetBattery(ESensoPositionType pos)
 {
     return(sensoThread.GetBatteryValue(pos));
 }
Ejemplo n.º 9
0
    /*void OrientationUpdated(OVRCameraRig rig)
     * {
     *  if (VRCameraHolder != null)
     *  {
     *      VRCameraHolder.localRotation = Quaternion.Inverse(rig.centerEyeAnchor.localRotation);
     *  }
     *  if (DateTime.Now >= orientationNextSend)
     *  {
     *      sensoThread.SendHMDOrientation(rig.centerEyeAnchor.localEulerAngles);
     *      orientationNextSend = DateTime.Now.AddMilliseconds(orientationSendEveryMS);
     *  }
     * }*/

    ///
    /// @brief Send vibration command to the server
    ///
    public void SendVibro(ESensoPositionType hand, ESensoFingerType finger, ushort duration, byte strength)
    {
        sensoThread.VibrateFinger(hand, finger, duration, strength);
    }