From b17e1bb7c081f2dd03eae7d75079680234cba79c Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 5 Jul 2002 19:04:04 +0000 Subject: [PATCH 1/1] Update controls so we can specify each tank on/off individually. Also updated the network interface files to add fuel tank selector information. --- src/Controls/controls.cxx | 38 +++++++++++++++++++++-------- src/Controls/controls.hxx | 14 +++++------ src/FDM/ExternalNet.cxx | 10 ++++++-- src/Network/atc610x.cxx | 47 ++++++++++++++++++++++++++---------- src/Network/native_ctrls.cxx | 6 +++++ src/Network/net_fdm.hxx | 4 +-- src/Network/raw_ctrls.hxx | 9 +++++-- 7 files changed, 92 insertions(+), 36 deletions(-) diff --git a/src/Controls/controls.cxx b/src/Controls/controls.cxx index 3af7ea2dd..106208d80 100644 --- a/src/Controls/controls.cxx +++ b/src/Controls/controls.cxx @@ -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 ) { diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index 2165df04c..51bb4328c 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -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 ); diff --git a/src/FDM/ExternalNet.cxx b/src/FDM/ExternalNet.cxx index 49e432096..47a1d2afd 100644 --- a/src/FDM/ExternalNet.cxx +++ b/src/FDM/ExternalNet.cxx @@ -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]); diff --git a/src/Network/atc610x.cxx b/src/Network/atc610x.cxx index 751b1ee6c..fca8ca3cd 100644 --- a/src/Network/atc610x.cxx +++ b/src/Network/atc610x.cxx @@ -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; } diff --git a/src/Network/native_ctrls.cxx b/src/Network/native_ctrls.cxx index 6f512b8e5..e5c79b2f7 100644 --- a/src/Network/native_ctrls.cxx +++ b/src/Network/native_ctrls.cxx @@ -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] ); } diff --git a/src/Network/net_fdm.hxx b/src/Network/net_fdm.hxx index 2363f2928..bb9728a3d 100644 --- a/src/Network/net_fdm.hxx +++ b/src/Network/net_fdm.hxx @@ -32,7 +32,7 @@ #include // 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 diff --git a/src/Network/raw_ctrls.hxx b/src/Network/raw_ctrls.hxx index d955e1f6b..576197af8 100644 --- a/src/Network/raw_ctrls.hxx +++ b/src/Network/raw_ctrls.hxx @@ -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 -- 2.39.2