2 * Copyright (C) 2008 The Android Open Source Project
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.
19 #include <cutils/log.h>
21 #include <cutils/properties.h>
25 #include "BoardConfig.h"
26 #include "SensorConfig.h"
27 #include "HidSensor_Accel3D.h"
28 #include "HidSensor_Gyro3D.h"
29 #include "HidSensor_Compass3D.h"
30 #include "HidSensor_ALS.h"
32 static const struct sensor_t sSensorList[] = {
33 AccelSensor::sSensorInfo_accel3D,
34 GyroSensor::sSensorInfo_gyro3D,
35 CompassSensor::sSensorInfo_compass3D,
36 ALSSensor::sSensorInfo_als,
39 const struct sensor_t* BoardConfig::sensorList()
44 int BoardConfig::sensorListSize()
48 struct dirent *dirp(0);
49 char *key = "persist.sys.sensors.iio.present";
50 char value[PROPERTY_VALUE_MAX];
52 if (property_get(key, value, "")) {
53 if (strncmp(value, "1", 1) == 0) {
54 ALOGI("IIO sensor hub detected previously; assuming it is still attached.");
55 return ARRAY_SIZE(sSensorList);
57 ALOGI("IIO sensor hub not detected previously; assuming it still is not attached.");
62 for (int i=0; i<250; i++) {
64 if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
68 while ((dirp = readdir(dp)) != NULL){
77 ALOGI("Found IIO sensor hub.");
78 if (property_set(key, "1") != 0) {
79 ALOGE("Failed to set %s", key);
81 return ARRAY_SIZE(sSensorList);
84 ALOGI("Didn't find IIO sensor hub.");
85 if (property_set(key, "0") != 0) {
86 ALOGE("Failed to set %s", key);
91 void BoardConfig::initSensors(SensorBase* sensors[])
93 sensors[accel] = new AccelSensor();
94 sensors[gyro] = new GyroSensor();
95 sensors[compass] = new CompassSensor();
96 sensors[light] = new ALSSensor();
99 int BoardConfig::handleToDriver(int handle)