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"
31 #include "OrientationSensor.h"
32 #include "RotVecSensor.h"
33 #include "SynthCompassSensor.h"
35 static const struct sensor_t sSensorList[] = {
36 AccelSensor::sSensorInfo_accel3D,
37 GyroSensor::sSensorInfo_gyro3D,
38 SynthCompassSensor::sSensorInfo_compass,
39 ALSSensor::sSensorInfo_als,
40 RotVecSensor::sSensorInfo_rotvec,
41 OrientationSensor::sSensorInfo_orientation,
44 const struct sensor_t* BoardConfig::sensorList()
49 int BoardConfig::sensorListSize()
53 struct dirent *dirp(0);
54 const char *key = "persist.sys.sensors.iio.present";
55 char value[PROPERTY_VALUE_MAX];
57 if (property_get(key, value, "1")) {
58 if (strncmp(value, "1", 1) == 0) {
59 ALOGI("IIO sensor hub detected previously; assuming it is still attached.");
60 return ARRAY_SIZE(sSensorList);
62 ALOGI("IIO sensor hub not detected previously; assuming it still is not attached.");
67 for (int i=0; i<250; i++) {
69 if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
73 while ((dirp = readdir(dp)) != NULL){
82 ALOGI("Found IIO sensor hub.");
83 if (property_set(key, "1") != 0) {
84 ALOGE("Failed to set %s", key);
86 return ARRAY_SIZE(sSensorList);
89 ALOGI("Didn't find IIO sensor hub.");
90 if (property_set(key, "0") != 0) {
91 ALOGE("Failed to set %s", key);
96 void BoardConfig::initSensors(SensorBase* sensors[])
98 sensors[accel] = new AccelSensor();
99 sensors[gyro] = new GyroSensor();
100 sensors[compass] = new CompassSensor();
101 sensors[light] = new ALSSensor();
102 sensors[rotvec] = new RotVecSensor();
103 sensors[syncompass] = new SynthCompassSensor();
104 sensors[orientation] = new OrientationSensor();
107 int BoardConfig::handleToDriver(int handle)