Skip to content

Commit

Permalink
feat: add precision setting for mix delay up & down (#5314)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Jul 29, 2024
1 parent e323bd6 commit bdfb94a
Show file tree
Hide file tree
Showing 42 changed files with 224 additions and 111 deletions.
2 changes: 2 additions & 0 deletions companion/src/firmwares/edgetx/yaml_mixdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Node convert<MixData>::encode(const MixData& rhs)
node["weight"] = YamlSourceNumRefEncode(rhs.weight);
node["swtch"] = rhs.swtch;
node["curve"] = rhs.curve;
node["delayPrec"] = rhs.delayPrec;
node["delayUp"] = rhs.delayUp;
node["delayDown"] = rhs.delayDown;
node["speedPrec"] = rhs.speedPrec;
Expand All @@ -166,6 +167,7 @@ bool convert<MixData>::decode(const Node& node, MixData& rhs)
}
node["swtch"] >> rhs.swtch;
node["curve"] >> rhs.curve;
node["delayPrec"] >> rhs.delayPrec;
node["delayUp"] >> rhs.delayUp;
node["delayDown"] >> rhs.delayDown;
node["speedPrec"] >> rhs.speedPrec;
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/mixdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MixData {
int weight;
RawSwitch swtch;
CurveReference curve;
unsigned int delayPrec;
unsigned int delayUp;
unsigned int delayDown;
unsigned int speedPrec;
Expand Down
31 changes: 26 additions & 5 deletions companion/src/modeledit/mixerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,23 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata,
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(md->swtch.toValue()));
ui->warningCB->setCurrentIndex(md->mixWarn);
ui->mltpxCB->setCurrentIndex(md->mltpx);
ui->delayPrecCB->setCurrentIndex(md->delayPrec);
ui->speedPrecCB->setCurrentIndex(md->speedPrec);

int scale=firmware->getCapability(SlowScale);
float range=firmware->getCapability(SlowRange);
float range = firmware->getCapability(SlowRange);

int scale = firmware->getCapability(SlowScale);
if (md->delayPrec) scale = scale * 10;
ui->delayDownSB->setMaximum(range / scale);
ui->delayDownSB->setSingleStep(1.0 / scale);
ui->delayDownSB->setDecimals((scale == 1 ? 0 : 1));
ui->delayDownSB->setDecimals((scale == 1 ? 0 : scale == 10 ? 1 : 2));
ui->delayDownSB->setValue((float)md->delayDown / scale);
ui->delayUpSB->setMaximum(range / scale);
ui->delayUpSB->setSingleStep(1.0 / scale);
ui->delayUpSB->setDecimals((scale == 1 ? 0 : 1));
ui->delayUpSB->setDecimals((scale == 1 ? 0 : scale == 10 ? 1 : 2));
ui->delayUpSB->setValue((float)md->delayUp / scale);

