1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215 |
- 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<AndroidJavaObject>("getInstance");
- }
- if (nxrSensorProClass == null)
- {
- nxrSensorProClass = new AndroidJavaClass("com.nibiru.nxrsensor.NxrSensor");
- }
- if (nxrSensorProClass != null && nxrSensorProInstance == null)
- {
- nxrSensorProInstance = nxrSensorProClass.CallStatic<AndroidJavaObject>("getInstance");
- }
- #endif
- }
- public AndroidJavaObject NxrSensorInstance
- {
- get { return nxrSensorInstance; }
- }
- public bool InitLibrary()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject>("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<float[]>("rotation");
- rotation[2] *= -1;
- translation = javaObject.Get<float[]>("translation");
- translation[2] *= -1;
- prediction_coff_s = javaObject.Get<float[]>("prediction_coff_s");
- prediction_coff_b = javaObject.Get<float[]>("prediction_coff_b");
- prediction_coff_bdt = javaObject.Get<float[]>("prediction_coff_bdt");
- prediction_coff_bdt2 = javaObject.Get<float[]>("prediction_coff_bdt2");
- fetchTimestamp = javaObject.Get<long>("fetchTimestamp");
- timestamp = javaObject.Get<long>("timestamp");
- source = javaObject.Get<int>("source");
- black = javaObject.Get<int>("black");
- rotateY = javaObject.Get<int>("rotateY");
- }
- public string toString()
- {
- if (androidJavaObject != null)
- {
- return androidJavaObject.Call<string>("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<AndroidJavaObject>("valueOf", type.ToString());
- return nxrSensorInstance.Call<bool>("startPlaneDetection", typeObj, new OnPlaneDetectionListener());
- }
- return false;
- }
- public bool StopPlaneDetection(int type)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<long>("hostTimestamp");
- deviceTimestamp = javaObject.Get<long>("deviceTimestamp");
- var pointsObj = javaObject.Get<AndroidJavaObject>("points");
- if (pointsObj != null)
- {
- if (pointsObj.GetRawObject().ToInt32() != 0)
- {
- var pointsObjArray =
- AndroidJNIHelper.ConvertFromJNIArray<AndroidJavaObject[]>(pointsObj.GetRawObject());
- points = new NxrPointD[pointsObjArray.Length];
- for (var i = 0; i < points.Length; i++)
- {
- var point = new NxrPointD();
- point.x = pointsObjArray[i].Get<double>("x");
- point.y = pointsObjArray[i].Get<double>("y");
- point.z = pointsObjArray[i].Get<double>("z");
- points[i] = point;
- pointsObjArray[i].Dispose();
- }
- }
- pointsObj.Dispose();
- }
- var normalObj = javaObject.Get<AndroidJavaObject>("normal");
- if (normalObj != null)
- {
- normal.x = normalObj.Get<double>("x");
- normal.y = normalObj.Get<double>("y");
- normal.z = normalObj.Get<double>("z");
- normalObj.Dispose();
- }
- size = javaObject.Get<int>("size");
- id = javaObject.Get<int>("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<int>("registerMapCallback", new OnMapV2Listener());
- }
- return -1;
- }
- public bool UnregisterMapCallback(int callbackId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject[]>(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<double>("x");
- point.y = nxrPointDArray[i].Get<double>("y");
- point.z = nxrPointDArray[i].Get<double>("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<bool>("loadMapAndSwitchToCslam", path, new OnMapListener());
- }
- return false;
- }
- public bool SaveMapAndSwitchToCslam(string path)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject>("getSlamMode");
- if (slamModeObj != null)
- {
- return (SlamMode) slamModeObj.Call<int>("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<AndroidJavaObject>("valueOf", type.ToString());
- return nxrSensorInstance.Call<bool>("startGesture", typeObj, new OnGestureListener());
- }
- return false;
- }
- public bool StopGesture(int type)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<int>("size");
- gesture = javaObject.Get<int[]>("gesture");
- distance = javaObject.Get<float>("distance");
- confidence = javaObject.Get<float>("confidence");
- var positionObj = javaObject.Get<AndroidJavaObject>("position");
- if (positionObj != null)
- {
- if (positionObj.GetRawObject().ToInt32() != 0)
- {
- var positionObjArray =
- AndroidJNIHelper.ConvertFromJNIArray<AndroidJavaObject[]>(positionObj.GetRawObject());
- position = new NxrPointF[positionObjArray.Length];
- for (var i = 0; i < position.Length; i++)
- {
- var tempPosition = new NxrPointF();
- tempPosition.x = positionObjArray[i].Get<float>("x");
- tempPosition.y = positionObjArray[i].Get<float>("y");
- tempPosition.z = positionObjArray[i].Get<float>("z");
- position[i] = tempPosition;
- positionObjArray[i].Dispose();
- }
- }
- positionObj.Dispose();
- }
- var slamPositionObj = javaObject.Get<AndroidJavaObject>("slamPosition");
- if (slamPositionObj != null)
- {
- if (slamPositionObj.GetRawObject().ToInt32() != 0)
- {
- var slamPositionObjArray =
- AndroidJNIHelper.ConvertFromJNIArray<AndroidJavaObject[]>(slamPositionObj.GetRawObject());
- slamPosition = new NxrPointF[slamPositionObjArray.Length];
- for (var i = 0; i < slamPosition.Length; i++)
- {
- var tempSlamPosition = new NxrPointF();
- tempSlamPosition.x = slamPositionObjArray[i].Get<float>("x");
- tempSlamPosition.y = slamPositionObjArray[i].Get<float>("y");
- tempSlamPosition.z = slamPositionObjArray[i].Get<float>("z");
- slamPosition[i] = tempSlamPosition;
- slamPositionObjArray[i].Dispose();
- }
- }
- slamPositionObj.Dispose();
- }
- dataFetchTimeMs = javaObject.Get<long>("dataFetchTimeMs");
- dataTimeStampMs = javaObject.Get<long>("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<bool>("startSlam");
- if (isStartSlam)
- {
- if (xvGestureTypeClass == null)
- {
- xvGestureTypeClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.XvGestureType");
- }
- var typeObj = xvGestureTypeClass.CallStatic<AndroidJavaObject>("valueOf", type.ToString());
- return nxrSensorInstance.Call<bool>("startSkeleton", typeObj, new OnSkeletonListener());
- }
- }
- return false;
- }
- public bool StopSkeleton(int type)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<int>("size");
- dataFetchTimeMS = javaObject.Get<long>("dataFetchTimeMS");
- dataTimeStampMs = javaObject.Get<long>("dataTimeStampMs");
- var joints0Array = javaObject.Get<AndroidJavaObject[]>("joints0");
- var joints1Array = javaObject.Get<AndroidJavaObject[]>("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<float>("x");
- joint0.y = joints0Array[i].Get<float>("y");
- joint0.z = joints0Array[i].Get<float>("z");
- var joint1 = new NxrPointF();
- joint1.x = joints1Array[i].Get<float>("x");
- joint1.y = joints1Array[i].Get<float>("y");
- joint1.z = joints1Array[i].Get<float>("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<string>("startTagDetector", tagFamliy, size, refreshRate);
- }
- return null;
- }
- public bool StopTagDetector(string detectorId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("stopTagDetector", detectorId);
- }
- return false;
- }
- public TagDetection[] GetTagDetections(string detectorId)
- {
- if (nxrSensorInstance != null)
- {
- var tagDetectionsObj = nxrSensorInstance.Call<AndroidJavaObject>("getTagDetections", detectorId);
- if (tagDetectionsObj != null)
- {
- var tagDetectionsArray =
- AndroidJNIHelper.ConvertFromJNIArray<AndroidJavaObject[]>(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<AndroidJavaObject>("detectTags", tagFamliy, size);
- if (tagDetectionsObj != null)
- {
- var tagDetectionsArray =
- AndroidJNIHelper.ConvertFromJNIArray<AndroidJavaObject[]>(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<int>("id");
- quaternion = javaObject.Get<float[]>("quaternion");
- quaternion[2] *= -1;
- translation = javaObject.Get<float[]>("translation");
- translation[2] *= -1;
- rotation = javaObject.Get<float[]>("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<AndroidJavaObject>("getTrackingDataInTagsMap", prediction);
- if (nxrTrackingDataObj != null)
- {
- return new NxrTrackingData(nxrTrackingDataObj);
- }
- }
- return null;
- }
- #endregion
- #region Display
- public DisplayCalibration ReadDisplayCalibrations()
- {
- if (nxrSensorInstance != null)
- {
- var javaObject = nxrSensorInstance.Call<AndroidJavaObject>("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<float[]>("K0");
- K1 = javaObject.Get<float[]>("K1");
- rotation0 = javaObject.Get<float[]>("rotation0");
- rotation1 = javaObject.Get<float[]>("rotation1");
- translation0 = javaObject.Get<float[]>("translation0");
- translation1 = javaObject.Get<float[]>("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<bool>("displayOpen");
- }
- return false;
- }
- public bool DisplayClose()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject>("valueOf", type.ToString());
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject>("valueOf", type.ToString());
- return nxrSensorInstance.Call<bool>("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<byte[]>("data");
- left = javaObject.Get<byte[]>("left");
- right = javaObject.Get<byte[]>("right");
- type = javaObject.Get<int>("type");
- format = javaObject.Get<int>("format");
- width = javaObject.Get<int>("width");
- height = javaObject.Get<int>("height");
- size = javaObject.Get<int>("size");
- leftSize = javaObject.Get<int>("leftSize");
- rightSize = javaObject.Get<int>("rightSize");
- timestamp = javaObject.Get<long>("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<int>("ordinal");
- var nxrStreamData = new NxrStreamData(paramNxrStreamData);
- if (Instance.StreamDataEvent != null)
- {
- Instance.StreamDataEvent(rawDataType, nxrStreamData);
- }
- }
- }
- }
- public RgbCalibration ReadRgbCalibrations()
- {
- if (nxrSensorInstance != null)
- {
- var javaObject = nxrSensorInstance.Call<AndroidJavaObject>("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<float[]>("rotation");
- translation = javaObject.Get<float[]>("translation");
- K0 = javaObject.Get<float[]>("K0");
- K1 = javaObject.Get<float[]>("K1");
- K2 = javaObject.Get<float[]>("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<AndroidJavaObject>("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<int>("registerColorDepthImageCallback", new OnStreamDataV3Listener());
- }
- return -1;
- }
- public bool UnregisterColorDepthImageCallback(int callbackId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject>("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<float[]>("K");
- rotation = javaObject.Get<float[]>("rotation");
- translation = javaObject.Get<float[]>("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<AndroidJavaObject>("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<AndroidJavaObject>("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<long>("dataFetchTimeMs");
- dataTimeStampMs = javaObject.Get<long>("dataTimeStampMs");
- var pointsArray = javaObject.Get<AndroidJavaObject[]>("points");
- points = new NxrPointF[pointsArray.Length];
- for (var i = 0; i < points.Length; i++)
- {
- var nxrPointF = new NxrPointF();
- nxrPointF.x = pointsArray[i].Get<float>("x");
- nxrPointF.y = pointsArray[i].Get<float>("y");
- nxrPointF.z = pointsArray[i].Get<float>("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<AndroidJavaObject>("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<AndroidJavaObject>("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<AndroidJavaObject>("readStereoFisheyesCalibrations", type);
- return new FishEyeCalibration(javaObject);
- }
- return null;
- }
- public FishEyeCalibration ReadStereoFisheyesPDMCalibrations(int type)
- {
- if (nxrSensorInstance != null)
- {
- var javaObject = nxrSensorInstance.Call<AndroidJavaObject>("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<int>("imu_fisheye_shift_us");
- delta = javaObject.Get<float>("delta");
- K0 = javaObject.Get<float[]>("K0");
- K1 = javaObject.Get<float[]>("K1");
- rotation0 = javaObject.Get<float[]>("rotation0");
- rotation1 = javaObject.Get<float[]>("rotation1");
- translation0 = javaObject.Get<float[]>("translation0");
- translation1 = javaObject.Get<float[]>("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<AndroidJavaObject>("get3dof", prediction);
- return new NxrTrackingData(javaObject);
- }
- return null;
- }
- public NxrTrackingData Get3dofAt(double timestamp)
- {
- if (nxrSensorInstance != null)
- {
- var javaObject = nxrSensorInstance.Call<AndroidJavaObject>("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<float[]>("acc");
- gyro = javaObject.Get<float[]>("gyro");
- mag = javaObject.Get<float[]>("mag");
- timestamp = javaObject.Get<long>("timestamp");
- quality = javaObject.Get<int>("quality");
- }
- }
- public bool HidWriteAndRead(byte[] values, int vlength, byte[] result, int rlength)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("hidWriteAndRead", values, vlength, result, rlength);
- }
- return false;
- }
- public NxrVersion Version()
- {
- if (nxrSensorInstance != null)
- {
- var javaObject = nxrSensorInstance.Call<AndroidJavaObject>("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<int>("major");
- minor = javaObject.Get<int>("minor");
- patch = javaObject.Get<int>("patch");
- }
- }
- public void SetLogLevel(XvLogLevel level)
- {
- if (nxrSensorInstance != null)
- {
- if (xvLogLevelClass == null)
- {
- xvLogLevelClass = new AndroidJavaClass("ruiyue.nxrsensor.library.type.XvLogLevel");
- }
- var levelObj = xvLogLevelClass.CallStatic<AndroidJavaObject>("valueOf", level.ToString());
- nxrSensorInstance.Call("setLogLevel", levelObj);
- }
- }
- #endregion
- #region Cnn
- public bool SetDescriptor(string path)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("setDescriptor", path);
- }
- return false;
- }
- public bool SetModel(string path)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("setModel", path);
- }
- return false;
- }
- public bool SetSource(int source)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("setSource", source);
- }
- return false;
- }
- public int GetSource()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<int>("getSource");
- }
- return -1;
- }
- public Descriptor GetDescriptor()
- {
- if (nxrSensorInstance != null)
- {
- var javaObject = nxrSensorInstance.Call<AndroidJavaObject>("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<string>("type");
- classes = javaObject.Get<string[]>("classes");
- threshold = javaObject.Get<double>("hreshold");
- flipStereo = javaObject.Get<bool>("flipStereo");
- flipRgb = javaObject.Get<bool>("flipRgb");
- flipTof = javaObject.Get<bool>("flipTof");
- }
- }
- public int RegisterCnnRawCallback()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<int>("registerCnnRawCallback", new OnCnnRawDataListener());
- }
- return -1;
- }
- public bool UnregisterCnnRawCallback(int callbackId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<float[]>("data");
- size = javaObject.Get<int>("size");
- }
- }
- #endregion
- #region Mic
- public bool MicStart()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("micStart");
- }
- return false;
- }
- public bool MicStop()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("micStop");
- }
- return false;
- }
- public int RegisterMicCallback()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<int>("registerMicCallback", new OnMicDataListener());
- }
- return -1;
- }
- public bool UnregisterMicCallback(int callbackId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<long>("dataFetchTimeMs");
- dataTimeStampMs = javaObject.Get<long>("dataTimeStampMs");
- data = javaObject.Get<byte[]>("data");
- size = javaObject.Get<int>("size");
- }
- }
- #endregion
- #region Speak
- public bool SpeakerEnable()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("speakerEnable");
- }
- return false;
- }
- public bool SpeakerDisable()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("speakerDisable");
- }
- return false;
- }
- public int SpeakerSend(byte[] data, int size)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<int>("speakerSend", data, size);
- }
- return -1;
- }
- public bool SpeakerPlay(string path)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("speakerPlay", path);
- }
- return false;
- }
- public bool SpeakerIsPlaying()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("speakerIsPlaying");
- }
- return false;
- }
- public int RegisterSpeakerCallback()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<int>("registerSpeakerCallback", new OnSpeakerListener());
- }
- return -1;
- }
- public bool UnregisterSpeakerCallback(int callbackId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<bool>("sgbmStart", path);
- }
- return false;
- }
- public bool SgbmStop()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("sgbmStop");
- }
- return false;
- }
- public int RegisterSgbmCallback()
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<int>("registerSgbmCallback", new OnStreamDataV3Listener());
- }
- return -1;
- }
- public bool UnregisterSgbmCallback(int callbackId)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("unregisterSgbmCallback", callbackId);
- }
- return false;
- }
- public bool SgbmSetConfig(string path)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("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<AndroidJavaObject>("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<bool>("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<bool>("uvcWriteAndRead", write, wLen, read, rLen);
- }
- return false;
- }
- public bool VscWriteAndRead(byte[] write, int wLen, byte[] read, int rLen)
- {
- if (nxrSensorInstance != null)
- {
- return nxrSensorInstance.Call<bool>("vscWriteAndRead", write, wLen, read, rLen);
- }
- return false;
- }
- #endregion
- }
|