sdlsensor.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // based on SDL_sensor.h
  2. {**
  3. * \brief SDL_sensor.h
  4. *
  5. * In order to use these functions, SDL_Init() must have been called
  6. * with the ::SDL_INIT_SENSOR flag. This causes SDL to scan the system
  7. * for sensors, and load appropriate drivers.
  8. *}
  9. type
  10. PPSDL_Sensor = ^PSDL_Sensor;
  11. PSDL_Sensor = ^TSDL_Sensor;
  12. TSDL_Sensor = record end;
  13. {**
  14. * This is a unique ID for a sensor for the time it is connected to the system,
  15. * and is never reused for the lifetime of the application.
  16. *
  17. * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
  18. *}
  19. type
  20. PPSDL_SensorID = ^PSDL_SensorID;
  21. PSDL_SensorID = ^TSDL_SensorID;
  22. TSDL_SensorID = type cint32;
  23. {**
  24. * The different sensors defined by SDL
  25. *
  26. * Additional sensors may be available, using platform dependent semantics.
  27. *
  28. * Hare are the additional Android sensors:
  29. * https://developer.android.com/reference/android/hardware/SensorEvent.html#values
  30. *}
  31. type
  32. PPSDL_SensorType = ^PSDL_SensorType;
  33. PSDL_SensorType = ^TSDL_SensorType;
  34. TSDL_SensorType = type cint;
  35. const
  36. SDL_SENSOR_INVALID = TSDL_SensorType(-1); {**< Returned for an invalid sensor *}
  37. SDL_SENSOR_UNKNOWN = TSDL_SensorType(0); {**< Unknown sensor type *}
  38. SDL_SENSOR_ACCEL = TSDL_SensorType(1); {**< Accelerometer *}
  39. SDL_SENSOR_GYRO = TSDL_SensorType(2); {**< Gyroscope *}
  40. SDL_SENSOR_ACCEL_L = TSDL_SensorType(3); {**< Accelerometer for left Joy-Con controller and Wii nunchuk *}
  41. SDL_SENSOR_GYRO_L = TSDL_SensorType(4); {**< Gyroscope for left Joy-Con controller *}
  42. SDL_SENSOR_ACCEL_R = TSDL_SensorType(5); {**< Accelerometer for right Joy-Con controller *}
  43. SDL_SENSOR_GYRO_R = TSDL_SensorType(6); {**< Gyroscope for right Joy-Con controller *}
  44. {**
  45. * Accelerometer sensor
  46. *
  47. * The accelerometer returns the current acceleration in SI meters per
  48. * second squared. This measurement includes the force of gravity, so
  49. * a device at rest will have an value of SDL_STANDARD_GRAVITY away
  50. * from the center of the earth.
  51. *
  52. * values[0]: Acceleration on the x axis
  53. * values[1]: Acceleration on the y axis
  54. * values[2]: Acceleration on the z axis
  55. *
  56. * For phones held in portrait mode and game controllers held in front of you,
  57. * the axes are defined as follows:
  58. * -X ... +X : left ... right
  59. * -Y ... +Y : bottom ... top
  60. * -Z ... +Z : farther ... closer
  61. *
  62. * The axis data is not changed when the phone is rotated.
  63. *
  64. * \sa SDL_GetDisplayOrientation()
  65. *}
  66. const
  67. SDL_STANDARD_GRAVITY = 9.80665;
  68. {**
  69. * Gyroscope sensor
  70. *
  71. * The gyroscope returns the current rate of rotation in radians per second.
  72. * The rotation is positive in the counter-clockwise direction. That is,
  73. * an observer looking from a positive location on one of the axes would
  74. * see positive rotation on that axis when it appeared to be rotating
  75. * counter-clockwise.
  76. *
  77. * values[0]: Angular speed around the x axis (pitch)
  78. * values[1]: Angular speed around the y axis (yaw)
  79. * values[2]: Angular speed around the z axis (roll)
  80. *
  81. * For phones held in portrait mode and game controllers held in front of you,
  82. * the axes are defined as follows:
  83. * -X ... +X : left ... right
  84. * -Y ... +Y : bottom ... top
  85. * -Z ... +Z : farther ... closer
  86. *
  87. * The axis data is not changed when the phone or controller is rotated.
  88. *
  89. * \sa SDL_GetDisplayOrientation()
  90. *}
  91. {--- Function prototypes ---}
  92. {**
  93. * Locking for multi-threaded access to the sensor API
  94. *
  95. * If you are using the sensor API or handling events from multiple threads
  96. * you should use these locking functions to protect access to the sensors.
  97. *
  98. * In particular, you are guaranteed that the sensor list won't change, so
  99. * the API functions that take a sensor index will be valid, and sensor
  100. * events will not be delivered.
  101. *
  102. * \since This function is available since SDL 2.0.14.
  103. *}
  104. procedure SDL_LockSensors(); cdecl;
  105. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LockSensors' {$ENDIF} {$ENDIF};
  106. procedure SDL_UnlockSensors(); cdecl;
  107. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UnlockSensors' {$ENDIF} {$ENDIF};
  108. {**
  109. * Count the number of sensors attached to the system right now.
  110. *
  111. * \returns the number of sensors detected.
  112. *
  113. * \since This function is available since SDL 2.0.9.
  114. *}
  115. function SDL_NumSensors(): cint; cdecl;
  116. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_NumSensors' {$ENDIF} {$ENDIF};
  117. {**
  118. * Get the implementation dependent name of a sensor.
  119. *
  120. * \param device_index The sensor to obtain name from
  121. * \returns the sensor name, or NIL if `device_index` is out of range.
  122. *
  123. * \since This function is available since SDL 2.0.9.
  124. *}
  125. function SDL_SensorGetDeviceName(device_index: cint): PAnsiChar; cdecl;
  126. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceName' {$ENDIF} {$ENDIF};
  127. {**
  128. * Get the type of a sensor.
  129. *
  130. * \param device_index The sensor to get the type from
  131. * \returns the SDL_SensorType, or `SDL_SENSOR_INVALID` if `device_index` is
  132. * out of range.
  133. *
  134. * \since This function is available since SDL 2.0.9.
  135. *}
  136. function SDL_SensorGetDeviceType(device_index: cint): TSDL_SensorType; cdecl;
  137. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceType' {$ENDIF} {$ENDIF};
  138. {**
  139. * Get the platform dependent type of a sensor.
  140. *
  141. * \param device_index The sensor to check
  142. * \returns the sensor platform dependent type, or -1 if `device_index` is out
  143. * of range.
  144. *
  145. * \since This function is available since SDL 2.0.9.
  146. *}
  147. function SDL_SensorGetDeviceNonPortableType(device_index: cint): cint; cdecl;
  148. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceNonPortableType' {$ENDIF} {$ENDIF};
  149. {**
  150. * Get the instance ID of a sensor.
  151. *
  152. * \param device_index The sensor to get instance id from
  153. * \returns the sensor instance ID, or -1 if `device_index` is out of range.
  154. *
  155. * \since This function is available since SDL 2.0.9.
  156. *}
  157. function SDL_SensorGetDeviceInstanceID(device_index: cint): TSDL_SensorID; cdecl;
  158. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceInstanceID' {$ENDIF} {$ENDIF};
  159. {**
  160. * Open a sensor for use.
  161. *
  162. * \param device_index The sensor to open
  163. * \returns an SDL_Sensor sensor object, or NIL if an error occurred.
  164. *
  165. * \since This function is available since SDL 2.0.9.
  166. *}
  167. function SDL_SensorOpen(device_index: cint): PSDL_Sensor; cdecl;
  168. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorOpen' {$ENDIF} {$ENDIF};
  169. {**
  170. * Return the SDL_Sensor associated with an instance id.
  171. *
  172. * \param instance_id The sensor from instance id
  173. * \returns an SDL_Sensor object.
  174. *
  175. * \since This function is available since SDL 2.0.9.
  176. *}
  177. function SDL_SensorFromInstanceID(instance_id: TSDL_SensorID): PSDL_Sensor; cdecl;
  178. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorFromInstanceID' {$ENDIF} {$ENDIF};
  179. {**
  180. * Get the implementation dependent name of a sensor
  181. *
  182. * \param sensor The SDL_Sensor object
  183. * \returns the sensor name, or NIL if `sensor` is NIL.
  184. *
  185. * \since This function is available since SDL 2.0.9.
  186. *}
  187. function SDL_SensorGetName(sensor: PSDL_Sensor): PAnsiChar; cdecl;
  188. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetName' {$ENDIF} {$ENDIF};
  189. {**
  190. * Get the type of a sensor.
  191. *
  192. * \param sensor The SDL_Sensor object to inspect
  193. * \returns the SDL_SensorType type, or `SDL_SENSOR_INVALID`
  194. * if `sensor` is NIL.
  195. *
  196. * \since This function is available since SDL 2.0.9.
  197. *}
  198. function SDL_SensorGetType(sensor: PSDL_Sensor): TSDL_SensorType; cdecl;
  199. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetType' {$ENDIF} {$ENDIF};
  200. {**
  201. * Get the platform dependent type of a sensor.
  202. *
  203. * \param sensor The SDL_Sensor object to inspect
  204. * \returns the sensor platform dependent type, or -1 if `sensor` is NIL.
  205. *
  206. * \since This function is available since SDL 2.0.9.
  207. *}
  208. function SDL_SensorGetNonPortableType(sensor: PSDL_Sensor): cint; cdecl;
  209. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetNonPortableType' {$ENDIF} {$ENDIF};
  210. {**
  211. * Get the instance ID of a sensor.
  212. *
  213. * \param sensor The SDL_Sensor object to inspect
  214. * \returns the sensor instance ID, or -1 if `sensor` is NIL.
  215. *
  216. * \since This function is available since SDL 2.0.9.
  217. *}
  218. function SDL_SensorGetInstanceID(sensor: PSDL_Sensor): TSDL_SensorID; cdecl;
  219. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetInstanceID' {$ENDIF} {$ENDIF};
  220. {**
  221. * Get the current state of an opened sensor.
  222. *
  223. * The number of values and interpretation of the data is sensor dependent.
  224. *
  225. * \param sensor The SDL_Sensor object to query
  226. * \param data A pointer filled with the current sensor state
  227. * \param num_values The number of values to write to data
  228. * \returns 0 or -1 if an error occurred.
  229. *
  230. * \since This function is available since SDL 2.0.9.
  231. *}
  232. function SDL_SensorGetData(sensor: PSDL_Sensor; data: pcfloat; num_values: cint): cint; cdecl;
  233. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetData' {$ENDIF} {$ENDIF};
  234. {**
  235. * Get the current state of an opened sensor with the timestamp of the last
  236. * update.
  237. *
  238. * The number of values and interpretation of the data is sensor dependent.
  239. *
  240. * \param sensor The SDL_Sensor object to query
  241. * \param timestamp A pointer filled with the timestamp in microseconds of the
  242. * current sensor reading if available, or 0 if not
  243. * \param data A pointer filled with the current sensor state
  244. * \param num_values The number of values to write to data
  245. * \returns 0 or -1 if an error occurred.
  246. *
  247. * \since This function is available since SDL 2.26.0.
  248. *}
  249. function SDL_SensorGetDataWithTimestamp(sensor: PSDL_Sensor; timestamp: pcuint64; data: pcfloat; num_values: cint): cint; cdecl;
  250. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDataWithTimestamp' {$ENDIF} {$ENDIF};
  251. {**
  252. * Close a sensor previously opened with SDL_SensorOpen().
  253. *
  254. * \param sensor The SDL_Sensor object to close
  255. *
  256. * \since This function is available since SDL 2.0.9.
  257. *}
  258. procedure SDL_SensorClose(sensor: PSDL_Sensor); cdecl;
  259. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorClose' {$ENDIF} {$ENDIF};
  260. {**
  261. * Update the current state of the open sensors.
  262. *
  263. * This is called automatically by the event loop if sensor events are
  264. * enabled.
  265. *
  266. * This needs to be called from the thread that initialized the sensor
  267. * subsystem.
  268. *
  269. * \since This function is available since SDL 2.0.9.
  270. *}
  271. procedure SDL_SensorUpdate(); cdecl;
  272. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorUpdate' {$ENDIF} {$ENDIF};