#include <Time/sunpos.hxx>
#include <Time/tmp.hxx>
#include <Cockpit/radiostack.hxx>
+#include <Cockpit/panel.hxx>
#ifndef FG_OLD_WEATHER
# include <WeatherCM/FGLocalWeatherDatabase.h>
#else
// Static variables.
////////////////////////////////////////////////////////////////////////
-bool FGBFI::_needReinit = false;
+ // Yech -- not thread-safe, etc. etc.
+static bool _needReinit = false;
+static string _temp;
+
+static inline void needReinit ()
+{
+ _needReinit = true;
+}
+
+
+/**
+ * Reinitialize FGFS to use the new BFI settings.
+ */
+static inline void
+reinit ()
+{
+ // Save the state of everything
+ // that's going to get clobbered
+ // when we reinit the subsystems.
+
+ cout << "BFI: start reinit\n";
+
+ // TODO: add more AP stuff
+ double elevator = FGBFI::getElevator();
+ double aileron = FGBFI::getAileron();
+ double rudder = FGBFI::getRudder();
+ double throttle = FGBFI::getThrottle();
+ double elevator_trim = FGBFI::getElevatorTrim();
+ double flaps = FGBFI::getFlaps();
+ double brake = FGBFI::getBrakes();
+ bool apHeadingLock = FGBFI::getAPHeadingLock();
+ double apHeadingMag = FGBFI::getAPHeadingMag();
+ bool apAltitudeLock = FGBFI::getAPAltitudeLock();
+ double apAltitude = FGBFI::getAPAltitude();
+ const string &targetAirport = FGBFI::getTargetAirport();
+ bool gpsLock = FGBFI::getGPSLock();
+ double gpsLatitude = FGBFI::getGPSTargetLatitude();
+ double gpsLongitude = FGBFI::getGPSTargetLongitude();
+
+ FGBFI::setTargetAirport("");
+ cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
+
+ fgReInitSubsystems();
+
+ // FIXME: this is wrong.
+ // All of these are scheduled events,
+ // and it should be possible to force
+ // them all to run once.
+ fgUpdateSunPos();
+ fgUpdateMoonPos();
+ cur_light_params.Update();
+ fgUpdateLocalTime();
+ fgUpdateWeatherDatabase();
+ fgRadioSearch();
+
+ // Restore all of the old states.
+ FGBFI::setElevator(elevator);
+ FGBFI::setAileron(aileron);
+ FGBFI::setRudder(rudder);
+ FGBFI::setThrottle(throttle);
+ FGBFI::setElevatorTrim(elevator_trim);
+ FGBFI::setFlaps(flaps);
+ FGBFI::setBrakes(brake);
+ FGBFI::setAPHeadingLock(apHeadingLock);
+ FGBFI::setAPHeadingMag(apHeadingMag);
+ FGBFI::setAPAltitudeLock(apAltitudeLock);
+ FGBFI::setAPAltitude(apAltitude);
+ FGBFI::setTargetAirport(targetAirport);
+ FGBFI::setGPSLock(gpsLock);
+
+ _needReinit = false;
+
+ cout << "BFI: end reinit\n";
+}
\f
// Simulation
current_properties.tieInt("/sim/flight-model",
getFlightModel, setFlightModel);
-// current_properties.tieString("/sim/aircraft",
-// getAircraft, setAircraft);
+ current_properties.tieString("/sim/aircraft",
+ getAircraft, setAircraft);
+ current_properties.tieString("/sim/aircraft-dir",
+ getAircraftDir, setAircraftDir);
// TODO: timeGMT
current_properties.tieString("/sim/time/gmt-string",
getGMTString, 0);
getHUDVisible, setHUDVisible);
current_properties.tieBool("/sim/panel/visibility",
getPanelVisible, setPanelVisible);
+ current_properties.tieInt("/sim/panel/x-offset",
+ getPanelXOffset, setPanelXOffset);
+ current_properties.tieInt("/sim/panel/y-offset",
+ getPanelYOffset, setPanelYOffset);
// Position
current_properties.tieString("/position/airport-id",
// Velocities
current_properties.tieDouble("/velocities/airspeed",
- getAirspeed, 0);
+ getAirspeed, setAirspeed);
current_properties.tieDouble("/velocities/side-slip",
getSideSlip, 0);
current_properties.tieDouble("/velocities/vertical-speed",
getVerticalSpeed, 0);
current_properties.tieDouble("/velocities/speed-north",
- getSpeedNorth, setSpeedNorth);
+ getSpeedNorth, 0);
current_properties.tieDouble("/velocities/speed-east",
- getSpeedEast, setSpeedEast);
+ getSpeedEast, 0);
current_properties.tieDouble("/velocities/speed-down",
- getSpeedDown, setSpeedDown);
+ getSpeedDown, 0);
// Controls
current_properties.tieDouble("/controls/throttle",
}
-/**
- * Reinitialize FGFS to use the new BFI settings.
- */
-void
-FGBFI::reinit ()
-{
- // Save the state of everything
- // that's going to get clobbered
- // when we reinit the subsystems.
-
- cout << "BFI: start reinit\n";
-
- // TODO: add more AP stuff
- double elevator = getElevator();
- double aileron = getAileron();
- double rudder = getRudder();
- double throttle = getThrottle();
- double elevator_trim = getElevatorTrim();
- double flaps = getFlaps();
- double brake = getBrakes();
- bool apHeadingLock = getAPHeadingLock();
- double apHeadingMag = getAPHeadingMag();
- bool apAltitudeLock = getAPAltitudeLock();
- double apAltitude = getAPAltitude();
- const string &targetAirport = getTargetAirport();
- bool gpsLock = getGPSLock();
- double gpsLatitude = getGPSTargetLatitude();
- double gpsLongitude = getGPSTargetLongitude();
-
- setTargetAirport("");
- cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
-
- fgReInitSubsystems();
-
- // FIXME: this is wrong.
- // All of these are scheduled events,
- // and it should be possible to force
- // them all to run once.
- fgUpdateSunPos();
- fgUpdateMoonPos();
- cur_light_params.Update();
- fgUpdateLocalTime();
- fgUpdateWeatherDatabase();
- fgRadioSearch();
-
- // Restore all of the old states.
- setElevator(elevator);
- setAileron(aileron);
- setRudder(rudder);
- setThrottle(throttle);
- setElevatorTrim(elevator_trim);
- setFlaps(flaps);
- setBrakes(brake);
- setAPHeadingLock(apHeadingLock);
- setAPHeadingMag(apHeadingMag);
- setAPAltitudeLock(apAltitudeLock);
- setAPAltitude(apAltitude);
- setTargetAirport(targetAirport);
- setGPSLock(gpsLock);
-
- _needReinit = false;
-
- cout << "BFI: end reinit\n";
-}
-
-
\f
////////////////////////////////////////////////////////////////////////
// Simulation.
/**
* Return the current aircraft as a string.
*/
-const string
+const string &
FGBFI::getAircraft ()
{
- return globals->get_options()->get_aircraft();
+ _temp = globals->get_options()->get_aircraft();
+ return _temp;
}
/**
* Return the current aircraft directory (UIUC) as a string.
*/
-const string
+const string &
FGBFI::getAircraftDir ()
{
- return aircraft_dir;
+ _temp = aircraft_dir;
+ return _temp;
}
}
+/**
+ * Get the panel's current x-shift.
+ */
+int
+FGBFI::getPanelXOffset ()
+{
+ if (current_panel != 0)
+ return current_panel->getXOffset();
+ else
+ return 0;
+}
+
+
+/**
+ * Set the panel's current x-shift.
+ */
+void
+FGBFI::setPanelXOffset (int offset)
+{
+ if (current_panel != 0)
+ current_panel->setXOffset(offset);
+}
+
+
+/**
+ * Get the panel's current y-shift.
+ */
+int
+FGBFI::getPanelYOffset ()
+{
+ if (current_panel != 0)
+ return current_panel->getYOffset();
+ else
+ return 0;
+}
+
+
+/**
+ * Set the panel's current y-shift.
+ */
+void
+FGBFI::setPanelYOffset (int offset)
+{
+ if (current_panel != 0)
+ current_panel->setYOffset(offset);
+}
+
+
+
+
\f
////////////////////////////////////////////////////////////////////////
// Position
void
FGBFI::setLatitude (double latitude)
{
- if (getLatitude() != latitude) {
- globals->get_options()->set_lat(latitude);
- current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
- needReinit();
- }
+ current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
}
void
FGBFI::setLongitude (double longitude)
{
- if (getLongitude() != longitude) {
- globals->get_options()->set_lon(longitude);
- current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
- needReinit();
- }
+ current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
}
void
FGBFI::setAltitude (double altitude)
{
- if (getAltitude() != altitude) {
- fgFDMForceAltitude(getFlightModel(), altitude);
- globals->get_options()->set_altitude(altitude);
- current_aircraft.fdm_state->set_Altitude(altitude);
- }
+ current_aircraft.fdm_state->set_Altitude(altitude);
}
void
FGBFI::setHeading (double heading)
{
- if (getHeading() != heading) {
- globals->get_options()->set_heading(heading);
- current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
- getPitch() * DEG_TO_RAD,
- heading * DEG_TO_RAD);
- needReinit();
- }
+ FGInterface * fdm = current_aircraft.fdm_state;
+ fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
+ heading * DEG_TO_RAD);
}
void
FGBFI::setPitch (double pitch)
{
- if (getPitch() != pitch) {
- globals->get_options()->set_pitch(pitch);
- current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
- pitch * DEG_TO_RAD,
- getHeading() * DEG_TO_RAD);
- needReinit();
- }
+ FGInterface * fdm = current_aircraft.fdm_state;
+ fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
}
void
FGBFI::setRoll (double roll)
{
- if (getRoll() != roll) {
- globals->get_options()->set_roll(roll);
- current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
- getPitch() * DEG_TO_RAD,
- getHeading() * DEG_TO_RAD);
- needReinit();
- }
+ FGInterface * fdm = current_aircraft.fdm_state;
+ fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
}
}
+/**
+ * Set the calibrated airspeed in knots.
+ */
+void
+FGBFI::setAirspeed (double speed)
+{
+ current_aircraft.fdm_state->set_V_calibrated_kts(speed);
+}
+
+
/**
* Return the current sideslip (FIXME: units unknown).
*/
}
-/**
- * Set the current north velocity (units??).
- */
-void
-FGBFI::setSpeedNorth (double speed)
-{
- if (getSpeedNorth() != speed) {
- current_aircraft.fdm_state->set_Velocities_Local(speed,
- getSpeedEast(),
- getSpeedDown());
- needReinit();
- }
-}
+// /**
+// * Set the current north velocity (units??).
+// */
+// void
+// FGBFI::setSpeedNorth (double speed)
+// {
+// FGInterface * fdm = current_aircraft.fdm_state;
+// // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
+// }
/**
}
-/**
- * Set the current east velocity (units??).
- */
-void
-FGBFI::setSpeedEast (double speed)
-{
- if (getSpeedEast() != speed) {
- current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
- speed,
- getSpeedDown());
- needReinit();
- }
-}
+// /**
+// * Set the current east velocity (units??).
+// */
+// void
+// FGBFI::setSpeedEast (double speed)
+// {
+// FGInterface * fdm = current_aircraft.fdm_state;
+// // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
+// }
/**
}
-/**
- * Set the current down velocity (units??).
- */
-void
-FGBFI::setSpeedDown (double speed)
-{
- if (getSpeedDown() != speed) {
- current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
- getSpeedEast(),
- speed);
- needReinit();
- }
-}
+// /**
+// * Set the current down velocity (units??).
+// */
+// void
+// FGBFI::setSpeedDown (double speed)
+// {
+// FGInterface * fdm = current_aircraft.fdm_state;
+// // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
+// }
\f
}
-/**
- * Check whether clouds are enabled.
- */
-bool
-FGBFI::getClouds ()
-{
- return globals->get_options()->get_clouds();
-}
-
-
-/**
- * Check the height of the clouds ASL (units?).
- */
-double
-FGBFI::getCloudsASL ()
-{
- return globals->get_options()->get_clouds_asl();
-}
-
-
/**
* Set the current visibility (units??).
*/
}
-/**
- * Switch clouds on or off.
- */
-void
-FGBFI::setClouds (bool clouds)
-{
- if (getClouds() != clouds) {
- cout << "Set clouds to " << clouds << endl;
- globals->get_options()->set_clouds(clouds);
- needReinit();
- }
-}
-
-
-/**
- * Set the cloud height.
- */
-void
-FGBFI::setCloudsASL (double cloudsASL)
-{
- if (getCloudsASL() != cloudsASL) {
- globals->get_options()->set_clouds_asl(cloudsASL);
- needReinit();
- }
-}
-
-
\f
////////////////////////////////////////////////////////////////////////
// Time
// Simulation
static int getFlightModel ();
- static const string getAircraft ();
- static const string getAircraftDir ();
- static time_t getTimeGMT ();
- static const string &getGMTString ();
- static bool getHUDVisible ();
- static bool getPanelVisible ();
-
static void setFlightModel (int flightModel);
+
+ static const string &getAircraft ();
static void setAircraft (const string &aircraft);
+
+ static const string &getAircraftDir ();
static void setAircraftDir (const string &aircraftDir);
+
+ static time_t getTimeGMT ();
static void setTimeGMT (time_t time);
+
+ static const string &getGMTString ();
+
+ static bool getHUDVisible ();
static void setHUDVisible (bool hudVisible);
+
+ static bool getPanelVisible ();
static void setPanelVisible (bool panelVisible);
+ static int getPanelXOffset ();
+ static void setPanelXOffset (int i);
+
+ static int getPanelYOffset ();
+ static void setPanelYOffset (int i);
+
// Position
static double getLatitude ();
- static double getLongitude ();
- static double getAltitude ();
- static double getAGL ();
-
static void setLatitude (double latitude);
+
+ static double getLongitude ();
static void setLongitude (double longitude);
+
+ static double getAltitude ();
static void setAltitude (double altitude);
+ static double getAGL ();
+
// Attitude
static double getHeading (); // true heading
+ static void setHeading (double heading);
+
static double getHeadingMag (); // exact magnetic heading
- static double getPitch ();
- static double getRoll ();
- static void setHeading (double heading);
+ static double getPitch ();
static void setPitch (double pitch);
+
+ static double getRoll ();
static void setRoll (double roll);
// Engine
static double getRPM ();
static void setRPM ( double rpm );
+
static double getEGT ();
static double getCHT ();
static double getMP ();
// Velocities
static double getAirspeed ();
+ static void setAirspeed (double speed);
+
static double getSideSlip ();
+
static double getVerticalSpeed ();
+
static double getSpeedNorth ();
+
static double getSpeedEast ();
+
static double getSpeedDown ();
- static void setSpeedNorth (double speed);
- static void setSpeedEast (double speed);
- static void setSpeedDown (double speed);
+// static void setSpeedNorth (double speed);
+// static void setSpeedEast (double speed);
+// static void setSpeedDown (double speed);
// Controls
static double getThrottle ();
- static double getMixture ();
- static double getPropAdvance ();
- static double getFlaps ();
- static double getAileron ();
- static double getRudder ();
- static double getElevator ();
- static double getElevatorTrim ();
- static double getBrakes ();
- static double getLeftBrake ();
- static double getRightBrake ();
- static double getCenterBrake ();
-
static void setThrottle (double throttle);
+
+ static double getMixture ();
static void setMixture (double mixture);
+
+ static double getPropAdvance ();
static void setPropAdvance (double pitch);
+
+ static double getFlaps ();
static void setFlaps (double flaps);
+
+ static double getAileron ();
static void setAileron (double aileron);
+
+ static double getRudder ();
static void setRudder (double rudder);
+
+ static double getElevator ();
static void setElevator (double elevator);
+
+ static double getElevatorTrim ();
static void setElevatorTrim (double trim);
+
+ static double getBrakes ();
static void setBrakes (double brake);
+
+ static double getLeftBrake ();
static void setLeftBrake (double brake);
+
+ static double getRightBrake ();
static void setRightBrake (double brake);
+
+ static double getCenterBrake ();
static void setCenterBrake (double brake);
// Autopilot
static bool getAPAltitudeLock ();
- static double getAPAltitude ();
- static bool getAPHeadingLock ();
- static double getAPHeading ();
- static double getAPHeadingMag ();
-
static void setAPAltitudeLock (bool lock);
+
+ static double getAPAltitude ();
static void setAPAltitude (double altitude);
+
+ static bool getAPHeadingLock ();
static void setAPHeadingLock (bool lock);
+
+ static double getAPHeading ();
static void setAPHeading (double heading);
+
+ static double getAPHeadingMag ();
static void setAPHeadingMag (double heading);
static bool getAPNAV1Lock ();
// Radio Navigation
static double getNAV1Freq ();
+ static void setNAV1Freq (double freq);
+
static double getNAV1AltFreq ();
+ static void setNAV1AltFreq (double freq);
+
static double getNAV1Radial ();
+
static double getNAV1SelRadial ();
+ static void setNAV1SelRadial (double radial);
+
static double getNAV1DistDME ();
+
static bool getNAV1TO ();
+
static bool getNAV1FROM ();
+
static bool getNAV1InRange ();
+
static bool getNAV1DMEInRange ();
static double getNAV2Freq ();
+ static void setNAV2Freq (double freq);
+
static double getNAV2AltFreq ();
+ static void setNAV2AltFreq (double freq);
+
static double getNAV2Radial ();
+
static double getNAV2SelRadial ();
+ static void setNAV2SelRadial (double radial);
+
static double getNAV2DistDME ();
+
static bool getNAV2TO ();
+
static bool getNAV2FROM ();
+
static bool getNAV2InRange ();
+
static bool getNAV2DMEInRange ();
static double getADFFreq ();
- static double getADFAltFreq ();
- static double getADFRotation ();
-
- static void setNAV1Freq (double freq);
- static void setNAV1AltFreq (double freq);
- static void setNAV1SelRadial (double radial);
-
- static void setNAV2Freq (double freq);
- static void setNAV2AltFreq (double freq);
- static void setNAV2SelRadial (double radial);
-
static void setADFFreq (double freq);
+
+ static double getADFAltFreq ();
static void setADFAltFreq (double freq);
+
+ static double getADFRotation ();
static void setADFRotation (double rot);
// GPS
static const string &getTargetAirport ();
+ static void setTargetAirport (const string &targetAirport);
+
static bool getGPSLock ();
+ static void setGPSLock (bool lock);
+
static double getGPSTargetLatitude ();
+
static double getGPSTargetLongitude ();
- static void setTargetAirport (const string &targetAirport);
- static void setGPSLock (bool lock);
// Weather
static double getVisibility ();
- static bool getClouds ();
- static double getCloudsASL ();
-
static void setVisibility (double visiblity);
- static void setClouds (bool clouds);
- static void setCloudsASL (double cloudsASL);
// Time (this varies with time) huh, huh
// Will cause a linking error if invoked.
FGBFI ();
- static void reinit ();
- static void needReinit () { _needReinit = true; }
- static bool _needReinit;
};
// end of bfi.hxx