diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2011-04-26 20:47:13 +0100 |
---|---|---|
committer | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-01-02 03:05:32 +0000 |
commit | 3ace5d2f1ad5da470d4a42e1d8e51021072bae4a (patch) | |
tree | e5c30452ffe9db288d713dcc17a9f60e97023001 | |
parent | 77ddb6525b8a9323fcfff54fcbcb62820a8d540d (diff) | |
download | frameworks_native-3ace5d2f1ad5da470d4a42e1d8e51021072bae4a.zip frameworks_native-3ace5d2f1ad5da470d4a42e1d8e51021072bae4a.tar.gz frameworks_native-3ace5d2f1ad5da470d4a42e1d8e51021072bae4a.tar.bz2 |
sensors: Add dummy light sensor
Some devices have a sysfs toggle for the lightsensor instead of
passing the LUX values for userspace processing; for those,
use BOARD_SYSFS_LIGHT_SENSOR:=<sysfs path>
This is necessary for the rest of userspace to recognize its existence
and toggle it for auto-brightness. It doesn't generate actual light
values, though; all backlight adjustments are made in-kernel.
Change-Id: I0e546b4740720bd34d1e1d85a96b295fcc697106
sensors: dummy ls: set unique handle
handles and types are usually the same, but it's not mandatory.
Sony DASH use custom handles, and the previous assumption broke
Proximity sensor on Sony devices.
Change-Id: I954e13765f42341e6b5393a12556f6a007c4e494
-rw-r--r-- | services/sensorservice/Android.mk | 4 | ||||
-rw-r--r-- | services/sensorservice/SensorDevice.cpp | 49 |
2 files changed, 52 insertions, 1 deletions
diff --git a/services/sensorservice/Android.mk b/services/sensorservice/Android.mk index 773eca5..40fe6e1 100644 --- a/services/sensorservice/Android.mk +++ b/services/sensorservice/Android.mk @@ -26,7 +26,9 @@ LOCAL_SHARED_LIBRARIES := \ libui \ libgui - +ifneq ($(BOARD_SYSFS_LIGHT_SENSOR),) + LOCAL_CFLAGS += -DSYSFS_LIGHT_SENSOR=\"$(BOARD_SYSFS_LIGHT_SENSOR)\" +endif LOCAL_MODULE:= libsensorservice diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp index a9e3ef4..e115efc 100644 --- a/services/sensorservice/SensorDevice.cpp +++ b/services/sensorservice/SensorDevice.cpp @@ -31,11 +31,37 @@ #include "SensorDevice.h" #include "SensorService.h" +#ifdef SYSFS_LIGHT_SENSOR +#include <fcntl.h> +#endif + namespace android { // --------------------------------------------------------------------------- ANDROID_SINGLETON_STATIC_INSTANCE(SensorDevice) +#ifdef SYSFS_LIGHT_SENSOR +#define DUMMY_ALS_HANDLE 0xdeadbeef +static ssize_t addDummyLightSensor(sensor_t const **list, ssize_t count) { + struct sensor_t dummy_light = { + name : "CyanogenMod dummy light sensor", + vendor : "CyanogenMod", + version : 1, + handle : DUMMY_ALS_HANDLE, + type : SENSOR_TYPE_LIGHT, + maxRange : 20, + resolution : 0.1, + power : 20, + }; + void * new_list = malloc((count+1)*sizeof(sensor_t)); + new_list = memcpy(new_list, *list, count*sizeof(sensor_t)); + ((sensor_t *)new_list)[count] = dummy_light; + *list = (sensor_t const *)new_list; + count++; + return count; +} +#endif + SensorDevice::SensorDevice() : mSensorDevice(0), mSensorModule(0) @@ -55,6 +81,9 @@ SensorDevice::SensorDevice() if (mSensorDevice) { sensor_t const* list; ssize_t count = mSensorModule->get_sensors_list(mSensorModule, &list); +#ifdef SYSFS_LIGHT_SENSOR + count = addDummyLightSensor(&list, count); +#endif mActivationCount.setCapacity(count); Info model; for (size_t i=0 ; i<size_t(count) ; i++) { @@ -95,7 +124,11 @@ void SensorDevice::dump(String8& result, char* buffer, size_t SIZE) ssize_t SensorDevice::getSensorList(sensor_t const** list) { if (!mSensorModule) return NO_INIT; ssize_t count = mSensorModule->get_sensors_list(mSensorModule, list); +#ifdef SYSFS_LIGHT_SENSOR + return addDummyLightSensor(list, count); +#else return count; +#endif } status_t SensorDevice::initCheck() const { @@ -117,6 +150,22 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled) status_t err(NO_ERROR); bool actuateHardware = false; +#ifdef SYSFS_LIGHT_SENSOR + if (handle == DUMMY_ALS_HANDLE) { + int nwr, ret, fd; + char value[2]; + + fd = open(SYSFS_LIGHT_SENSOR, O_RDWR); + if(fd < 0) + return -ENODEV; + + nwr = sprintf(value, "%s\n", enabled ? "1" : "0"); + write(fd, value, nwr); + close(fd); + return 0; + } +#endif + Info& info( mActivationCount.editValueFor(handle) ); |