From 56d167e45f56f439f15583bd24eb94286ca0e036 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 24 Feb 2014 07:45:37 +0100 Subject: [PATCH 1/5] Issue #650 fixed - 0.1s precision in durations/delays for logical switches --- companion/src/eeprominterface.cpp | 4 ++-- companion/src/modeledit/customswitches.cpp | 16 ++++++++-------- radio/src/eeprom_conversions.cpp | 4 ++-- radio/src/gui/menu_model.cpp | 4 ++-- radio/src/myeeprom.h | 4 ++-- radio/src/opentx.cpp | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 1df1f4e98..d97b8cf1a 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -539,9 +539,9 @@ QString LogicalSwitchData::toString(const ModelData & model) if (GetEepromInterface()->getCapability(LogicalSwitchesExt)) { if (delay) - result += QObject::tr(" Delay %1 sec").arg(delay/2.0); + result += QObject::tr(" Delay %1 sec").arg(delay/10.0); if (duration) - result += QObject::tr(" Duration %1 sec").arg(duration/2.0); + result += QObject::tr(" Duration %1 sec").arg(duration/10.0); } return result; diff --git a/companion/src/modeledit/customswitches.cpp b/companion/src/modeledit/customswitches.cpp index cf02f4430..ad418df68 100644 --- a/companion/src/modeledit/customswitches.cpp +++ b/companion/src/modeledit/customswitches.cpp @@ -85,8 +85,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model): // Duration cswitchDuration[i] = new QDoubleSpinBox(this); cswitchDuration[i]->setProperty("index", i); - cswitchDuration[i]->setSingleStep(0.5); - cswitchDuration[i]->setMaximum(50); + cswitchDuration[i]->setSingleStep(0.1); + cswitchDuration[i]->setMaximum(25); cswitchDuration[i]->setMinimum(0); cswitchDuration[i]->setAccelerated(true); cswitchDuration[i]->setDecimals(1); @@ -96,8 +96,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model): // Delay cswitchDelay[i] = new QDoubleSpinBox(this); cswitchDelay[i]->setProperty("index", i); - cswitchDelay[i]->setSingleStep(0.5); - cswitchDelay[i]->setMaximum(50); + cswitchDelay[i]->setSingleStep(0.1); + cswitchDelay[i]->setMaximum(25); cswitchDelay[i]->setMinimum(0); cswitchDelay[i]->setAccelerated(true); cswitchDelay[i]->setDecimals(1); @@ -164,14 +164,14 @@ void LogicalSwitchesPanel::andEdited(int value) void LogicalSwitchesPanel::durationEdited(double duration) { int index = sender()->property("index").toInt(); - model.customSw[index].duration = (uint8_t)round(duration*2); + model.customSw[index].duration = (uint8_t)round(duration*10); emit modified(); } void LogicalSwitchesPanel::delayEdited(double delay) { int index = sender()->property("index").toInt(); - model.customSw[index].delay = (uint8_t)round(delay*2); + model.customSw[index].delay = (uint8_t)round(delay*10); emit modified(); } @@ -325,8 +325,8 @@ void LogicalSwitchesPanel::update() lock = true; populateAndSwitchCB(cswitchAnd[i], RawSwitch(model.customSw[i].andsw)); if (GetEepromInterface()->getCapability(LogicalSwitchesExt)) { - cswitchDuration[i]->setValue(model.customSw[i].duration/2.0); - cswitchDelay[i]->setValue(model.customSw[i].delay/2.0); + cswitchDuration[i]->setValue(model.customSw[i].duration/10.0); + cswitchDelay[i]->setValue(model.customSw[i].delay/10.0); } lock = false; } diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index f12353cb0..15abd195e 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -470,8 +470,8 @@ void ConvertModel_215_to_216(ModelData &model) if (sw.func >= LS_FUNC_STAY) sw.func += 1; sw.v1 = oldModel.customSw[i].v1; sw.v2 = oldModel.customSw[i].v2; - sw.delay = oldModel.customSw[i].delay; - sw.duration = oldModel.customSw[i].duration; + sw.delay = oldModel.customSw[i].delay * 5; + sw.duration = oldModel.customSw[i].duration * 5; sw.andsw = ConvertSwitch_215_to_216(oldModel.customSw[i].andsw); #if defined(PCBTARANIS) uint8_t cstate = cswFamily(sw.func); diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index d1dd68a46..bb78da5ff 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -4363,7 +4363,7 @@ void menuModelLogicalSwitchOne(uint8_t event) case LS_FIELD_DURATION: lcd_putsLeft(y, STR_DURATION); if (cs->duration > 0) - lcd_outdezAtt(CSWONE_2ND_COLUMN, y, 5*cs->duration, attr|PREC1|LEFT); + lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->duration, attr|PREC1|LEFT); else lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_LS_DURATION); @@ -4371,7 +4371,7 @@ void menuModelLogicalSwitchOne(uint8_t event) case LS_FIELD_DELAY: lcd_putsLeft(y, STR_DELAY); if (cs->delay > 0) - lcd_outdezAtt(CSWONE_2ND_COLUMN, y, 5*cs->delay, attr|PREC1|LEFT); + lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->delay, attr|PREC1|LEFT); else lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_LS_DELAY); diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 94b6cbb9e..dc427485a 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -712,8 +712,8 @@ enum LogicalSwitchesFunctions { }; #if defined(CPUARM) -#define MAX_LS_DURATION 120 /*60s*/ -#define MAX_LS_DELAY 120 /*60s*/ +#define MAX_LS_DURATION 250 /*25s*/ +#define MAX_LS_DELAY 250 /*25s*/ #define MAX_LS_ANDSW SWSRC_LAST typedef int16_t ls_telemetry_value_t; PACK(typedef struct t_LogicalSwitchData { // Custom Switches data diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 36d95d213..75e41dd80 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1589,13 +1589,13 @@ bool getSwitch(int8_t swtch) result = false; } else { - cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*50); + cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*10); } } if (cs->duration) { if (result && !cswStates[cs_idx]) { - cswDurations[cs_idx] = get_tmr10ms() + (cs->duration*50); + cswDurations[cs_idx] = get_tmr10ms() + (cs->duration*10); } cswStates[cs_idx] = result; From 0029f57413d77fd1dc5891141cb9605ff94d5fa9 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 24 Feb 2014 19:52:35 +0100 Subject: [PATCH 2/5] Conversions from older EEPROM for duration/delay fields (x5) --- companion/src/firmwares/opentx/opentxeeprom.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 37f148900..dff4d73fb 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -1196,8 +1196,9 @@ class LogicalSwitchField: public TransformedField { if (IS_ARM(board)) { internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function")); - internalField.Append(new UnsignedField<8>(csw.delay)); - internalField.Append(new UnsignedField<8>(csw.duration)); + int scale = (version >= 216 ? 0 : 5); + internalField.Append(new ConversionField< UnsignedField<8> >(csw.delay, 0, scale)); + internalField.Append(new ConversionField< UnsignedField<8> >(csw.duration, 0, scale)); if (version >= 214) { internalField.Append(new ConversionField< SignedField<8> >((int &)csw.andsw, andswitchesConversionTable, "AND switch")); } From 4d2f8d29182856ea861afcc967538c486b58c8da Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Tue, 25 Feb 2014 19:49:21 +0100 Subject: [PATCH 3/5] Duration/delay display wasn't adapted on Taranis --- radio/src/gui/menu_model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 5e020efae..5593cd0c6 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -4661,7 +4661,7 @@ void menuModelLogicalSwitches(uint8_t event) #if defined(CPUARM) // CSW duration if (cs->duration > 0) - lcd_outdezAtt(CSW_5TH_COLUMN, y, 5*cs->duration, (horz==LS_FIELD_DURATION ? attr : 0)|PREC1|LEFT); + lcd_outdezAtt(CSW_5TH_COLUMN, y, cs->duration, (horz==LS_FIELD_DURATION ? attr : 0)|PREC1|LEFT); else lcd_putsiAtt(CSW_5TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DURATION ? attr : 0); @@ -4673,7 +4673,7 @@ void menuModelLogicalSwitches(uint8_t event) } } else if (cs->delay > 0) { - lcd_outdezAtt(CSW_6TH_COLUMN, y, 5*cs->delay, (horz==LS_FIELD_DELAY ? attr : 0)|PREC1|LEFT); + lcd_outdezAtt(CSW_6TH_COLUMN, y, cs->delay, (horz==LS_FIELD_DELAY ? attr : 0)|PREC1|LEFT); } else { lcd_putsiAtt(CSW_6TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DELAY ? attr : 0); From f5b9ebfcc3fad4c5d928b841b7e5e4622aacce5d Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 26 Feb 2014 09:54:25 +0100 Subject: [PATCH 4/5] Core in import of EEPROMS < 216 --- companion/src/eepromimportexport.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/companion/src/eepromimportexport.h b/companion/src/eepromimportexport.h index 91eda318c..5ea132e61 100644 --- a/companion/src/eepromimportexport.h +++ b/companion/src/eepromimportexport.h @@ -650,12 +650,14 @@ class ConversionField: public TransformedField { if (!error.isEmpty()) EEPROMWarnings += error + "\n"; } - else if (shift) { + + if (shift) { if (val < min) _field = min + shift; else if (val > max) _field = max + shift; else _field = val + shift; } - else { + + if (exportFunc) { _field = exportFunc(val); } } @@ -666,10 +668,12 @@ class ConversionField: public TransformedField { if (table->importValue(_field, field)) return; } - else if (shift) { + + if (shift) { field = _field - shift; } - else { + + if (importFunc) { field = importFunc(_field); } From d14fc31f885072661aa21fb5928a730b44d5c739 Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 26 Feb 2014 11:21:09 +0100 Subject: [PATCH 5/5] Import bug, scale result was always 0 --- companion/src/eepromimportexport.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/companion/src/eepromimportexport.h b/companion/src/eepromimportexport.h index 5ea132e61..242c1f7f7 100644 --- a/companion/src/eepromimportexport.h +++ b/companion/src/eepromimportexport.h @@ -669,9 +669,7 @@ class ConversionField: public TransformedField { return; } - if (shift) { - field = _field - shift; - } + field = _field - shift; if (importFunc) { field = importFunc(_field);