4 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef _SENSOR_HAL_H_
21 #define _SENSOR_HAL_H_
26 #define SENSOR_HAL_VERSION(maj,min) \
27 ((((maj) & 0xffff) << 24) | ((min) & 0xffff))
32 #endif /* __cplusplus */
36 * These types are used to controll the sensors
39 * acceleration values : meter per second^2 (m/s^2)
40 * magnetic values : micro-Tesla (uT)
41 * orientation values : degrees
42 * gyroscope values : degree/s
43 * temperature values : degrees centigrade
44 * proximity valeus : distance
46 * pressure values : hectopascal (hPa)
47 * humidity : relative humidity (%)
50 SENSOR_DEVICE_UNKNOWN = -2,
51 SENSOR_DEVICE_ALL = -1,
52 SENSOR_DEVICE_ACCELEROMETER,
53 SENSOR_DEVICE_GRAVITY,
54 SENSOR_DEVICE_LINEAR_ACCELERATION,
55 SENSOR_DEVICE_GEOMAGNETIC,
56 SENSOR_DEVICE_ROTATION_VECTOR,
57 SENSOR_DEVICE_ORIENTATION,
58 SENSOR_DEVICE_GYROSCOPE,
60 SENSOR_DEVICE_PROXIMITY,
61 SENSOR_DEVICE_PRESSURE,
62 SENSOR_DEVICE_ULTRAVIOLET,
63 SENSOR_DEVICE_TEMPERATURE,
64 SENSOR_DEVICE_HUMIDITY,
66 SENSOR_DEVICE_HRM_LED_GREEN,
67 SENSOR_DEVICE_HRM_LED_IR,
68 SENSOR_DEVICE_HRM_LED_RED,
69 SENSOR_DEVICE_GYROSCOPE_UNCAL,
70 SENSOR_DEVICE_GEOMAGNETIC_UNCAL,
71 SENSOR_DEVICE_GYROSCOPE_RV,
72 SENSOR_DEVICE_GEOMAGNETIC_RV,
74 SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x100,
75 SENSOR_DEVICE_ACTIVITY_WALK,
76 SENSOR_DEVICE_ACTIVITY_RUN,
77 SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
78 SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
80 SENSOR_DEVICE_GESTURE_MOVEMENT = 0x200,
81 SENSOR_DEVICE_GESTURE_WRIST_UP,
82 SENSOR_DEVICE_GESTURE_WRIST_DOWN,
84 SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
85 SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
87 SENSOR_DEVICE_FUSION = 0x900,
88 SENSOR_DEVICE_AUTO_ROTATION,
90 SENSOR_DEVICE_CONTEXT = 0x1000,
93 SENSOR_DEVICE_PIR_LONG,
95 SENSOR_DEVICE_THERMOMETER,
96 SENSOR_DEVICE_PEDOMETER,
98 SENSOR_DEVICE_HRM_RAW,
100 SENSOR_DEVICE_ROTATION_VECTOR_RAW,
101 } sensor_device_type;
103 typedef struct sensor_info_t {
104 const char *model_name;
111 bool wakeup_supported;
115 * A platform sensor handler is generated based on this handle
116 * ID can be assigned from HAL developer. so it has to be unique in HAL.
118 typedef struct sensor_handle_t {
121 sensor_device_type type;
122 unsigned int event_type; // for Internal API
126 enum sensor_accuracy_t {
127 SENSOR_ACCURACY_UNDEFINED = -1,
128 SENSOR_ACCURACY_BAD = 0,
129 SENSOR_ACCURACY_NORMAL =1,
130 SENSOR_ACCURACY_GOOD = 2,
131 SENSOR_ACCURACY_VERYGOOD = 3
134 #define SENSOR_DATA_VALUE_SIZE 16
137 typedef struct sensor_data_t {
139 unsigned long long timestamp;
141 float values[SENSOR_DATA_VALUE_SIZE];
146 #endif /* __cplusplus */
152 typedef void *sensor_device_t;
153 typedef int (*create_t)(sensor_device_t **devices);
156 * Sensor device interface
157 * 1 device must be abstracted from 1 device event node
162 virtual ~sensor_device() {}
164 uint32_t get_hal_version(void)
166 return SENSOR_HAL_VERSION(1, 0);
169 virtual int get_poll_fd(void) = 0;
170 virtual int get_sensors(const sensor_handle_t **sensors) = 0;
172 virtual bool enable(uint16_t id) = 0;
173 virtual bool disable(uint16_t id) = 0;
175 virtual bool set_interval(uint16_t id, unsigned long val) = 0;
176 virtual bool set_batch_latency(uint16_t id, unsigned long val) = 0;
177 virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0;
179 virtual int read_fd(uint16_t **ids) = 0;
180 virtual int get_data(uint16_t id, sensor_data_t **data, int *length) = 0;
182 virtual bool flush(uint16_t id) = 0;
184 #endif /* __cplusplus */
186 #endif /* _SENSOR_HAL_H_ */