mirror of
https://github.com/opentx/opentx.git
synced 2025-07-16 21:05:26 +03:00
Logical Switches range bugfixes (both Companion and Firmware)
This commit is contained in:
parent
13fd1f04c0
commit
405391033d
5 changed files with 56 additions and 54 deletions
|
@ -92,12 +92,13 @@ QString getGVarString(int16_t val, bool sign)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RawSourceRange RawSource::getRange(const ModelData & model, const GeneralSettings & settings, bool singleprec)
|
RawSourceRange RawSource::getRange(const ModelData & model, const GeneralSettings & settings, unsigned int flags)
|
||||||
{
|
{
|
||||||
RawSourceRange result;
|
RawSourceRange result;
|
||||||
|
|
||||||
FirmwareInterface * firmware = GetCurrentFirmware();
|
FirmwareInterface * firmware = GetCurrentFirmware();
|
||||||
int board = firmware->getBoard();
|
int board = firmware->getBoard();
|
||||||
|
bool singleprec = (flags & RANGE_SINGLE_PRECISION);
|
||||||
|
|
||||||
if (!singleprec && !IS_ARM(board)) {
|
if (!singleprec && !IS_ARM(board)) {
|
||||||
singleprec = true;
|
singleprec = true;
|
||||||
|
@ -266,6 +267,17 @@ RawSourceRange RawSource::getRange(const ModelData & model, const GeneralSetting
|
||||||
if (singleprec && result.offset==-DBL_MAX) {
|
if (singleprec && result.offset==-DBL_MAX) {
|
||||||
result.offset = result.max - (127*result.step);
|
result.offset = result.max - (127*result.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & (RANGE_DELTA_FUNCTION|RANGE_DELTA_ABS_FUNCTION)) {
|
||||||
|
if (singleprec) {
|
||||||
|
result.offset = 0;
|
||||||
|
result.min = result.step * -127;
|
||||||
|
result.max = result.step * 127;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.min = -result.max;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -274,6 +286,10 @@ RawSourceRange RawSource::getRange(const ModelData & model, const GeneralSetting
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & RANGE_DELTA_ABS_FUNCTION) {
|
||||||
|
result.min = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,9 +513,14 @@ CSFunctionFamily LogicalSwitchData::getFunctionFamily()
|
||||||
return LS_FAMILY_VCOMP;
|
return LS_FAMILY_VCOMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogicalSwitchData::isDeltaFunction()
|
unsigned int LogicalSwitchData::getRangeFlags()
|
||||||
{
|
{
|
||||||
return (func == LS_FN_DPOS || func == LS_FN_DAPOS);
|
if (func == LS_FN_DPOS)
|
||||||
|
return RANGE_DELTA_FUNCTION;
|
||||||
|
else if (func == LS_FN_DAPOS)
|
||||||
|
return RANGE_DELTA_ABS_FUNCTION;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LogicalSwitchData::funcToString()
|
QString LogicalSwitchData::funcToString()
|
||||||
|
@ -588,7 +609,7 @@ QString LogicalSwitchData::toString(const ModelData & model, const GeneralSettin
|
||||||
else if (func == LS_FN_DPOS) result = "d(" + res + ")";
|
else if (func == LS_FN_DPOS) result = "d(" + res + ")";
|
||||||
result += res;
|
result += res;
|
||||||
|
|
||||||
if (func == LS_FN_APOS || func == LS_FN_VPOS || isDeltaFunction())
|
if (func == LS_FN_APOS || func == LS_FN_VPOS || func == LS_FN_DPOS || func == LS_FN_DAPOS)
|
||||||
result += " > ";
|
result += " > ";
|
||||||
else if (func == LS_FN_ANEG || func == LS_FN_VNEG)
|
else if (func == LS_FN_ANEG || func == LS_FN_VNEG)
|
||||||
result += " < ";
|
result += " < ";
|
||||||
|
|
|
@ -330,6 +330,10 @@ class RawSourceRange
|
||||||
QString unit;
|
QString unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define RANGE_SINGLE_PRECISION 1
|
||||||
|
#define RANGE_DELTA_FUNCTION 2
|
||||||
|
#define RANGE_DELTA_ABS_FUNCTION 4
|
||||||
|
|
||||||
class GeneralSettings;
|
class GeneralSettings;
|
||||||
class RawSource {
|
class RawSource {
|
||||||
public:
|
public:
|
||||||
|
@ -358,7 +362,7 @@ class RawSource {
|
||||||
|
|
||||||
QString toString(const ModelData & model);
|
QString toString(const ModelData & model);
|
||||||
|
|
||||||
RawSourceRange getRange(const ModelData & model, const GeneralSettings & settings, bool singleprec=false);
|
RawSourceRange getRange(const ModelData & model, const GeneralSettings & settings, unsigned int flags=0);
|
||||||
|
|
||||||
bool operator == ( const RawSource & other) {
|
bool operator == ( const RawSource & other) {
|
||||||
return (this->type == other.type) && (this->index == other.index);
|
return (this->type == other.type) && (this->index == other.index);
|
||||||
|
@ -712,7 +716,7 @@ class LogicalSwitchData { // Logical Switches data
|
||||||
int andsw;
|
int andsw;
|
||||||
void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
|
void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
|
||||||
CSFunctionFamily getFunctionFamily();
|
CSFunctionFamily getFunctionFamily();
|
||||||
bool isDeltaFunction();
|
unsigned int getRangeFlags();
|
||||||
QString funcToString();
|
QString funcToString();
|
||||||
QString toString(const ModelData & model, const GeneralSettings & settings);
|
QString toString(const ModelData & model, const GeneralSettings & settings);
|
||||||
};
|
};
|
||||||
|
|
|
@ -139,13 +139,8 @@ void LogicalSwitchesPanel::v1Edited(int value)
|
||||||
model.customSw[i].val1 = cswitchSource1[i]->itemData(value).toInt();
|
model.customSw[i].val1 = cswitchSource1[i]->itemData(value).toInt();
|
||||||
if (model.customSw[i].getFunctionFamily() == LS_FAMILY_VOFS) {
|
if (model.customSw[i].getFunctionFamily() == LS_FAMILY_VOFS) {
|
||||||
RawSource source = RawSource(model.customSw[i].val1);
|
RawSource source = RawSource(model.customSw[i].val1);
|
||||||
RawSourceRange range = source.getRange(model, generalSettings);
|
RawSourceRange range = source.getRange(model, generalSettings, model.customSw[i].getRangeFlags());
|
||||||
if (model.customSw[i].isDeltaFunction()) {
|
model.customSw[i].val2 = (cswitchOffset[i]->value() - range.offset) / range.step;
|
||||||
model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
model.customSw[i].val2 = (cswitchOffset[i]->value() - range.offset) / range.step;
|
|
||||||
}
|
|
||||||
setSwitchWidgetVisibility(i);
|
setSwitchWidgetVisibility(i);
|
||||||
}
|
}
|
||||||
emit modified();
|
emit modified();
|
||||||
|
@ -191,7 +186,6 @@ void LogicalSwitchesPanel::edited()
|
||||||
int i = sender()->property("index").toInt();
|
int i = sender()->property("index").toInt();
|
||||||
int newFunc = csw[i]->itemData(csw[i]->currentIndex()).toInt();
|
int newFunc = csw[i]->itemData(csw[i]->currentIndex()).toInt();
|
||||||
bool chAr = (model.customSw[i].getFunctionFamily() != LogicalSwitchData(newFunc).getFunctionFamily());
|
bool chAr = (model.customSw[i].getFunctionFamily() != LogicalSwitchData(newFunc).getFunctionFamily());
|
||||||
bool chDelta = (model.customSw[i].isDeltaFunction() ^ LogicalSwitchData(newFunc).isDeltaFunction());
|
|
||||||
model.customSw[i].func = newFunc;
|
model.customSw[i].func = newFunc;
|
||||||
if (chAr) {
|
if (chAr) {
|
||||||
if (model.customSw[i].getFunctionFamily() == LS_FAMILY_TIMER) {
|
if (model.customSw[i].getFunctionFamily() == LS_FAMILY_TIMER) {
|
||||||
|
@ -210,28 +204,18 @@ void LogicalSwitchesPanel::edited()
|
||||||
model.customSw[i].andsw = 0;
|
model.customSw[i].andsw = 0;
|
||||||
setSwitchWidgetVisibility(i);
|
setSwitchWidgetVisibility(i);
|
||||||
}
|
}
|
||||||
if (chDelta) {
|
|
||||||
model.customSw[i].val2 = 0;
|
|
||||||
setSwitchWidgetVisibility(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
RawSource source;
|
RawSource source;
|
||||||
|
|
||||||
switch (model.customSw[i].getFunctionFamily())
|
switch (model.customSw[i].getFunctionFamily())
|
||||||
{
|
{
|
||||||
case LS_FAMILY_VOFS:
|
case LS_FAMILY_VOFS:
|
||||||
{
|
{
|
||||||
source = RawSource(model.customSw[i].val1);
|
source = RawSource(model.customSw[i].val1);
|
||||||
RawSourceRange range = source.getRange(model, generalSettings);
|
RawSourceRange range = source.getRange(model, generalSettings, model.customSw[i].getRangeFlags());
|
||||||
double value = source.isTimeBased() ? QTimeS(cswitchTOffset[i]->time()).seconds() : cswitchOffset[i]->value();
|
double value = source.isTimeBased() ? QTimeS(cswitchTOffset[i]->time()).seconds() : cswitchOffset[i]->value();
|
||||||
if (model.customSw[i].isDeltaFunction()) {
|
model.customSw[i].val2 = round((value-range.offset)/range.step);;
|
||||||
/*TODO: is this delta function value set correctly*/
|
value = model.customSw[i].val2*range.step + range.offset;
|
||||||
model.customSw[i].val2 = round(value/range.step);
|
|
||||||
value=model.customSw[i].val2*range.step;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
model.customSw[i].val2 = round((value-range.offset)/range.step);;
|
|
||||||
value = model.customSw[i].val2*range.step + range.offset;
|
|
||||||
}
|
|
||||||
if (source.isTimeBased())
|
if (source.isTimeBased())
|
||||||
cswitchTOffset[i]->setTime(QTimeS(round(value)));
|
cswitchTOffset[i]->setTime(QTimeS(round(value)));
|
||||||
else
|
else
|
||||||
|
@ -296,7 +280,7 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||||
|
|
||||||
unsigned int mask = 0;
|
unsigned int mask = 0;
|
||||||
RawSource source = RawSource(model.customSw[i].val1);
|
RawSource source = RawSource(model.customSw[i].val1);
|
||||||
RawSourceRange range = source.getRange(model, generalSettings);
|
RawSourceRange range = source.getRange(model, generalSettings, model.customSw[i].getRangeFlags());
|
||||||
|
|
||||||
switch (model.customSw[i].getFunctionFamily())
|
switch (model.customSw[i].getFunctionFamily())
|
||||||
{
|
{
|
||||||
|
@ -307,17 +291,8 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||||
cswitchOffset[i]->setSingleStep(range.step);
|
cswitchOffset[i]->setSingleStep(range.step);
|
||||||
if (source.isTimeBased()) {
|
if (source.isTimeBased()) {
|
||||||
mask |= VALUE_TO_VISIBLE;
|
mask |= VALUE_TO_VISIBLE;
|
||||||
int maxTime;
|
int maxTime = round(range.max);
|
||||||
int value;
|
int value = round(range.step*model.customSw[i].val2 + range.offset);
|
||||||
if (model.customSw[i].isDeltaFunction()) {
|
|
||||||
/*TODO: is this delta function value set correctly*/
|
|
||||||
maxTime = round(range.step*127);
|
|
||||||
value = round(range.step*model.customSw[i].val2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
maxTime = round(range.max);
|
|
||||||
value = round(range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset);
|
|
||||||
}
|
|
||||||
cswitchTOffset[i]->setMaximumTime(QTimeS(maxTime));
|
cswitchTOffset[i]->setMaximumTime(QTimeS(maxTime));
|
||||||
cswitchTOffset[i]->setDisplayFormat((maxTime>=3600)?"hh:mm:ss":"mm:ss");
|
cswitchTOffset[i]->setDisplayFormat((maxTime>=3600)?"hh:mm:ss":"mm:ss");
|
||||||
cswitchTOffset[i]->setTime(QTimeS(value));
|
cswitchTOffset[i]->setTime(QTimeS(value));
|
||||||
|
@ -328,17 +303,9 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
|
||||||
cswitchOffset[i]->setSuffix("");
|
cswitchOffset[i]->setSuffix("");
|
||||||
else
|
else
|
||||||
cswitchOffset[i]->setSuffix(" " + range.unit);
|
cswitchOffset[i]->setSuffix(" " + range.unit);
|
||||||
if (model.customSw[i].isDeltaFunction()) {
|
cswitchOffset[i]->setMinimum(range.min);
|
||||||
/*TODO: is this delta function value set correctly*/
|
cswitchOffset[i]->setMaximum(range.max);
|
||||||
cswitchOffset[i]->setMinimum(range.step*-127);
|
cswitchOffset[i]->setValue(range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset);
|
||||||
cswitchOffset[i]->setMaximum(range.step*127);
|
|
||||||
cswitchOffset[i]->setValue(range.step*model.customSw[i].val2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cswitchOffset[i]->setMinimum(range.min);
|
|
||||||
cswitchOffset[i]->setMaximum(range.max);
|
|
||||||
cswitchOffset[i]->setValue(range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LS_FAMILY_VBOOL:
|
case LS_FAMILY_VBOOL:
|
||||||
|
|
|
@ -408,7 +408,7 @@ void TelemetryCustomScreen::updateBar(int line)
|
||||||
barsCB[line]->setCurrentIndex(index);
|
barsCB[line]->setCurrentIndex(index);
|
||||||
if (index) {
|
if (index) {
|
||||||
RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, index-1);
|
RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, index-1);
|
||||||
RawSourceRange range = source.getRange(model, generalSettings, true);
|
RawSourceRange range = source.getRange(model, generalSettings, RANGE_SINGLE_PRECISION);
|
||||||
int max = round((range.max - range.min) / range.step);
|
int max = round((range.max - range.min) / range.step);
|
||||||
if (int(255-screen.body.bars[line].barMax) > max)
|
if (int(255-screen.body.bars[line].barMax) > max)
|
||||||
screen.body.bars[line].barMax = 255 - max;
|
screen.body.bars[line].barMax = 255 - max;
|
||||||
|
|
|
@ -4397,7 +4397,12 @@ void menuModelLogicalSwitchOne(uint8_t event)
|
||||||
if (v1_val >= MIXSRC_FIRST_TELEM) {
|
if (v1_val >= MIXSRC_FIRST_TELEM) {
|
||||||
putsTelemetryChannel(CSWONE_2ND_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), attr|LEFT);
|
putsTelemetryChannel(CSWONE_2ND_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), attr|LEFT);
|
||||||
v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
||||||
v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
if (cs->func == LS_FUNC_DIFFEGREATER)
|
||||||
|
v2_min = -v2_max;
|
||||||
|
else if (cs->func == LS_FUNC_ADIFFEGREATER)
|
||||||
|
v2_min = 0;
|
||||||
|
else
|
||||||
|
v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
||||||
INCDEC_SET_FLAG(INCDEC_REP10 | NO_INCDEC_MARKS);
|
INCDEC_SET_FLAG(INCDEC_REP10 | NO_INCDEC_MARKS);
|
||||||
if (cs->v2 < v2_min || cs->v2 > v2_max) {
|
if (cs->v2 < v2_min || cs->v2 > v2_max) {
|
||||||
cs->v2 = 0;
|
cs->v2 = 0;
|
||||||
|
@ -4682,7 +4687,12 @@ void menuModelLogicalSwitches(uint8_t event)
|
||||||
putsTelemetryChannel(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT|attr2);
|
putsTelemetryChannel(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT|attr2);
|
||||||
v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
if (cs->func == LS_FUNC_DIFFEGREATER)
|
||||||
|
v2_min = -v2_max;
|
||||||
|
else if (cs->func == LS_FUNC_ADIFFEGREATER)
|
||||||
|
v2_min = 0;
|
||||||
|
else
|
||||||
|
v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
|
||||||
if (horz == 2 && v2_max-v2_min > 1000)
|
if (horz == 2 && v2_max-v2_min > 1000)
|
||||||
INCDEC_SET_FLAG(INCDEC_REP10 | NO_INCDEC_MARKS);
|
INCDEC_SET_FLAG(INCDEC_REP10 | NO_INCDEC_MARKS);
|
||||||
if (cs->v2 < v2_min || cs->v2 > v2_max) {
|
if (cs->v2 < v2_min || cs->v2 > v2_max) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue