123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- using System;
- using System.Runtime.InteropServices;
- using System.Collections.Generic;
- //#if UNITY_EDITOR || UNITY_IOS || UNITY_ANDROID || UNITY_WIN || UNITY_MAC
- #if true
- using UnityEngine;
- using UnityEngine.Events;
- using XDebug = UnityEngine.Debug;
- #else
- using XDebug = System.Diagnostics.Debug;
- #endif // UNITY_EDITOR
- using NativeHandle = System.IntPtr;
- using NativeExHandle = System.IntPtr;
- using AOT;
- namespace Ximmerse.XR
- {
- public partial class XDevicePlugin
- {
- ///////////////////////////////////////////////////////
- /// @enum XControllerButtonMasks
- /// @brief Masks of Controller buttons.
- // Reference : https://msdn.microsoft.com/en-us/library/windows/apps/microsoft.directx_sdk.reference.xinput_gamepad
- public enum XControllerButtonMasks
- {
- kXControllerButton_DpapUp = 0x0001,
- kXControllerButton_DpapDown = 0x0002,
- kXControllerButton_DpadLeft = 0x0004,
- kXControllerButton_DpadRight = 0x0008,
- kXControllerButton_Start = 0x0010,
- kXControllerButton_Back = 0x0020,
- kXControllerButton_LeftThumb = 0x0040,
- kXControllerButton_RightThumb = 0x0080,
- kXControllerButton_LeftShoulder = 0x0100,
- kXControllerButton_RightShoulder = 0x0200,
- kXControllerButton_Guide = 0x0400,
- kXControllerButton_A = 0x1000,
- kXControllerButton_B = 0x2000,
- kXControllerButton_X = 0x4000,
- kXControllerButton_Y = 0x8000,
- // Emulation
- kXControllerButton_LeftThumbMove = 0x10000,
- kXControllerButton_RightThumbMove = 0x20000,
- kXControllerButton_LeftTrigger = 0x40000,
- kXControllerButton_RightTrigger = 0x80000,
- kXControllerButton_LeftThumbUp = 0x100000,
- kXControllerButton_LeftThumbDown = 0x200000,
- kXControllerButton_LeftThumbLeft = 0x400000,
- kXControllerButton_LeftThumbRight = 0x800000,
- kXControllerButton_RightThumbUp = 0x1000000,
- kXControllerButton_RightThumbDown = 0x2000000,
- kXControllerButton_RightThumbLeft = 0x4000000,
- kXControllerButton_RightThumbRight = 0x8000000,
- //
- kXControllerButton_None = 0x0,
- kXControllerButton_ANY = ~kXControllerButton_None,
- };
- public enum XContextStates
- {
- kXContextStInited, ///< context state, context enviroment allocted, but not working.
- kXContextStStarted, ///< context state, devices in context working.
- kXContextStWillRelease, ///< context state, moment before release.
- };
- ////////////////////////////////////////////////////////
- /// @enum XContextAttributes
- /// @brief Attributes of Context
- /// @deprecated
- public enum XContextAttributes
- {
- //kXCtxAttr_DeviceVersion,
- kXCtxAttr_Int_SdkVersion,
- kXCtxAttr_Str_SdkVersion,
- kXCtxAttr_Int_SDKALGVersion, // int
- kXCtxAttr_Int_State, ///< State value indicated context working state,
- kXCtxAttr_Str_SdkBuildDetail,
- };
- ////////////////////////////////////////////////////////
- /// @enum XVpuAttributes
- /// @brief Attributes of VPU Device.
- /// @deprecated
- public enum XVpuAttributes
- {
- kXVpuAttr_Str_SoftwareRevision,
- kXVpuAttr_Str_HardwareRevision,
- kXVpuAttr_Str_SerialNumber,
- kXVpuAttr_Str_DeviceName,
- kXVpuAttr_Str_ModelName,
- kXVpuAttr_Str_FPGAVersion,
- kXVpuAttr_Str_ALGVersion,
- kXVpuAttr_Int_ImuFps,
- kXVpuAttr_Int_FpgaFps,
- /// Reversed
- kXVpuAttr_Int_AlgorithmPoseFps,
- kXVpuAttr_Int_ErrorCode,
- /// Connection state of Controller, see \ref XConnectionStates
- kXVpuAttr_Int_ConnectionState,
- kXVpuAttr_Int_PowerMode,
- /// Battery Level. Invalid if battery mode is external power
- kXVpuAttr_Int_Battery,
- kXVpuAttr_Int_BatteryVoltage,
- kXVpuAttr_Int_BatteryTemperature,
- /// IMU info of device, see \ref XAttrImuInfo
- kXVpuAttr_Obj_ImuInfo,
- /// IMU info of device, Output to variable aguments
- kXVpuAttr_V_ImuInfo,
- /// 6Dof info of device, see \ref XAttr6DofInfo
- kXVpuAttr_Obj_6DofInfo,
- /// 6Dof info of device, Output to variable aguments
- kXVpuAttr_V_6DofInfo,
- /// Pressed button bits
- kXVpuAttr_Int_ButtonBits, // int
- /// Button events, \ref XButtonEvents
- kXVpuAttr_Int_ButtonEvent = kXVpuAttr_Int_ButtonBits,
- /// Number of Paired controllers
- kXVpuAttr_Int_PairedNumber,
- /// Device infos, imu, 6dof, buttons ... see \ref XAttrControllerState
- kXVpuAttr_Obj_ControllerState,
- /// VPU cammera tracking object pose info. see \ref XAttrTrackingInfo
- kXVpuAttr_Obj_TrackingInfo,
- /// VPU cammera tracking object pose info. Output to variable aguments
- kXVpuAttr_V_TrackingInfo,
- //kXVpuAttr_Evt_TrackingPoseUpdate,
- /// VPU paired controllers, see \ref XAttrPairedInfos
- kXVpuAttr_Obj_PairedInfos,
- };
- ////////////////////////////////////////////////////////
- /// @enum XControllerAttributes
- /// @brief Attribute types of controller.
- /// @deprecated
- public enum XControllerAttributes
- {
- kXCAttr_Str_FirmwareRevision,
- kXCAttr_Str_SoftwareRevision,
- kXCAttr_Str_HardwareRevision,
- kXCAttr_Str_SerialNumber,
- kXCAttr_Str_DeviceName,
- kXCAttr_Str_ModelName,
- kXCAttr_Str_ManufacturerName,
- /// FPS of controller device reporting IMU data
- kXCAttr_Int_ImuFps,
- kXCAttr_Int_ErrorCode,
- /// Connection state of Controller, see \ref XConnectionStates
- kXCAttr_Int_ConnectionState,
- kXCAttr_Int_PowerMode,
- /// Battery Level. Invalid if battery mode is external power
- kXCAttr_Int_Battery,
- kXCAttr_Int_BatteryVoltage,
- kXCAttr_Int_BatteryTemperature,
- /// IMU info of device, see \ref XAttrImuInfo
- kXCAttr_Obj_ImuInfo,
- /// IMU info of device, Output to variable aguments
- kXCAttr_V_ImuInfo,
- /// 6Dof info of device, see \ref XAttr6DofInfo
- kXCAttr_Obj_6DofInfo,
- /// 6Dof info of device, Output to variable aguments
- kXCAttr_V_6DofInfo,
- /// Pressed button bits
- kXCAttr_Int_ButtonBits,
- /// Button events, \ref XButtonEvents
- kXCAttr_Int_ButtonEvent = kXCAttr_Int_ButtonBits,
- kXCAttr_Int_Trigger,
- /// Device touchpad state info. see \ref XAttrTouchPadInfo
- kXCAttr_Obj_TouchPadState,
- //kXCAttr_Int_TouchPadState, //
- /// Device infos, imu, 6dof, buttons ... see \ref XAttrControllerState
- kXCAttr_Obj_ControllerState,
- /// Get Controller device type, see \ref XControllerTypes.
- kXCAttr_Int_Type,
- /// Get Controller device address (MAC address)
- kXCAttr_Obj_Address,
- /// Get Hex String MAC Address of controller.
- kXCAttr_Str_Address,
- /// Get Bind ID of connected controller.
- kXCAttr_Int_BindID,
- };
- public enum XPowerModes
- {
- kXPowerModeExternal = 0, ///< External power supply
- kXPowerModeBattery = 1, ///< battery
- };
- /// /////////////////////////////////////////////////////////////////////
- /// \enum XControllerTypes
- /// \bref Types defined of Ximmerse Controllers
- public enum XControllerTypes
- {
- kControllerType_Saber = 0x0000,
- kControllerType_Kylo = 0x0001,
- kControllerType_DType = 0x0002,
- kControllerType_PickUp = 0x0003,
- kControllerType_3Dof = 0x0200,
- kControllerType_Tag = 0x0100,
- kControllerType_TagLeft = kControllerType_Tag,
- kControllerType_TagRight = 0x0101,
- kControllerType_TagRfid = 0x0102,
- kControllerType_Cube = 0x0103,
- kControllerType_TouchPad = 0x0104,
- kControllerType_ShortGun = 0x0105,
- kControllerType_LongGun = 0x0106,
- kControllerType_CircularLeft = 0x010A,
- kControllerType_CircularRight = 0x010B,
-
- kControllerType_Unknow = 0xffff,
- kControllerType_BitMask = 0xffff,
- }
- ////////////////////////////////////////////////////////
- /// @enum XControllerTrackModes
- /// @brief Algorithm tracking types of controller.
- public enum XControllerTrackModes
- {
- kControllerTrackModeNone,
- kControllerTrackModeVisable,
- kControllerTrackModeTagMark,
- };
-
- //////////////////////////////////////
- /// @enum XButtonEvents
- /// @brief Button events
- public enum XButtonEvents
- {
- kXBtnEvt_Down,
- kXBtnEvt_Up,
- //kXBtnEvt_LongPress,
- };
-
- ///////////////////////////////////////
- /// @struct XButtonEventParam
- /// @brief Parameters for button event notification
- [StructLayout(LayoutKind.Sequential)]
- public struct XButtonEventParam
- {
- /// Button key value.
- public int btn;
- /// Event value. see \ref XButtonEvents
- public int evt;
- public XButtonEventParam(int btn, int evt)
- {
- this.btn = btn;
- this.evt = evt;
- }
- };
-
- ////////////////////////////////////////
- /// @enum XConnectionStates
- /// @brief Connection state of device
- public enum XConnectionStates
- {
- kXConnSt_Disconnected = 0,
- kXConnSt_Scanning = 1,
- kXConnSt_Connecting = 2,
- kXConnSt_Connected = 3,
- kXConnSt_Disconnecting = 4,
- //kXConnSt_Disconnected = ?
- };
- public enum XPairingStates
- {
- kXPairStUnpaired = 0,
- kXPairStPairing = 1,
- kXPairStPaired = 2,
- kXPairStUnpairing = 3,
- };
- public enum XTrackResults
- {
- kXTrackResultNone = 0,
- kXTrackResultPose = 1,
- kXTrackResultPosition = 2,
- kXTrackResultAll = kXTrackResultPosition | kXTrackResultPose,
- };
- ///////////////////////////////////////////////
- /// @struct XAttr6DofInfo
- /// @brief Structure for gettting 6Dof information
- [StructLayout(LayoutKind.Sequential)]
- public struct XAttr6DofInfo
- {
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] position; /// < float buffer for gettting position values
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
- public float[] rotation; /// < float buffer for getting quaternions of rotation.
- public UInt64 timestamp;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] euler; /// < float buffer for gettting euler rotation.
- public XAttr6DofInfo(UInt64 timestamp = 0, float[] position = null, float[] rotation = null)
- {
- this.timestamp = timestamp;
- this.position = position == null ? new float[3] { 0, 0, 0 } : position;
- this.rotation = rotation == null ? new float[4] { 0, 0, 0, 0 } : rotation;
- this.euler = new float[3];
- }
- };
- //////////////////////////////////////////////
- /// @struct XAttrImuInfo
- /// @brief Structure for getting IMU information.
- [StructLayout(LayoutKind.Sequential)]
- public struct XAttrImuInfo
- {
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] accelerometer; ///< (out) float buffer for getting accelerometer values.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] gyroscope; ///< float buffer for getting gyroscope values.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] magnetism; /// < float buffer for getting magnetism values.
- public UInt64 timestamp;
- public XAttrImuInfo(
- UInt64 timestamp = 0,
- float[] accelerometer = null,
- float[] gyroscope = null, float[] magnetism = null)
- {
- this.timestamp = timestamp;
- this.accelerometer = accelerometer == null ? new float[3] { 0, 0, 0 } : accelerometer;
- this.gyroscope = gyroscope == null ? new float[3] { 0, 0, 0 } : gyroscope;
- this.magnetism = magnetism == null ? new float[3] { 0, 0, 0 } : magnetism;
- }
- };
-
- /////////////////////////////////////////////
- /// @struct XAttrTrackingInfo
- /// @brief VPU cammera tracking object pose info.
- [StructLayout(LayoutKind.Sequential)]
- public struct XAttrTrackingInfo
- {
- public int index;
- public int state;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] position;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
- public float[] rotation;
- public UInt64 timestamp;
- public UInt64 recognized_markers_mask;
- public double confidence;
- public double marker_distance;
- public XAttrTrackingInfo(
- UInt64 timestamp = 0,
- int index = 0,
- int state = 0,
- float[] position = null,
- float[] rotation = null,
- double confidence = 0,
- double marker_distance = 0)
- {
- this.timestamp = timestamp;
- this.index = index;
- this.state = state;
- this.position = position == null ? new float[3] { 0, 0, 0 } : position;
- this.rotation = rotation == null ? new float[4] { 0, 0, 0, 0 } : rotation;
- this.recognized_markers_mask = 0;
- this.confidence = 0;
- this.marker_distance = 0;
- }
- public override string ToString() {
- Quaternion q = new Quaternion(rotation[0], rotation[1], rotation[2], rotation[3]);
- return string.Format("id:{0},st:{1},time:{2},P:{3},{4},{5}, R:{6},{7},{8}",
- index, state, timestamp,
- position[0], position[1], position[2],
- q.eulerAngles.x, q.eulerAngles.y, q.eulerAngles.z);
- }
- };
- //////////////////////////////////////
- /// @struct XAttrControllerState
- /// @brief Structure for getting controller state informations.
- [StructLayout(LayoutKind.Sequential)]
- public struct XAttrControllerState
- {
- /// quaternion
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
- public float[] rotation;
- /// x, y, z
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] position;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] accelerometer;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] gyroscope;
- public UInt64 timestamp;
- /// bit map indicating button pressed state of controller.
- public UInt32 button_state;
- //uint8_t valid_flag; ///
- // TouchPad, reverve
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
- public float[] axes;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
- public float[] euler; /// < float buffer for gettting euler rotation.
- public int trigger;
- public XAttrControllerState(
- UInt64 timestamp = 0,
- UInt32 button_state = 0,
- float[] rotation = null,
- float[] position = null,
- float[] accelerometer = null,
- float[] gyroscope = null,
- float[] axes = null,
- int trigger = 0)
- {
- this.timestamp = timestamp;
- this.button_state = button_state;
- this.rotation = rotation == null ? new float[4] { 0, 0, 0, 0 } : rotation;
- this.position = position == null ? new float[3] { 0, 0, 0 } : position;
- this.accelerometer = accelerometer == null ? new float[3] { 0, 0, 0 } : accelerometer;
- this.gyroscope = gyroscope == null ? new float[3] { 0, 0, 0 } : gyroscope;
- this.axes = axes == null ? new float[6] { 0, 0, 0, 0, 0, 0 } : axes;
- euler = new float[3];
- this.trigger = trigger;
- }
- };
- public enum XAttrTouchPadEvents
- {
- kAttrTpadEvt_Idle = 0x00,
- kAttrTpadEvt_Press = 0x01,
- kAttrTpadEvt_Release = 0x02,
- kAttrTpadEvt_Move = 0x03,
- };
- [StructLayout(LayoutKind.Sequential)]
- public struct XAttrTouchPadState
- {
- public bool pressed; ///< indicated touchpad is touching.
- public float x; ///< x coordinate value, from 0 to 1.
- public float y; ///< y coordinate value, from 0 to 1.
- };
- public struct XAttrMacAddress
- {
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
- public byte[] mac;
- }
- /////////////////////////////
- /// \struct XAttrPairedInfos
- /// \bref Structure for getting infomation of paired controllers.
- [StructLayout(LayoutKind.Sequential)]
- public struct XAttrPairedInfos
- {
- public int c; ///< Number of paired controller.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
- public int[] bind_id_a; ///< An array containing bind ID of paired controllers.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6 * 16)]
- public XAttrMacAddress[] mac_a; ///< An array containing MAC address of paired controllers.
- };
- public enum XErrorCodes
- {
- kErrNoError = 0,
- kErrUnknonw = -1,
- kErrBegin = -1000,
- kErrOperationFail,
- kErrDeviceNotFound,
- kErrInvalidArgument,
- kErrVpuNotArrived,
- kErrFileNotExist,
- kErrFileEmpty,
- kErrChecksumFail,
- kErrInWrongState,
- kErrVpuAuthFailed,
- kErrReadMarkerConfigFailed,
- kErrNotFound, // no usage
- kErrApiInvalid,
- kErrVpuCommandFail,
- kErrNoDeviceToConnect,
- kErrWrongConnectState,
- kErrWrongPairingState,
- kErrPairListIsFull,
- kErrWaitTimeout,
- kErrBindIdInvalid,
- kErrOutoffMemory,
- kErrServiceNotRunning,
- kErrServiceInvalid,
- kErrCodeError,
- // kErrOpClient = -2000,
- kErrEnd,
- };
- public enum XEvents{
- kXEvtVpuRequestSuccess,
- kXEvtVpuRequestFailed,
- kXEvtVpuFwUpgradingStart = 100,
- kXEvtVpuFwUpgradingProgress,
- kXEvtVpuFwUpgradingEndSuccess,
- kXEvtVpuFwUpgradingEndFail,
- kXEvtAuthResult = 200,
- kXEvtJavaBroadcast = 201,
- kXEvtJavaOpcReport = 202,
- };
- }
- }
|