Improve Maemo accelerometer handling
authorAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 6 Jul 2011 11:01:10 +0000 (14:01 +0300)
committerAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 6 Jul 2011 11:01:10 +0000 (14:01 +0300)
share/tilt_maemo.c

index efac68a..45afaee 100644 (file)
@@ -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;
 }
+