fix(cpn): Only timers with active modes should be included in lists (#3956)
* disable timers with mode OFF * fix isModeOff to reference mode not switch * update model edit source lists when timer mode changed * add timer mode test to reset function * add timer mode test for Set and Reset functions * change yaml special source TIMERx to Tmrx
This commit is contained in:
@@ -240,7 +240,7 @@ QString CustomFunctionData::enabledToString() const
|
||||
}
|
||||
|
||||
// static
|
||||
bool CustomFunctionData::isFuncAvailable(const int index)
|
||||
bool CustomFunctionData::isFuncAvailable(const int index, const ModelData * model)
|
||||
{
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
@@ -250,7 +250,8 @@ bool CustomFunctionData::isFuncAvailable(const int index)
|
||||
((index == FuncPlayHaptic) && !fw->getCapability(Haptic)) ||
|
||||
((index == FuncPlayBoth) && !fw->getCapability(HasBeeper)) ||
|
||||
((index == FuncLogs) && !fw->getCapability(HasSDLogs)) ||
|
||||
((index >= FuncSetTimer1 && index <= FuncSetTimerLast) && index > FuncSetTimer1 + fw->getCapability(Timers)) ||
|
||||
((index >= FuncSetTimer1 && index <= FuncSetTimerLast) &&
|
||||
(index > FuncSetTimer1 + fw->getCapability(Timers) || model->timers[index - FuncSetTimer1].isModeOff())) ||
|
||||
((index == FuncScreenshot) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
|
||||
((index >= FuncRangeCheckInternalModule && index <= FuncBindExternalModule) && !fw->getCapability(DangerousFunctions)) ||
|
||||
((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars)) ||
|
||||
@@ -312,7 +313,7 @@ bool CustomFunctionData::isResetParamAvailable(const int index, const ModelData
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
|
||||
if (index < CPN_MAX_TIMERS) {
|
||||
if (index < firmware->getCapability(Timers))
|
||||
if (index < firmware->getCapability(Timers) && !model->timers[index].isModeOff())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
@@ -122,7 +122,7 @@ class CustomFunctionData {
|
||||
|
||||
static QString nameToString(const int index, const bool globalContext = false);
|
||||
static QString funcToString(const AssignFunc func, const ModelData * model = nullptr);
|
||||
static bool isFuncAvailable(const int index);
|
||||
static bool isFuncAvailable(const int index, const ModelData * model = nullptr);
|
||||
static int funcContext(const int index);
|
||||
static QString resetToString(const int value, const ModelData * model = nullptr);
|
||||
static int resetParamCount();
|
||||
|
||||
@@ -278,7 +278,23 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
|
||||
rhs.index = cyc_idx;
|
||||
}
|
||||
|
||||
int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(src_str.c_str());
|
||||
std::string special_str;
|
||||
node >> special_str;
|
||||
|
||||
// 2.10 conversion of TIMERx to Tmrx
|
||||
if (special_str.size() == 6) {
|
||||
if (special_str.substr(0, 6) == "TIMER1") {
|
||||
special_str = "Tmr1";
|
||||
}
|
||||
else if (special_str.substr(0, 6) == "TIMER2") {
|
||||
special_str = "Tmr2";
|
||||
}
|
||||
else if (special_str.substr(0, 6) == "TIMER3") {
|
||||
special_str = "Tmr3";
|
||||
}
|
||||
}
|
||||
|
||||
int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(special_str.c_str());
|
||||
if (sp_idx >= 0) {
|
||||
rhs.type = SOURCE_TYPE_SPECIAL;
|
||||
rhs.index = sp_idx;
|
||||
|
||||
@@ -323,8 +323,13 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings
|
||||
if (!model || index >= b.getCapability(Board::FunctionSwitches))
|
||||
return false;
|
||||
|
||||
if (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED && index <= SOURCE_TYPE_SPECIAL_LAST_RESERVED)
|
||||
return false;
|
||||
if (type == SOURCE_TYPE_SPECIAL) {
|
||||
if (index >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED && index <= SOURCE_TYPE_SPECIAL_LAST_RESERVED)
|
||||
return false;
|
||||
else if (index >= SOURCE_TYPE_SPECIAL_FIRST_TIMER && index <= SOURCE_TYPE_SPECIAL_LAST_TIMER &&
|
||||
model->timers[index - SOURCE_TYPE_SPECIAL_FIRST_TIMER].isModeOff())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (model) {
|
||||
if (type == SOURCE_TYPE_FUNCTIONSWITCH && !model->isFunctionSwitchSourceAllowed(index))
|
||||
@@ -458,9 +463,9 @@ tbl.insert(tbl.end(), {
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED2), "RESERVED2"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED3), "RESERVED3"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED4), "RESERVED4"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER1), "TIMER1"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER2), "TIMER2"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER3), "TIMER3"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER1), "Tmr1"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER2), "Tmr2"},
|
||||
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER3), "Tmr3"},
|
||||
});
|
||||
|
||||
return tbl;
|
||||
|
||||
@@ -43,9 +43,9 @@ bool TimerData::isEmpty() const
|
||||
persistent == 0 /*&& pvalue == 0*/);
|
||||
}
|
||||
|
||||
bool TimerData::isModeOff()
|
||||
bool TimerData::isModeOff() const
|
||||
{
|
||||
return swtch == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0);
|
||||
return mode == TIMERMODE_OFF;
|
||||
}
|
||||
|
||||
QString TimerData::nameToString(int index) const
|
||||
|
||||
@@ -100,7 +100,7 @@ class TimerData {
|
||||
void convert(RadioDataConversionState& cstate);
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
bool isModeOff();
|
||||
bool isModeOff() const;
|
||||
QString nameToString(int index) const;
|
||||
QString countdownBeepToString() const;
|
||||
QString countdownStartToString() const;
|
||||
|
||||
Reference in New Issue
Block a user