using Assets.NXR.Scripts.Slam; using UnityEngine; public class NxrSensor { private static object syncRoot = new object(); private static NxrSensor _instance = null; public static NxrSensor Instance { get { if (_instance == null) { lock (syncRoot) { if (_instance == null) { _instance = new NxrSensor(); } } } return _instance; } } private AndroidJavaClass nxrSensorClass; private AndroidJavaObject nxrSensorInstance; private AndroidJavaClass nxrSensorProClass; private AndroidJavaObject nxrSensorProInstance; private AndroidJavaClass xvGestureTypeClass; private AndroidJavaClass rawDataTypeClass; private AndroidJavaClass rgbResolutionClass; private AndroidJavaClass tofFPSClass; private AndroidJavaClass tofStreamModeClass; private AndroidJavaClass distanceModeClass; private AndroidJavaClass thermalModeClass; private AndroidJavaClass planeTypeClass; private AndroidJavaClass xvLogLevelClass; public NxrSensor() { #if UNITY_ANDROID if (nxrSensorClass == null) { nxrSensorClass = new AndroidJavaClass("ruiyue.nxrsensor.library.NxrXvLibrary"); } if (nxrSensorClass != null && nxrSensorInstance == null) { nxrSensorInstance = nxrSensorClass.CallStatic("getInstance"); } if (nxrSensorProClass == null) { nxrSensorProClass = new AndroidJavaClass("com.nibiru.nxrsensor.NxrSensor"); } if (nxrSensorProClass != null && nxrSensorProInstance == null) { nxrSensorProInstance = nxrSensorProClass.CallStatic("getInstance"); } #endif } public AndroidJavaObject NxrSensorInstance { get { return nxrSensorInstance; } } public bool InitLibrary() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("initLibrary"); } return false; } public void UninitLibrary() { if (nxrSensorInstance != null) { nxrSensorInstance.Call("uninitLibrary"); } } #region Slam public enum PlaneType { NONE, TOF, STEREO } public enum SlamMode { Edge, Mixed, EdgeFusionOnHost, NONE } public NxrTrackingData GetTrackingDataAt(long paramLong) { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("getTrackingDataAt", paramLong); if (javaObject != null) { return new NxrTrackingData(javaObject); } } return null; } public class NxrTrackingData { public float[] rotation; public float[] translation; public float[] prediction_coff_s; public float[] prediction_coff_b; public float[] prediction_coff_bdt; public float[] prediction_coff_bdt2; public long fetchTimestamp; public long timestamp; public int source; public int black; public int rotateY; private AndroidJavaObject androidJavaObject; public NxrTrackingData() { } public NxrTrackingData(AndroidJavaObject javaObject) { androidJavaObject = javaObject; rotation = javaObject.Get("rotation"); rotation[2] *= -1; translation = javaObject.Get("translation"); translation[2] *= -1; prediction_coff_s = javaObject.Get("prediction_coff_s"); prediction_coff_b = javaObject.Get("prediction_coff_b"); prediction_coff_bdt = javaObject.Get("prediction_coff_bdt"); prediction_coff_bdt2 = javaObject.Get("prediction_coff_bdt2"); fetchTimestamp = javaObject.Get("fetchTimestamp"); timestamp = javaObject.Get("timestamp"); source = javaObject.Get("source"); black = javaObject.Get("black"); rotateY = javaObject.Get("rotateY"); } public string toString() { if (androidJavaObject != null) { return androidJavaObject.Call("toString"); } return ""; } } public void RegisterPoseCallback() { if (nxrSensorInstance != null) { nxrSensorInstance.Call("registerPoseCallback", new OnPoseListener()); } } public delegate void PoseCallback(NxrTrackingData nxrTrackingData); public PoseCallback PoseEvent; public class OnPoseListener : AndroidJavaProxy { public OnPoseListener() : base("ruiyue.nxrsensor.library.listener.OnPoseListener") { } public void onPose(AndroidJavaObject paramNxrTrackingData) { if (paramNxrTrackingData != null) { var nxrTrackingData = new NxrTrackingData(paramNxrTrackingData); if (Instance.PoseEvent != null) { Instance.PoseEvent(nxrTrackingData); } } else { Debug.LogError("AndroidJavaObject paramNxrTrackingData is null !!!"); } } } public bool StartPlaneDetection(PlaneType type) { if (nxrSensorInstance != null) { Debug.Log("StartPlaneDetection:[type=" + type + "]"); if (planeTypeClass != null) { planeTypeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.PlaneType"); } var typeObj = planeTypeClass.CallStatic("valueOf", type.ToString()); return nxrSensorInstance.Call("startPlaneDetection", typeObj, new OnPlaneDetectionListener()); } return false; } public bool StopPlaneDetection(int type) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("stopPlaneDetection", type); } return false; } public class NxrPlaneData { public long hostTimestamp = 0L; public long deviceTimestamp = 0L; public NxrPointD[] points; public NxrPointD normal = new NxrPointD(); public int size; public int id = -1; public NxrPlaneData(AndroidJavaObject javaObject) { hostTimestamp = javaObject.Get("hostTimestamp"); deviceTimestamp = javaObject.Get("deviceTimestamp"); var pointsObj = javaObject.Get("points"); if (pointsObj != null) { if (pointsObj.GetRawObject().ToInt32() != 0) { var pointsObjArray = AndroidJNIHelper.ConvertFromJNIArray(pointsObj.GetRawObject()); points = new NxrPointD[pointsObjArray.Length]; for (var i = 0; i < points.Length; i++) { var point = new NxrPointD(); point.x = pointsObjArray[i].Get("x"); point.y = pointsObjArray[i].Get("y"); point.z = pointsObjArray[i].Get("z"); points[i] = point; pointsObjArray[i].Dispose(); } } pointsObj.Dispose(); } var normalObj = javaObject.Get("normal"); if (normalObj != null) { normal.x = normalObj.Get("x"); normal.y = normalObj.Get("y"); normal.z = normalObj.Get("z"); normalObj.Dispose(); } size = javaObject.Get("size"); id = javaObject.Get("id"); } } public class NxrPointD { public double x; public double y; public double z; } public delegate void PlaneDetectedCallback(NxrPlaneData nxrPlaneData); public PlaneDetectedCallback PlaneDetectedEvent; public class OnPlaneDetectionListener : AndroidJavaProxy { public OnPlaneDetectionListener() : base("ruiyue.nxrsensor.library.listener.OnPlaneDetectionListener") { } public void onPlaneDetected(AndroidJavaObject paramNxrPlaneData) { if (paramNxrPlaneData != null) { var nxrPlaneData = new NxrPlaneData(paramNxrPlaneData); if (Instance.PlaneDetectedEvent != null) { Instance.PlaneDetectedEvent(nxrPlaneData); } } else { Debug.LogError("AndroidJavaObject paramNxrPlaneData is null !!!"); } } } public int RegisterMapCallback() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("registerMapCallback", new OnMapV2Listener()); } return -1; } public bool UnregisterMapCallback(int callbackId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("unregisterMapCallback", callbackId); } return false; } public delegate void MapV2Callback(NxrPointD[] nxrPointDs); public MapV2Callback MapV2Event; public class OnMapV2Listener : AndroidJavaProxy { public OnMapV2Listener() : base("ruiyue.nxrsensor.library.listener.OnMapV2Listener") { } public void onMapV2(AndroidJavaObject paramArrayOfNxrPointD) { if (paramArrayOfNxrPointD != null) { if (paramArrayOfNxrPointD.GetRawObject().ToInt32() != 0) { var nxrPointDArray = AndroidJNIHelper.ConvertFromJNIArray(paramArrayOfNxrPointD.GetRawObject()); var points = new NxrPointD[nxrPointDArray.Length]; for (var i = 0; i < points.Length; i++) { var point = new NxrPointD(); point.x = nxrPointDArray[i].Get("x"); point.y = nxrPointDArray[i].Get("y"); point.z = nxrPointDArray[i].Get("z"); points[i] = point; nxrPointDArray[i].Dispose(); } if (Instance.MapV2Event != null) { Instance.MapV2Event(points); } } } else { Debug.LogError("AndroidJavaObject paramArrayOfNxrPointD is null !!!"); } } } public bool LoadMapAndSwitchToCslam(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("loadMapAndSwitchToCslam", path, new OnMapListener()); } return false; } public bool SaveMapAndSwitchToCslam(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("saveMapAndSwitchToCslam", path, new OnMapListener()); } return false; } public delegate void MapPercentCallback(float paramFloat); public delegate void MapStatusAndQualityCallback(int paramInt1, int paramInt2); public MapPercentCallback MapPercentEvent; public MapStatusAndQualityCallback MapStatusAndQualityEvent; public class OnMapListener : AndroidJavaProxy { public OnMapListener() : base("ruiyue.nxrsensor.library.listener.OnMapListener") { } public void onMapPercent(float paramFloat) { if (Instance.MapPercentEvent != null) { Instance.MapPercentEvent(paramFloat); } } public void onMapStatusAndQuality(int paramInt1, int paramInt2) { if (Instance.MapStatusAndQualityEvent != null) { Instance.MapStatusAndQualityEvent(paramInt1, paramInt2); } } } public SlamMode GetSlamMode() { if (nxrSensorInstance != null) { var slamModeObj = nxrSensorInstance.Call("getSlamMode"); if (slamModeObj != null) { return (SlamMode) slamModeObj.Call("ordinal"); } } return SlamMode.NONE; } #endregion #region Gesture public enum XvGestureType { NONE, NORMAL, DYNAMIC_OR_SLAM } public bool StartGesture(XvGestureType type) { if (nxrSensorInstance != null) { if (xvGestureTypeClass == null) { xvGestureTypeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.XvGestureType"); } var typeObj = xvGestureTypeClass.CallStatic("valueOf", type.ToString()); return nxrSensorInstance.Call("startGesture", typeObj, new OnGestureListener()); } return false; } public bool StopGesture(int type) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("stopGesture", type); } return false; } public class NxrGesture { public int size; public int[] gesture; public float distance; public float confidence; public NxrPointF[] position; public NxrPointF[] slamPosition; public long dataFetchTimeMs; public long dataTimeStampMs; public NxrGesture(AndroidJavaObject javaObject) { size = javaObject.Get("size"); gesture = javaObject.Get("gesture"); distance = javaObject.Get("distance"); confidence = javaObject.Get("confidence"); var positionObj = javaObject.Get("position"); if (positionObj != null) { if (positionObj.GetRawObject().ToInt32() != 0) { var positionObjArray = AndroidJNIHelper.ConvertFromJNIArray(positionObj.GetRawObject()); position = new NxrPointF[positionObjArray.Length]; for (var i = 0; i < position.Length; i++) { var tempPosition = new NxrPointF(); tempPosition.x = positionObjArray[i].Get("x"); tempPosition.y = positionObjArray[i].Get("y"); tempPosition.z = positionObjArray[i].Get("z"); position[i] = tempPosition; positionObjArray[i].Dispose(); } } positionObj.Dispose(); } var slamPositionObj = javaObject.Get("slamPosition"); if (slamPositionObj != null) { if (slamPositionObj.GetRawObject().ToInt32() != 0) { var slamPositionObjArray = AndroidJNIHelper.ConvertFromJNIArray(slamPositionObj.GetRawObject()); slamPosition = new NxrPointF[slamPositionObjArray.Length]; for (var i = 0; i < slamPosition.Length; i++) { var tempSlamPosition = new NxrPointF(); tempSlamPosition.x = slamPositionObjArray[i].Get("x"); tempSlamPosition.y = slamPositionObjArray[i].Get("y"); tempSlamPosition.z = slamPositionObjArray[i].Get("z"); slamPosition[i] = tempSlamPosition; slamPositionObjArray[i].Dispose(); } } slamPositionObj.Dispose(); } dataFetchTimeMs = javaObject.Get("dataFetchTimeMs"); dataTimeStampMs = javaObject.Get("dataTimeStampMs"); } } public class NxrPointF { public float x; public float y; public float z; } public delegate void GestureCallback(NxrGesture nxrGesture); public GestureCallback GestureEvent; public class OnGestureListener : AndroidJavaProxy { public OnGestureListener() : base("ruiyue.nxrsensor.library.listener.OnGestureListener") { } public void onGesture(AndroidJavaObject paramNxrGesture) { if (paramNxrGesture != null) { var nxrGesture = new NxrGesture(paramNxrGesture); if (Instance.GestureEvent != null) { Instance.GestureEvent(nxrGesture); } } else { Debug.LogError("AndroidJavaObject paramNxrGesture is null !!!"); } } } public bool StartSkeleton(XvGestureType type) { if (nxrSensorInstance != null) { var isStartSlam = nxrSensorInstance.Call("startSlam"); if (isStartSlam) { if (xvGestureTypeClass == null) { xvGestureTypeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.XvGestureType"); } var typeObj = xvGestureTypeClass.CallStatic("valueOf", type.ToString()); return nxrSensorInstance.Call("startSkeleton", typeObj, new OnSkeletonListener()); } } return false; } public bool StopSkeleton(int type) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("stopSkeleton", type); } return false; } public class NxrSkeleton { public int size; public NxrPointF[][] joints; public long dataFetchTimeMS; public long dataTimeStampMs; public NxrPointF[] joints0; public NxrPointF[] joints1; public NxrSkeleton(AndroidJavaObject javaObject) { size = javaObject.Get("size"); dataFetchTimeMS = javaObject.Get("dataFetchTimeMS"); dataTimeStampMs = javaObject.Get("dataTimeStampMs"); var joints0Array = javaObject.Get("joints0"); var joints1Array = javaObject.Get("joints1"); joints0 = new NxrPointF[joints0Array.Length]; joints1 = new NxrPointF[joints1Array.Length]; for (var i = 0; i < joints0.Length; i++) { var joint0 = new NxrPointF(); joint0.x = joints0Array[i].Get("x"); joint0.y = joints0Array[i].Get("y"); joint0.z = joints0Array[i].Get("z"); var joint1 = new NxrPointF(); joint1.x = joints1Array[i].Get("x"); joint1.y = joints1Array[i].Get("y"); joint1.z = joints1Array[i].Get("z"); joints0[i] = joint0; joints1[i] = joint1; joints0Array[i].Dispose(); joints1Array[i].Dispose(); } joints = new NxrPointF[2][]; joints[0] = joints0; joints[1] = joints1; } } public delegate void SkeletonCallback(NxrSkeleton nxrSkeleton); public SkeletonCallback SkeletonEvent; public class OnSkeletonListener : AndroidJavaProxy { public OnSkeletonListener() : base("ruiyue.nxrsensor.library.listener.OnSkeletonListener") { } public void onSkeleton(AndroidJavaObject paramNxrSkeleton) { if (paramNxrSkeleton != null) { var nxrSkeleton = new NxrSkeleton(paramNxrSkeleton); if (Instance.SkeletonEvent != null) { Instance.SkeletonEvent(nxrSkeleton); } } else { Debug.LogError("AndroidJavaObject paramNxrSkeleton is null !!!"); } } } public void SetConfigPath(string path) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setConfigPath", path); } } #endregion #region Apriltag public string StartTagDetector(string tagFamliy, double size, double refreshRate) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("startTagDetector", tagFamliy, size, refreshRate); } return null; } public bool StopTagDetector(string detectorId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("stopTagDetector", detectorId); } return false; } public TagDetection[] GetTagDetections(string detectorId) { if (nxrSensorInstance != null) { var tagDetectionsObj = nxrSensorInstance.Call("getTagDetections", detectorId); if (tagDetectionsObj != null) { var tagDetectionsArray = AndroidJNIHelper.ConvertFromJNIArray(tagDetectionsObj.GetRawObject()); var tagDetections = new TagDetection[tagDetectionsArray.Length]; for (var i = 0; i < tagDetections.Length; i++) { tagDetections[i] = new TagDetection(tagDetectionsArray[i]); tagDetectionsArray[i].Dispose(); } tagDetectionsObj.Dispose(); return tagDetections; } } return null; } public TagDetection[] DetectTags(string tagFamliy, double size) { if (nxrSensorInstance != null) { var tagDetectionsObj = nxrSensorInstance.Call("detectTags", tagFamliy, size); if (tagDetectionsObj != null) { var tagDetectionsArray = AndroidJNIHelper.ConvertFromJNIArray(tagDetectionsObj.GetRawObject()); var tagDetections = new TagDetection[tagDetectionsArray.Length]; for (var i = 0; i < tagDetections.Length; i++) { tagDetections[i] = new TagDetection(tagDetectionsArray[i]); tagDetectionsArray[i].Dispose(); } tagDetectionsObj.Dispose(); return tagDetections; } } return null; } public class TagDetection { public int id; public float[] quaternion; public float[] translation; public float[] rotation; public TagDetection(AndroidJavaObject javaObject) { id = javaObject.Get("id"); quaternion = javaObject.Get("quaternion"); quaternion[2] *= -1; translation = javaObject.Get("translation"); translation[2] *= -1; rotation = javaObject.Get("rotation"); } } public void SetTagsMap(string tagFamliy, double tagSize, int[] tagIds, NxrTrackingData[] transforms) { if (nxrSensorProInstance != null && transforms != null) { var nxrTrackingDataSize = transforms.Length; var rotation_size = new int[nxrTrackingDataSize]; var translation_size = new int[nxrTrackingDataSize]; var prediction_coff_s_size = new int[nxrTrackingDataSize]; var prediction_coff_b_size = new int[nxrTrackingDataSize]; var prediction_coff_bdt_size = new int[nxrTrackingDataSize]; var prediction_coff_bdt2_size = new int[nxrTrackingDataSize]; var rotation_count = 0; var translation_count = 0; var prediction_coff_s_count = 0; var prediction_coff_b_count = 0; var prediction_coff_bdt_count = 0; var prediction_coff_bdt2_count = 0; var fetchTimestamp = new long[nxrTrackingDataSize]; var timestamp = new long[nxrTrackingDataSize]; var source = new int[nxrTrackingDataSize]; var black = new int[nxrTrackingDataSize]; var rotateY = new int[nxrTrackingDataSize]; for (var i = 0; i < nxrTrackingDataSize; i++) { rotation_size[i] = transforms[i].rotation.Length; translation_size[i] = transforms[i].translation.Length; prediction_coff_s_size[i] = transforms[i].prediction_coff_s.Length; prediction_coff_b_size[i] = transforms[i].prediction_coff_b.Length; prediction_coff_bdt_size[i] = transforms[i].prediction_coff_bdt.Length; prediction_coff_bdt2_size[i] = transforms[i].prediction_coff_bdt2.Length; rotation_count += rotation_size[i]; translation_count += translation_size[i]; prediction_coff_s_count += prediction_coff_s_size[i]; prediction_coff_b_count += prediction_coff_b_size[i]; prediction_coff_bdt_count += prediction_coff_bdt_size[i]; prediction_coff_bdt2_count += prediction_coff_bdt2_size[i]; fetchTimestamp[i] = transforms[i].fetchTimestamp; timestamp[i] = transforms[i].timestamp; source[i] = transforms[i].source; black[i] = transforms[i].black; rotateY[i] = transforms[i].rotateY; } var rotation = new float[rotation_count]; var translation = new float[translation_count]; var prediction_coff_s = new float[prediction_coff_s_count]; var prediction_coff_b = new float[prediction_coff_b_count]; var prediction_coff_bdt = new float[prediction_coff_bdt_count]; var prediction_coff_bdt2 = new float[prediction_coff_bdt2_count]; var count = 0; for (var i = 0; i < nxrTrackingDataSize; i++) { for (int j = 0; j < rotation_size[i]; j++) { rotation[count] = transforms[i].rotation[j]; count++; } } count = 0; for (var i = 0; i < nxrTrackingDataSize; i++) { for (int j = 0; j < translation_size[i]; j++) { translation[count] = transforms[i].translation[j]; count++; } } count = 0; for (var i = 0; i < nxrTrackingDataSize; i++) { for (int j = 0; j < prediction_coff_s_size[i]; j++) { prediction_coff_s[count] = transforms[i].prediction_coff_s[j]; count++; } } count = 0; for (var i = 0; i < nxrTrackingDataSize; i++) { for (int j = 0; j < prediction_coff_b_size[i]; j++) { prediction_coff_b[count] = transforms[i].prediction_coff_b[j]; count++; } } count = 0; for (var i = 0; i < nxrTrackingDataSize; i++) { for (int j = 0; j < prediction_coff_bdt_size[i]; j++) { prediction_coff_bdt[count] = transforms[i].prediction_coff_bdt[j]; count++; } } count = 0; for (var i = 0; i < nxrTrackingDataSize; i++) { for (int j = 0; j < prediction_coff_bdt2_size[i]; j++) { prediction_coff_bdt2[count] = transforms[i].prediction_coff_bdt2[j]; count++; } } nxrSensorProInstance.Call("setTagsMap", tagFamliy, tagSize, tagIds, nxrTrackingDataSize, rotation_size, translation_size, prediction_coff_s_size, prediction_coff_b_size, prediction_coff_bdt_size, prediction_coff_bdt2_size, rotation, translation, prediction_coff_s, prediction_coff_b, prediction_coff_bdt, prediction_coff_bdt2, fetchTimestamp, timestamp, source, black, rotateY); } } public NxrTrackingData GetTrackingDataInTagsMap(double prediction) { if (nxrSensorInstance != null) { var nxrTrackingDataObj = nxrSensorInstance.Call("getTrackingDataInTagsMap", prediction); if (nxrTrackingDataObj != null) { return new NxrTrackingData(nxrTrackingDataObj); } } return null; } #endregion #region Display public DisplayCalibration ReadDisplayCalibrations() { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("readDisplayCalibrations"); if (javaObject != null) { return new DisplayCalibration(javaObject); } } return null; } public class DisplayCalibration { public float[][] K; public float[][] rotation; public float[][] translation; public float[] K0; public float[] K1; public float[] rotation0; public float[] rotation1; public float[] translation0; public float[] translation1; public DisplayCalibration(AndroidJavaObject javaObject) { K0 = javaObject.Get("K0"); K1 = javaObject.Get("K1"); rotation0 = javaObject.Get("rotation0"); rotation1 = javaObject.Get("rotation1"); translation0 = javaObject.Get("translation0"); translation1 = javaObject.Get("translation1"); K = new float[2][]; K[0] = K0; K[1] = K1; rotation = new float[2][]; rotation[0] = rotation0; rotation[1] = rotation1; translation = new float[2][]; translation[0] = translation0; translation[1] = translation1; } } public void SetDisplayBrightnessLevel(int level) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setDisplayBrightnessLevel", level); } } public bool DisplayOpen() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("displayOpen"); } return false; } public bool DisplayClose() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("displayClose"); } return false; } #endregion #region Rgb public bool StartStreaming(NxrSlam.RawDataType type) { if (nxrSensorInstance != null) { if (rawDataTypeClass == null) { rawDataTypeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.RawDataType"); } var typeObj = rawDataTypeClass.CallStatic("valueOf", type.ToString()); return nxrSensorInstance.Call("startStreaming", typeObj, new OnStreamDataListener()); } return false; } public bool StopStreaming(NxrSlam.RawDataType type) { if (nxrSensorInstance != null) { if (rawDataTypeClass == null) { rawDataTypeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.RawDataType"); } var typeObj = rawDataTypeClass.CallStatic("valueOf", type.ToString()); return nxrSensorInstance.Call("stopStreaming", typeObj); } return false; } public class NxrStreamData { public byte[] data; public byte[] left; public byte[] right; public int type; public int format; public int width; public int height; public int size; public int leftSize; public int rightSize; public long timestamp; public NxrStreamData() { } public NxrStreamData(AndroidJavaObject javaObject) { data = javaObject.Get("data"); left = javaObject.Get("left"); right = javaObject.Get("right"); type = javaObject.Get("type"); format = javaObject.Get("format"); width = javaObject.Get("width"); height = javaObject.Get("height"); size = javaObject.Get("size"); leftSize = javaObject.Get("leftSize"); rightSize = javaObject.Get("rightSize"); timestamp = javaObject.Get("timestamp"); } } public delegate void StreamDataCallback(NxrSlam.RawDataType paramRawDataType, NxrStreamData paramNxrStreamData); public StreamDataCallback StreamDataEvent; public class OnStreamDataListener : AndroidJavaProxy { public OnStreamDataListener() : base("ruiyue.nxrsensor.library.listener.OnStreamDataListener") { } public void onStreamData(AndroidJavaObject paramRawDataType, AndroidJavaObject paramNxrStreamData) { if (paramNxrStreamData != null) { var rawDataType = (NxrSlam.RawDataType) paramRawDataType.Call("ordinal"); var nxrStreamData = new NxrStreamData(paramNxrStreamData); if (Instance.StreamDataEvent != null) { Instance.StreamDataEvent(rawDataType, nxrStreamData); } } } } public RgbCalibration ReadRgbCalibrations() { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("readRgbCalibrations"); if (javaObject != null) { return new RgbCalibration(javaObject); } } return null; } public class RgbCalibration { public float[][] K; public float[] rotation; public float[] translation; public float[] K0; public float[] K1; public float[] K2; public RgbCalibration(AndroidJavaObject javaObject) { rotation = javaObject.Get("rotation"); translation = javaObject.Get("translation"); K0 = javaObject.Get("K0"); K1 = javaObject.Get("K1"); K2 = javaObject.Get("K2"); K = new float[3][]; K[0] = K0; K[1] = K1; K[2] = K2; } } public void SetRgbResolution(NxrSlam.RgbResolution r) { if (nxrSensorInstance != null) { if (rgbResolutionClass == null) { rgbResolutionClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.RgbResolution"); } var rObj = rgbResolutionClass.CallStatic("valueOf", r.ToString()); nxrSensorInstance.Call("setRgbResolution", rObj); } } public void SetRgbExposure(int aecMode, int exposureGain, int exposureTimeMs) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setRgbExposure", aecMode, exposureGain, exposureTimeMs); } } public void SetRgbBrightnessLevel(int level) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setRgbBrightnessLevel", level); } } #endregion #region Tof public enum TofFPS { TOF_FPS_5, TOF_FPS_10, TOF_FPS_15, TOF_FPS_20, TOF_FPS_25, TOF_FPS_30 } public enum TofStreamMode { ONLY_DEPTH, ONLY_CLOUD, DEPTH_CLOUD, NONE, CLOUD_ON_LEFTHAND_SLAM } public enum DistanceMode { SHORT, MIDDLE, LONG } public int RegisterColorDepthImageCallback() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("registerColorDepthImageCallback", new OnStreamDataV3Listener()); } return -1; } public bool UnregisterColorDepthImageCallback(int callbackId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("unregisterColorDepthImageCallback", callbackId); } return false; } public delegate void StreamDataV3ListenerCallback(NxrStreamData paramNxrStreamData); public StreamDataV3ListenerCallback StreamDataV3ListenerEvent; public class OnStreamDataV3Listener : AndroidJavaProxy { public OnStreamDataV3Listener() : base("ruiyue.nxrsensor.library.listener.OnStreamDataV3Listener") { } public void onStreamDataV3(AndroidJavaObject paramNxrStreamData) { if (paramNxrStreamData != null) { var nxrStreamData = new NxrStreamData(paramNxrStreamData); if (Instance.StreamDataV3ListenerEvent != null) { Instance.StreamDataV3ListenerEvent(nxrStreamData); } } } } public TofCalibration ReadTofCalibration() { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("readTofCalibration"); if (javaObject != null) { return new TofCalibration(javaObject); } } return null; } public class TofCalibration { public float[] K; public float[] rotation; public float[] translation; public TofCalibration(AndroidJavaObject javaObject) { K = javaObject.Get("K"); rotation = javaObject.Get("rotation"); translation = javaObject.Get("translation"); } } public void SetTofExposure(int aecMode, int exposureGain, int exposureTimeMs) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setTofExposure", aecMode, exposureGain, exposureTimeMs); } } public void SetTofBrightnessLevel(int level) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setTofBrightnessLevel", level); } } public void SetTofFrameRate(TofFPS fps) { if (nxrSensorInstance != null) { if (tofFPSClass == null) { tofFPSClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.TofFPS"); } var fpsObj = tofFPSClass.CallStatic("valueOf", fps.ToString()); nxrSensorInstance.Call("setTofFrameRate", fpsObj); } } public void SetTofResolution(int resolution) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setTofResolution", resolution); } } public NxrPointCloud DepthImageToPointCloud(NxrStreamData stream) { if (nxrSensorProInstance != null && stream != null) { var data = stream.data; var left = stream.left; var right = stream.right; var type = stream.type; var format = stream.format; var width = stream.width; var height = stream.height; var size = stream.size; var leftSize = stream.leftSize; var rightSize = stream.rightSize; var timestamp = stream.timestamp; var javaObject = nxrSensorProInstance.Call("depthImageToPointCloud", data, left, right, type, format, width, height, size, leftSize, rightSize, timestamp); if (javaObject != null) { return new NxrPointCloud(javaObject); } } return null; } public class NxrPointCloud { public long dataFetchTimeMs; public long dataTimeStampMs; public NxrPointF[] points; public NxrPointCloud(AndroidJavaObject javaObject) { dataFetchTimeMs = javaObject.Get("dataFetchTimeMs"); dataTimeStampMs = javaObject.Get("dataTimeStampMs"); var pointsArray = javaObject.Get("points"); points = new NxrPointF[pointsArray.Length]; for (var i = 0; i < points.Length; i++) { var nxrPointF = new NxrPointF(); nxrPointF.x = pointsArray[i].Get("x"); nxrPointF.y = pointsArray[i].Get("y"); nxrPointF.z = pointsArray[i].Get("z"); points[i] = nxrPointF; pointsArray[i].Dispose(); } } } public void SetTofStreamMode(TofStreamMode mode) { if (nxrSensorInstance != null) { if (tofStreamModeClass == null) { tofStreamModeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.TofStreamMode"); } var modeObj = tofStreamModeClass.CallStatic("valueOf", mode.ToString()); nxrSensorInstance.Call("setTofStreamMode", modeObj); } } public void SetTofDistanceMode(DistanceMode mode) { if (nxrSensorInstance != null) { if (distanceModeClass == null) { distanceModeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.DistanceMode"); } var modeObj = distanceModeClass.CallStatic("valueOf", mode.ToString()); nxrSensorInstance.Call("setTofDistanceMode", modeObj); } } public void SetTofMode(int mode) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setTofMode", mode); } } #endregion #region FishEye public FishEyeCalibration ReadStereoFisheyesCalibrations(int type) { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("readStereoFisheyesCalibrations", type); return new FishEyeCalibration(javaObject); } return null; } public FishEyeCalibration ReadStereoFisheyesPDMCalibrations(int type) { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("readStereoFisheyesPDMCalibrations", type); return new FishEyeCalibration(javaObject); } return null; } public class FishEyeCalibration { public float[][] K; public float[][] rotation; public float[][] translation; public int imu_fisheye_shift_us; public float delta; public float[] K0; public float[] K1; public float[] rotation0; public float[] rotation1; public float[] translation0; public float[] translation1; public FishEyeCalibration(AndroidJavaObject javaObject) { imu_fisheye_shift_us = javaObject.Get("imu_fisheye_shift_us"); delta = javaObject.Get("delta"); K0 = javaObject.Get("K0"); K1 = javaObject.Get("K1"); rotation0 = javaObject.Get("rotation0"); rotation1 = javaObject.Get("rotation1"); translation0 = javaObject.Get("translation0"); translation1 = javaObject.Get("translation1"); K = new float[2][]; K[0] = K0; K[1] = K1; rotation = new float[2][]; rotation[0] = rotation0; rotation[1] = rotation1; translation = new float[2][]; translation[0] = translation0; translation[1] = translation1; } } public void SetFishEyeExposure(int aecMode, int exposureGain, int exposureTimeMs) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setFishEyeExposure", aecMode, exposureGain, exposureTimeMs); } } public void SetFishEyeBrightnessLevel(int level) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setFishEyeBrightnessLevel", level); } } #endregion #region Eyetracking public void SetEyeTrackingExposure(int leftGain, int leftTimeMs, int rightGain, int rightTimeMs) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setEyeTrackingExposure", leftGain, leftTimeMs, rightGain, rightTimeMs); } } public void SetEyeTrackingLedBrightness(int eye, int led, int brightness) { if (nxrSensorInstance != null) { nxrSensorInstance.Call("setEyeTrackingLedBrightness", eye, led, brightness); } } #endregion #region 3dof public NxrTrackingData Get3dof(double prediction) { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("get3dof", prediction); return new NxrTrackingData(javaObject); } return null; } public NxrTrackingData Get3dofAt(double timestamp) { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("get3dofAt", timestamp); return new NxrTrackingData(javaObject); } return null; } public void RegisterOrientationCallback() { if (nxrSensorInstance != null) { nxrSensorInstance.Call("registerOrientationCallback", new OnOrientationListener()); } } public delegate void OrientationCallback(NxrTrackingData paramNxrTrackingData); public OrientationCallback OrientationEvent; public class OnOrientationListener : AndroidJavaProxy { public OnOrientationListener() : base("ruiyue.nxrsensor.library.listener.OnOrientationListener") { } public void onOrientation(AndroidJavaObject paramNxrTrackingData) { if (paramNxrTrackingData != null) { var nxrTrackingData = new NxrTrackingData(paramNxrTrackingData); if (Instance.OrientationEvent != null) { Instance.OrientationEvent(nxrTrackingData); } } } } #endregion #region EventStream public void RegisterEventCallback() { if (nxrSensorInstance != null) { nxrSensorInstance.Call("registerEventCallback", new OnEventListener()); } } public delegate void EventCallback(int paramInt1, int paramInt2); public EventCallback eventCallback; public class OnEventListener : AndroidJavaProxy { public OnEventListener() : base("ruiyue.nxrsensor.library.listener.OnEventListener") { } public void onEvent(int paramInt1, int paramInt2) { if (Instance.eventCallback != null) { Instance.eventCallback(paramInt1, paramInt2); } } } #endregion #region Imu public enum XvLogLevel { NONE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF } public void RegisterImuCallback() { if (nxrSensorInstance != null) { nxrSensorInstance.Call("registerImuCallback", new OnRawDataListener()); } } public delegate void ImuCallback(NxrRawData paramNxrRawData); public ImuCallback ImuEvent; public class OnRawDataListener : AndroidJavaProxy { public OnRawDataListener() : base("ruiyue.nxrsensor.library.listener.OnRawDataListener") { } public void onImu(AndroidJavaObject paramNxrRawData) { if (paramNxrRawData != null) { var nxrRawData = new NxrRawData(paramNxrRawData); if (Instance.ImuEvent != null) { Instance.ImuEvent(nxrRawData); } } } } public class NxrRawData { public float[] acc; public float[] gyro; public float[] mag; public long timestamp; public int quality; public NxrRawData(AndroidJavaObject javaObject) { acc = javaObject.Get("acc"); gyro = javaObject.Get("gyro"); mag = javaObject.Get("mag"); timestamp = javaObject.Get("timestamp"); quality = javaObject.Get("quality"); } } public bool HidWriteAndRead(byte[] values, int vlength, byte[] result, int rlength) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("hidWriteAndRead", values, vlength, result, rlength); } return false; } public NxrVersion Version() { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("version"); return new NxrVersion(javaObject); } return null; } public class NxrVersion { public int major = 0; public int minor = 0; public int patch = 0; public NxrVersion(AndroidJavaObject javaObject) { major = javaObject.Get("major"); minor = javaObject.Get("minor"); patch = javaObject.Get("patch"); } } public void SetLogLevel(XvLogLevel level) { if (nxrSensorInstance != null) { if (xvLogLevelClass == null) { xvLogLevelClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.XvLogLevel"); } var levelObj = xvLogLevelClass.CallStatic("valueOf", level.ToString()); nxrSensorInstance.Call("setLogLevel", levelObj); } } #endregion #region Cnn public bool SetDescriptor(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("setDescriptor", path); } return false; } public bool SetModel(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("setModel", path); } return false; } public bool SetSource(int source) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("setSource", source); } return false; } public int GetSource() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("getSource"); } return -1; } public Descriptor GetDescriptor() { if (nxrSensorInstance != null) { var javaObject = nxrSensorInstance.Call("getDescriptor"); return new Descriptor(javaObject); } return null; } public class Descriptor { public string type; public string[] classes; public double threshold; public bool flipStereo; public bool flipRgb; public bool flipTof; public Descriptor(AndroidJavaObject javaObject) { type = javaObject.Get("type"); classes = javaObject.Get("classes"); threshold = javaObject.Get("hreshold"); flipStereo = javaObject.Get("flipStereo"); flipRgb = javaObject.Get("flipRgb"); flipTof = javaObject.Get("flipTof"); } } public int RegisterCnnRawCallback() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("registerCnnRawCallback", new OnCnnRawDataListener()); } return -1; } public bool UnregisterCnnRawCallback(int callbackId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("unregisterCnnRawCallback", callbackId); } return false; } public delegate void CnnCallback(NxrCnnRawData paramNxrCnnRawData); public CnnCallback CnnEvent; public class OnCnnRawDataListener : AndroidJavaProxy { public OnCnnRawDataListener() : base("ruiyue.nxrsensor.library.listener.OnCnnRawDataListener") { } public void onCnn(AndroidJavaObject paramNxrCnnRawData) { if (paramNxrCnnRawData != null) { var nxrCnnRawData = new NxrCnnRawData(paramNxrCnnRawData); if (Instance.CnnEvent != null) { Instance.CnnEvent(nxrCnnRawData); } } } } public class NxrCnnRawData { public float[] data; public int size; public NxrCnnRawData(AndroidJavaObject javaObject) { data = javaObject.Get("data"); size = javaObject.Get("size"); } } #endregion #region Mic public bool MicStart() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("micStart"); } return false; } public bool MicStop() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("micStop"); } return false; } public int RegisterMicCallback() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("registerMicCallback", new OnMicDataListener()); } return -1; } public bool UnregisterMicCallback(int callbackId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("unregisterMicCallback", callbackId); } return false; } public delegate void MicCallback(NxrMicData paramNxrMicData); public MicCallback MicEvent; public class OnMicDataListener : AndroidJavaProxy { public OnMicDataListener() : base("ruiyue.nxrsensor.library.listener.OnMicDataListener") { } public void onMic(AndroidJavaObject paramNxrMicData) { if (paramNxrMicData != null) { var nxrMicData = new NxrMicData(paramNxrMicData); if (Instance.MicEvent != null) { Instance.MicEvent(nxrMicData); } } } } public class NxrMicData { public long dataFetchTimeMs; public long dataTimeStampMs; public byte[] data; public int size; public NxrMicData(AndroidJavaObject javaObject) { dataFetchTimeMs = javaObject.Get("dataFetchTimeMs"); dataTimeStampMs = javaObject.Get("dataTimeStampMs"); data = javaObject.Get("data"); size = javaObject.Get("size"); } } #endregion #region Speak public bool SpeakerEnable() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("speakerEnable"); } return false; } public bool SpeakerDisable() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("speakerDisable"); } return false; } public int SpeakerSend(byte[] data, int size) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("speakerSend", data, size); } return -1; } public bool SpeakerPlay(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("speakerPlay", path); } return false; } public bool SpeakerIsPlaying() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("speakerIsPlaying"); } return false; } public int RegisterSpeakerCallback() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("registerSpeakerCallback", new OnSpeakerListener()); } return -1; } public bool UnregisterSpeakerCallback(int callbackId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("unregisterSpeakerCallback", callbackId); } return false; } public delegate void SpeakerCallback(); public SpeakerCallback SpeakerEvent; public class OnSpeakerListener : AndroidJavaProxy { public OnSpeakerListener() : base("ruiyue.nxrsensor.library.listener.OnSpeakerListener") { } public void onSpeaker() { if (Instance.SpeakerEvent != null) { Instance.SpeakerEvent(); } } } #endregion #region Sgbm public bool SgbmStart(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("sgbmStart", path); } return false; } public bool SgbmStop() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("sgbmStop"); } return false; } public int RegisterSgbmCallback() { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("registerSgbmCallback", new OnStreamDataV3Listener()); } return -1; } public bool UnregisterSgbmCallback(int callbackId) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("unregisterSgbmCallback", callbackId); } return false; } public bool SgbmSetConfig(string path) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("sgbmSetConfig", path); } return false; } #endregion #region Thermal public enum ThermalMode { TEMPERATURE = 0, TEMPERTURE = 0, GREY = 1 } public void SetThermalMode(ThermalMode mode) { if (nxrSensorInstance != null) { if (thermalModeClass == null) { thermalModeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.ThermalMode"); } var modeObj = thermalModeClass.CallStatic("valueOf", mode.ToString()); nxrSensorInstance.Call("setThermalMode", modeObj); } } public bool Control(NxrDeviceSetting setting) { if (nxrSensorProInstance != null && setting != null) { var iso_value = setting.iso_value; var exp_abs = setting.exp_abs; var exp_mode = setting.exp_mode; var exp_level = setting.exp_level; var exp_anti = setting.exp_anti; var iso_mode = setting.iso_mode; var awb_mode = setting.awb_mode; var awb_lock = setting.awb_lock; var af_mode = setting.af_mode; var af_dist = setting.af_dist; var cmd = setting.cmd; var val = setting.val; var val16 = setting.val16; var val32 = setting.val32; return nxrSensorProInstance.Call("control", iso_value, exp_abs, exp_mode, exp_level, exp_anti, iso_mode, awb_mode, awb_lock, af_mode, af_dist, cmd, val, val16, val32); } return false; } public class NxrDeviceSetting { public int iso_value; public int exp_abs; public int exp_mode; public int exp_level; public int exp_anti; public int iso_mode; public int awb_mode; public int awb_lock; public int af_mode; public int af_dist; public int cmd; public int[] val; public int val16; public int val32; } public bool UvcWriteAndRead(byte[] write, int wLen, byte[] read, int rLen) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("uvcWriteAndRead", write, wLen, read, rLen); } return false; } public bool VscWriteAndRead(byte[] write, int wLen, byte[] read, int rLen) { if (nxrSensorInstance != null) { return nxrSensorInstance.Call("vscWriteAndRead", write, wLen, read, rLen); } return false; } #endregion }