Skip to content

Commit fe4bea5

Browse files
Finish SDL_sensor.inc
1 parent 51c7561 commit fe4bea5

File tree

2 files changed

+284
-1
lines changed

2 files changed

+284
-1
lines changed

units/SDL3.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ interface
9191
{$I SDL_error.inc} // 3.1.6-prev
9292
{$I SDL_power.inc} // 3.1.6-prev
9393
{$I SDL_audio.inc} // 3.1.6-prev (unfinished)
94-
{$I SDL_sensor.inc} // 3.1.6-prev (unfinished)
94+
{$I SDL_sensor.inc} // 3.1.6-prev
9595
{$I SDL_mouse.inc} // 3.1.6-prev (unfinished)
9696
{$I SDL_keyboard.inc} // 3.1.6-prev (unfinished)
9797
{$I SDL_joystick.inc} // 3.1.6-prev (unfinished)

units/SDL_sensor.inc

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
{
2+
This file is part of:
3+
4+
SDL3 for Pascal
5+
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
6+
SPDX-License-Identifier: Zlib
7+
}
8+
9+
{*
10+
* # CategorySensor
11+
*
12+
* SDL sensor management.
13+
*
14+
* In order to use these functions, SDL_Init() must have been called with the
15+
* SDL_INIT_SENSOR flag. This causes SDL to scan the system for sensors, and
16+
* load appropriate drivers.
17+
}
18+
19+
type
20+
PPSDL_Sensor = ^PSDL_Sensor;
21+
PSDL_Sensor = type Pointer;
22+
123
{*
224
* This is a unique ID for a sensor for the time it is connected to the
325
* system, and is never reused for the lifetime of the application.
@@ -11,3 +33,264 @@ type
1133
PSDL_SensorID = ^TSDL_SensorID;
1234
TSDL_SensorID = cuint32;
1335

36+
{*
37+
* A constant to represent standard gravity for accelerometer sensors.
38+
*
39+
* The accelerometer returns the current acceleration in SI meters per second
40+
* squared. This measurement includes the force of gravity, so a device at
41+
* rest will have an value of SDL_STANDARD_GRAVITY away from the center of the
42+
* earth, which is a positive Y value.
43+
*
44+
* \since This macro is available since SDL 3.1.3.
45+
}
46+
const
47+
SDL_STANDARD_GRAVITY = cfloat(9.80665);
48+
49+
{*
50+
* The different sensors defined by SDL.
51+
*
52+
* Additional sensors may be available, using platform dependent semantics.
53+
*
54+
* Here are the additional Android sensors:
55+
*
56+
* https://developer.android.com/reference/android/hardware/SensorEvent.html#values
57+
*
58+
* Accelerometer sensor notes:
59+
*
60+
* The accelerometer returns the current acceleration in SI meters per second
61+
* squared. This measurement includes the force of gravity, so a device at
62+
* rest will have an value of SDL_STANDARD_GRAVITY away from the center of the
63+
* earth, which is a positive Y value.
64+
*
65+
* - `values[0]`: Acceleration on the x axis
66+
* - `values[1]`: Acceleration on the y axis
67+
* - `values[2]`: Acceleration on the z axis
68+
*
69+
* For phones and tablets held in natural orientation and game controllers
70+
* held in front of you, the axes are defined as follows:
71+
*
72+
* - -X ... +X: left ... right
73+
* - -Y ... +Y: bottom ... top
74+
* - -Z ... +Z: farther ... closer
75+
*
76+
* The accelerometer axis data is not changed when the device is rotated.
77+
*
78+
* Gyroscope sensor notes:
79+
*
80+
* The gyroscope returns the current rate of rotation in radians per second.
81+
* The rotation is positive in the counter-clockwise direction. That is, an
82+
* observer looking from a positive location on one of the axes would see
83+
* positive rotation on that axis when it appeared to be rotating
84+
* counter-clockwise.
85+
*
86+
* - `values[0]`: Angular speed around the x axis (pitch)
87+
* - `values[1]`: Angular speed around the y axis (yaw)
88+
* - `values[2]`: Angular speed around the z axis (roll)
89+
*
90+
* For phones and tablets held in natural orientation and game controllers
91+
* held in front of you, the axes are defined as follows:
92+
*
93+
* - -X ... +X: left ... right
94+
* - -Y ... +Y: bottom ... top
95+
* - -Z ... +Z: farther ... closer
96+
*
97+
* The gyroscope axis data is not changed when the device is rotated.
98+
*
99+
* \since This enum is available since SDL 3.1.3.
100+
*
101+
* \sa SDL_GetCurrentDisplayOrientation
102+
}
103+
type
104+
PPSDL_SensorType = ^PSDL_SensorType;
105+
PSDL_SensorType = ^TSDL_SensorType;
106+
TSDL_SensorType = type Integer;
107+
const
108+
SDL_SENSOR_INVALID = TSDL_SensorType(-1); {*< Returned for an invalid sensor }
109+
SDL_SENSOR_UNKNOWN = TSDL_SensorType(0); {*< Unknown sensor type }
110+
SDL_SENSOR_ACCEL = TSDL_SensorType(1); {*< Accelerometer }
111+
SDL_SENSOR_GYRO = TSDL_SensorType(2); {*< Gyroscope }
112+
SDL_SENSOR_ACCEL_L = TSDL_SensorType(3); {*< Accelerometer for left Joy-Con controller and Wii nunchuk }
113+
SDL_SENSOR_GYRO_L = TSDL_SensorType(4); {*< Gyroscope for left Joy-Con controller }
114+
SDL_SENSOR_ACCEL_R = TSDL_SensorType(5); {*< Accelerometer for right Joy-Con controller }
115+
SDL_SENSOR_GYRO_R = TSDL_SensorType(6); {*< Gyroscope for right Joy-Con controller }
116+
117+
{ Function prototypes }
118+
119+
{*
120+
* Get a list of currently connected sensors.
121+
*
122+
* \param count a Pointer filled in with the number of sensors returned, may
123+
* be nil.
124+
* \returns a 0 terminated array of sensor instance IDs or nil on failure;
125+
* call SDL_GetError() for more information. This should be freed
126+
* with SDL_free() when it is no longer needed.
127+
*
128+
* \since This function is available since SDL 3.1.3.
129+
}
130+
function SDL_GetSensors(count: pcint): PSDL_SensorID; cdecl;
131+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensors' {$ENDIF} {$ENDIF};
132+
133+
{*
134+
* Get the implementation dependent name of a sensor.
135+
*
136+
* This can be called before any sensors are opened.
137+
*
138+
* \param instance_id the sensor instance ID.
139+
* \returns the sensor name, or nil if `instance_id` is not valid.
140+
*
141+
* \since This function is available since SDL 3.1.3.
142+
}
143+
function SDL_GetSensorNameForID(instance_id: TSDL_SensorID): PAnsiChar; cdecl;
144+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorNameForID' {$ENDIF} {$ENDIF};
145+
146+
{*
147+
* Get the type of a sensor.
148+
*
149+
* This can be called before any sensors are opened.
150+
*
151+
* \param instance_id the sensor instance ID.
152+
* \returns the SDL_SensorType, or `SDL_SENSOR_INVALID` if `instance_id` is
153+
* not valid.
154+
*
155+
* \since This function is available since SDL 3.1.3.
156+
}
157+
function SDL_GetSensorTypeForID(instance_id: TSDL_SensorID): TSDL_SensorType; cdecl;
158+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorTypeForID' {$ENDIF} {$ENDIF};
159+
160+
{*
161+
* Get the platform dependent type of a sensor.
162+
*
163+
* This can be called before any sensors are opened.
164+
*
165+
* \param instance_id the sensor instance ID.
166+
* \returns the sensor platform dependent type, or -1 if `instance_id` is not
167+
* valid.
168+
*
169+
* \since This function is available since SDL 3.1.3.
170+
}
171+
function SDL_GetSensorNonPortableTypeForID(instance_id: TSDL_SensorID): cint; cdecl;
172+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorNonPortableTypeForID' {$ENDIF} {$ENDIF};
173+
174+
{*
175+
* Open a sensor for use.
176+
*
177+
* \param instance_id the sensor instance ID.
178+
* \returns an SDL_Sensor object or nil on failure; call SDL_GetError() for
179+
* more information.
180+
*
181+
* \since This function is available since SDL 3.1.3.
182+
}
183+
function SDL_OpenSensor(instance_id: TSDL_SensorID): PSDL_Sensor; cdecl;
184+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_OpenSensor' {$ENDIF} {$ENDIF};
185+
186+
{*
187+
* Return the SDL_Sensor associated with an instance ID.
188+
*
189+
* \param instance_id the sensor instance ID.
190+
* \returns an SDL_Sensor object or nil on failure; call SDL_GetError() for
191+
* more information.
192+
*
193+
* \since This function is available since SDL 3.1.3.
194+
}
195+
function SDL_GetSensorFromID(instance_id: TSDL_SensorID): PSDL_Sensor; cdecl;
196+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorFromID' {$ENDIF} {$ENDIF};
197+
198+
{*
199+
* Get the properties associated with a sensor.
200+
*
201+
* \param sensor the SDL_Sensor object.
202+
* \returns a valid property ID on success or 0 on failure; call
203+
* SDL_GetError() for more information.
204+
*
205+
* \since This function is available since SDL 3.1.3.
206+
}
207+
function SDL_GetSensorProperties(sensor: PSDL_Sensor): TSDL_PropertiesID; cdecl;
208+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorProperties' {$ENDIF} {$ENDIF};
209+
210+
{*
211+
* Get the implementation dependent name of a sensor.
212+
*
213+
* \param sensor the SDL_Sensor object.
214+
* \returns the sensor name or nil on failure; call SDL_GetError() for more
215+
* information.
216+
*
217+
* \since This function is available since SDL 3.1.3.
218+
}
219+
function SDL_GetSensorName(sensor: PSDL_Sensor): PAnsiChar; cdecl;
220+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorName' {$ENDIF} {$ENDIF};
221+
222+
{*
223+
* Get the type of a sensor.
224+
*
225+
* \param sensor the SDL_Sensor object to inspect.
226+
* \returns the SDL_SensorType type, or `SDL_SENSOR_INVALID` if `sensor` is
227+
* nil.
228+
*
229+
* \since This function is available since SDL 3.1.3.
230+
}
231+
function SDL_GetSensorType(sensor: PSDL_Sensor): TSDL_SensorType; cdecl;
232+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorType' {$ENDIF} {$ENDIF};
233+
234+
{*
235+
* Get the platform dependent type of a sensor.
236+
*
237+
* \param sensor the SDL_Sensor object to inspect.
238+
* \returns the sensor platform dependent type, or -1 if `sensor` is nil.
239+
*
240+
* \since This function is available since SDL 3.1.3.
241+
}
242+
function SDL_GetSensorNonPortableType(sensor: PSDL_Sensor): cint; cdecl;
243+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorNonPortableType' {$ENDIF} {$ENDIF};
244+
245+
{*
246+
* Get the instance ID of a sensor.
247+
*
248+
* \param sensor the SDL_Sensor object to inspect.
249+
* \returns the sensor instance ID, or 0 on failure; call SDL_GetError() for
250+
* more information.
251+
*
252+
* \since This function is available since SDL 3.1.3.
253+
}
254+
function SDL_GetSensorID(sensor: PSDL_Sensor): TSDL_SensorID; cdecl;
255+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorID' {$ENDIF} {$ENDIF};
256+
257+
{*
258+
* Get the current state of an opened sensor.
259+
*
260+
* The number of values and interpretation of the data is sensor dependent.
261+
*
262+
* \param sensor the SDL_Sensor object to query.
263+
* \param data a Pointer filled with the current sensor state.
264+
* \param num_values the number of values to write to data.
265+
* \returns true on success or false on failure; call SDL_GetError() for more
266+
* information.
267+
*
268+
* \since This function is available since SDL 3.1.3.
269+
}
270+
function SDL_GetSensorData(sensor: PSDL_Sensor; data: pcfloat; num_values: cint): cbool; cdecl;
271+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSensorData' {$ENDIF} {$ENDIF};
272+
273+
{*
274+
* Close a sensor previously opened with SDL_OpenSensor().
275+
*
276+
* \param sensor the SDL_Sensor object to close.
277+
*
278+
* \since This function is available since SDL 3.1.3.
279+
}
280+
procedure SDL_CloseSensor(sensor: PSDL_Sensor); cdecl;
281+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CloseSensor' {$ENDIF} {$ENDIF};
282+
283+
{*
284+
* Update the current state of the open sensors.
285+
*
286+
* This is called automatically by the event loop if sensor events are
287+
* enabled.
288+
*
289+
* This needs to be called from the thread that initialized the sensor
290+
* subsystem.
291+
*
292+
* \since This function is available since SDL 3.1.3.
293+
}
294+
procedure SDL_UpdateSensors; cdecl;
295+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UpdateSensors' {$ENDIF} {$ENDIF};
296+

0 commit comments

Comments
 (0)