]> git.mxchange.org Git - flightgear.git/blob - src/Joystick/js_demo.cxx
Swapped throttle and rudder axes.
[flightgear.git] / src / Joystick / js_demo.cxx
1
2 #include <plib/js.h>
3
4 int main ( int, char ** )
5 {
6   jsJoystick *js[2] ;
7   float      *ax[2] ;
8
9   js[0] = new jsJoystick ( 0 ) ;
10   js[1] = new jsJoystick ( 1 ) ;
11
12   printf ( "Joystick test program.\n" ) ;
13   printf ( "~~~~~~~~~~~~~~~~~~~~~~\n" ) ;
14
15   if ( js[0]->notWorking () ) printf ( "Joystick 0 not detected\n" ) ;
16   if ( js[1]->notWorking () ) printf ( "Joystick 1 not detected\n" ) ;
17   if ( js[0]->notWorking () && js[1]->notWorking () ) exit ( 1 ) ;
18
19   ax[0] = new float [ js[0]->getNumAxes () ] ;
20   ax[1] = new float [ js[1]->getNumAxes () ] ;
21
22   int i, j ;
23
24   for ( i = 0 ; i < 2 ; i++ )
25     printf ( "+---------------JS.%d-----------------", i ) ;
26
27   printf ( "+\n" ) ;
28
29   for ( i = 0 ; i < 2 ; i++ )
30   {
31     if ( js[i]->notWorking () )
32       printf ( "|       ~~~ Not Detected ~~~         " ) ;
33     else
34     {
35       printf ( "| Btns " ) ;
36
37       for ( j = 0 ; j < js[i]->getNumAxes () ; j++ )
38         printf ( "Ax:%d ", j ) ;
39
40       for ( ; j < 6 ; j++ )
41         printf ( "     " ) ;
42     }
43   }
44
45   printf ( "|\n" ) ;
46
47   for ( i = 0 ; i < 2 ; i++ )
48     printf ( "+------------------------------------" ) ;
49
50   printf ( "+\n" ) ;
51
52   while (1)
53   {
54     for ( i = 0 ; i < 2 ; i++ )
55     {
56       if ( js[i]->notWorking () )
57         printf ( "|  .   .   .   .   .   .   .   .   . " ) ;
58       else
59       {
60         int b ;
61
62         js[i]->read ( &b, ax[i] ) ;
63
64         printf ( "| %04x ", b ) ;
65
66         for ( j = 0 ; j < js[i]->getNumAxes () ; j++ )
67           printf ( "%+.1f ", ax[i][j] ) ;
68
69         for ( ; j < 6 ; j++ )
70           printf ( "  .  " ) ;
71       }
72     }
73
74     printf ( "|\r" ) ;
75     fflush ( stdout ) ;
76
77     /* give other processes a chance */
78
79 #ifdef WIN32
80     Sleep ( 1 ) ;
81 #elif defined(sgi)
82     sginap ( 1 ) ;
83 #else
84     usleep ( 1000 ) ;
85 #endif
86   }
87
88   return 0 ;
89 }
90
91