//------------------------------------------------------------------------------ // updateData() - updates the values //------------------------------------------------------------------------------ void MapPage::updateData(const LCreal dt) { // find our nearest map page above us and get the data from it! MapPage* page = static_cast<MapPage*>(findContainerByType(typeid(MapPage))); if (page != nullptr) { setHeadingDeg(page->getHeadingDeg()); setDisplacement(page->getDisplacement()); setReferenceLatDeg(page->getReferenceLatDeg()); setReferenceLonDeg(page->getReferenceLonDeg()); setOuterRadius(page->getOuterRadius()); setOuterRadiusDC(page->getOuterRadiusDC()); setCentered(page->getCentered()); setRange(page->getRange()); setNorthUp(page->getNorthUp()); nm2Screen = page->getScale(); } // if we are the top map page, we do the calculations ourself else { // determine if we are centered or not, and set our displacement and radius accordingly if (isCentered) nm2Screen = outerRadius / range; else nm2Screen = outerRadiusDC / range; } // update base class stuff BaseClass::updateData(dt); }
// ---------------------------------------------------------------------------- // 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); }
// ---------------------------------------------------------------------------- // 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); } } }