-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMUManager.cs
69 lines (58 loc) · 2.05 KB
/
IMUManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Runtime.InteropServices;
using TMPro;
using UnityEngine;
public class IMUManager : MonoBehaviour
{
[StructLayout(LayoutKind.Sequential)]
struct OUTPUT
{
public float x;
public float y;
public float z;
}
#if ENABLE_WINMD_SUPPORT
[DllImport("HL2RmUnityPlugin", EntryPoint = "StartStreaming", CallingConvention = CallingConvention.StdCall)]
public static extern void StartStreaming();
[DllImport("HL2RmUnityPlugin", EntryPoint = "GetAccelSample", CallingConvention = CallingConvention.StdCall)]
public static extern int GetAccelSample(IntPtr pv1);
[DllImport("HL2RmUnityPlugin", EntryPoint = "GetGyroSample", CallingConvention = CallingConvention.StdCall)]
public static extern int GetGyroSample(IntPtr pv1);
[DllImport("HL2RmUnityPlugin", EntryPoint = "GetMagSample", CallingConvention = CallingConvention.StdCall)]
public static extern int GetMagSample(IntPtr pv1);
#endif
public TextMeshPro accelTextMesh;
public TextMeshPro gyroTextMesh;
public TextMeshPro magTextMesh;
private void Start()
{
#if ENABLE_WINMD_SUPPORT
StartStreaming();
#endif
}
private void Update()
{
#if ENABLE_WINMD_SUPPORT
int sizeOut = Marshal.SizeOf(typeof(OUTPUT));
IntPtr pBuffOut = Marshal.AllocHGlobal(sizeOut);
int result = GetAccelSample(pBuffOut);
OUTPUT pOut = (OUTPUT)Marshal.PtrToStructure(pBuffOut, typeof(OUTPUT));
if (accelTextMesh != null)
{
accelTextMesh.text = $"Accel: {pOut.x} {pOut.y} {pOut.z}";
}
result = GetGyroSample(pBuffOut);
pOut = (OUTPUT)Marshal.PtrToStructure(pBuffOut, typeof(OUTPUT));
if (gyroTextMesh != null)
{
gyroTextMesh.text = $"Gyro: {pOut.x} {pOut.y} {pOut.z}";
}
result = GetMagSample(pBuffOut);
pOut = (OUTPUT)Marshal.PtrToStructure(pBuffOut, typeof(OUTPUT));
if (magTextMesh != null)
{
magTextMesh.text = $"Mag: {pOut.x} {pOut.y} {pOut.z}";
}
#endif
}
}