From 40a1a077303da1ab052fc7ebd155b658e5d5d285 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 10 Nov 1999 20:50:58 +0000 Subject: [PATCH] Added js_demo.cxx from plib source tree. --- src/Joystick/Makefile.am | 4 ++ src/Joystick/js_demo.cxx | 91 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/Joystick/js_demo.cxx diff --git a/src/Joystick/Makefile.am b/src/Joystick/Makefile.am index d4efb29b9..5c3c58a00 100644 --- a/src/Joystick/Makefile.am +++ b/src/Joystick/Makefile.am @@ -2,6 +2,10 @@ noinst_LIBRARIES = libJoystick.a libJoystick_a_SOURCES = joystick.cxx joystick.hxx +noinst_PROGRAMS = js_demo + +js_demo_SOURCES = js_demo.cxx + INCLUDES += -I$(top_builddir) \ -I$(top_builddir)/Lib \ -I$(top_builddir)/Lib/plib/include \ diff --git a/src/Joystick/js_demo.cxx b/src/Joystick/js_demo.cxx new file mode 100644 index 000000000..d2e88f0cb --- /dev/null +++ b/src/Joystick/js_demo.cxx @@ -0,0 +1,91 @@ + +#include "js.h" + +int main ( int, char ** ) +{ + jsJoystick *js[2] ; + float *ax[2] ; + + js[0] = new jsJoystick ( 0 ) ; + js[1] = new jsJoystick ( 1 ) ; + + printf ( "Joystick test program.\n" ) ; + printf ( "~~~~~~~~~~~~~~~~~~~~~~\n" ) ; + + if ( js[0]->notWorking () ) printf ( "Joystick 0 not detected\n" ) ; + if ( js[1]->notWorking () ) printf ( "Joystick 1 not detected\n" ) ; + if ( js[0]->notWorking () && js[1]->notWorking () ) exit ( 1 ) ; + + ax[0] = new float [ js[0]->getNumAxes () ] ; + ax[1] = new float [ js[1]->getNumAxes () ] ; + + int i, j ; + + for ( i = 0 ; i < 2 ; i++ ) + printf ( "+---------------JS.%d-----------------", i ) ; + + printf ( "+\n" ) ; + + for ( i = 0 ; i < 2 ; i++ ) + { + if ( js[i]->notWorking () ) + printf ( "| ~~~ Not Detected ~~~ " ) ; + else + { + printf ( "| Btns " ) ; + + for ( j = 0 ; j < js[i]->getNumAxes () ; j++ ) + printf ( "Ax:%d ", j ) ; + + for ( ; j < 6 ; j++ ) + printf ( " " ) ; + } + } + + printf ( "|\n" ) ; + + for ( i = 0 ; i < 2 ; i++ ) + printf ( "+------------------------------------" ) ; + + printf ( "+\n" ) ; + + while (1) + { + for ( i = 0 ; i < 2 ; i++ ) + { + if ( js[i]->notWorking () ) + printf ( "| . . . . . . . . . " ) ; + else + { + int b ; + + js[i]->read ( &b, ax[i] ) ; + + printf ( "| %04x ", b ) ; + + for ( j = 0 ; j < js[i]->getNumAxes () ; j++ ) + printf ( "%+.1f ", ax[i][j] ) ; + + for ( ; j < 6 ; j++ ) + printf ( " . " ) ; + } + } + + printf ( "|\r" ) ; + fflush ( stdout ) ; + + /* give other processes a chance */ + +#ifdef WIN32 + Sleep ( 1 ) ; +#elif defined(sgi) + sginap ( 1 ) ; +#else + usleep ( 1000 ) ; +#endif + } + + return 0 ; +} + + -- 2.39.5