From 55f600a63cac229e2ea58e20995646e655708fe1 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 7 Feb 2014 18:24:25 +0100 Subject: [PATCH] Stay function added in Companion --- companion/src/eeprominterface.cpp | 4 +- .../src/firmwares/opentx/opentxeeprom.cpp | 2 + companion/src/helpers.cpp | 2 + companion/src/modeledit/customswitches.cpp | 131 ++++++------------ companion/src/modeledit/customswitches.h | 1 + 5 files changed, 50 insertions(+), 90 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index e313a6057..3705559ce 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -337,7 +337,9 @@ QString CurveReference::toString() CSFunctionFamily CustomSwData::getFunctionFamily() { - if (func == CS_FN_TIMER) + if (func == CS_FN_STAY) + return CS_FAMILY_STAY; + else if (func == CS_FN_TIMER) return CS_FAMILY_TIMER; else if (func == CS_FN_STICKY) return CS_FAMILY_STICKY; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 779012861..9dc1fe4e6 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -1032,11 +1032,13 @@ class CustomSwitchesFunctionsTable: public ConversionTable { addConversion(CS_FN_VEQUAL, val++); addConversion(CS_FN_VPOS, val++); addConversion(CS_FN_VNEG, val++); + if (IS_ARM(board) && version >= 216) val++; // later RANGE addConversion(CS_FN_APOS, val++); addConversion(CS_FN_ANEG, val++); addConversion(CS_FN_AND, val++); addConversion(CS_FN_OR, val++); addConversion(CS_FN_XOR, val++); + if (IS_ARM(board) && version >= 216) addConversion(CS_FN_STAY, val++); addConversion(CS_FN_EQUAL, val++); if (!release21March2013) addConversion(CS_FN_NEQUAL, val++); diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 7864dc100..ed845e371 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -673,11 +673,13 @@ void populateCSWCB(QComboBox *b, int value) CS_FN_VEQUAL, // added at the end to avoid everything renumbered CS_FN_VPOS, CS_FN_VNEG, + // CS_FN_RANGE, CS_FN_APOS, CS_FN_ANEG, CS_FN_AND, CS_FN_OR, CS_FN_XOR, + CS_FN_STAY, CS_FN_EQUAL, CS_FN_NEQUAL, CS_FN_GREATER, diff --git a/companion/src/modeledit/customswitches.cpp b/companion/src/modeledit/customswitches.cpp index aea3dd602..72c9404f0 100644 --- a/companion/src/modeledit/customswitches.cpp +++ b/companion/src/modeledit/customswitches.cpp @@ -180,16 +180,19 @@ void CustomSwitchesPanel::edited() if (!lock) { lock = true; int i = sender()->property("index").toInt(); - bool chAr; - float value, step; - int newval; - chAr = (model.customSw[i].getFunctionFamily() != CustomSwData(csw[i]->itemData(csw[i]->currentIndex()).toInt()).getFunctionFamily()); - model.customSw[i].func = csw[i]->itemData(csw[i]->currentIndex()).toInt(); - if(chAr) { + int newFunc = csw[i]->itemData(csw[i]->currentIndex()).toInt(); + bool chAr = (model.customSw[i].getFunctionFamily() != CustomSwData(newFunc).getFunctionFamily()); + model.customSw[i].func = newFunc; + if (chAr) { if (model.customSw[i].getFunctionFamily() == CS_FAMILY_TIMER) { model.customSw[i].val1 = -119; model.customSw[i].val2 = -119; } + else if (model.customSw[i].getFunctionFamily() == CS_FAMILY_STAY) { + model.customSw[i].val1 = 0; + model.customSw[i].val2 = -129; + model.customSw[i].val3 = 0; + } else { model.customSw[i].val1 = 0; model.customSw[i].val2 = 0; @@ -216,65 +219,15 @@ void CustomSwitchesPanel::edited() } break; case CS_FAMILY_TIMER: - { - value = cswitchOffset[i]->value(); - newval=TimToVal(value); - if (newval>model.customSw[i].val2) { - if (value >=60) { - value=round(value); - step=1; - } else if (value>=2) { - value=(round(value*2.0)/2); - step=0.5; - } else { - step=0.1; - } - } - else { - if (value <=2) { - step=0.1; - } else if (value<=60) { - value=(round(value*2.0)/2); - step=0.5; - } else { - value=round(value); - step=1; - } - } - model.customSw[i].val2=TimToVal(value); - value=ValToTim(model.customSw[i].val2); - cswitchOffset[i]->setValue(value); - cswitchOffset[i]->setSingleStep(step); - - value=cswitchValue[i]->value(); - newval=TimToVal(value); - if (newval>model.customSw[i].val1) { - if (value >=60) { - value=round(value); - step=1; - } else if (value>=2) { - value=(round(value*2.0)/2); - step=0.5; - } else { - step=0.1; - } - } else { - if (value <=2) { - step=0.1; - } else if (value<=60) { - value=(round(value*2.0)/2); - step=0.5; - } else { - value=round(value); - step=1; - } - } - model.customSw[i].val1=TimToVal(value); - value=ValToTim(model.customSw[i].val1); - cswitchValue[i]->setValue(value); - cswitchValue[i]->setSingleStep(step); + model.customSw[i].val1 = TimToVal(cswitchValue[i]->value()); + model.customSw[i].val2 = TimToVal(cswitchOffset[i]->value()); + updateTimerParam(cswitchValue[i], model.customSw[i].val1); + updateTimerParam(cswitchOffset[i], model.customSw[i].val2); + break; + case CS_FAMILY_STAY: + model.customSw[i].val2 = TimToVal(cswitchOffset[i]->value()); + updateTimerParam(cswitchOffset[i], model.customSw[i].val2, true); break; - } default: break; } @@ -283,6 +236,22 @@ void CustomSwitchesPanel::edited() } } +void CustomSwitchesPanel::updateTimerParam(QDoubleSpinBox *sb, int timer, bool allowZero) +{ + sb->setVisible(true); + sb->setDecimals(1); + sb->setMinimum(allowZero ? 0.0 : 0.1); + sb->setMaximum(175); + float value = ValToTim(timer); + if (value>60) + sb->setSingleStep(1); + else if (value>2) + sb->setSingleStep(0.5); + else + sb->setSingleStep(0.1); + sb->setValue(value); +} + void CustomSwitchesPanel::setSwitchWidgetVisibility(int i) { lock = true; @@ -320,6 +289,13 @@ void CustomSwitchesPanel::setSwitchWidgetVisibility(int i) populateSwitchCB(cswitchSource1[i], RawSwitch(model.customSw[i].val1)); populateSwitchCB(cswitchSource2[i], RawSwitch(model.customSw[i].val2)); break; + case CS_FAMILY_STAY: + cswitchSource1[i]->setVisible(true); + cswitchSource2[i]->setVisible(false); + cswitchValue[i]->setVisible(false); + populateSwitchCB(cswitchSource1[i], RawSwitch(model.customSw[i].val1)); + updateTimerParam(cswitchOffset[i], model.customSw[i].val2, true); + break; case CS_FAMILY_VCOMP: cswitchSource1[i]->setVisible(true); cswitchSource2[i]->setVisible(true); @@ -331,31 +307,8 @@ void CustomSwitchesPanel::setSwitchWidgetVisibility(int i) case CS_FAMILY_TIMER: cswitchSource1[i]->setVisible(false); cswitchSource2[i]->setVisible(false); - cswitchValue[i]->setVisible(true); - cswitchOffset[i]->setVisible(true); - cswitchOffset[i]->setDecimals(1); - cswitchOffset[i]->setMinimum(0.1); - cswitchOffset[i]->setMaximum(175); - float value=ValToTim(model.customSw[i].val2); - cswitchOffset[i]->setSingleStep(0.1); - if (value>60) { - cswitchOffset[i]->setSingleStep(1); - } else if (value>2) { - cswitchOffset[i]->setSingleStep(0.5); - } - cswitchOffset[i]->setValue(value); - - cswitchValue[i]->setDecimals(1); - cswitchValue[i]->setMinimum(0.1); - cswitchValue[i]->setMaximum(175); - value=ValToTim(model.customSw[i].val1); - cswitchValue[i]->setSingleStep(0.1); - if (value>60) { - cswitchValue[i]->setSingleStep(1); - } else if (value>2) { - cswitchValue[i]->setSingleStep(0.5); - } - cswitchValue[i]->setValue(value); + updateTimerParam(cswitchValue[i], model.customSw[i].val1); + updateTimerParam(cswitchOffset[i], model.customSw[i].val2); break; } diff --git a/companion/src/modeledit/customswitches.h b/companion/src/modeledit/customswitches.h index f4354bcb9..0ff1973d6 100644 --- a/companion/src/modeledit/customswitches.h +++ b/companion/src/modeledit/customswitches.h @@ -42,6 +42,7 @@ class CustomSwitchesPanel : public ModelPanel void updateSelectedSwitch(); void updateV2(int index); + void updateTimerParam(QDoubleSpinBox *sb, int timer, bool allowZero=false); };