User:Sagacis/ForceFeedback
From Openmoko
I've added tactile feedback to touchscreen presses to the neod. See the attached patch.
It's configured using the neod gconf file. I still have to figure out how to put that in the build.
Sagacis 05:04, 3 October 2007 (CEST)
Index: neod/src/buttonactions.c
===================================================================
--- neod.orig/src/buttonactions.c 2007-09-30 11:19:30.000000000 -0500
+++ neod/src/buttonactions.c 2007-09-30 15:20:40.000000000 -0500
@@ -43,6 +43,7 @@
//#define DEBUG_THIS_FILE
#define SYS_CLASS_BACKLIGHT "/sys/class/backlight/"
+#define SYS_VIBRATE "/sys/class/leds/gta01:vibrator/"
static gchar* backlight_node = NULL;
static int backlight_max_brightness = 1;
@@ -76,6 +77,9 @@
int powersave_timer2 = -1;
int powersave_timer3 = -1;
+int tactile_feedback_duration_ms = 20;
+int tactile_feedback_enabled = 1;
+
GtkWidget* aux_menu = 0;
GtkWidget* power_menu = 0;
@@ -225,6 +229,10 @@
GError* error = 0;
pm_value = gconf_client_get_int( gconfc, "/desktop/openmoko/neod/power_management", &error );
if ( error ) g_debug( "gconf error: %s", error->message );
+ tactile_feedback_enabled = gconf_client_get_int( gconfc, "/desktop/openmoko/neod/tactile_feedback_enabled", &error );
+ if ( error ) g_debug( "gconf error: %s", error->message );
+ tactile_feedback_duration_ms = gconf_client_get_int( gconfc, "/desktop/openmoko/neod/tactile_feedback_duration_ms", &error );
+ if ( error ) g_debug( "gconf error: %s", error->message );
gconf_client_add_dir( gconfc, "/desktop/openmoko/neod", GCONF_CLIENT_PRELOAD_NONE, &error );
if ( error ) g_debug( "gconf error: %s", error->message );
gconf_client_notify_add( gconfc, "/desktop/openmoko/neod/power_management", (GConfClientNotifyFunc) neod_buttonactions_gconf_cb, NULL, NULL, &error );
@@ -306,6 +314,9 @@
{
g_debug( "stylus pressed" );
neod_buttonactions_sound_play( "touchscreen" );
+ if (tactile_feedback_enabled == 1 &&
+ tactile_feedback_duration_ms > 10 && tactile_feedback_duration_ms <= 1000)
+ neod_buttonactions_vibrate( tactile_feedback_duration_ms );
}
else if ( event.value == 0 ) /* released */
{
@@ -807,3 +818,27 @@
}
+void
+moko_notify_vibrate (char* value)
+{
+ gint fd;
+ gchar buf[100];
+ gint len;
+
+ fd = g_open (SYS_VIBRATE"brightness", O_WRONLY, 0);
+ if (fd == -1)
+ {
+ g_warning ("Unable to open vibration device");
+ return;
+ }
+ len = g_sprintf (buf, "%s", value);
+ write (fd, buf, len);
+ close (fd);
+}
+
+void neod_buttonactions_vibrate( int ms_duration )
+{
+ moko_notify_vibrate("1");
+ usleep(ms_duration * 1000);
+ moko_notify_vibrate("0");
+}
Index: neod/src/buttonactions.h
===================================================================
--- neod.orig/src/buttonactions.h 2007-09-30 11:19:30.000000000 -0500
+++ neod/src/buttonactions.h 2007-09-30 11:19:44.000000000 -0500
@@ -40,5 +40,6 @@
void neod_buttonactions_sound_init();
void neod_buttonactions_set_display( int brightness );
void neod_buttonactions_sound_play( const gchar* samplename );
+void neod_buttonactions_vibrate( int duration );
#endif
