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 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';
28 sprintf(sensor_info[s].friendly_name, "S%d", s);
31 return sensor_info[s].friendly_name;
35 char* sensor_get_vendor (int s)
37 if (sensor_info[s].vendor_name[0])
38 return sensor_info[s].vendor_name;
44 int sensor_get_version (int handle)
46 return IIO_SENSOR_HAL_VERSION;
50 float sensor_get_max_range (int s)
55 if (sensor_info[s].max_range != 0.0)
56 return sensor_info[s].max_range;
58 /* Try returning a sensible value given the sensor type */
60 /* We should cap returned samples accordingly... */
62 catalog_index = sensor_info[s].catalog_index;
63 sensor_type = sensor_catalog[catalog_index].type;
65 switch (sensor_type) {
66 case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */
69 case SENSOR_TYPE_MAGNETIC_FIELD: /* micro-tesla */
72 case SENSOR_TYPE_ORIENTATION: /* degrees */
75 case SENSOR_TYPE_GYROSCOPE: /* radians/s */
78 case SENSOR_TYPE_LIGHT: /* SI lux units */
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 */
94 float sensor_get_resolution (int s)
96 return sensor_info[s].resolution;
100 float sensor_get_power (int s)
102 /* mA used while sensor is in use ; not sure about volts :) */
103 return sensor_info[s].power;