xref: /aosp_15_r20/hardware/interfaces/sensors/2.1/types.hal (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1/*
2 * Copyright (C) 2020 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
17package [email protected];
18
19import @1.0::EventPayload;
20import @1.0::SensorType;
21import @1.0::SensorFlagBits;
22
23@export(name="", value_prefix="SENSOR_TYPE_")
24enum SensorType : @1.0::SensorType {
25    /**
26     * HINGE_ANGLE
27     * reporting-mode: on-change
28     * wake-up sensor: yes
29     *
30     * A sensor of this type measures the angle, in degrees, between two
31     * integral parts of the device. Movement of a hinge measured by this sensor
32     * type is expected to alter the ways in which the user may interact with
33     * the device, for example by unfolding or revealing a display.
34     *
35     * Sensor data is output using @1.0::EventPayload.scalar.
36     *
37     * Implement wake-up proximity sensor before implementing a non wake-up
38     * proximity sensor.
39     */
40    HINGE_ANGLE                     = 36,
41};
42
43struct Event {
44    /** Time measured in nanoseconds, in "elapsedRealtimeNano()'s" timebase. */
45    int64_t timestamp;
46
47    /** sensor identifier */
48    int32_t sensorHandle;
49
50    @2.1::SensorType sensorType;
51
52    /** Union discriminated on sensorType */
53    EventPayload u;
54};
55
56struct SensorInfo {
57    /**
58     * handle that identifies this sensors. This handle is used to reference
59     * this sensor throughout the HAL API.
60     */
61    int32_t sensorHandle;
62
63    /**
64     * Name of this sensor.
65     * All sensors of the same "type" must have a different "name".
66     */
67    string name;
68
69    /** vendor of the hardware part */
70    string vendor;
71
72    /**
73     * version of the hardware part + driver. The value of this field
74     * must increase when the driver is updated in a way that changes the
75     * output of this sensor. This is important for fused sensors when the
76     * fusion algorithm is updated.
77     */
78    int32_t version;
79
80    /** this sensor's type. */
81    @2.1::SensorType type;
82
83    /**
84     * type of this sensor as a string.
85     *
86     * When defining an OEM specific sensor or sensor manufacturer specific
87     * sensor, use your reserve domain name as a prefix.
88     * e.g. com.google.glass.onheaddetector
89     *
90     * For sensors of known type defined in SensorType (value <
91     * SensorType::DEVICE_PRIVATE_BASE), this can be an empty string.
92     */
93    string typeAsString;
94
95    /** maximum range of this sensor's value in SI units */
96    float maxRange;
97
98    /** smallest difference between two values reported by this sensor */
99    float resolution;
100
101    /** rough estimate of this sensor's power consumption in mA */
102    float power;
103
104    /**
105     * this value depends on the reporting mode:
106     *
107     *   continuous: minimum sample period allowed in microseconds
108     *   on-change : 0
109     *   one-shot  :-1
110     *   special   : 0, unless otherwise noted
111     */
112    int32_t minDelay;
113
114    /**
115     * number of events reserved for this sensor in the batch mode FIFO.
116     * If there is a dedicated FIFO for this sensor, then this is the
117     * size of this FIFO. If the FIFO is shared with other sensors,
118     * this is the size reserved for that sensor and it can be zero.
119     */
120    uint32_t fifoReservedEventCount;
121
122    /**
123     * maximum number of events of this sensor that could be batched.
124     * This is especially relevant when the FIFO is shared between
125     * several sensors; this value is then set to the size of that FIFO.
126     */
127    uint32_t fifoMaxEventCount;
128
129    /**
130     * permission required to see this sensor, register to it and receive data.
131     * Set to "" if no permission is required. Some sensor types like the
132     * heart rate monitor have a mandatory require_permission.
133     * For sensors that always require a specific permission, like the heart
134     * rate monitor, the android framework might overwrite this string
135     * automatically.
136     */
137    string requiredPermission;
138
139    /**
140     * This value is defined only for continuous mode and on-change sensors.
141     * It is the delay between two sensor events corresponding to the lowest
142     * frequency that this sensor supports. When lower frequencies are requested
143     * through batch()/setDelay() the events will be generated at this frequency
144     * instead.
145     * It can be used by the framework or applications to estimate when the
146     * batch FIFO may be full.
147     *
148     * NOTE: periodNs is in nanoseconds where as maxDelay/minDelay are in
149     *       microseconds.
150     *
151     *       continuous, on-change: maximum sampling period allowed in
152     *                              microseconds.
153     *
154     *          one-shot, special : 0
155     */
156    int32_t maxDelay;
157
158    /** Bitmask of SensorFlagBits */
159    bitfield<SensorFlagBits> flags;
160};