From: Alberto Mardegan Date: Wed, 6 Jul 2011 11:01:10 +0000 (+0300) Subject: Improve Maemo accelerometer handling X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=702ec359f3d2988eda7ea2a82c269e5a54ad2667;p=neverball Improve Maemo accelerometer handling --- diff --git a/share/tilt_maemo.c b/share/tilt_maemo.c index efac68a..45afaee 100644 --- a/share/tilt_maemo.c +++ b/share/tilt_maemo.c @@ -50,11 +50,17 @@ int tilt_stat(void) /* Combine with previous reading */ if (has_read) { - accel.x = ax * 0.4f + accel.x * 0.6f; - accel.y = ay * 0.4f + accel.y * 0.6f; + accel.x = ax * 0.2f + accel.x * 0.8f; + accel.y = ay * 0.2f + accel.y * 0.8f; + accel.z = az * 0.2f + accel.z * 0.8f; } else + { + accel.x = ax; + accel.y = ay; + accel.z = az; has_read = 1; + } return i == 3 ? 1 : 0; } @@ -66,10 +72,11 @@ int tilt_get_button(int *b, int *s) float tilt_get_x(void) { - return asinf(accel.y / 1000.0f) * 180.0f / M_PI; + return atan2f(accel.y, -accel.z) * 180.0f / M_PI; } float tilt_get_z(void) { - return asinf(-accel.x / 1000.0f) * 180.0f / M_PI; + return atan2f(-accel.x, -accel.z) * 180.0f / M_PI; } +