]> git.mxchange.org Git - flightgear.git/commitdiff
Update controls so we can specify each tank on/off individually. Also
authorcurt <curt>
Fri, 5 Jul 2002 19:04:04 +0000 (19:04 +0000)
committercurt <curt>
Fri, 5 Jul 2002 19:04:04 +0000 (19:04 +0000)
updated the network interface files to add fuel tank selector information.

src/Controls/controls.cxx
src/Controls/controls.hxx
src/FDM/ExternalNet.cxx
src/Network/atc610x.cxx
src/Network/native_ctrls.cxx
src/Network/net_fdm.hxx
src/Network/raw_ctrls.hxx

index 3af7ea2ddaaba3306dab7f932fbb62e9edbef549..106208d807e2f7f7ea0523e54ea4e37c3e6fdc90 100644 (file)
@@ -62,7 +62,6 @@ FGControls::FGControls() :
     flaps( 0.0 ),
     parking_brake( 0.0 ),
     throttle_idle( true ),
-    fuel_selector( FUEL_BOTH ),
     gear_down( false )
 {
 }
@@ -80,7 +79,7 @@ void FGControls::reset_all()
     set_starter( ALL_ENGINES, false );
     set_magnetos( ALL_ENGINES, 0 );
     throttle_idle = true;
-    fuel_selector = FUEL_BOTH;
+    set_fuel_selector( ALL_TANKS, true );
     gear_down = true;
 }
 
@@ -161,15 +160,19 @@ FGControls::bind ()
        &FGControls::get_parking_brake, &FGControls::set_parking_brake);
   fgSetArchivable("/controls/parking-brake");
   for (index = 0; index < MAX_WHEELS; index++) {
-    char name[32];
-    sprintf(name, "/controls/brakes[%d]", index);
-    fgTie(name, this, index,
-        &FGControls::get_brake, &FGControls::set_brake);
-    fgSetArchivable(name);
+      char name[32];
+      sprintf(name, "/controls/brakes[%d]", index);
+      fgTie(name, this, index,
+            &FGControls::get_brake, &FGControls::set_brake);
+      fgSetArchivable(name);
+  }
+  for (index = 0; index < MAX_TANKS; index++) {
+      char name[32];
+      sprintf(name, "/controls/fuel-selector[%d]", index);
+      fgTie(name, this, index,
+            &FGControls::get_fuel_selector, &FGControls::set_fuel_selector);
+      fgSetArchivable(name);
   }
-  fgTie("/controls/fuel-selector", this,
-       &FGControls::get_fuel_selector, &FGControls::set_fuel_selector);
-  fgSetArchivable("/controls/fuel-selector");
   fgTie("/controls/gear-down", this,
        &FGControls::get_gear_down, &FGControls::set_gear_down);
   fgSetArchivable("/controls/gear-down");
@@ -472,6 +475,21 @@ FGControls::set_starter( int engine, bool flag )
     }
 }
 
+void
+FGControls::set_fuel_selector( int tank, bool pos )
+{
+    if ( tank == ALL_TANKS ) {
+       for ( int i = 0; i < MAX_TANKS; i++ ) {
+           fuel_selector[i] = pos;
+       }
+    } else {
+       if ( (tank >= 0) && (tank < MAX_TANKS) ) {
+           fuel_selector[tank] = pos;
+       }
+    }
+}
+
+
 void
 FGControls::set_parking_brake( double pos )
 {
index 2165df04c3fea8a8e7fe1e37042fe5028184527c..51bb4328c88337788b4ff7d3016cd508fa5f0e56 100644 (file)
@@ -52,10 +52,8 @@ public:
     };
 
     enum {
-        FUEL_OFF = 0,
-        FUEL_LEFT = 1,
-        FUEL_RIGHT = 2,
-        FUEL_BOTH = 3
+       ALL_TANKS = -1,
+       MAX_TANKS = 4
     };
 
 private:
@@ -75,7 +73,7 @@ private:
     int magnetos[MAX_ENGINES];
     bool throttle_idle;
     bool starter[MAX_ENGINES];
