X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=bdw_rvp%2FBoardConfig.cpp;fp=bdw_rvp%2FBoardConfig.cpp;h=16e4d297cbb7e90c77c94d5d2969f9cf6143b94e;hb=a7019b7ae4362a1771fa773791943cb4e746bbd8;hp=0000000000000000000000000000000000000000;hpb=c7308c1f363ed0bbe49dfa85bcf6d7ee708f14a5;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/bdw_rvp/BoardConfig.cpp b/bdw_rvp/BoardConfig.cpp new file mode 100644 index 0000000..16e4d29 --- /dev/null +++ b/bdw_rvp/BoardConfig.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "common.h" + +#include "BoardConfig.h" +#include "SensorConfig.h" +#include "HidSensor_Accel3D.h" +#include "HidSensor_Gyro3D.h" +#include "HidSensor_Compass3D.h" +#include "HidSensor_ALS.h" +#include "HidSensor_Pressure.h" +#include "OrientationSensor.h" +#include "RotVecSensor.h" +#include "SynthCompassSensor.h" + +static const struct sensor_t sSensorList[] = { + AccelSensor::sSensorInfo_accel3D, + GyroSensor::sSensorInfo_gyro3D, + SynthCompassSensor::sSensorInfo_compass, + ALSSensor::sSensorInfo_als, + PressureSensor::sSensorInfo_pressure, + RotVecSensor::sSensorInfo_rotvec, + OrientationSensor::sSensorInfo_orientation, +}; + +const struct sensor_t* BoardConfig::sensorList() +{ + return sSensorList; +} + +int BoardConfig::sensorListSize() +{ + int num_files(0); + DIR *dp(0); + struct dirent *dirp(0); + const char *key = "persist.sys.sensors.iio.present"; + char value[PROPERTY_VALUE_MAX]; + + if (property_get(key, value, "")) { + if (strncmp(value, "1", 1) == 0) { + ALOGI("IIO sensor hub detected previously; assuming it is still attached."); + return ARRAY_SIZE(sSensorList); + } else { + ALOGI("IIO sensor hub not detected previously; assuming it still is not attached."); + return 0; + } + } + + for (int i=0; i<250; i++) { + num_files = 0; + if ((dp = opendir("/sys/bus/iio/devices")) == NULL){ + usleep(20000); + continue; + } + while ((dirp = readdir(dp)) != NULL){ + num_files++; + } + closedir(dp); + + if (num_files <= 2) { + usleep(20000); + continue; + } + ALOGI("Found IIO sensor hub."); + if (property_set(key, "1") != 0) { + ALOGE("Failed to set %s", key); + } + return ARRAY_SIZE(sSensorList); + } + + ALOGI("Didn't find IIO sensor hub."); + if (property_set(key, "0") != 0) { + ALOGE("Failed to set %s", key); + } + return 0; +} + +void BoardConfig::initSensors(SensorBase* sensors[]) +{ + sensors[accel] = new AccelSensor(); + sensors[gyro] = new GyroSensor(); + sensors[compass] = new CompassSensor(); + sensors[light] = new ALSSensor(); + sensors[pressure] = new PressureSensor(); + sensors[rotvec] = new RotVecSensor(); + sensors[syncompass] = new SynthCompassSensor(); + sensors[orientation] = new OrientationSensor(); +} + +int BoardConfig::handleToDriver(int handle) +{ + switch (handle) { + case ID_A: + return accel; + case ID_M: + return compass; + case ID_PR: + return pressure; + case ID_T: + return -EINVAL; + case ID_GY: + return gyro; + case ID_L: + return light; + case ID_R: + return rotvec; + case ID_SC: + return syncompass; + case ID_O: + return orientation; + case ID_P: + return -EINVAL; + default: + return -EINVAL; + } + return -EINVAL; +}