Sensor devices are exporting channel specific scale values as well.
example: in_magn_x_scale, in_magn_y_scale, in_magn_z_scale, etc.
Channel specific scales are enumerated when no common scale(example:
in_magn_scale) is provided.
Issue: GMIN-355
Change-Id: Ib49750228a2f0a44528470672be93dc3945c2bae
Signed-off-by: suyyala <sridhar.uyyala@intel.com>
#define BASE_PATH "/sys/bus/iio/devices/iio:device%d/"
+
#define CHANNEL_PATH BASE_PATH "scan_elements/"
#define ENABLE_PATH BASE_PATH "buffer/enable"
#define NAME_PATH BASE_PATH "name"
#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
+
struct channel_descriptor_t
{
/* sysfs entries located under scan_elements */
/* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
const char *raw_path; /* _raw sysfs file name */
const char *input_path; /* _input sysfs file name */
+ const char *scale_path; /* _scale sysfs file name */
};
struct sensor_catalog_entry_t
{
int offset; /* Offset in bytes within the iio character device report */
int size; /* Field size in bytes */
+ float scale; /* scale for each channel */
char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
struct datum_info_t type_info; /* Decoded contents of type spec */
};
float power;
float offset; /* (cooked = raw + offset) * scale */
- float scale;
+ float scale; /*default: 1. when set to 0, use channel specific value*/
float illumincalib; /* to set the calibration for the ALS */
int sampling_rate; /* requested events / second */
char sysfs_path[PATH_MAX];
const char* prefix;
float scale;
+ int c;
if (sensor_count == MAX_SENSORS) {
ALOGE("Too many sensors!\n");
sysfs_read_float(sysfs_path, &sensor_info[s].offset);
sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
- if (!sysfs_read_float(sysfs_path, &scale))
+ if (!sysfs_read_float(sysfs_path, &scale)) {
sensor_info[s].scale = scale;
- else
+ ALOGI("Scale path %s scale: %f, dev_num =%d \n",
+ sysfs_path, scale, dev_num);
+ }else {
sensor_info[s].scale = 1;
+ /* Read channel specific scale if any*/
+ for (c = 0; c < sensor_catalog[catalog_index].num_channels; c++)
+ {
+ sprintf(sysfs_path, BASE_PATH "%s", dev_num,
+ sensor_catalog[catalog_index].channel[c].scale_path);
+
+ if (!sysfs_read_float(sysfs_path, &scale)) {
+ sensor_info[s].channel[c].scale = scale;
+ sensor_info[s].scale = 0;
+ }
+ ALOGI("Scale path %s channel scale: %f dev_num %d\n",
+ sysfs_path, scale, dev_num);
+ }
+ }
/* Initialize Android-visible descriptor */
sensor_desc[s].name = sensor_get_name(s);
"in_"tag spacer name"_index", \
"in_"tag spacer name"_raw", \
"in_"tag spacer name"_input", \
+ "in_"tag spacer name"_scale", \
},
#define DECLARE_NAMED_CHANNEL(tag, name) DECLARE_CHANNEL(tag, "_", name)
{
struct datum_info_t* sample_type = &sensor_info[s].channel[c].type_info;
int64_t s64 = sample_as_int64(sample_data, sample_type);
-
+ float scale = sensor_info[s].scale ?
+ sensor_info[s].scale : sensor_info[s].channel[c].scale;
/* Apply default scaling rules */
- return (sensor_info[s].offset + s64) * sensor_info[s].scale;
+ return (sensor_info[s].offset + s64) * scale;
}
int i = sensor_info[s].catalog_index;
const char* raw_path = sensor_catalog[i].channel[c].raw_path;
const char* input_path = sensor_catalog[i].channel[c].input_path;
- float scale = sensor_info[s].scale;
+ float scale = sensor_info[s].scale ?
+ sensor_info[s].scale : sensor_info[s].channel[c].scale;
float offset = sensor_info[s].offset;
int sensor_type = sensor_catalog[i].type;