1
0
Fork 0

Added js_demo.cxx from plib source tree.

This commit is contained in:
curt 1999-11-10 20:50:58 +00:00
parent 021ee36a78
commit 40a1a07730
2 changed files with 95 additions and 0 deletions

View file

@ -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 \

91
src/Joystick/js_demo.cxx Normal file
View file

@ -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 ;
}