-    int fuel_selector;
+    bool fuel_selector[MAX_TANKS];
     bool gear_down;
 
     SGPropertyNode * auto_coordination;
@@ -111,7 +109,9 @@ public:
     inline double get_brake(int wheel) const { return brake[wheel]; }
     inline int get_magnetos(int engine) const { return magnetos[engine]; }
     inline bool get_starter(int engine) const { return starter[engine]; }
-    inline int get_fuel_selector() const { return fuel_selector; }
+    inline bool get_fuel_selector(int tank) const {
+        return fuel_selector[tank];
+    }
     inline bool get_gear_down() const { return gear_down; }
 
     // Update functions
@@ -138,7 +138,7 @@ public:
     void set_magnetos( int engine, int pos );
     void move_magnetos( int engine, int amt );
     void set_starter( int engine, bool flag );
-    void set_fuel_selector( int pos ) { fuel_selector = pos; }
+    void set_fuel_selector( int tank, bool pos );
     void set_parking_brake( double pos );
     void set_brake( int wheel, double pos );
     void move_brake( int wheel, double amt );
index 49e432096240de1f3504a8b5c7f2a9fdc1204a5c..47a1d2afdd7ffba3ce0f1735626132ab39bc3e43 100644 (file)
@@ -87,6 +87,9 @@ static void global2raw( FGRawCtrls *raw ) {
          //      << endl;
        }
     }
+    for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
+        raw->fuel_selector[i] = node->getDoubleValue( "fuel-selector", true );
+    }
     for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
        raw->brake[i] = node->getDoubleValue( "brakes", 0.0 );
     }
@@ -105,8 +108,11 @@ static void global2raw( FGRawCtrls *raw ) {
        htond(raw->throttle[i]);
        htond(raw->mixture[i]);
        htond(raw->prop_advance[i]);
-       htonl(raw->magnetos[i]);
-       htonl(raw->starter[i]);
+       raw->magnetos[i] = htonl(raw->magnetos[i]);
+       raw->starter[i] = htonl(raw->starter[i]);
+    }
+    for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
+        raw->fuel_selector[i] = htonl(raw->fuel_selector[i]);
     }
     for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
        htond(raw->brake[i]);
index 751b1ee6c745eb91c742bffad3ab792aa8b57a15..fca8ca3cdbf3c1c886220293312528831a9917b0 100644 (file)
@@ -1340,18 +1340,6 @@ bool FGATC610x::do_switches() {
        starter = false;
     }
 
-    // flaps
-    float flaps = 0.0;
-    if ( switch_matrix[board][6][3] == 1 ) {
-       flaps = 1.0;
-    } else if ( switch_matrix[board][5][3] == 1 ) {
-       flaps = 2.0 / 3.0;
-    } else if ( switch_matrix[board][4][3] == 1 ) {
-       flaps = 1.0 / 3.0;
-    } else if ( switch_matrix[board][4][3] == 0 ) {
-       flaps = 0.0;
-    }
-
     // do a bit of filtering on the magneto/starter switch and the
     // flap lever because these are not well debounced in hardware
     static int mag1, mag2, mag3;
