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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 jsInput::jsInput(jsSuper *j) {
26 joystick=axis=button=-1;
30 jsInput::~jsInput(void) {}
32 int jsInput::getInput(){
37 int i, current_button = 0, button_bits = 0;
39 joystick=axis=button=-1;
43 printf ( "+----------------------------------------------\n" ) ;
44 printf ( "| Btns " ) ;
46 for ( i = 0 ; i < jss->getJoystick()->getNumAxes() ; i++ )
47 printf ( "Ax:%1d ", i ) ;
54 printf ( "+----------------------------------------------\n" ) ;
60 jss->getJoystick()->read ( &button_iv[jss->getCurrentJoystickId()],
61 axes_iv[jss->getCurrentJoystickId()] ) ;
62 } while( jss->nextJoystick() );
70 jss->getJoystick()->read ( ¤t_button, axes ) ;
72 if(pretty_display) printf ( "| %04x ", current_button ) ;
74 for ( i = 0 ; i < jss->getJoystick()->getNumAxes(); i++ ) {
76 delta = axes[i] - axes_iv[jss->getCurrentJoystickId()][i];
77 if(pretty_display) printf ( "%+.1f ", delta ) ;
79 if( fabs(delta) > axis_threshold ) {
81 joystick=jss->getCurrentJoystickId();
83 axis_positive=(delta>0);
84 } else if( current_button != 0 ) {
86 joystick=jss->getCurrentJoystickId();
87 button_bits=current_button;
98 } while( jss->nextJoystick() && !gotit);
104 ulMilliSecondSleep(1);
106 if(button_bits != 0) {
107 for(int i=0;i<=31;i++) {
108 if( ( button_bits & (1 << i) ) > 0 ) {