blib/lib/SDL2/sensor.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 51 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package SDL2::sensor 0.01 {
2 use SDL2::Utils;
3 #
4 use SDL2::stdinc;
5 use SDL2::error;
6  
7 package SDL2::Sensor {
8 use SDL2::Utils;
9 our $TYPE = has();
10 };
11 ffi->type( 'sint32' => 'SDL_SensorID' );
12 enum SDL_SensorType => [
13 [ SDL_SENSOR_INVALID => -1 ], qw[SDL_SENSOR_UNKNOWN
14 SDL_SENSOR_ACCEL
15 SDL_SENSOR_GYRO]
16 ];
17 define sensor => [ [ SDL_STANDARD_GRAVITY => 9.80665 ] ];
18 attach sensor => {
19 SDL_LockSensors => [ [] ],
20 SDL_UnlockSensors => [ [] ],
21 SDL_NumSensors => [ [], 'int' ],
22 SDL_SensorGetDeviceName => [ ['int'], 'string' ],
23 SDL_SensorGetDeviceType => [ ['int'], 'SDL_SensorType' ],
24 SDL_SensorGetDeviceNonPortableType => [ ['int'], 'int' ],
25 SDL_SensorGetDeviceInstanceID => [ ['int'], 'SDL_SensorID' ],
26 SDL_SensorOpen => [ ['int'], 'SDL_Sensor' ],
27 SDL_SensorFromInstanceID => [ ['SDL_SensorID'], 'SDL_Sensor' ],
28 SDL_SensorGetName => [ ['SDL_Sensor'], 'string' ],
29 SDL_SensorGetType => [ ['SDL_Sensor'], 'SDL_SensorType' ],
30 SDL_SensorGetNonPortableType => [ ['SDL_Sensor'], 'int' ],
31 SDL_SensorGetInstanceID => [ ['SDL_Sensor'], 'SDL_SensorID' ],
32 SDL_SensorGetData => [ [ 'SDL_Sensor', 'float*', 'int' ], 'int' ],
33 SDL_SensorClose => [ ['SDL_Sensor'] ],
34 SDL_SensorUpdate => [ [] ],
35 };
36  
37 =encoding utf-8
38  
39 =head1 NAME
40  
41 SDL2::sensor - SDL Sensor Event Handling
42  
43 =head1 SYNOPSIS
44  
45 use SDL2 qw[:sensor];
46  
47 =head1 DESCRIPTION
48  
49 In order to use these functions, C<SDL_Init( ... )> must have been called with
50 the C<SDL_INIT_SENSOR> flag. This causes SDL to scan the system for sensors,
51 and load appropriate drivers.
52  
53 =head1 Functions
54  
55 You may import these by name or with the C<:sensor> tag.
56  
57 =head2 C<SDL_LockSensors( )>
58  
59 Locking for multi-threaded access to the sensor API.
60  
61 If you are using the sensor API or handling events from multiple threads you
62 should use these locking functions to protect access to the sensors.
63  
64 In particular, you are guaranteed that the sensor list won't change, so the API
65 functions that take a sensor index will be valid, and sensor events will not be
66 delivered.
67  
68 =head2 C<SDL_UnlockSensors( )>
69  
70 Unlocking for multi-threaded access to the sensor API
71  
72 If you are using the sensor API or handling events from multiple threads you
73 should use these locking functions to protect access to the sensors.
74  
75 In particular, you are guaranteed that the sensor list won't change, so the API
76 functions that take a sensor index will be valid, and sensor events will not be
77 delivered.
78  
79 =head2 C<SDL_NumSensors( )>
80  
81 Count the number of sensors attached to the system right now.
82  
83 Returns the number of sensors detected.
84  
85 =head2 C<SDL_SensorGetDeviceName( ... )>
86  
87 Get the implementation dependent name of a sensor.
88  
89 Expected parameters include:
90  
91 =over
92  
93 =item C<device_index> - the sensor to obtain name from
94  
95 =back
96  
97 Returns The sensor name, or C<undef> if C<device_index> is out of range.
98  
99 =head2 C<SDL_SensorGetDeviceType( ... )>
100  
101 Get the type of a sensor.
102  
103 Expected parameters include:
104  
105 =over
106  
107 =item C<device_index> - the sensor to get the type from
108  
109 =back
110  
111 Returns the C<SDL_SensorType>, or C<SDL_SENSOR_INVALID> if C<device_index> is
112 out of range.
113  
114 =head2 C<SDL_SensorGetDeviceNonPortableType( ... )>
115  
116 Get the platform dependent type of a sensor.
117  
118 Expected parameters include:
119  
120 =over
121  
122 =item C<device_index> - the sensor to check
123  
124 =back
125  
126 Returns the sensor platform dependent type, or C<-1> if C<device_index> is out
127 of range.
128  
129 =head2 C<SDL_SensorGetDeviceInstanceID( ... )>
130  
131 Get the instance ID of a sensor.
132  
133 Expected parameters include:
134  
135 =over
136  
137 =item C<device_index> - the sensor to get instance id from
138  
139 =back
140  
141 Returns the sensor instance ID, or C<-1> if C<device_index> is out of range.
142  
143 =head2 C<SDL_SensorOpen( ... )>
144  
145 Open a sensor for use.
146  
147 Expected parameters include:
148  
149 =over
150  
151 =item C<device_index> - the sensor to open
152  
153 =back
154  
155 Returns an L<SDL2::Sensor> sensor object, or C<undef> if an error occurred.
156  
157 =head2 C<SDL_SensorFromInstanceID( ... )>
158  
159 Return the SDL_Sensor associated with an instance id.
160  
161 Expected parameters include:
162  
163 =over
164  
165 =item C<instance_id> - the sensor from instance id
166  
167 =back
168  
169 Returns an L<SDL2::Sensor> object.
170  
171 =head2 C<SDL_SensorGetName( ... )>
172  
173 Get the implementation dependent name of a sensor
174  
175 Expected parameters include:
176  
177 =over
178  
179 =item C<sensor> - the L<SDL2::Sensor> object
180  
181 =back
182  
183 Returns the sensor name, or C<undef> if C<sensor> is C<undef>.
184  
185 =head2 C<SDL_SensorGetType( ... )>
186 /**
187 * Get the type of a sensor.
188  
189 Expected parameters include:
190  
191 =over
192  
193 =item C<sensor> - the L<SDL2::Sensor> object to inspect
194  
195 =back
196  
197 Returns the C<SDL_SensorType> type, or C<SDL_SENSOR_INVALID> if C<sensor> is
198 C<undef>.
199  
200 =head2 C<SDL_SensorGetNonPortableType( ... )>
201  
202 Get the platform dependent type of a sensor.
203  
204 Expected parameters include:
205  
206 =over
207  
208 =item C<sensor> - the L<SDL2::Sensor> object to inspect
209  
210 =back
211  
212 Returns the sensor platform dependent type, or C<-1> if C<sensor> is C<undef>.
213  
214 =head2 C<SDL_SensorGetInstanceID( ... )>
215  
216 Get the instance ID of a sensor.
217  
218 Expected parameters include:
219  
220 =over
221  
222 =item C<sensor> - the L<SDL2::Sensor> object to inspect
223  
224 =back
225  
226 Returns the sensor instance ID, or C<-1> if C<sensor> is C<undef>.
227  
228 =head2 C<SDL_SensorGetData( ... )>
229  
230 Get the current state of an opened sensor.
231  
232 The number of values and interpretation of the data is sensor dependent.
233  
234 Expected parameters include:
235  
236 =over
237  
238 =item C<sensor> - the L<SDL2::Sensor> object to query
239  
240 =item C<data> - a pointer filled with the current sensor state
241  
242 =item C<num_values> - the number of values to write to data
243  
244 =back
245  
246 Returns C<0> or C<-1> if an error occurred.
247  
248 =head2 C<SDL_SensorClose( ... )>
249  
250 Close a sensor previously opened with L<< C<SDL_SensorOpen( ...
251 )>|/C<SDL_SensorOpen( ... )> >>.
252  
253 Expected parameters include:
254  
255 =over
256  
257 =item C<sensor> - the L<SDL2::Sensor> object to close
258  
259 =back
260  
261 =head2 C<SDL_SensorUpdate( )>
262  
263 Update the current state of the open sensors.
264  
265 This is called automatically by the event loop if sensor events are enabled.
266  
267 This needs to be called from the thread that initialized the sensor subsystem.
268  
269 =head1 Defined Types, Values, and Enumerations
270  
271 These may be imported by name or with the C<:sensor> tag.
272  
273 =head2 C<SDL_SensorID>
274  
275 This is a unique ID for a sensor for the time it is connected to the system,
276 and is never reused for the lifetime of the application.
277  
278 The ID value starts at C<0> and increments from there. The value C<-1> is an
279 invalid ID.
280  
281 =head2 C<SDL_SensorType>
282  
283 The different sensors defined by SDL.
284  
285 Additional sensors may be available, using platform dependent semantics.
286  
287 Here are the additional Android sensors:
288 L<https://developer.android.com/reference/android/hardware/SensorEvent.html#values>
289  
290 =over
291  
292 =item C<SDL_SENSOR_INVALID> - Returned for an invalid sensor
293  
294 =item C<SDL_SENSOR_UNKNOWN> - Unknown sensor type
295  
296 =item C<SDL_SENSOR_ACCEL> - Accelerometer
297  
298 =item C<SDL_SENSOR_GYRO> - Gyroscope
299  
300 =back
301  
302 =head2 C<SDL_STANDARD_GRAVITY>
303  
304 This is the standard value for gravitational acceleration.
305  
306 =head1 Accelerometer Sensor
307  
308 The accelerometer returns the current acceleration in SI meters per second
309 squared. This measurement includes the force of gravity, so a device at rest
310 will have an value of C<SDL_STANDARD_GRAVITY> away from the center of the
311 earth.
312  
313 values[0]: Acceleration on the x axis
314 values[1]: Acceleration on the y axis
315 values[2]: Acceleration on the z axis
316  
317 For phones held in portrait mode and game controllers held in front of you, the
318 axes are defined as follows:
319  
320 -X ... +X : left ... right
321 -Y ... +Y : bottom ... top
322 -Z ... +Z : farther ... closer
323  
324 The axis data is not changed when the phone is rotated.
325  
326 =head1 Gyroscope Sensor
327  
328 The gyroscope returns the current rate of rotation in radians per second. The
329 rotation is positive in the counter-clockwise direction. That is, an observer
330 looking from a positive location on one of the axes would see positive rotation
331 on that axis when it appeared to be rotating counter-clockwise.
332  
333 values[0]: Angular speed around the x axis (pitch)
334 values[1]: Angular speed around the y axis (yaw)
335 values[2]: Angular speed around the z axis (roll)
336  
337 For phones held in portrait mode and game controllers held in front of you, the
338 axes are defined as follows:
339  
340 -X ... +X : left ... right
341 -Y ... +Y : bottom ... top
342 -Z ... +Z : farther ... closer
343  
344 The axis data is not changed when the phone or controller is rotated.
345  
346 =head1 LICENSE
347  
348 Copyright (C) Sanko Robinson.
349  
350 This library is free software; you can redistribute it and/or modify it under
351 the terms found in the Artistic License 2. Other copyrights, terms, and
352 conditions may apply to data transmitted through this module.
353  
354 =head1 AUTHOR
355  
356 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
357  
358 =begin stopwords
359  
360 =end stopwords
361  
362 =cut
363  
364 };
365 1;