2 * Copyright (C) 2014 Intel Corporation.
6 #include <hardware/sensors.h>
7 #include "enumeration.h"
10 * This information should be provided on a sensor basis through a configuration
11 * file, or we should build a catalog of known sensors.
14 #define IIO_SENSOR_HAL_VERSION 1
17 char* sensor_get_name (int s)
19 if (sensor_info[s].friendly_name[0] == '\0') {
21 /* If we got a iio device name from sysfs, use it */
22 if (sensor_info[s].internal_name[0])
23 sprintf(sensor_info[s].friendly_name, "S%d-%s", s,
24 sensor_info[s].internal_name);
26 sprintf(sensor_info[s].friendly_name, "S%d", s);
29 return sensor_info[s].friendly_name;
33 char* sensor_get_vendor (int s)
35 if (sensor_info[s].vendor_name[0])
36 return sensor_info[s].vendor_name;
42 int sensor_get_version (int handle)
44 return IIO_SENSOR_HAL_VERSION;
48 float sensor_get_max_range (int s)
53 if (sensor_info[s].max_range != 0.0)
54 return sensor_info[s].max_range;
56 /* Try returning a sensible value given the sensor type */
58 /* We should cap returned samples accordingly... */
60 catalog_index = sensor_info[s].catalog_index;
61 sensor_type = sensor_catalog[catalog_index].type;
63 switch (sensor_type) {
64 case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */
67 case SENSOR_TYPE_MAGNETIC_FIELD: /* micro-tesla */
70 case SENSOR_TYPE_ORIENTATION: /* degrees */
73 case SENSOR_TYPE_GYROSCOPE: /* radians/s */
76 case SENSOR_TYPE_LIGHT: /* SI lux units */
79 case SENSOR_TYPE_AMBIENT_TEMPERATURE: /* °C */
80 case SENSOR_TYPE_TEMPERATURE: /* °C */
81 case SENSOR_TYPE_PROXIMITY: /* centimeters */
82 case SENSOR_TYPE_PRESSURE: /* hecto-pascal */
83 case SENSOR_TYPE_RELATIVE_HUMIDITY: /* percent */
92 float sensor_get_resolution (int s)
94 return sensor_info[s].resolution;
98 float sensor_get_power (int s)
100 /* mA used while sensor is in use ; not sure about volts :) */
101 return sensor_info[s].power;