diff --git a/Android.mk b/Android.mk new file mode 100755 index 0000000..2b6ae7d --- /dev/null +++ b/Android.mk @@ -0,0 +1,22 @@ +# Copyright (C) 2009 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 := $(my-dir) +subdir_makefiles := \ + $(LOCAL_PATH)/libreference-ril/Android.mk \ + $(LOCAL_PATH)/libgps/Android.mk \ + $(LOCAL_PATH)/libsensors/Android.mk \ + $(LOCAL_PATH)/liblights/Android.mk + +include $(subdir_makefiles) diff --git a/apns-conf.xml b/apns-conf.xml deleted file mode 100644 index e12f7da..0000000 --- a/apns-conf.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - diff --git a/leo.mk b/leo.mk index 822ce19..c1f56db 100755 --- a/leo.mk +++ b/leo.mk @@ -28,15 +28,22 @@ PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \ device/htc/leo/init.leo.rc:root/init.leo.rc \ -PRODUCT_PROPERTY_OVERRIDES := \ +PRODUCT_PROPERTY_OVERRIDES += \ ro.sf.lcd_density=240 \ rild.libpath=/system/lib/libhtc_ril.so \ - wifi.interface=eth0 \ - wifi.supplicant_scan_interval=15 \ + ro.ril.ecc.HTC-ELL=92,93,94 \ + ro.ril.ecc.HTC-WWE=999 \ + ro.ril.enable.a52.HTC-ITA=1 \ + ro.ril.enable.a53.HTC-ITA=1 \ + ro.ril.enable.a52=0 \ + ro.ril.enable.a53=1 \ + ro.ril.enable.dtm = 1 \ + ro.ril.gprsclass = 12 \ + ro.ril.hsdpa.category=8 \ + ro.ril.hsupa.category=5 \ ro.ril.hsxpa=2 \ - ro.ril.gprsclass=10 - - + wifi.interface=eth0 \ + wifi.supplicant_scan_interval=15 # Default network type. # 0 => WCDMA preferred. @@ -47,6 +54,10 @@ PRODUCT_PROPERTY_OVERRIDES += \ PRODUCT_PROPERTY_OVERRIDES += \ ro.ril.disable.power.collapse = 1 +# AGPS otpions +PRODUCT_PROPERTY_OVERRIDES += \ + ro.ril.def.agps.mode=2 + # The OpenGL ES API level that is natively supported by this device. # This is a 16.16 fixed point number PRODUCT_PROPERTY_OVERRIDES += \ diff --git a/libsensors/AkmSensor.cpp b/libsensors/AkmSensor.cpp new file mode 100644 index 0000000..6abfca2 --- /dev/null +++ b/libsensors/AkmSensor.cpp @@ -0,0 +1,295 @@ +/* + * 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 "AkmSensor.h" + +/*****************************************************************************/ + +AkmSensor::AkmSensor() +: SensorBase(AKM_DEVICE_NAME, "compass"), + mEnabled(0), + mPendingMask(0), + mInputReader(32) +{ + 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_ACCURACY_HIGH; + + 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; + + mPendingEvents[Orientation ].version = sizeof(sensors_event_t); + mPendingEvents[Orientation ].sensor = ID_O; + mPendingEvents[Orientation ].type = SENSOR_TYPE_ORIENTATION; + mPendingEvents[Orientation ].orientation.status = SENSOR_STATUS_ACCURACY_HIGH; + + for (int i=0 ; i= numSensors) + return -EINVAL; + + int newState = en ? 1 : 0; + int err = 0; + + if ((uint32_t(newState)<= numSensors) + return -EINVAL; + + if (ns < 0) + return -EINVAL; + + mDelays[what] = ns; + return update_delay(); +#else + return -1; +#endif +} + +int AkmSensor::update_delay() +{ + if (mEnabled) { + uint64_t wanted = -1LLU; + for (int i=0 ; itype; + 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_ACCEL_X: + mPendingMask |= 1< +#include +#include +#include + + +#include "nusensors.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); + +private: + int update_delay(); + 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 index cc62133..164bef2 100644 --- a/libsensors/Android.mk +++ b/libsensors/Android.mk @@ -27,7 +27,16 @@ LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw LOCAL_MODULE_TAGS := optional -LOCAL_SRC_FILES := leosensors.c +LOCAL_CFLAGS := -DLOG_TAG=\"Sensors\" +LOCAL_SRC_FILES := \ + sensors.c \ + nusensors.cpp \ + InputEventReader.cpp \ + SensorBase.cpp \ + LightSensor.cpp \ + ProximitySensor.cpp \ + AkmSensor.cpp + LOCAL_SHARED_LIBRARIES := liblog libcutils LOCAL_PRELINK_MODULE := false diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp new file mode 100644 index 0000000..1014f29 --- /dev/null +++ b/libsensors/InputEventReader.cpp @@ -0,0 +1,88 @@ +/* + * 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 "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 new file mode 100644 index 0000000..180aade --- /dev/null +++ b/libsensors/InputEventReader.h @@ -0,0 +1,47 @@ +/* + * 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 new file mode 100644 index 0000000..2c660ec --- /dev/null +++ b/libsensors/LightSensor.cpp @@ -0,0 +1,154 @@ +/* + * 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" + +/*****************************************************************************/ + +LightSensor::LightSensor() + : SensorBase(LS_DEVICE_NAME, "lightsensor-level"), + 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)); + + open_device(); + + int flags = 0; + if (!ioctl(dev_fd, LIGHTSENSOR_IOCTL_GET_ENABLED, &flags)) { + if (flags) { + mEnabled = 1; + setInitialState(); + } + } + + if (!mEnabled) { + close_device(); + } +} + +LightSensor::~LightSensor() { +} + +int LightSensor::setInitialState() { + struct input_absinfo absinfo; + if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_LIGHT), &absinfo)) { + mPendingEvent.light = indexToValue(absinfo.value); + mHasPendingEvent = true; + } + return 0; +} + +int LightSensor::enable(int32_t, int en) { + int flags = en ? 1 : 0; + int err = 0; + if (flags != mEnabled) { + if (!mEnabled) { + open_device(); + } + err = ioctl(dev_fd, LIGHTSENSOR_IOCTL_ENABLE, &flags); + err = err<0 ? -errno : 0; + LOGE_IF(err, "LIGHTSENSOR_IOCTL_ENABLE failed (%s)", strerror(-err)); + if (!err) { + mEnabled = en ? 1 : 0; + if (en) { + setInitialState(); + } + } + if (!mEnabled) { + close_device(); + } + } + return err; +} + +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_ABS) { + if (event->code == EVENT_TYPE_LIGHT) { + if (event->value != -1) { + // FIXME: not sure why we're getting -1 sometimes + mPendingEvent.light = indexToValue(event->value); + } + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + *data++ = mPendingEvent; + count--; + numEventReceived++; + } + } else { + LOGE("LightSensor: unknown event (type=%d, code=%d)", + type, event->code); + } + mInputReader.next(); + } + + return numEventReceived; +} + +float LightSensor::indexToValue(size_t index) const +{ + static const float luxValues[10] = { + 10.0, 160.0, 225.0, 320.0, 640.0, + 1280.0, 2600.0, 5800.0, 8000.0, 10240.0 + }; + + const size_t maxIndex = sizeof(luxValues)/sizeof(*luxValues) - 1; + if (index > maxIndex) + index = maxIndex; + return luxValues[index]; +} diff --git a/libsensors/LightSensor.h b/libsensors/LightSensor.h new file mode 100644 index 0000000..13591a3 --- /dev/null +++ b/libsensors/LightSensor.h @@ -0,0 +1,52 @@ +/* + * 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 "nusensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class LightSensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + + 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 enable(int32_t handle, int enabled); +}; + +/*****************************************************************************/ + +#endif // ANDROID_LIGHT_SENSOR_H diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp new file mode 100644 index 0000000..abd8e6b --- /dev/null +++ b/libsensors/ProximitySensor.cpp @@ -0,0 +1,144 @@ +/* + * 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 "ProximitySensor.h" + +/*****************************************************************************/ + +ProximitySensor::ProximitySensor() + : SensorBase(CM_DEVICE_NAME, "proximity"), + 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)); + + open_device(); + + int flags = 0; + if (!ioctl(dev_fd, CAPELLA_CM3602_IOCTL_GET_ENABLED, &flags)) { + mEnabled = 1; + if (flags) { + setInitialState(); + } + } + if (!mEnabled) { + close_device(); + } +} + +ProximitySensor::~ProximitySensor() { +} + +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::enable(int32_t, int en) { + int newState = en ? 1 : 0; + int err = 0; + if (newState != mEnabled) { + if (!mEnabled) { + open_device(); + } + int flags = newState; + err = ioctl(dev_fd, CAPELLA_CM3602_IOCTL_ENABLE, &flags); + err = err<0 ? -errno : 0; + LOGE_IF(err, "CAPELLA_CM3602_IOCTL_ENABLE failed (%s)", strerror(-err)); + if (!err) { + mEnabled = newState; + if (en) { + setInitialState(); + } + } + if (!mEnabled) { + close_device(); + } + } + return err; +} + +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) { + mPendingEvent.distance = indexToValue(event->value); + } + } else if (type == EV_SYN) { + mPendingEvent.timestamp = timevalToNano(event->time); + if (mEnabled) { + *data++ = mPendingEvent; + count--; + numEventReceived++; + } + } else { + LOGE("ProximitySensor: unknown event (type=%d, code=%d)", + type, event->code); + } + mInputReader.next(); + } + + return numEventReceived; +} + +float ProximitySensor::indexToValue(size_t index) const +{ + return index * PROXIMITY_THRESHOLD_CM; +} diff --git a/libsensors/ProximitySensor.h b/libsensors/ProximitySensor.h new file mode 100644 index 0000000..650035a --- /dev/null +++ b/libsensors/ProximitySensor.h @@ -0,0 +1,52 @@ +/* + * 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 "nusensors.h" +#include "SensorBase.h" +#include "InputEventReader.h" + +/*****************************************************************************/ + +struct input_event; + +class ProximitySensor : public SensorBase { + int mEnabled; + InputEventCircularReader mInputReader; + sensors_event_t mPendingEvent; + bool mHasPendingEvent; + + 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); +}; + +/*****************************************************************************/ + +#endif // ANDROID_PROXIMITY_SENSOR_H diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp new file mode 100644 index 0000000..e0554e4 --- /dev/null +++ b/libsensors/SensorBase.cpp @@ -0,0 +1,122 @@ +/* + * 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 "SensorBase.h" + +/*****************************************************************************/ + +SensorBase::SensorBase( + const char* dev_name, + const char* data_name) + : dev_name(dev_name), data_name(data_name), + dev_fd(-1), data_fd(-1) +{ + 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); + LOGE_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 { + 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_MONOTONIC, &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)) { + break; + } else { + close(fd); + fd = -1; + } + } + } + closedir(dir); + LOGE_IF(fd<0, "couldn't find '%s' input device", inputName); + return fd; +} diff --git a/libsensors/SensorBase.h b/libsensors/SensorBase.h new file mode 100644 index 0000000..c8cc276 --- /dev/null +++ b/libsensors/SensorBase.h @@ -0,0 +1,64 @@ +/* + * 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 + + +/*****************************************************************************/ + +struct sensors_event_t; + +class SensorBase { +protected: + const char* dev_name; + const char* data_name; + int dev_fd; + int data_fd; + + static 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; +}; + +/*****************************************************************************/ + +#endif // ANDROID_SENSOR_BASE_H diff --git a/libsensors/nusensors.cpp b/libsensors/nusensors.cpp new file mode 100644 index 0000000..248acc5 --- /dev/null +++ b/libsensors/nusensors.cpp @@ -0,0 +1,228 @@ +/* + * 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 "nusensors.h" +#include "LightSensor.h" +#include "ProximitySensor.h" +#include "AkmSensor.h" + +/*****************************************************************************/ + +struct sensors_poll_context_t { + struct sensors_poll_device_t device; // must be first + + sensors_poll_context_t(); + ~sensors_poll_context_t(); + int activate(int handle, int enabled); + int setDelay(int handle, int64_t ns); + int pollEvents(sensors_event_t* data, int count); + +private: + enum { + light = 0, + proximity = 1, + akm = 2, + numSensorDrivers, + numFds, + }; + + static const size_t wake = numFds - 1; + static const char WAKE_MESSAGE = 'W'; + struct pollfd mPollFds[numFds]; + int mWritePipeFd; + SensorBase* mSensors[numSensorDrivers]; + + int handleToDriver(int handle) const { + switch (handle) { + case ID_A: + case ID_M: + case ID_O: + return akm; + case ID_P: + return proximity; + case ID_L: + return light; + } + return -EINVAL; + } +}; + +/*****************************************************************************/ + +sensors_poll_context_t::sensors_poll_context_t() +{ + mSensors[light] = new LightSensor(); + mPollFds[light].fd = mSensors[light]->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; + + int wakeFds[2]; + int result = pipe(wakeFds); + LOGE_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; +} + +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); + LOGE_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) { + LOGE("poll() failed (%s)", strerror(errno)); + return -errno; + } + if (mPollFds[wake].revents & POLLIN) { + char msg; + int result = read(mPollFds[wake].fd, &msg, 1); + LOGE_IF(result<0, "error reading from wake pipe (%s)", strerror(errno)); + LOGE_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; +} + +/*****************************************************************************/ + +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); +} + +/*****************************************************************************/ + +int init_nusensors(hw_module_t const* module, 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_t)); + + dev->device.common.tag = HARDWARE_DEVICE_TAG; + dev->device.common.version = 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; + + *device = &dev->device.common; + status = 0; + return status; +} diff --git a/libsensors/nusensors.h b/libsensors/nusensors.h new file mode 100644 index 0000000..f1de58d --- /dev/null +++ b/libsensors/nusensors.h @@ -0,0 +1,108 @@ +/* + * 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 + +/*****************************************************************************/ + +int init_nusensors(hw_module_t const* module, hw_device_t** device); + +/*****************************************************************************/ + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +#define ID_A (0) +#define ID_M (1) +#define ID_O (2) +#define ID_P (3) +#define ID_L (4) + +/*****************************************************************************/ + +/* + * The SENSORS Module + */ + +/* the CM3602 is a binary proximity sensor that triggers around 9 cm on + * this hardware */ +#define PROXIMITY_THRESHOLD_CM 9.0f + +/*****************************************************************************/ + +#define AKM_DEVICE_NAME "/dev/akm8973_aot" +#define CM_DEVICE_NAME "/dev/cm3602" +#define LS_DEVICE_NAME "/dev/lightsensor" + +#define EVENT_TYPE_ACCEL_X ABS_X +#define EVENT_TYPE_ACCEL_Y ABS_Z +#define EVENT_TYPE_ACCEL_Z ABS_Y +#define EVENT_TYPE_ACCEL_STATUS ABS_WHEEL + +#define EVENT_TYPE_YAW ABS_RX +#define EVENT_TYPE_PITCH ABS_RY +#define EVENT_TYPE_ROLL ABS_RZ +#define EVENT_TYPE_ORIENT_STATUS ABS_RUDDER + +#define EVENT_TYPE_MAGV_X ABS_HAT0X +#define EVENT_TYPE_MAGV_Y ABS_HAT0Y +#define EVENT_TYPE_MAGV_Z ABS_BRAKE + +#define EVENT_TYPE_TEMPERATURE ABS_THROTTLE +#define EVENT_TYPE_STEP_COUNT ABS_GAS +#define EVENT_TYPE_PROXIMITY ABS_DISTANCE +#define EVENT_TYPE_LIGHT ABS_MISC + +// 720 LSG = 1G +#define LSG (720.0f) + + +// conversion of acceleration data to SI units (m/s^2) +#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) + +#define CONVERT_O (1.0f) +#define CONVERT_O_Y (CONVERT_O) +#define CONVERT_O_P (CONVERT_O) +#define CONVERT_O_R (-CONVERT_O) + +#define SENSOR_STATE_MASK (0x7FFF) + +/*****************************************************************************/ + +__END_DECLS + +#endif // ANDROID_SENSORS_H diff --git a/libsensors/sensors.c b/libsensors/sensors.c new file mode 100644 index 0000000..12a9368 --- /dev/null +++ b/libsensors/sensors.c @@ -0,0 +1,91 @@ +/* + * 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 "nusensors.h" + +/*****************************************************************************/ + +/* + * The SENSORS Module + */ + +/* + * the AK8973 has a 8-bit ADC but the firmware seems to average 16 samples, + * or at least makes its calibration on 12-bits values. This increases the + * resolution by 4 bits. + */ + +static const struct sensor_t sSensorList[] = { + { "BMA150 3-axis Accelerometer", + "Bosh", + 1, SENSORS_HANDLE_BASE+ID_A, + SENSOR_TYPE_ACCELEROMETER, 4.0f*9.81f, (4.0f*9.81f)/256.0f, 0.2f, 0, { } }, + { "AK8973 3-axis Magnetic field sensor", + "Asahi Kasei", + 1, SENSORS_HANDLE_BASE+ID_M, + SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, 1.0f/16.0f, 6.8f, 0, { } }, + { "AK8973 Orientation sensor", + "Asahi Kasei", + 1, SENSORS_HANDLE_BASE+ID_O, + SENSOR_TYPE_ORIENTATION, 360.0f, 1.0f, 7.0f, 0, { } }, + { "CM3602 Proximity sensor", + "Capella Microsystems", + 1, SENSORS_HANDLE_BASE+ID_P, + SENSOR_TYPE_PROXIMITY, + PROXIMITY_THRESHOLD_CM, PROXIMITY_THRESHOLD_CM, + 0.5f, 0, { } }, + { "CM3602 Light sensor", + "Capella Microsystems", + 1, SENSORS_HANDLE_BASE+ID_L, + SENSOR_TYPE_LIGHT, 10240.0f, 1.0f, 0.5f, 0, { } }, +}; + +static int open_sensors(const struct hw_module_t* module, const char* name, + struct hw_device_t** device); + +static int sensors__get_sensors_list(struct sensors_module_t* module, + struct sensor_t const** list) +{ + *list = sSensorList; + return ARRAY_SIZE(sSensorList); +} + +static struct hw_module_methods_t sensors_module_methods = { + .open = open_sensors +}; + +const struct sensors_module_t HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = SENSORS_HARDWARE_MODULE_ID, + .name = "AK8973A & CM3602 Sensors Module", + .author = "The Android Open Source Project", + .methods = &sensors_module_methods, + }, + .get_sensors_list = sensors__get_sensors_list +}; + +/*****************************************************************************/ + +static int open_sensors(const struct hw_module_t* module, const char* name, + struct hw_device_t** device) +{ + return init_nusensors(module, device); +} diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index f87e31a..a482888 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -20,17 +20,13 @@ - - - true - true + + true + true @@ -45,15 +41,10 @@ Must be overridden in platform specific overlays --> - 11 - 41 - 91 - 161 - 226 - 321 - 641 - 1281 - 2601 + 200 + 400 + 1000 + 3000 - 89 - 89 - 126 - 164 - 164 - 164 - 187 - 210 - 233 - 255 + 35 + 55 + 70 + 70 + 250 "wifi,1,1,1" - "wimax,6,2,0" "mobile,0,0,0" "mobile_mms,2,0,2" "mobile_supl,3,0,2" @@ -146,17 +121,6 @@ "mobile_hipri,5,0,3" - - - - "2,1" - "1,1" - "0,1" - - @@ -187,11 +151,4 @@ 30 - - com.android.wallpaper/.nexus.NexusWallpaper - - - false - diff --git a/overlay/frameworks/base/core/res/res/xml/eri.xml b/overlay/frameworks/base/core/res/res/xml/eri.xml deleted file mode 100644 index 6a116e1..0000000 --- a/overlay/frameworks/base/core/res/res/xml/eri.xml +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/overlay/frameworks/base/core/res/res/xml/power_profile.xml b/overlay/frameworks/base/core/res/res/xml/power_profile.xml new file mode 100644 index 0000000..9be6384 --- /dev/null +++ b/overlay/frameworks/base/core/res/res/xml/power_profile.xml @@ -0,0 +1,72 @@ + + + + + 0 + 100 + 142 + 0.3 + + 35690 + 160 + 4 + 120 + 220 + 88 + 88 + 300 + 170 + 1390 + 70 + + 3 + 3 + + + 245000 + 384000 + 460800 + 499200 + 576000 + 614400 + 652800 + 691200 + 768000 + 806400 + 844800 + 998400 + + + 2.8 + + + 66.6 + 84 + 90.8 + 96 + 105 + 111.5 + 117.3 + 123.6 + 134.5 + 141.8 + 148.5 + 168.4 + + diff --git a/overlay/packages/apps/CMParts/res/values/config.xml b/overlay/packages/apps/CMParts/res/values/config.xml deleted file mode 100644 index 7b5a5e4..0000000 --- a/overlay/packages/apps/CMParts/res/values/config.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - false - diff --git a/overlay/packages/apps/Mms/res/xml/mms_config.xml b/overlay/packages/apps/Mms/res/xml/mms_config.xml index 5ecc2f3..73a57b5 100644 --- a/overlay/packages/apps/Mms/res/xml/mms_config.xml +++ b/overlay/packages/apps/Mms/res/xml/mms_config.xml @@ -22,18 +22,18 @@ - 307200 + 1048576 - 1000 + 1944 - 1296 + 2592 - Sprint APA9292KT + Passion - http://device.sprintpcs.com/HTC/APA9292KT/1326511.rdf + http://www.htcmms.com.tw/Android/Common/nexusone/ua-profile.xml diff --git a/overlay/packages/apps/Settings/res/values/bools.xml b/overlay/packages/apps/Settings/res/values/bools.xml index 06dd83f..9697c07 100644 --- a/overlay/packages/apps/Settings/res/values/bools.xml +++ b/overlay/packages/apps/Settings/res/values/bools.xml @@ -17,7 +17,7 @@ - false + true true diff --git a/system.prop b/system.prop deleted file mode 100644 index 86f9902..0000000 --- a/system.prop +++ /dev/null @@ -1,40 +0,0 @@ -# -# system.prop for device -# - -rild.libpath=/system/lib/libhtc_ril.so -ro.ril.def.preferred.network = 4 -ro.telephony.default_network = 4 -wifi.interface = eth0 -wifi.supplicant_scan_interval=15 -ro.com.google.locationfeatures = 1 -# density in DPI of the LCD of this board. This is used to scale the UI -# appropriately. If this property is not defined, the default value is 160 dpi. -ro.sf.lcd_density = 240 -# ro.sf.lcd_density = 160 - -# For SD storage insert notification sound -persist.service.mount.playsnd = 0 - -# For the agps default value -ro.ril.def.agps.mode = 2 - -# For auto backlight default value -settings.display.autobacklight=1 - -# default value of brightness -settings.display.brightness=143 - -# For emmc phone storage -ro.phone_storage = 1 - -# This is a high density device with more memory, so larger vm heaps for it. -dalvik.vm.heapsize=32m - -gsm.sim.operator.numeric = 0 -gsm.sim.operator.alpha = 0 -gsm.sim.operator.iso-country = 0 - -#Modify MTU from 1500 to 1472 on 3G network -ro.ril.set.mtu1472 = 1 -