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 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 37 deletions(-) (limited to 'bindings/cs/Demo') 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) { - } } -- cgit v1.3.1 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 +- include/libsurvive/survive.h | 4 ++-- src/survive.c | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'bindings/cs/Demo') 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")] diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 8a4183e..b829a52 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -122,8 +122,8 @@ struct SurviveObject { SURVIVE_EXPORT const char *survive_object_codename(SurviveObject *so); SURVIVE_EXPORT const char *survive_object_drivername(SurviveObject *so); -SURVIVE_EXPORT const int8_t *survive_object_charge(SurviveObject *so); -SURVIVE_EXPORT const bool *survive_object_charging(SurviveObject *so); +SURVIVE_EXPORT const int8_t survive_object_charge(SurviveObject *so); +SURVIVE_EXPORT const bool survive_object_charging(SurviveObject *so); SURVIVE_EXPORT const SurvivePose *survive_object_pose(SurviveObject *so); diff --git a/src/survive.c b/src/survive.c index e4015de..f74de85 100644 --- a/src/survive.c +++ b/src/survive.c @@ -567,8 +567,8 @@ int survive_simple_inflate(struct SurviveContext *ctx, const char *input, int in const char *survive_object_codename(SurviveObject *so) { return so->codename; } const char *survive_object_drivername(SurviveObject *so) { return so->drivername; } -const int8_t *survive_object_charge(SurviveObject *so) { return so->charge; } -const bool *survive_object_charging(SurviveObject *so) { return so->charging; } +const int8_t survive_object_charge(SurviveObject *so) { return so->charge; } +const bool survive_object_charging(SurviveObject *so) { return so->charging; } const SurvivePose *survive_object_pose(SurviveObject *so) { return &so->OutPose; } -- cgit v1.3.1 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/cs/Demo') 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.3.1