From 1413351f63cc2ad6186f1a99ae4316088412c6fe Mon Sep 17 00:00:00 2001 From: Wolfgang Wiedmeyer Date: Wed, 22 Feb 2017 14:04:12 +0100 Subject: remove unused sensor implementation Signed-off-by: Wolfgang Wiedmeyer --- libsensors/AccelSensor.cpp | 156 --------------- libsensors/AccelSensor.h | 70 ------- libsensors/AkmSensor.cpp | 322 ------------------------------ libsensors/AkmSensor.h | 66 ------- libsensors/Android.mk | 47 ----- libsensors/GyroSensor.cpp | 178 ----------------- libsensors/GyroSensor.h | 55 ------ libsensors/InputEventReader.cpp | 89 --------- libsensors/InputEventReader.h | 47 ----- libsensors/LightSensor.cpp | 149 -------------- libsensors/LightSensor.h | 55 ------ libsensors/MODULE_LICENSE_APACHE2 | 0 libsensors/PressureSensor.cpp | 153 --------------- libsensors/PressureSensor.h | 54 ----- libsensors/ProximitySensor.cpp | 159 --------------- libsensors/ProximitySensor.h | 55 ------ libsensors/SensorBase.cpp | 185 ------------------ libsensors/SensorBase.h | 72 ------- libsensors/ak8973b.h | 51 ----- libsensors/sensors.cpp | 400 -------------------------------------- libsensors/sensors.h | 135 ------------- 21 files changed, 2498 deletions(-) delete mode 100644 libsensors/AccelSensor.cpp delete mode 100644 libsensors/AccelSensor.h delete mode 100644 libsensors/AkmSensor.cpp delete mode 100644 libsensors/AkmSensor.h delete mode 100644 libsensors/Android.mk delete mode 100644 libsensors/GyroSensor.cpp delete mode 100644 libsensors/GyroSensor.h delete mode 100644 libsensors/InputEventReader.cpp delete mode 100644 libsensors/InputEventReader.h delete mode 100644 libsensors/LightSensor.cpp delete mode 100644 libsensors/LightSensor.h delete mode 100644 libsensors/MODULE_LICENSE_APACHE2 delete mode 100644 libsensors/PressureSensor.cpp delete mode 100644 libsensors/PressureSensor.h delete mode 100644 libsensors/ProximitySensor.cpp delete mode 100644 libsensors/ProximitySensor.h delete mode 100644 libsensors/SensorBase.cpp delete mode 100644 libsensors/SensorBase.h delete mode 100644 libsensors/ak8973b.h delete mode 100644 libsensors/sensors.cpp delete mode 100644 libsensors/sensors.h diff --git a/libsensors/AccelSensor.cpp b/libsensors/AccelSensor.cpp deleted file mode 100644 index 7b6ba67..0000000 --- a/libsensors/AccelSensor.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include "AccelSensor.h" - -#define LOGTAG "AccelerometerSensor" - -/*****************************************************************************/ -AccelSensor::AccelSensor() - : SensorBase(NULL, "accelerometer_sensor"), - mEnabled(0), - - mInputReader(4), - mHasPendingEvent(false) -{ - mPendingEvent.version = sizeof(sensors_event_t); - mPendingEvent.sensor = ID_A; - mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER; - memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); - - if (data_fd) { - strcpy(input_sysfs_path, "/sys/class/input/"); - strcat(input_sysfs_path, input_name); - strcat(input_sysfs_path, "/device/"); - input_sysfs_path_len = strlen(input_sysfs_path); - } -} - -AccelSensor::~AccelSensor() { - - // ALOGD("AccelSensor::~AccelSensor()"); - if (mEnabled) { - enable(0, 0); - } -} - -int AccelSensor::setInitialState() -{ - return 0; -} - -int AccelSensor::enable(int32_t handle, int en) { - int flags = en ? 1 : 0; - int err; - if (flags != mEnabled) { - err = sspEnable(LOGTAG, SSP_ACCEL, en); - if(err >= 0){ - mEnabled = flags; - setInitialState(); - - return 0; - } - return -1; - } - return 0; -} - - -bool AccelSensor::hasPendingEvents() const { - /* FIXME probably here should be returning mEnabled but instead - mHasPendingEvents. It does not work, so we cheat.*/ - //ALOGD("AccelSensor::~hasPendingEvents %d", mHasPendingEvent ? 1 : 0 ); - return mHasPendingEvent; -} - - -int AccelSensor::setDelay(int32_t handle, int64_t ns) -{ - int fd; - - if (ns < 10000000) { - ns = 10000000; // Minimum on stock - } - - strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); - fd = open(input_sysfs_path, O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - return 0; - } - return -1; -} - - -int AccelSensor::readEvents(sensors_event_t* data, int count) -{ - if (count < 1) - return -EINVAL; - - if (mHasPendingEvent) { - mHasPendingEvent = false; - mPendingEvent.timestamp = getTimestamp(); - *data = mPendingEvent; - return mEnabled ? 1 : 0; - } - - ssize_t n = mInputReader.fill(data_fd); - if (n < 0) - return n; - int numEventReceived = 0; - input_event const* event; - - while (count && mInputReader.readEvent(&event)) { - int type = event->type; - if (type == EV_REL) { - float value = event->value; - if (event->code == EVENT_TYPE_ACCEL_X) { - mPendingEvent.acceleration.x = value * CONVERT_A_X; - } else if (event->code == EVENT_TYPE_ACCEL_Y) { - mPendingEvent.acceleration.y = value * CONVERT_A_Y; - } else if (event->code == EVENT_TYPE_ACCEL_Z) { - mPendingEvent.acceleration.z = value * CONVERT_A_Z; - } - } else if (type == EV_SYN) { - mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled) { - *data++ = mPendingEvent; - count--; - numEventReceived++; - } - } else { - ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, - type, event->code); - } - - mInputReader.next(); - } - return numEventReceived++; - -} diff --git a/libsensors/AccelSensor.h b/libsensors/AccelSensor.h deleted file mode 100644 index 0162147..0000000 --- a/libsensors/AccelSensor.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_SMB380_SENSOR_H -#define ANDROID_SMB380_SENSOR_H - -#include -#include -#include -#include - -#include "sensors.h" -#include "SensorBase.h" -#include "InputEventReader.h" - -/*****************************************************************************/ - - -struct smb380acc_t { - short x, /**< holds x-axis acceleration data sign extended. Range -512 to 511. */ - y, /**< holds y-axis acceleration data sign extended. Range -512 to 511. */ - z; /**< holds z-axis acceleration data sign extended. Range -512 to 511. */ -} ; - -/* smb ioctl command label */ -#define IOCTL_SMB_GET_ACC_VALUE 0 -#define DCM_IOC_MAGIC 's' -#define IOC_SET_ACCELEROMETER _IO (DCM_IOC_MAGIC, 0x64) -#define BMA150_CALIBRATION _IOWR(DCM_IOC_MAGIC,48,short) - -#define SMB_POWER_OFF 0 -#define SMB_POWER_ON 1 - -struct input_event; - -class AccelSensor : public SensorBase { - int mEnabled; - InputEventCircularReader mInputReader; - sensors_event_t mPendingEvent; - bool mHasPendingEvent; - char input_sysfs_path[PATH_MAX]; - int input_sysfs_path_len; - - int setInitialState(); - -public: - AccelSensor(); - virtual ~AccelSensor(); - virtual int readEvents(sensors_event_t* data, int count); - virtual bool hasPendingEvents() const; - virtual int setDelay(int32_t handle, int64_t ns); - virtual int enable(int32_t handle, int enabled); -}; - -/*****************************************************************************/ - -#endif // ANDROID_GYRO_SENSOR_H diff --git a/libsensors/AkmSensor.cpp b/libsensors/AkmSensor.cpp deleted file mode 100644 index d82e6f8..0000000 --- a/libsensors/AkmSensor.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include "ak8973b.h" - -#include -#include "AkmSensor.h" - -#define LOGTAG "AkmSensor" - -//#define ALOG_NDEBUG 0 - -/*****************************************************************************/ - -int (*akm_is_sensor_enabled)(uint32_t sensor_type); -int (*akm_enable_sensor)(uint32_t sensor_type); -int (*akm_disable_sensor)(uint32_t sensor_type); -int (*akm_set_delay)(uint32_t sensor_type, uint64_t delay); - -int stub_is_sensor_enabled(uint32_t sensor_type) { - return 0; -} - -int stub_enable_disable_sensor(uint32_t sensor_type) { - return -ENODEV; -} - -int stub_set_delay(uint32_t sensor_type, uint64_t delay) { - return -ENODEV; -} - - -AkmSensor::AkmSensor() -: SensorBase(NULL, NULL), - mEnabled(0), - mPendingMask(0), - mInputReader(32) -{ - /* Open the library before opening the input device. The library - * creates a uinput device. - */ - if (loadAKMLibrary() == 0) { - data_name = "compass_sensor"; - data_fd = openInput("compass_sensor"); - } - - //Incase first time fails - if(data_fd < 0){ - ALOGI("%s: retrying to open compass sensor", LOGTAG); - data_fd = openInput("compass_sensor"); - } - - if(data_fd > 0){ - ALOGI("%s: compass sensor successfully opened: %i", LOGTAG, data_fd); - }else{ - ALOGI("%s: failed to open compass sensor", LOGTAG); - } - - memset(mPendingEvents, 0, sizeof(mPendingEvents)); - - mPendingEvents[Accelerometer].version = sizeof(sensors_event_t); - mPendingEvents[Accelerometer].sensor = ID_A; - mPendingEvents[Accelerometer].type = SENSOR_TYPE_ACCELEROMETER; - mPendingEvents[Accelerometer].acceleration.status = SENSOR_STATUS_UNRELIABLE; - - mPendingEvents[MagneticField].version = sizeof(sensors_event_t); - mPendingEvents[MagneticField].sensor = ID_M; - mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD; - mPendingEvents[MagneticField].magnetic.status = SENSOR_STATUS_ACCURACY_HIGH; - - // read the actual value of all sensors if they're enabled already - struct input_absinfo absinfo; - short flags = 0; - - if (akm_is_sensor_enabled(SENSOR_TYPE_ACCELEROMETER)) { - mEnabled |= 1<= numSensors) - return -EINVAL; - - int newState = en ? 1 : 0; - int err = 0; - - if ((uint32_t(newState)<= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - } - - fd = open("/sys/class/sensors/ssp_sensor/ori_poll_delay", O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - } - - mDelays[what] = ns; - return update_delay(); -} - -int AkmSensor::update_delay() -{ - if (mEnabled) { - uint64_t wanted = -1LLU; - for (int i=0 ; itype; - if (type == EV_REL) { - processEvent(event->code, event->value); - mInputReader.next(); - } else if (type == EV_ABS) { - processEvent(event->code, event->value); - mInputReader.next(); - } else if (type == EV_SYN) { - int64_t time = timevalToNano(event->time); - for (int j=0 ; count && mPendingMask && jcode); - mInputReader.next(); - } - } - return numEventReceived; -} - -void AkmSensor::processEvent(int code, int value) -{ - switch (code) { - case EVENT_TYPE_MAGV_X: - mPendingMask |= 1<%d", value); - mPendingMask |= 1< -#include -#include -#include - - -#include "sensors.h" -#include "SensorBase.h" -#include "InputEventReader.h" - -/*****************************************************************************/ - -struct input_event; - -class AkmSensor : public SensorBase { -public: - AkmSensor(); - virtual ~AkmSensor(); - - enum { - Accelerometer = 0, - MagneticField = 1, - Orientation = 2, - numSensors - }; - - virtual int setDelay(int32_t handle, int64_t ns); - virtual int enable(int32_t handle, int enabled); - virtual int readEvents(sensors_event_t* data, int count); - void processEvent(int code, int value); - - int setInitialState(); - -private: - int loadAKMLibrary(); - int update_delay(); - void *mLibAKM; - uint32_t mEnabled; - uint32_t mPendingMask; - InputEventCircularReader mInputReader; - sensors_event_t mPendingEvents[numSensors]; - uint64_t mDelays[numSensors]; -}; - -/*****************************************************************************/ - -#endif // ANDROID_AKM_SENSOR_H diff --git a/libsensors/Android.mk b/libsensors/Android.mk deleted file mode 100644 index 47a90e5..0000000 --- a/libsensors/Android.mk +++ /dev/null @@ -1,47 +0,0 @@ -# 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. - - -LOCAL_PATH := $(call my-dir) - -ifneq ($(TARGET_SIMULATOR),true) - -# HAL module implemenation, not prelinked, and stored in -# hw/..so -include $(CLEAR_VARS) - -LOCAL_MODULE := sensors.$(TARGET_BOOTLOADER_BOARD_NAME) - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw - -LOCAL_MODULE_TAGS := optional - -LOCAL_CFLAGS := -DALOG_TAG=\"Sensors\" -LOCAL_SRC_FILES := \ - sensors.cpp \ - SensorBase.cpp \ - LightSensor.cpp \ - ProximitySensor.cpp \ - AkmSensor.cpp \ - GyroSensor.cpp \ - InputEventReader.cpp \ - AccelSensor.cpp \ - PressureSensor.cpp - -LOCAL_SHARED_LIBRARIES := liblog libcutils libdl -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) - -endif # !TARGET_SIMULATOR diff --git a/libsensors/GyroSensor.cpp b/libsensors/GyroSensor.cpp deleted file mode 100644 index 75a24ca..0000000 --- a/libsensors/GyroSensor.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include "GyroSensor.h" - -#define LOGTAG "GyroSensor" - -#define FETCH_FULL_EVENT_BEFORE_RETURN 1 -#define IGNORE_EVENT_TIME 350000000 -/*****************************************************************************/ - -GyroSensor::GyroSensor() - : SensorBase(NULL, "gyro_sensor"), - mEnabled(0), - mInputReader(4), - mHasPendingEvent(false), - mEnabledTime(0) -{ - mPendingEvent.version = sizeof(sensors_event_t); - mPendingEvent.sensor = ID_GY; - mPendingEvent.type = SENSOR_TYPE_GYROSCOPE; - memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); - - if (data_fd) { - strcpy(input_sysfs_path, "/sys/class/input/"); - strcat(input_sysfs_path, input_name); - strcat(input_sysfs_path, "/device/"); - input_sysfs_path_len = strlen(input_sysfs_path); - enable(0, 1); - } -} - -GyroSensor::~GyroSensor() { - if (mEnabled) { - enable(0, 0); - } -} - -int GyroSensor::setInitialState() { - struct input_absinfo absinfo_x; - struct input_absinfo absinfo_y; - struct input_absinfo absinfo_z; - float value; - if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_x) && - !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_y) && - !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_z)) { - value = absinfo_x.value; - mPendingEvent.data[0] = value * CONVERT_GYRO_X; - value = absinfo_x.value; - mPendingEvent.data[1] = value * CONVERT_GYRO_Y; - value = absinfo_x.value; - mPendingEvent.data[2] = value * CONVERT_GYRO_Z; - mHasPendingEvent = true; - } - return 0; -} - -int GyroSensor::enable(int32_t handle, int en) { - int flags = en ? 1 : 0; - int err; - if (flags != mEnabled) { - err = sspEnable(LOGTAG, SSP_GYRO, en); - if(err >= 0){ - mEnabled = flags; - setInitialState(); - - return 0; - } - return -1; - } - return 0; -} - -bool GyroSensor::hasPendingEvents() const { - return mHasPendingEvent; -} - -int GyroSensor::setDelay(int32_t handle, int64_t ns) -{ - int fd; - - strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); - fd = open(input_sysfs_path, O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - return 0; - } - return -1; -} - -int GyroSensor::readEvents(sensors_event_t* data, int count) -{ - if (count < 1) - return -EINVAL; - - if (mHasPendingEvent) { - mHasPendingEvent = false; - mPendingEvent.timestamp = getTimestamp(); - *data = mPendingEvent; - return mEnabled ? 1 : 0; - } - - ssize_t n = mInputReader.fill(data_fd); - if (n < 0) - return n; - - int numEventReceived = 0; - input_event const* event; - -#if FETCH_FULL_EVENT_BEFORE_RETURN -again: -#endif - while (count && mInputReader.readEvent(&event)) { - int type = event->type; - if (type == EV_REL) { - float value = event->value; - if (event->code == EVENT_TYPE_GYRO_X) { - mPendingEvent.data[0] = value * CONVERT_GYRO_X; - } else if (event->code == EVENT_TYPE_GYRO_Y) { - mPendingEvent.data[1] = value * CONVERT_GYRO_Y; - } else if (event->code == EVENT_TYPE_GYRO_Z) { - mPendingEvent.data[2] = value * CONVERT_GYRO_Z; - } - } else if (type == EV_SYN) { - mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled) { - if (mPendingEvent.timestamp >= mEnabledTime) { - *data++ = mPendingEvent; - numEventReceived++; - } - count--; - } - } else { - ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, - type, event->code); - } - mInputReader.next(); - } - -#if FETCH_FULL_EVENT_BEFORE_RETURN - /* if we didn't read a complete event, see if we can fill and - try again instead of returning with nothing and redoing poll. */ - if (numEventReceived == 0 && mEnabled == 1) { - n = mInputReader.fill(data_fd); - if (n) - goto again; - } -#endif - - return numEventReceived; -} - diff --git a/libsensors/GyroSensor.h b/libsensors/GyroSensor.h deleted file mode 100644 index e8997de..0000000 --- a/libsensors/GyroSensor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_GYRO_SENSOR_H -#define ANDROID_GYRO_SENSOR_H - -#include -#include -#include -#include - -#include "sensors.h" -#include "SensorBase.h" -#include "InputEventReader.h" - -/*****************************************************************************/ - -struct input_event; - -class GyroSensor : public SensorBase { - int mEnabled; - InputEventCircularReader mInputReader; - sensors_event_t mPendingEvent; - bool mHasPendingEvent; - char input_sysfs_path[PATH_MAX]; - int input_sysfs_path_len; - int64_t mEnabledTime; - - int setInitialState(); - -public: - GyroSensor(); - virtual ~GyroSensor(); - virtual int readEvents(sensors_event_t* data, int count); - virtual bool hasPendingEvents() const; - virtual int setDelay(int32_t handle, int64_t ns); - virtual int enable(int32_t handle, int enabled); -}; - -/*****************************************************************************/ - -#endif // ANDROID_GYRO_SENSOR_H diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp deleted file mode 100644 index ab23a22..0000000 --- a/libsensors/InputEventReader.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 -#include - -#include - -#include - -#include "InputEventReader.h" - -/*****************************************************************************/ - -struct input_event; - -InputEventCircularReader::InputEventCircularReader(size_t numEvents) - : mBuffer(new input_event[numEvents * 2]), - mBufferEnd(mBuffer + numEvents), - mHead(mBuffer), - mCurr(mBuffer), - mFreeSpace(numEvents) -{ -} - -InputEventCircularReader::~InputEventCircularReader() -{ - delete [] mBuffer; -} - -ssize_t InputEventCircularReader::fill(int fd) -{ - size_t numEventsRead = 0; - if (mFreeSpace) { - const ssize_t nread = read(fd, mHead, mFreeSpace * sizeof(input_event)); - if (nread<0 || nread % sizeof(input_event)) { - // we got a partial event!! - return nread<0 ? -errno : -EINVAL; - } - - numEventsRead = nread / sizeof(input_event); - if (numEventsRead) { - mHead += numEventsRead; - mFreeSpace -= numEventsRead; - if (mHead > mBufferEnd) { - size_t s = mHead - mBufferEnd; - memcpy(mBuffer, mBufferEnd, s * sizeof(input_event)); - mHead = mBuffer + s; - } - } - } - - return numEventsRead; -} - -ssize_t InputEventCircularReader::readEvent(input_event const** events) -{ - *events = mCurr; - ssize_t available = (mBufferEnd - mBuffer) - mFreeSpace; - return available ? 1 : 0; -} - -void InputEventCircularReader::next() -{ - mCurr++; - mFreeSpace++; - if (mCurr >= mBufferEnd) { - mCurr = mBuffer; - } -} diff --git a/libsensors/InputEventReader.h b/libsensors/InputEventReader.h deleted file mode 100644 index 180aade..0000000 --- a/libsensors/InputEventReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_INPUT_EVENT_READER_H -#define ANDROID_INPUT_EVENT_READER_H - -#include -#include -#include -#include - -/*****************************************************************************/ - -struct input_event; - -class InputEventCircularReader -{ - struct input_event* const mBuffer; - struct input_event* const mBufferEnd; - struct input_event* mHead; - struct input_event* mCurr; - ssize_t mFreeSpace; - -public: - InputEventCircularReader(size_t numEvents); - ~InputEventCircularReader(); - ssize_t fill(int fd); - ssize_t readEvent(input_event const** events); - void next(); -}; - -/*****************************************************************************/ - -#endif // ANDROID_INPUT_EVENT_READER_H diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp deleted file mode 100644 index 4423412..0000000 --- a/libsensors/LightSensor.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * 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 -#include -#include - -#include - -#include "LightSensor.h" - -#define LOGTAG "LightSensor" - -// #define ALOG_NDEBUG 0 - -/*****************************************************************************/ - -LightSensor::LightSensor() - : SensorBase(NULL, "light_sensor"), - mEnabled(0), - mInputReader(4), - mHasPendingEvent(false) -{ - mPendingEvent.version = sizeof(sensors_event_t); - mPendingEvent.sensor = ID_L; - mPendingEvent.type = SENSOR_TYPE_LIGHT; - memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); - - if (data_fd) { - strcpy(input_sysfs_path, "/sys/class/input/"); - strcat(input_sysfs_path, input_name); - strcat(input_sysfs_path, "/device/"); - input_sysfs_path_len = strlen(input_sysfs_path); - enable(0, 1); - } -} - -LightSensor::~LightSensor() { - if (mEnabled) { - enable(0, 0); - } -} - -int LightSensor::setInitialState() { - struct input_absinfo absinfo; - if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_LIGHT), &absinfo)) { - // make sure to report an event immediately - mHasPendingEvent = true; - mPendingEvent.light = absinfo.value; - } - return 0; -} - -int LightSensor::setDelay(int32_t handle, int64_t ns) -{ - int fd; - - strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); - fd = open(input_sysfs_path, O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - return 0; - } - return -1; -} - -int LightSensor::enable(int32_t handle, int en) -{ - int flags = en ? 1 : 0; - int err; - if (flags != mEnabled) { - err = sspEnable(LOGTAG, SSP_LIGHT, en); - if(err >= 0){ - mEnabled = flags; - setInitialState(); - - return 0; - } - return -1; - } - return 0; -} - -bool LightSensor::hasPendingEvents() const { - return mHasPendingEvent; -} - -int LightSensor::readEvents(sensors_event_t* data, int count) -{ - if (count < 1) - return -EINVAL; - - if (mHasPendingEvent) { - mHasPendingEvent = false; - mPendingEvent.timestamp = getTimestamp(); - *data = mPendingEvent; - return mEnabled ? 1 : 0; - } - - ssize_t n = mInputReader.fill(data_fd); - if (n < 0) - return n; - - int numEventReceived = 0; - input_event const* event; - - while (count && mInputReader.readEvent(&event)) { - int type = event->type; - if (type == EV_REL) { - if (event->code == EVENT_TYPE_LIGHT) { - mPendingEvent.light = event->value; - } - } else if (type == EV_SYN) { - mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled) { - *data++ = mPendingEvent; - count--; - numEventReceived++; - } - } else { - ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, - type, event->code); - } - mInputReader.next(); - } - - return numEventReceived; -} diff --git a/libsensors/LightSensor.h b/libsensors/LightSensor.h deleted file mode 100644 index 85e65d9..0000000 --- a/libsensors/LightSensor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_LIGHT_SENSOR_H -#define ANDROID_LIGHT_SENSOR_H - -#include -#include -#include -#include - -#include "sensors.h" -#include "SensorBase.h" -#include "InputEventReader.h" - -/*****************************************************************************/ - -struct input_event; - -class LightSensor : public SensorBase { - int mEnabled; - InputEventCircularReader mInputReader; - sensors_event_t mPendingEvent; - bool mHasPendingEvent; - char input_sysfs_path[PATH_MAX]; - int input_sysfs_path_len; - - float indexToValue(size_t index) const; - int setInitialState(); - -public: - LightSensor(); - virtual ~LightSensor(); - virtual int readEvents(sensors_event_t* data, int count); - virtual bool hasPendingEvents() const; - virtual int setDelay(int32_t handle, int64_t ns); - virtual int enable(int32_t handle, int enabled); -}; - -/*****************************************************************************/ - -#endif // ANDROID_LIGHT_SENSOR_H diff --git a/libsensors/MODULE_LICENSE_APACHE2 b/libsensors/MODULE_LICENSE_APACHE2 deleted file mode 100644 index e69de29..0000000 diff --git a/libsensors/PressureSensor.cpp b/libsensors/PressureSensor.cpp deleted file mode 100644 index e77ee79..0000000 --- a/libsensors/PressureSensor.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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 -#include -#include - -#include - -#include "PressureSensor.h" - -#define LOGTAG "PressureSensor" - -/* - * The BMP driver gives pascal values. - * It needs to be changed into hectoPascal - */ -#define PRESSURE_HECTO (1.0f/100.0f) - -/*****************************************************************************/ - -PressureSensor::PressureSensor() - : SensorBase(NULL, "pressure_sensor"), - mEnabled(0), - mInputReader(4), - mHasPendingEvent(false) -{ - mPendingEvent.version = sizeof(sensors_event_t); - mPendingEvent.sensor = ID_PR; - mPendingEvent.type = SENSOR_TYPE_PRESSURE; - memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); - - if (data_fd) { - strcpy(input_sysfs_path, "/sys/class/input/"); - strcat(input_sysfs_path, input_name); - strcat(input_sysfs_path, "/device/"); - input_sysfs_path_len = strlen(input_sysfs_path); - enable(0, 1); - } -} - -PressureSensor::~PressureSensor() { - if (mEnabled) { - enable(0, 0); - } -} - -int PressureSensor::setInitialState() { - struct input_absinfo absinfo; - if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PRESSURE), &absinfo)) { - // make sure to report an event immediately - mHasPendingEvent = true; - mPendingEvent.pressure = absinfo.value * PRESSURE_HECTO; - } - return 0; -} - -int PressureSensor::enable(int32_t handle, int en) { - int flags = en ? 1 : 0; - int err; - if (flags != mEnabled) { - err = sspEnable(LOGTAG, SSP_PRESS, en); - if(err >= 0){ - mEnabled = flags; - setInitialState(); - - return 0; - } - return -1; - } - return 0; -} - -bool PressureSensor::hasPendingEvents() const { - return mHasPendingEvent; -} - -int PressureSensor::setDelay(int32_t handle, int64_t ns) -{ - int fd; - - strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); - fd = open(input_sysfs_path, O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - return 0; - } - return -1; -} - - -int PressureSensor::readEvents(sensors_event_t* data, int count) -{ - if (count < 1) - return -EINVAL; - - if (mHasPendingEvent) { - mHasPendingEvent = false; - mPendingEvent.timestamp = getTimestamp(); - *data = mPendingEvent; - return mEnabled ? 1 : 0; - } - - ssize_t n = mInputReader.fill(data_fd); - if (n < 0) - return n; - - int numEventReceived = 0; - input_event const* event; - - while (count && mInputReader.readEvent(&event)) { - int type = event->type; - if (type == EV_REL) { - if (event->code == EVENT_TYPE_PRESSURE) { - mPendingEvent.pressure = event->value * PRESSURE_HECTO; - } - } else if (type == EV_SYN) { - mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled) { - *data++ = mPendingEvent; - count--; - numEventReceived++; - } - } else { - ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, - type, event->code); - } - mInputReader.next(); - } - - return numEventReceived; -} diff --git a/libsensors/PressureSensor.h b/libsensors/PressureSensor.h deleted file mode 100644 index 9333d44..0000000 --- a/libsensors/PressureSensor.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_PRESSURE_SENSOR_H -#define ANDROID_PRESSURE_SENSOR_H - -#include -#include -#include -#include - -#include "sensors.h" -#include "SensorBase.h" -#include "InputEventReader.h" - -/*****************************************************************************/ - -struct input_event; - -class PressureSensor : public SensorBase { - int mEnabled; - InputEventCircularReader mInputReader; - sensors_event_t mPendingEvent; - bool mHasPendingEvent; - char input_sysfs_path[PATH_MAX]; - int input_sysfs_path_len; - - int setInitialState(); - -public: - PressureSensor(); - virtual ~PressureSensor(); - virtual int readEvents(sensors_event_t* data, int count); - virtual bool hasPendingEvents() const; - virtual int enable(int32_t handle, int enabled); - virtual int setDelay(int32_t handle, int64_t ns); -}; - -/*****************************************************************************/ - -#endif // ANDROID_PRESSURE_SENSOR_H diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp deleted file mode 100644 index ab7db13..0000000 --- a/libsensors/ProximitySensor.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include - -#include "ProximitySensor.h" -#include "SensorBase.h" - -#define LOGTAG "ProximitySensor" - -/*****************************************************************************/ - -ProximitySensor::ProximitySensor() - : SensorBase(NULL, "proximity_sensor"), - mEnabled(0), - mInputReader(4), - mHasPendingEvent(false) -{ - mPendingEvent.version = sizeof(sensors_event_t); - mPendingEvent.sensor = ID_P; - mPendingEvent.type = SENSOR_TYPE_PROXIMITY; - memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); - - if (data_fd) { - strcpy(input_sysfs_path, "/sys/class/input/"); - strcat(input_sysfs_path, input_name); - strcat(input_sysfs_path, "/device/"); - input_sysfs_path_len = strlen(input_sysfs_path); - enable(0, 1); - } -} - -ProximitySensor::~ProximitySensor() { - if (mEnabled) { - enable(0, 0); - } -} - -int ProximitySensor::setInitialState() { - struct input_absinfo absinfo; - if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PROXIMITY), &absinfo)) { - // make sure to report an event immediately - mHasPendingEvent = true; - mPendingEvent.distance = indexToValue(absinfo.value); - } - return 0; -} - -int ProximitySensor::setDelay(int32_t handle, int64_t ns) -{ - int fd; - - strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); - fd = open(input_sysfs_path, O_RDWR); - if (fd >= 0) { - char buf[80]; - sprintf(buf, "%lld", ns); - write(fd, buf, strlen(buf)+1); - close(fd); - return 0; - } - return -1; -} - -int ProximitySensor::enable(int32_t handle, int en) { - - int flags = en ? 1 : 0; - int err; - //ALOGD("%s: Enable: %i", __func__, en); - if (flags != mEnabled) { - err = sspEnable(LOGTAG, SSP_PROX, en); - if(err >= 0){ - mEnabled = flags; - setInitialState(); - - return 0; - } - return -1; - } - return 0; -} - -bool ProximitySensor::hasPendingEvents() const { - return mHasPendingEvent; -} - -int ProximitySensor::readEvents(sensors_event_t* data, int count) -{ - if (count < 1) - return -EINVAL; - - if (mHasPendingEvent) { - mHasPendingEvent = false; - mPendingEvent.timestamp = getTimestamp(); - *data = mPendingEvent; - return mEnabled ? 1 : 0; - } - - ssize_t n = mInputReader.fill(data_fd); - if (n < 0) - return n; - - int numEventReceived = 0; - input_event const* event; - - while (count && mInputReader.readEvent(&event)) { - int type = event->type; - if (type == EV_ABS) { - if (event->code == EVENT_TYPE_PROXIMITY) { - if (event->value != -1) { - // FIXME: not sure why we're getting -1 sometimes - mPendingEvent.distance = indexToValue(event->value); - } - } - } else if (type == EV_SYN) { - mPendingEvent.timestamp = timevalToNano(event->time); - if (mEnabled) { - *data++ = mPendingEvent; - count--; - numEventReceived++; - } - } else { - ALOGE("%s: unknown event (type=%d, code=%d)",LOGTAG, - type, event->code); - } - mInputReader.next(); - } - - return numEventReceived; -} - -float ProximitySensor::indexToValue(size_t index) const -{ - ALOGV("%s: Index = %zu",LOGTAG, index); - return index * PROXIMITY_THRESHOLD_CM; -} diff --git a/libsensors/ProximitySensor.h b/libsensors/ProximitySensor.h deleted file mode 100644 index a6aa851..0000000 --- a/libsensors/ProximitySensor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_PROXIMITY_SENSOR_H -#define ANDROID_PROXIMITY_SENSOR_H - -#include -#include -#include -#include - -#include "sensors.h" -#include "SensorBase.h" -#include "InputEventReader.h" - -/*****************************************************************************/ - -struct input_event; - -class ProximitySensor : public SensorBase { - int mEnabled; - InputEventCircularReader mInputReader; - sensors_event_t mPendingEvent; - bool mHasPendingEvent; - char input_sysfs_path[PATH_MAX]; - int input_sysfs_path_len; - - int setInitialState(); - float indexToValue(size_t index) const; - -public: - ProximitySensor(); - virtual ~ProximitySensor(); - virtual int readEvents(sensors_event_t* data, int count); - virtual bool hasPendingEvents() const; - virtual int enable(int32_t handle, int enabled); - virtual int setDelay(int32_t handle, int64_t ns); -}; - -/*****************************************************************************/ - -#endif // ANDROID_PROXIMITY_SENSOR_H diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp deleted file mode 100644 index 5742ed2..0000000 --- a/libsensors/SensorBase.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include - -#include - -#include "SensorBase.h" - -/*****************************************************************************/ - -static pthread_mutex_t sspEnableLock = PTHREAD_MUTEX_INITIALIZER; - -SensorBase::SensorBase( - const char* dev_name, - const char* data_name) - : dev_name(dev_name), data_name(data_name), - dev_fd(-1), data_fd(-1) -{ - if (data_name) { - data_fd = openInput(data_name); - } -} - -SensorBase::~SensorBase() { - if (data_fd >= 0) { - close(data_fd); - } - if (dev_fd >= 0) { - close(dev_fd); - } -} - -int SensorBase::open_device() { - if (dev_fd<0 && dev_name) { - dev_fd = open(dev_name, O_RDONLY); - ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno)); - } - return 0; -} - -int SensorBase::close_device() { - if (dev_fd >= 0) { - close(dev_fd); - dev_fd = -1; - } - return 0; -} - -int SensorBase::getFd() const { - if (!data_name) { - return dev_fd; - } - return data_fd; -} - -int SensorBase::setDelay(int32_t handle, int64_t ns) { - return 0; -} - -bool SensorBase::hasPendingEvents() const { - return false; -} - -int64_t SensorBase::getTimestamp() { - struct timespec t; - t.tv_sec = t.tv_nsec = 0; - clock_gettime(CLOCK_BOOTTIME, &t); - return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; -} - -int SensorBase::openInput(const char* inputName) { - int fd = -1; - const char *dirname = "/dev/input"; - char devname[PATH_MAX]; - char *filename; - DIR *dir; - struct dirent *de; - dir = opendir(dirname); - if(dir == NULL) - return -1; - strcpy(devname, dirname); - filename = devname + strlen(devname); - *filename++ = '/'; - while((de = readdir(dir))) { - if(de->d_name[0] == '.' && - (de->d_name[1] == '\0' || - (de->d_name[1] == '.' && de->d_name[2] == '\0'))) - continue; - strcpy(filename, de->d_name); - fd = open(devname, O_RDONLY); - if (fd>=0) { - char name[80]; - if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { - name[0] = '\0'; - } - if (!strcmp(name, inputName)) { - strcpy(input_name, filename); - break; - } else { - close(fd); - fd = -1; - } - } - } - closedir(dir); - ALOGE_IF(fd<0, "couldn't find '%s' input device", inputName); - - return fd; -} - -int SensorBase::batch(int handle, int flags, int64_t period_ns, int64_t timeout) -{ - return 0; -} - -int SensorBase::flush(int handle) -{ - return 0; -} - -int SensorBase::sspEnable(const char* sensorname, int sensorvalue, int en) -{ - FILE* sspfile; - int sspValue = 0; - - pthread_mutex_lock(&sspEnableLock); - - sspfile = fopen(SSP_DEVICE_ENABLE, "r+"); - fscanf(sspfile, "%d", &sspValue); - fclose(sspfile); - - if (en) - sspValue |= sensorvalue; - else - sspValue &= ~sensorvalue; - - sspWrite(sspValue); - - pthread_mutex_unlock(&sspEnableLock); - - return 0; -} - -int SensorBase::sspWrite(int sensorvalue) -{ - char buf[12]; - int fd, ret, err; - - sprintf(buf, "%d", sensorvalue); - fd = open(SSP_DEVICE_ENABLE, O_RDWR); - if (fd >= 0) { - err = write(fd, buf, sizeof(buf)); - ret = 0; - } else { - ALOGI("%s: error writing to file", __func__); - ret = -1; - } - - close(fd); - return ret; -} diff --git a/libsensors/SensorBase.h b/libsensors/SensorBase.h deleted file mode 100644 index aeac510..0000000 --- a/libsensors/SensorBase.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_SENSOR_BASE_H -#define ANDROID_SENSOR_BASE_H - -#include -#include -#include -#include - -#include "sensors.h" - - -/*****************************************************************************/ - -struct sensors_event_t; - -class SensorBase { -protected: - const char* dev_name; - const char* data_name; - char input_name[PATH_MAX]; - int dev_fd; - int data_fd; - - int openInput(const char* inputName); - static int64_t getTimestamp(); - - - static int64_t timevalToNano(timeval const& t) { - return t.tv_sec*1000000000LL + t.tv_usec*1000; - } - - int open_device(); - int close_device(); - -public: - SensorBase( - const char* dev_name, - const char* data_name); - - virtual ~SensorBase(); - - virtual int readEvents(sensors_event_t* data, int count) = 0; - virtual bool hasPendingEvents() const; - virtual int getFd() const; - virtual int setDelay(int32_t handle, int64_t ns); - virtual int enable(int32_t handle, int enabled) = 0; - int sspEnable(const char* sensorname, int sensorvalue, int en); - int sspWrite(int sensorvalue); - virtual int batch(int handle, int flags, int64_t period_ns, int64_t timeout); - virtual int flush(int handle); - -}; - -/*****************************************************************************/ - -#endif // ANDROID_SENSOR_BASE_H diff --git a/libsensors/ak8973b.h b/libsensors/ak8973b.h deleted file mode 100644 index 9b7ab60..0000000 --- a/libsensors/ak8973b.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Definitions for akm8973 compass chip. - */ -#ifndef AKM8973_H -#define AKM8973_H - -#include - -#define AKM8973_I2C_NAME "ak8973b" - -#define AKMIO 0xA1 - -/* IOCTLs for AKM library */ -#define ECS_IOCTL_WRITE _IOW(AKMIO, 0x01, char*) -#define ECS_IOCTL_READ _IOWR(AKMIO, 0x02, char*) -#define ECS_IOCTL_RESET _IO(AKMIO, 0x03) -#define ECS_IOCTL_SET_MODE _IOW(AKMIO, 0x04, short) -#define ECS_IOCTL_GETDATA _IOR(AKMIO, 0x05, char[SENSOR_DATA_SIZE]) -#define ECS_IOCTL_SET_YPR _IOW(AKMIO, 0x06, short[12]) -#define ECS_IOCTL_GET_OPEN_STATUS _IOR(AKMIO, 0x07, int) -#define ECS_IOCTL_GET_CLOSE_STATUS _IOR(AKMIO, 0x08, int) -#define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, int64_t) -#define ECS_IOCTL_GET_PROJECT_NAME _IOR(AKMIO, 0x0D, char[64]) -#define ECS_IOCTL_GET_MATRIX _IOR(AKMIO, 0x0E, short [4][3][3]) - -/* IOCTLs for APPs */ -#define ECS_IOCTL_APP_SET_MODE _IOW(AKMIO, 0x10, short) -#define ECS_IOCTL_APP_SET_MFLAG _IOW(AKMIO, 0x11, short) -#define ECS_IOCTL_APP_GET_MFLAG _IOW(AKMIO, 0x12, short) -#define ECS_IOCTL_APP_SET_AFLAG _IOW(AKMIO, 0x13, short) -#define ECS_IOCTL_APP_GET_AFLAG _IOR(AKMIO, 0x14, short) -#define ECS_IOCTL_APP_SET_TFLAG _IOR(AKMIO, 0x15, short) -#define ECS_IOCTL_APP_GET_TFLAG _IOR(AKMIO, 0x16, short) -#define ECS_IOCTL_APP_RESET_PEDOMETER _IO(AKMIO, 0x17) -#define ECS_IOCTL_APP_SET_DELAY _IOW(AKMIO, 0x18, int64_t) -#define ECS_IOCTL_APP_GET_DELAY ECS_IOCTL_GET_DELAY - -/* Set raw magnetic vector flag */ -#define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short) - -/* Get raw magnetic vector flag */ -#define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short) - -struct akm8973_platform_data { - short layouts[4][3][3]; - char project_name[64]; - int gpio_RST; - int gpio_INT; -}; - -#endif diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp deleted file mode 100644 index e7e48ec..0000000 --- a/libsensors/sensors.cpp +++ /dev/null @@ -1,400 +0,0 @@ -/* - * 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. - */ - -#define ALOG_TAG "Sensors" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "sensors.h" - -#include "LightSensor.h" -#include "ProximitySensor.h" -#include "AkmSensor.h" -#include "GyroSensor.h" -#include "AccelSensor.h" -#include "PressureSensor.h" - -/*****************************************************************************/ - -#define DELAY_OUT_TIME 0x7FFFFFFF - -#define LIGHT_SENSOR_POLLTIME 2000000000 - - -#define SENSORS_ACCELERATION (1<getFd(); - mPollFds[light].events = POLLIN; - mPollFds[light].revents = 0; - - mSensors[proximity] = new ProximitySensor(); - mPollFds[proximity].fd = mSensors[proximity]->getFd(); - mPollFds[proximity].events = POLLIN; - mPollFds[proximity].revents = 0; - - mSensors[akm] = new AkmSensor(); - mPollFds[akm].fd = mSensors[akm]->getFd(); - mPollFds[akm].events = POLLIN; - mPollFds[akm].revents = 0; - - mSensors[gyro] = new GyroSensor(); - mPollFds[gyro].fd = mSensors[gyro]->getFd(); - mPollFds[gyro].events = POLLIN; - mPollFds[gyro].revents = 0; - - mSensors[accel] = new AccelSensor(); - mPollFds[accel].fd = mSensors[accel]->getFd(); - mPollFds[accel].events = POLLIN; - mPollFds[accel].revents = 0; - - mSensors[pressure] = new PressureSensor(); - mPollFds[pressure].fd = mSensors[pressure]->getFd(); - mPollFds[pressure].events = POLLIN; - mPollFds[pressure].revents = 0; - - int wakeFds[2]; - int result = pipe(wakeFds); - ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno)); - fcntl(wakeFds[0], F_SETFL, O_NONBLOCK); - fcntl(wakeFds[1], F_SETFL, O_NONBLOCK); - mWritePipeFd = wakeFds[1]; - - mPollFds[wake].fd = wakeFds[0]; - mPollFds[wake].events = POLLIN; - mPollFds[wake].revents = 0; - mInitialized = true; -} - -sensors_poll_context_t::~sensors_poll_context_t() { - for (int i=0 ; ienable(handle, enabled); - if (enabled && !err) { - const char wakeMessage(WAKE_MESSAGE); - int result = write(mWritePipeFd, &wakeMessage, 1); - ALOGE_IF(result<0, "error sending wake message (%s)", strerror(errno)); - } - return err; -} - -int sensors_poll_context_t::setDelay(int handle, int64_t ns) { - - int index = handleToDriver(handle); - if (index < 0) return index; - return mSensors[index]->setDelay(handle, ns); -} - -int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count) -{ - int nbEvents = 0; - int n = 0; - - do { - // see if we have some leftover from the last poll() - for (int i=0 ; count && ihasPendingEvents())) { - int nb = sensor->readEvents(data, count); - if (nb < count) { - // no more data for this sensor - mPollFds[i].revents = 0; - } - count -= nb; - nbEvents += nb; - data += nb; - } - } - - if (count) { - // we still have some room, so try to see if we can get - // some events immediately or just wait if we don't have - // anything to return - n = poll(mPollFds, numFds, nbEvents ? 0 : -1); - if (n<0) { - ALOGE("poll() failed (%s)", strerror(errno)); - return -errno; - } - if (mPollFds[wake].revents & POLLIN) { - char msg; - int result = read(mPollFds[wake].fd, &msg, 1); - ALOGE_IF(result<0, "error reading from wake pipe (%s)", strerror(errno)); - ALOGE_IF(msg != WAKE_MESSAGE, "unknown message on wake queue (0x%02x)", int(msg)); - mPollFds[wake].revents = 0; - } - } - // if we have events and space, go read them - } while (n && count); - - return nbEvents; -} - -int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns, int64_t timeout) -{ - int index = handleToDriver(handle); - if (index < 0) return index; - return mSensors[index]->batch(handle, flags, period_ns, timeout); -} - -int sensors_poll_context_t::flush(int handle) -{ - int index = handleToDriver(handle); - if (index < 0) return index; - return mSensors[index]->flush(handle); -} - -/*****************************************************************************/ - -static int poll__close(struct hw_device_t *dev) -{ - sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; - if (ctx) { - delete ctx; - } - return 0; -} - -static int poll__activate(struct sensors_poll_device_t *dev, - int handle, int enabled) { - sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; - return ctx->activate(handle, enabled); -} - -static int poll__setDelay(struct sensors_poll_device_t *dev, - int handle, int64_t ns) { - sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; - return ctx->setDelay(handle, ns); -} - -static int poll__poll(struct sensors_poll_device_t *dev, - sensors_event_t* data, int count) { - sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; - return ctx->pollEvents(data, count); -} - -static int poll__batch(struct sensors_poll_device_1 *dev, - int handle, int flags, int64_t period_ns, int64_t timeout) -{ - sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; - return ctx->batch(handle, flags, period_ns, timeout); -} - -static int poll__flush(struct sensors_poll_device_1 *dev, - int handle) -{ - sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; - return ctx->flush(handle); -} - -/*****************************************************************************/ - -/** Open a new instance of a sensor device using name */ -static int open_sensors(const struct hw_module_t* module, const char* id, - struct hw_device_t** device) -{ - int status = -EINVAL; - sensors_poll_context_t *dev = new sensors_poll_context_t(); - - memset(&dev->device, 0, sizeof(sensors_poll_device_1)); - - dev->device.common.tag = HARDWARE_DEVICE_TAG; - dev->device.common.version = SENSORS_DEVICE_API_VERSION_1_0; - dev->device.common.module = const_cast(module); - dev->device.common.close = poll__close; - dev->device.activate = poll__activate; - dev->device.setDelay = poll__setDelay; - dev->device.poll = poll__poll; - - /* Batch processing */ - dev->device.batch = poll__batch; - dev->device.flush = poll__flush; - - *device = &dev->device.common; - status = 0; - - return status; -} - diff --git a/libsensors/sensors.h b/libsensors/sensors.h deleted file mode 100644 index a415253..0000000 --- a/libsensors/sensors.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_SENSORS_H -#define ANDROID_SENSORS_H - -#include -#include -#include -#include - -#include - -#include -#include - -__BEGIN_DECLS - -/*****************************************************************************/ - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -#define ID_A (0) -#define ID_M (1) -#define ID_O (2) -#define ID_L (3) -#define ID_P (4) -#define ID_GY (5) -#define ID_PR (6) - -#define SSP_ACCEL (1) -#define SSP_GYRO (2) -#define SSP_MAG (4) -#define SSP_PRESS (8) -#define SSP_PROX (32) -#define SSP_LIGHT (64) - -#define SSP_DEVICE_ENABLE "/sys/class/sensors/ssp_sensor/enable" - -const int ssp_sensors[] = { - SSP_ACCEL, - SSP_GYRO, - SSP_MAG, - SSP_PRESS, - SSP_PROX, - SSP_LIGHT -}; - - -/*****************************************************************************/ - -/* - * The SENSORS Module - */ - -/* the CM3663 is a binary proximity sensor that triggers around 6 cm on - * this hardware */ -#define PROXIMITY_THRESHOLD_CM 8.0f - -/*****************************************************************************/ - -#define EVENT_TYPE_ACCEL_X REL_X //1 -#define EVENT_TYPE_ACCEL_Y REL_Y //0 -#define EVENT_TYPE_ACCEL_Z REL_Z //2 - -#define EVENT_TYPE_YAW ABS_RX //3 -#define EVENT_TYPE_PITCH ABS_RY //4 -#define EVENT_TYPE_ROLL ABS_RZ //5 -#define EVENT_TYPE_ORIENT_STATUS ABS_WHEEL //8 - -#define EVENT_TYPE_MAGV_X ABS_RX // 3 -#define EVENT_TYPE_MAGV_Y ABS_RY // 4 -#define EVENT_TYPE_MAGV_Z ABS_RZ // 5 -#define EVENT_TYPE_MAGV_ACC ABS_WHEEL // 8 - -#define EVENT_TYPE_TEMPERATURE ABS_THROTTLE -#define EVENT_TYPE_STEP_COUNT ABS_GAS -#define EVENT_TYPE_PROXIMITY ABS_DISTANCE -#define EVENT_TYPE_LIGHT REL_MISC - -#define EVENT_TYPE_GYRO_X REL_RX -#define EVENT_TYPE_GYRO_Y REL_RY -#define EVENT_TYPE_GYRO_Z REL_RZ - -#define EVENT_TYPE_PRESSURE REL_HWHEEL - -#define LSG (1000.0f) - -// conversion of acceleration data to SI units (m/s^2) -#define RANGE_A (2*GRAVITY_EARTH) -#define RESOLUTION_A (GRAVITY_EARTH / LSG) -#define CONVERT_A (GRAVITY_EARTH / LSG) -#define CONVERT_A_X (CONVERT_A) -#define CONVERT_A_Y (CONVERT_A) -#define CONVERT_A_Z (CONVERT_A) - -// conversion of magnetic data to uT units -#define CONVERT_M (1.0f/16.0f) -#define CONVERT_M_X (CONVERT_M) -#define CONVERT_M_Y (CONVERT_M) -#define CONVERT_M_Z (CONVERT_M) - -/* conversion of orientation data to degree units */ -#define CONVERT_O (1.0f/1000.0f) -#define CONVERT_O_A (CONVERT_O) -#define CONVERT_O_P (CONVERT_O) -#define CONVERT_O_R (CONVERT_O) - -// conversion of gyro data to SI units (radian/sec) -#define RANGE_GYRO (2000.0f*(float)M_PI/180.0f) -#define CONVERT_GYRO ((70.0f / 4000.0f) * ((float)M_PI / 180.0f)) -#define CONVERT_GYRO_X (CONVERT_GYRO) -#define CONVERT_GYRO_Y (CONVERT_GYRO) -#define CONVERT_GYRO_Z (CONVERT_GYRO) - -#define SENSOR_STATE_MASK (0x7FFF) - -/*****************************************************************************/ - -__END_DECLS - -#endif // ANDROID_SENSORS_H -- cgit v1.2.3