1 // jsinput.cxx -- wait for and identify input from joystick
3 // Written by Tony Peden, started May 2001
5 // Copyright (C) 2001 Tony Peden (apeden@earthlink.net)
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.
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.
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.
23 jsInput::jsInput(jsSuper *j) {
26 joystick=axis=button=-1;
30 jsInput::~jsInput(void) {}
32 int jsInput::getInput(void){
37 int i, current_button = 0, button_bits = 0;
39 joystick=axis=button=-1;
42 printf ( "+----------------------------------------------\n" ) ;
43 printf ( "| Btns " ) ;
45 for ( i = 0 ; i < jss->getJoystick()->getNumAxes() ; i++ )
46 printf ( "Ax:%1d ", i ) ;
53 printf ( "+----------------------------------------------\n" ) ;
59 jss->getJoystick()->read ( &button_iv[jss->getCurrentJoystickId()],
60 axes_iv[jss->getCurrentJoystickId()] ) ;
61 } while( jss->nextJoystick() );
69 jss->getJoystick()->read ( ¤t_button, axes ) ;
71 if(pretty_display) printf ( "| %04x ", current_button ) ;
73 for ( i = 0 ; i < jss->getJoystick()->getNumAxes(); i++ ) {
75 delta = axes[i] - axes_iv[jss->getCurrentJoystickId()][i];
76 if(pretty_display) printf ( "%+.1f ", delta ) ;
78 if( fabs(delta) > axis_threshold ) {
80 joystick=jss->getCurrentJoystickId();
82 } else if( current_button != 0 ) {
84 joystick=jss->getCurrentJoystickId();
85 button_bits=current_button;
96 } while( jss->nextJoystick() && !gotit);
102 ulMilliSecondSleep(1);
104 if(button_bits != 0) {
105 for(int i=1;i<=31;i++) {
106 if( ( button_bits & (1 << i) ) > 0 ) {