OSDN Git Service

Merge branch 'lineage-16.0' of https://github.com/me176c-dev/android_hardware_iio...
[android-x86/hardware-intel-libsensors.git] / discovery.c
1 /*
2 // Copyright (c) 2015 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #include <stdlib.h>
18 #include <utils/Log.h>
19 #include <stdint.h>
20 #include <dirent.h>
21 #include <sys/types.h>
22 #include <hardware/sensors.h>
23
24 #include "common.h"
25
26 void discover_sensors(int dev_num, char *sysfs_base_path, char map[catalog_size],
27                       void (*discover_sensor)(int, char*, char*))
28 {
29         char sysfs_dir[PATH_MAX];
30         DIR *dir;
31         struct dirent *d;
32         unsigned int i;
33
34         memset(map, 0, catalog_size);
35
36         snprintf(sysfs_dir, sizeof(sysfs_dir), sysfs_base_path, dev_num);
37
38         dir = opendir(sysfs_dir);
39         if (!dir) {
40                 return;
41         }
42
43         /* Enumerate entries in this iio device's base folder */
44
45         while ((d = readdir(dir))) {
46                 if (!strncmp(d->d_name, ".", sizeof(".")) || !strncmp(d->d_name, "..", sizeof("..")))
47                         continue;
48
49                 /* If the name matches a catalog entry, flag it */
50                 for (i = 0; i < catalog_size; i++) {
51
52                         /* No discovery for virtual sensors */
53                         if (sensor_catalog[i].is_virtual)
54                                 continue;
55                         discover_sensor(i, d->d_name, map);
56                 }
57         }
58
59         closedir(dir);
60 }
61
62 void check_event_sensors(int i, char *sysfs_file, char map[catalog_size])
63 {
64         int j, k;
65
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)) {
69                                 map[i] = 1;
70                                 return;
71                         }
72                 }
73 }
74
75 void check_poll_sensors (int i, char *sysfs_file, char map[catalog_size])
76 {
77         int c;
78
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)) {
82                         map[i] = 1;
83                         break;
84                 }
85 }
86
87 void check_trig_sensors (int i, char *sysfs_file, char map[catalog_size])
88 {
89
90         if (!strcmp(sysfs_file, sensor_catalog[i].channel[0].en_path)) {
91                 map[i] = 1;
92                 return;
93         }
94 }