summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Balster <christian.balster@gmail.com>2015-06-02 14:51:42 +0200
committerforkbomb <keepcalm444@gmail.com>2015-11-25 08:34:30 +1100
commita0449080d1eedfd4980b28bd6e73b177ffd73728 (patch)
tree231faabd069a63df9c15e9cf0ee97e93f57ff1c7
parentd7864758c2c931aa082e0623bb3d9d1912a53abf (diff)
downloaddevice_samsung_i9300-a0449080d1eedfd4980b28bd6e73b177ffd73728.zip
device_samsung_i9300-a0449080d1eedfd4980b28bd6e73b177ffd73728.tar.gz
device_samsung_i9300-a0449080d1eedfd4980b28bd6e73b177ffd73728.tar.bz2
i9300: libsensors: Fix compass orientation (for real)
Actually this fixes several more problems, but the compass orientation is the most noticeable symptom of this: Android expects sensor event timestamps in nanoseconds. Linux timestamps on the other hand are saved in the timeval struct in seconds and micro- seconds. Therefore these need to be converted, which is easy enough and is implemented in input.c of libsensors. Unfortunately, the current implementation uses type long int for the return value and all further calculations. Since the nanosecond values easily exceed 2^32 the buffers overflow and wrap, which results in the reported timestamps moving between -2^16 and 2^16. The consequences of this are noticeable especially with fused sensors integrating the gyroscope readings, which use the difference of two timestamps to calculate the change in orientation by multiplying it by the rotation rate. When the buffer wraps around this results in a huge time difference and thus leads to a momentary orientation change every ~4.3 seconds. This commit fixes this behavior by using long long int. Change-Id: Ib47bdc36ece16371c82f61b125315074ec048e32
-rw-r--r--libsensors/akm8975.c2
-rw-r--r--libsensors/input.c4
-rw-r--r--libsensors/lsm330dlc_acceleration.c2
-rw-r--r--libsensors/smdk4x12_sensors.h4
4 files changed, 6 insertions, 6 deletions
diff --git a/libsensors/akm8975.c b/libsensors/akm8975.c
index 8de0215..ca85518 100644
--- a/libsensors/akm8975.c
+++ b/libsensors/akm8975.c
@@ -168,7 +168,7 @@ void *akm8975_thread(void *thread_data)
char i2c_data[SENSOR_DATA_SIZE] = { 0 };
short magnetic_data[3];
short mode;
- long int before, after;
+ long long int before, after;
int diff;
int device_fd;
int uinput_fd;
diff --git a/libsensors/input.c b/libsensors/input.c
index cdd82c9..d78dc64 100644
--- a/libsensors/input.c
+++ b/libsensors/input.c
@@ -44,7 +44,7 @@ void input_event_set(struct input_event *event, int type, int code, int value)
gettimeofday(&event->time, NULL);
}
-long int timestamp(struct timeval *time)
+long long int timestamp(struct timeval *time)
{
if (time == NULL)
return -1;
@@ -52,7 +52,7 @@ long int timestamp(struct timeval *time)
return time->tv_sec * 1000000000LL + time->tv_usec * 1000;
}
-long int input_timestamp(struct input_event *event)
+long long int input_timestamp(struct input_event *event)
{
if (event == NULL)
return -1;
diff --git a/libsensors/lsm330dlc_acceleration.c b/libsensors/lsm330dlc_acceleration.c
index 2483cf8..5782d57 100644
--- a/libsensors/lsm330dlc_acceleration.c
+++ b/libsensors/lsm330dlc_acceleration.c
@@ -49,7 +49,7 @@ void *lsm330dlc_acceleration_thread(void *thread_data)
struct input_event event;
struct timeval time;
struct lsm330dlc_acc acceleration_data;
- long int before, after;
+ long long int before, after;
int diff;
int device_fd;
int uinput_fd;
diff --git a/libsensors/smdk4x12_sensors.h b/libsensors/smdk4x12_sensors.h
index 984834a..3a4d31f 100644
--- a/libsensors/smdk4x12_sensors.h
+++ b/libsensors/smdk4x12_sensors.h
@@ -76,8 +76,8 @@ int smdk4x12_sensors_poll(struct sensors_poll_device_t *dev,
*/
void input_event_set(struct input_event *event, int type, int code, int value);
-long int timestamp(struct timeval *time);
-long int input_timestamp(struct input_event *event);
+long long int timestamp(struct timeval *time);
+long long int input_timestamp(struct input_event *event);
int uinput_rel_create(const char *name);
void uinput_destroy(int uinput_fd);
int input_open(char *name);