]> git.mxchange.org Git - flightgear.git/blob - src/Input/js_demo.cxx
Changes to keep the various autopilot properties from stepping on each
[flightgear.git] / src / Input / js_demo.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #ifdef HAVE_WINDOWS_H
6 #  include <windows.h>                     
7 #endif
8
9 #include <string.h>             // plib/js.h should really include this !!!!!!
10 #include <plib/js.h>
11
12 #define Z 8
13
14 int main ( int, char ** )
15 {
16   jsJoystick *js[Z] ;
17   float      *ax[Z] ;
18   int i, j, t, useful[Z];
19
20   for ( i = 0; i < Z; i++ )
21       js[i] = new jsJoystick ( i ) ;
22
23   printf ( "Joystick test program.\n" ) ;
24   printf ( "~~~~~~~~~~~~~~~~~~~~~~\n" ) ;
25
26   t = 0;
27   for ( i = 0; i < Z; i++ )
28   { useful[i] = ! ( js[i]->notWorking () );
29     if ( useful[i] )
30          t++;
31     else printf ( "Joystick %i not detected\n", i ) ;
32   }
33   if ( t == 0 ) exit ( 1 ) ;
34
35   for ( i = 0; i < Z; i++ )
36     if ( useful[i] )
37        ax[i] = new float [ js[i]->getNumAxes () ] ;
38
39   for ( i = 0 ; i < Z ; i++ )
40     if ( useful[i] )
41        printf ( "+--------------------JS.%d----------------------", i ) ;
42
43   printf ( "+\n" ) ;
44
45   for ( i = 0 ; i < Z ; i++ )
46    if ( useful[i] )
47    {
48     if ( js[i]->notWorking () )
49       printf ( "|           ~~~ Not Detected ~~~             " ) ;
50     else
51     {
52       printf ( "| Btns " ) ;
53
54       for ( j = 0 ; j < js[i]->getNumAxes () ; j++ )
55         printf ( "Ax:%1d ", j ) ;
56
57       for ( ; j < 8 ; j++ )
58         printf ( "     " ) ;
59     }
60    }
61
62   printf ( "|\n" ) ;
63
64   for ( i = 0 ; i < Z ; i++ )
65     if ( useful[i] )
66       printf ( "+----------------------------------------------" ) ;
67
68   printf ( "+\n" ) ;
69
70   while (1)
71   {
72     for ( i = 0 ; i < Z ; i++ )
73     if ( useful[i] )
74      {
75       if ( js[i]->notWorking () )
76         printf ( "|  .   .   .   .   .   .   .   .   .   .   . " ) ;
77       else
78       {
79         int b ;
80
81         js[i]->read ( &b, ax[i] ) ;
82
83         printf ( "| %04x ", b ) ;
84
85         for ( j = 0 ; j < js[i]->getNumAxes () ; j++ )
86           printf ( "%+.1f ", ax[i][j] ) ;
87
88         for ( ; j < 8 ; j++ )
89           printf ( "  .  " ) ;
90       }
91      }
92
93     printf ( "|\r" ) ;
94     fflush ( stdout ) ;
95
96     /* give other processes a chance */
97
98 #ifdef WIN32
99     Sleep ( 1 ) ;
100 #elif defined(sgi)
101     sginap ( 1 ) ;
102 #else
103     usleep ( 1000 ) ;
104 #endif
105   }
106
107   return 0 ;
108 }
109
110