Skip to content

Instantly share code, notes, and snippets.

@rjth
Created March 2, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjth/b4a5582ada689f4cd3db9644bf54fe64 to your computer and use it in GitHub Desktop.
Save rjth/b4a5582ada689f4cd3db9644bf54fe64 to your computer and use it in GitHub Desktop.
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