OSDN Git Service

STPK-1429 Minor optimization to poll-mode sensor handling
[android-x86/hardware-intel-libsensors.git] / description.c
1 /*
2  * Copyright (C) 2014 Intel Corporation.
3  */
4
5 #include <utils/Log.h>
6 #include <hardware/sensors.h>
7 #include "enumeration.h"
8
9 /*
10  * This information should be provided on a sensor basis through a configuration
11  * file, or we should build a catalog of known sensors.
12  */
13
14 #define IIO_SENSOR_HAL_VERSION  1
15
16
17 char* sensor_get_name (int s)
18 {
19         if (sensor_info[s].friendly_name[0] == '\0') {
20
21                 /* If we got a iio device name from sysfs, use it */
22                 if (sensor_info[s].internal_name[0]) {
23                         snprintf(sensor_info[s].friendly_name,
24                                  MAX_NAME_SIZE, "S%d-%s", s,
25                                  sensor_info[s].internal_name);
26                         sensor_info[s].friendly_name[MAX_NAME_SIZE-1] = '\0';
27                 } else
28                         sprintf(sensor_info[s].friendly_name, "S%d", s);
29         }
30
31         return sensor_info[s].friendly_name;
32 }
33
34
35 char* sensor_get_vendor (int s)
36 {
37         if (sensor_info[s].vendor_name[0])
38                 return sensor_info[s].vendor_name;
39
40         return "<unknown>";
41 }
42
43
44 int sensor_get_version (int handle)
45 {
46         return IIO_SENSOR_HAL_VERSION;
47 }
48
49
50 float sensor_get_max_range (int s)
51 {
52         int catalog_index;
53         int sensor_type;
54
55         if (sensor_info[s].max_range != 0.0)
56                 return sensor_info[s].max_range;
57
58         /* Try returning a sensible value given the sensor type */
59
60         /* We should cap returned samples accordingly... */
61
62         catalog_index = sensor_info[s].catalog_index;
63         sensor_type = sensor_catalog[catalog_index].type;
64
65         switch (sensor_type) {
66                 case SENSOR_TYPE_ACCELEROMETER:         /* m/s^2        */
67                         return 50;
68
69                 case SENSOR_TYPE_MAGNETIC_FIELD:        /* micro-tesla  */
70                         return 500;
71
72                 case SENSOR_TYPE_ORIENTATION:           /* degrees      */
73                         return 360;
74
75                 case SENSOR_TYPE_GYROSCOPE:             /* radians/s    */
76                         return 10;
77
78                 case SENSOR_TYPE_LIGHT:                 /* SI lux units */
79                         return 50000;
80
81                 case SENSOR_TYPE_AMBIENT_TEMPERATURE:   /* °C          */
82                 case SENSOR_TYPE_TEMPERATURE:           /* °C          */
83                 case SENSOR_TYPE_PROXIMITY:             /* centimeters  */
84                 case SENSOR_TYPE_PRESSURE:              /* hecto-pascal */
85                 case SENSOR_TYPE_RELATIVE_HUMIDITY:     /* percent */
86                         return 100;
87
88                 default:
89                         return 0.0;
90                 }
91 }
92
93
94 float sensor_get_resolution (int s)
95 {
96         return sensor_info[s].resolution;
97 }
98
99
100 float sensor_get_power (int s)
101 {
102         /* mA used while sensor is in use ; not sure about volts :) */
103         return sensor_info[s].power;
104 }