scale = firmware->getCapability(SlowScale);
if (md->speedPrec) scale = scale * 10;
ui->slowDownSB->setMaximum(range / scale);
ui->slowDownSB->setSingleStep(1.0 / scale);
Expand All @@ -178,6 +181,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata,
connect(ui->switchesCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->warningCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->mltpxCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->delayPrecCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->delayDownSB, SIGNAL(editingFinished()), this, SLOT(valuesChanged()));
connect(ui->delayUpSB, SIGNAL(editingFinished()), this, SLOT(valuesChanged()));
connect(ui->speedPrecCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
Expand Down Expand Up @@ -229,18 +233,35 @@ void MixerDialog::valuesChanged()
md->mixWarn = ui->warningCB->currentIndex();
md->mltpx = (MltpxValue)ui->mltpxCB->currentIndex();

float range = firmware->getCapability(SlowRange);

// Update values based on old precision (in case it changed)
int scale = firmware->getCapability(SlowScale);
if (md->delayPrec) scale = scale * 10;
md->delayDown = round(ui->delayDownSB->value() * scale);
md->delayUp = round(ui->delayUpSB->value() * scale);

// Get new precion and update controls
md->delayPrec = ui->delayPrecCB->currentIndex();
scale = firmware->getCapability(SlowScale);
if (md->delayPrec) scale = scale * 10;
ui->delayDownSB->setMaximum(range / scale);
ui->delayDownSB->setSingleStep(1.0 / scale);
ui->delayDownSB->setDecimals((scale == 1 ? 0 : scale == 10 ? 1 : 2));
ui->delayDownSB->setValue((float)md->delayDown / scale);
ui->delayUpSB->setMaximum(range / scale);
ui->delayUpSB->setSingleStep(1.0 / scale);
ui->delayUpSB->setDecimals((scale == 1 ? 0 : scale == 10 ? 1 : 2));
ui->delayUpSB->setValue((float)md->delayUp / scale);

// Update values based on old precision (in case it changed)
scale = firmware->getCapability(SlowScale);
if (md->speedPrec) scale = scale * 10;
md->speedDown = round(ui->slowDownSB->value() * scale);
md->speedUp = round(ui->slowUpSB->value() * scale);

// Get new precion and update controls
md->speedPrec = ui->speedPrecCB->currentIndex();
float range = firmware->getCapability(SlowRange);
scale = firmware->getCapability(SlowScale);
if (md->speedPrec) scale = scale * 10;
ui->slowDownSB->setMaximum(range / scale);
Expand Down
175 changes: 96 additions & 79 deletions companion/src/modeledit/mixerdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>752</width>
<height>623</height>
<width>763</width>
<height>655</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -63,13 +63,6 @@
</item>
</layout>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Slow up/dn prec</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="sourceCB"/>
</item>
Expand All @@ -80,20 +73,6 @@
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QComboBox" name="speedPrecCB">
<item>
<property name="text">
<string>0.0</string>
</property>
</item>
<item>
<property name="text">
<string>0.00</string>
</property>
</item>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="switchesCB"/>
</item>
Expand Down Expand Up @@ -521,8 +500,72 @@
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="slowUpSB">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="delayDownSB">
<property name="whatsThis">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Delay ans Slow&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600; text-decoration: underline;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;These values control the speed and delay of the output of the mix. &lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;If Delay is not zero the actuation of the mix will be delayed by the specified amount of seconds.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;If Slow is not zero then the speed of the mix will be set by the value specified -&amp;gt; the value states the number of seconds it takes to transit from -100 to 100.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Slow</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Delay</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Up</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Down</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="slowDownSB">
<property name="whatsThis">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
Expand Down Expand Up @@ -550,7 +593,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="delayUpSB">
<property name="whatsThis">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
Expand All @@ -574,7 +617,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="2" column="2">
<widget class="QDoubleSpinBox" name="slowDownSB">
<widget class="QDoubleSpinBox" name="slowUpSB">
<property name="whatsThis">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
Expand Down Expand Up @@ -602,68 +645,42 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Down</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Up</string>
<string>Precision</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Delay</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Slow</string>
</property>
<item row="1" column="2">
<widget class="QComboBox" name="speedPrecCB">
<item>
<property name="text">
<string>0.0</string>
</property>
</item>
<item>
<property name="text">
<string>0.00</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="delayDownSB">
<property name="whatsThis">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Delay ans Slow&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600; text-decoration: underline;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;These values control the speed and delay of the output of the mix. &lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;If Delay is not zero the actuation of the mix will be delayed by the specified amount of seconds.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;If Slow is not zero then the speed of the mix will be set by the value specified -&amp;gt; the value states the number of seconds it takes to transit from -100 to 100.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<number>1</number>
</property>
<item row="1" column="1">
<widget class="QComboBox" name="delayPrecCB">
<item>
<property name="text">
<string>0.0</string>
</property>
</item>
<item>
<property name="text">
<string>0.00</string>
</property>
</item>
</widget>
</item>
</layout>
Expand Down
9 changes: 7 additions & 2 deletions companion/src/modelprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,15 @@ QString ModelPrinter::printMixerLine(const MixData & mix, bool showMultiplex, in
if (mix.curve.value)
str += " " + mix.curve.toString(&model, true, &generalSettings).toHtmlEscaped();
int scale = firmware->getCapability(SlowScale);
if (scale == 0)
scale = 1;
if (scale == 0) scale = 1;
if (mix.delayPrec) {
scale = scale * 10;
str += " " + tr("Delay precision(0.00)").toHtmlEscaped();
}
if (mix.delayDown || mix.delayUp)
str += " " + tr("Delay(u%1:d%2)").arg((double)mix.delayUp / scale).arg((double)mix.delayDown / scale).toHtmlEscaped();
scale = firmware->getCapability(SlowScale);
if (scale == 0) scale = 1;
if (mix.speedPrec) {
scale = scale * 10;
str += " " + tr("Slow precision(0.00)").toHtmlEscaped();
Expand Down
3 changes: 2 additions & 1 deletion radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ PACK(struct MixData {
uint16_t carryTrim:1;
uint16_t mixWarn:2; // mixer warning
uint16_t mltpx:2 ENUM(MixerMultiplex);
uint16_t delayPrec:1;
uint16_t speedPrec:1;
uint16_t flightModes:9 CUST(r_flightModes, w_flightModes);
uint16_t spare:2 SKIP;
uint16_t spare:1 SKIP;
uint32_t weight:11 CUST(r_sourceNumVal,w_sourceNumVal);
uint32_t offset:11 CUST(r_sourceNumVal,w_sourceNumVal);
int32_t swtch:10 CUST(r_swtchSrc,w_swtchSrc);
Expand Down
9 changes: 7 additions & 2 deletions radio/src/gui/128x64/model_mix_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum MixFields {
MIX_FIELD_SWITCH,
MIX_FIELD_WARNING,
MIX_FIELD_MLTPX,
MIX_FIELD_DELAY_PREC,
MIX_FIELD_DELAY_UP,
MIX_FIELD_DELAY_DOWN,
MIX_FIELD_SLOW_PREC,
Expand Down Expand Up @@ -185,12 +186,16 @@ void menuModelMixOne(event_t event)
md2->mltpx = editChoice(MIXES_2ND_COLUMN, y, STR_MULTPX, STR_VMLTPX, md2->mltpx, 0, 2, attr, event);
break;

case MIX_FIELD_DELAY_PREC:
md2->delayPrec = editChoice(MIXES_2ND_COLUMN, y, STR_MIX_DELAY_PREC, &STR_VPREC[1], md2->delayPrec, 0, 1, attr, event);
break;

case MIX_FIELD_DELAY_UP:
md2->delayUp = EDIT_DELAY(0, y, event, attr, STR_DELAYUP, md2->delayUp, PREC1);
md2->delayUp = EDIT_DELAY(0, y, event, attr, STR_DELAYUP, md2->delayUp, (md2->delayPrec ? PREC2 : PREC1));
break;

case MIX_FIELD_DELAY_DOWN:
md2->delayDown = EDIT_DELAY(0, y, event, attr, STR_DELAYDOWN, md2->delayDown, PREC1);
md2->delayDown = EDIT_DELAY(0, y, event, attr, STR_DELAYDOWN, md2->delayDown, (md2->delayPrec ? PREC2 : PREC1));
break;

case MIX_FIELD_SLOW_PREC:
Expand Down
Loading

0 comments on commit bdfb94a

Please sign in to comment.