• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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_H
18 #define ANDROID_SENSORS_H
19 
20 #include <stdint.h>
21 #include <errno.h>
22 #include <sys/cdefs.h>
23 #include <sys/types.h>
24 #include <math.h>
25 
26 #include <linux/input.h>
27 
28 #include <hardware/hardware.h>
29 #include <hardware/sensors.h>
30 
31 __BEGIN_DECLS
32 
33 /*****************************************************************************/
34 
35 int init_nusensors(hw_module_t const* module, hw_device_t** device);
36 
37 /*****************************************************************************/
38 
39 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
40 
41 #define ID_A  (0)
42 #define ID_M  (1)
43 #define ID_O  (2)
44 #define ID_T  (3)
45 #define ID_P  (4)
46 #define ID_L  (5)
47 #define ID_B  (6)
48 #define ID_G  (7)
49 
50 /*****************************************************************************/
51 
52 /*
53  * The SENSORS Module
54  */
55 
56 /* the SFH7743 is a binary proximity sensor that triggers around 6 cm on
57  * this hardware */
58 #define PROXIMITY_THRESHOLD_CM  6.0f
59 
60 /*****************************************************************************/
61 
62 #define AKM_DEVICE_NAME             "/dev/akm8975_aot"
63 #define ACCELEROMETER_DEVICE_NAME   "/dev/kxtf9"
64 #define LIGHTING_DEVICE_NAME        "/dev/max9635"
65 #define BAROMETER_DEVICE_NAME       "/dev/bmp085"
66 #define GYROSCOPE_DEVICE_NAME       "/dev/l3g4200d"
67 
68 #define EVENT_TYPE_ACCEL_X          REL_X
69 #define EVENT_TYPE_ACCEL_Y          REL_Y
70 #define EVENT_TYPE_ACCEL_Z          REL_Z
71 
72 #define EVENT_TYPE_YAW              REL_RX
73 #define EVENT_TYPE_PITCH            REL_RY
74 #define EVENT_TYPE_ROLL             REL_RZ
75 #define EVENT_TYPE_ORIENT_STATUS    REL_HWHEEL
76 
77 #define EVENT_TYPE_MAGV_X           REL_DIAL
78 #define EVENT_TYPE_MAGV_Y           REL_WHEEL
79 #define EVENT_TYPE_MAGV_Z           REL_MISC
80 
81 #define EVENT_TYPE_LIGHT            MSC_RAW
82 #define EVENT_TYPE_PRESSURE         ABS_PRESSURE
83 
84 #define EVENT_TYPE_GYRO_P           REL_RX
85 #define EVENT_TYPE_GYRO_R           REL_RY
86 #define EVENT_TYPE_GYRO_Y           REL_RZ
87 
88 // 1024 LSG = 1G
89 #define LSG                         (1024.0f)
90 #define MAX_RANGE_A                 (2*GRAVITY_EARTH)
91 // conversion of acceleration data to SI units (m/s^2)
92 #define CONVERT_A                   (GRAVITY_EARTH / LSG)
93 #define CONVERT_A_X                 (CONVERT_A)
94 #define CONVERT_A_Y                 (CONVERT_A)
95 #define CONVERT_A_Z                 (CONVERT_A)
96 
97 // conversion of magnetic data to uT units
98 #define CONVERT_M                   (1.0f/16.0f)
99 #define CONVERT_M_X                 (CONVERT_M)
100 #define CONVERT_M_Y                 (CONVERT_M)
101 #define CONVERT_M_Z                 (CONVERT_M)
102 
103 #define CONVERT_O                   (1.0f/64.0f)
104 #define CONVERT_O_Y                 (CONVERT_O)
105 #define CONVERT_O_P                 (CONVERT_O)
106 #define CONVERT_O_R                 (-CONVERT_O)
107 
108 // conversion of angular velocity(millidegrees/second) to rad/s
109 #define MAX_RANGE_G                 (2000.0f * ((float)(M_PI/180.0f)))
110 #define CONVERT_G                   ((70.0f/1000.0f) * ((float)(M_PI/180.0f)))
111 #define CONVERT_G_P                 (CONVERT_G)
112 #define CONVERT_G_R                 (CONVERT_G)
113 #define CONVERT_G_Y                 (CONVERT_G)
114 
115 #define CONVERT_B                   (1.0f/100.0f)
116 
117 #define SENSOR_STATE_MASK           (0x7FFF)
118 
119 /*****************************************************************************/
120 
121 __END_DECLS
122 
123 #endif  // ANDROID_SENSORS_H
124