On Sun, Oct 19, 2008 at 12:08 AM, Georg Vollnhals <[EMAIL PROTECTED]> wrote:
>
> I missed your patch and could not find the post with a search.

That's because I gave it to AJ on IRC ;)

-- 
Csaba/Jester
? utils/Modeller/photomodel
Index: utils/js_server/js_server.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/utils/js_server/js_server.cxx,v
retrieving revision 1.2
diff -u -r1.2 js_server.cxx
--- utils/js_server/js_server.cxx	21 Feb 2006 01:20:38 -0000	1.2
+++ utils/js_server/js_server.cxx	8 Oct 2008 17:23:30 -0000
@@ -40,6 +40,7 @@
 {
   jsJoystick * js ;
   float      * ax;
+  bool       * bn;
   int port = 16759;
   char * host; /* = "192.168.1.7"; */
   int activeaxes = 4;
@@ -66,6 +67,9 @@
   int numaxes = js->getNumAxes();
   ax = new float [ numaxes ] ;
   activeaxes = numaxes;
+
+  int numbuttons = js->getNumButtons();
+  bn = new bool [ numbuttons ];
   
   if( numaxes < 4 )
   {
@@ -94,11 +98,10 @@
   char packet[256] = "Hello world!";
   while(1)
   {
-        int b;
 	int len = 0;
 	int axis = 0;
 
-        js->read( &b, ax );
+        js->read( bn, ax );
 	for ( axis = 0 ; axis < activeaxes ; axis++ )
 	{
 	  long axisvalue = (long int)(ax[axis]*2147483647.0);
@@ -114,7 +117,9 @@
 	  len+=4;
 	}
 
-	long int b_l = b;
+	long int b_l = 0;
+	for( int i = 0 ; i < numbuttons && i < sizeof(b_l) * 8 ; i++ )
+	  if (bn[i]) b_l |= (1L << i);
         memcpy(packet+len, &b_l, 4);
         len+=4;
 
Index: src/Input/input.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Input/input.cxx,v
retrieving revision 1.107
diff -u -r1.107 input.cxx
--- src/Input/input.cxx	1 Aug 2008 15:57:32 -0000	1.107
+++ src/Input/input.cxx	8 Oct 2008 17:23:34 -0000
@@ -822,7 +822,6 @@
 FGInput::_update_joystick (double dt)
 {
   int modifiers = KEYMOD_NONE;  // FIXME: any way to get the real ones?
-  int buttons;
   // float js_val, diff;
   float axis_values[MAX_JOYSTICK_AXES];
 
@@ -835,7 +834,8 @@
     if (js == 0 || js->notWorking())
       continue;
 
-    js->read(&buttons, axis_values);
+    bool buttons[js->getNumButtons()];
+    js->read(buttons, axis_values);
 
                                 // Fire bindings for the axes.
     for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
@@ -878,7 +878,7 @@
       if(b.last_dt >= b.interval_sec) {
         _update_button(_joystick_bindings[i].buttons[j],
                        modifiers,
-                       (buttons & (1 << j)) > 0,
+                       buttons[j],
                        -1, -1);
         b.last_dt -= b.interval_sec;
       }
Index: src/Input/js_demo.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Input/js_demo.cxx,v
retrieving revision 1.3
diff -u -r1.3 js_demo.cxx
--- src/Input/js_demo.cxx	4 May 2004 19:02:19 -0000	1.3
+++ src/Input/js_demo.cxx	8 Oct 2008 17:23:34 -0000
@@ -15,6 +15,7 @@
 {
   jsJoystick *js[Z] ;
   float      *ax[Z] ;
+  bool       *bn[Z] ;
   int i, j, t, useful[Z];
 
   jsInit();
@@ -35,39 +36,54 @@
   }
   if ( t == 0 ) exit ( 1 ) ;
 
+  int max_buttons = 0;
   for ( i = 0; i < Z; i++ )
-    if ( useful[i] )
+    if ( useful[i] ) {
        ax[i] = new float [ js[i]->getNumAxes () ] ;
-
+       int num_buttons = js[i]->getNumButtons () ;
+       bn[i] = new bool [ num_buttons ] ;
+       if ( num_buttons > max_buttons ) max_buttons = num_buttons;
+    }
+  int width = 46 + ((max_buttons < 4) ? 0 : (max_buttons - 4));
   for ( i = 0 ; i < Z ; i++ )
-    if ( useful[i] )
-       printf ( "+--------------------JS.%d----------------------", i ) ;
-
+    if ( useful[i] ) {
+       j = printf ( "+ JS.%d ", i ) - 1;
+       for ( ; j < width; j++ )
+         printf ( "-" ); 
+    }
   printf ( "+\n" ) ;
 
   for ( i = 0 ; i < Z ; i++ )
    if ( useful[i] )
    {
-    if ( js[i]->notWorking () )
-      printf ( "|           ~~~ Not Detected ~~~             " ) ;
+    if ( js[i]->notWorking () ) {
+      printf ( "| ~~~ Not Detected ~~~ " ) ;
+      for ( j = 22 ; j < width ; j++ )
+        printf ( " " );
+    }
     else
     {
       printf ( "| Btns " ) ;
+      for ( j = 0 ; j < max_buttons - 4 ; j++ )
+        printf ( " " ) ;
 
       for ( j = 0 ; j < js[i]->getNumAxes () ; j++ )
         printf ( "Ax:%1d ", j ) ;
 
       for ( ; j < 8 ; j++ )
         printf ( "     " ) ;
+
     }
    }
 
   printf ( "|\n" ) ;
 
   for ( i = 0 ; i < Z ; i++ )
-    if ( useful[i] )
-      printf ( "+----------------------------------------------" ) ;
-
+    if ( useful[i] ) {
+      printf ( "+" ) ;
+      for ( j = 0 ; j < width ; j++ )
+        printf ( "-" );
+    }
   printf ( "+\n" ) ;
 
   while (1)
@@ -75,15 +91,22 @@
     for ( i = 0 ; i < Z ; i++ )
     if ( useful[i] )
      {
-      if ( js[i]->notWorking () )
-        printf ( "|  .   .   .   .   .   .   .   .   .   .   . " ) ;
+      if ( js[i]->notWorking () ) {
+        printf ( "| ....");
+        for ( j = 4 ; j < max_buttons ; j++ )
+          printf ( "." );
+        printf ( "  .    .    .    .    .    .    .    .   " ) ;
+      }
       else
       {
-        int b ;
-
-        js[i]->read ( &b, ax[i] ) ;
+        js[i]->read ( bn[i], ax[i] ) ;
 
-        printf ( "| %04x ", b ) ;
+        printf ( "| " ) ;
+        for ( j = 0 ; j < js[i]->getNumButtons () ; j++ )
+          printf ( "%c", bn[i][j] ? '*' : '-' ) ;
+        printf ( " " ) ;
+        for ( ; j < max_buttons ; j++ )
+          printf ( " " );
 
 	for ( j = 0 ; j < js[i]->getNumAxes () ; j++ )
 	  printf ( "%+.1f ", ax[i][j] ) ;
Index: src/Input/jsinput.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Input/jsinput.cxx,v
retrieving revision 1.6
diff -u -r1.6 jsinput.cxx
--- src/Input/jsinput.cxx	27 Jul 2008 16:25:15 -0000	1.6
+++ src/Input/jsinput.cxx	8 Oct 2008 17:23:34 -0000
@@ -33,16 +33,24 @@
     pretty_display=true;
     joystick=axis=button=-1;
     axis_threshold=0.2;
+    jss->firstJoystick();
+    do {
+        button_iv[jss->getCurrentJoystickId()] = new bool[jss->getJoystick()->getNumButtons()];
+    } while( jss->nextJoystick() );
 }
 
-jsInput::~jsInput(void) {}
+jsInput::~jsInput(void) {
+    for(int i = 0; i < MAX_JOYSTICKS; i++) {
+        if (button_iv[i]) delete button_iv[i];
+    }
+}
 
 int jsInput::getInput() {
 
     bool gotit=false;
 
     float delta;
-    int i, current_button = 0, button_bits = 0;
+    int i;
 
     joystick=axis=button=-1;
     axis_positive=false;
@@ -65,7 +73,7 @@
 
     jss->firstJoystick();
     do {
-        jss->getJoystick()->read ( &button_iv[jss->getCurrentJoystickId()],
+        jss->getJoystick()->read ( button_iv[jss->getCurrentJoystickId()],
                 axes_iv[jss->getCurrentJoystickId()] ) ;
     } while( jss->nextJoystick() );
 
@@ -74,10 +82,16 @@
     while(!gotit) {
         jss->firstJoystick();
         do {
+            int num_buttons = jss->getJoystick()->getNumButtons();
+            bool current_buttons[num_buttons];
+            jss->getJoystick()->read ( current_buttons, axes ) ;
 
-            jss->getJoystick()->read ( &current_button, axes ) ;
-
-            if(pretty_display) printf ( "| %04x ", current_button ) ;
+            if(pretty_display) {
+	        printf ( "| ");
+                for(int j = 0; j < num_buttons; j++) {
+                    printf("%c", current_buttons[j] ? '*' : '-');
+                }
+            }
 
             for ( i = 0 ; i < jss->getJoystick()->getNumAxes(); i++ ) {
 
@@ -89,10 +103,13 @@
                         joystick=jss->getCurrentJoystickId();
                         axis=i;
                         axis_positive=(delta>0);
-                    } else if( current_button != 0 ) {
-                        gotit=true;
-                        joystick=jss->getCurrentJoystickId();
-                        button_bits=current_button;
+                    } else {
+                        for( int j = 0; j < num_buttons; j++ ) {
+                            if(current_buttons[j]) {
+                                button=j;
+                                gotit=true;
+                            }
+                        }
                     }
                 }
             }
@@ -111,14 +128,6 @@
 
         ulMilliSecondSleep(1);
     }
-    if(button_bits != 0) {
-        for(int i=0;i<=31;i++) {
-            if( ( button_bits & (1 << i) ) > 0 ) {
-                button=i;
-                break;
-            }
-        }
-    }
 
     return 0;
 }
Index: src/Input/jsinput.h
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Input/jsinput.h,v
retrieving revision 1.4
diff -u -r1.4 jsinput.h
--- src/Input/jsinput.h	4 Jul 2006 23:29:05 -0000	1.4
+++ src/Input/jsinput.h	8 Oct 2008 17:23:34 -0000
@@ -31,7 +31,7 @@
     bool pretty_display;
     float axes[_JS_MAX_AXES];
     float axes_iv[MAX_JOYSTICKS][_JS_MAX_AXES];
-    int button_iv[MAX_JOYSTICKS];
+    bool* button_iv[MAX_JOYSTICKS];
 
     int joystick,axis,button;
     bool axis_positive;
diff -ur plib-1.8.5.orig/src/js/js.cxx plib-1.8.5/src/js/js.cxx
--- plib-1.8.5.orig/src/js/js.cxx	2008-03-11 03:06:21.000000000 +0100
+++ plib-1.8.5/src/js/js.cxx	2008-10-08 19:26:34.000000000 +0200
@@ -59,12 +59,12 @@
 }
 
 
-void jsJoystick::read ( int *buttons, float *axes )
+void jsJoystick::read ( bool *buttons, float *axes )
 {
   if ( error )
   {
     if ( buttons )
-      *buttons = 0 ;
+      memset( buttons, 0, sizeof(bool) * num_buttons );
 
     if ( axes )
       for ( int i = 0 ; i < num_axes ; i++ )
diff -ur plib-1.8.5.orig/src/js/js.h plib-1.8.5/src/js/js.h
--- plib-1.8.5.orig/src/js/js.h	2008-03-11 03:06:21.000000000 +0100
+++ plib-1.8.5/src/js/js.h	2008-10-08 17:42:38.000000000 +0200
@@ -86,8 +86,8 @@
   void getMaxRange ( float *axes ) const { memcpy ( axes, max   , num_axes * sizeof(float) ) ; }
   void getCenter   ( float *axes ) const { memcpy ( axes, center, num_axes * sizeof(float) ) ; }
 
-  void read    ( int *buttons, float *axes ) ;
-  void rawRead ( int *buttons, float *axes ) ;
+  void read    ( bool *buttons, float *axes ) ;
+  void rawRead ( bool *buttons, float *axes ) ;
   // bool SetForceFeedBack ( int axe, float force );
 } ;
 
diff -ur plib-1.8.5.orig/src/js/jsLinux.cxx plib-1.8.5/src/js/jsLinux.cxx
--- plib-1.8.5.orig/src/js/jsLinux.cxx	2008-03-11 03:06:21.000000000 +0100
+++ plib-1.8.5/src/js/jsLinux.cxx	2008-10-08 17:46:18.000000000 +0200
@@ -35,10 +35,18 @@
 
 struct os_specific_s {
   js_event     js          ;
-  int          tmp_buttons ;
+  bool*        tmp_buttons ;
   float        tmp_axes [ _JS_MAX_AXES ] ;
   char         fname [ 128 ] ;
   int          fd ;
+  
+  os_specific_s() : tmp_buttons(0) {};
+  ~os_specific_s() { if (tmp_buttons) delete tmp_buttons; };
+  void allocate_buttons(int num_buttons)
+  {
+    if (tmp_buttons) delete tmp_buttons;
+    tmp_buttons = new bool[num_buttons];
+  }
 };
 
 void jsInit () {}
@@ -50,8 +58,6 @@
   for ( int i = 0 ; i < _JS_MAX_AXES ; i++ )
     os->tmp_axes [ i ] = 0.0f ;
 
-  os->tmp_buttons = 0 ;
-
   os->fd = ::open ( os->fname, O_RDONLY ) ;
 
   error = ( os->fd < 0 ) ;
@@ -72,6 +78,7 @@
   num_axes = u ;
   ioctl ( os->fd, JSIOCGBUTTONS, &u ) ;
   num_buttons = u ;
+  os->allocate_buttons(num_buttons);
   ioctl ( os->fd, JSIOCGNAME ( sizeof(name) ), name ) ;
   fcntl ( os->fd, F_SETFL      , O_NONBLOCK   ) ;
 
@@ -127,12 +134,12 @@
 }
 
 
-void jsJoystick::rawRead ( int *buttons, float *axes )
+void jsJoystick::rawRead ( bool *buttons, float *axes )
 {
   if ( error )
   {
     if ( buttons )
-      *buttons = 0 ;
+      memset(buttons, 0, sizeof(bool) * num_buttons);
 
     if ( axes )
       for ( int i = 0 ; i < num_axes ; i++ )
@@ -149,7 +156,8 @@
     {
       /* use the old values */
 
-      if ( buttons != NULL ) *buttons = os->tmp_buttons ;
+      if ( buttons != NULL )
+        memcpy ( buttons, os->tmp_buttons, sizeof(bool) * num_buttons );
       if ( axes    != NULL )
         memcpy ( axes, os->tmp_axes, sizeof(float) * num_axes ) ;
 
@@ -165,9 +173,9 @@
     {
       case JS_EVENT_BUTTON :
         if ( os->js.value == 0 ) /* clear the flag */
-          os->tmp_buttons &= ~(1 << os->js.number) ;
+          os->tmp_buttons[os->js.number] = false;
         else
-          os->tmp_buttons |=  (1 << os->js.number) ;
+          os->tmp_buttons[os->js.number] = true;
         break ;
 
       case JS_EVENT_AXIS:
@@ -185,7 +193,8 @@
 
         /* use the old values */
 
-        if ( buttons != NULL ) *buttons = os->tmp_buttons ;
+        if ( buttons != NULL )
+          memcpy ( buttons, os->tmp_buttons, sizeof(bool) * num_buttons );
         if ( axes    != NULL )
           memcpy ( axes, os->tmp_axes, sizeof(float) * num_axes ) ;
 
@@ -193,7 +202,7 @@
     }
 
     if ( buttons != NULL )
-      *buttons = os->tmp_buttons ;
+      memcpy ( buttons, os->tmp_buttons, sizeof(bool) * num_buttons );
   }
 }
 
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to