--- gui/fb.cpp.orig 2008-02-19 20:20:49.000000000 +0100 +++ gui/fb.cpp 2008-04-11 09:58:08.000000000 +0200 @@ -63,6 +63,22 @@ /// the coordinates you just found out. Write the coordinates separated by /// commas (X,Y,X,Y), like this: /// TSCALIB=491,1635,1581,639 gnash yourmovie.swf +/// +/// 10-4-2008 N. Coesel +/// Added support for tslib. Tslib is a library which allows to create +/// a stack / cascade of filters to filter and scale touch-screen output. +/// The source doesn't come with much documentation, but writing your +/// own filter based on an existing filter is really easy. Tslib can +/// deal with old style H3600 style touchscreens and the newer event +/// interface. See http://tslib.berlios.de/ to get the source. +/// +/// The check_tslib() routine assumes filtering for movement and presses +/// is properly setup. Scaling is supposed to be performed by tslib or +/// the underlying touchscreen driver. +/// +/// 11-4-2008 N. Coesel +/// Change timer stuff in run() to 64 bit (unsigned long long) integers + #ifdef HAVE_CONFIG_H #include "gnashconfig.h" @@ -93,6 +109,8 @@ #include // for /dev/input/event* +#define USE_TSLIB + //#define DEBUG_SHOW_FPS // prints number of frames per second to STDOUT #ifdef DEBUG_SHOW_FPS @@ -119,6 +137,16 @@ //-- +// NC: Some defines to turn mouse support on or off +#ifdef USE_MOUSE_PS2 +#define USE_MOUSE +#endif + +#ifdef USE_MOUSE_ETT +#define USE_MOUSE +#endif + + namespace gnash { @@ -177,6 +205,9 @@ #endif input_fd=-1; +#ifdef USE_TSLIB + tsDev = NULL; +#endif signal(SIGINT, terminate_signal); signal(SIGTERM, terminate_signal); @@ -193,6 +224,13 @@ close(input_fd); +#ifdef USE_TSLIB + if (tsDev!=NULL) + { + ts_close(tsDev); //ts_close doesn't like a NULL pointer + } +#endif + #ifdef DOUBLE_BUFFER if (buffer) { log_debug("Free'ing offscreen buffer\n"); @@ -244,17 +282,28 @@ bool FBGui::init(int /*argc*/, char *** /*argv*/) { + +#ifdef USE_MOUSE // Initialize mouse (don't abort if no mouse found) if (!init_mouse()) { // just report to the user, keep on going... log_debug("You won't have any pointing input device, sorry."); } +#endif // Initialize keyboard (still not critical) if (!init_keyboard()) { log_debug("You won't have any keyboard input device, sorry."); } +#ifdef USE_TSLIB + if (init_tslib()==false) + { + log_debug("You won't have any tslib input device, sorry."); + } +#endif + + // Open the framebuffer device fd = open("/dev/fb0", O_RDWR); if (fd<0) { @@ -364,13 +413,20 @@ { struct timeval tv; - double timer = 0.0; - double start_timer; + unsigned long long timer=0; //64 bit timer in usec + unsigned long long start_timer; + unsigned long long gui_interval; + + gui_interval = _interval * 1000; + +#ifdef USE_TSLIB + int ts_loop_count; +#endif if (!gettimeofday(&tv, NULL)) - start_timer = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; + start_timer = tv.tv_sec * 1000000 + tv.tv_usec; else - start_timer = 0.0; + start_timer = 0; // let the GUI recompute the x/y scale factors to best fit the whole screen @@ -378,17 +434,32 @@ while (!terminate_request) { - double prevtimer = timer; + unsigned long long prevtimer = timer; - while ((timer-prevtimer)*1000 < _interval) { +#ifdef USE_TSLIB + //Make sure we sample the touch screen a few times otherwise + //responsiveness may suffer at high CPU loads + ts_loop_count=0; + while ( ((timer-prevtimer) < gui_interval) && (ts_loop_count<10) ) { +#else + while ((timer-prevtimer) < gui_interval) { +#endif usleep(1); // task switch - + +#ifdef USE_MOUSE check_mouse(); // TODO: Exit delay loop on mouse events! +#endif + check_keyboard(); // TODO: Exit delay loop on keyboard events! - + +#ifdef USE_TSLIB + check_tslib(); + ts_loop_count++; //increase loopcount +#endif + if (!gettimeofday(&tv, NULL)) - timer = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; + timer = tv.tv_sec * 1000000 + tv.tv_usec; } // advance movie @@ -1428,5 +1499,69 @@ } +#ifdef USE_TSLIB +bool FBGui::init_tslib() +{ + char* devname = getenv(TSLIB_DEVICE_ENV); + if (!devname) devname=TSLIB_DEVICE_NAME; + + + tsDev = ts_open(devname,1); //Open tslib non-blocking + if (tsDev==NULL) + { + log_debug("Could not open touchscreen %s: %s", devname, strerror(errno)); + return false; + } + + ts_config(tsDev); + if (ts_fd(tsDev)<0) + { + log_debug("Could not get touchscreen fd %s: %s", devname, strerror(errno)); + return false; + } + + log_debug("Using TSLIB on %s", devname); + return true; + +} + +void FBGui::check_tslib() +{ + //Read events from the touchscreen and transport them into Gnash + //Tslib should be setup so the output is pretty clean. + struct ts_sample event; + int n; + unsigned long flags; + unsigned long buttons; + + if (tsDev==NULL) return; //No tslib device initialized, exit! + + n = ts_read(tsDev, &event, 1); //read one event + + //Did we read an event? + if (n==1) + { + if (event.pressure>0) + { + //the screen is touched + if (event.x > m_stage_width ) event.x = m_stage_width; + if (event.y > m_stage_height) event.y = m_stage_height; + notify_mouse_moved(int(event.x / getXScale()), int(event.y / getYScale())); + notify_mouse_clicked(true, 1); //fire mouse click event into Gnash + log_debug("Touched x: %d y: %d width: %d height: %d",event.x , event.y, m_stage_width, m_stage_height); //debug + } + else + { + notify_mouse_clicked(false, 1); //button released + log_debug("lifted x: %d y: %d",event.x , event.y); //debug + } + } +} + + +#endif //end USE_TSLIB + + + // end of namespace gnash }