From cf4c2c50e75e6b21d7aa65211031417619e4dacd Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Fri, 30 Mar 2018 20:54:08 +0200 Subject: Some tests --- bindings/cs/Demo/Program.cs | 46 ++------ bindings/cs/libsurvive.net/SurviveContext.cs | 93 ++++++++++++---- bindings/cs/libsurvive.net/cfunctions.cs | 132 ++++++++++++++--------- bindings/cs/libsurvive.net/libsurvive.net.csproj | 2 +- 4 files changed, 165 insertions(+), 108 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/Demo/Program.cs b/bindings/cs/Demo/Program.cs index c03d83c..aa98b6c 100644 --- a/bindings/cs/Demo/Program.cs +++ b/bindings/cs/Demo/Program.cs @@ -7,50 +7,22 @@ using System.Threading.Tasks; namespace Demo { - internal class MyHandler : SurviveContext + + class Program { - private static void WritePose(string name, SurvivePose pose) + static void Main(string[] args) { - Console.Out.WriteLine(name); - Console.Out.Write(" [ "); - for (int i = 0; i < 3; i++) - Console.Out.Write("{0} ", pose.Pos[i]); - Console.Out.Write(" ] [ "); - for (int i = 0; i < 4; i++) - Console.Out.Write("{0} ", pose.Rot[i]); - Console.Out.Write(" ] "); - Console.Out.WriteLine(); - } + SurviveContext context = new SurviveContext(args); + context.AddPoseUpdateCallback(HMDUpdate, -1); - public MyHandler() : base() - { - } - public MyHandler(string[] args) : base(args) - { - } + while (context.Poll() == 0) { + } - protected void LightHouseEvent1(IntPtr ctx, byte lighthouse, SurvivePose lighthouse_pose, SurvivePose object_pose) - { - base.LightHouseEvent(ctx, lighthouse, lighthouse_pose, object_pose); - WritePose("Lighthouse", lighthouse_pose); - WritePose("Object", object_pose); } - - protected override void PoseEvent(IntPtr so, byte lighthouse, SurvivePose pose) - { - WritePose("Pose", pose); - base.PoseEvent(so, lighthouse, pose); - } - } - class Program - { - static void Main(string[] args) + + public static void HMDUpdate(int ObjectID, Vector3 pos) { - MyHandler handler = new MyHandler(args); - - while (handler.Poll() == 0) { - } } diff --git a/bindings/cs/libsurvive.net/SurviveContext.cs b/bindings/cs/libsurvive.net/SurviveContext.cs index bafcf2b..37f67e4 100644 --- a/bindings/cs/libsurvive.net/SurviveContext.cs +++ b/bindings/cs/libsurvive.net/SurviveContext.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace libsurvive { @@ -8,16 +9,17 @@ namespace libsurvive public class SurviveContext : IDisposable { + public delegate void PoseUpdate(int ObjectID, Vector3 pos); + + protected IntPtr ctx; public void Dispose() { - cfunctions.survive_close(ctx); + cfunctions.Survive_close(ctx); ctx = IntPtr.Zero; } - public SurviveContext() : this(null) { } - /** * We need to keep these delegates around for the lifespan of this object. * if we just pass the functions in, it creates temporary delegates that @@ -34,12 +36,28 @@ namespace libsurvive text_feedback_func info_func; public SurviveContext(string[] args) + { + Init(args); + } + + public SurviveContext(string replaydata) + { + string[] vs = new[] { "--playback", "lightcap-reformat.log"}; + Init(vs); + } + + internal void Init(string[] args) { string[] newArgs = new string[args.Length + 1]; newArgs[0] = System.Reflection.Assembly.GetEntryAssembly().FullName; Array.Copy(args, 0, newArgs, 1, args.Length); - ctx = cfunctions.survive_init_internal(newArgs.Length, newArgs); + ctx = cfunctions.Survive_init_internal(newArgs.Length, newArgs); + + if (ctx == IntPtr.Zero) + { + throw new Exception("There was a problem initializing the lib!"); + } light_Process_Func = LightEvent; raw_Pose_Func = PoseEvent; @@ -51,17 +69,29 @@ namespace libsurvive error_func = ErrorEvent; info_func = InfoEvent; - cfunctions.survive_install_raw_pose_fn(ctx, raw_Pose_Func); - cfunctions.survive_install_light_fn(ctx, light_Process_Func); - cfunctions.survive_install_lighthouse_pose_fn(ctx, lighthouse_Pose_Func); - cfunctions.survive_install_angle_fn(ctx, angle_Process_Func); - cfunctions.survive_install_button_fn(ctx, button_Process_Func); - cfunctions.survive_install_htc_config_fn(ctx, htc_Config_Func); - cfunctions.survive_install_imu_fn(ctx, imu_Process_Func); - cfunctions.survive_install_error_fn(ctx, error_func); - cfunctions.survive_install_info_fn(ctx, info_func); + cfunctions.Survive_install_raw_pose_fn(ctx, raw_Pose_Func); + cfunctions.Survive_install_light_fn(ctx, light_Process_Func); + cfunctions.Survive_install_lighthouse_pose_fn(ctx, lighthouse_Pose_Func); + cfunctions.Survive_install_angle_fn(ctx, angle_Process_Func); + cfunctions.Survive_install_button_fn(ctx, button_Process_Func); + cfunctions.Survive_install_htc_config_fn(ctx, htc_Config_Func); + cfunctions.Survive_install_imu_fn(ctx, imu_Process_Func); + cfunctions.Survive_install_error_fn(ctx, error_func); + cfunctions.Survive_install_info_fn(ctx, info_func); } + + //Dictionary PoseUpdateCallbacks = new Dictionary(); + PoseUpdate poseUpdate; + + public void AddPoseUpdateCallback(PoseUpdate update, int objectID) + { + //PoseUpdateCallbacks[objectID] += update; + poseUpdate += update; + } + + + virtual protected void InfoEvent(SurviveObjectPtr ctx, string fault) { Console.Out.WriteLine(fault); @@ -74,42 +104,61 @@ namespace libsurvive virtual protected void IMUEvent(SurviveObjectPtr so, int mask, double[] accelgyro, uint timecode, int id) { - cfunctions.survive_default_imu_process(so, mask, accelgyro, timecode, id); + cfunctions.Survive_default_imu_process(so, mask, accelgyro, timecode, id); } virtual protected int HTCConfigEvent(SurviveObjectPtr so, string ct0conf, int len) { - return cfunctions.survive_default_htc_config_process(so, ct0conf, len); + return cfunctions.Survive_default_htc_config_process(so, ct0conf, len); } virtual protected void ButtonEvent(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, ushort axis1Val, byte axis2Id, ushort axis2Val) { - cfunctions.survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); + cfunctions.Survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); } virtual protected void AngleEvent(SurviveObjectPtr so, int sensor_id, int acode, uint timecode, double length, double angle, uint lh) { - cfunctions.survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); + cfunctions.Survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); } protected void LightHouseEvent(SurviveObjectPtr ctx, byte lighthouse, SurvivePose lighthouse_pose, SurvivePose object_pose) { - cfunctions.survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); + cfunctions.Survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); } virtual protected void LightEvent(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse) { - cfunctions.survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); + cfunctions.Survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); + + //Console.WriteLine("LightEvent"); } - virtual protected void PoseEvent(IntPtr so, byte lighthouse, SurvivePose pose) + virtual protected void PoseEvent(SurviveObjectPtr so, byte lighthouse, SurvivePose pose) { - cfunctions.survive_default_raw_pose_process(so, lighthouse, pose); + cfunctions.Survive_default_raw_pose_process(so, lighthouse, pose); + + Console.WriteLine("PoseEvent"); } public int Poll() { - return cfunctions.survive_poll(ctx); + return cfunctions.Survive_poll(ctx); } } + + public struct Vector3 + { + public float x; + public float y; + public float z; + } + + public struct Qutarnion + { + public float x; + public float y; + public float z; + public float w; + } } \ No newline at end of file diff --git a/bindings/cs/libsurvive.net/cfunctions.cs b/bindings/cs/libsurvive.net/cfunctions.cs index 760681e..6715a36 100644 --- a/bindings/cs/libsurvive.net/cfunctions.cs +++ b/bindings/cs/libsurvive.net/cfunctions.cs @@ -18,74 +18,110 @@ namespace libsurvive public double[] Rot; // Quaternion in the form wxyz } + [StructLayout(LayoutKind.Sequential)] + public class SurviveObject + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public char[] codename; //3 letters, null-terminated. Currently HMD, WM0, WM1. + } + class cfunctions { -#pragma warning disable IDE1006 // Naming Styles - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall) ] - public static extern SurviveContextPtr survive_init_internal(int argc, string[] args); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern SurviveContextPtr survive_close(SurviveContextPtr ctx); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern int survive_poll(SurviveContextPtr ctx); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern int survive_startup(SurviveContextPtr ctx); - - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_htc_config_fn(SurviveContextPtr ctx, htc_config_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_info_fn(SurviveContextPtr ctx, text_feedback_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_error_fn(SurviveContextPtr ctx, text_feedback_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_imu_fn(SurviveContextPtr ctx, imu_process_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_angle_fn(SurviveContextPtr ctx, angle_process_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_button_fn(SurviveContextPtr ctx, button_process_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_raw_pose_fn(SurviveContextPtr ctx, raw_pose_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_lighthouse_pose_fn(SurviveContextPtr ctx, lighthouse_pose_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_install_light_fn(SurviveContextPtr ctx, light_process_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_cal_install(SurviveContextPtr ctx); - - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_default_light_process(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lh); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_default_imu_process(SurviveObjectPtr so, int mode, double[] accelgyro, UInt32 timecode, int id); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_default_angle_process(SurviveObjectPtr so, int sensor_id, int acode, UInt32 timecode, double length, double angle, UInt32 lh); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_default_button_process(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, UInt16 axis1Val, byte axis2Id, UInt16 axis2Val); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_default_raw_pose_process(SurviveObjectPtr so, byte lighthouse, SurvivePose pose); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern void survive_default_lighthouse_pose_process(SurviveContextPtr ctx, byte lighthouse, SurvivePose lh_pose, - SurvivePose obj_pose); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - public static extern int survive_default_htc_config_process(SurviveObjectPtr so, string ct0conf, int len); - -#pragma warning restore IDE1006 // Naming Styles +//#pragma warning disable IDE1006 // Naming Styles + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_init_internal") ] + public static extern SurviveContextPtr Survive_init_internal(int argc, string[] args); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_close")] + public static extern SurviveContextPtr Survive_close(SurviveContextPtr ctx); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_poll")] + public static extern int Survive_poll(SurviveContextPtr ctx); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_startup")] + public static extern int Survive_startup(SurviveContextPtr ctx); + + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_htc_config_fn")] + public static extern void Survive_install_htc_config_fn(SurviveContextPtr ctx, htc_config_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_info_fn")] + public static extern void Survive_install_info_fn(SurviveContextPtr ctx, text_feedback_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_error_fn")] + public static extern void Survive_install_error_fn(SurviveContextPtr ctx, text_feedback_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_imu_fn")] + public static extern void Survive_install_imu_fn(SurviveContextPtr ctx, imu_process_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_angle_fn")] + public static extern void Survive_install_angle_fn(SurviveContextPtr ctx, angle_process_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_button_fn")] + public static extern void Survive_install_button_fn(SurviveContextPtr ctx, button_process_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_raw_pose_fn")] + public static extern void Survive_install_raw_pose_fn(SurviveContextPtr ctx, raw_pose_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_lighthouse_pose_fn")] + public static extern void Survive_install_lighthouse_pose_fn(SurviveContextPtr ctx, lighthouse_pose_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_install_light_fn")] + public static extern void Survive_install_light_fn(SurviveContextPtr ctx, light_process_func fbp); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_cal_install")] + public static extern void Survive_cal_install(SurviveContextPtr ctx); + + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_light_process")] + public static extern void Survive_default_light_process(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lh); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_imu_process")] + public static extern void Survive_default_imu_process(SurviveObjectPtr so, int mode, double[] accelgyro, UInt32 timecode, int id); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_angle_process")] + public static extern void Survive_default_angle_process(SurviveObjectPtr so, int sensor_id, int acode, UInt32 timecode, double length, double angle, UInt32 lh); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_button_process")] + public static extern void Survive_default_button_process(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, UInt16 axis1Val, byte axis2Id, UInt16 axis2Val); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_raw_pose_process")] + public static extern void Survive_default_raw_pose_process(SurviveObjectPtr so, byte lighthouse, SurvivePose pose); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_lighthouse_pose_process")] + public static extern void Survive_default_lighthouse_pose_process(SurviveContextPtr ctx, byte lighthouse, SurvivePose lh_pose, SurvivePose obj_pose); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_default_htc_config_process")] + public static extern int Survive_default_htc_config_process(SurviveObjectPtr so, string ct0conf, int len); + + +//#pragma warning restore IDE1006 // Naming Styles } + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int htc_config_func(SurviveObjectPtr so, string ct0conf, int len); [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void text_feedback_func(SurviveContextPtr ctx, string fault); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void light_process_func(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void imu_process_func(SurviveObjectPtr so, int mask, double[] accelgyro, UInt32 timecode, int id); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void angle_process_func(SurviveObjectPtr so, int sensor_id, int acode, UInt32 timecode, double length, double angle, UInt32 lh); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void button_process_func(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, UInt16 axis1Val, byte axis2Id, UInt16 axis2Val); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void raw_pose_func(SurviveObjectPtr so, byte lighthouse, SurvivePose pose); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void lighthouse_pose_func(SurviveContextPtr ctx, byte lighthouse, SurvivePose lighthouse_pose, SurvivePose object_pose); + } diff --git a/bindings/cs/libsurvive.net/libsurvive.net.csproj b/bindings/cs/libsurvive.net/libsurvive.net.csproj index eac3503..9f5c4f4 100644 --- a/bindings/cs/libsurvive.net/libsurvive.net.csproj +++ b/bindings/cs/libsurvive.net/libsurvive.net.csproj @@ -1,7 +1,7 @@ - netstandard1.6 + netstandard2.0 -- cgit v1.2.3 From ee3160032cd6a609a490be011019b323fe1c0c02 Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Sun, 1 Apr 2018 17:36:08 +0200 Subject: Added new accesors (WIP) --- bindings/cs/libsurvive.net/cfunctions.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/cfunctions.cs b/bindings/cs/libsurvive.net/cfunctions.cs index 6715a36..67812f5 100644 --- a/bindings/cs/libsurvive.net/cfunctions.cs +++ b/bindings/cs/libsurvive.net/cfunctions.cs @@ -94,7 +94,29 @@ namespace libsurvive public static extern int Survive_default_htc_config_process(SurviveObjectPtr so, string ct0conf, int len); -//#pragma warning restore IDE1006 // Naming Styles + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_codename")] + public static extern char Survive_object_codename(SurviveObjectPtr so); + + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_drivername")] + public static extern char Survive_object_drivername(SurviveObject so); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_charge")] + public static extern byte Survive_object_charge(SurviveObject so); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_charging")] + public static extern bool Survive_object_charging(SurviveObject so); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_pose")] + public static extern SurvivePose Survive_object_pose(SurviveObject so); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_sensor_locations")] + public static extern int Survive_object_sensor_locations(SurviveObjectPtr so); + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_sensor_normals")] + public static extern int Survive_object_sensor_normals(SurviveObjectPtr so); + + //#pragma warning restore IDE1006 // Naming Styles } -- cgit v1.2.3 From c05e42e756e8e1560adc22aacde87dbdf2e02b45 Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Sun, 1 Apr 2018 17:37:11 +0200 Subject: Updated the launch parameters --- bindings/cs/libsurvive.net/SurviveContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/SurviveContext.cs b/bindings/cs/libsurvive.net/SurviveContext.cs index 37f67e4..084df31 100644 --- a/bindings/cs/libsurvive.net/SurviveContext.cs +++ b/bindings/cs/libsurvive.net/SurviveContext.cs @@ -42,7 +42,7 @@ namespace libsurvive public SurviveContext(string replaydata) { - string[] vs = new[] { "--playback", "lightcap-reformat.log"}; + string[] vs = new[] { "--playback", "P:/c/libsurvive-data/lightcap-reformat/lightcap-reformat.log", "--disambiguator", "StateBased", "--calibrate" }; Init(vs); } -- cgit v1.2.3 From 0eea189db82fc72463a83a678d9b8d609fd09c6e Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Sun, 1 Apr 2018 18:58:19 +0200 Subject: Added the API file from Unity --- bindings/cs/libsurvive.net/LibSurViveAPI.cs | 342 ++++++++++++++++++++++++++++ bindings/cs/libsurvive.net/cfunctions.cs | 35 ++- 2 files changed, 359 insertions(+), 18 deletions(-) create mode 100644 bindings/cs/libsurvive.net/LibSurViveAPI.cs (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/LibSurViveAPI.cs b/bindings/cs/libsurvive.net/LibSurViveAPI.cs new file mode 100644 index 0000000..48336e8 --- /dev/null +++ b/bindings/cs/libsurvive.net/LibSurViveAPI.cs @@ -0,0 +1,342 @@ +//using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +using libsurvive; +using System; +using System.Threading; + +public class LibSurViveAPI +{ + + public struct SetupConfigs + { + public string playbaskFile; + public int playbackFactor; + public Disambiguator disambiguator; + public Poser poser; + public BoolConfig calibrate; + public string configFile; + } + + public enum Disambiguator + { + StateBased, + Charles, + Turvey, + Default + } + + public enum Poser + { + CharlesSlow, + DaveOrtho, + Dummy, + EPNP, + SBA + } + + public enum BoolConfig + { + Yes, + No, + Default + } + + + private static LibSurViveAPI _instance; + public static LibSurViveAPI instance + { + get + { + if (_instance == null) + { + _instance = new LibSurViveAPI(); + } + + return _instance; + } + } + + LibSurViveAPI() + { + CreateContext(); + + CreateTread(); + + } + + ~LibSurViveAPI() + { + running = false; + } + + Thread internalPollTread; + + private void CreateTread() + { + internalPollTread = new Thread(InternalPoll); + internalPollTread.Start(); + } + + bool running = true; + + void InternalPoll() + { + while (running) + { + cfunctions.Survive_poll(context); + } + } + + //private SurviveContext _context; + public IntPtr context; + + light_process_func light_Process_Func; + raw_pose_func raw_Pose_Func; + lighthouse_pose_func lighthouse_Pose_Func; + angle_process_func angle_Process_Func; + button_process_func button_Process_Func; + htc_config_func htc_Config_Func; + imu_process_func imu_Process_Func; + text_feedback_func error_func; + text_feedback_func info_func; + + internal void CreateContext() + { + //Debug.Log("Start Init"); + + SetupConfigs configs = new SetupConfigs + { + playbaskFile = "P:/c/libsurvive-data/lightcap-reformat/lightcap-reformat.log", + configFile = "survive_conf.json", + playbackFactor = 1 + }; + + string[] args = CreateStartParameters(configs); + + //string[] vs = new[] { "--playback", "P:/c/libsurvive-data/lightcap-reformat/lightcap-reformat.log", "--disambiguator", "StateBased", "--calibrate" }; + + context = cfunctions.Survive_init_internal(args.Length, args); + + if (context == IntPtr.Zero) + { + throw new Exception("There was a problem initializing the lib!"); + } + + light_Process_Func = LightEvent; + raw_Pose_Func = PoseEvent; + lighthouse_Pose_Func = LightHouseEvent; + angle_Process_Func = AngleEvent; + button_Process_Func = ButtonEvent; + htc_Config_Func = HTCConfigEvent; + imu_Process_Func = IMUEvent; + error_func = ErrorEvent; + info_func = InfoEvent; + + cfunctions.Survive_install_raw_pose_fn(context, raw_Pose_Func); + cfunctions.Survive_install_light_fn(context, light_Process_Func); + cfunctions.Survive_install_lighthouse_pose_fn(context, lighthouse_Pose_Func); + cfunctions.Survive_install_angle_fn(context, angle_Process_Func); + cfunctions.Survive_install_button_fn(context, button_Process_Func); + cfunctions.Survive_install_htc_config_fn(context, htc_Config_Func); + cfunctions.Survive_install_imu_fn(context, imu_Process_Func); + cfunctions.Survive_install_error_fn(context, error_func); + cfunctions.Survive_install_info_fn(context, info_func); + + //Debug.Log("Finished Init"); + + //Debug.Log("Start Startup"); + + //Debug.LogError("ASD"); + + int a = 0; + try + { + a = cfunctions.Survive_startup(context); + } + catch (Exception) + { + throw; + } + + if (a != 0) + { + throw new Exception("Error in startup"); + } + + //Debug.Log("Finished Startup"); + + } + + + static public string[] CreateStartParameters(SetupConfigs configs) + { + List args = new List(); + + args.Add("unity"); + + if (configs.playbaskFile != "") + { + args.AddRange(new[] { "--playback", configs.playbaskFile }); + args.AddRange(new[] { "--playback-factor", configs.playbackFactor.ToString() }); + } + + if(configs.disambiguator != Disambiguator.Default) + args.AddRange(new[] { "--disambiguator", Enum.GetName(typeof(Disambiguator), configs.disambiguator) }); + + if (configs.calibrate != BoolConfig.Default) + args.Add(configs.calibrate == BoolConfig.Yes ? "--calibrate" : "--no-calibrate"); + + if (configs.configFile != "") + args.AddRange(new[] { "-c", configs.configFile }); + + //args.AddRange(new[] { "--disambiguator", Enum.GetName(typeof(Poser), disambiguator) }); + + + + return args.ToArray(); + } + + + + + + virtual protected void InfoEvent(IntPtr ctx, string fault) + { + //Debug.Log(fault); + } + + virtual protected void ErrorEvent(IntPtr ctx, string fault) + { + //Debug.LogError(fault); + } + + virtual protected void IMUEvent(IntPtr so, int mask, double[] accelgyro, uint timecode, int id) + { + cfunctions.Survive_default_imu_process(so, mask, accelgyro, timecode, id); + } + + virtual protected int HTCConfigEvent(IntPtr so, string ct0conf, int len) + { + return cfunctions.Survive_default_htc_config_process(so, ct0conf, len); + } + + virtual protected void ButtonEvent(IntPtr so, byte eventType, byte buttonId, byte axis1Id, ushort axis1Val, byte axis2Id, ushort axis2Val) + { + cfunctions.Survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); + } + + virtual protected void AngleEvent(IntPtr so, int sensor_id, int acode, uint timecode, double length, double angle, uint lh) + { + cfunctions.Survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); + + //Debug.Log("AngleEvent"); + } + + protected void LightHouseEvent(IntPtr ctx, byte lighthouse, SurvivePose lighthouse_pose, SurvivePose object_pose) + { + cfunctions.Survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); + + //Debug.Log("LightHouseEvent"); + } + + virtual protected void LightEvent(IntPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse) + { + cfunctions.Survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); + + //Console.WriteLine("LightEvent"); + //Debug.Log("LightEvent"); + } + + virtual protected void PoseEvent(IntPtr so, byte lighthouse, SurvivePose pose) + { + cfunctions.Survive_default_raw_pose_process(so, lighthouse, pose); + + //vaDebug.Log("PoseEvent"); + + //poseUpdate(-1, new Vector3((float)pose.Pos[0], (float)pose.Pos[1], (float)pose.Pos[2]), new Quaternion((float)pose.Rot[0], (float)pose.Rot[1], (float)pose.Rot[2], (float)pose.Rot[3])); + + /* + string a = cfunctions.Survive_object_codename(so); + if (updates.ContainsKey(a)) + { + Vector3 pos = new Vector3((float)pose.Pos[0], (float)pose.Pos[1], (float)pose.Pos[2]); + Quaternion rot = new Quaternion((float)pose.Rot[0], (float)pose.Rot[1], (float)pose.Rot[2], (float)pose.Rot[3]); + updates[a](pos, rot); + } + */ + } + + + public delegate void PoseUpdate(SurviveVector3 pos, SurviveQuaternion quat); + + public Dictionary updates = new Dictionary(); + + public void AddCalback(string ID, PoseUpdate update) + { + if (!updates.ContainsKey(ID)) + { + updates.Add(ID, update); + } + else + { + updates[ID] += update; + } + } + + /* + public void Poll() + { + cfunctions.Survive_poll(context); + } + */ + + public SurviveObject GetSurviveObjectByName(string name) + { + if (name == "") + { + throw new Exception("Empty string is not accepted"); + } + + if (context == IntPtr.Zero) + throw new Exception("The context hasn't been initialsied yet"); + + return new SurviveObject( cfunctions.Survive_get_so_by_name(context, name)); + } +} + +public class SurviveObject +{ + public SurvivePose pose { get; private set; } + + public int charge { get; private set; } + public bool charging { get; private set; } + + + public SurviveObject(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + throw new Exception("Can't create SurviveObject with 0 pointer"); + } + + //pose = cfunctions.Survive_object_pose(ptr); + charge = cfunctions.Survive_object_charge(ptr); + charging = cfunctions.Survive_object_charging(ptr); + } +} + +public class SurviveVector3 +{ + float x; + float y; + float z; +} + +public class SurviveQuaternion +{ + float x; + float y; + float z; +} diff --git a/bindings/cs/libsurvive.net/cfunctions.cs b/bindings/cs/libsurvive.net/cfunctions.cs index 67812f5..ab5f7fd 100644 --- a/bindings/cs/libsurvive.net/cfunctions.cs +++ b/bindings/cs/libsurvive.net/cfunctions.cs @@ -12,23 +12,16 @@ namespace libsurvive [StructLayout(LayoutKind.Sequential)] public class SurvivePose { - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public double[] Pos; // Position in the form xyz [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public double[] Rot; // Quaternion in the form wxyz - } - - [StructLayout(LayoutKind.Sequential)] - public class SurviveObject - { - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public char[] codename; //3 letters, null-terminated. Currently HMD, WM0, WM1. + public double[] Rot; // Quaternion in the form wxyz } class cfunctions { -//#pragma warning disable IDE1006 // Naming Styles - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_init_internal") ] + //#pragma warning disable IDE1006 // Naming Styles + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_init_internal")] public static extern SurviveContextPtr Survive_init_internal(int argc, string[] args); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_close")] @@ -95,26 +88,32 @@ namespace libsurvive [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_codename")] - public static extern char Survive_object_codename(SurviveObjectPtr so); + public static extern string Survive_object_codename(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_drivername")] - public static extern char Survive_object_drivername(SurviveObject so); + public static extern char Survive_object_drivername(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_charge")] - public static extern byte Survive_object_charge(SurviveObject so); + public static extern byte Survive_object_charge(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_charging")] - public static extern bool Survive_object_charging(SurviveObject so); + public static extern bool Survive_object_charging(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_pose")] - public static extern SurvivePose Survive_object_pose(SurviveObject so); + public static extern SurvivePose Survive_object_pose(SurviveObjectPtr so); + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_sensor_locations")] - public static extern int Survive_object_sensor_locations(SurviveObjectPtr so); + public static extern double[] Survive_object_sensor_locations(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_sensor_normals")] - public static extern int Survive_object_sensor_normals(SurviveObjectPtr so); + public static extern double[] Survive_object_sensor_normals(SurviveObjectPtr so); + + + + [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_get_so_by_name")] + public static extern IntPtr Survive_get_so_by_name(IntPtr ctx, string name); //#pragma warning restore IDE1006 // Naming Styles } -- cgit v1.2.3 From 7770495e7f14fe5094b31df5f5976c34fd68a0da Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 11:48:56 -0600 Subject: Fixed marshalling --- bindings/cs/Demo/Program.cs | 11 ++++------- bindings/cs/libsurvive.net/LibSurViveAPI.cs | 7 +++++-- bindings/cs/libsurvive.net/cfunctions.cs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/Demo/Program.cs b/bindings/cs/Demo/Program.cs index aa98b6c..53c2307 100644 --- a/bindings/cs/Demo/Program.cs +++ b/bindings/cs/Demo/Program.cs @@ -12,13 +12,10 @@ namespace Demo { static void Main(string[] args) { - SurviveContext context = new SurviveContext(args); - context.AddPoseUpdateCallback(HMDUpdate, -1); - - - while (context.Poll() == 0) { - } - + LibSurViveAPI api = LibSurViveAPI.instance; + + var so = api.GetSurviveObjectByName("HMD"); + } public static void HMDUpdate(int ObjectID, Vector3 pos) diff --git a/bindings/cs/libsurvive.net/LibSurViveAPI.cs b/bindings/cs/libsurvive.net/LibSurViveAPI.cs index 48336e8..aa2fdae 100644 --- a/bindings/cs/libsurvive.net/LibSurViveAPI.cs +++ b/bindings/cs/libsurvive.net/LibSurViveAPI.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using libsurvive; using System; using System.Threading; +using System.Runtime.InteropServices; public class LibSurViveAPI { @@ -108,7 +109,7 @@ public class LibSurViveAPI SetupConfigs configs = new SetupConfigs { - playbaskFile = "P:/c/libsurvive-data/lightcap-reformat/lightcap-reformat.log", + playbaskFile = @"C:\Users\justin\source\libsurvive-win-update\bindings\cs\Demo\lightcap-reformat.log", configFile = "survive_conf.json", playbackFactor = 1 }; @@ -320,8 +321,10 @@ public class SurviveObject { throw new Exception("Can't create SurviveObject with 0 pointer"); } + var ptr1 = cfunctions.Survive_object_pose(ptr); + pose = (SurvivePose)Marshal.PtrToStructure(ptr1, typeof(SurvivePose)); - //pose = cfunctions.Survive_object_pose(ptr); + //pose = charge = cfunctions.Survive_object_charge(ptr); charging = cfunctions.Survive_object_charging(ptr); } diff --git a/bindings/cs/libsurvive.net/cfunctions.cs b/bindings/cs/libsurvive.net/cfunctions.cs index ab5f7fd..ce46d18 100644 --- a/bindings/cs/libsurvive.net/cfunctions.cs +++ b/bindings/cs/libsurvive.net/cfunctions.cs @@ -101,7 +101,7 @@ namespace libsurvive public static extern bool Survive_object_charging(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_pose")] - public static extern SurvivePose Survive_object_pose(SurviveObjectPtr so); + public static extern IntPtr Survive_object_pose(SurviveObjectPtr so); [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_object_sensor_locations")] -- cgit v1.2.3 From 4fc4476108f0ad49a4dce99ff2506c3da9b3994a Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Sun, 1 Apr 2018 21:28:19 +0200 Subject: Fixed the parameters --- bindings/cs/libsurvive.net/LibSurViveAPI.cs | 40 +++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/LibSurViveAPI.cs b/bindings/cs/libsurvive.net/LibSurViveAPI.cs index aa2fdae..922a055 100644 --- a/bindings/cs/libsurvive.net/LibSurViveAPI.cs +++ b/bindings/cs/libsurvive.net/LibSurViveAPI.cs @@ -309,24 +309,42 @@ public class LibSurViveAPI public class SurviveObject { - public SurvivePose pose { get; private set; } + private SurvivePose _pose; + public SurvivePose Pose + { + get + { + var ptr1 = cfunctions.Survive_object_pose(ptr); + return (SurvivePose)Marshal.PtrToStructure(ptr1, typeof(SurvivePose)); + } + } - public int charge { get; private set; } - public bool charging { get; private set; } + private int _charge; + public int Charge + { + get + { + return cfunctions.Survive_object_charge(ptr); + } + } + public bool Charging + { + get + { + return cfunctions.Survive_object_charging(ptr); + } + } + IntPtr ptr; + private bool _charging; - public SurviveObject(IntPtr ptr) + public SurviveObject(IntPtr obj_ptr) { - if (ptr == IntPtr.Zero) + if (obj_ptr == IntPtr.Zero) { throw new Exception("Can't create SurviveObject with 0 pointer"); } - var ptr1 = cfunctions.Survive_object_pose(ptr); - pose = (SurvivePose)Marshal.PtrToStructure(ptr1, typeof(SurvivePose)); - - //pose = - charge = cfunctions.Survive_object_charge(ptr); - charging = cfunctions.Survive_object_charging(ptr); + ptr = obj_ptr; } } -- cgit v1.2.3 From cc3931e2b6a94dd7b685331bd965f7f5537622e4 Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Sun, 1 Apr 2018 21:42:51 +0200 Subject: Removed unity specific stuff --- bindings/cs/libsurvive.net/LibSurViveAPI.cs | 226 +++++++++++++-------------- bindings/cs/libsurvive.net/SurviveContext.cs | 38 ++--- bindings/cs/libsurvive.net/cfunctions.cs | 2 +- 3 files changed, 127 insertions(+), 139 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/LibSurViveAPI.cs b/bindings/cs/libsurvive.net/LibSurViveAPI.cs index 922a055..ff6d100 100644 --- a/bindings/cs/libsurvive.net/LibSurViveAPI.cs +++ b/bindings/cs/libsurvive.net/LibSurViveAPI.cs @@ -1,5 +1,4 @@ -//using UnityEngine; -using System.Collections; +using System.Collections; using System.Collections.Generic; using libsurvive; @@ -9,44 +8,8 @@ using System.Runtime.InteropServices; public class LibSurViveAPI { - - public struct SetupConfigs - { - public string playbaskFile; - public int playbackFactor; - public Disambiguator disambiguator; - public Poser poser; - public BoolConfig calibrate; - public string configFile; - } - - public enum Disambiguator - { - StateBased, - Charles, - Turvey, - Default - } - - public enum Poser - { - CharlesSlow, - DaveOrtho, - Dummy, - EPNP, - SBA - } - - public enum BoolConfig - { - Yes, - No, - Default - } - - private static LibSurViveAPI _instance; - public static LibSurViveAPI instance + public static LibSurViveAPI Instance { get { @@ -59,12 +22,32 @@ public class LibSurViveAPI } } + bool running = true; + Thread internalPollTread; + + public IntPtr context; + + light_process_func light_Process_Func; + raw_pose_func raw_Pose_Func; + lighthouse_pose_func lighthouse_Pose_Func; + angle_process_func angle_Process_Func; + button_process_func button_Process_Func; + htc_config_func htc_Config_Func; + imu_process_func imu_Process_Func; + text_feedback_func error_func; + text_feedback_func info_func; + + public delegate void Log(string message); + Log LogInfo; + + public delegate void ErrorLog(string message); + ErrorLog LogError; + LibSurViveAPI() { CreateContext(); CreateTread(); - } ~LibSurViveAPI() @@ -72,40 +55,28 @@ public class LibSurViveAPI running = false; } - Thread internalPollTread; - private void CreateTread() { internalPollTread = new Thread(InternalPoll); internalPollTread.Start(); } - bool running = true; - void InternalPoll() { while (running) { - cfunctions.Survive_poll(context); + int code = Cfunctions.Survive_poll(context); + + if (code != 0) + { + running = false; + } } } - //private SurviveContext _context; - public IntPtr context; - - light_process_func light_Process_Func; - raw_pose_func raw_Pose_Func; - lighthouse_pose_func lighthouse_Pose_Func; - angle_process_func angle_Process_Func; - button_process_func button_Process_Func; - htc_config_func htc_Config_Func; - imu_process_func imu_Process_Func; - text_feedback_func error_func; - text_feedback_func info_func; - internal void CreateContext() { - //Debug.Log("Start Init"); + LogInfo("Start Init"); SetupConfigs configs = new SetupConfigs { @@ -118,7 +89,7 @@ public class LibSurViveAPI //string[] vs = new[] { "--playback", "P:/c/libsurvive-data/lightcap-reformat/lightcap-reformat.log", "--disambiguator", "StateBased", "--calibrate" }; - context = cfunctions.Survive_init_internal(args.Length, args); + context = Cfunctions.Survive_init_internal(args.Length, args); if (context == IntPtr.Zero) { @@ -135,26 +106,24 @@ public class LibSurViveAPI error_func = ErrorEvent; info_func = InfoEvent; - cfunctions.Survive_install_raw_pose_fn(context, raw_Pose_Func); - cfunctions.Survive_install_light_fn(context, light_Process_Func); - cfunctions.Survive_install_lighthouse_pose_fn(context, lighthouse_Pose_Func); - cfunctions.Survive_install_angle_fn(context, angle_Process_Func); - cfunctions.Survive_install_button_fn(context, button_Process_Func); - cfunctions.Survive_install_htc_config_fn(context, htc_Config_Func); - cfunctions.Survive_install_imu_fn(context, imu_Process_Func); - cfunctions.Survive_install_error_fn(context, error_func); - cfunctions.Survive_install_info_fn(context, info_func); - - //Debug.Log("Finished Init"); + Cfunctions.Survive_install_raw_pose_fn(context, raw_Pose_Func); + Cfunctions.Survive_install_light_fn(context, light_Process_Func); + Cfunctions.Survive_install_lighthouse_pose_fn(context, lighthouse_Pose_Func); + Cfunctions.Survive_install_angle_fn(context, angle_Process_Func); + Cfunctions.Survive_install_button_fn(context, button_Process_Func); + Cfunctions.Survive_install_htc_config_fn(context, htc_Config_Func); + Cfunctions.Survive_install_imu_fn(context, imu_Process_Func); + Cfunctions.Survive_install_error_fn(context, error_func); + Cfunctions.Survive_install_info_fn(context, info_func); - //Debug.Log("Start Startup"); + LogInfo("Finished Init"); - //Debug.LogError("ASD"); + LogInfo("Start Startup"); int a = 0; try { - a = cfunctions.Survive_startup(context); + a = Cfunctions.Survive_startup(context); } catch (Exception) { @@ -166,16 +135,17 @@ public class LibSurViveAPI throw new Exception("Error in startup"); } - //Debug.Log("Finished Startup"); + LogInfo("Finished Startup"); } static public string[] CreateStartParameters(SetupConfigs configs) { - List args = new List(); - - args.Add("unity"); + List args = new List + { + "unity" + }; if (configs.playbaskFile != "") { @@ -201,50 +171,48 @@ public class LibSurViveAPI - - virtual protected void InfoEvent(IntPtr ctx, string fault) { - //Debug.Log(fault); + LogInfo(fault); } virtual protected void ErrorEvent(IntPtr ctx, string fault) { - //Debug.LogError(fault); + LogError(fault); } virtual protected void IMUEvent(IntPtr so, int mask, double[] accelgyro, uint timecode, int id) { - cfunctions.Survive_default_imu_process(so, mask, accelgyro, timecode, id); + Cfunctions.Survive_default_imu_process(so, mask, accelgyro, timecode, id); } virtual protected int HTCConfigEvent(IntPtr so, string ct0conf, int len) { - return cfunctions.Survive_default_htc_config_process(so, ct0conf, len); + return Cfunctions.Survive_default_htc_config_process(so, ct0conf, len); } virtual protected void ButtonEvent(IntPtr so, byte eventType, byte buttonId, byte axis1Id, ushort axis1Val, byte axis2Id, ushort axis2Val) { - cfunctions.Survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); + Cfunctions.Survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); } virtual protected void AngleEvent(IntPtr so, int sensor_id, int acode, uint timecode, double length, double angle, uint lh) { - cfunctions.Survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); + Cfunctions.Survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); //Debug.Log("AngleEvent"); } protected void LightHouseEvent(IntPtr ctx, byte lighthouse, SurvivePose lighthouse_pose, SurvivePose object_pose) { - cfunctions.Survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); + Cfunctions.Survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); //Debug.Log("LightHouseEvent"); } virtual protected void LightEvent(IntPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse) { - cfunctions.Survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); + Cfunctions.Survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); //Console.WriteLine("LightEvent"); //Debug.Log("LightEvent"); @@ -252,24 +220,12 @@ public class LibSurViveAPI virtual protected void PoseEvent(IntPtr so, byte lighthouse, SurvivePose pose) { - cfunctions.Survive_default_raw_pose_process(so, lighthouse, pose); + Cfunctions.Survive_default_raw_pose_process(so, lighthouse, pose); - //vaDebug.Log("PoseEvent"); - - //poseUpdate(-1, new Vector3((float)pose.Pos[0], (float)pose.Pos[1], (float)pose.Pos[2]), new Quaternion((float)pose.Rot[0], (float)pose.Rot[1], (float)pose.Rot[2], (float)pose.Rot[3])); - - /* - string a = cfunctions.Survive_object_codename(so); - if (updates.ContainsKey(a)) - { - Vector3 pos = new Vector3((float)pose.Pos[0], (float)pose.Pos[1], (float)pose.Pos[2]); - Quaternion rot = new Quaternion((float)pose.Rot[0], (float)pose.Rot[1], (float)pose.Rot[2], (float)pose.Rot[3]); - updates[a](pos, rot); - } - */ + //Debug.Log("PoseEvent"); } - + /* public delegate void PoseUpdate(SurviveVector3 pos, SurviveQuaternion quat); public Dictionary updates = new Dictionary(); @@ -285,14 +241,9 @@ public class LibSurViveAPI updates[ID] += update; } } - - /* - public void Poll() - { - cfunctions.Survive_poll(context); - } */ + public SurviveObject GetSurviveObjectByName(string name) { if (name == "") @@ -303,10 +254,46 @@ public class LibSurViveAPI if (context == IntPtr.Zero) throw new Exception("The context hasn't been initialsied yet"); - return new SurviveObject( cfunctions.Survive_get_so_by_name(context, name)); + return new SurviveObject( Cfunctions.Survive_get_so_by_name(context, name)); } } + +public struct SetupConfigs +{ + public string playbaskFile; + public int playbackFactor; + public Disambiguator disambiguator; + public Poser poser; + public BoolConfig calibrate; + public string configFile; +} + +public enum Disambiguator +{ + StateBased, + Charles, + Turvey, + Default +} + +public enum Poser +{ + CharlesSlow, + DaveOrtho, + Dummy, + EPNP, + SBA +} + +public enum BoolConfig +{ + Yes, + No, + Default +} + + public class SurviveObject { private SurvivePose _pose; @@ -314,7 +301,7 @@ public class SurviveObject { get { - var ptr1 = cfunctions.Survive_object_pose(ptr); + var ptr1 = Cfunctions.Survive_object_pose(ptr); return (SurvivePose)Marshal.PtrToStructure(ptr1, typeof(SurvivePose)); } } @@ -324,14 +311,14 @@ public class SurviveObject { get { - return cfunctions.Survive_object_charge(ptr); + return Cfunctions.Survive_object_charge(ptr); } } public bool Charging { get { - return cfunctions.Survive_object_charging(ptr); + return Cfunctions.Survive_object_charging(ptr); } } @@ -350,14 +337,15 @@ public class SurviveObject public class SurviveVector3 { - float x; - float y; - float z; + double x; + double y; + double z; } public class SurviveQuaternion { - float x; - float y; - float z; + double x; + double y; + double z; + double w; } diff --git a/bindings/cs/libsurvive.net/SurviveContext.cs b/bindings/cs/libsurvive.net/SurviveContext.cs index 084df31..b1eb711 100644 --- a/bindings/cs/libsurvive.net/SurviveContext.cs +++ b/bindings/cs/libsurvive.net/SurviveContext.cs @@ -16,7 +16,7 @@ namespace libsurvive public void Dispose() { - cfunctions.Survive_close(ctx); + Cfunctions.Survive_close(ctx); ctx = IntPtr.Zero; } @@ -52,7 +52,7 @@ namespace libsurvive newArgs[0] = System.Reflection.Assembly.GetEntryAssembly().FullName; Array.Copy(args, 0, newArgs, 1, args.Length); - ctx = cfunctions.Survive_init_internal(newArgs.Length, newArgs); + ctx = Cfunctions.Survive_init_internal(newArgs.Length, newArgs); if (ctx == IntPtr.Zero) { @@ -69,15 +69,15 @@ namespace libsurvive error_func = ErrorEvent; info_func = InfoEvent; - cfunctions.Survive_install_raw_pose_fn(ctx, raw_Pose_Func); - cfunctions.Survive_install_light_fn(ctx, light_Process_Func); - cfunctions.Survive_install_lighthouse_pose_fn(ctx, lighthouse_Pose_Func); - cfunctions.Survive_install_angle_fn(ctx, angle_Process_Func); - cfunctions.Survive_install_button_fn(ctx, button_Process_Func); - cfunctions.Survive_install_htc_config_fn(ctx, htc_Config_Func); - cfunctions.Survive_install_imu_fn(ctx, imu_Process_Func); - cfunctions.Survive_install_error_fn(ctx, error_func); - cfunctions.Survive_install_info_fn(ctx, info_func); + Cfunctions.Survive_install_raw_pose_fn(ctx, raw_Pose_Func); + Cfunctions.Survive_install_light_fn(ctx, light_Process_Func); + Cfunctions.Survive_install_lighthouse_pose_fn(ctx, lighthouse_Pose_Func); + Cfunctions.Survive_install_angle_fn(ctx, angle_Process_Func); + Cfunctions.Survive_install_button_fn(ctx, button_Process_Func); + Cfunctions.Survive_install_htc_config_fn(ctx, htc_Config_Func); + Cfunctions.Survive_install_imu_fn(ctx, imu_Process_Func); + Cfunctions.Survive_install_error_fn(ctx, error_func); + Cfunctions.Survive_install_info_fn(ctx, info_func); } @@ -104,46 +104,46 @@ namespace libsurvive virtual protected void IMUEvent(SurviveObjectPtr so, int mask, double[] accelgyro, uint timecode, int id) { - cfunctions.Survive_default_imu_process(so, mask, accelgyro, timecode, id); + Cfunctions.Survive_default_imu_process(so, mask, accelgyro, timecode, id); } virtual protected int HTCConfigEvent(SurviveObjectPtr so, string ct0conf, int len) { - return cfunctions.Survive_default_htc_config_process(so, ct0conf, len); + return Cfunctions.Survive_default_htc_config_process(so, ct0conf, len); } virtual protected void ButtonEvent(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, ushort axis1Val, byte axis2Id, ushort axis2Val) { - cfunctions.Survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); + Cfunctions.Survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); } virtual protected void AngleEvent(SurviveObjectPtr so, int sensor_id, int acode, uint timecode, double length, double angle, uint lh) { - cfunctions.Survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); + Cfunctions.Survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); } protected void LightHouseEvent(SurviveObjectPtr ctx, byte lighthouse, SurvivePose lighthouse_pose, SurvivePose object_pose) { - cfunctions.Survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); + Cfunctions.Survive_default_lighthouse_pose_process(ctx, lighthouse, lighthouse_pose, object_pose); } virtual protected void LightEvent(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse) { - cfunctions.Survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); + Cfunctions.Survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); //Console.WriteLine("LightEvent"); } virtual protected void PoseEvent(SurviveObjectPtr so, byte lighthouse, SurvivePose pose) { - cfunctions.Survive_default_raw_pose_process(so, lighthouse, pose); + Cfunctions.Survive_default_raw_pose_process(so, lighthouse, pose); Console.WriteLine("PoseEvent"); } public int Poll() { - return cfunctions.Survive_poll(ctx); + return Cfunctions.Survive_poll(ctx); } } diff --git a/bindings/cs/libsurvive.net/cfunctions.cs b/bindings/cs/libsurvive.net/cfunctions.cs index ce46d18..d003976 100644 --- a/bindings/cs/libsurvive.net/cfunctions.cs +++ b/bindings/cs/libsurvive.net/cfunctions.cs @@ -18,7 +18,7 @@ namespace libsurvive public double[] Rot; // Quaternion in the form wxyz } - class cfunctions + class Cfunctions { //#pragma warning disable IDE1006 // Naming Styles [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall, EntryPoint = "survive_init_internal")] -- cgit v1.2.3 From 09eb4225a93073cce8728032a1af6f6d69138307 Mon Sep 17 00:00:00 2001 From: dpeter99 Date: Sun, 1 Apr 2018 21:58:51 +0200 Subject: Removed the hard coded path --- bindings/cs/libsurvive.net/LibSurViveAPI.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/LibSurViveAPI.cs b/bindings/cs/libsurvive.net/LibSurViveAPI.cs index ff6d100..7e8b73a 100644 --- a/bindings/cs/libsurvive.net/LibSurViveAPI.cs +++ b/bindings/cs/libsurvive.net/LibSurViveAPI.cs @@ -80,9 +80,7 @@ public class LibSurViveAPI SetupConfigs configs = new SetupConfigs { - playbaskFile = @"C:\Users\justin\source\libsurvive-win-update\bindings\cs\Demo\lightcap-reformat.log", - configFile = "survive_conf.json", - playbackFactor = 1 + configFile = "survive_conf.json" }; string[] args = CreateStartParameters(configs); -- cgit v1.2.3 From b449d5228c3c9b3f60e427f7427eb35c1509ca2f Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Mon, 2 Apr 2018 00:14:15 -0600 Subject: Fixed case issue --- bindings/cs/Demo/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/Demo/Program.cs b/bindings/cs/Demo/Program.cs index 53c2307..c838a4e 100644 --- a/bindings/cs/Demo/Program.cs +++ b/bindings/cs/Demo/Program.cs @@ -12,8 +12,8 @@ namespace Demo { static void Main(string[] args) { - LibSurViveAPI api = LibSurViveAPI.instance; - + LibSurViveAPI api = LibSurViveAPI.Instance; + var so = api.GetSurviveObjectByName("HMD"); } -- cgit v1.2.3 From 3f2cd96e959494f296c46ce66d70fda0ca9a41f4 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Mon, 2 Apr 2018 00:21:49 -0600 Subject: Fixed crashes, typo --- bindings/cs/libsurvive.net/LibSurViveAPI.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bindings') diff --git a/bindings/cs/libsurvive.net/LibSurViveAPI.cs b/bindings/cs/libsurvive.net/LibSurViveAPI.cs index 7e8b73a..1fb8cae 100644 --- a/bindings/cs/libsurvive.net/LibSurViveAPI.cs +++ b/bindings/cs/libsurvive.net/LibSurViveAPI.cs @@ -38,10 +38,10 @@ public class LibSurViveAPI text_feedback_func info_func; public delegate void Log(string message); - Log LogInfo; + Log LogInfo = delegate { }; public delegate void ErrorLog(string message); - ErrorLog LogError; + ErrorLog LogError = delegate { }; LibSurViveAPI() { @@ -145,9 +145,9 @@ public class LibSurViveAPI "unity" }; - if (configs.playbaskFile != "") + if (configs.playbackFile != "" && configs.playbackFile != null) { - args.AddRange(new[] { "--playback", configs.playbaskFile }); + args.AddRange(new[] { "--playback", configs.playbackFile }); args.AddRange(new[] { "--playback-factor", configs.playbackFactor.ToString() }); } @@ -259,7 +259,7 @@ public class LibSurViveAPI public struct SetupConfigs { - public string playbaskFile; + public string playbackFile; public int playbackFactor; public Disambiguator disambiguator; public Poser poser; -- cgit v1.2.3