mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 01:05:10 +03:00
parent
6609481c23
commit
31d734d14a
7 changed files with 70 additions and 38 deletions
|
@ -109,7 +109,8 @@ class LimitData {
|
|||
int offset;
|
||||
int ppmCenter;
|
||||
bool symetrical;
|
||||
char name[LIMITDATA_NAME_LEN+1];
|
||||
int failsafe;
|
||||
char name[LIMITDATA_NAME_LEN + 1];
|
||||
CurveReference curve;
|
||||
QString minToString() const;
|
||||
QString maxToString() const;
|
||||
|
|
|
@ -1174,8 +1174,7 @@ void ModelData::updateModuleFailsafes(ModuleData * md)
|
|||
|
||||
bool updated = false;
|
||||
|
||||
switch (updRefInfo.action)
|
||||
{
|
||||
switch (updRefInfo.action) {
|
||||
case REF_UPD_ACT_CLEAR:
|
||||
break;
|
||||
case REF_UPD_ACT_SHIFT:
|
||||
|
@ -1183,16 +1182,16 @@ void ModelData::updateModuleFailsafes(ModuleData * md)
|
|||
return;
|
||||
|
||||
if (updRefInfo.shift > 0) {
|
||||
for (int i = (CPN_MAX_CHNOUT - 1); i > updRefInfo.index1; i--) {
|
||||
md->failsafeChannels[i] = md->failsafeChannels[i - 1];
|
||||
for (int i = CPN_MAX_CHNOUT - 1; i > updRefInfo.index1; i--) {
|
||||
limitData[i].failsafe = limitData[i - 1].failsafe;
|
||||
}
|
||||
md->failsafeChannels[updRefInfo.index1] = 0;
|
||||
limitData[updRefInfo.index1].failsafe = 0;
|
||||
}
|
||||
else {
|
||||
for (int i = (updRefInfo.index1 + 1); i < (CPN_MAX_CHNOUT - 1); i++) {
|
||||
md->failsafeChannels[i - 1] = md->failsafeChannels[i];
|
||||
for (int i = updRefInfo.index1 + 1; i < CPN_MAX_CHNOUT - 1; i++) {
|
||||
limitData[i - 1].failsafe = limitData[i].failsafe;
|
||||
}
|
||||
md->failsafeChannels[CPN_MAX_CHNOUT - 1] = 0;
|
||||
limitData[CPN_MAX_CHNOUT - 1].failsafe = 0;
|
||||
}
|
||||
updated = true;
|
||||
break;
|
||||
|
@ -1200,17 +1199,18 @@ void ModelData::updateModuleFailsafes(ModuleData * md)
|
|||
int tmp;
|
||||
if (updRefInfo.index1 >= 0 && updRefInfo.index1 < CPN_MAX_CHNOUT) {
|
||||
updated = true;
|
||||
tmp = md->failsafeChannels[updRefInfo.index1];
|
||||
tmp = limitData[updRefInfo.index1].failsafe;
|
||||
if (updRefInfo.index2 >= 0 && updRefInfo.index2 < CPN_MAX_CHNOUT)
|
||||
md->failsafeChannels[updRefInfo.index1] = md->failsafeChannels[updRefInfo.index2];
|
||||
limitData[updRefInfo.index1].failsafe = limitData[updRefInfo.index2].failsafe;
|
||||
else
|
||||
md->failsafeChannels[updRefInfo.index1] = 0;
|
||||
limitData[updRefInfo.index1].failsafe = 0;
|
||||
}
|
||||
else
|
||||
tmp = 0;
|
||||
if (updRefInfo.index2 >= 0 && updRefInfo.index2 < CPN_MAX_CHNOUT)
|
||||
if (updRefInfo.index2 >= 0 && updRefInfo.index2 < CPN_MAX_CHNOUT) {
|
||||
updated = true;
|
||||
md->failsafeChannels[updRefInfo.index2] = tmp;
|
||||
limitData[updRefInfo.index2].failsafe = tmp;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Error - unhandled action:" << updRefInfo.action;
|
||||
|
|
|
@ -158,7 +158,11 @@ class ModuleData {
|
|||
Q_DECLARE_TR_FUNCTIONS(ModuleData)
|
||||
|
||||
public:
|
||||
ModuleData() { clear(); }
|
||||
ModuleData()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
unsigned int modelId;
|
||||
unsigned int protocol; // type in datastructs.h
|
||||
int rfProtocol; // rfProtocol in datastructs.h
|
||||
|
@ -168,7 +172,6 @@ class ModuleData {
|
|||
unsigned int channelsStart;
|
||||
int channelsCount; // 0=8 channels
|
||||
unsigned int failsafeMode;
|
||||
int failsafeChannels[CPN_MAX_CHNOUT];
|
||||
|
||||
struct PPM {
|
||||
int delay;
|
||||
|
|
|
@ -2184,7 +2184,7 @@ class ModuleUnionField: public UnionField<unsigned int> {
|
|||
|
||||
class ModuleField: public TransformedField {
|
||||
public:
|
||||
ModuleField(DataField * parent, ModuleData & module, Board::Type board, unsigned int version):
|
||||
ModuleField(DataField * parent, ModuleData & module, ModelData & model, Board::Type board, unsigned int version):
|
||||
TransformedField(parent, internalField),
|
||||
internalField(this, "Module"),
|
||||
module(module),
|
||||
|
@ -2198,8 +2198,8 @@ class ModuleField: public TransformedField {
|
|||
internalField.Append(new UnsignedField<3>(this, module.subType));
|
||||
internalField.Append(new BoolField<1>(this, module.invertedSerial));
|
||||
if (version <= 218) {
|
||||
for (int i=0; i<32; i++) {
|
||||
internalField.Append(new SignedField<16>(this, module.failsafeChannels[i]));
|
||||
for (int i = 0; i < 32; i++) {
|
||||
internalField.Append(new SignedField<16>(this, model.limitData[i].failsafe));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2393,12 +2393,12 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, Board::Type board, unsig
|
|||
|
||||
int modulesCount = (version <= 218 ? 3 : 2);
|
||||
for (int module = 0; module < modulesCount; module++) {
|
||||
internalField.Append(new ModuleField(this, modelData.moduleData[module], board, version));
|
||||
internalField.Append(new ModuleField(this, modelData.moduleData[module], modelData, board, version));
|
||||
}
|
||||
|
||||
if (version >= 219) {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
internalField.Append(new SignedField<16>(this, modelData.moduleData[0].failsafeChannels[i]));
|
||||
internalField.Append(new SignedField<16>(this, modelData.limitData[i].failsafe));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -792,18 +792,22 @@ void ModulePanel::on_lowPower_stateChanged(int state)
|
|||
module.multi.lowPowerMode = (state == Qt::Checked);
|
||||
}
|
||||
|
||||
// updtSb (update spin box(es)): 0=none or bitmask of FailsafeValueDisplayTypes
|
||||
void ModulePanel::setChannelFailsafeValue(const int channel, const int value, quint8 updtSb)
|
||||
void ModulePanel::onFailsafeModified(unsigned channel)
|
||||
{
|
||||
if (channel < 0 || channel >= CPN_MAX_CHNOUT)
|
||||
return;
|
||||
updateFailsafeUI(channel, FAILSAFE_DISPLAY_PERCENT | FAILSAFE_DISPLAY_USEC);
|
||||
}
|
||||
|
||||
module.failsafeChannels[channel] = value;
|
||||
void ModulePanel::updateFailsafeUI(unsigned channel, quint8 updtSb)
|
||||
{
|
||||
int value = model->limitData[channel].failsafe;
|
||||
double pctVal = divRoundClosest(value * 1000, 1024) / 10.0;
|
||||
// qDebug() << value << pctVal;
|
||||
|
||||
if (failsafeGroupsMap.contains(channel)) {
|
||||
const ChannelFailsafeWidgetsGroup & grp = failsafeGroupsMap.value(channel);
|
||||
bool disable = (value == FAILSAFE_CHANNEL_HOLD || value == FAILSAFE_CHANNEL_NOPULSE);
|
||||
if (grp.combo) {
|
||||
grp.combo->setCurrentIndex(grp.combo->findData(disable ? value : 0));
|
||||
}
|
||||
if ((updtSb & FAILSAFE_DISPLAY_PERCENT) && grp.sbPercent) {
|
||||
grp.sbPercent->blockSignals(true);
|
||||
grp.sbPercent->setValue(pctVal);
|
||||
|
@ -815,8 +819,21 @@ void ModulePanel::setChannelFailsafeValue(const int channel, const int value, qu
|
|||
grp.sbUsec->blockSignals(false);
|
||||
}
|
||||
}
|
||||
if (!lock)
|
||||
}
|
||||
|
||||
// updtSb (update spin box(es)): 0=none or bitmask of FailsafeValueDisplayTypes
|
||||
void ModulePanel::setChannelFailsafeValue(const int channel, const int value, quint8 updtSb)
|
||||
{
|
||||
if (channel < 0 || channel >= CPN_MAX_CHNOUT)
|
||||
return;
|
||||
|
||||
model->limitData[channel].failsafe = value;
|
||||
updateFailsafeUI(channel, updtSb);
|
||||
|
||||
if (!lock) {
|
||||
emit failsafeModified(channel);
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
void ModulePanel::onFailsafeUsecChanged(int value)
|
||||
|
@ -853,8 +870,9 @@ void ModulePanel::onFailsafeComboIndexChanged(int index)
|
|||
bool ok = false;
|
||||
int channel = sender()->property("index").toInt(&ok);
|
||||
if (ok) {
|
||||
module.failsafeChannels[channel] = cb->itemData(index).toInt();
|
||||
model->limitData[channel].failsafe = cb->itemData(index).toInt();
|
||||
updateFailsafe(channel);
|
||||
emit failsafeModified(channel);
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
|
@ -886,12 +904,12 @@ void ModulePanel::onExtendedLimitsToggled()
|
|||
}
|
||||
}
|
||||
|
||||
void ModulePanel::updateFailsafe(int channel)
|
||||
void ModulePanel::updateFailsafe(unsigned channel)
|
||||
{
|
||||
if (channel >= CPN_MAX_CHNOUT || !failsafeGroupsMap.contains(channel))
|
||||
return;
|
||||
|
||||
const int failsafeValue = module.failsafeChannels[channel];
|
||||
const int failsafeValue = model->limitData[channel].failsafe;
|
||||
const ChannelFailsafeWidgetsGroup & grp = failsafeGroupsMap.value(channel);
|
||||
const bool valDisable = (failsafeValue == FAILSAFE_CHANNEL_HOLD || failsafeValue == FAILSAFE_CHANNEL_NOPULSE);
|
||||
|
||||
|
@ -903,7 +921,7 @@ void ModulePanel::updateFailsafe(int channel)
|
|||
grp.sbUsec->setDisabled(valDisable);
|
||||
|
||||
if (!valDisable)
|
||||
setChannelFailsafeValue(channel, failsafeValue, (FAILSAFE_DISPLAY_PERCENT | FAILSAFE_DISPLAY_USEC));
|
||||
setChannelFailsafeValue(channel, failsafeValue, FAILSAFE_DISPLAY_PERCENT | FAILSAFE_DISPLAY_USEC);
|
||||
}
|
||||
|
||||
void ModulePanel::onClearAccessRxClicked()
|
||||
|
@ -1166,13 +1184,21 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
|||
ui->trimsDisplay->hide();
|
||||
}
|
||||
|
||||
for (int i=firmware->getCapability(NumFirstUsableModule); i<firmware->getCapability(NumModules); i++) {
|
||||
for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) {
|
||||
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i);
|
||||
ui->modulesLayout->addWidget(modules[i]);
|
||||
connect(modules[i], &ModulePanel::modified, this, &SetupPanel::modified);
|
||||
connect(this, &SetupPanel::extendedLimitsToggled, modules[i], &ModulePanel::onExtendedLimitsToggled);
|
||||
}
|
||||
|
||||
for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) {
|
||||
for (int j = firmware->getCapability(NumFirstUsableModule); j < firmware->getCapability(NumModules); j++) {
|
||||
if (i != j) {
|
||||
connect(modules[i], SIGNAL(failsafeModified(unsigned)), modules[j], SLOT(onFailsafeModified(unsigned)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (firmware->getCapability(ModelTrainerEnable)) {
|
||||
modules[CPN_MAX_MODULES] = new ModulePanel(this, model, model.moduleData[CPN_MAX_MODULES], generalSettings, firmware, -1);
|
||||
ui->modulesLayout->addWidget(modules[CPN_MAX_MODULES]);
|
||||
|
|
|
@ -61,15 +61,17 @@ class ModulePanel : public ModelPanel
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx);
|
||||
ModulePanel(QWidget * parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx);
|
||||
virtual ~ModulePanel();
|
||||
virtual void update();
|
||||
|
||||
public slots:
|
||||
void onExtendedLimitsToggled();
|
||||
void onFailsafeModified(unsigned index);
|
||||
|
||||
signals:
|
||||
void channelsRangeChanged();
|
||||
void failsafeModified(unsigned index);
|
||||
|
||||
private slots:
|
||||
void setupFailsafes();
|
||||
|
@ -95,7 +97,7 @@ class ModulePanel : public ModelPanel
|
|||
void onFailsafeUsecChanged(int value);
|
||||
void onFailsafePercentChanged(double value);
|
||||
void onFailsafesDisplayValueTypeChanged(int type);
|
||||
void updateFailsafe(int channel);
|
||||
void updateFailsafe(unsigned channel);
|
||||
void on_optionValue_editingFinished();
|
||||
void onClearAccessRxClicked();
|
||||
|
||||
|
@ -114,6 +116,7 @@ class ModulePanel : public ModelPanel
|
|||
Ui::Module *ui;
|
||||
QMap<int, ChannelFailsafeWidgetsGroup> failsafeGroupsMap;
|
||||
static quint8 failsafesValueDisplayType; // FailsafeValueDisplayTypes
|
||||
void updateFailsafeUI(unsigned channel, quint8 updtSb);
|
||||
};
|
||||
|
||||
class SetupPanel : public ModelPanel
|
||||
|
|
|
@ -897,9 +897,8 @@ QString ModelPrinter::printFailsafe(int idx)
|
|||
ModuleData module = model.moduleData[idx];
|
||||
strl << printLabelValue(tr("Failsafe Mode"), printFailsafeMode(module.failsafeMode));
|
||||
if (module.failsafeMode == FAILSAFE_CUSTOM) {
|
||||
for (int i=0; i<module.channelsCount; i++) {
|
||||
//strl << QString("%1(%2)").arg(printChannelName(module.channelsStart + i).trimmed()).arg(printFailsafeValue(module.failsafeChannels[i]));
|
||||
strl << printLabelValue(printChannelName(module.channelsStart + i).trimmed(), printFailsafeValue(module.failsafeChannels[i]));
|
||||
for (int i = 0; i < module.channelsCount; i++) {
|
||||
strl << printLabelValue(printChannelName(module.channelsStart + i).trimmed(), printFailsafeValue(model.limitData[i].failsafe));
|
||||
}
|
||||
}
|
||||
return strl.join(" ");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue