1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef ANDROID_SENSORS_INTERFACE_H
18 #define ANDROID_SENSORS_INTERFACE_H
19
20 #include <stdint.h>
21 #include <sys/cdefs.h>
22 #include <sys/types.h>
23
24 #include <hardware/hardware.h>
25 #include <cutils/native_handle.h>
26
27 __BEGIN_DECLS
28
29 /*****************************************************************************/
30
31 #define SENSORS_HEADER_VERSION 1
32 #define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
33 #define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION)
34 #define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION)
35 #define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION)
36 #define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION)
37 #define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION)
38
39 /**
40 * Please see the Sensors section of source.android.com for an
41 * introduction to and detailed descriptions of Android sensor types:
42 * http://source.android.com/devices/sensors/index.html
43 */
44
45 /**
46 * The id of this module
47 */
48 #define SENSORS_HARDWARE_MODULE_ID "sensors"
49
50 /**
51 * Name of the sensors device to open
52 */
53 #define SENSORS_HARDWARE_POLL "poll"
54
55 /**
56 * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
57 * A Handle identifies a given sensors. The handle is used to activate
58 * and/or deactivate sensors.
59 * In this version of the API there can only be 256 handles.
60 */
61 #define SENSORS_HANDLE_BASE 0
62 #define SENSORS_HANDLE_BITS 8
63 #define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
64
65
66 /*
67 * **** Deprecated *****
68 * flags for (*batch)()
69 * Availability: SENSORS_DEVICE_API_VERSION_1_0
70 * see (*batch)() documentation for details.
71 * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3.
72 * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept.
73 */
74 enum {
75 SENSORS_BATCH_DRY_RUN = 0x00000001,
76 SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
77 };
78
79 /*
80 * what field for meta_data_event_t
81 */
82 enum {
83 /* a previous flush operation has completed */
84 META_DATA_FLUSH_COMPLETE = 1,
85 META_DATA_VERSION /* always last, leave auto-assigned */
86 };
87
88 /*
89 * The permission to use for body sensors (like heart rate monitors).
90 * See sensor types for more details on what sensors should require this
91 * permission.
92 */
93 #define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS"
94
95 /*
96 * Availability: SENSORS_DEVICE_API_VERSION_1_3
97 * Sensor flags used in sensor_t.flags.
98 */
99 enum {
100 /*
101 * Whether this sensor wakes up the AP from suspend mode when data is available. Whenever
102 * sensor events are delivered from a wake_up sensor, the driver needs to hold a wake_lock till
103 * the events are read by the SensorService i.e till sensors_poll_device_t.poll() is called the
104 * next time. Once poll is called again it means events have been read by the SensorService, the
105 * driver can safely release the wake_lock. SensorService will continue to hold a wake_lock till
106 * the app actually reads the events.
107 */
108 SENSOR_FLAG_WAKE_UP = 1U << 0,
109 /*
110 * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
111 * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
112 * modes.
113 */
114 SENSOR_FLAG_CONTINUOUS_MODE = 0, // 0000
115 SENSOR_FLAG_ON_CHANGE_MODE = 0x2, // 0010
116 SENSOR_FLAG_ONE_SHOT_MODE = 0x4, // 0100
117 SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6 // 0110
118 };
119
120 /*
121 * Mask and shift for reporting mode sensor flags defined above.
122 */
123 #define REPORTING_MODE_MASK (0xE)
124 #define REPORTING_MODE_SHIFT (1)
125
126 /*
127 * Sensor type
128 *
129 * Each sensor has a type which defines what this sensor measures and how
130 * measures are reported. See the Base sensors and Composite sensors lists
131 * for complete descriptions:
132 * http://source.android.com/devices/sensors/base_triggers.html
133 * http://source.android.com/devices/sensors/composite_sensors.html
134 *
135 * Device manufacturers (OEMs) can define their own sensor types, for
136 * their private use by applications or services provided by them. Such
137 * sensor types are specific to an OEM and can't be exposed in the SDK.
138 * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE.
139 *
140 * All sensors defined outside of the device private range must correspond to
141 * a type defined in this file, and must satisfy the characteristics listed in
142 * the description of the sensor type.
143 *
144 * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also
145 * has a stringType.
146 * - StringType of sensors inside of the device private range MUST be prefixed
147 * by the sensor provider's or OEM reverse domain name. In particular, they
148 * cannot use the "android.sensor" prefix.
149 * - StringType of sensors outside of the device private range MUST correspond
150 * to the one defined in this file (starting with "android.sensor").
151 * For example, accelerometers must have
152 * type=SENSOR_TYPE_ACCELEROMETER and
153 * stringType=SENSOR_STRING_TYPE_ACCELEROMETER
154 *
155 * When android introduces a new sensor type that can replace an OEM-defined
156 * sensor type, the OEM must use the official sensor type and stringType on
157 * versions of the HAL that support this new official sensor type.
158 *
159 * Example (made up): Suppose Google's Glass team wants to surface a sensor
160 * detecting that Glass is on a head.
161 * - Such a sensor is not officially supported in android KitKat
162 * - Glass devices launching on KitKat can implement a sensor with
163 * type = 0x10001 and stringType = "com.google.glass.onheaddetector"
164 * - In L android release, if android decides to define
165 * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR,
166 * those types should replace the Glass-team-specific types in all future
167 * launches.
168 * - When launching Glass on the L release, Google should now use the official
169 * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType.
170 * - This way, all applications can now use this sensor.
171 */
172
173 /*
174 * Base for device manufacturers private sensor types.
175 * These sensor types can't be exposed in the SDK.
176 */
177 #define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000
178
179 /*
180 * SENSOR_TYPE_META_DATA
181 * reporting-mode: n/a
182 * wake-up sensor: n/a
183 *
184 * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
185 *
186 * SENSOR_TYPE_META_DATA is a special token used to populate the
187 * sensors_meta_data_event structure. It doesn't correspond to a physical
188 * sensor. sensors_meta_data_event are special, they exist only inside
189 * the HAL and are generated spontaneously, as opposed to be related to
190 * a physical sensor.
191 *
192 * sensors_meta_data_event_t.version must be META_DATA_VERSION
193 * sensors_meta_data_event_t.sensor must be 0
194 * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA
195 * sensors_meta_data_event_t.reserved must be 0
196 * sensors_meta_data_event_t.timestamp must be 0
197 *
198 * The payload is a meta_data_event_t, where:
199 * meta_data_event_t.what can take the following values:
200 *
201 * META_DATA_FLUSH_COMPLETE
202 * This event indicates that a previous (*flush)() call has completed for the sensor
203 * handle specified in meta_data_event_t.sensor.
204 * see (*flush)() for more details
205 *
206 * All other values for meta_data_event_t.what are reserved and
207 * must not be used.
208 *
209 */
210 #define SENSOR_TYPE_META_DATA (0)
211
212 /*
213 * Wake up sensors.
214 * Each sensor may have either or both a wake-up and a non-wake variant.
215 * When registered in batch mode, wake-up sensors will wake up the AP when
216 * their FIFOs are full or when the batch timeout expires. A separate FIFO has
217 * to be maintained for wake up sensors and non wake up sensors. The non wake-up
218 * sensors need to overwrite their FIFOs when they are full till the AP wakes up
219 * and the wake-up sensors will wake-up the AP when their FIFOs are full or when
220 * the batch timeout expires without losing events. Wake-up and non wake-up variants
221 * of each sensor can be activated at different rates independently of each other.
222 *
223 * Note: Proximity sensor and significant motion sensor which were defined in previous
224 * releases are also wake-up sensors and should be treated as such. Wake-up one-shot
225 * sensors like SIGNIFICANT_MOTION cannot be batched, hence the text about batch above
226 * doesn't apply to them. See the definitions of SENSOR_TYPE_PROXIMITY and
227 * SENSOR_TYPE_SIGNIFICANT_MOTION for more info.
228 *
229 * Set SENSOR_FLAG_WAKE_UP flag for all wake-up sensors.
230 *
231 * For example, A device can have two sensors both of SENSOR_TYPE_ACCELEROMETER and
232 * one of them can be a wake_up sensor (with SENSOR_FLAG_WAKE_UP flag set) and the other
233 * can be a regular non wake_up sensor. Both of these sensors must be activated/deactivated
234 * independently of the other.
235 */
236
237 /*
238 * SENSOR_TYPE_ACCELEROMETER
239 * reporting-mode: continuous
240 *
241 * All values are in SI units (m/s^2) and measure the acceleration of the
242 * device minus the force of gravity.
243 *
244 * Implement the non-wake-up version of this sensor and implement the wake-up
245 * version if the system possesses a wake up fifo.
246 */
247 #define SENSOR_TYPE_ACCELEROMETER (1)
248 #define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer"
249
250 /*
251 * SENSOR_TYPE_GEOMAGNETIC_FIELD
252 * reporting-mode: continuous
253 *
254 * All values are in micro-Tesla (uT) and measure the geomagnetic
255 * field in the X, Y and Z axis.
256 *
257 * Implement the non-wake-up version of this sensor and implement the wake-up
258 * version if the system possesses a wake up fifo.
259 */
260 #define SENSOR_TYPE_GEOMAGNETIC_FIELD (2)
261 #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
262 #define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field"
263
264 /*
265 * SENSOR_TYPE_ORIENTATION
266 * reporting-mode: continuous
267 *
268 * All values are angles in degrees.
269 *
270 * Orientation sensors return sensor events for all 3 axes at a constant
271 * rate defined by setDelay().
272 *
273 * Implement the non-wake-up version of this sensor and implement the wake-up
274 * version if the system possesses a wake up fifo.
275 */
276 #define SENSOR_TYPE_ORIENTATION (3)
277 #define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation"
278
279 /*
280 * SENSOR_TYPE_GYROSCOPE
281 * reporting-mode: continuous
282 *
283 * All values are in radians/second and measure the rate of rotation
284 * around the X, Y and Z axis.
285 *
286 * Implement the non-wake-up version of this sensor and implement the wake-up
287 * version if the system possesses a wake up fifo.
288 */
289 #define SENSOR_TYPE_GYROSCOPE (4)
290 #define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope"
291
292 /*
293 * SENSOR_TYPE_LIGHT
294 * reporting-mode: on-change
295 *
296 * The light sensor value is returned in SI lux units.
297 *
298 * Both wake-up and non wake-up versions are useful.
299 */
300 #define SENSOR_TYPE_LIGHT (5)
301 #define SENSOR_STRING_TYPE_LIGHT "android.sensor.light"
302
303 /*
304 * SENSOR_TYPE_PRESSURE
305 * reporting-mode: continuous
306 *
307 * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
308 *
309 * Implement the non-wake-up version of this sensor and implement the wake-up
310 * version if the system possesses a wake up fifo.
311 */
312 #define SENSOR_TYPE_PRESSURE (6)
313 #define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure"
314
315 /* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
316 #define SENSOR_TYPE_TEMPERATURE (7)
317 #define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature"
318
319 /*
320 * SENSOR_TYPE_PROXIMITY
321 * reporting-mode: on-change
322 *
323 * The proximity sensor which turns the screen off and back on during calls is the
324 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
325 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
326 * SENSOR_FLAG_WAKE_UP.
327 * The value corresponds to the distance to the nearest object in centimeters.
328 */
329 #define SENSOR_TYPE_PROXIMITY (8)
330 #define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity"
331
332 /*
333 * SENSOR_TYPE_GRAVITY
334 * reporting-mode: continuous
335 *
336 * A gravity output indicates the direction of and magnitude of gravity in
337 * the devices's coordinates.
338 *
339 * Implement the non-wake-up version of this sensor and implement the wake-up
340 * version if the system possesses a wake up fifo.
341 */
342 #define SENSOR_TYPE_GRAVITY (9)
343 #define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity"
344
345 /*
346 * SENSOR_TYPE_LINEAR_ACCELERATION
347 * reporting-mode: continuous
348 *
349 * Indicates the linear acceleration of the device in device coordinates,
350 * not including gravity.
351 *
352 * Implement the non-wake-up version of this sensor and implement the wake-up
353 * version if the system possesses a wake up fifo.
354 */
355 #define SENSOR_TYPE_LINEAR_ACCELERATION (10)
356 #define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration"
357
358
359 /*
360 * SENSOR_TYPE_ROTATION_VECTOR
361 * reporting-mode: continuous
362 *
363 * The rotation vector symbolizes the orientation of the device relative to the
364 * East-North-Up coordinates frame.
365 *
366 * Implement the non-wake-up version of this sensor and implement the wake-up
367 * version if the system possesses a wake up fifo.
368 */
369 #define SENSOR_TYPE_ROTATION_VECTOR (11)
370 #define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector"
371
372 /*
373 * SENSOR_TYPE_RELATIVE_HUMIDITY
374 * reporting-mode: on-change
375 *
376 * A relative humidity sensor measures relative ambient air humidity and
377 * returns a value in percent.
378 *
379 * Both wake-up and non wake-up versions are useful.
380 */
381 #define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
382 #define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity"
383
384 /*
385 * SENSOR_TYPE_AMBIENT_TEMPERATURE
386 * reporting-mode: on-change
387 *
388 * The ambient (room) temperature in degree Celsius.
389 *
390 * Both wake-up and non wake-up versions are useful.
391 */
392 #define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
393 #define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature"
394
395 /*
396 * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
397 * reporting-mode: continuous
398 *
399 * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
400 * reported separately instead of being included in the measurement.
401 *
402 * Implement the non-wake-up version of this sensor and implement the wake-up
403 * version if the system possesses a wake up fifo.
404 */
405 #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
406 #define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated"
407
408 /*
409 * SENSOR_TYPE_GAME_ROTATION_VECTOR
410 * reporting-mode: continuous
411 *
412 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
413 * field.
414 *
415 * Implement the non-wake-up version of this sensor and implement the wake-up
416 * version if the system possesses a wake up fifo.
417 */
418 #define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
419 #define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector"
420
421 /*
422 * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
423 * reporting-mode: continuous
424 *
425 * All values are in radians/second and measure the rate of rotation
426 * around the X, Y and Z axis.
427 *
428 * Implement the non-wake-up version of this sensor and implement the wake-up
429 * version if the system possesses a wake up fifo.
430 */
431 #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
432 #define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated"
433
434 /*
435 * SENSOR_TYPE_SIGNIFICANT_MOTION
436 * reporting-mode: one-shot
437 *
438 * A sensor of this type triggers an event each time significant motion
439 * is detected and automatically disables itself.
440 * For Significant Motion sensor to be useful, it must be defined as a
441 * wake-up sensor. (set SENSOR_FLAG_WAKE_UP). Implement the wake-up significant motion
442 * sensor. A non wake-up version is not useful.
443 * The only allowed value to return is 1.0.
444 */
445
446 #define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
447 #define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion"
448
449 /*
450 * SENSOR_TYPE_STEP_DETECTOR
451 * reporting-mode: special
452 *
453 * A sensor of this type triggers an event each time a step is taken
454 * by the user. The only allowed value to return is 1.0 and an event
455 * is generated for each step.
456 *
457 * Both wake-up and non wake-up versions are useful.
458 */
459
460 #define SENSOR_TYPE_STEP_DETECTOR (18)
461 #define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector"
462
463
464 /*
465 * SENSOR_TYPE_STEP_COUNTER
466 * reporting-mode: on-change
467 *
468 * A sensor of this type returns the number of steps taken by the user since
469 * the last reboot while activated. The value is returned as a uint64_t and is
470 * reset to zero only on a system / android reboot.
471 *
472 * Implement the non-wake-up version of this sensor and implement the wake-up
473 * version if the system possesses a wake up fifo.
474 */
475
476 #define SENSOR_TYPE_STEP_COUNTER (19)
477 #define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter"
478
479 /*
480 * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
481 * reporting-mode: continuous
482 *
483 * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
484 * of using a gyroscope.
485 *
486 * Implement the non-wake-up version of this sensor and implement the wake-up
487 * version if the system possesses a wake up fifo.
488 */
489 #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)
490 #define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector"
491
492 /*
493 * SENSOR_TYPE_HEART_RATE
494 * reporting-mode: on-change
495 *
496 * A sensor of this type returns the current heart rate.
497 * The events contain the current heart rate in beats per minute (BPM) and the
498 * status of the sensor during the measurement. See heart_rate_event_t for more
499 * details.
500 *
501 * Because this sensor is on-change, events must be generated when and only
502 * when heart_rate.bpm or heart_rate.status have changed since the last
503 * event. In particular, upon the first activation, unless the device is known
504 * to not be on the body, the status field of the first event must be set to
505 * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every
506 * period_ns passed to setDelay() or to batch().
507 * See the definition of the on-change reporting mode for more information.
508 *
509 * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
510 *
511 * Both wake-up and non wake-up versions are useful.
512 */
513 #define SENSOR_TYPE_HEART_RATE (21)
514 #define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate"
515
516 /*
517 * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
518 * reporting-mode: special (setDelay has no impact)
519 *
520 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
521 * should be generated if the direction of the 2-seconds window average gravity changed by at least
522 * 35 degrees since the activation or the last trigger of the sensor.
523 * reference_estimated_gravity = average of accelerometer measurements over the first
524 * 1 second after activation or the estimated gravity at the last
525 * trigger.
526 * current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
527 * trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
528 *
529 * Large accelerations without a change in phone orientation should not trigger a tilt event.
530 * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
531 * event, even though the angle of the average acceleration might vary by more than 35 degrees.
532 *
533 * Typically, this sensor is implemented with the help of only an accelerometer. Other sensors can
534 * be used as well if they do not increase the power consumption significantly. This is a low power
535 * sensor that should allow the AP to go into suspend mode. Do not emulate this sensor in the HAL.
536 * Like other wake up sensors, the driver is expected to a hold a wake_lock with a timeout of 200 ms
537 * while reporting this event. The only allowed return value is 1.0.
538 *
539 * Implement only the wake-up version of this sensor.
540 */
541 #define SENSOR_TYPE_TILT_DETECTOR (22)
542 #define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector"
543
544 /*
545 * SENSOR_TYPE_WAKE_GESTURE
546 * reporting-mode: one-shot
547 *
548 * A sensor enabling waking up the device based on a device specific motion.
549 *
550 * When this sensor triggers, the device behaves as if the power button was
551 * pressed, turning the screen on. This behavior (turning on the screen when
552 * this sensor triggers) might be deactivated by the user in the device
553 * settings. Changes in settings do not impact the behavior of the sensor:
554 * only whether the framework turns the screen on when it triggers.
555 *
556 * The actual gesture to be detected is not specified, and can be chosen by
557 * the manufacturer of the device.
558 * This sensor must be low power, as it is likely to be activated 24/7.
559 * The only allowed value to return is 1.0.
560 *
561 * Implement only the wake-up version of this sensor.
562 */
563 #define SENSOR_TYPE_WAKE_GESTURE (23)
564 #define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture"
565
566 /*
567 * SENSOR_TYPE_GLANCE_GESTURE
568 * reporting-mode: one-shot
569 *
570 * A sensor enabling briefly turning the screen on to enable the user to
571 * glance content on screen based on a specific motion. The device should
572 * turn the screen off after a few moments.
573 *
574 * When this sensor triggers, the device turns the screen on momentarily
575 * to allow the user to glance notifications or other content while the
576 * device remains locked in a non-interactive state (dozing). This behavior
577 * (briefly turning on the screen when this sensor triggers) might be deactivated
578 * by the user in the device settings. Changes in settings do not impact the
579 * behavior of the sensor: only whether the framework briefly turns the screen on
580 * when it triggers.
581 *
582 * The actual gesture to be detected is not specified, and can be chosen by
583 * the manufacturer of the device.
584 * This sensor must be low power, as it is likely to be activated 24/7.
585 * The only allowed value to return is 1.0.
586 *
587 * Implement only the wake-up version of this sensor.
588 */
589 #define SENSOR_TYPE_GLANCE_GESTURE (24)
590 #define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture"
591
592 /**
593 * SENSOR_TYPE_PICK_UP_GESTURE
594 * reporting-mode: one-shot
595 *
596 * A sensor of this type triggers when the device is picked up regardless of wherever is was
597 * before (desk, pocket, bag). The only allowed return value is 1.0.
598 * This sensor de-activates itself immediately after it triggers.
599 *
600 * Implement only the wake-up version of this sensor.
601 */
602 #define SENSOR_TYPE_PICK_UP_GESTURE (25)
603 #define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture"
604
605 /**
606 * Values returned by the accelerometer in various locations in the universe.
607 * all values are in SI units (m/s^2)
608 */
609 #define GRAVITY_SUN (275.0f)
610 #define GRAVITY_EARTH (9.80665f)
611
612 /** Maximum magnetic field on Earth's surface */
613 #define MAGNETIC_FIELD_EARTH_MAX (60.0f)
614
615 /** Minimum magnetic field on Earth's surface */
616 #define MAGNETIC_FIELD_EARTH_MIN (30.0f)
617
618 /**
619 * Possible values of the status field of sensor events.
620 */
621 #define SENSOR_STATUS_NO_CONTACT -1
622 #define SENSOR_STATUS_UNRELIABLE 0
623 #define SENSOR_STATUS_ACCURACY_LOW 1
624 #define SENSOR_STATUS_ACCURACY_MEDIUM 2
625 #define SENSOR_STATUS_ACCURACY_HIGH 3
626
627 /**
628 * sensor event data
629 */
630 typedef struct {
631 union {
632 float v[3];
633 struct {
634 float x;
635 float y;
636 float z;
637 };
638 struct {
639 float azimuth;
640 float pitch;
641 float roll;
642 };
643 };
644 int8_t status;
645 uint8_t reserved[3];
646 } sensors_vec_t;
647
648 /**
649 * uncalibrated gyroscope and magnetometer event data
650 */
651 typedef struct {
652 union {
653 float uncalib[3];
654 struct {
655 float x_uncalib;
656 float y_uncalib;
657 float z_uncalib;
658 };
659 };
660 union {
661 float bias[3];
662 struct {
663 float x_bias;
664 float y_bias;
665 float z_bias;
666 };
667 };
668 } uncalibrated_event_t;
669
670 /**
671 * Meta data event data
672 */
673 typedef struct meta_data_event {
674 int32_t what;
675 int32_t sensor;
676 } meta_data_event_t;
677
678 /**
679 * Heart rate event data
680 */
681 typedef struct {
682 // Heart rate in beats per minute.
683 // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
684 float bpm;
685 // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
686 // Note that this value should only be set for sensors that explicitly define
687 // the meaning of this field. This field is not piped through the framework
688 // for other sensors.
689 int8_t status;
690 } heart_rate_event_t;
691
692 /**
693 * Union of the various types of sensor data
694 * that can be returned.
695 */
696 typedef struct sensors_event_t {
697 /* must be sizeof(struct sensors_event_t) */
698 int32_t version;
699
700 /* sensor identifier */
701 int32_t sensor;
702
703 /* sensor type */
704 int32_t type;
705
706 /* reserved */
707 int32_t reserved0;
708
709 /* time is in nanosecond */
710 int64_t timestamp;
711
712 union {
713 union {
714 float data[16];
715
716 /* acceleration values are in meter per second per second (m/s^2) */
717 sensors_vec_t acceleration;
718
719 /* magnetic vector values are in micro-Tesla (uT) */
720 sensors_vec_t magnetic;
721
722 /* orientation values are in degrees */
723 sensors_vec_t orientation;
724
725 /* gyroscope values are in rad/s */
726 sensors_vec_t gyro;
727
728 /* temperature is in degrees centigrade (Celsius) */
729 float temperature;
730
731 /* distance in centimeters */
732 float distance;
733
734 /* light in SI lux units */
735 float light;
736
737 /* pressure in hectopascal (hPa) */
738 float pressure;
739
740 /* relative humidity in percent */
741 float relative_humidity;
742
743 /* uncalibrated gyroscope values are in rad/s */
744 uncalibrated_event_t uncalibrated_gyro;
745
746 /* uncalibrated magnetometer values are in micro-Teslas */
747 uncalibrated_event_t uncalibrated_magnetic;
748
749 /* heart rate data containing value in bpm and status */
750 heart_rate_event_t heart_rate;
751
752 /* this is a special event. see SENSOR_TYPE_META_DATA above.
753 * sensors_meta_data_event_t events are all reported with a type of
754 * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero.
755 */
756 meta_data_event_t meta_data;
757 };
758
759 union {
760 uint64_t data[8];
761
762 /* step-counter */
763 uint64_t step_counter;
764 } u64;
765 };
766
767 /* Reserved flags for internal use. Set to zero. */
768 uint32_t flags;
769
770 uint32_t reserved1[3];
771 } sensors_event_t;
772
773
774 /* see SENSOR_TYPE_META_DATA */
775 typedef sensors_event_t sensors_meta_data_event_t;
776
777
778 struct sensor_t;
779
780 /**
781 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
782 * and the fields of this data structure must begin with hw_module_t
783 * followed by module specific information.
784 */
785 struct sensors_module_t {
786 struct hw_module_t common;
787
788 /**
789 * Enumerate all available sensors. The list is returned in "list".
790 * @return number of sensors in the list
791 */
792 int (*get_sensors_list)(struct sensors_module_t* module,
793 struct sensor_t const** list);
794 };
795
796 struct sensor_t {
797
798 /* Name of this sensor.
799 * All sensors of the same "type" must have a different "name".
800 */
801 const char* name;
802
803 /* vendor of the hardware part */
804 const char* vendor;
805
806 /* version of the hardware part + driver. The value of this field
807 * must increase when the driver is updated in a way that changes the
808 * output of this sensor. This is important for fused sensors when the
809 * fusion algorithm is updated.
810 */
811 int version;
812
813 /* handle that identifies this sensors. This handle is used to reference
814 * this sensor throughout the HAL API.
815 */
816 int handle;
817
818 /* this sensor's type. */
819 int type;
820
821 /* maximum range of this sensor's value in SI units */
822 float maxRange;
823
824 /* smallest difference between two values reported by this sensor */
825 float resolution;
826
827 /* rough estimate of this sensor's power consumption in mA */
828 float power;
829
830 /* this value depends on the reporting mode:
831 *
832 * continuous: minimum sample period allowed in microseconds
833 * on-change : 0
834 * one-shot :-1
835 * special : 0, unless otherwise noted
836 */
837 int32_t minDelay;
838
839 /* number of events reserved for this sensor in the batch mode FIFO.
840 * If there is a dedicated FIFO for this sensor, then this is the
841 * size of this FIFO. If the FIFO is shared with other sensors,
842 * this is the size reserved for that sensor and it can be zero.
843 */
844 uint32_t fifoReservedEventCount;
845
846 /* maximum number of events of this sensor that could be batched.
847 * This is especially relevant when the FIFO is shared between
848 * several sensors; this value is then set to the size of that FIFO.
849 */
850 uint32_t fifoMaxEventCount;
851
852 /* type of this sensor as a string. Set to corresponding
853 * SENSOR_STRING_TYPE_*.
854 * When defining an OEM specific sensor or sensor manufacturer specific
855 * sensor, use your reserve domain name as a prefix.
856 * ex: com.google.glass.onheaddetector
857 * For sensors of known type, the android framework might overwrite this
858 * string automatically.
859 */
860 const char* stringType;
861
862 /* permission required to see this sensor, register to it and receive data.
863 * Set to "" if no permission is required. Some sensor types like the
864 * heart rate monitor have a mandatory require_permission.
865 * For sensors that always require a specific permission, like the heart
866 * rate monitor, the android framework might overwrite this string
867 * automatically.
868 */
869 const char* requiredPermission;
870
871 /* This value is defined only for continuous mode and on-change sensors. It is the delay between
872 * two sensor events corresponding to the lowest frequency that this sensor supports. When lower
873 * frequencies are requested through batch()/setDelay() the events will be generated at this
874 * frequency instead. It can be used by the framework or applications to estimate when the batch
875 * FIFO may be full.
876 *
877 * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
878 * continuous, on-change: maximum sampling period allowed in microseconds.
879 * one-shot, special : 0
880 * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
881 * on 64 bit architectures only for binary compatibility reasons.
882 * Availability: SENSORS_DEVICE_API_VERSION_1_3
883 */
884 #ifdef __LP64__
885 int64_t maxDelay;
886 #else
887 int32_t maxDelay;
888 #endif
889
890 /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
891 * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
892 * Availability: SENSORS_DEVICE_API_VERSION_1_3
893 */
894 #ifdef __LP64__
895 uint64_t flags;
896 #else
897 uint32_t flags;
898 #endif
899
900 /* reserved fields, must be zero */
901 void* reserved[2];
902 };
903
904
905 /*
906 * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
907 * and is present for backward binary and source compatibility.
908 * See the Sensors HAL interface section for complete descriptions of the
909 * following functions:
910 * http://source.android.com/devices/sensors/index.html#hal
911 */
912 struct sensors_poll_device_t {
913 struct hw_device_t common;
914 int (*activate)(struct sensors_poll_device_t *dev,
915 int sensor_handle, int enabled);
916 int (*setDelay)(struct sensors_poll_device_t *dev,
917 int sensor_handle, int64_t sampling_period_ns);
918 int (*poll)(struct sensors_poll_device_t *dev,
919 sensors_event_t* data, int count);
920 };
921
922 /*
923 * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0
924 */
925 typedef struct sensors_poll_device_1 {
926 union {
927 /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
928 * and can be down-cast to it
929 */
930 struct sensors_poll_device_t v0;
931
932 struct {
933 struct hw_device_t common;
934
935 /* Activate/de-activate one sensor. Return 0 on success, negative
936 *
937 * sensor_handle is the handle of the sensor to change.
938 * enabled set to 1 to enable, or 0 to disable the sensor.
939 *
940 * Return 0 on success, negative errno code otherwise.
941 */
942 int (*activate)(struct sensors_poll_device_t *dev,
943 int sensor_handle, int enabled);
944
945 /**
946 * Set the events's period in nanoseconds for a given sensor.
947 * If sampling_period_ns > max_delay it will be truncated to
948 * max_delay and if sampling_period_ns < min_delay it will be
949 * replaced by min_delay.
950 */
951 int (*setDelay)(struct sensors_poll_device_t *dev,
952 int sensor_handle, int64_t sampling_period_ns);
953
954 /**
955 * Returns an array of sensor data.
956 */
957 int (*poll)(struct sensors_poll_device_t *dev,
958 sensors_event_t* data, int count);
959 };
960 };
961
962
963 /*
964 * Sets a sensor’s parameters, including sampling frequency and maximum
965 * report latency. This function can be called while the sensor is
966 * activated, in which case it must not cause any sensor measurements to
967 * be lost: transitioning from one sampling rate to the other cannot cause
968 * lost events, nor can transitioning from a high maximum report latency to
969 * a low maximum report latency.
970 * See the Batching sensor results page for details:
971 * http://source.android.com/devices/sensors/batching.html
972 */
973 int (*batch)(struct sensors_poll_device_1* dev,
974 int sensor_handle, int flags, int64_t sampling_period_ns,
975 int64_t max_report_latency_ns);
976
977 /*
978 * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
979 * to the end of the "batch mode" FIFO for the specified sensor and flushes
980 * the FIFO.
981 * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
982 * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
983 * event stream. This applies to all sensors other than one-shot sensors.
984 * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate
985 * any flush complete metadata.
986 * If the sensor is not active at the time flush() is called, flush() should return
987 * -EINVAL.
988 */
989 int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle);
990
991 void (*reserved_procs[8])(void);
992
993 } sensors_poll_device_1_t;
994
995
996 /** convenience API for opening and closing a device */
997
sensors_open(const struct hw_module_t * module,struct sensors_poll_device_t ** device)998 static inline int sensors_open(const struct hw_module_t* module,
999 struct sensors_poll_device_t** device) {
1000 return module->methods->open(module,
1001 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1002 }
1003
sensors_close(struct sensors_poll_device_t * device)1004 static inline int sensors_close(struct sensors_poll_device_t* device) {
1005 return device->common.close(&device->common);
1006 }
1007
sensors_open_1(const struct hw_module_t * module,sensors_poll_device_1_t ** device)1008 static inline int sensors_open_1(const struct hw_module_t* module,
1009 sensors_poll_device_1_t** device) {
1010 return module->methods->open(module,
1011 SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1012 }
1013
sensors_close_1(sensors_poll_device_1_t * device)1014 static inline int sensors_close_1(sensors_poll_device_1_t* device) {
1015 return device->common.close(&device->common);
1016 }
1017
1018 __END_DECLS
1019
1020 #endif // ANDROID_SENSORS_INTERFACE_H
1021