From 28e3038bf810016925668ff5d8236325d37aaab9 Mon Sep 17 00:00:00 2001 From: sbrissen Date: Wed, 11 Dec 2013 18:23:22 +0530 Subject: N7100: Open source sensors smdk4412: https://gerrit.omnirom.org/#/c/3934/ This reverts commit 1862e93acf995525493f0c47f4ba6fde37611ba2. Change-Id: Ib5c14f7da94ea1696bae36f7d0bf19a0c63e57e9 Conflicts: BoardConfig.mk --- libsensors/ProximitySensor.cpp | 157 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 libsensors/ProximitySensor.cpp (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp new file mode 100644 index 0000000..404bdbc --- /dev/null +++ b/libsensors/ProximitySensor.cpp @@ -0,0 +1,157 @@ +/* + * 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" +#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], "prox_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; + 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; +} -- cgit v1.1 From cd5145640187472147f77a2e9be8e7055097b581 Mon Sep 17 00:00:00 2001 From: sbrissen Date: Tue, 25 Feb 2014 14:34:07 -0500 Subject: n7100: fix up sensors -dibable all sensors when screen is off. port from t0: http://review.cyanogenmod.org/#/c/60292/ Change-Id: I66566f5a17acdc7c6dda84eef81af928567cfa37 Conflicts: libsensors/sensors.h --- libsensors/ProximitySensor.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp index 404bdbc..f9579fa 100644 --- a/libsensors/ProximitySensor.cpp +++ b/libsensors/ProximitySensor.cpp @@ -88,6 +88,7 @@ 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){ -- cgit v1.1 From 25167a3ebc96d346ec41c8361a8396afac77ad5d Mon Sep 17 00:00:00 2001 From: tilaksidduram Date: Tue, 10 Jun 2014 21:22:28 +0530 Subject: Revert "n7100: fix up sensors" This reverts commit cd5145640187472147f77a2e9be8e7055097b581. --- libsensors/ProximitySensor.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp index f9579fa..404bdbc 100644 --- a/libsensors/ProximitySensor.cpp +++ b/libsensors/ProximitySensor.cpp @@ -88,7 +88,6 @@ 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){ -- cgit v1.1 From e4884eadc0332211a061f4643d4a978e2991a636 Mon Sep 17 00:00:00 2001 From: tilaksidduram Date: Tue, 10 Jun 2014 21:22:50 +0530 Subject: Revert "N7100: Open source sensors" This reverts commit 28e3038bf810016925668ff5d8236325d37aaab9. --- libsensors/ProximitySensor.cpp | 157 ----------------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 libsensors/ProximitySensor.cpp (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp deleted file mode 100644 index 404bdbc..0000000 --- a/libsensors/ProximitySensor.cpp +++ /dev/null @@ -1,157 +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 "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], "prox_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; - 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; -} -- cgit v1.1 From 9fec655291ddf36e5e568ce57a8ae10a161e3a5a Mon Sep 17 00:00:00 2001 From: Dheeraj CVR Date: Thu, 1 Jan 2015 21:33:39 +0530 Subject: n7100: Bring back open source sensors This reverts commit 00ac0f43785afd63a16b74034f4701928e941360. Change-Id: I810bad7b533d8c8edf0152b36874789e02994bad n7100: sensors: Fix buffer size Change-Id: I93a999a47ade6982c0b1fec56d611465f8dad830 Conflicts: n7100.mk --- libsensors/ProximitySensor.cpp | 158 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 libsensors/ProximitySensor.cpp (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp new file mode 100644 index 0000000..f9579fa --- /dev/null +++ b/libsensors/ProximitySensor.cpp @@ -0,0 +1,158 @@ +/* + * 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" +#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], "prox_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; +} -- cgit v1.1 From f4e064db516feb2111a94ccf23d763e12aeef527 Mon Sep 17 00:00:00 2001 From: DerTeufel Date: Mon, 29 Dec 2014 18:52:07 +0100 Subject: libsensors: update paths to match new kernel base Change-Id: I89bcc9c86d1974348f67ec4b5974f52c05de711d --- libsensors/ProximitySensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp index f9579fa..53d6381 100644 --- a/libsensors/ProximitySensor.cpp +++ b/libsensors/ProximitySensor.cpp @@ -72,7 +72,7 @@ int ProximitySensor::setDelay(int32_t handle, int64_t ns) { int fd; - strcpy(&input_sysfs_path[input_sysfs_path_len], "prox_poll_delay"); + strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); fd = open(input_sysfs_path, O_RDWR); if (fd >= 0) { char buf[80]; -- cgit v1.1 From 86a5f7480a7f3b02eda02a08f1309fa28b67b65c Mon Sep 17 00:00:00 2001 From: tilaksidduram Date: Tue, 17 Nov 2015 11:07:53 +0530 Subject: n7100: Fix sensors build --- libsensors/ProximitySensor.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'libsensors/ProximitySensor.cpp') diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp index 53d6381..ab7db13 100644 --- a/libsensors/ProximitySensor.cpp +++ b/libsensors/ProximitySensor.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include -- cgit v1.1