set_elevator_trim(0.0);
set_rudder(0.0);
set_throttle(FGControls::ALL_ENGINES, 0.0);
+ set_starter(FGControls::ALL_ENGINES, false);
+ set_magnetos(FGControls::ALL_ENGINES, 0);
throttle_idle = true;
gear_down = true;
}
throttle[engine] = 0.0;
mixture[engine] = 1.0;
prop_advance[engine] = 1.0;
+ magnetos[engine] = 0;
+ starter[engine] = false;
}
for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
fgTie(name, this, index,
&FGControls::get_prop_advance, &FGControls::set_prop_advance);
fgSetArchivable(name);
+ sprintf(name, "/controls/magnetos[%d]", index);
+ fgTie(name, this, index,
+ &FGControls::get_magnetos, &FGControls::set_magnetos);
+ fgSetArchivable(name);
+ sprintf(name, "/controls/starter[%d]", index);
+ fgTie(name, this, index,
+ &FGControls::get_starter, &FGControls::set_starter);
+ fgSetArchivable(name);
}
for (index = 0; index < MAX_WHEELS; index++) {
char name[32];
fgUntie(name);
sprintf(name, "/controls/propellor-pitch[%d]", index);
fgUntie(name);
+ sprintf(name, "/controls/magnetos[%d]", index);
+ fgUntie(name);
+ sprintf(name, "/controls/starter[%d]", index);
+ fgUntie(name);
}
for (index = 0; index < MAX_WHEELS; index++) {
char name[32];
double mixture[MAX_ENGINES];
double prop_advance[MAX_ENGINES];
double brake[MAX_WHEELS];
+ int magnetos[MAX_ENGINES];
bool throttle_idle;
+ bool starter[MAX_ENGINES];
bool gear_down;
SGPropertyNode * auto_coordination;
if ( *x < min ) { *x = min; }
if ( *x > max ) { *x = max; }
}
-
+
+ inline void CLAMP(int *i, int min, int max ) {
+ if ( *i < min ) { *i = min; }
+ if ( *i > max ) { *i = max; }
+ }
+
public:
FGControls();
return prop_advance[engine];
}
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 bool get_gear_down() const { return gear_down; }
// Update functions
}
}
}
+ inline void set_magnetos( int engine, int pos ) {
+ if ( engine == ALL_ENGINES ) {
+ for ( int i = 0; i < MAX_ENGINES; i++ ) {
+ magnetos[i] = pos;
+ CLAMP( &magnetos[i], 0, 3 );
+ }
+ } else {
+ if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+ magnetos[engine] = pos;
+ CLAMP( &magnetos[engine], 0, 3 );
+ }
+ }
+ }
+ inline void move_magnetos( int engine, int amt ) {
+ if ( engine == ALL_ENGINES ) {
+ for ( int i = 0; i < MAX_ENGINES; i++ ) {
+ magnetos[i] += amt;
+ CLAMP( &magnetos[i], 0, 3 );
+ }
+ } else {
+ if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+ magnetos[engine] += amt;
+ CLAMP( &magnetos[engine], 0, 3 );
+ }
+ }
+ }
+ inline void set_starter( int engine, bool flag ) {
+ if ( engine == ALL_ENGINES ) {
+ for ( int i = 0; i < MAX_ENGINES; i++ ) {
+ starter[i] = flag;
+ }
+ } else {
+ if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
+ starter[engine] = flag;
+ }
+ }
+ }
inline void set_brake( int wheel, double pos ) {
if ( wheel == ALL_WHEELS ) {
for ( int i = 0; i < MAX_WHEELS; i++ ) {
n_R = 2; // Number of crank revolutions per power cycle - 2 for a 4 stroke engine.
// Various bits of housekeeping describing the engines initial state.
- running = fgGetBool("/engines/engine[0]/running");
+ running = false;
cranking = false;
crank_counter = false;
- fgSetBool("/engines/engine[0]/cranking", false);
+ starter = false;
// Initialise Engine Variables used by this instance
if(running)
// Check for spark
bool Magneto_Left = false;
bool Magneto_Right = false;
- int mag_pos = fgGetInt("/engines/engine[0]/magneto");
// Magneto positions:
// 0 -> off
// 1 -> left only
} // Need to make this better, eg position of fuel selector switch.
// Check if we are turning the starter motor
- bool temp = fgGetBool("/engines/engine[0]/starter");
- if(cranking != temp) {
+ if(cranking != starter) {
// This check saves .../cranking from getting updated every loop - they only update when changed.
- cranking = temp;
- if(cranking)
- fgSetBool("/engines/engine[0]/cranking", true);
- else
- fgSetBool("/engines/engine[0]/cranking", false);
- crank_counter = 0;
+ cranking = starter;
+ crank_counter = 0;
}
// Note that although /engines/engine[0]/starter and /engines/engine[0]/cranking might appear to be duplication it is
// not since the starter may be engaged with the battery voltage too low for cranking to occur (or perhaps the master
if(RPM > 450) {
// For now just instantaneously start but later we should maybe crank for a bit
running = true;
- fgSetBool("/engines/engine[0]/running", true);
// RPM = 600;
}
}
// Cut the engine
// note that we only cut the power - the engine may continue to spin if the prop is in a moving airstream
running = false;
- fgSetBool("/engines/engine[0]/running", false);
}
// Now we've ascertained whether the engine is running or not we can start to do the engine calculations 'proper'
//Check if we have stalled the engine
if (RPM == 0) {
running = false;
- fgSetBool("/engines/engine[0]/running", false);
} else if((RPM <= 480) && (cranking)) {
//Make sure the engine noise dosn't play if the engine won't start due to eg mixture lever pulled out.
running = false;
- fgSetBool("/engines/engine[0]/running", false);
}
}
}
float Throttle_Lever_Pos; // 0 = Closed, 100 = Fully Open
float Propeller_Lever_Pos; // 0 = Full Course 100 = Full Fine
float Mixture_Lever_Pos; // 0 = Idle Cut Off 100 = Full Rich
+ int mag_pos; // 0=off, 1=left, 2=right, 3=both.
+ bool starter;
//misc
float IAS;
inline void set_Mixture_Lever_Pos( float value ) {
Mixture_Lever_Pos = value;
}
+ // set the magneto switch position
+ inline void set_Magneto_Switch_Pos( int value ) {
+ mag_pos = value;
+ }
+ inline void setStarterFlag( bool flag ) {
+ starter = flag;
+ }
// set ambient pressure - takes pounds per square foot
inline void set_p_amb( float value ) {
p_amb = value * 47.88026;
inline float get_prop_thrust_lbs() const { return (prop_thrust * 0.2248); }
inline float get_fuel_flow_gals_hr() const { return (Fuel_Flow_gals_hr); }
inline float get_oil_temp() const { return ((current_oil_temp * 1.8) - 459.67); }
+ inline bool getRunningFlag() const { return running; }
+ inline bool getCrankingFlag() const { return cranking; }
+ inline bool getStarterFlag() const { return starter; }
};
// Hardwired to C172 full tanks for now - need to fix this sometime
// Also note that this is the max quantity - the usable quantity
// is slightly less
- set_Tank1Fuel(14.0);
- set_Tank2Fuel(14.0);
-
-
+ set_Tank1Fuel(28.0);
+ set_Tank2Fuel(28.0);
}
FGLaRCsim::~FGLaRCsim(void) {
eng.set_Propeller_Lever_Pos( 100 );
eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 )
* 100.0 );
+ eng.set_Magneto_Switch_Pos( globals->get_controls()->get_magnetos(0) );
+ eng.setStarterFlag( globals->get_controls()->get_starter(0) );
eng.set_p_amb( Static_pressure );
eng.set_T_amb( Static_temperature );
// copy engine state values onto "bus"
FGEngInterface *e = get_engine( 0 );
- e->set_Throttle( globals->get_controls()->get_throttle( 0 ) * 100.0 );
- e->set_Mixture( 80 );
+ e->set_Throttle( globals->get_controls()->get_throttle(0) * 100.0 );
+ e->set_Mixture( 80 ); // ???????
e->set_Prop_Advance( 100 );
e->set_RPM( eng.get_RPM() );
e->set_Manifold_Pressure( eng.get_Manifold_Pressure() );
e->set_prop_thrust( eng.get_prop_thrust_SI() );
e->set_Fuel_Flow( eng.get_fuel_flow_gals_hr() );
e->set_Oil_Temp( eng.get_oil_temp() );
+ e->set_Running_Flag( eng.getRunningFlag() );
+ e->set_Cranking_Flag( eng.getCrankingFlag() );
//Assume we are using both tanks equally for now
reduce_Tank1Fuel( (eng.get_fuel_flow_gals_hr() / (2 * 3600))
double Throttle;
double Mixture;
double Prop_Advance;
- int Magnetos; // 0=off, 1=left, 2=right, 3=both
- bool Starter; // flag to indicate the starter switch is on
+// int Magnetos; // 0=off, 1=left, 2=right, 3=both
+// bool Starter; // flag to indicate the starter switch is on
// outputs
double RPM;
inline void set_Throttle( double t ) { Throttle = t; }
inline void set_Mixture( double m ) { Mixture = m; }
inline void set_Prop_Advance( double p ) { Prop_Advance = p; }
- inline void set_Magnetos( int m ) { Magnetos = m; }
- inline void set_Starter( bool s ) { Starter = s; }
inline void set_RPM( double r ) { RPM = r; }
inline void set_Manifold_Pressure( double mp ) { Manifold_Pressure = mp; }
inline void set_MaxHP( double hp ) { MaxHP = hp; }
inline void set_prop_thrust( double t ) { prop_thrust = t; }
inline void set_Fuel_Flow( double f ) { Fuel_Flow = f; }
inline void set_Oil_Temp (double o) { Oil_Temp = o; }
+ inline void set_Running_Flag (bool r) { running = r; }
+ inline void set_Cranking_Flag (bool c) { cranking = c; }
};
}
}
+/**
+ * Return the current engine0 running flag
+ */
+static bool
+getRunningFlag ()
+{
+ if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ return current_aircraft.fdm_state->get_engine(0)->get_Running_Flag();
+ } else {
+ return false;
+ }
+}
+
+/**
+ * Return the current engine0 cranking flag
+ */
+static bool
+getCrankingFlag ()
+{
+ if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ return current_aircraft.fdm_state->get_engine(0)->get_Cranking_Flag();
+ } else {
+ return false;
+ }
+}
+
/**
* Return the fuel level in tank 1
*/
speed);
}
+/*
+ * Set the current engine0 running flag.
+ */
+static void
+setRunningFlag (bool flag)
+{
+ if(current_aircraft.fdm_state->get_engine(0) != NULL) {
+ current_aircraft.fdm_state->get_engine(0)->set_Running_Flag( flag );
+ }
+}
+
+/*
+ * Set the current engine0 cranking flag.
+ */
+//Although there is no real reason to want to tell the engine that it is cranking,
+//this is currently necessary to avoid the cranking sound being played
+//before the engine inits.
+static void
+setCrankingFlag (bool flag)
+{
+ if(current_aircraft.fdm_state->get_engine(0) != NULL) {
+ current_aircraft.fdm_state->get_engine(0)->set_Cranking_Flag( flag );
+ }
+}
+
static double
getFOV ()
{
fgTie("/engines/engine[0]/oil-temperature-degf", getOilTemp);
fgTie("/engines/engine[0]/mp-osi", getMP);
fgTie("/engines/engine[0]/fuel-flow-gph", getFuelFlow);
+ fgTie("/engines/engine[0]/running", getRunningFlag, setRunningFlag);
+ fgTie("/engines/engine[0]/cranking", getCrankingFlag, setCrankingFlag);
//consumables
fgTie("/consumables/fuel/tank[0]/level-gal_us",
#include <FDM/flight.hxx>
#include <FDM/ADA.hxx>
#include <Scenery/tileentry.hxx>
-// Should be inlcluded by gl.h if needed by your platform
+// Should already be inlcluded by gl.h if needed by your platform so
+// we shouldn't include this here.
// #include <GL/glext.h>
PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
// Run audio scheduler
#ifdef ENABLE_AUDIO_SUPPORT
+ static bool bCranking;
if ( fgGetBool("/sim/sound") && globals->get_soundmgr()->is_working() ) {
if ( fgGetString("/sim/aircraft") == "c172" ) {
if(fgGetBool("/engines/engine[0]/running")) {
s1->set_pitch(0.0);
s1->set_volume(0.0);
}
- } else {
+ if(fgGetBool("/engines/engine[0]/cranking")) {
+ if(!bCranking) {
+ globals->get_soundmgr()->play_looped("cranking");
+ bCranking = true;
+ }
+ } else {
+ if(bCranking) {
+ globals->get_soundmgr()->stop("cranking");
+ bCranking = false;
+ }
+ }
+ } else { // Not C172
double param
= globals->get_controls()->get_throttle( 0 ) * 2.0 + 1.0;
s1->set_pitch( param );
// s2 = new FGSimpleSound( "Sounds/corflaps.wav" );
// s2->set_volume( 0.3 );
// globals->get_soundmgr()->add( s2, "flaps" );
+ s2 = new FGSimpleSound( fgGetString("/sim/sounds/engine",
+ "Sounds/cranking.wav") );
+ globals->get_soundmgr()->add( s2, "cranking" );
+ s2->set_pitch(1.5);
+ s2->set_volume(0.25);
}
#endif