WIP: Vibra support vibra
authorAlberto Mardegan <mardy@users.sourceforge.net>
Sat, 9 Jul 2011 08:41:24 +0000 (11:41 +0300)
committerAlberto Mardegan <mardy@users.sourceforge.net>
Sat, 9 Jul 2011 08:41:24 +0000 (11:41 +0300)
Check process stuck at futex when level terminates, needs investigation.

ball/game_server.c
share/maemo.c
share/maemo.h

index b82bd45..9e00048 100644 (file)
@@ -21,6 +21,9 @@
 #include "config.h"
 #include "binary.h"
 #include "common.h"
+#ifdef __MAEMO__
+#include "maemo.h"
+#endif
 
 #include "solid_sim.h"
 #include "solid_all.h"
@@ -760,6 +763,9 @@ static int game_step(const float g[3], float dt, int bt)
                     else                             audio_play(AUD_BUMPM, k);
                 }
                 else audio_play(AUD_BUMPM, k);
+#ifdef __MAEMO__
+                maemo_vibra(k);
+#endif
             }
         }
 
index 7a16ff8..d1cb4ea 100644 (file)
 #include "maemo.h"
 #include <SDL/SDL_timer.h>
 #include <libosso.h>
+#define __USE_BSD
+#include <sys/types.h>
+#include <unistd.h>
+
+#define VIBRA_FILE "/sys/class/i2c-adapter/i2c-1/1-0048/twl4030_vibra/pulse"
 
 static osso_context_t *osso_context = NULL;
 static SDL_TimerID screen_timer_id = 0;
@@ -61,8 +66,19 @@ static void fpu_set_fast_mode(int fast_mode)
 #endif /* if __arm__ */
 }
 
+static void drop_root()
+{
+    seteuid(getuid());
+}
+
+static void gain_root()
+{
+    seteuid(0);
+}
+
 int maemo_init(const char *program)
 {
+    drop_root();
     osso_context = osso_initialize(program, "1.0", 0, NULL);
     if (!osso_context) {
         fprintf(stderr, "osso_initialize failed!\n");
@@ -84,3 +100,25 @@ void maemo_quit(void)
     SDL_RemoveTimer(screen_timer_id);
 }
 
+void maemo_vibra(float intensity)
+{
+    FILE *fd;
+    int speed, duration;
+
+    if (intensity < 5) return;
+    else if (intensity < 10) speed = -100;
+    else speed = -500;
+
+    duration = 20 + 5 * intensity;
+    gain_root();
+    fd = fopen(VIBRA_FILE, "w");
+    if (fd != NULL)
+    {
+        fprintf(fd, "%d %d\n", speed, duration);
+        fclose(fd);
+    }
+    else
+        printf("no root");
+    drop_root();
+}
+
index 8a5e1c5..a2b3ef2 100644 (file)
@@ -20,3 +20,5 @@
 int maemo_init(const char *program);
 void maemo_quit(void);
 
+void maemo_vibra(float intensity);
+