]> git.mxchange.org Git - flightgear.git/blob - src/Input/jsinput.cxx
Declare fgReshape into gui.h
[flightgear.git] / src / Input / jsinput.cxx
1 // jsinput.cxx -- wait for and identify input from joystick
2 //
3 // Written by Tony Peden, started May 2001
4 //
5 // Copyright (C) 2001  Tony Peden (apeden@earthlink.net)
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #include "jsinput.h"
22
23 jsInput::jsInput(jsSuper *j) {
24   jss=j;
25   pretty_display=true;
26   joystick=axis=button=-1;
27   axis_threshold=0.2;
28 }
29
30 jsInput::~jsInput(void) {}
31
32 int jsInput::getInput(void){
33       
34       bool gotit=false;
35       
36       float delta;
37       int i, current_button = 0, button_bits = 0;
38
39       joystick=axis=button=-1;
40       
41       if(pretty_display) {
42           printf ( "+----------------------------------------------\n" ) ;
43           printf ( "| Btns " ) ;
44
45           for ( i = 0 ; i < jss->getJoystick()->getNumAxes() ; i++ )
46             printf ( "Ax:%1d ", i ) ;
47
48           for ( ; i < 8 ; i++ )
49             printf ( "     " ) ;
50
51           printf ( "|\n" ) ;
52
53           printf ( "+----------------------------------------------\n" ) ;
54       }
55       
56
57       jss->firstJoystick();
58       do {
59         jss->getJoystick()->read ( &button_iv[jss->getCurrentJoystickId()],
60                                        axes_iv[jss->getCurrentJoystickId()] ) ;
61       } while( jss->nextJoystick() );  
62       
63       
64       
65       while(!gotit) {
66         jss->firstJoystick();
67         do {
68
69           jss->getJoystick()->read ( &current_button, axes ) ;
70
71           if(pretty_display) printf ( "| %04x ", current_button ) ;
72
73                 for ( i = 0 ; i < jss->getJoystick()->getNumAxes(); i++ ) {
74
75             delta = axes[i] - axes_iv[jss->getCurrentJoystickId()][i]; 
76             if(pretty_display) printf ( "%+.1f ", delta ) ; 
77             if(!gotit) {
78               if( fabs(delta) > axis_threshold ) {
79                 gotit=true;
80                 joystick=jss->getCurrentJoystickId();
81                 axis=i;
82               } else if( current_button != 0 ) {
83                 gotit=true;
84                 joystick=jss->getCurrentJoystickId();  
85                 button_bits=current_button;
86               } 
87             }            
88           }
89                 
90           if(pretty_display) {
91             for ( ; i < 8 ; i++ )
92                     printf ( "  .  " ) ;
93           }
94
95
96         } while( jss->nextJoystick() && !gotit); 
97         if(pretty_display) {
98           printf ( "|\r" ) ;
99           fflush ( stdout ) ;
100         }
101
102         ulMilliSecondSleep(1);
103       }
104       if(button_bits != 0) {
105         for(int i=1;i<=31;i++) {
106           if( ( button_bits & (1 << i) ) > 0 ) {
107              button=i;
108              break;
109           } 
110         }    
111       } 
112
113       return 0;
114 }
115