From: Alberto Mardegan Date: Sat, 9 Jul 2011 08:41:24 +0000 (+0300) Subject: WIP: Vibra support X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fvibra;p=neverball WIP: Vibra support Check process stuck at futex when level terminates, needs investigation. --- diff --git a/ball/game_server.c b/ball/game_server.c index b82bd45..9e00048 100644 --- a/ball/game_server.c +++ b/ball/game_server.c @@ -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 } } diff --git a/share/maemo.c b/share/maemo.c index 7a16ff8..d1cb4ea 100644 --- a/share/maemo.c +++ b/share/maemo.c @@ -20,6 +20,11 @@ #include "maemo.h" #include #include +#define __USE_BSD +#include +#include + +#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(); +} + diff --git a/share/maemo.h b/share/maemo.h index 8a5e1c5..a2b3ef2 100644 --- a/share/maemo.h +++ b/share/maemo.h @@ -20,3 +20,5 @@ int maemo_init(const char *program); void maemo_quit(void); +void maemo_vibra(float intensity); +