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