diff options
author | Christian Balster <christian.balster@gmail.com> | 2015-06-02 14:51:42 +0200 |
---|---|---|
committer | forkbomb <keepcalm444@gmail.com> | 2015-11-25 08:34:30 +1100 |
commit | a0449080d1eedfd4980b28bd6e73b177ffd73728 (patch) | |
tree | 231faabd069a63df9c15e9cf0ee97e93f57ff1c7 /libsensors/input.c | |
parent | d7864758c2c931aa082e0623bb3d9d1912a53abf (diff) | |
download | device_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
Diffstat (limited to 'libsensors/input.c')
-rw-r--r-- | libsensors/input.c | 4 |
1 files changed, 2 insertions, 2 deletions
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; |