]> git.mxchange.org Git - flightgear.git/blobdiff - src/Joystick/joystick.cxx
Swapped throttle and rudder axes.
[flightgear.git] / src / Joystick / joystick.cxx
index 1f766e363dbea08bcf78ad89b2dedb967f270809..28810d97c4f3ce9bb16d3f9ac9f0e3d4e9d8d9b0 100644 (file)
 #  include <windows.h>                     
 #endif
 
+#include <simgear/debug/logstream.hxx>
+
 #include <Aircraft/aircraft.hxx>
-#include <Debug/logstream.hxx>
 #include <Main/options.hxx>
 
 #if defined( ENABLE_PLIB_JOYSTICK )
-#  include <js.h>              // plib include
+#  include <plib/js.h>         // plib include
 #elif defined( ENABLE_GLUT_JOYSTICK )
 #  include <GL/glut.h>
-#  include <XGL/xgl.h>
+#  include <simgear/xgl.h>
 #endif
 
 
@@ -53,6 +54,12 @@ static jsJoystick *js1;
 // these will hold the values of the axes
 static float *js_ax0, *js_ax1;
 
+static bool sync_throttle=false;
+
+static float throttle_tmp=0;
+
+#define SYNC_TOLERANCE 0.02
+
 #elif defined( ENABLE_GLUT_JOYSTICK )
 
 // Do we want these user settable ??
@@ -175,6 +182,12 @@ int fgJoystickInit( void ) {
     {
        current_options.set_auto_coordination(fgOPTIONS::FG_AUTO_COORD_ENABLED);
     }
+    
+    if(current_options.get_trim_mode() > 0) {
+        FG_LOG(FG_INPUT, FG_INFO,
+              "  Waiting for user to synchronize throttle lever...");
+        sync_throttle=true;
+    }
 
 
 #elif defined( ENABLE_GLUT_JOYSTICK )
@@ -204,11 +217,26 @@ int fgJoystickRead( void ) {
 
        //  Added by William Riley -- riley@technologist.com
        if ( js0->getNumAxes() >= 3 ) {
-           controls.set_throttle( FGControls::ALL_ENGINES,
-                                  ((-js_ax0[2] + 1) / 2) );
+           throttle_tmp=(-js_ax0[3] + 1) / 2;
+        
+           if(sync_throttle == true) {
+               if (fabs(controls.get_throttle(0)-throttle_tmp)
+                   < SYNC_TOLERANCE)
+               {
+                   FG_LOG(FG_INPUT, FG_INFO, "  Throttle lever synchronized.");
+                   controls.set_throttle(FGControls::ALL_ENGINES,throttle_tmp);
+                   sync_throttle=false;
+               }    
+           } else {
+               controls.set_throttle( FGControls::ALL_ENGINES,throttle_tmp );
+           }
        } 
        if ( js0->getNumAxes() > 3 ) {
-           controls.set_rudder( js_ax0[3] );
+           if ( current_options.get_auto_coordination() !=
+                 fgOPTIONS::FG_AUTO_COORD_ENABLED ) 
+           {
+               controls.set_rudder( js_ax0[2] );
+           }
        }
        //  End of William's code
 
@@ -216,7 +244,11 @@ int fgJoystickRead( void ) {
 
     if ( ! js1->notWorking() ) {
        js1->read( &b, js_ax1 ) ;
-       controls.set_rudder( js_ax1[0] );
+       if ( current_options.get_auto_coordination() !=
+            fgOPTIONS::FG_AUTO_COORD_ENABLED ) 
+       {
+           controls.set_rudder( js_ax1[0] );
+       }
        controls.set_throttle( FGControls::ALL_ENGINES, -js_ax1[1] * 1.05 );
     }