fix(cpn): logical switch global variable compare range (#7007)

This commit is contained in:
Neil Horne
2026-01-25 13:12:37 +10:00
committed by GitHub
parent 87b2788884
commit 3573a804da
4 changed files with 154 additions and 100 deletions
+54 -11
View File
@@ -34,13 +34,40 @@
float RawSourceRange::getValue(int value)
{
return float(value) * step;
return float(value) * step; // TODO + offset ??
}
double RawSourceRange::toDisplay(int value)
{
return (double(value) * step) + offset;
}
int RawSourceRange::toRaw(double value)
{
return round((value - offset) / step);
}
double RawSourceRange::validateDisplay(double value)
{
if (value < min || value > max)
value = (value < min) ? min : max;
return value;
}
int RawSourceRange::validateRaw(int val)
{
double value = toDisplay(val);
if (value < min || value > max)
value = (value < min) ? min : max;
return toRaw(value);
}
/*
* RawSource
*/
*/
RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSettings & settings, unsigned int flags) const
{
@@ -80,25 +107,45 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
GVarData gv = model->gvarData[index - 1];
result.step = gv.multiplierGet();
result.decimals = gv.prec;
result.max = gv.getMaxPrec();
result.min = gv.getMinPrec();
result.unit = gv.unitToString();
result.min = 0;
result.max= 0;
if (flags & RANGE_DELTA_FUNCTION) {
result.min = gv.getMinPrec() - gv.getMaxPrec();
result.max = gv.getMaxPrec() - gv.getMinPrec();
} else {
result.min = gv.getMinPrec();
result.max = gv.getMaxPrec();
}
if (flags & RANGE_ABS_FUNCTION) {
result.min = (flags & RANGE_DELTA_FUNCTION) ? 0 : abs(result.min);
result.max = abs(result.max);
}
if (result.min > result.max) {
double tmp = result.min;
result.min = result.max;
result.max = tmp;
}
break;
}
case SOURCE_TYPE_SPECIAL:
if (abs(index) == 1) { // Batt
if (abs(index) == SOURCE_TYPE_SPECIAL_TX_BATT) {
result.step = 0.1;
result.decimals = 1;
result.max = 25.5;
result.unit = tr("V");
}
else if (abs(index) == 2) { // Time
else if (abs(index) == SOURCE_TYPE_SPECIAL_TX_TIME) {
result.step = 60;
result.max = 24 * 60 * result.step - 60; // 23:59:00 with 1-minute resolution
result.unit = tr("s");
}
else if (abs(index) == 3) { // GPS
else if (abs(index) == SOURCE_TYPE_SPECIAL_TX_GPS) {
result.max = 30000;
result.min = -result.max;
}
@@ -122,10 +169,6 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
break;
}
if (flags & RANGE_ABS_FUNCTION) {
result.min = 0;
}
return result;
}