X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffreeglut_joystick.c;h=4bb8a3720fd09777a6dc0ab06f6fda06936ed47f;hb=7fad69335a7488fd62a47281d7a5a22acf20db16;hp=7c7d112051aa4b8555edf8c242a6f70f758f35a5;hpb=2a0c45b1a10b1bf07fc6760b55172a16e69c9739;p=freeglut diff --git a/src/freeglut_joystick.c b/src/freeglut_joystick.c index 7c7d112..4bb8a37 100644 --- a/src/freeglut_joystick.c +++ b/src/freeglut_joystick.c @@ -42,8 +42,6 @@ #include "config.h" #endif -#define G_LOG_DOMAIN "freeglut-joystick" - #include "../include/GL/freeglut.h" #include "freeglut_internal.h" @@ -118,6 +116,9 @@ typedef struct tagSFG_Joystick SFG_Joystick; struct tagSFG_Joystick { +/* + * XXX All BSDs might share this? + */ #ifdef __FreeBSD__ int id; #endif @@ -238,7 +239,7 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes ) case JS_EVENT_BUTTON: if ( joy->js.value == 0 ) /* clear the flag */ joy->tmp_buttons &= ~(1 << joy->js.number); - else + else joy->tmp_buttons |= (1 << joy->js.number); break; @@ -291,15 +292,15 @@ static float fghJoystickFudgeAxis( SFG_Joystick* joy, float value, int axis ) joy->min[ axis ]); if( xx < -joy->saturate[ axis ] ) - return( -1.0f ); + return -1.0f; if( xx > -joy->dead_band [ axis ] ) - return( 0.0f ); + return 0.0f; xx = (xx + joy->dead_band[ axis ]) / (joy->saturate[ axis ] - joy->dead_band[ axis ]); - return( ( xx < -1.0f ) ? -1.0f : xx ); + return ( xx < -1.0f ) ? -1.0f : xx; } else { @@ -315,7 +316,7 @@ static float fghJoystickFudgeAxis( SFG_Joystick* joy, float value, int axis ) xx = (xx - joy->dead_band[ axis ]) / (joy->saturate[ axis ] - joy->dead_band[ axis ]); - return( ( xx > 1.0f ) ? 1.0f : xx ); + return ( xx > 1.0f ) ? 1.0f : xx; } } @@ -440,7 +441,9 @@ static void fghJoystickOpen( SFG_Joystick* joy ) if( joy->error ) return; - +/* + * XXX All BSDs should share this? + */ # ifdef __FreeBSD__ fghJoystickRawRead(joy, buttons, axes ); joy->error = axes[ 0 ] < -1000000000.0f; @@ -477,6 +480,7 @@ static void fghJoystickOpen( SFG_Joystick* joy ) * Set the correct number of axes for the linux driver */ # ifdef JS_NEW + ioctl( joy->fd, JSIOCGAXES , &joy->num_axes ); ioctl( joy->fd, JSIOCGBUTTONS, &joy->num_buttons ); fcntl( joy->fd, F_SETFL, O_NONBLOCK ); @@ -498,7 +502,10 @@ static void fghJoystickOpen( SFG_Joystick* joy ) { fghJoystickRawRead( joy, NULL, joy->center ); counter++; - } while( !joy->error && counter < 100 && joy->center[ 0 ] == 512.0f && joy->center[ 1 ] == 512.0f ); + } while( !joy->error && + counter < 100 && + joy->center[ 0 ] == 512.0f && + joy->center[ 1 ] == 512.0f ); if( counter >= 100 ) joy->error = TRUE; @@ -534,12 +541,24 @@ void fgJoystickInit( int ident ) #ifdef WIN32 switch( ident ) { - case 0: fgJoystick->js_id = JOYSTICKID1; fghJoystickOpen( fgJoystick ); break; - case 1: fgJoystick->js_id = JOYSTICKID2; fghJoystickOpen( fgJoystick ); break; - default: fgJoystick->num_axes = 0; fgJoystick->error = TRUE; break; + case 0: + fgJoystick->js_id = JOYSTICKID1; + fghJoystickOpen( fgJoystick ); + break; + case 1: + fgJoystick->js_id = JOYSTICKID2; + fghJoystickOpen( fgJoystick ); + break; + default: + fgJoystick->num_axes = 0; + fgJoystick->error = TRUE; + break; } #else +/* + * XXX All BSDs should share this code? + */ # ifdef __FreeBSD__ fgJoystick->id = ident; sprintf( fgJoystick->fname, "/dev/joy%d", ident ); @@ -578,17 +597,26 @@ void fgJoystickPollWindow( SFG_Window* window ) int buttons; freeglut_return_if_fail( fgJoystick != NULL && window != NULL ); - freeglut_return_if_fail( window->Callbacks.Joystick != NULL ); + freeglut_return_if_fail( FETCH_WCB( *window, Joystick ) ); fghJoystickRead( fgJoystick, &buttons, axes ); - fgSetWindow (window); - window->Callbacks.Joystick( - buttons, - (int) (axes[ 0 ] * 1000.0f), - (int) (axes[ 1 ] * 1000.0f), - (int) (axes[ 2 ] * 1000.0f) + INVOKE_WCB( *window, Joystick, + ( buttons, + (int) (axes[ 0 ] * 1000.0f ), + (int) (axes[ 1 ] * 1000.0f ), + (int) (axes[ 2 ] * 1000.0f ) ) ); + + /* + * fgSetWindow (window); + * window->Callbacks.Joystick( + * buttons, + * (int) (axes[ 0 ] * 1000.0f), + * (int) (axes[ 1 ] * 1000.0f), + * (int) (axes[ 2 ] * 1000.0f) + * ); + */ } /* @@ -596,22 +624,34 @@ void fgJoystickPollWindow( SFG_Window* window ) * We might consider adding such functions to freeglut-2.0. */ #if 0 - int getNumAxes () { return num_axes ; } - int notWorking () { return error ; } - - float getDeadBand ( int axis ) { return dead_band [ axis ] ; } - void setDeadBand ( int axis, float db ) { dead_band [ axis ] = db ; } - - float getSaturation ( int axis ) { return saturate [ axis ] ; } - void setSaturation ( int axis, float st ) { saturate [ axis ] = st ; } - - void setMinRange ( float *axes ) { memcpy ( min , axes, num_axes * sizeof(float) ) ; } - void setMaxRange ( float *axes ) { memcpy ( max , axes, num_axes * sizeof(float) ) ; } - void setCenter ( float *axes ) { memcpy ( center, axes, num_axes * sizeof(float) ) ; } - - void getMinRange ( float *axes ) { memcpy ( axes, min , num_axes * sizeof(float) ) ; } - void getMaxRange ( float *axes ) { memcpy ( axes, max , num_axes * sizeof(float) ) ; } - void getCenter ( float *axes ) { memcpy ( axes, center, num_axes * sizeof(float) ) ; } +int getNumAxes () + { return num_axes; } +int notWorking () + { return error; } + +float getDeadBand ( int axis ) + { return dead_band [ axis ]; } +void setDeadBand ( int axis, float db ) + { dead_band [ axis ] = db; } + +float getSaturation ( int axis ) + { return saturate [ axis ]; } +void setSaturation ( int axis, float st ) + { saturate [ axis ] = st; } + +void setMinRange ( float *axes ) + { memcpy ( min , axes, num_axes * sizeof(float) ); } +void setMaxRange ( float *axes ) + { memcpy ( max , axes, num_axes * sizeof(float) ); } +void setCenter ( float *axes ) + { memcpy ( center, axes, num_axes * sizeof(float) ); } + +void getMinRange ( float *axes ) + { memcpy ( axes, min , num_axes * sizeof(float) ); } +void getMaxRange ( float *axes ) + { memcpy ( axes, max , num_axes * sizeof(float) ); } +void getCenter ( float *axes ) + { memcpy ( axes, center, num_axes * sizeof(float) ); } #endif /*** END OF FILE ***/