From 3ace5d2f1ad5da470d4a42e1d8e51021072bae4a Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Tue, 26 Apr 2011 20:47:13 +0100 Subject: 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:= 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 --- services/sensorservice/Android.mk | 4 ++- services/sensorservice/SensorDevice.cpp | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) 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 +#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 ; iget_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) ); -- cgit v1.1