// ---------------------------------------------------------------------------- // updateData() - update background data // ---------------------------------------------------------------------------- void MapDisplay::updateData(const LCreal dt) { BaseClass::updateData(dt); // get pointer to MapPage data int cmdRange = 0; MapPage* page = static_cast<MapPage*>(subpage()); if (page != 0) { cmdRange = static_cast<int>(page->getRange()); } double cmdAirspeed = 0, cmdAltitude = 0, cmdHeading = 0; bool apButtonsVis = false; // pilot max double maxAccel = 0, maxTurn = 0, maxBank = 0, maxClimb = 0; // default to autopilot mode off int apMode = 1; Simulation::Aircraft* pA = static_cast<Simulation::Aircraft*>(getOwnship()); if (pA != 0) { Simulation::Autopilot* ap = static_cast<Simulation::Autopilot*>(pA->getPilot()); if (ap != 0) { // button visibility is based on autopilot being in NO modes apButtonsVis = (ap->isNavModeOn() || ap->isLoiterModeOn() || ap->isFollowTheLeadModeOn()); cmdAirspeed = ap->getCommandedVelocityKts(); cmdAltitude = ap->getCommandedAltitudeFt(); cmdHeading = ap->getCommandedHeadingD(); if (ap->isNavModeOn()) apMode = 2; else if (ap->isLoiterModeOn()) apMode = 3; else if (ap->isFollowTheLeadModeOn()) apMode = 4; maxAccel = ap->getMaxVelAcc(); maxTurn = ap->getMaxTurnRate(); maxBank = ap->getMaxBankAngle(); maxClimb = ap->getMaxClimbRate(); } } // get pointer to LaeroModel data send("cmdRange", UPDATE_VALUE, cmdRange, cmdRangeSD); send("cmdAirspeed", UPDATE_VALUE, cmdAirspeed, cmdAirspeedSD); send("cmdAltitude", UPDATE_VALUE, cmdAltitude, cmdAltitudeSD); send("cmdHeading", UPDATE_VALUE, cmdHeading, cmdHeadingSD); // Autopilot mode send("apMode", SELECT, apMode, apModeSD); // button visibility send("apReqButtons", SET_VISIBILITY, !apButtonsVis, apReqButtonVisSD); // maximums send("cmdAccel", UPDATE_VALUE, maxAccel, maxAccelSD); send("cmdClimb", UPDATE_VALUE, maxClimb, maxClimbSD); send("cmdRot", UPDATE_VALUE, maxTurn, maxTurnSD); send("cmdBank", UPDATE_VALUE, maxBank, maxBankSD); }
//------------------------------------------------------------------------------ // Handle input devices //------------------------------------------------------------------------------ void IoHandler::inputDevices(const LCreal dt) { BaseClass::inputDevices(dt); // --- // get the Input data buffer // --- const Basic::IoData* const inData = getInputData(); // --- // get the Station, Simulation and our ownship player // --- SimStation* const sta = static_cast<SimStation*>( findContainerByType(typeid(SimStation)) ); Simulation::Simulation* sim = 0; Simulation::AirVehicle* av = 0; if (sta != 0) { sim = sta->getSimulation(); av = dynamic_cast<Simulation::AirVehicle*>(sta->getOwnship()); } // --- // If we have everything we need .... // --- if (av != 0 && sim != 0 && inData != 0) { // find the (optional) autopilot Simulation::Autopilot* ap = 0; { Basic::Pair* p = av->getPilotByType( typeid( Simulation::Autopilot) ); if (p != 0) ap = static_cast<Simulation::Autopilot*>( p->object() ); } // ------------------------------------------------------------ // Simulation Control Inputs // ------------------------------------------------------------ { bool enabled = false; inData->getDiscreteInput(CTL_ENABLE_SW, &enabled); { // Toggle simulation freeze bool sw = false; inData->getDiscreteInput(FREEZE_SW, &sw); bool frzSw = sw && enabled; if (frzSw && !frzSw1) { Basic::Boolean newFrz( !sim->isFrozen() ); sim->event(FREEZE_EVENT, &newFrz); } frzSw1 = frzSw; } { // Send a reset pulse to the station bool sw = false; inData->getDiscreteInput(RESET_SW, &sw); bool rstSw = sw && enabled; if (rstSw && !rstSw1) { sta->event(RESET_EVENT); } rstSw1 = rstSw; } { // Send a weapons reload pulse to the station bool sw = false; inData->getDiscreteInput(RELOAD_SW, &sw); bool wpnReloadSw = sw && enabled; if (wpnReloadSw && !wpnReloadSw1) { sta->event(WPN_RELOAD); } wpnReloadSw1 = wpnReloadSw; } } // ------------------------------------------------------------ // Flight Control Inputs // ------------------------------------------------------------ { // Process Roll Input LCreal ai = 0; inData->getAnalogInput(ROLL_AI, &ai); LCreal aiLim = alim(ai, 1.0f); if (ap != 0) ap->setControlStickRollInput(aiLim); else av->setControlStickRollInput(aiLim); } { // Process Pitch Input LCreal ai = 0; inData->getAnalogInput(PITCH_AI, &ai); LCreal aiLim = alim(ai, 1.0f); if (ap != 0) ap->setControlStickPitchInput(aiLim); else av->setControlStickPitchInput(aiLim); } { // Process Rudder Input LCreal ai = 0; inData->getAnalogInput(RUDDER_AI, &ai); LCreal aiLim = alim(ai, 1.0f); av->setRudderPedalInput(aiLim); } { // Process Throttle Input LCreal value = 0; inData->getAnalogInput(THROTTLE_AI, &value); if (value < 0.0f) value = 0.0f; else if (value > 2.0f) value = 2.0f; if (ap != 0) ap->setThrottles(&value,1); else av->setThrottles(&value,1); } { // Weapons Release bool sw = false; inData->getDiscreteInput(PICKLE_SW, &sw); if (sw != wpnRelSw1) { Basic::Boolean sw(sw); av->event(WPN_REL_EVENT, &sw); } wpnRelSw1 = sw; } { // Trigger switch bool sw = false; inData->getDiscreteInput(TRIGGER_SW2, &sw); if (sw != trgSw1) { Basic::Boolean sw(sw); av->event(TRIGGER_SW_EVENT, &sw); } trgSw1 = sw; } { // Target Step (reject) bool sw = false; inData->getDiscreteInput(TMS_RIGHT_SW, &sw); if (sw && !tgtStepSw1) { av->event(TGT_STEP_EVENT); } tgtStepSw1 = sw; } { // Target Designate bool sw = false; inData->getDiscreteInput(TMS_UP_SW, &sw); if (sw && !tgtDesSw1) { av->event(TGT_DESIGNATE); } tgtDesSw1 = sw; } { // Return-To-Search bool sw = false; inData->getDiscreteInput(TMS_DOWN_SW, &sw); if (sw && !rtn2SrchSw1) { av->event(SENSOR_RTS); } rtn2SrchSw1 = sw; } { // Autopilot disengage bool autopilotSw = false; inData->getDiscreteInput(PADDLE_SW, &autopilotSw); if (autopilotSw && !autopilotSw1) { Simulation::Autopilot* ap = dynamic_cast<Simulation::Autopilot*>(av->getPilot()); if (ap != 0) { ap->setHeadingHoldMode(false); ap->setAltitudeHoldMode(false); ap->setVelocityHoldMode(false); ap->setLoiterMode(false); ap->setNavMode(false); } } autopilotSw1 = autopilotSw; } { // Speedbrake switch bool sbExtSw = false; bool sbRetSw = false; inData->getDiscreteInput(SB_EXT_SW, &sbExtSw); inData->getDiscreteInput(SB_RET_SW, &sbRetSw); LCreal sb = 0.0; if(sbExtSw) sb = -1.0f; if(sbRetSw) sb = 1.0f; av->setSpeedBrakesSwitch(sb); } { // Steerpoint increment bool incStptSw = false; inData->getDiscreteInput(DMS_UP_SW, &incStptSw); if(incStptSw && !incStptSw1) { // find our route and increment the steerpoint Simulation::Navigation* myNav = av->getNavigation(); if (myNav != 0) { myNav->ref(); Simulation::Route* myRoute = myNav->getPriRoute(); if (myRoute != 0) { myRoute->ref(); myRoute->incStpt(); myRoute->unref(); } } } incStptSw1 = incStptSw; } { // Steerpoint decrement bool decStptSw = false; inData->getDiscreteInput(DMS_DOWN_SW, &decStptSw); if (decStptSw && !decStptSw1) { // find our route and increment the steerpoint Simulation::Navigation* myNav = av->getNavigation(); if (myNav != 0) { myNav->ref(); Simulation::Route* myRoute = myNav->getPriRoute(); if (myRoute != 0) { myRoute->ref(); myRoute->decStpt(); myRoute->unref(); } } } decStptSw1 = decStptSw; } } }
// ---------------------------------------------------------------------------- // buttonEvent() - called when a button is pressed // ---------------------------------------------------------------------------- void MapDisplay::buttonEvent(const int b) { // cmdRange up, down MapPage* page = static_cast<MapPage*>(subpage()); // cmdAirspeed, cmdAltitude, cmdHeading up, down Simulation::Player* pA = getOwnship(); Simulation::Autopilot* ap = 0; if (pA != 0) { ap = static_cast<Simulation::Autopilot*>(pA->getPilot()); } if (page != 0 && ap != 0) { if (b == DEC_RANGE) { if (page->getRange() > 5) { page->setRange(page->getRange() - 5); } } else if (b == INC_RANGE) { if (page->getRange() < 320) { page->setRange(page->getRange() + 5); } } else if (b == DEC_CMD_AS) { double cmdAirspeed = ap->getCommandedVelocityKts(); if (cmdAirspeed > 100) { cmdAirspeed -= 10; ap->setCommandedVelocityKts(cmdAirspeed); } } else if (b == INC_CMD_AS) { double cmdAirspeed = ap->getCommandedVelocityKts(); if (cmdAirspeed < 400) { cmdAirspeed += 10; ap->setCommandedVelocityKts(cmdAirspeed); } } else if (b == DEC_CMD_ALT) { double cmdAltitude = ap->getCommandedAltitudeFt(); if (cmdAltitude > 1000) { cmdAltitude -= 500; ap->setCommandedAltitudeFt(cmdAltitude); } } else if (b == INC_CMD_ALT) { double cmdAltitude = ap->getCommandedAltitudeFt(); if (cmdAltitude < 40000) { cmdAltitude += 500; ap->setCommandedAltitudeFt(cmdAltitude); } } else if (b == DEC_CMD_HDG) { double cmdHeading = ap->getCommandedHeadingD(); cmdHeading -= 10; if (cmdHeading < -180.0) cmdHeading += 360; ap->setCommandedHeadingD(cmdHeading); } else if (b == INC_CMD_HDG) { double cmdHeading = ap->getCommandedHeadingD(); cmdHeading += 10; if (cmdHeading > 180.0) cmdHeading -= 360; ap->setCommandedHeadingD(cmdHeading); } else if (b == INC_CMD_AS_NPS) { double maxAccel = ap->getMaxVelAcc(); if (maxAccel < 20) maxAccel++; ap->setMaxVelAccNps(maxAccel); } else if (b == DEC_CMD_AS_NPS) { double maxAccel = ap->getMaxVelAcc(); if (maxAccel > 1) maxAccel--; ap->setMaxVelAccNps(maxAccel); } // Climb rate in meters per second else if (b == INC_CMD_ALT_MPS) { double maxClimb = ap->getMaxClimbRate(); if (maxClimb < 100) maxClimb += 5; ap->setMaxClimbRateMps(maxClimb); } else if (b == DEC_CMD_ALT_MPS) { double maxClimb = ap->getMaxClimbRate(); if (maxClimb > 5) maxClimb -= 5; ap->setMaxClimbRateMps(maxClimb); } // Turn rate in degrees per second else if (b == INC_CMD_HDG_ROT) { double maxTR = ap->getMaxTurnRate(); if (maxTR < 25) maxTR++; ap->setMaxTurnRateDps(maxTR); } else if (b == DEC_CMD_HDG_ROT) { double maxTR = ap->getMaxTurnRate(); if (maxTR > 0) maxTR--; ap->setMaxTurnRateDps(maxTR); } // Max bank (degrees) else if (b == INC_CMD_HDG_BNK) { double maxBank = ap->getMaxBankAngle(); if (maxBank < 90) maxBank++; ap->setMaxBankAngleDeg(maxBank); } else if (b == DEC_CMD_HDG_BNK) { double maxBank = ap->getMaxBankAngle(); if (maxBank > 0) maxBank--; ap->setMaxBankAngleDeg(maxBank); } else if (b == PASSIVE_ENABLE) { passiveEnable = true; } else if (b == PASSIVE_DISABLE) { passiveEnable = false; } // get our autopilot mode and change it else if (b == CHANGE_AP_MODE) { // if off, go to nav bool navMode = ap->isNavModeOn(); bool loiterMode = ap->isLoiterModeOn(); bool flMode = ap->isFollowTheLeadModeOn(); // if in nav mode, go to loiter mode if (navMode) { ap->setNavMode(false); ap->setLoiterMode(true); } // if in loiter mode, go to follow the lead mode else if (loiterMode) { ap->setLoiterMode(false); ap->setFollowTheLeadMode(true); } // if in follow the lead mode, turn off all modes else if (flMode) { ap->setFollowTheLeadMode(false); } // all modes off, go back to nav else ap->setNavMode(true); } } }