1 /*
2  * Copyright (C) 2016 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 #include "sensorlist.h"
18 
19 #include <math.h>
20 
21 #include "hubdefs.h"
22 
23 using namespace android;
24 
25 const int kVersion = 1;
26 
27 const float kMinSampleRateHzAccel = 6.250f;
28 const float kMaxSampleRateHzAccel = 400.0f;
29 extern const float kScaleAccel = (8.0f * 9.81f / 32768.0f);
30 
31 const float kMinSampleRateHzGyro = 6.250f;
32 const float kMaxSampleRateHzGyro = 400.0f;
33 
34 const float kMinSampleRateHzMag = 3.125f;
35 const float kMaxSampleRateHzMag = 50.0f;
36 extern const float kScaleMag = 0.0625f;         // 1.0f / 16.0f
37 
38 const float kMinSampleRateHzPolling = 0.1f;
39 const float kMaxSampleRateHzPolling = 25.0f;
40 
41 const float kMinSampleRateHzPressure = 0.1f;
42 const float kMaxSampleRateHzPressure = 10.0f;
43 
44 const float kMinSampleRateHzTemperature = kMinSampleRateHzPolling;
45 const float kMaxSampleRateHzTemperature = kMaxSampleRateHzPolling;
46 
47 const float kMinSampleRateHzProximity = kMinSampleRateHzPolling;
48 const float kMaxSampleRateHzProximity = 5.0;
49 
50 const float kMinSampleRateHzLight = kMinSampleRateHzPolling;
51 const float kMaxSampleRateHzLight = 5.0;
52 
53 const float kMinSampleRateHzOrientation = 12.5f;
54 const float kMaxSampleRateHzOrientation = 200.0f;
55 
56 /*
57  * The fowllowing max count is determined by the total number of blocks
58  * avaliable in the shared nanohub buffer and number of samples each type of
59  * event can hold within a buffer block.
60  * For angler's case, there are 239 blocks in the shared sensor buffer and
61  * each block can hold 30 OneAxis Samples, 15 ThreeAxis Samples or 24
62  * RawThreeAxies Samples.
63  */
64 const int kMaxOneAxisEventCount = 7170;
65 const int kMaxThreeAxisEventCount = 3585;
66 const int kMaxRawThreeAxisEventCount = 5736;
67 
68 const int kMinFifoReservedEventCount = 20;
69 
70 const char SENSOR_STRING_TYPE_INTERNAL_TEMPERATURE[] =
71     "com.google.sensor.internal_temperature";
72 const char SENSOR_STRING_TYPE_SYNC[] =
73     "com.google.sensor.sync";
74 const char SENSOR_STRING_TYPE_DOUBLE_TWIST[] =
75     "com.google.sensor.double_twist";
76 const char SENSOR_STRING_TYPE_DOUBLE_TAP[] =
77     "com.google.sensor.double_tap";
78 
79 extern const sensor_t kSensorList[] = {
80     {
81         "TMD27723 Proximity Sensor",
82         "AMS",
83         kVersion,
84         COMMS_SENSOR_PROXIMITY,
85         SENSOR_TYPE_PROXIMITY,
86         5.0f,                                          // maxRange (cm)
87         1.0f,                                          // resolution (cm)
88         0.0f,                                          // XXX power
89         (int32_t)(1.0E6f / kMaxSampleRateHzProximity), // minDelay
90         300,                                           // XXX fifoReservedEventCount
91         kMaxOneAxisEventCount,                         // XXX fifoMaxEventCount
92         SENSOR_STRING_TYPE_PROXIMITY,
93         "",                                            // requiredPermission
94         (long)(1.0E6f / kMinSampleRateHzProximity),    // maxDelay
95         SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE,
96         { NULL, NULL }
97     },
98     {
99         "TMD27723 Light Sensor",
100         "AMS",
101         kVersion,
102         COMMS_SENSOR_LIGHT,
103         SENSOR_TYPE_LIGHT,
104         10000.0f,                                  // maxRange (lx)
105         10.0f,                                     // XXX resolution (lx)
106         0.0f,                                      // XXX power
107         (int32_t)(1.0E6f / kMaxSampleRateHzLight), // minDelay
108         kMinFifoReservedEventCount,                // XXX fifoReservedEventCount
109         kMaxOneAxisEventCount,                     // XXX fifoMaxEventCount
110         SENSOR_STRING_TYPE_LIGHT,
111         "",                                        // requiredPermission
112         (long)(1.0E6f / kMinSampleRateHzLight),    // maxDelay
113         SENSOR_FLAG_ON_CHANGE_MODE,
114         { NULL, NULL }
115     },
116     {
117         "BMI160 accelerometer",
118         "Bosch",
119         kVersion,
120         COMMS_SENSOR_ACCEL,
121         SENSOR_TYPE_ACCELEROMETER,
122         GRAVITY_EARTH * 8.0f,                      // maxRange
123         GRAVITY_EARTH * 8.0f / 32768.0f,           // resolution
124         0.0f,                                      // XXX power
125         (int32_t)(1.0E6f / kMaxSampleRateHzAccel), // minDelay
126         3000,                                      // XXX fifoReservedEventCount
127         kMaxRawThreeAxisEventCount,                // XXX fifoMaxEventCount
128         SENSOR_STRING_TYPE_ACCELEROMETER,
129         "",                                        // requiredPermission
130         (long)(1.0E6f / kMinSampleRateHzAccel),    // maxDelay
131         SENSOR_FLAG_CONTINUOUS_MODE,
132         { NULL, NULL }
133     },
134     {
135         "BMI160 gyroscope",
136         "Bosch",
137         kVersion,
138         COMMS_SENSOR_GYRO,
139         SENSOR_TYPE_GYROSCOPE,
140         1000.0f * M_PI / 180.0f,                   // maxRange
141         1000.0f * M_PI / (180.0f * 32768.0f),      // resolution
142         0.0f,                                      // XXX power
143         (int32_t)(1.0E6f / kMaxSampleRateHzGyro),  // minDelay
144         kMinFifoReservedEventCount,                // XXX fifoReservedEventCount
145         kMaxThreeAxisEventCount,                   // XXX fifoMaxEventCount
146         SENSOR_STRING_TYPE_GYROSCOPE,
147         "",                                        // requiredPermission
148         (long)(1.0E6f / kMinSampleRateHzGyro),     // maxDelay
149         SENSOR_FLAG_CONTINUOUS_MODE,
150         { NULL, NULL }
151     },
152     {
153         "BMI160 gyroscope (uncalibrated)",
154         "Bosch",
155         kVersion,
156         COMMS_SENSOR_GYRO_UNCALIBRATED,
157         SENSOR_TYPE_GYROSCOPE_UNCALIBRATED,
158         1000.0f * M_PI / 180.0f,                   // maxRange
159         1000.0f * M_PI / (180.0f * 32768.0f),      // resolution
160         0.0f,                                      // XXX power
161         (int32_t)(1.0E6f / kMaxSampleRateHzGyro),  // minDelay
162         kMinFifoReservedEventCount,                // XXX fifoReservedEventCount
163         kMaxThreeAxisEventCount,                   // XXX fifoMaxEventCount
164         SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED,
165         "",                                        // requiredPermission
166         (long)(1.0E6f / kMinSampleRateHzGyro),     // maxDelay
167         SENSOR_FLAG_CONTINUOUS_MODE,
168         { NULL, NULL }
169     },
170     {
171         "BMM150 magnetometer",
172         "Bosch",
173         kVersion,
174         COMMS_SENSOR_MAG,
175         SENSOR_TYPE_MAGNETIC_FIELD,
176         1300.0f,                                   // XXX maxRange
177         0.0f,                                      // XXX resolution
178         0.0f,                                      // XXX power
179         (int32_t)(1.0E6f / kMaxSampleRateHzMag),   // minDelay
180         600,                                       // XXX fifoReservedEventCount
181         kMaxThreeAxisEventCount,                   // XXX fifoMaxEventCount
182         SENSOR_STRING_TYPE_MAGNETIC_FIELD,
183         "",                                        // requiredPermission
184         (long)(1.0E6f / kMinSampleRateHzMag),      // maxDelay
185         SENSOR_FLAG_CONTINUOUS_MODE,
186         { NULL, NULL }
187     },
188     {
189         "BMM150 magnetometer (uncalibrated)",
190         "Bosch",
191         kVersion,
192         COMMS_SENSOR_MAG_UNCALIBRATED,
193         SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
194         1300.0f,                                        // XXX maxRange
195         0.0f,                                           // XXX resolution
196         0.0f,                                           // XXX power
197         (int32_t)(1.0E6f / kMaxSampleRateHzMag),        // minDelay
198         600,                                            // XXX fifoReservedEventCount
199         kMaxThreeAxisEventCount,                        // XXX fifoMaxEventCount
200         SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
201         "",                                             // requiredPermission
202         (long)(1.0E6f / kMinSampleRateHzMag),           // maxDelay
203         SENSOR_FLAG_CONTINUOUS_MODE,
204         { NULL, NULL }
205     },
206     {
207         "BMP280 pressure",
208         "Bosch",
209         kVersion,
210         COMMS_SENSOR_PRESSURE,
211         SENSOR_TYPE_PRESSURE,
212         1100.0f,                                      // maxRange (hPa)
213         0.005f,                                       // resolution (hPa)
214         0.0f,                                         // XXX power
215         (int32_t)(1.0E6f / kMaxSampleRateHzPressure), // minDelay
216         300,                                          // XXX fifoReservedEventCount
217         kMaxOneAxisEventCount,                        // XXX fifoMaxEventCount
218         SENSOR_STRING_TYPE_PRESSURE,
219         "",                                           // requiredPermission
220         (long)(1.0E6f / kMinSampleRateHzPressure),    // maxDelay
221         SENSOR_FLAG_CONTINUOUS_MODE,
222         { NULL, NULL }
223     },
224     {
225         "BMP280 temperature",
226         "Bosch",
227         kVersion,
228         COMMS_SENSOR_TEMPERATURE,
229         SENSOR_TYPE_INTERNAL_TEMPERATURE,
230         85.0f,                                           // maxRange (degC)
231         0.01,                                            // resolution (degC)
232         0.0f,                                            // XXX power
233         (int32_t)(1.0E6f / kMaxSampleRateHzTemperature), // minDelay
234         kMinFifoReservedEventCount,                      // XXX fifoReservedEventCount
235         kMaxOneAxisEventCount,                           // XXX fifoMaxEventCount
236         SENSOR_STRING_TYPE_INTERNAL_TEMPERATURE,
237         "",                                              // requiredPermission
238         (long)(1.0E6f / kMinSampleRateHzTemperature),    // maxDelay
239         SENSOR_FLAG_CONTINUOUS_MODE,
240         { NULL, NULL }
241     },
242     {
243         "Orientation",
244         "Google",
245         kVersion,
246         COMMS_SENSOR_ORIENTATION,
247         SENSOR_TYPE_ORIENTATION,
248         360.0f,                                          // maxRange (deg)
249         1.0f,                                            // XXX resolution (deg)
250         0.0f,                                            // XXX power
251         (int32_t)(1.0E6f / kMaxSampleRateHzOrientation), // minDelay
252         kMinFifoReservedEventCount,                      // XXX fifoReservedEventCount
253         kMaxThreeAxisEventCount,                         // XXX fifoMaxEventCount
254         SENSOR_STRING_TYPE_ORIENTATION,
255         "",                                              // requiredPermission
256         (long)(1.0E6f / kMinSampleRateHzOrientation),    // maxDelay
257         SENSOR_FLAG_CONTINUOUS_MODE,
258         { NULL, NULL }
259     },
260     {
261         "BMI160 Step detector",
262         "Bosch",
263         kVersion,
264         COMMS_SENSOR_STEP_DETECTOR,
265         SENSOR_TYPE_STEP_DETECTOR,
266         1.0f,                                   // maxRange
267         1.0f,                                   // XXX resolution
268         0.0f,                                   // XXX power
269         0,                                      // minDelay
270         100,                                    // XXX fifoReservedEventCount
271         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
272         SENSOR_STRING_TYPE_STEP_DETECTOR,
273         "",                                     // requiredPermission
274         0,                                      // maxDelay
275         SENSOR_FLAG_SPECIAL_REPORTING_MODE,
276         { NULL, NULL }
277     },
278     {
279         "BMI160 Step counter",
280         "Bosch",
281         kVersion,
282         COMMS_SENSOR_STEP_COUNTER,
283         SENSOR_TYPE_STEP_COUNTER,
284         1.0f,                                   // XXX maxRange
285         1.0f,                                   // resolution
286         0.0f,                                   // XXX power
287         0,                                      // minDelay
288         kMinFifoReservedEventCount,             // XXX fifoReservedEventCount
289         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
290         SENSOR_STRING_TYPE_STEP_COUNTER,
291         "",                                     // requiredPermission
292         0,                                      // maxDelay
293         SENSOR_FLAG_ON_CHANGE_MODE,
294         { NULL, NULL }
295     },
296     {
297         "Significant motion",
298         "Google",
299         kVersion,
300         COMMS_SENSOR_SIGNIFICANT_MOTION,
301         SENSOR_TYPE_SIGNIFICANT_MOTION,
302         1.0f,                                   // maxRange
303         1.0f,                                   // XXX resolution
304         0.0f,                                   // XXX power
305         -1,                                     // minDelay
306         0,                                      // XXX fifoReservedEventCount
307         0,                                      // XXX fifoMaxEventCount
308         SENSOR_STRING_TYPE_SIGNIFICANT_MOTION,
309         "",                                     // requiredPermission
310         0,                                      // maxDelay
311         SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ONE_SHOT_MODE,
312         { NULL, NULL }
313     },
314     {
315         "Gravity",
316         "Google",
317         kVersion,
318         COMMS_SENSOR_GRAVITY,
319         SENSOR_TYPE_GRAVITY,
320         1000.0f,                                         // maxRange
321         1.0f,                                            // XXX resolution
322         0.0f,                                            // XXX power
323         (int32_t)(1.0E6f / kMaxSampleRateHzOrientation), // minDelay
324         kMinFifoReservedEventCount,                      // XXX fifoReservedEventCount
325         kMaxThreeAxisEventCount,                         // XXX fifoMaxEventCount
326         SENSOR_STRING_TYPE_GRAVITY,
327         "",                                              // requiredPermission
328         (long)(1.0E6f / kMinSampleRateHzOrientation),    // maxDelay
329         SENSOR_FLAG_CONTINUOUS_MODE,
330         { NULL, NULL }
331     },
332     {
333         "Linear Acceleration",
334         "Google",
335         kVersion,
336         COMMS_SENSOR_LINEAR_ACCEL,
337         SENSOR_TYPE_LINEAR_ACCELERATION,
338         1000.0f,                                         // maxRange
339         1.0f,                                            // XXX resolution
340         0.0f,                                            // XXX power
341         (int32_t)(1.0E6f / kMaxSampleRateHzOrientation), // minDelay
342         kMinFifoReservedEventCount,                      // XXX fifoReservedEventCount
343         kMaxThreeAxisEventCount,                         // XXX fifoMaxEventCount
344         SENSOR_STRING_TYPE_LINEAR_ACCELERATION,
345         "",                                              // requiredPermission
346         (long)(1.0E6f / kMinSampleRateHzOrientation),    // maxDelay
347         SENSOR_FLAG_CONTINUOUS_MODE,
348         { NULL, NULL }
349     },
350     {
351         "Rotation Vector",
352         "Google",
353         kVersion,
354         COMMS_SENSOR_ROTATION_VECTOR,
355         SENSOR_TYPE_ROTATION_VECTOR,
356         1000.0f,                                         // maxRange
357         1.0f,                                            // XXX resolution
358         0.0f,                                            // XXX power
359         (int32_t)(1.0E6f / kMaxSampleRateHzOrientation), // minDelay
360         kMinFifoReservedEventCount,                      // XXX fifoReservedEventCount
361         kMaxThreeAxisEventCount,                         // XXX fifoMaxEventCount
362         SENSOR_STRING_TYPE_ROTATION_VECTOR,
363         "",                                              // requiredPermission
364         (long)(1.0E6f / kMinSampleRateHzOrientation),    // maxDelay
365         SENSOR_FLAG_CONTINUOUS_MODE,
366         { NULL, NULL }
367     },
368     {
369         "Geomagnetic Rotation Vector",
370         "Google",
371         kVersion,
372         COMMS_SENSOR_GEO_MAG,
373         SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR,
374         1000.0f,                                         // maxRange
375         1.0f,                                            // XXX resolution
376         0.0f,                                            // XXX power
377         (int32_t)(1.0E6f / kMaxSampleRateHzOrientation), // minDelay
378         kMinFifoReservedEventCount,                      // XXX fifoReservedEventCount
379         kMaxThreeAxisEventCount,                         // XXX fifoMaxEventCount
380         SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR,
381         "",                                              // requiredPermission
382         (long)(1.0E6f / kMinSampleRateHzOrientation),    // maxDelay
383         SENSOR_FLAG_CONTINUOUS_MODE,
384         { NULL, NULL }
385     },
386     {
387         "Game Rotation Vector",
388         "Google",
389         kVersion,
390         COMMS_SENSOR_GAME_ROTATION_VECTOR,
391         SENSOR_TYPE_GAME_ROTATION_VECTOR,
392         1000.0f,                                         // maxRange
393         1.0f,                                            // XXX resolution
394         0.0f,                                            // XXX power
395         (int32_t)(1.0E6f / kMaxSampleRateHzOrientation), // minDelay
396         300,                                             // XXX fifoReservedEventCount
397         kMaxThreeAxisEventCount,                         // XXX fifoMaxEventCount
398         SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR,
399         "",                                              // requiredPermission
400         (long)(1.0E6f / kMinSampleRateHzOrientation),    // maxDelay
401         SENSOR_FLAG_CONTINUOUS_MODE,
402         { NULL, NULL }
403     },
404     {
405         "Tilt Detector",
406         "Google",
407         kVersion,
408         COMMS_SENSOR_TILT,
409         SENSOR_TYPE_TILT_DETECTOR,
410         1.0f,                                   // maxRange
411         1.0f,                                   // XXX resolution
412         0.0f,                                   // XXX power
413         0,                                      // minDelay
414         kMinFifoReservedEventCount,             // XXX fifoReservedEventCount
415         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
416         SENSOR_STRING_TYPE_TILT_DETECTOR,
417         "",                                     // requiredPermission
418         0,                                      // maxDelay
419         SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_SPECIAL_REPORTING_MODE,
420         { NULL, NULL }
421     },
422     {
423         "Pickup Gesture",
424         "Google",
425         kVersion,
426         COMMS_SENSOR_GESTURE,
427         SENSOR_TYPE_PICK_UP_GESTURE,
428         1.0f,                                   // maxRange
429         1.0f,                                   // XXX resolution
430         0.0f,                                   // XXX power
431         -1,                                     // minDelay
432         0,                                      // XXX fifoReservedEventCount
433         0,                                      // XXX fifoMaxEventCount
434         SENSOR_STRING_TYPE_PICK_UP_GESTURE,
435         "",                                     // requiredPermission
436         0,                                      // maxDelay
437         SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ONE_SHOT_MODE,
438         { NULL, NULL }
439     },
440     {
441         "Sensors Sync",
442         "Google",
443         kVersion,
444         COMMS_SENSOR_SYNC,
445         SENSOR_TYPE_SYNC,
446         1.0f,                                   // maxRange
447         1.0f,                                   // XXX resolution
448         0.1f,                                   // XXX power
449         0,                                      // minDelay
450         kMinFifoReservedEventCount,             // XXX fifoReservedEventCount
451         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
452         SENSOR_STRING_TYPE_SYNC,
453         "",                                     // requiredPermission
454         0,                                      // maxDelay
455         SENSOR_FLAG_SPECIAL_REPORTING_MODE,
456         { NULL, NULL }
457     },
458     {
459         "Double Twist",
460         "Google",
461         kVersion,
462         COMMS_SENSOR_DOUBLE_TWIST,
463         SENSOR_TYPE_DOUBLE_TWIST,
464         1.0f,                                   // maxRange
465         1.0f,                                   // XXX resolution
466         0.1f,                                   // XXX power
467         0,                                      // minDelay
468         kMinFifoReservedEventCount,             // XXX fifoReservedEventCount
469         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
470         SENSOR_STRING_TYPE_DOUBLE_TWIST,
471         "",                                     // requiredPermission
472         0,                                      // maxDelay
473         SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_SPECIAL_REPORTING_MODE,
474         { NULL, NULL }
475     },
476     {
477         "Double Tap",
478         "Google",
479         kVersion,
480         COMMS_SENSOR_DOUBLE_TAP,
481         SENSOR_TYPE_DOUBLE_TAP,
482         1.0f,                                   // maxRange
483         1.0f,                                   // XXX resolution
484         0.1f,                                   // XXX power
485         0,                                      // minDelay
486         kMinFifoReservedEventCount,             // XXX fifoReservedEventCount
487         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
488         SENSOR_STRING_TYPE_DOUBLE_TAP,
489         "",                                     // requiredPermission
490         0,                                      // maxDelay
491         SENSOR_FLAG_SPECIAL_REPORTING_MODE,
492         { NULL, NULL }
493     },
494     {
495         "Device Orientation",
496         "Google",
497         kVersion,
498         COMMS_SENSOR_WINDOW_ORIENTATION,
499         SENSOR_TYPE_DEVICE_ORIENTATION,
500         3.0f,                                   // maxRange
501         1.0f,                                   // XXX resolution
502         0.1f,                                   // XXX power
503         0,                                      // minDelay
504         kMinFifoReservedEventCount,             // XXX fifoReservedEventCount
505         kMaxOneAxisEventCount,                  // XXX fifoMaxEventCount
506         SENSOR_STRING_TYPE_DEVICE_ORIENTATION,
507         "",                                     // requiredPermission
508         0,                                      // maxDelay
509         SENSOR_FLAG_ON_CHANGE_MODE,
510         { NULL, NULL }
511     },
512     {
513         "BMI160 accelerometer (uncalibrated)",
514         "Bosch",
515         kVersion,
516         COMMS_SENSOR_ACCEL_UNCALIBRATED,
517         SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED,
518         GRAVITY_EARTH * 8.0f,                      // maxRange
519         GRAVITY_EARTH * 8.0f / 32768.0f,           // resolution
520         0.0f,                                      // XXX power
521         (int32_t)(1.0E6f / kMaxSampleRateHzAccel), // minDelay
522         3000,                                      // XXX fifoReservedEventCount
523         kMaxRawThreeAxisEventCount,                // XXX fifoMaxEventCount
524         SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED,
525         "",                                        // requiredPermission
526         (long)(1.0E6f / kMinSampleRateHzAccel),    // maxDelay
527         SENSOR_FLAG_CONTINUOUS_MODE,
528         { NULL, NULL }
529     },
530 };
531 
532 extern const size_t kSensorCount = sizeof(kSensorList) / sizeof(sensor_t);
533