summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortilaksidduram <tilaksidduram@gmail.com>2016-03-28 13:55:09 +0530
committertilaksidduram <tilaksidduram@gmail.com>2016-04-02 11:18:22 +0530
commit1c76a1b3a2d18c95a441e86f771e27494905dabc (patch)
tree17096da503cea52799bdd4f9f4359174a74c7cf9
parent0a4d368084f62673639d0f53f35b9f8623c53753 (diff)
downloaddevice_samsung_n7100-1c76a1b3a2d18c95a441e86f771e27494905dabc.zip
device_samsung_n7100-1c76a1b3a2d18c95a441e86f771e27494905dabc.tar.gz
device_samsung_n7100-1c76a1b3a2d18c95a441e86f771e27494905dabc.tar.bz2
n7100: update sensors
* trying to fix compass.
-rw-r--r--libsensors/AkmSensor.cpp47
-rw-r--r--libsensors/GyroSensor.cpp21
-rw-r--r--libsensors/ak8973b.h51
-rw-r--r--libsensors/sensors.h1
4 files changed, 111 insertions, 9 deletions
diff --git a/libsensors/AkmSensor.cpp b/libsensors/AkmSensor.cpp
index 9dc98bc..d82e6f8 100644
--- a/libsensors/AkmSensor.cpp
+++ b/libsensors/AkmSensor.cpp
@@ -24,6 +24,8 @@
#include <dlfcn.h>
#include <cstring>
+#include "ak8973b.h"
+
#include <cutils/log.h>
#include "AkmSensor.h"
@@ -79,6 +81,11 @@ AkmSensor::AkmSensor()
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_UNRELIABLE;
+
mPendingEvents[MagneticField].version = sizeof(sensors_event_t);
mPendingEvents[MagneticField].sensor = ID_M;
mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD;
@@ -87,6 +94,19 @@ AkmSensor::AkmSensor()
// read the actual value of all sensors if they're enabled already
struct input_absinfo absinfo;
short flags = 0;
+
+ if (akm_is_sensor_enabled(SENSOR_TYPE_ACCELEROMETER)) {
+ mEnabled |= 1<<Accelerometer;
+ if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_ACCEL_X), &absinfo)) {
+ mPendingEvents[Accelerometer].acceleration.x = absinfo.value * CONVERT_A_X;
+ }
+ if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_ACCEL_Y), &absinfo)) {
+ mPendingEvents[Accelerometer].acceleration.y = absinfo.value * CONVERT_A_Y;
+ }
+ if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_ACCEL_Z), &absinfo)) {
+ mPendingEvents[Accelerometer].acceleration.z = absinfo.value * CONVERT_A_Z;
+ }
+ }
if (akm_is_sensor_enabled(SENSOR_TYPE_MAGNETIC_FIELD)) {
mEnabled |= 1<<MagneticField;
if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_MAGV_X), &absinfo)) {
@@ -118,6 +138,7 @@ int AkmSensor::enable(int32_t handle, int en)
int what = -1;
switch (handle) {
+ case ID_A: what = Accelerometer; break;
case ID_M: what = MagneticField; break;
case ID_O: what = Orientation; break;
}
@@ -164,6 +185,7 @@ int AkmSensor::setDelay(int32_t handle, int64_t ns)
return -EINVAL;
switch (handle) {
+ case ID_A: sensor_type = SENSOR_TYPE_ACCELEROMETER; break;
case ID_M: sensor_type = SENSOR_TYPE_MAGNETIC_FIELD; break;
}
@@ -187,6 +209,24 @@ int AkmSensor::setDelay(int32_t handle, int64_t ns)
}
mDelays[what] = ns;
+ return update_delay();
+}
+
+int AkmSensor::update_delay()
+{
+ if (mEnabled) {
+ uint64_t wanted = -1LLU;
+ for (int i=0 ; i<numSensors ; i++) {
+ if (mEnabled & (1<<i)) {
+ uint64_t ns = mDelays[i];
+ wanted = wanted < ns ? wanted : ns;
+ }
+ }
+ short delay = int64_t(wanted) / 1000000;
+ if (ioctl(dev_fd, ECS_IOCTL_APP_SET_DELAY, &delay)) {
+ return -errno;
+ }
+ }
return 0;
}
@@ -271,5 +311,12 @@ void AkmSensor::processEvent(int code, int value)
mPendingMask |= 1<<MagneticField;
mPendingEvents[MagneticField].magnetic.z = value * CONVERT_M_Z;
break;
+ case EVENT_TYPE_MAGV_ACC:
+ ALOGV("AkmSensor: MAGV_ACC=>%d", value);
+ mPendingMask |= 1<<MagneticField;
+ mPendingEvents[MagneticField].magnetic.status = value;
+ default:
+ ALOGV("AkmSensor: unkown REL event code=%d, value=%d", code, value);
+ break;
}
}
diff --git a/libsensors/GyroSensor.cpp b/libsensors/GyroSensor.cpp
index 7d3a2d9..770afbd 100644
--- a/libsensors/GyroSensor.cpp
+++ b/libsensors/GyroSensor.cpp
@@ -80,16 +80,19 @@ int GyroSensor::setInitialState() {
int GyroSensor::enable(int32_t handle, int en) {
int flags = en ? 1 : 0;
- int err;
+ int fd;
if (flags != mEnabled) {
- if(err >= 0){
- mEnabled = flags;
- err = sspEnable(LOGTAG, SSP_GYRO, en);
- setInitialState();
-
- return 0;
- }
- return -1;
+ strcpy(&input_sysfs_path[input_sysfs_path_len], "enable");
+ fd = open(input_sysfs_path, O_RDWR);
+ if (fd >= 0){
+ write(fd, en == 1 ? "1" : "0", 2);
+ close(fd);
+ mEnabled = flags;
+ setInitialState();
+
+ return 0;
+ }
+ return -1;
}
return 0;
}
diff --git a/libsensors/ak8973b.h b/libsensors/ak8973b.h
new file mode 100644
index 0000000..9b7ab60
--- /dev/null
+++ b/libsensors/ak8973b.h
@@ -0,0 +1,51 @@
+/*
+ * Definitions for akm8973 compass chip.
+ */
+#ifndef AKM8973_H
+#define AKM8973_H
+
+#include <linux/ioctl.h>
+
+#define AKM8973_I2C_NAME "ak8973b"
+
+#define AKMIO 0xA1
+
+/* IOCTLs for AKM library */
+#define ECS_IOCTL_WRITE _IOW(AKMIO, 0x01, char*)
+#define ECS_IOCTL_READ _IOWR(AKMIO, 0x02, char*)
+#define ECS_IOCTL_RESET _IO(AKMIO, 0x03)
+#define ECS_IOCTL_SET_MODE _IOW(AKMIO, 0x04, short)
+#define ECS_IOCTL_GETDATA _IOR(AKMIO, 0x05, char[SENSOR_DATA_SIZE])
+#define ECS_IOCTL_SET_YPR _IOW(AKMIO, 0x06, short[12])
+#define ECS_IOCTL_GET_OPEN_STATUS _IOR(AKMIO, 0x07, int)
+#define ECS_IOCTL_GET_CLOSE_STATUS _IOR(AKMIO, 0x08, int)
+#define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, int64_t)
+#define ECS_IOCTL_GET_PROJECT_NAME _IOR(AKMIO, 0x0D, char[64])
+#define ECS_IOCTL_GET_MATRIX _IOR(AKMIO, 0x0E, short [4][3][3])
+
+/* IOCTLs for APPs */
+#define ECS_IOCTL_APP_SET_MODE _IOW(AKMIO, 0x10, short)
+#define ECS_IOCTL_APP_SET_MFLAG _IOW(AKMIO, 0x11, short)
+#define ECS_IOCTL_APP_GET_MFLAG _IOW(AKMIO, 0x12, short)
+#define ECS_IOCTL_APP_SET_AFLAG _IOW(AKMIO, 0x13, short)
+#define ECS_IOCTL_APP_GET_AFLAG _IOR(AKMIO, 0x14, short)
+#define ECS_IOCTL_APP_SET_TFLAG _IOR(AKMIO, 0x15, short)
+#define ECS_IOCTL_APP_GET_TFLAG _IOR(AKMIO, 0x16, short)
+#define ECS_IOCTL_APP_RESET_PEDOMETER _IO(AKMIO, 0x17)
+#define ECS_IOCTL_APP_SET_DELAY _IOW(AKMIO, 0x18, int64_t)
+#define ECS_IOCTL_APP_GET_DELAY ECS_IOCTL_GET_DELAY
+
+/* Set raw magnetic vector flag */
+#define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short)
+
+/* Get raw magnetic vector flag */
+#define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short)
+
+struct akm8973_platform_data {
+ short layouts[4][3][3];
+ char project_name[64];
+ int gpio_RST;
+ int gpio_INT;
+};
+
+#endif
diff --git a/libsensors/sensors.h b/libsensors/sensors.h
index 5ad1b80..a415253 100644
--- a/libsensors/sensors.h
+++ b/libsensors/sensors.h
@@ -84,6 +84,7 @@ const int ssp_sensors[] = {
#define EVENT_TYPE_MAGV_X ABS_RX // 3
#define EVENT_TYPE_MAGV_Y ABS_RY // 4
#define EVENT_TYPE_MAGV_Z ABS_RZ // 5
+#define EVENT_TYPE_MAGV_ACC ABS_WHEEL // 8
#define EVENT_TYPE_TEMPERATURE ABS_THROTTLE
#define EVENT_TYPE_STEP_COUNT ABS_GAS