chore(cpn): move global variables from flight/drive modes tab to own tab (#6624)
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
#include "flightmodedata.h"
|
||||
#include "radiodata.h"
|
||||
#include "radiodataconversionstate.h"
|
||||
#include "compounditemmodels.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
void FlightModeData::convert(RadioDataConversionState & cstate)
|
||||
{
|
||||
@@ -33,35 +35,44 @@ void FlightModeData::convert(RadioDataConversionState & cstate)
|
||||
void FlightModeData::clear(const int phaseIdx)
|
||||
{
|
||||
memset(reinterpret_cast<void *>(this), 0, sizeof(FlightModeData));
|
||||
|
||||
for (int i = 0; i < CPN_MAX_GVARS; i++) {
|
||||
gvars[i] = linkedGVarFlightModeZero(phaseIdx);
|
||||
}
|
||||
for (int i = 0; i < CPN_MAX_ENCODERS; i++) {
|
||||
rotaryEncoders[i] = linkedREncFlightModeZero(phaseIdx);
|
||||
}
|
||||
}
|
||||
|
||||
QString FlightModeData::nameToString(int phaseIdx) const
|
||||
{
|
||||
return RadioData::getElementName(Boards::isAir() ? tr("FM") : tr("DM"), phaseIdx, name); // names are zero-based, FM0, FM1, etc
|
||||
return RadioData::getElementName(tr("%1M").arg(modeAbbrev()), phaseIdx, name); // names are zero-based, FM0, FM1, etc
|
||||
}
|
||||
|
||||
// static
|
||||
QString FlightModeData::modeAbbrev()
|
||||
{
|
||||
return Boards::isAir() ? tr("F") : tr("D");
|
||||
}
|
||||
|
||||
// static
|
||||
QString FlightModeData::modeName()
|
||||
{
|
||||
return Boards::isAir() ? tr("Flight") : tr("Drive");
|
||||
}
|
||||
|
||||
bool FlightModeData::isEmpty(int phaseIdx) const
|
||||
{
|
||||
if (name[0] != '\0' || swtch.isSet() || fadeIn != 0 || fadeOut != 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < CPN_MAX_TRIMS; i++) {
|
||||
if (trim[i] != 0 || trimRef[i] != 0 || trimMode[i] != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_GVARS; i++) {
|
||||
if (!isGVarEmpty(phaseIdx, i))
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < CPN_MAX_ENCODERS; i++) {
|
||||
if (!isREncEmpty(phaseIdx, i))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,13 +80,7 @@ bool FlightModeData::isGVarEmpty(int phaseIdx, int gvIdx) const
|
||||
{
|
||||
if ((phaseIdx == 0 && gvars[gvIdx] == 0) || (phaseIdx != 0 && gvars[gvIdx] == linkedGVarFlightModeZero(phaseIdx)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FlightModeData::isREncEmpty(int phaseIdx, int reIdx) const
|
||||
{
|
||||
if ((phaseIdx == 0 && rotaryEncoders[reIdx] == 0) || (phaseIdx != 0 && rotaryEncoders[reIdx] == linkedREncFlightModeZero(phaseIdx)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -83,6 +88,7 @@ int FlightModeData::linkedFlightModeZero(int phaseIdx, int maxOwnValue) const
|
||||
{
|
||||
if (phaseIdx == 0)
|
||||
return 0;
|
||||
|
||||
return maxOwnValue + 1;
|
||||
}
|
||||
|
||||
@@ -91,7 +97,19 @@ int FlightModeData::linkedGVarFlightModeZero(int phaseIdx) const
|
||||
return linkedFlightModeZero(phaseIdx, GVAR_MAX_VALUE);
|
||||
}
|
||||
|
||||
int FlightModeData::linkedREncFlightModeZero(int phaseIdx) const
|
||||
// static
|
||||
AbstractStaticItemModel * FlightModeData::gvarModesItemModel(int excludeMode)
|
||||
{
|
||||
return linkedFlightModeZero(phaseIdx, RENC_MAX_VALUE);
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_FLIGHTMODEDATA_GVARFM);
|
||||
int modes = getCurrentFirmware()->getCapability(FlightModes);
|
||||
|
||||
for (int i = 0; i < modes; i++) {
|
||||
if (i != excludeMode)
|
||||
mdl->appendToItemList(tr("%1M%2").arg(modeAbbrev()).arg(i),
|
||||
GVAR_MAX_VALUE + 1 + i - (i > excludeMode ? 1 : 0));
|
||||
}
|
||||
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user