04e3249af24fce6fc3d64a04a1768702c441a058
[platform/core/system/sensord.git] / src / shared / sensor_hal.h
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #ifndef _SENSOR_HAL_H_
21 #define _SENSOR_HAL_H_
22
23 #include <stdint.h>
24
25 #define SENSOR_HAL_VERSION(maj,min) \
26                         ((((maj) & 0xffff) << 24) | ((min) & 0xffff))
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif /* __cplusplus */
32
33 /*
34  * Sensor Types
35  * These types are used to controll the sensors
36  *
37  * - base unit
38  *   acceleration values : meter per second^2 (m/s^2)
39  *   magnetic values     : micro-Tesla (uT)
40  *   orientation values  : degrees
41  *   gyroscope values    : degree/s
42  *   temperature values  : degrees centigrade
43  *   proximity valeus    : distance
44  *   light values        : lux
45  *   pressure values     : hectopascal (hPa)
46  *   humidity            : relative humidity (%)
47  */
48 typedef enum {
49         SENSOR_DEVICE_UNKNOWN = -2,
50         SENSOR_DEVICE_ALL = -1,
51         SENSOR_DEVICE_ACCELEROMETER,
52         SENSOR_DEVICE_GRAVITY,
53         SENSOR_DEVICE_LINEAR_ACCELERATION,
54         SENSOR_DEVICE_GEOMAGNETIC,
55         SENSOR_DEVICE_ROTATION_VECTOR,
56         SENSOR_DEVICE_ORIENTATION,
57         SENSOR_DEVICE_GYROSCOPE,
58         SENSOR_DEVICE_LIGHT,
59         SENSOR_DEVICE_PROXIMITY,
60         SENSOR_DEVICE_PRESSURE,
61         SENSOR_DEVICE_ULTRAVIOLET,
62         SENSOR_DEVICE_TEMPERATURE,
63         SENSOR_DEVICE_HUMIDITY,
64         SENSOR_DEVICE_HRM,
65         SENSOR_DEVICE_HRM_LED_GREEN,
66         SENSOR_DEVICE_HRM_LED_IR,
67         SENSOR_DEVICE_HRM_LED_RED,
68         SENSOR_DEVICE_GYROSCOPE_UNCAL,
69         SENSOR_DEVICE_GEOMAGNETIC_UNCAL,
70         SENSOR_DEVICE_GYROSCOPE_RV,
71         SENSOR_DEVICE_GEOMAGNETIC_RV,
72
73         SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x100,
74         SENSOR_DEVICE_ACTIVITY_WALK,
75         SENSOR_DEVICE_ACTIVITY_RUN,
76         SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
77         SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
78
79         SENSOR_DEVICE_GESTURE_MOVEMENT = 0x200,
80         SENSOR_DEVICE_GESTURE_WRIST_UP,
81         SENSOR_DEVICE_GESTURE_WRIST_DOWN,
82
83         SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
84         SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
85
86         SENSOR_DEVICE_FUSION = 0x900,
87         SENSOR_DEVICE_AUTO_ROTATION,
88
89         SENSOR_DEVICE_CONTEXT = 0x1000,
90         SENSOR_DEVICE_MOTION,
91         SENSOR_DEVICE_PIR,
92         SENSOR_DEVICE_PIR_LONG,
93         SENSOR_DEVICE_DUST,
94         SENSOR_DEVICE_THERMOMETER,
95         SENSOR_DEVICE_PEDOMETER,
96         SENSOR_DEVICE_FLAT,
97         SENSOR_DEVICE_HRM_RAW,
98         SENSOR_DEVICE_TILT,
99         SENSOR_DEVICE_ROTATION_VECTOR_RAW,
100 } sensor_device_type;
101
102 typedef struct sensor_info_t {
103         const char *model_name;
104         const char *vendor;
105         float min_range;
106         float max_range;
107         float resolution;
108         int min_interval;
109         int max_batch_count;
110         bool wakeup_supported;
111 } sensor_info_t;
112
113 /*
114  * A platform sensor handler is generated based on this handle
115  * ID can be assigned from HAL developer. so it has to be unique in HAL.
116  */
117 typedef struct sensor_handle_t {
118         uint16_t id;
119         const char *name;
120         sensor_device_type type;
121         unsigned int event_type; // for Internal API
122         sensor_info_t info;
123 } sensor_handle_t;
124
125 enum sensor_accuracy_t {
126         SENSOR_ACCURACY_UNDEFINED = -1,
127         SENSOR_ACCURACY_BAD = 0,
128         SENSOR_ACCURACY_NORMAL =1,
129         SENSOR_ACCURACY_GOOD = 2,
130         SENSOR_ACCURACY_VERYGOOD = 3
131 };
132
133 #define SENSOR_DATA_VALUE_SIZE 16
134
135 /* sensor_data_t */
136 typedef struct sensor_data_t {
137         int accuracy;
138         unsigned long long timestamp;
139         int value_count;
140         float values[SENSOR_DATA_VALUE_SIZE];
141 } sensor_data_t;
142
143 #ifdef __cplusplus
144 }
145 #endif /* __cplusplus */
146
147 #ifdef __cplusplus
148 /*
149  * Create devices
150  */
151 typedef void *sensor_device_t;
152 typedef int (*create_t)(sensor_device_t **devices);
153
154 /*
155  * Sensor device interface
156  * 1 device must be abstracted from 1 device event node
157  */
158 class sensor_device
159 {
160 public:
161         virtual ~sensor_device() {}
162
163         uint32_t get_hal_version(void)
164         {
165                 return SENSOR_HAL_VERSION(1, 0);
166         }
167
168         virtual int get_poll_fd(void) = 0;
169         virtual int get_sensors(const sensor_handle_t **sensors) = 0;
170
171         virtual bool enable(uint16_t id) = 0;
172         virtual bool disable(uint16_t id) = 0;
173
174         virtual bool set_interval(uint16_t id, unsigned long val) = 0;
175         virtual bool set_batch_latency(uint16_t id, unsigned long val) = 0;
176         virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0;
177
178         virtual int read_fd(uint16_t **ids) = 0;
179         virtual int get_data(uint16_t id, sensor_data_t **data, int *length) = 0;
180
181         virtual bool flush(uint16_t id) = 0;
182 };
183 #endif /* __cplusplus */
184
185 #endif /* _SENSOR_HAL_H_ */