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 "HidSensor_Proximity.h"
32 #include "HidSensor_Pressure.h"
33 #include "OrientationSensor.h"
34 #include "RotVecSensor.h"
35 #include "SynthCompassSensor.h"
37 static const struct sensor_t sSensorList[] = {
38 AccelSensor::sSensorInfo_accel3D,
39 GyroSensor::sSensorInfo_gyro3D,
40 SynthCompassSensor::sSensorInfo_compass,
41 ALSSensor::sSensorInfo_als,
42 ProximitySensor::sSensorInfo_proximity,
43 PressureSensor::sSensorInfo_pressure,
44 RotVecSensor::sSensorInfo_rotvec,
45 OrientationSensor::sSensorInfo_orientation,
48 const struct sensor_t* BoardConfig::sensorList()
53 int BoardConfig::sensorListSize()
57 struct dirent *dirp(0);
58 const char *key = "persist.sys.sensors.iio.present";
59 char value[PROPERTY_VALUE_MAX];
61 if (property_get(key, value, "")) {
62 if (strncmp(value, "1", 1) == 0) {
63 ALOGI("IIO sensor hub detected previously; assuming it is still attached.");
64 return ARRAY_SIZE(sSensorList);
66 ALOGI("IIO sensor hub not detected previously; assuming it still is not attached.");
71 for (int i=0; i<250; i++) {
73 if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
77 while ((dirp = readdir(dp)) != NULL){
86 ALOGI("Found IIO sensor hub.");
87 if (property_set(key, "1") != 0) {
88 ALOGE("Failed to set %s", key);
90 return ARRAY_SIZE(sSensorList);
93 ALOGI("Didn't find IIO sensor hub.");
94 if (property_set(key, "0") != 0) {
95 ALOGE("Failed to set %s", key);
100 void BoardConfig::initSensors(SensorBase* sensors[])
102 sensors[accel] = new AccelSensor();
103 sensors[gyro] = new GyroSensor();
104 sensors[compass] = new CompassSensor();
105 sensors[light] = new ALSSensor();
106 sensors[proximity] = new ProximitySensor();
107 sensors[pressure] = new PressureSensor();
108 sensors[rotvec] = new RotVecSensor();
109 sensors[syncompass] = new SynthCompassSensor();
110 sensors[orientation] = new OrientationSensor();
113 int BoardConfig::handleToDriver(int handle)