Skip to content

Commit 2b7d484

Browse files
committed
Add sdlsensor.inc (based on SDL_sensor.h)
1 parent 256ea45 commit 2b7d484

File tree

2 files changed

+236
-0
lines changed

2 files changed

+236
-0
lines changed

sdl2.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ interface
163163
{$I sdlhaptic.inc}
164164
{$I sdltouch.inc}
165165
{$I sdlgesture.inc}
166+
{$I sdlsensor.inc}
166167
{$I sdlsyswm.inc}
167168
{$I sdlevents.inc}
168169
{$I sdlclipboard.inc}

sdlsensor.inc

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
// based on SDL_sensor.h
2+
3+
4+
{**
5+
* \brief SDL_sensor.h
6+
*
7+
* In order to use these functions, SDL_Init() must have been called
8+
* with the ::SDL_INIT_SENSOR flag. This causes SDL to scan the system
9+
* for sensors, and load appropriate drivers.
10+
*}
11+
type
12+
TSDL_Sensor = record end;
13+
PSDL_Sensor = ^TSDL_Sensor;
14+
15+
{**
16+
* This is a unique ID for a sensor for the time it is connected to the system,
17+
* and is never reused for the lifetime of the application.
18+
*
19+
* The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
20+
*}
21+
type
22+
TSDL_SensorID = type SInt32;
23+
24+
{**
25+
* The different sensors defined by SDL
26+
*
27+
* Additional sensors may be available, using platform dependent semantics.
28+
*
29+
* Hare are the additional Android sensors:
30+
* https://developer.android.com/reference/android/hardware/SensorEvent.html#values
31+
*}
32+
type
33+
TSDL_SensorType = type SInt32;
34+
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+
41+
{**
42+
* Accelerometer sensor
43+
*
44+
* The accelerometer returns the current acceleration in SI meters per
45+
* second squared. This measurement includes the force of gravity, so
46+
* a device at rest will have an value of SDL_STANDARD_GRAVITY away
47+
* from the center of the earth.
48+
*
49+
* values[0]: Acceleration on the x axis
50+
* values[1]: Acceleration on the y axis
51+
* values[2]: Acceleration on the z axis
52+
*
53+
* For phones held in portrait mode and game controllers held in front of you,
54+
* the axes are defined as follows:
55+
* -X ... +X : left ... right
56+
* -Y ... +Y : bottom ... top
57+
* -Z ... +Z : farther ... closer
58+
*
59+
* The axis data is not changed when the phone is rotated.
60+
*
61+
* \sa SDL_GetDisplayOrientation()
62+
*}
63+
const
64+
SDL_STANDARD_GRAVITY = 9.80665;
65+
66+
{**
67+
* Gyroscope sensor
68+
*
69+
* The gyroscope returns the current rate of rotation in radians per second.
70+
* The rotation is positive in the counter-clockwise direction. That is,
71+
* an observer looking from a positive location on one of the axes would
72+
* see positive rotation on that axis when it appeared to be rotating
73+
* counter-clockwise.
74+
*
75+
* values[0]: Angular speed around the x axis (pitch)
76+
* values[1]: Angular speed around the y axis (yaw)
77+
* values[2]: Angular speed around the z axis (roll)
78+
*
79+
* For phones held in portrait mode and game controllers held in front of you,
80+
* the axes are defined as follows:
81+
* -X ... +X : left ... right
82+
* -Y ... +Y : bottom ... top
83+
* -Z ... +Z : farther ... closer
84+
*
85+
* The axis data is not changed when the phone or controller is rotated.
86+
*
87+
* \sa SDL_GetDisplayOrientation()
88+
*}
89+
90+
{--- Function prototypes ---}
91+
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+
procedure SDL_LockSensors(); cdecl;
103+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LockSensors' {$ENDIF} {$ENDIF};
104+
procedure SDL_UnlockSensors(); cdecl;
105+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UnlockSensors' {$ENDIF} {$ENDIF};
106+
107+
{**
108+
* \brief Count the number of sensors attached to the system right now
109+
*}
110+
function SDL_NumSensors(): SInt32; cdecl;
111+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_NumSensors' {$ENDIF} {$ENDIF};
112+
113+
{**
114+
* \brief Get the implementation dependent name of a sensor.
115+
*
116+
* This can be called before any sensors are opened.
117+
*
118+
* \return The sensor name, or NIL if device_index is out of range.
119+
*}
120+
function SDL_SensorGetDeviceName(device_index: SInt32): PChar; cdecl;
121+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceName' {$ENDIF} {$ENDIF};
122+
123+
{**
124+
* \brief Get the type of a sensor.
125+
*
126+
* This can be called before any sensors are opened.
127+
*
128+
* \return The sensor type, or SDL_SENSOR_INVALID if device_index is out of range.
129+
*}
130+
function SDL_SensorGetDeviceType(device_index: SInt32): TSDL_SensorType; cdecl;
131+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceType' {$ENDIF} {$ENDIF};
132+
133+
{**
134+
* \brief Get the platform dependent type of a sensor.
135+
*
136+
* This can be called before any sensors are opened.
137+
*
138+
* \return The sensor platform dependent type, or -1 if device_index is out of range.
139+
*}
140+
function SDL_SensorGetDeviceNonPortableType(device_index: SInt32): SInt32; cdecl;
141+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceNonPortableType' {$ENDIF} {$ENDIF};
142+
143+
{**
144+
* \brief Get the instance ID of a sensor.
145+
*
146+
* This can be called before any sensors are opened.
147+
*
148+
* \return The sensor instance ID, or -1 if device_index is out of range.
149+
*}
150+
function SDL_SensorGetDeviceInstanceID(device_index: SInt32): TSDL_SensorID; cdecl;
151+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetDeviceInstanceID' {$ENDIF} {$ENDIF};
152+
153+
{**
154+
* \brief Open a sensor for use.
155+
*
156+
* The index passed as an argument refers to the N'th sensor on the system.
157+
*
158+
* \return A sensor identifier, or NIL if an error occurred.
159+
*}
160+
function SDL_SensorOpen(device_index: SInt32): PSDL_Sensor; cdecl;
161+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorOpen' {$ENDIF} {$ENDIF};
162+
163+
{**
164+
* Return the SDL_Sensor associated with an instance id.
165+
*}
166+
function SDL_SensorFromInstanceID(instance_id: TSDL_SensorID): PSDL_Sensor; cdecl;
167+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorFromInstanceID' {$ENDIF} {$ENDIF};
168+
169+
{**
170+
* \brief Get the implementation dependent name of a sensor.
171+
*
172+
* \return The sensor name, or NIL if the sensor is NIL.
173+
*}
174+
function SDL_SensorGetName(sensor: PSDL_Sensor): PChar; cdecl;
175+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetName' {$ENDIF} {$ENDIF};
176+
177+
{**
178+
* \brief Get the type of a sensor.
179+
*
180+
* This can be called before any sensors are opened.
181+
*
182+
* \return The sensor type, or SDL_SENSOR_INVALID if the sensor is NIL.
183+
*}
184+
function SDL_SensorGetType(sensor: PSDL_Sensor): TSDL_SensorType; cdecl;
185+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetType' {$ENDIF} {$ENDIF};
186+
187+
{**
188+
* \brief Get the platform dependent type of a sensor.
189+
*
190+
* This can be called before any sensors are opened.
191+
*
192+
* \return The sensor platform dependent type, or -1 if the sensor is NIL.
193+
*}
194+
function SDL_SensorGetNonPortableType(sensor: PSDL_Sensor): SInt32; cdecl;
195+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetNonPortableType' {$ENDIF} {$ENDIF};
196+
197+
{**
198+
* \brief Get the instance ID of a sensor.
199+
*
200+
* This can be called before any sensors are opened.
201+
*
202+
* \return The sensor instance ID, or -1 if the sensor is NIL.
203+
*}
204+
function SDL_SensorGetInstanceID(sensor: PSDL_Sensor): TSDL_SensorID; cdecl;
205+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetInstanceID' {$ENDIF} {$ENDIF};
206+
207+
{**
208+
* Get the current state of an opened sensor.
209+
*
210+
* The number of values and interpretation of the data is sensor dependent.
211+
*
212+
* \param sensor The sensor to query
213+
* \param data A pointer filled with the current sensor state
214+
* \param num_values The number of values to write to data
215+
*
216+
* \return 0 or -1 if an error occurred.
217+
*}
218+
function SDL_SensorGetData(sensor: PSDL_Sensor; data: PSingle; num_values: SInt32): SInt32; cdecl;
219+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorGetData' {$ENDIF} {$ENDIF};
220+
221+
{**
222+
* Close a sensor previously opened with SDL_SensorOpen()
223+
*}
224+
procedure SDL_SensorClose(sensor: PSDL_Sensor); cdecl;
225+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorClose' {$ENDIF} {$ENDIF};
226+
227+
{**
228+
* Update the current state of the open sensors.
229+
*
230+
* This is called automatically by the event loop if sensor events are enabled.
231+
*
232+
* This needs to be called from the thread that initialized the sensor subsystem.
233+
*}
234+
procedure SDL_SensorUpdate(); cdecl;
235+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SensorUpdate' {$ENDIF} {$ENDIF};

0 commit comments

Comments
 (0)