Created
March 2, 2018 18:02
-
-
Save rjth/b4a5582ada689f4cd3db9644bf54fe64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
namespace Sensel | |
{ | |
class SenselContacts : MonoBehaviour | |
{ | |
IntPtr _handle = IntPtr.Zero; | |
SenselFrame _frame = new SenselFrame(); | |
SenselSensorInfo _sensor_info; | |
void Start() | |
{ | |
SenselDeviceList list = new SenselDeviceList(); | |
list.num_devices = 0; | |
Sensel.senselGetDeviceList(ref list); | |
Debug.Log("Num Devices: " + list.num_devices); | |
if (list.num_devices != 0) | |
{ | |
Sensel.senselOpenDeviceByID(ref _handle, list.devices[0].idx); | |
} | |
if (_handle != IntPtr.Zero) | |
{ | |
Sensel.senselGetSensorInfo(_handle, ref _sensor_info); | |
Sensel.senselSetFrameContent(_handle, 1); | |
Sensel.senselAllocateFrameData(_handle, _frame); | |
Sensel.senselStartScanning(_handle); | |
} | |
} | |
void LateUpdate() | |
{ | |
if (_handle != IntPtr.Zero) | |
{ | |
Int32 num_frames = 0; | |
Sensel.senselReadSensor(_handle); | |
Sensel.senselGetNumAvailableFrames(_handle, ref num_frames); | |
for (int f = 0; f < num_frames; ++f) | |
{ | |
Sensel.senselGetFrame(_handle, _frame); | |
if (f + 1 == num_frames) | |
{ | |
// Force value is returned, without problem | |
Debug.Log(_frame.force_array[10]); | |
// Number of contacts always stays null, doesn't return anything | |
Debug.Log(_frame.contacts.Length); | |
Debug.Log(_frame.contacts[0].x_pos); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment