]> git.mxchange.org Git - flightgear.git/blob - Joystick/js.cxx
Renamed joystick.[ch] to joystick.[ch]xx
[flightgear.git] / Joystick / js.cxx
1
2 #include "js.h"
3
4 jsJoystick js0 ( 0 ) ;
5 jsJoystick js1 ( 1 ) ;
6
7 int main ()
8 {
9   printf ( "Joystick test program.\n" ) ;
10   printf ( "~~~~~~~~~~~~~~~~~~~~~~\n" ) ;
11
12   if ( js0 . notWorking () ) printf ( "Joystick 0 not detected\n" ) ;
13   if ( js1 . notWorking () ) printf ( "Joystick 1 not detected\n" ) ;
14   if ( js0 . notWorking () && js1 . notWorking () ) exit ( 1 ) ;
15
16   js0 . setDeadBand ( 0, 0.1 ) ;
17   js0 . setDeadBand ( 1, 0.1 ) ;
18   js1 . setDeadBand ( 0, 0.1 ) ;
19   js1 . setDeadBand ( 1, 0.1 ) ;
20
21   float *ax0 = new float [ js0.getNumAxes () ] ;
22   float *ax1 = new float [ js1.getNumAxes () ] ;
23
24   while (1)
25   {
26     int b ;
27
28     if ( ! js0 . notWorking () )
29     {
30       js0 . read ( &b, ax0 ) ;
31
32       printf ( "JS0: b0:%s b1:%s X:%1.3f Y:%1.3f   ",
33          ( b & 1 ) ? "on " : "off", ( b & 2 ) ? "on " : "off", ax0[0], ax0[1] ) ;
34     }
35
36     if ( ! js1 . notWorking () )
37     {
38       js1 . read ( &b, ax1 ) ;
39
40       printf ( "JS1: b0:%s b1:%s X:%1.3f Y:%1.3f   ",
41        ( b & 1 ) ? "on " : "off", ( b & 2 ) ? "on " : "off", ax1[0], ax1[1] ) ;
42     }
43
44     printf ( "\r" ) ;
45     fflush ( stdout ) ;
46
47     /* give other processes a chance */
48
49     usleep ( 1 ) ;
50   }
51
52   exit ( 0 ) ;
53 }
54