1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-22 15:55:26 +03:00
This commit is contained in:
bsongis 2014-08-12 16:16:59 +02:00
parent dd08886f2c
commit 36481471a3
17 changed files with 142 additions and 89 deletions

View file

@ -40,11 +40,11 @@ inline int switchIndex(int i, BoardEnum board, unsigned int version)
class SwitchesConversionTable: public ConversionTable { class SwitchesConversionTable: public ConversionTable {
public: public:
SwitchesConversionTable(BoardEnum board, unsigned int version, unsigned long flags=0) SwitchesConversionTable(BoardEnum board, unsigned int version, bool timer=false)
{ {
int val=0; int val=0;
int offset=0; int offset=0;
if (flags & POPULATE_TIMER_MODES) { if (timer) {
offset = 4; offset = 4;
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
addConversion(RawSwitch(SWITCH_TYPE_TIMER_MODE, i), val++); addConversion(RawSwitch(SWITCH_TYPE_TIMER_MODE, i), val++);
@ -93,17 +93,15 @@ class SwitchesConversionTable: public ConversionTable {
addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, i), val++); addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, i), val++);
} }
if (!(flags & POPULATE_TIMER_MODES)) { addConversion(RawSwitch(SWITCH_TYPE_OFF), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_OFF), -val+offset); addConversion(RawSwitch(SWITCH_TYPE_ON), val++);
addConversion(RawSwitch(SWITCH_TYPE_ON), val++); if (version >= 216) {
if (version >= 216) { addConversion(RawSwitch(SWITCH_TYPE_ONE, -1), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_ONE, -1), -val+offset); addConversion(RawSwitch(SWITCH_TYPE_ONE, 1), val++);
addConversion(RawSwitch(SWITCH_TYPE_ONE, 1), val++); if (IS_ARM(board)) {
if (IS_ARM(board)) { for (int i=1; i<=MAX_FLIGHT_MODES(board, version); i++) {
for (int i=1; i<=MAX_FLIGHT_MODES(board, version); i++) { addConversion(RawSwitch(SWITCH_TYPE_FLIGHT_MODE, -i), -val+offset);
addConversion(RawSwitch(SWITCH_TYPE_FLIGHT_MODE, -i), -val+offset); addConversion(RawSwitch(SWITCH_TYPE_FLIGHT_MODE, i), val++);
addConversion(RawSwitch(SWITCH_TYPE_FLIGHT_MODE, i), val++);
}
} }
} }
} }
@ -2429,7 +2427,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
} }
for (int i=0; i<O9X_MAX_TIMERS; i++) { for (int i=0; i<O9X_MAX_TIMERS; i++) {
internalField.Append(new SwitchField<8>(modelData.timers[i].mode, board, version, POPULATE_TIMER_MODES)); internalField.Append(new SwitchField<8>(modelData.timers[i].mode, board, version, true));
if ((IS_ARM(board) || IS_2560(board)) && version >= 216) { if ((IS_ARM(board) || IS_2560(board)) && version >= 216) {
internalField.Append(new UnsignedField<16>(modelData.timers[i].val)); internalField.Append(new UnsignedField<16>(modelData.timers[i].val));
internalField.Append(new UnsignedField<2>(modelData.timers[i].countdownBeep)); internalField.Append(new UnsignedField<2>(modelData.timers[i].countdownBeep));

View file

@ -378,13 +378,13 @@ void populateBacklightCB(QComboBox *b, const uint8_t value)
} }
} }
void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettings & generalSettings, unsigned long attr) void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettings & generalSettings, SwitchContext context)
{ {
RawSwitch item; RawSwitch item;
b->clear(); b->clear();
if (attr & POPULATE_ONOFF) { if (context != MixesContext) {
// !FMx // !FMx
if (IS_ARM(GetCurrentFirmware()->getBoard())) { if (IS_ARM(GetCurrentFirmware()->getBoard())) {
for (int i=-GetCurrentFirmware()->getCapability(FlightModes); i<0; i++) { for (int i=-GetCurrentFirmware()->getCapability(FlightModes); i<0; i++) {
@ -393,14 +393,6 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
if (item == value) b->setCurrentIndex(b->count()-1); if (item == value) b->setCurrentIndex(b->count()-1);
} }
} }
// !One
item = RawSwitch(SWITCH_TYPE_ONE, 1);
b->addItem(item.toString(), item.toValue());
if (item == value) b->setCurrentIndex(b->count()-1);
// OFF
item = RawSwitch(SWITCH_TYPE_OFF);
b->addItem(item.toString(), item.toValue());
if (item == value) b->setCurrentIndex(b->count()-1);
} }
for (int i=-GetCurrentFirmware()->getCapability(LogicalSwitches); i<0; i++) { for (int i=-GetCurrentFirmware()->getCapability(LogicalSwitches); i<0; i++) {
@ -435,13 +427,13 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
item = RawSwitch(SWITCH_TYPE_SWITCH, i); item = RawSwitch(SWITCH_TYPE_SWITCH, i);
if (IS_TARANIS(GetCurrentFirmware()->getBoard())) { if (IS_TARANIS(GetCurrentFirmware()->getBoard())) {
//hide up and down for !SH and !SF, because they are redundant (!SFup == SFdown) //hide up and down for !SH and !SF, because they are redundant (!SFup == SFdown)
if (item.toString().contains("H") || item.toString().contains("F")) continue; if (item.toString().contains("H") || item.toString().contains("F")) continue;
} }
b->addItem(item.toString(), item.toValue()); b->addItem(item.toString(), item.toValue());
if (item == value) b->setCurrentIndex(b->count()-1); if (item == value) b->setCurrentIndex(b->count()-1);
} }
if (attr & POPULATE_TIMER_MODES) { if (context == TimersContext) {
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
item = RawSwitch(SWITCH_TYPE_TIMER_MODE, i); item = RawSwitch(SWITCH_TYPE_TIMER_MODE, i);
b->addItem(item.toString(), item.toValue()); b->addItem(item.toString(), item.toValue());
@ -488,7 +480,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
if (item == value) b->setCurrentIndex(b->count()-1); if (item == value) b->setCurrentIndex(b->count()-1);
} }
if (attr & POPULATE_ONOFF) { if (context == CustomFunctionsContext) {
// ON // ON
item = RawSwitch(SWITCH_TYPE_ON); item = RawSwitch(SWITCH_TYPE_ON);
b->addItem(item.toString(), item.toValue()); b->addItem(item.toString(), item.toValue());
@ -497,7 +489,10 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
item = RawSwitch(SWITCH_TYPE_ONE, 1); item = RawSwitch(SWITCH_TYPE_ONE, 1);
b->addItem(item.toString(), item.toValue()); b->addItem(item.toString(), item.toValue());
if (item == value) b->setCurrentIndex(b->count()-1); if (item == value) b->setCurrentIndex(b->count()-1);
// FMx }
// FMx
if (context != MixesContext) {
if (IS_ARM(GetCurrentFirmware()->getBoard())) { if (IS_ARM(GetCurrentFirmware()->getBoard())) {
for (int i=1; i<=GetCurrentFirmware()->getCapability(FlightModes); i++) { for (int i=1; i<=GetCurrentFirmware()->getCapability(FlightModes); i++) {
item = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, i); item = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, i);

View file

@ -6,7 +6,7 @@
extern const QColor colors[C9X_MAX_CURVES]; extern const QColor colors[C9X_MAX_CURVES];
#define TMR_NUM_OPTION (TMR_VAROFS+2*9+2*GetCurrentFirmware()->getCapability(LogicalSwitches)-1) #define TMR_NUM_OPTION (TMRMODE_COUNT+2*9+2*GetCurrentFirmware()->getCapability(LogicalSwitches)-1)
//convert from mode 1 to mode generalSettings.stickMode //convert from mode 1 to mode generalSettings.stickMode
//NOTICE! => 1..4 -> 1..4 //NOTICE! => 1..4 -> 1..4
@ -81,9 +81,15 @@ class CurveGroup : public QObject {
int lastType; int lastType;
}; };
#define POPULATE_ONOFF 0x01 enum SwitchContext
#define POPULATE_TIMER_MODES 0x02 {
void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettings & generalSettings, unsigned long attr=0); LogicalSwitchesContext,
CustomFunctionsContext,
TimersContext,
MixesContext
};
void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettings & generalSettings, SwitchContext context);
void populatePhasesCB(QComboBox *b, int value); void populatePhasesCB(QComboBox *b, int value);
void populateGvarUseCB(QComboBox *b, unsigned int phase); void populateGvarUseCB(QComboBox *b, unsigned int phase);

View file

@ -506,7 +506,7 @@ void CustomFunctionsPanel::update()
lock = true; lock = true;
for (int i=0; i<firmware->getCapability(CustomFunctions); i++) { for (int i=0; i<firmware->getCapability(CustomFunctions); i++) {
if (!initialized) { if (!initialized) {
populateSwitchCB(fswtchSwtch[i], model.funcSw[i].swtch, generalSettings, POPULATE_ONOFF); populateSwitchCB(fswtchSwtch[i], model.funcSw[i].swtch, generalSettings, CustomFunctionsContext);
populateFuncCB(fswtchFunc[i], model.funcSw[i].func); populateFuncCB(fswtchFunc[i], model.funcSw[i].func);
populateGVmodeCB(fswtchGVmode[i], model.funcSw[i].adjustMode); populateGVmodeCB(fswtchGVmode[i], model.funcSw[i].adjustMode);
populateFuncParamCB(fswtchParamT[i], model, model.funcSw[i].func, model.funcSw[i].param, model.funcSw[i].adjustMode); populateFuncParamCB(fswtchParamT[i], model, model.funcSw[i].func, model.funcSw[i].param, model.funcSw[i].adjustMode);
@ -527,7 +527,7 @@ void CustomFunctionsPanel::fswPaste()
FuncSwData *fsw = &model.funcSw[selectedFunction]; FuncSwData *fsw = &model.funcSw[selectedFunction];
memcpy(fsw, fswData.mid(0, sizeof(FuncSwData)).constData(), sizeof(FuncSwData)); memcpy(fsw, fswData.mid(0, sizeof(FuncSwData)).constData(), sizeof(FuncSwData));
lock = true; lock = true;
populateSwitchCB(fswtchSwtch[selectedFunction], model.funcSw[selectedFunction].swtch, generalSettings, POPULATE_ONOFF); populateSwitchCB(fswtchSwtch[selectedFunction], model.funcSw[selectedFunction].swtch, generalSettings, CustomFunctionsContext);
populateFuncCB(fswtchFunc[selectedFunction], model.funcSw[selectedFunction].func); populateFuncCB(fswtchFunc[selectedFunction], model.funcSw[selectedFunction].func);
populateGVmodeCB(fswtchGVmode[selectedFunction], model.funcSw[selectedFunction].adjustMode); populateGVmodeCB(fswtchGVmode[selectedFunction], model.funcSw[selectedFunction].adjustMode);
populateFuncParamCB(fswtchParamT[selectedFunction], model, model.funcSw[selectedFunction].func, model.funcSw[selectedFunction].param, model.funcSw[selectedFunction].adjustMode); populateFuncParamCB(fswtchParamT[selectedFunction], model, model.funcSw[selectedFunction].func, model.funcSw[selectedFunction].param, model.funcSw[selectedFunction].adjustMode);
@ -543,7 +543,7 @@ void CustomFunctionsPanel::fswDelete()
model.funcSw[selectedFunction].clear(); model.funcSw[selectedFunction].clear();
// TODO update switch and func // TODO update switch and func
lock = true; lock = true;
populateSwitchCB(fswtchSwtch[selectedFunction], model.funcSw[selectedFunction].swtch, generalSettings, POPULATE_ONOFF); populateSwitchCB(fswtchSwtch[selectedFunction], model.funcSw[selectedFunction].swtch, generalSettings, CustomFunctionsContext);
populateFuncCB(fswtchFunc[selectedFunction], model.funcSw[selectedFunction].func); populateFuncCB(fswtchFunc[selectedFunction], model.funcSw[selectedFunction].func);
refreshCustomFunction(selectedFunction); refreshCustomFunction(selectedFunction);
lock = false; lock = false;

View file

@ -33,7 +33,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G
curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve); curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve);
populateSwitchCB(ui->switchesCB, ed->swtch, generalSettings); populateSwitchCB(ui->switchesCB, ed->swtch, generalSettings, MixesContext);
ui->sideCB->setCurrentIndex(ed->mode-1); ui->sideCB->setCurrentIndex(ed->mode-1);

View file

@ -30,7 +30,7 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
// Phase switch // Phase switch
if (phaseIdx > 0) { if (phaseIdx > 0) {
populateSwitchCB(ui->swtch, phase.swtch, generalSettings); populateSwitchCB(ui->swtch, phase.swtch, generalSettings, MixesContext);
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int))); connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
} }
else { else {

View file

@ -324,12 +324,12 @@ void LogicalSwitchesPanel::setSwitchWidgetVisibility(int i)
// no break // no break
case LS_FAMILY_VBOOL: case LS_FAMILY_VBOOL:
mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE; mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE;
populateSwitchCB(cswitchSource1[i], RawSwitch(model.customSw[i].val1), generalSettings); populateSwitchCB(cswitchSource1[i], RawSwitch(model.customSw[i].val1), generalSettings, LogicalSwitchesContext);
populateSwitchCB(cswitchSource2[i], RawSwitch(model.customSw[i].val2), generalSettings); populateSwitchCB(cswitchSource2[i], RawSwitch(model.customSw[i].val2), generalSettings, LogicalSwitchesContext);
break; break;
case LS_FAMILY_STAY: case LS_FAMILY_STAY:
mask |= SOURCE1_VISIBLE | VALUE2_VISIBLE | VALUE3_VISIBLE; mask |= SOURCE1_VISIBLE | VALUE2_VISIBLE | VALUE3_VISIBLE;
populateSwitchCB(cswitchSource1[i], RawSwitch(model.customSw[i].val1), generalSettings); populateSwitchCB(cswitchSource1[i], RawSwitch(model.customSw[i].val1), generalSettings, LogicalSwitchesContext);
updateTimerParam(cswitchOffset[i], model.customSw[i].val2, 0.0); updateTimerParam(cswitchOffset[i], model.customSw[i].val2, 0.0);
updateTimerParam(cswitchOffset2[i], model.customSw[i].val2+model.customSw[i].val3, cswitchOffset[i]->value()); updateTimerParam(cswitchOffset2[i], model.customSw[i].val2+model.customSw[i].val3, cswitchOffset[i]->value());
if (model.customSw[i].val3 == 0) { if (model.customSw[i].val3 == 0) {
@ -410,7 +410,7 @@ void LogicalSwitchesPanel::populateCSWCB(QComboBox *b, int value)
void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b, const RawSwitch & value) void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b, const RawSwitch & value)
{ {
if (IS_ARM(firmware->getBoard())) { if (IS_ARM(firmware->getBoard())) {
populateSwitchCB(b, value, generalSettings, POPULATE_ONOFF); populateSwitchCB(b, value, generalSettings, LogicalSwitchesContext);
} }
else { else {
RawSwitch item; RawSwitch item;

View file

@ -76,7 +76,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData *mixdata, G
} }
} }
populateSwitchCB(ui->switchesCB, md->swtch, generalSettings); populateSwitchCB(ui->switchesCB, md->swtch, generalSettings, MixesContext);
ui->warningCB->setCurrentIndex(md->mixWarn); ui->warningCB->setCurrentIndex(md->mixWarn);
ui->mltpxCB->setCurrentIndex(md->mltpx); ui->mltpxCB->setCurrentIndex(md->mltpx);
int scale=firmware->getCapability(SlowScale); int scale=firmware->getCapability(SlowScale);

View file

@ -15,7 +15,7 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
lock = true; lock = true;
// Mode // Mode
populateSwitchCB(ui->mode, timer.mode, generalSettings, POPULATE_TIMER_MODES); populateSwitchCB(ui->mode, timer.mode, generalSettings, TimersContext);
if (!firmware->getCapability(PermTimers)) { if (!firmware->getCapability(PermTimers)) {
ui->persistent->hide(); ui->persistent->hide();

View file

@ -472,8 +472,8 @@ void ConvertModel_215_to_216(ModelData &model)
memcpy(&g_model.header, &oldModel.header, sizeof(g_model.header)); memcpy(&g_model.header, &oldModel.header, sizeof(g_model.header));
for (uint8_t i=0; i<2; i++) { for (uint8_t i=0; i<2; i++) {
TimerData & timer = g_model.timers[i]; TimerData & timer = g_model.timers[i];
if (oldModel.timers[i].mode >= TMRMODE_FIRST_SWITCH) if (oldModel.timers[i].mode >= TMRMODE_COUNT)
timer.mode = TMRMODE_FIRST_SWITCH + ConvertSwitch_215_to_216(oldModel.timers[i].mode - TMRMODE_FIRST_SWITCH + 1) - 1; timer.mode = TMRMODE_COUNT + ConvertSwitch_215_to_216(oldModel.timers[i].mode - TMRMODE_COUNT + 1) - 1;
else else
timer.mode = oldModel.timers[i].mode; timer.mode = oldModel.timers[i].mode;
timer.start = oldModel.timers[i].start; timer.start = oldModel.timers[i].start;

View file

@ -1120,7 +1120,7 @@ void menuModelSetup(uint8_t event)
div_t qr = div(timer->start, 60); div_t qr = div(timer->start, 60);
switch (m_posHorz) { switch (m_posHorz) {
case 0: case 0:
CHECK_INCDEC_MODELVAR(event, timer->mode, SWSRC_FIRST, TMR_VAROFS+SWSRC_LAST-1); CHECK_INCDEC_MODELVAR_CHECK(event, timer->mode, SWSRC_FIRST, TMRMODE_COUNT+SWSRC_LAST-1/*SWSRC_None removed*/, isSwitchAvailableInTimers);
break; break;
case 1: case 1:
CHECK_INCDEC_MODELVAR_ZERO(event, qr.quot, 59); CHECK_INCDEC_MODELVAR_ZERO(event, qr.quot, 59);
@ -1940,7 +1940,7 @@ void menuModelFlightModesAll(uint8_t event)
case ITEM_FLIGHT_MODES_SWITCH: case ITEM_FLIGHT_MODES_SWITCH:
putsSwitches((5+LEN_FP_NAME)*FW+FW/2, y, p->swtch, attr); putsSwitches((5+LEN_FP_NAME)*FW+FW/2, y, p->swtch, attr);
if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, SWSRC_FIRST_SHORT_LIST, SWSRC_LAST_SHORT_LIST); if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableInMixes);
break; break;
case ITEM_FLIGHT_MODES_TRIM_RUD: case ITEM_FLIGHT_MODES_TRIM_RUD:
@ -4691,8 +4691,8 @@ void menuModelLogicalSwitches(uint8_t event)
if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) { if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1); putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1);
putsSwitches(CSW_3RD_COLUMN, y, cs->v2, attr2); putsSwitches(CSW_3RD_COLUMN, y, cs->v2, attr2);
v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1; v1_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v1_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
v2_min = SWSRC_OFF+1; v2_max = SWSRC_ON-1; v2_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v2_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
INCDEC_SET_FLAG(INCDEC_SWITCH); INCDEC_SET_FLAG(INCDEC_SWITCH);
INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches); INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
} }
@ -4707,12 +4707,12 @@ void menuModelLogicalSwitches(uint8_t event)
else else
lcd_outdezAtt(lcdLastPos+3, y, lswTimerValue(cs->v2+cs->v3), LEFT|PREC1|(horz==LS_FIELD_V3 ? attr : 0)); lcd_outdezAtt(lcdLastPos+3, y, lswTimerValue(cs->v2+cs->v3), LEFT|PREC1|(horz==LS_FIELD_V3 ? attr : 0));
lcd_putc(lcdLastPos, y, ']'); lcd_putc(lcdLastPos, y, ']');
v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1; v1_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v1_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
v2_min=-129; v2_max = 122; v2_min=-129; v2_max = 122;
v3_max = 222 - cs->v2; v3_max = 222 - cs->v2;
if (horz == 1) { if (horz == 1) {
INCDEC_SET_FLAG(INCDEC_SWITCH); INCDEC_SET_FLAG(INCDEC_SWITCH);
INCDEC_ENABLE_CHECK(isSwitchAvailable); INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
} }
else { else {
INCDEC_SET_FLAG(0); INCDEC_SET_FLAG(0);
@ -5042,7 +5042,7 @@ void menuModelCustomFunctions(uint8_t event)
switch (j) { switch (j) {
case 0: case 0:
putsSwitches(MODEL_CUSTOM_FUNC_1ST_COLUMN, y, CFN_SWITCH(sd), attr | ((activeFnSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0)); putsSwitches(MODEL_CUSTOM_FUNC_1ST_COLUMN, y, CFN_SWITCH(sd), attr | ((activeFnSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0));
if (active || AUTOSWITCH_ENTER_LONG()) CHECK_INCDEC_MODELSWITCH(event, CFN_SWITCH(sd), SWSRC_FIRST, SWSRC_LAST); if (active || AUTOSWITCH_ENTER_LONG()) CHECK_INCDEC_MODELSWITCH(event, CFN_SWITCH(sd), SWSRC_FIRST, SWSRC_LAST, isSwitchAvailableInCustomFunctions);
break; break;
case 1: case 1:

View file

@ -1117,7 +1117,7 @@ int8_t switchMenuItem(uint8_t x, uint8_t y, int8_t value, LcdFlags attr, uint8_t
{ {
lcd_putsColumnLeft(x, y, STR_SWITCH); lcd_putsColumnLeft(x, y, STR_SWITCH);
putsSwitches(x, y, value, attr); putsSwitches(x, y, value, attr);
if (attr) CHECK_INCDEC_MODELSWITCH(event, value, SWSRC_FIRST_SHORT_LIST, SWSRC_LAST_SHORT_LIST); if (attr) CHECK_INCDEC_MODELSWITCH(event, value, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableInMixes);
return value; return value;
} }
@ -1488,17 +1488,25 @@ bool isInputSourceAvailable(int source)
return false; return false;
} }
bool isSwitchAvailableInLogicalSwitches(int swtch) enum SwitchContext
{
LogicalSwitchesContext,
CustomFunctionsContext,
TimersContext,
MixesContext
};
bool isSwitchAvailable(int swtch, SwitchContext context)
{ {
if (swtch < 0) { if (swtch < 0) {
if (swtch <= -SWSRC_ON)
return false;
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
else if (swtch == -SWSRC_SF0 || swtch == -SWSRC_SF2 || swtch == -SWSRC_SH0 || swtch == -SWSRC_SH2) if (swtch == -SWSRC_SF0 || swtch == -SWSRC_SF2 || swtch == -SWSRC_SH0 || swtch == -SWSRC_SH2)
return false; return false;
#endif #endif
else if (swtch == -SWSRC_ON || swtch == -SWSRC_One) {
swtch = -swtch; return false;
}
swtch = -swtch;
} }
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
@ -1514,27 +1522,59 @@ bool isSwitchAvailableInLogicalSwitches(int swtch)
} }
#endif #endif
return true; if (context != LogicalSwitchesContext && swtch >= SWSRC_FIRST_LOGICAL_SWITCH && swtch <= SWSRC_LAST_LOGICAL_SWITCH) {
}
bool isSwitchAvailable(int swtch)
{
if (!isSwitchAvailableInLogicalSwitches(swtch)) {
return false;
}
if (swtch < 0) {
swtch = -swtch;
}
if (swtch >= SWSRC_FIRST_LOGICAL_SWITCH && swtch <= SWSRC_LAST_LOGICAL_SWITCH) {
LogicalSwitchData * cs = lswAddress(swtch-SWSRC_FIRST_LOGICAL_SWITCH); LogicalSwitchData * cs = lswAddress(swtch-SWSRC_FIRST_LOGICAL_SWITCH);
return (cs->func != LS_FUNC_NONE); return (cs->func != LS_FUNC_NONE);
} }
if (context != CustomFunctionsContext && (swtch == SWSRC_ON || swtch == SWSRC_One)) {
return false;
}
if (swtch >= SWSRC_FIRST_FLIGHT_MODE && swtch <= SWSRC_LAST_FLIGHT_MODE) {
if (context == MixesContext) {
return false;
}
else {
swtch -= SWSRC_FIRST_FLIGHT_MODE;
if (swtch == 0) {
return true;
}
FlightModeData * fm = flightModeAddress(swtch);
return (fm->swtch != SWSRC_NONE);
}
}
return true; return true;
} }
bool isSwitchAvailableInLogicalSwitches(int swtch)
{
return isSwitchAvailable(swtch, LogicalSwitchesContext);
}
bool isSwitchAvailableInCustomFunctions(int swtch)
{
return isSwitchAvailable(swtch, CustomFunctionsContext);
}
bool isSwitchAvailableInMixes(int swtch)
{
return isSwitchAvailable(swtch, MixesContext);
}
bool isSwitchAvailableInTimers(int swtch)
{
if (swtch >= 0) {
if (swtch < TMRMODE_COUNT) {
return true;
}
swtch -= TMRMODE_COUNT-1;
}
return isSwitchAvailable(swtch, TimersContext);
}
bool isThrottleSourceAvailable(int source) bool isThrottleSourceAvailable(int source)
{ {
#if defined(PCBTARANIS) #if defined(PCBTARANIS)

View file

@ -209,9 +209,13 @@ int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max);
var = checkIncDecModelZero(event,var,max) var = checkIncDecModelZero(event,var,max)
#if defined(CPUARM) #if defined(CPUARM)
#define CHECK_INCDEC_MODELVAR_CHECK(event, var, min, max, check) \
var = checkIncDec(event, var, min, max, EE_MODEL, check)
#define CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, var, max, check) \ #define CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, var, max, check) \
var = checkIncDec(event, var, 0, max, EE_MODEL, check) var = checkIncDec(event, var, 0, max, EE_MODEL, check)
#else #else
#define CHECK_INCDEC_MODELVAR_CHECK(event, var, min, max, check) \
var = checkIncDec(event, var, min, max, EE_MODEL)
#define CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, var, max, check) \ #define CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, var, max, check) \
CHECK_INCDEC_MODELVAR_ZERO(event, var, max) CHECK_INCDEC_MODELVAR_ZERO(event, var, max)
#endif #endif
@ -220,19 +224,22 @@ int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max);
bool isThrottleSourceAvailable(int source); bool isThrottleSourceAvailable(int source);
bool isLogicalSwitchFunctionAvailable(int function); bool isLogicalSwitchFunctionAvailable(int function);
bool isAssignableFunctionAvailable(int function); bool isAssignableFunctionAvailable(int function);
bool isSwitchAvailable(int swtch);
bool isSwitchAvailableInLogicalSwitches(int swtch); bool isSwitchAvailableInLogicalSwitches(int swtch);
bool isSwitchAvailableInCustomFunctions(int swtch);
bool isSwitchAvailableInMixes(int swtch);
bool isSwitchAvailableInTimers(int swtch);
bool isModuleAvailable(int module); bool isModuleAvailable(int module);
#define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER)) #define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER))
#define CHECK_INCDEC_MODELSWITCH(event, var, min, max) \ #define CHECK_INCDEC_MODELSWITCH(event, var, min, max, available) \
var = checkIncDec(event,var,min,max,EE_MODEL|INCDEC_SWITCH|NO_INCDEC_MARKS, isSwitchAvailable) var = checkIncDec(event,var,min,max,EE_MODEL|INCDEC_SWITCH|NO_INCDEC_MARKS, available)
#elif defined(AUTOSWITCH) #elif defined(AUTOSWITCH)
#define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER)) #define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER))
#define CHECK_INCDEC_MODELSWITCH(event, var, min, max) \ #define CHECK_INCDEC_MODELSWITCH(event, var, min, max, available) \
var = checkIncDec(event,var,min,max,EE_MODEL|INCDEC_SWITCH) var = checkIncDec(event,var,min,max,EE_MODEL|INCDEC_SWITCH)
#else #else
#define AUTOSWITCH_ENTER_LONG() (0) #define AUTOSWITCH_ENTER_LONG() (0)
#define CHECK_INCDEC_MODELSWITCH CHECK_INCDEC_MODELVAR #define CHECK_INCDEC_MODELSWITCH(event, var, min, max, available) \
CHECK_INCDEC_MODELVAR(event, var, min, max)
#endif #endif
#if defined(CPUARM) #if defined(CPUARM)

View file

@ -843,10 +843,10 @@ void putsCurve(xcoord_t x, uint8_t y, int8_t idx, LcdFlags att)
void putsTimerMode(xcoord_t x, uint8_t y, int8_t mode, LcdFlags att) void putsTimerMode(xcoord_t x, uint8_t y, int8_t mode, LcdFlags att)
{ {
if (mode >= 0) { if (mode >= 0) {
if (mode < TMR_VAROFS) if (mode < TMRMODE_COUNT)
return lcd_putsiAtt(x, y, STR_VTMRMODES, mode, att); return lcd_putsiAtt(x, y, STR_VTMRMODES, mode, att);
else else
mode -= (TMR_VAROFS-1); mode -= (TMRMODE_COUNT-1);
} }
putsSwitches(x, y, mode, att); putsSwitches(x, y, mode, att);
} }

View file

@ -1451,8 +1451,15 @@ enum SwitchSources {
SWSRC_LAST = SWSRC_COUNT-1, SWSRC_LAST = SWSRC_COUNT-1,
SWSRC_FIRST = -SWSRC_LAST, SWSRC_FIRST = -SWSRC_LAST,
SWSRC_LAST_SHORT_LIST = SWSRC_LAST_LOGICAL_SWITCH, #if defined(CPUARM)
SWSRC_FIRST_SHORT_LIST = -SWSRC_LAST_SHORT_LIST, SWSRC_LAST_IN_LOGICAL_SWITCHES = SWSRC_LAST_FLIGHT_MODE,
SWSRC_LAST_IN_MIXES = SWSRC_LAST_FLIGHT_MODE,
#else
SWSRC_LAST_IN_LOGICAL_SWITCHES = SWSRC_LAST_LOGICAL_SWITCH,
SWSRC_LAST_IN_MIXES = SWSRC_LAST_LOGICAL_SWITCH,
#endif
SWSRC_FIRST_IN_LOGICAL_SWITCHES = -SWSRC_LAST_IN_LOGICAL_SWITCHES,
SWSRC_FIRST_IN_MIXES = -SWSRC_LAST_IN_MIXES,
}; };
enum MixSources { enum MixSources {
@ -1610,12 +1617,14 @@ enum TimerModes {
TMRMODE_THR, TMRMODE_THR,
TMRMODE_THR_REL, TMRMODE_THR_REL,
TMRMODE_THR_TRG, TMRMODE_THR_TRG,
TMRMODE_FIRST_SWITCH TMRMODE_COUNT
}; };
#define COUNTDOWN_SILENT 0 enum CountDownModes {
#define COUNTDOWN_BEEPS 1 COUNTDOWN_SILENT,
#define COUNTDOWN_VOICE 2 COUNTDOWN_BEEPS,
COUNTDOWN_VOICE
};
#if defined(CPUARM) || defined(CPUM2560) #if defined(CPUARM) || defined(CPUM2560)
PACK(typedef struct t_TimerData { PACK(typedef struct t_TimerData {

View file

@ -2322,7 +2322,7 @@ void doMixerCalculations()
} }
} }
else { else {
if (tm > 0) tm -= (TMR_VAROFS-1); if (tm > 0) tm -= (TMRMODE_COUNT-1);
if (getSwitch(tm)) if (getSwitch(tm))
newTimerVal++; newTimerVal++;
} }

View file

@ -1085,8 +1085,6 @@ extern int16_t calcRESXto1000(int16_t x);
extern int8_t calcRESXto100(int16_t x); extern int8_t calcRESXto100(int16_t x);
#endif #endif
#define TMR_VAROFS 5
extern const char vers_stamp[]; extern const char vers_stamp[];
extern uint8_t g_vbat100mV; extern uint8_t g_vbat100mV;