1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 14:25:11 +03:00

Merge pull request #745 from opentx/bsongis/Issue650_precise_logical_switches_delays_durations

Issue #650 fixed - 0.1s precision in durations/delays for logical
This commit is contained in:
Andre Bernet 2014-02-26 11:26:52 +01:00
commit 32aa5e9bc4
8 changed files with 31 additions and 28 deletions

View file

@ -650,12 +650,14 @@ class ConversionField: public TransformedField {
if (!error.isEmpty()) if (!error.isEmpty())
EEPROMWarnings += error + "\n"; EEPROMWarnings += error + "\n";
} }
else if (shift) {
if (shift) {
if (val < min) _field = min + shift; if (val < min) _field = min + shift;
else if (val > max) _field = max + shift; else if (val > max) _field = max + shift;
else _field = val + shift; else _field = val + shift;
} }
else {
if (exportFunc) {
_field = exportFunc(val); _field = exportFunc(val);
} }
} }
@ -666,10 +668,10 @@ class ConversionField: public TransformedField {
if (table->importValue(_field, field)) if (table->importValue(_field, field))
return; return;
} }
else if (shift) {
field = _field - shift; field = _field - shift;
}
else { if (importFunc) {
field = importFunc(_field); field = importFunc(_field);
} }

View file

@ -541,9 +541,9 @@ QString LogicalSwitchData::toString(const ModelData & model)
if (GetEepromInterface()->getCapability(LogicalSwitchesExt)) { if (GetEepromInterface()->getCapability(LogicalSwitchesExt)) {
if (delay) if (delay)
result += QObject::tr(" Delay %1 sec").arg(delay/2.0); result += QObject::tr(" Delay %1 sec").arg(delay/10.0);
if (duration) if (duration)
result += QObject::tr(" Duration %1 sec").arg(duration/2.0); result += QObject::tr(" Duration %1 sec").arg(duration/10.0);
} }
return result; return result;

View file

@ -1198,8 +1198,9 @@ class LogicalSwitchField: public TransformedField {
if (IS_ARM(board)) { if (IS_ARM(board)) {
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function")); internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
internalField.Append(new UnsignedField<8>(csw.delay)); int scale = (version >= 216 ? 0 : 5);
internalField.Append(new UnsignedField<8>(csw.duration)); internalField.Append(new ConversionField< UnsignedField<8> >(csw.delay, 0, scale));
internalField.Append(new ConversionField< UnsignedField<8> >(csw.duration, 0, scale));
if (version >= 214) { if (version >= 214) {
internalField.Append(new ConversionField< SignedField<8> >((int &)csw.andsw, andswitchesConversionTable, "AND switch")); internalField.Append(new ConversionField< SignedField<8> >((int &)csw.andsw, andswitchesConversionTable, "AND switch"));
} }

View file

@ -85,8 +85,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model):
// Duration // Duration
cswitchDuration[i] = new QDoubleSpinBox(this); cswitchDuration[i] = new QDoubleSpinBox(this);
cswitchDuration[i]->setProperty("index", i); cswitchDuration[i]->setProperty("index", i);
cswitchDuration[i]->setSingleStep(0.5); cswitchDuration[i]->setSingleStep(0.1);
cswitchDuration[i]->setMaximum(50); cswitchDuration[i]->setMaximum(25);
cswitchDuration[i]->setMinimum(0); cswitchDuration[i]->setMinimum(0);
cswitchDuration[i]->setAccelerated(true); cswitchDuration[i]->setAccelerated(true);
cswitchDuration[i]->setDecimals(1); cswitchDuration[i]->setDecimals(1);
@ -96,8 +96,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model):
// Delay // Delay
cswitchDelay[i] = new QDoubleSpinBox(this); cswitchDelay[i] = new QDoubleSpinBox(this);
cswitchDelay[i]->setProperty("index", i); cswitchDelay[i]->setProperty("index", i);
cswitchDelay[i]->setSingleStep(0.5); cswitchDelay[i]->setSingleStep(0.1);
cswitchDelay[i]->setMaximum(50); cswitchDelay[i]->setMaximum(25);
cswitchDelay[i]->setMinimum(0); cswitchDelay[i]->setMinimum(0);
cswitchDelay[i]->setAccelerated(true); cswitchDelay[i]->setAccelerated(true);
cswitchDelay[i]->setDecimals(1); cswitchDelay[i]->setDecimals(1);
@ -164,14 +164,14 @@ void LogicalSwitchesPanel::andEdited(int value)
void LogicalSwitchesPanel::durationEdited(double duration) void LogicalSwitchesPanel::durationEdited(double duration)
{ {
int index = sender()->property("index").toInt(); 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(); emit modified();
} }
void LogicalSwitchesPanel::delayEdited(double delay) void LogicalSwitchesPanel::delayEdited(double delay)
{ {
int index = sender()->property("index").toInt(); 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(); emit modified();
} }
@ -325,8 +325,8 @@ void LogicalSwitchesPanel::update()
lock = true; lock = true;
populateAndSwitchCB(cswitchAnd[i], RawSwitch(model.customSw[i].andsw)); populateAndSwitchCB(cswitchAnd[i], RawSwitch(model.customSw[i].andsw));
if (GetEepromInterface()->getCapability(LogicalSwitchesExt)) { if (GetEepromInterface()->getCapability(LogicalSwitchesExt)) {
cswitchDuration[i]->setValue(model.customSw[i].duration/2.0); cswitchDuration[i]->setValue(model.customSw[i].duration/10.0);
cswitchDelay[i]->setValue(model.customSw[i].delay/2.0); cswitchDelay[i]->setValue(model.customSw[i].delay/10.0);
} }
lock = false; lock = false;
} }

