void HapticGrabberThread()
    {
        //       while (!_isDone)
        {
            _dataArrived = false;
            _samples.Clear();
            while (_receiver.GrabFrame() && !_isDone)
            {
                int length = _receiver.GetDataLength();
                _receiver.GetData(_tmpdata, length);
                int pos = 0;
                while (pos < length)
                {
                    _samples.Add(BitConverter.ToSingle(_tmpdata, pos) * Scaler + Offset);
                    pos += sizeof(float);
                }
                _dataArrived = true;
//                 _forceVector.x = BitConverter.ToSingle(data, 0);
//                 _forceVector.y = BitConverter.ToSingle(data, sizeof(float));
//                 _forceVector.z = BitConverter.ToSingle(data, sizeof(float) * 2);
//                 Force.Invoke(_forceVector);
            }
            if (_dataArrived)
            {
                Samples.Invoke(_samples);
            }
        }
    }
 void HapticGrabberThread()
 {
     //  while (!_isDone)
     {
         byte[] data = null;
         _dataArrived = false;
         while (_receiver.GrabFrame() && !_isDone)
         {
             int length = _receiver.GetDataLength();
             if (length == 0)
             {
                 continue;
             }
             data = new byte[length];
             _receiver.GetData(data, length);
             _dataArrived = true;
         }
         if (_dataArrived)
         {
             int count = data.Length / sizeof(float);
             _tactileVector.Clear();
             _tactileVector.Capacity = count;
             receviedCount           = count;
             int ptr = 0;
             for (int i = 0; i < count; ++i)
             {
                 _tactileVector.Add(BitConverter.ToSingle(data, ptr));
                 ptr += sizeof(float);
             }
             dataReceived = _tactileVector.ToArray();
             _dataArrived = true;
         }
     }
 }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        while (_player.GrabFrame())
        {
            int    length = _player.GetDataLength();
            byte[] data   = new byte[length];
            count = length / sizeof(float);
            _player.GetData(data, length);

            int ptr = 0;
            int min = (count < vals.Length ? count : vals.Length);
            for (int i = 0; i < min; ++i)
            {
                vals[i] = BitConverter.ToSingle(data, ptr);
                ptr    += sizeof(float);
            }
        }
    }