]> git.mxchange.org Git - flightgear.git/commitdiff
Added js_demo.cxx from plib source tree.
authorcurt <curt>
Wed, 10 Nov 1999 20:50:58 +0000 (20:50 +0000)
committercurt <curt>
Wed, 10 Nov 1999 20:50:58 +0000 (20:50 +0000)
src/Joystick/Makefile.am
src/Joystick/js_demo.cxx [new file with mode: 0644]

index d4efb29b94c7c7dd36e249625c9255a9fb65bcda..5c3c58a00c5941eec94dbb636cb3e72c3e5d708f 100644 (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 \
diff --git a/src/Joystick/js_demo.cxx b/src/Joystick/js_demo.cxx
new file mode 100644 (file)
index 0000000..d2e88f0
--- /dev/null
@@ -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 ;
+}
+
+