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.
27 jsInput::jsInput(jsSuper *j) {
30 joystick=axis=button=-1;
34 jsInput::~jsInput(void) {}
36 int jsInput::getInput(void){
41 int i,current_button=0,button_bits;
43 joystick=axis=button=-1;
46 printf ( "+----------------------------------------------\n" ) ;
47 printf ( "| Btns " ) ;
49 for ( i = 0 ; i < jss->getJoystick()->getNumAxes() ; i++ )
50 printf ( "Ax:%1d ", i ) ;
57 printf ( "+----------------------------------------------\n" ) ;
63 jss->getJoystick()->read ( &button_iv[jss->getCurrentJoystickId()],
64 axes_iv[jss->getCurrentJoystickId()] ) ;
65 } while( jss->nextJoystick() );
73 jss->getJoystick()->read ( ¤t_button, axes ) ;
75 if(pretty_display) printf ( "| %04x ", current_button ) ;
77 for ( i = 0 ; i < jss->getJoystick()->getNumAxes(); i++ ) {
79 delta = axes[i] - axes_iv[jss->getCurrentJoystickId()][i];
80 if(pretty_display) printf ( "%+.1f ", delta ) ;
82 if( fabs(delta) > axis_threshold ) {
84 joystick=jss->getCurrentJoystickId();
86 } else if( current_button != 0 ) {
88 joystick=jss->getCurrentJoystickId();
89 button_bits=current_button;
100 } while( jss->nextJoystick() && !gotit);
106 ulMilliSecondSleep(1);
108 if(button_bits != 0) {
109 for(int i=1;i<=31;i++) {
110 if( ( button_bits & (1 << i) ) > 0 ) {