@@ -1361,7 +1349,6 @@ bool FGATC610x::do_switches() {
     if ( mag1 == mag2 && mag2 == mag3 ) {
         fgSetInt( "/controls/magnetos[0]", magnetos );
     }
-
     static bool start1, start2, start3;
     start3 = start2;
     start2 = start1;
@@ -1370,6 +1357,21 @@ bool FGATC610x::do_switches() {
         fgSetBool( "/controls/starter[0]", starter );
     }
 
+
+    // flaps
+    float flaps = 0.0;
+    if ( switch_matrix[board][6][3] == 1 ) {
+       flaps = 1.0;
+    } else if ( switch_matrix[board][5][3] == 1 ) {
+       flaps = 2.0 / 3.0;
+    } else if ( switch_matrix[board][4][3] == 1 ) {
+       flaps = 1.0 / 3.0;
+    } else if ( switch_matrix[board][4][3] == 0 ) {
+       flaps = 0.0;
+    }
+
+    // do a bit of filtering on the magneto/starter switch and the
+    // flap lever because these are not well debounced in hardware
     static float flap1, flap2, flap3;
     flap3 = flap2;
     flap2 = flap1;
@@ -1378,6 +1380,25 @@ bool FGATC610x::do_switches() {
         fgSetFloat( "/controls/flaps", flaps );
     }
 
+    // fuel selector (not finished)
+    if ( true ) {
+        // both
+        fgSetFloat( "/controls/fuel-selector[0]", true );
+        fgSetFloat( "/controls/fuel-selector[1]", true );
+    } else if ( true ) {
+        // left
+        fgSetFloat( "/controls/fuel-selector[0]", true );
+        fgSetFloat( "/controls/fuel-selector[1]", false );
+    } else if ( true ) {
+        // right
+        fgSetFloat( "/controls/fuel-selector[0]", false );
+        fgSetFloat( "/controls/fuel-selector[1]", true );
+    } else {
+        // fuel cutoff
+        fgSetFloat( "/controls/fuel-selector[0]", false );
+        fgSetFloat( "/controls/fuel-selector[1]", false );
+    }
+
     return true;
 }
 
index 6f512b8e5ac82a6a281073d447e3eba92e5f2c07..e5c79b2f740c52994879b5cad06549990731755c 100644 (file)
@@ -71,6 +71,9 @@ static void global2raw( const FGControls *global, FGRawCtrls *raw ) {
        raw->mixture[i] = globals->get_controls()->get_mixture(i);
        raw->prop_advance[i] = globals->get_controls()->get_prop_advance(i);
     }
+    for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
+        raw->fuel_selector[i] = globals->get_controls()->get_fuel_selector(i);
+    }
     for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
        raw->brake[i] =  globals->get_controls()->get_brake(i);
     }
@@ -93,6 +96,9 @@ static void raw2global( const FGRawCtrls *raw, FGControls *global ) {
            globals->get_controls()->set_mixture( i, raw->mixture[i] );
            globals->get_controls()->set_prop_advance( i, raw->prop_advance[i]);
        }
+       for ( i = 0; i < FGRawCtrls::FG_MAX_TANKS; ++i ) {
+           globals->get_controls()->set_fuel_selector( i, raw->fuel_selector[i] );
+       }
        for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) {
            globals->get_controls()->set_brake( i, raw->brake[i] );
        }
index 2363f29285afb6c33574d7ab47ca9094dffcd92d..bb9728a3dab94b99fdd384ce9ccc576f8c6737c1 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <time.h> // time_t
 
-const int FG_NET_FDM_VERSION = 7;
+const int FG_NET_FDM_VERSION = 8;
 
 
 // Define a structure containing the top level flight dynamics model
@@ -51,7 +51,7 @@ public:
     enum {
         FG_MAX_ENGINES = 4,
         FG_MAX_WHEELS = 3,
-        FG_MAX_TANKS = 2
+        FG_MAX_TANKS = 4
     };
 
     // Positions
index d955e1f6b1377178d0d3bcfee4d4b5ad26285b76..576197af899776a9c59472a32e51d3009bcda183 100644 (file)
@@ -30,7 +30,7 @@
 # error This library requires C++
 #endif                                   
 
-const int FG_RAW_CTRLS_VERSION = 6;
+const int FG_RAW_CTRLS_VERSION = 7;
 
 
 // Define a structure containing the control parameters
@@ -43,7 +43,8 @@ public:
 
     enum {
         FG_MAX_ENGINES = 4,
-        FG_MAX_WHEELS = 3
+        FG_MAX_WHEELS = 3,
+        FG_MAX_TANKS = 4
     };
 
     // Aero controls
@@ -61,6 +62,10 @@ public:
     double mixture[FG_MAX_ENGINES];      //  0 ... 1
     double prop_advance[FG_MAX_ENGINES]; //  0 ... 1
 
+    // Fuel management
+    int num_tanks;                       // number of valid tanks
+    bool fuel_selector[FG_MAX_TANKS];    // false = off, true = on
+
     // Brake controls
     int num_wheels;                     // number of valid wheels
     double brake[FG_MAX_WHEELS];         //  0 ... 1