2 // Copyright (c) 2015 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <utils/Log.h>
21 #include <sys/types.h>
22 #include <hardware/sensors.h>
26 void discover_sensors(int dev_num, char *sysfs_base_path, char map[catalog_size],
27 void (*discover_sensor)(int, char*, char*))
29 char sysfs_dir[PATH_MAX];
34 memset(map, 0, catalog_size);
36 snprintf(sysfs_dir, sizeof(sysfs_dir), sysfs_base_path, dev_num);
38 dir = opendir(sysfs_dir);
43 /* Enumerate entries in this iio device's base folder */
45 while ((d = readdir(dir))) {
46 if (!strncmp(d->d_name, ".", sizeof(".")) || !strncmp(d->d_name, "..", sizeof("..")))
49 /* If the name matches a catalog entry, flag it */
50 for (i = 0; i < catalog_size; i++) {
52 /* No discovery for virtual sensors */
53 if (sensor_catalog[i].is_virtual)
55 discover_sensor(i, d->d_name, map);
62 void check_event_sensors(int i, char *sysfs_file, char map[catalog_size])
66 for (j = 0; j < sensor_catalog[i].num_channels; j++)
67 for (k = 0; k < sensor_catalog[i].channel[j].num_events; k++) {
68 if (!strcmp(sysfs_file, sensor_catalog[i].channel[j].event[k].ev_en_path)) {
75 void check_poll_sensors (int i, char *sysfs_file, char map[catalog_size])
79 for (c = 0; c < sensor_catalog[i].num_channels; c++)
80 if (!strcmp(sysfs_file, sensor_catalog[i].channel[c].raw_path) ||
81 !strcmp(sysfs_file, sensor_catalog[i].channel[c].input_path)) {
87 void check_trig_sensors (int i, char *sysfs_file, char map[catalog_size])
90 if (!strcmp(sysfs_file, sensor_catalog[i].channel[0].en_path)) {