NativeGlassesController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using System.Runtime.InteropServices;
  13. /// <summary>
  14. /// The callback method type which will be called when put on or take off nreal glasses. </summary>
  15. /// <param name="glasses_control_handle"> glasses_control_handle The handle of GlassesControl.</param>
  16. /// <param name="wearing_status"> wear_or_not , 1: put on glasses . 0: take off glasses.</param>
  17. /// <param name="user_data"> The custom user data.</param>
  18. public delegate void NRGlassesControlWearCallback(UInt64 glasses_control_handle, int wearing_status, UInt64 user_data);
  19. /// <summary>
  20. /// The callback method type which will be called when plug off nreal glasses. </summary>
  21. /// <param name="glasses_control_handle"> glasses_control_handle The handle of GlassesControl.</param>
  22. /// <param name="user_data"> The custom user data.</param>
  23. public delegate void NRGlassesControlPlugOffCallback(UInt64 glasses_control_handle, UInt64 user_data);
  24. /// <summary>
  25. /// The callback method type which will be called when plug off nreal glasses. </summary>
  26. /// <param name="glasses_control_handle"> glasses_control_handle The handle of GlassesControl.</param>
  27. /// <param name="user_data"> user_data The custom user data.</param>
  28. /// <param name="reason"> The reason of glasses disconnect.</param>
  29. public delegate void NRGlassesControlNotifyQuitAppCallback(UInt64 glasses_control_handle, IntPtr user_data, GlassesDisconnectReason reason);
  30. /// <summary> A controller for handling native glasses. </summary>
  31. public partial class NativeGlassesController
  32. {
  33. /// <summary> Handle of the glasses controller. </summary>
  34. private UInt64 m_GlassesControllerHandle = 0;
  35. /// <summary> Gets the handle of the glasses controller. </summary>
  36. /// <value> The glasses controller handle. </value>
  37. public UInt64 GlassesControllerHandle
  38. {
  39. get
  40. {
  41. return m_GlassesControllerHandle;
  42. }
  43. }
  44. /// <summary> Creates this object. </summary>
  45. public void Create()
  46. {
  47. NativeResult result = NativeApi.NRGlassesControlCreate(ref m_GlassesControllerHandle);
  48. NativeErrorListener.Check(result, this, "Create");
  49. }
  50. /// <summary> Back, called when the regis glasses wear. </summary>
  51. /// <param name="callback"> The callback.</param>
  52. /// <param name="userdata"> The userdata.</param>
  53. public void RegisGlassesWearCallBack(NRGlassesControlWearCallback callback, ulong userdata)
  54. {
  55. NativeResult result = NativeApi.NRGlassesControlSetGlassesWearingCallback(m_GlassesControllerHandle, callback, userdata);
  56. NativeErrorListener.Check(result, this, "RegisGlassesWearCallBack");
  57. }
  58. /// <summary> Gets temprature level. </summary>
  59. /// <returns> The temprature level. </returns>
  60. public GlassesTemperatureLevel GetTempratureLevel()
  61. {
  62. GlassesTemperatureLevel level = GlassesTemperatureLevel.TEMPERATURE_LEVEL_NORMAL;
  63. NativeResult result = NativeApi.NRGlassesControlGetTemperatureLevel(m_GlassesControllerHandle, ref level);
  64. NativeErrorListener.Check(result, this, "GetTempratureLevel");
  65. return level;
  66. }
  67. /// <summary> Back, called when the regis glasses plug out. </summary>
  68. /// <param name="callback"> The callback.</param>
  69. /// <param name="userdata"> The userdata.</param>
  70. public void RegisGlassesPlugOutCallBack(NRGlassesControlPlugOffCallback callback, ulong userdata)
  71. {
  72. NativeResult result = NativeApi.NRGlassesControlSetGlassesDisconnectedCallback(m_GlassesControllerHandle, callback, userdata);
  73. NativeErrorListener.Check(result, this, "RegisGlassesPlugOutCallBack");
  74. }
  75. /// <summary> Back, called when the regist glasses event. </summary>
  76. /// <param name="callback"> The callback.</param>
  77. public void RegistGlassesEventCallBack(NRGlassesControlNotifyQuitAppCallback callback)
  78. {
  79. NativeResult result = NativeApi.NRGlassesControlSetNotifyQuitAppCallback(m_GlassesControllerHandle, callback, 0);
  80. NativeErrorListener.Check(result, this, "RegistGlassesEventCallBack");
  81. }
  82. /// <summary> Starts this object. </summary>
  83. public void Start()
  84. {
  85. NativeResult result = NativeApi.NRGlassesControlStart(m_GlassesControllerHandle);
  86. NativeErrorListener.Check(result, this, "Start", true);
  87. }
  88. /// <summary> Pauses this object. </summary>
  89. public void Pause()
  90. {
  91. NativeResult result = NativeApi.NRGlassesControlPause(m_GlassesControllerHandle);
  92. NativeErrorListener.Check(result, this, "Pause", true);
  93. }
  94. /// <summary> Resumes this object. </summary>
  95. public void Resume()
  96. {
  97. NativeResult result = NativeApi.NRGlassesControlResume(m_GlassesControllerHandle);
  98. NativeErrorListener.Check(result, this, "Resume", true);
  99. }
  100. /// <summary> Stops this object. </summary>
  101. public void Stop()
  102. {
  103. NativeResult result = NativeApi.NRGlassesControlStop(m_GlassesControllerHandle);
  104. NativeErrorListener.Check(result, this, "Stop");
  105. }
  106. /// <summary> Destroys this object. </summary>
  107. public void Destroy()
  108. {
  109. NativeResult result = NativeApi.NRGlassesControlDestroy(m_GlassesControllerHandle);
  110. NativeErrorListener.Check(result, this, "Destroy");
  111. }
  112. private partial struct NativeApi
  113. {
  114. /// <summary> Create the GlassesControl object. </summary>
  115. /// <param name="out_glasses_control_handle"> [in,out] The handle of GlassesControl.</param>
  116. /// <returns> The result of operation. </returns>
  117. [DllImport(NativeConstants.NRNativeLibrary)]
  118. public static extern NativeResult NRGlassesControlCreate(ref UInt64 out_glasses_control_handle);
  119. /// <summary> Start the GlassesControl system. </summary>
  120. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  121. /// <returns> The result of operation. </returns>
  122. [DllImport(NativeConstants.NRNativeLibrary)]
  123. public static extern NativeResult NRGlassesControlStart(UInt64 glasses_control_handle);
  124. /// <summary> Pause the GlassesControl system. </summary>
  125. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  126. /// <returns> The result of operation. </returns>
  127. [DllImport(NativeConstants.NRNativeLibrary)]
  128. public static extern NativeResult NRGlassesControlPause(UInt64 glasses_control_handle);
  129. /// <summary> Resume the GlassesControl system. </summary>
  130. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  131. /// <returns> The result of operation. </returns>
  132. [DllImport(NativeConstants.NRNativeLibrary)]
  133. public static extern NativeResult NRGlassesControlResume(UInt64 glasses_control_handle);
  134. /// <summary> Stop the GlassesControl system. </summary>
  135. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  136. /// <returns> The result of operation. </returns>
  137. [DllImport(NativeConstants.NRNativeLibrary)]
  138. public static extern NativeResult NRGlassesControlStop(UInt64 glasses_control_handle);
  139. /// <summary> Release memory used by the GlassesControl. </summary>
  140. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  141. /// <returns> The result of operation. </returns>
  142. [DllImport(NativeConstants.NRNativeLibrary)]
  143. public static extern NativeResult NRGlassesControlDestroy(UInt64 glasses_control_handle);
  144. /// <summary> Nr glasses control get temperature level. </summary>
  145. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  146. /// <param name="temperature_level"> [in,out] The temperature level.</param>
  147. /// <returns> A NativeResult. </returns>
  148. [DllImport(NativeConstants.NRNativeLibrary)]
  149. public static extern NativeResult NRGlassesControlGetTemperatureLevel(UInt64 glasses_control_handle, ref GlassesTemperatureLevel temperature_level);
  150. /// <summary> Set the callback method when put on or take off glasses. </summary>
  151. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  152. /// <param name="data_callback"> The callback method.</param>
  153. /// <param name="user_data"> The data which will be returned when callback is
  154. /// triggered.</param>
  155. /// <returns> The result of operation. </returns>
  156. [DllImport(NativeConstants.NRNativeLibrary)]
  157. public static extern NativeResult NRGlassesControlSetGlassesWearingCallback(
  158. UInt64 glasses_control_handle, NRGlassesControlWearCallback data_callback, UInt64 user_data);
  159. /// <summary>
  160. /// Callback, called when the nr glasses control set notify quit application. </summary>
  161. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  162. /// <param name="callback"> The callback.</param>
  163. /// <param name="user_data"> The data which will be returned when callback is
  164. /// triggered.</param>
  165. /// <returns> A NativeResult. </returns>
  166. [DllImport(NativeConstants.NRNativeLibrary)]
  167. public static extern NativeResult NRGlassesControlSetNotifyQuitAppCallback(UInt64 glasses_control_handle,
  168. NRGlassesControlNotifyQuitAppCallback callback, UInt64 user_data);
  169. /// <summary> Set the callback method when plug off the glasses. </summary>
  170. /// <param name="glasses_control_handle"> The handle of GlassesControl.</param>
  171. /// <param name="data_callback"> The callback method.</param>
  172. /// <param name="user_data"> The data which will be returned when callback is
  173. /// triggered.</param>
  174. /// <returns> The result of operation. </returns>
  175. [DllImport(NativeConstants.NRNativeLibrary)]
  176. public static extern NativeResult NRGlassesControlSetGlassesDisconnectedCallback(
  177. UInt64 glasses_control_handle, NRGlassesControlPlugOffCallback data_callback, UInt64 user_data);
  178. }
  179. }
  180. }