summaryrefslogtreecommitdiffstats
path: root/libsensors/SensorBase.cpp
diff options
context:
space:
mode:
authorcodeworkx <codeworkx@cyanogenmod.org>2016-04-30 20:56:15 +0200
committercodeworkx <codeworkx@cyanogenmod.org>2016-04-30 20:56:15 +0200
commit732bf7a24e16add354c45704e237cb2357d2683c (patch)
treeb25b62ef6c1715638ab3e0b7b40961d13bf32ad1 /libsensors/SensorBase.cpp
parent3dd3324a32a32cf6295e56b0bf7ef697d7d58bdd (diff)
parentd41c859a0678da88519a27560e75983c750155c0 (diff)
downloaddevice_samsung_n7100-732bf7a24e16add354c45704e237cb2357d2683c.zip
device_samsung_n7100-732bf7a24e16add354c45704e237cb2357d2683c.tar.gz
device_samsung_n7100-732bf7a24e16add354c45704e237cb2357d2683c.tar.bz2
Merge branch 'cm-13.0' of github.com:tilaksidduram/android_device_samsung_n7100 into HEAD
Change-Id: I492f715515d6cf681a5f6d2bc59f6929f92b7b47
Diffstat (limited to 'libsensors/SensorBase.cpp')
-rw-r--r--libsensors/SensorBase.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp
index 5c5b52d..5742ed2 100644
--- a/libsensors/SensorBase.cpp
+++ b/libsensors/SensorBase.cpp
@@ -21,8 +21,10 @@
#include <unistd.h>
#include <dirent.h>
#include <sys/select.h>
+#include <pthread.h>
+#include <cstring>
-#include <utils/Log.h>
+#include <cutils/log.h>
#include <linux/input.h>
@@ -30,6 +32,8 @@
/*****************************************************************************/
+static pthread_mutex_t sspEnableLock = PTHREAD_MUTEX_INITIALIZER;
+
SensorBase::SensorBase(
const char* dev_name,
const char* data_name)
@@ -39,11 +43,6 @@ SensorBase::SensorBase(
if (data_name) {
data_fd = openInput(data_name);
}
-
- if (!data_fd)
- {
- ALOGE("open device %s failed", dev_name);
- }
}
SensorBase::~SensorBase() {
@@ -89,7 +88,7 @@ bool SensorBase::hasPendingEvents() const {
int64_t SensorBase::getTimestamp() {
struct timespec t;
t.tv_sec = t.tv_nsec = 0;
- clock_gettime(CLOCK_MONOTONIC, &t);
+ clock_gettime(CLOCK_BOOTTIME, &t);
return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec;
}
@@ -146,30 +145,29 @@ int SensorBase::flush(int handle)
int SensorBase::sspEnable(const char* sensorname, int sensorvalue, int en)
{
FILE* sspfile;
- int oldvalue = 0;
- int reset = 0;
- int newvalue;
- int fd;
+ int sspValue = 0;
- sspfile = fopen(SSP_DEVICE_ENABLE, "r");
- fscanf(sspfile, "%d", &oldvalue);
+ pthread_mutex_lock(&sspEnableLock);
+
+ sspfile = fopen(SSP_DEVICE_ENABLE, "r+");
+ fscanf(sspfile, "%d", &sspValue);
fclose(sspfile);
- if(en) {
- newvalue = oldvalue | sensorvalue;
- } else {
- newvalue = oldvalue & (~sensorvalue);
- }
- ALOGI("%s: name: %s sensor: %i old value: %x new value: %x ", __func__, sensorname, sensorvalue, oldvalue, newvalue);
- if (sspWrite(newvalue))
- return -1;
+ if (en)
+ sspValue |= sensorvalue;
else
- return 0;
+ sspValue &= ~sensorvalue;
+
+ sspWrite(sspValue);
+
+ pthread_mutex_unlock(&sspEnableLock);
+
+ return 0;
}
int SensorBase::sspWrite(int sensorvalue)
{
- char buf[10];
+ char buf[12];
int fd, ret, err;
sprintf(buf, "%d", sensorvalue);