[Plib-cvs] plib/src/js js.cxx,1.3,1.4 js.h,1.30,1.31 jsBSD.cxx,1.3,1.4 jsLinux.cxx,1.3,1.4 jsLinuxOl
Brought to you by:
sjbaker
From: Eric L. <smo...@us...> - 2004-08-15 00:12:42
|
Update of /cvsroot/plib/plib/src/js In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13436 Modified Files: js.cxx js.h jsBSD.cxx jsLinux.cxx jsLinuxOld.cxx jsMacOS.cxx jsMacOSX.cxx jsNone.cxx jsWindows.cxx Log Message: Olivier A's js rewrite Index: js.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/js.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- js.cxx 29 Nov 2002 19:39:48 -0000 1.3 +++ js.cxx 15 Aug 2004 00:12:32 -0000 1.4 @@ -22,7 +22,8 @@ #include "js.h" -void jsInit () {} + +/// void jsInit () {} float jsJoystick::fudge_axis ( float value, int axis ) const { Index: js.h =================================================================== RCS file: /cvsroot/plib/plib/src/js/js.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- js.h 11 Nov 2003 22:54:48 -0000 1.30 +++ js.h 15 Aug 2004 00:12:32 -0000 1.31 @@ -32,106 +32,18 @@ #define _JS_MAX_AXES 16 #define _JS_MAX_BUTTONS 32 - -#ifdef UL_MACINTOSH -# include <InputSprocket.h> -#endif - -#ifdef UL_MAC_OSX -# include <mach/mach.h> -# include <IOKit/IOkitLib.h> [...94 lines suppressed...] + friend struct os_specific_s ; int error ; char name [ 128 ] ; int num_axes ; @@ -143,7 +55,6 @@ float max [ _JS_MAX_AXES ] ; float min [ _JS_MAX_AXES ] ; - void open () ; void close () ; @@ -175,6 +86,7 @@ void read ( int *buttons, float *axes ) ; void rawRead ( int *buttons, float *axes ) ; + // bool SetForceFeedBack ( int axe, float force ); } ; extern void jsInit () ; Index: jsBSD.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsBSD.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- jsBSD.cxx 20 Mar 2004 00:21:53 -0000 1.3 +++ jsBSD.cxx 15 Aug 2004 00:12:32 -0000 1.4 @@ -35,6 +35,7 @@ * an API extension, and to be useful for my devious purposes, FlightGear * would need to understand that. */ + #include "js.h" #if defined(UL_BSD) @@ -495,4 +496,6 @@ #endif } +void jsInit () {} + #endif Index: jsLinux.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsLinux.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- jsLinux.cxx 10 Apr 2003 12:36:27 -0000 1.3 +++ jsLinux.cxx 15 Aug 2004 00:12:32 -0000 1.4 @@ -29,6 +29,17 @@ #include <fcntl.h> #include <sys/ioctl.h> +struct os_specific_s { + js_event js ; + int tmp_buttons ; + float tmp_axes [ _JS_MAX_AXES ] ; + char fname [ 128 ] ; + int fd ; +}; + [...117 lines suppressed...] @@ -156,15 +169,15 @@ /* use the old values */ - if ( buttons != NULL ) *buttons = tmp_buttons ; + if ( buttons != NULL ) *buttons = os->tmp_buttons ; if ( axes != NULL ) - memcpy ( axes, tmp_axes, sizeof(float) * num_axes ) ; + memcpy ( axes, os->tmp_axes, sizeof(float) * num_axes ) ; return ; } if ( buttons != NULL ) - *buttons = tmp_buttons ; + *buttons = os->tmp_buttons ; } } Index: jsLinuxOld.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsLinuxOld.cxx,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- jsLinuxOld.cxx 29 Nov 2002 19:39:48 -0000 1.1 +++ jsLinuxOld.cxx 15 Aug 2004 00:12:32 -0000 1.2 @@ -29,6 +29,12 @@ #include <sys/ioctl.h> #include <linux/joystick.h> +struct os_specific_s { + JS_DATA_TYPE js ; + char fname [ 128 ] ; + int fd ; +}; + void jsJoystick::open () { name [0] = '\0' ; @@ -36,9 +42,9 @@ num_axes = 2 ; /* Default for older Linux systems. */ num_buttons = 32 ; - fd = ::open ( fname, O_RDONLY ) ; + os->fd = ::open ( os->fname, O_RDONLY ) ; - error = ( fd < 0 ) ; + error = ( os->fd < 0 ) ; if ( error ) return ; @@ -79,18 +85,20 @@ void jsJoystick::close () { if ( ! error ) - ::close ( fd ) ; + ::close ( os->fd ) ; + delete os; } jsJoystick::jsJoystick ( int ident ) { id = ident ; + os = new struct os_specific_s; + + sprintf ( os->fname, "/dev/input/js%d", ident ) ; - sprintf ( fname, "/dev/input/js%d", ident ) ; - - if ( access ( fname, F_OK ) != 0 ) - sprintf ( fname, "/dev/js%d", ident ) ; + if ( access ( os->fname, F_OK ) != 0 ) + sprintf ( os->fname, "/dev/js%d", ident ) ; open () ; } @@ -110,24 +118,25 @@ return ; } - int status = ::read ( fd, &js, JS_RETURN ) ; + int status = ::read ( os->fd, &(os->js), JS_RETURN ) ; if ( status != JS_RETURN ) { - perror ( fname ) ; + perror ( os->fname ) ; setError () ; return ; } if ( buttons != NULL ) - *buttons = js.buttons ; + *buttons = os->js.buttons ; if ( axes != NULL ) { - axes[0] = (float) js.x ; - axes[1] = (float) js.y ; + axes[0] = (float) os->js.x ; + axes[1] = (float) os->js.y ; } } -#endif +void jsInit() {} +#endif Index: jsMacOS.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsMacOS.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- jsMacOS.cxx 30 Nov 2002 00:41:49 -0000 1.2 +++ jsMacOS.cxx 15 Aug 2004 00:12:32 -0000 1.3 @@ -25,8 +25,16 @@ #ifdef UL_MACINTOSH -#define _JS_MAX_AXES 9 +#include <InputSprocket.h> +//#define _JS_MAX_AXES_MAC 9 // not used +#define isp_num_axis 9 +#define isp_num_needs 41 + +struct os_specific_s { + ISpElementReference isp_elem [ isp_num_needs ] ; + ISpNeed isp_needs [ isp_num_needs ] ; +}; void jsJoystick::open () { @@ -93,7 +101,7 @@ { "\pButton 31", 128, 0, 0, kISpElementKind_Button, kISpElementLabel_Btn_Select, 0, 0, 0, 0 }, } ; - memcpy ( isp_needs, temp_isp_needs, sizeof(temp_isp_needs) ) ; + memcpy ( os->isp_needs, temp_isp_needs, sizeof(temp_isp_needs) ) ; // next two calls allow keyboard and mouse to emulate other input @@ -108,10 +116,10 @@ ISP_CHECK_ERR(err) */ - err = ISpElement_NewVirtualFromNeeds ( isp_num_needs, isp_needs, isp_elem, 0 ) ; + err = ISpElement_NewVirtualFromNeeds ( isp_num_needs, os->isp_needs, os->isp_elem, 0 ) ; ISP_CHECK_ERR(err) - err = ISpInit ( isp_num_needs, isp_needs, isp_elem, 'PLIB', nil, 0, 128, 0 ) ; + err = ISpInit ( isp_num_needs, os->isp_needs, os->isp_elem, 'PLIB', nil, 0, 128, 0 ) ; ISP_CHECK_ERR(err) num_buttons = isp_num_needs - isp_num_axis ; @@ -141,13 +149,15 @@ ISpSuspend () ; ISpStop () ; ISpShutdown () ; + delete os; } jsJoystick::jsJoystick ( int ident ) { id = ident ; - sprintf ( fname, "/dev/js%d", ident ) ; /* FIXME */ + os = new struct os_specific_s; + // sprintf ( fname, "/dev/js%d", ident ) ; /* FIXME */ open () ; } @@ -176,7 +186,7 @@ for ( i = 0 ; i < num_buttons ; i++ ) { - err = ISpElement_GetSimpleState ( isp_elem [ i + isp_num_axis ], &state) ; + err = ISpElement_GetSimpleState ( os->isp_elem [ i + isp_num_axis ], &state) ; ISP_CHECK_ERR(err) *buttons |= state << i ; @@ -187,7 +197,7 @@ { for ( i = 0 ; i < num_axes ; i++ ) { - err = ISpElement_GetSimpleState ( isp_elem [ i ], &state ) ; + err = ISpElement_GetSimpleState ( os->isp_elem [ i ], &state ) ; ISP_CHECK_ERR(err) axes [i] = (float) state ; @@ -195,4 +205,7 @@ } } +void jsInit() {} + #endif + Index: jsMacOSX.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsMacOSX.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- jsMacOSX.cxx 18 Mar 2004 17:20:52 -0000 1.2 +++ jsMacOSX.cxx 15 Aug 2004 00:12:32 -0000 1.3 @@ -1,7 +1,33 @@ +/* + PLIB - A Suite of Portable Game Libraries + Copyright (C) 1998,2002 Steve Baker + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of [...432 lines suppressed...] + + // hats: + for (int h=0; h < os->num_hats; ++h) { + (*(os->hidDev))->getElementValue(os->hidDev, os->hatCookies[h], &hidEvent); + long result = ( hidEvent.value - os->hat_min[h] ) * 8; + result /= ( os->hat_max[h] - os->hat_min[h] + 1 ); + if ( (result>=0) && (result<8) ) + { + axes[h+real_num_axes+1] = NS_hat[result]; + axes[h+real_num_axes] = WE_hat[result]; + } + else + { + axes[h+real_num_axes] = 0; + axes[h+real_num_axes+1] = 0; + } + } } #endif Index: jsNone.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsNone.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- jsNone.cxx 4 Jan 2003 02:55:54 -0000 1.2 +++ jsNone.cxx 15 Aug 2004 00:12:32 -0000 1.3 @@ -24,7 +24,11 @@ #if defined(UL_IRIX) || defined(UL_SOLARIS) || defined(UL_HPUX) -/* check the joystick driver version */ +/* +struct os_specific_s { +} +*/ + void jsJoystick::open () { @@ -33,10 +37,9 @@ } - void jsJoystick::close () { - error = TRUE ; + // if (os) delete os; } @@ -44,6 +47,7 @@ { error = TRUE ; num_axes = num_buttons = 0 ; + os = NULL; } Index: jsWindows.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/jsWindows.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- jsWindows.cxx 24 Mar 2004 15:57:09 -0000 1.2 +++ jsWindows.cxx 15 Aug 2004 00:12:32 -0000 1.3 @@ -27,17 +27,23 @@ // Since we use joyGetPosEx to request the joystick values, // we have never more than 8 axes to worry about: -#undef _JS_MAX_AXES -#define _JS_MAX_AXES 8 /* X,Y,Z,R,U,V,POV_X,POV_Y */ +#define _JS_MAX_AXES_WIN 8 /* X,Y,Z,R,U,V,POV_X,POV_Y */ + +struct os_specific_s { + JOYCAPS jsCaps ; + JOYINFOEX js ; + UINT js_id ; [...165 lines suppressed...] - case 3: axes[2] = (float) js . dwZpos ; - case 2: axes[1] = (float) js . dwYpos ; - case 1: axes[0] = (float) js . dwXpos ; + case 6: axes[5] = (float) os->js . dwVpos ; + case 5: axes[4] = (float) os->js . dwUpos ; + case 4: axes[3] = (float) os->js . dwRpos ; + case 3: axes[2] = (float) os->js . dwZpos ; + case 2: axes[1] = (float) os->js . dwYpos ; + case 1: axes[0] = (float) os->js . dwXpos ; break; default: @@ -247,5 +255,7 @@ } } +void jsInit() {} + #endif |