View file

@ -471,8 +471,8 @@ void ConvertModel_215_to_216(ModelData &model)
if (sw.func >= LS_FUNC_STAY) sw.func += 1; if (sw.func >= LS_FUNC_STAY) sw.func += 1;
sw.v1 = oldModel.customSw[i].v1; sw.v1 = oldModel.customSw[i].v1;
sw.v2 = oldModel.customSw[i].v2; sw.v2 = oldModel.customSw[i].v2;
sw.delay = oldModel.customSw[i].delay; sw.delay = oldModel.customSw[i].delay * 5;
sw.duration = oldModel.customSw[i].duration; sw.duration = oldModel.customSw[i].duration * 5;
sw.andsw = ConvertSwitch_215_to_216(oldModel.customSw[i].andsw); sw.andsw = ConvertSwitch_215_to_216(oldModel.customSw[i].andsw);
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
uint8_t cstate = cswFamily(sw.func); uint8_t cstate = cswFamily(sw.func);

View file

@ -4379,7 +4379,7 @@ void menuModelLogicalSwitchOne(uint8_t event)
case LS_FIELD_DURATION: case LS_FIELD_DURATION:
lcd_putsLeft(y, STR_DURATION); lcd_putsLeft(y, STR_DURATION);
if (cs->duration > 0) 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 else
lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr); lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_LS_DURATION); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_LS_DURATION);
@ -4387,7 +4387,7 @@ void menuModelLogicalSwitchOne(uint8_t event)
case LS_FIELD_DELAY: case LS_FIELD_DELAY:
lcd_putsLeft(y, STR_DELAY); lcd_putsLeft(y, STR_DELAY);
if (cs->delay > 0) 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 else
lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr); lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_LS_DELAY); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_LS_DELAY);
@ -4677,7 +4677,7 @@ void menuModelLogicalSwitches(uint8_t event)
#if defined(CPUARM) #if defined(CPUARM)
// CSW duration // CSW duration
if (cs->duration > 0) 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 else
lcd_putsiAtt(CSW_5TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DURATION ? attr : 0); lcd_putsiAtt(CSW_5TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DURATION ? attr : 0);
@ -4689,7 +4689,7 @@ void menuModelLogicalSwitches(uint8_t event)
} }
} }
else if (cs->delay > 0) { 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 { else {
lcd_putsiAtt(CSW_6TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DELAY ? attr : 0); lcd_putsiAtt(CSW_6TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DELAY ? attr : 0);

View file

@ -719,8 +719,8 @@ enum LogicalSwitchesFunctions {
}; };
#if defined(CPUARM) #if defined(CPUARM)
#define MAX_LS_DURATION 120 /*60s*/ #define MAX_LS_DURATION 250 /*25s*/
#define MAX_LS_DELAY 120 /*60s*/ #define MAX_LS_DELAY 250 /*25s*/
#define MAX_LS_ANDSW SWSRC_LAST #define MAX_LS_ANDSW SWSRC_LAST
typedef int16_t ls_telemetry_value_t; typedef int16_t ls_telemetry_value_t;
PACK(typedef struct t_LogicalSwitchData { // Custom Switches data PACK(typedef struct t_LogicalSwitchData { // Custom Switches data

View file

@ -1634,13 +1634,13 @@ bool getSwitch(int8_t swtch)
result = false; result = false;
} }
else { else {
cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*50); cswDelays[cs_idx] = get_tmr10ms() + (cs->delay*10);
} }
} }
if (cs->duration) { if (cs->duration) {
if (result && !cswStates[cs_idx]) { 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; cswStates[cs_idx] = result;