1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00

Companion switches / anas names configuration

This commit is contained in:
bsongis 2014-11-16 13:06:46 +01:00
parent 06437b2954
commit 50978c15c5
21 changed files with 1206 additions and 297 deletions

View file

@ -519,7 +519,7 @@ void burnDialog::on_BurnFlashButton_clicked()
byte8u=(uint8_t)BeeperSet.mid(0,2).toUInt(&ok,16);
if (ok)
radioData.generalSettings.beeperMode=(BeeperMode)byte8u;
radioData.generalSettings.beeperMode=(GeneralSettings::BeeperMode)byte8u;
byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16);
if (ok)
@ -527,7 +527,7 @@ void burnDialog::on_BurnFlashButton_clicked()
byte8u=(uint8_t)HapticSet.mid(0,2).toUInt(&ok,16);
if (ok)
radioData.generalSettings.hapticMode=(BeeperMode)byte8u;
radioData.generalSettings.hapticMode=(GeneralSettings::BeeperMode)byte8u;
byte8u=(uint8_t)HapticSet.mid(2,2).toUInt(&ok,16);
if (ok)

View file

@ -15,7 +15,7 @@
std::list<QString> EEPROMWarnings;
const char * switches9X[] = { "3POS", "THR", "RUD", "ELE", "AIL", "GEA", "TRN" };
const char * switchesX9D[] = { "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH" };
const char * switchesX9D[] = { "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN" };
const char leftArrow[] = {(char)0xE2, (char)0x86, (char)0x90, 0};
const char rightArrow[] = {(char)0xE2, (char)0x86, (char)0x92, 0};
const char upArrow[] = {(char)0xE2, (char)0x86, (char)0x91, 0};
@ -531,6 +531,12 @@ QString RawSwitch::toString()
SwitchUp('F'), SwitchDn('F'),
SwitchUp('G'), QString::fromUtf8("SG-"), SwitchDn('G'),
SwitchUp('H'), SwitchDn('H'),
SwitchUp('I'), SwitchDn('I'),
SwitchUp('J'), SwitchDn('J'),
SwitchUp('K'), SwitchDn('K'),
SwitchUp('L'), SwitchDn('L'),
SwitchUp('M'), SwitchDn('M'),
SwitchUp('N'), SwitchDn('N'),
};
static const QString logicalSwitches[] = {
@ -976,6 +982,33 @@ void LimitData::clear()
max = +1000;
}
GeneralSettings::SwitchInfo GeneralSettings::switchInfoFromSwitchPositionTaranis(unsigned int index)
{
if (index <= 3*5)
return SwitchInfo((index-1)/3, (index-1)%3);
else if (index <= 17)
return SwitchInfo(5, index==17 ? 2 : 0);
else if (index <= 20)
return SwitchInfo(6, index-18);
else
return SwitchInfo(7+(index-21)/2, 2*((index-21)%2));
}
bool GeneralSettings::switchPositionAllowedTaranis(int index) const
{
if (index == 0)
return true;
SwitchInfo info = switchInfoFromSwitchPositionTaranis(abs(index));
if (index < 0 && switchConfigTaranis(info.index) != SWITCH_3POS)
return false;
else if (info.index >= 8)
return switchConfigTaranis(info.index-8) == SWITCH_2x2POS;
else if (info.position == 1)
return switchConfigTaranis(info.index) == SWITCH_3POS;
else
return true;
}
GeneralSettings::GeneralSettings()
{
memset(this, 0, sizeof(GeneralSettings));

View file

@ -126,7 +126,14 @@ enum Switches {
SWITCH_SG1,
SWITCH_SG2,
SWITCH_SH0,
SWITCH_SH1
SWITCH_SH2,
SWITCH_SI0,
SWITCH_SI2,
SWITCH_SJ0,
SWITCH_SJ2,
SWITCH_SK0,
SWITCH_SK2,
};
enum TimerModes {
@ -1007,7 +1014,7 @@ class ModelData {
unsigned int thrTraceSrc;
unsigned int modelId;
unsigned int switchWarningStates;
unsigned int nSwToWarn;
unsigned int switchWarningEnable;
unsigned int nPotsToWarn;
int potPosition[C9X_NUM_POTS];
bool displayChecklist;
@ -1070,15 +1077,24 @@ class TrainerData {
void clear() { memset(this, 0, sizeof(TrainerData)); }
};
enum BeeperMode {
e_quiet = -2,
e_alarms_only = -1,
e_no_keys = 0,
e_all = 1
};
class GeneralSettings {
public:
enum BeeperMode {
BEEPER_QUIET = -2,
BEEPER_ALARMS_ONLY = -1,
BEEPER_NOKEYS = 0,
BEEPER_ALL = 1
};
enum SwitchConfig {
SWITCH_DEFAULT,
SWITCH_TOGGLE,
SWITCH_2POS,
SWITCH_3POS,
SWITCH_2x2POS
};
GeneralSettings();
int getDefaultStick(unsigned int channel) const;
@ -1166,6 +1182,49 @@ class GeneralSettings {
unsigned int potsType[8];
unsigned int backlightColor;
CustomFunctionData customFn[C9X_MAX_CUSTOM_FUNCTIONS];
unsigned int switchConfig[8];
char switchNames[32][3+1];
char anaNames[32][3+1];
struct SwitchInfo {
SwitchInfo(unsigned int index, unsigned int position):
index(index),
position(position)
{
}
unsigned int index;
unsigned int position;
};
static SwitchInfo switchInfoFromSwitchPositionTaranis(unsigned int index);
bool switchPositionAllowedTaranis(int index) const;
static unsigned int switchDefaultConfigTaranis(unsigned int index)
{
if (index == 5)
return SWITCH_2POS;
else if (index == 7)
return SWITCH_TOGGLE;
else
return SWITCH_3POS;
}
unsigned int switchConfigTaranis(unsigned int index) const
{
unsigned int result = switchConfig[index];
if (result == SWITCH_DEFAULT)
result = switchDefaultConfigTaranis(index);
return result;
}
bool isSwitchWarningAllowedTaranis(unsigned int index) const
{
if (index < 8)
return switchConfigTaranis(index) != SWITCH_TOGGLE;
else
return switchConfig[index-8] == SWITCH_2x2POS;
}
};
class RadioData {

View file

@ -85,13 +85,13 @@ Er9xGeneral::operator GeneralSettings ()
switch (beeperVal) {
case 0:
result.beeperMode = e_quiet;
result.beeperMode = GeneralSettings::BEEPER_QUIET;
break;
case 1:
result.beeperMode = e_no_keys;
result.beeperMode = GeneralSettings::BEEPER_NOKEYS;
break;
default:
result.beeperMode = e_all;
result.beeperMode = GeneralSettings::BEEPER_ALL;
result.beeperLength = beeperVal - 4;
break;
}

View file

@ -105,13 +105,13 @@ Ersky9xGeneral::operator GeneralSettings ()
switch (beeperVal) {
case 0:
result.beeperMode = e_quiet;
result.beeperMode = GeneralSettings::BEEPER_QUIET;
break;
case 1:
result.beeperMode = e_no_keys;
result.beeperMode = GeneralSettings::BEEPER_NOKEYS;
break;
default:
result.beeperMode = e_all;
result.beeperMode = GeneralSettings::BEEPER_ALL;
result.beeperLength = beeperVal - 4;
break;
}

View file

@ -88,13 +88,13 @@ Gruvin9xGeneral_v103::operator GeneralSettings ()
switch (beeperVal) {
case 0:
result.beeperMode = e_quiet;
result.beeperMode = GeneralSettings::BEEPER_QUIET;
break;
case 1:
result.beeperMode = e_no_keys;
result.beeperMode = GeneralSettings::BEEPER_NOKEYS;
break;
default:
result.beeperMode = e_all;
result.beeperMode = GeneralSettings::BEEPER_ALL;
result.beeperLength = beeperVal - 4;
break;
}
@ -142,7 +142,7 @@ Gruvin9xGeneral_v104::operator GeneralSettings ()
result.view = view;
result.disableThrottleWarning = disableThrottleWarning;
result.switchWarning = switchWarning;
result.beeperMode = (BeeperMode)beeperVal;
result.beeperMode = (GeneralSettings::BeeperMode)beeperVal;
result.disableMemoryWarning = disableMemoryWarning;
result.disableAlarmWarning = disableAlarmWarning;
result.stickMode = stickMode;

View file

@ -12,8 +12,8 @@
#define HAS_LARGE_LCD(board) IS_TARANIS(board)
#define MAX_VIEWS(board) (HAS_LARGE_LCD(board) ? 2 : 256)
#define MAX_POTS(board) (IS_TARANIS(board) ? 5 : 3)
#define MAX_SWITCHES(board) (IS_TARANIS(board) ? 8 : 7)
#define MAX_SWITCHES_POSITION(board) (IS_TARANIS(board) ? 22 : 9)
#define MAX_SWITCHES(board, version) (version >= 217 ? (IS_TARANIS(board) ? 8+6 : 7) : (IS_TARANIS(board) ? 8 : 7))
#define MAX_SWITCHES_POSITION(board, version) (IS_TARANIS(board) ? (version >= 217 ? 22+12 : 22) : 9)
#define MAX_ROTARY_ENCODERS(board) (board==BOARD_GRUVIN9X ? 2 : (IS_SKY9X(board) ? 1 : 0))
#define MAX_FLIGHT_MODES(board, version) (IS_ARM(board) ? 9 : (IS_DBLRAM(board, version) ? 6 : 5))
#define MAX_TIMERS(board, version) ((IS_ARM(board) && version >= 217) ? 3 : 2)
@ -56,7 +56,7 @@ class SwitchesConversionTable: public ConversionTable {
addConversion(RawSwitch(SWITCH_TYPE_NONE), val++);
}
for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) {
for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) {
int s = switchIndex(i, board, version);
addConversion(RawSwitch(SWITCH_TYPE_SWITCH, s), val);
if (IS_TARANIS(board) && s>=21/*SHup/SHdown*/) {
@ -110,7 +110,7 @@ class SwitchesConversionTable: public ConversionTable {
if (version < 216) {
// previous "moment" switches
for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) {
for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) {
int s = switchIndex(i, board, version);
addConversion(RawSwitch(SWITCH_TYPE_SWITCH, s), val++);
}
@ -241,7 +241,7 @@ class SourcesConversionTable: public ConversionTable {
if (!(flags & FLAG_NOSWITCHES)) {
if (afterrelease21March2013) {
for (int i=1; i<MAX_SWITCHES(board); i++)
for (int i=1; i<MAX_SWITCHES(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_SWITCH, i), val++);
}
else {
@ -1548,7 +1548,7 @@ class AndSwitchesConversionTable: public ConversionTable {
addConversion(RawSwitch(SWITCH_TYPE_NONE), val++);
if (IS_TARANIS(board)) {
for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) {
for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) {
int s = switchIndex(i, board, version);
addConversion(RawSwitch(SWITCH_TYPE_SWITCH, -s), -val);
addConversion(RawSwitch(SWITCH_TYPE_SWITCH, s), val++);
@ -2856,14 +2856,18 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
internalField.Append(new UnsignedField<8>(modelData.modelId));
}
if (IS_TARANIS(board))
if (IS_TARANIS(board) && version >= 217)
internalField.Append(new SwitchesWarningField<32>(modelData.switchWarningStates, board, version));
else if (IS_TARANIS(board))
internalField.Append(new SwitchesWarningField<16>(modelData.switchWarningStates, board, version));
else
internalField.Append(new SwitchesWarningField<8>(modelData.switchWarningStates, board, version));
if (version >= 216) {
internalField.Append(new UnsignedField<8>(modelData.nSwToWarn));
}
if (IS_TARANIS(board) && version >= 217)
internalField.Append(new UnsignedField<16>(modelData.switchWarningEnable));
else if (version >= 216)
internalField.Append(new UnsignedField<8>(modelData.switchWarningEnable));
if ((board == BOARD_STOCK || (board == BOARD_M128 && version >= 215)) && (variant & GVARS_VARIANT)) {
for (int i=0; i<MAX_GVARS(board, version); i++) {
@ -3174,14 +3178,31 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, BoardEnum bo
}
internalField.Append(new UnsignedField<8>(generalData.backlightColor));
}
if (version >= 216) {
if (IS_TARANIS(board)) {
if (version >= 217)
internalField.Append(new SpareBitsField<32>());
else
internalField.Append(new SpareBitsField<16>());
}
if (version >= 217) {
for (int i=0; i<MAX_CUSTOM_FUNCTIONS(board, version); i++) {
internalField.Append(new ArmCustomFunctionField(generalData.customFn[i], board, version, variant));
}
}
if (IS_TARANIS(board) && version >= 217) {
for (int i=0; i<8; i++) {
internalField.Append(new UnsignedField<4>(generalData.switchConfig[i]));
}
for (int i=0; i<MAX_SWITCHES(board, version); ++i) {
internalField.Append(new ZCharField<3>(generalData.switchNames[i]));
}
for (int i=0; i<NUM_STICKS+MAX_POTS(board); ++i) {
internalField.Append(new ZCharField<3>(generalData.anaNames[i]));
}
}
}
}

View file

@ -571,9 +571,9 @@ int OpenTxFirmware::getCapability(const Capability capability)
case Pots:
return (IS_TARANIS(board) ? 5 : 3);
case Switches:
return (IS_TARANIS(board) ? 8 : 7);
return (IS_TARANIS(board) ? 8+6 : 7);
case SwitchesPositions:
return (IS_TARANIS(board) ? 22 : 9);
return (IS_TARANIS(board) ? 22+12 : 9);
case CustomFunctions:
if (IS_TARANIS(board))
return 64;

View file

@ -71,16 +71,16 @@ Th9xGeneral::operator GeneralSettings ()
result.disableMemoryWarning = disableMemoryWarning;
switch (beeperVal) {
case 0:
result.beeperMode = e_quiet;
result.beeperMode = GeneralSettings::BEEPER_QUIET;
break;
case 1:
result.beeperMode = e_no_keys;
result.beeperMode = GeneralSettings::BEEPER_NOKEYS;
break;
case 2:
result.beeperMode = e_all;
result.beeperMode = GeneralSettings::BEEPER_ALL;
break;
case 3:
result.beeperMode = e_all;
result.beeperMode = GeneralSettings::BEEPER_ALL;
result.beeperLength = 2;
}
result.stickMode = stickMode;

View file

@ -20,6 +20,93 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSe
ui->pot2TypeLabel->hide();
ui->pot3Type->hide();
ui->pot3TypeLabel->hide();
ui->pot4Label->hide();
ui->pot5Label->hide();
}
if (IS_TARANIS(firmware->getBoard())) {
ui->rudName->setField(generalSettings.anaNames[0], 3, this);
ui->eleName->setField(generalSettings.anaNames[1], 3, this);
ui->thrName->setField(generalSettings.anaNames[2], 3, this);
ui->ailName->setField(generalSettings.anaNames[3], 3, this);
ui->pot1Name->setField(generalSettings.anaNames[4], 3, this);
ui->pot2Name->setField(generalSettings.anaNames[5], 3, this);
ui->pot3Name->setField(generalSettings.anaNames[6], 3, this);
ui->pot4Name->setField(generalSettings.anaNames[7], 3, this);
ui->pot5Name->setField(generalSettings.anaNames[8], 3, this);
ui->saName->setField(generalSettings.switchNames[0], 3, this);
ui->saType->setField(generalSettings.switchConfig[0], this);
ui->sbName->setField(generalSettings.switchNames[1], 3, this);
ui->sbType->setField(generalSettings.switchConfig[1], this);
ui->scName->setField(generalSettings.switchNames[2], 3, this);
ui->scType->setField(generalSettings.switchConfig[2], this);
ui->sdName->setField(generalSettings.switchNames[3], 3, this);
ui->sdType->setField(generalSettings.switchConfig[3], this);
ui->seName->setField(generalSettings.switchNames[4], 3, this);
ui->seType->setField(generalSettings.switchConfig[4], this);
ui->sfName->setField(generalSettings.switchNames[5], 3, this);
ui->sfType->setField(generalSettings.switchConfig[5], this);
ui->sgName->setField(generalSettings.switchNames[6], 3, this);
ui->sgType->setField(generalSettings.switchConfig[6], this);
ui->shName->setField(generalSettings.switchNames[7], 3, this);
ui->shType->setField(generalSettings.switchConfig[7], this);
ui->siName->setField(generalSettings.switchNames[8], 3, this);
ui->sjName->setField(generalSettings.switchNames[9], 3, this);
ui->skName->setField(generalSettings.switchNames[10], 3, this);
ui->slName->setField(generalSettings.switchNames[11], 3, this);
ui->smName->setField(generalSettings.switchNames[12], 3, this);
ui->snName->setField(generalSettings.switchNames[13], 3, this);
connect(ui->saType, SIGNAL(currentIndexChanged(int)), this, SLOT(update()));
connect(ui->sbType, SIGNAL(currentIndexChanged(int)), this, SLOT(update()));
connect(ui->scType, SIGNAL(currentIndexChanged(int)), this, SLOT(update()));
connect(ui->sdType, SIGNAL(currentIndexChanged(int)), this, SLOT(update()));
connect(ui->seType, SIGNAL(currentIndexChanged(int)), this, SLOT(update()));
connect(ui->sgType, SIGNAL(currentIndexChanged(int)), this, SLOT(update()));
}
else {
ui->rudLabel->hide();
ui->rudName->hide();
ui->eleLabel->hide();
ui->eleName->hide();
ui->thrLabel->hide();
ui->thrName->hide();
ui->ailLabel->hide();
ui->ailName->hide();
ui->pot1Name->hide();
ui->pot2Name->hide();
ui->pot3Name->hide();
ui->pot4Name->hide();
ui->pot5Name->hide();
ui->saLabel->hide();
ui->saName->hide();
ui->saType->hide();
ui->sbLabel->hide();
ui->sbName->hide();
ui->sbType->hide();
ui->scLabel->hide();
ui->scName->hide();
ui->scType->hide();
ui->sdLabel->hide();
ui->sdName->hide();
ui->sdType->hide();
ui->seLabel->hide();
ui->seName->hide();
ui->seType->hide();
ui->sfLabel->hide();
ui->sfName->hide();
ui->sfType->hide();
ui->sgLabel->hide();
ui->sgName->hide();
ui->sgType->hide();
ui->shLabel->hide();
ui->shName->hide();
ui->shType->hide();
ui->siName->hide();
ui->sjName->hide();
ui->skName->hide();
ui->slName->hide();
ui->smName->hide();
ui->snName->hide();
}
int potsCount = GetCurrentFirmware()->getCapability(Pots);
@ -46,6 +133,22 @@ CalibrationPanel::~CalibrationPanel()
delete ui;
}
void CalibrationPanel::update()
{
ui->siLabel->setVisible(generalSettings.switchConfig[0] == GeneralSettings::SWITCH_2x2POS);
ui->siName->setVisible(generalSettings.switchConfig[0] == GeneralSettings::SWITCH_2x2POS);
ui->sjLabel->setVisible(generalSettings.switchConfig[1] == GeneralSettings::SWITCH_2x2POS);
ui->sjName->setVisible(generalSettings.switchConfig[1] == GeneralSettings::SWITCH_2x2POS);
ui->skLabel->setVisible(generalSettings.switchConfig[2] == GeneralSettings::SWITCH_2x2POS);
ui->skName->setVisible(generalSettings.switchConfig[2] == GeneralSettings::SWITCH_2x2POS);
ui->slLabel->setVisible(generalSettings.switchConfig[3] == GeneralSettings::SWITCH_2x2POS);
ui->slName->setVisible(generalSettings.switchConfig[3] == GeneralSettings::SWITCH_2x2POS);
ui->smLabel->setVisible(generalSettings.switchConfig[4] == GeneralSettings::SWITCH_2x2POS);
ui->smName->setVisible(generalSettings.switchConfig[4] == GeneralSettings::SWITCH_2x2POS);
ui->snLabel->setVisible(generalSettings.switchConfig[6] == GeneralSettings::SWITCH_2x2POS);
ui->snName->setVisible(generalSettings.switchConfig[6] == GeneralSettings::SWITCH_2x2POS);
}
void CalibrationPanel::on_PPM_MultiplierDSB_editingFinished()
{
generalSettings.PPM_Multiplier = (int)(ui->PPM_MultiplierDSB->value()*10)-10;

View file

@ -14,6 +14,7 @@ class CalibrationPanel : public GeneralPanel
public:
CalibrationPanel(QWidget *parent, GeneralSettings & generalSettings, FirmwareInterface * firmware);
virtual ~CalibrationPanel();
virtual void update();
private slots:
void on_battCalibDSB_editingFinished();
@ -52,10 +53,10 @@ class CalibrationPanel : public GeneralPanel
void on_ana7Pos_editingFinished();
void on_ana8Pos_editingFinished();
void on_pot1Type_currentIndexChanged(int index);
void on_pot2Type_currentIndexChanged(int index);
void on_pot3Type_currentIndexChanged(int index);
void on_serialPortMode_currentIndexChanged(int index);
private:

File diff suppressed because it is too large Load diff

View file

@ -142,13 +142,13 @@ void GeneralEdit::on_calretrieve_PB_clicked()
generalSettings.backlightBright=byte8u;
byte8=(int8_t)BeeperSet.mid(0,2).toUInt(&ok,16);
if (ok)
generalSettings.beeperMode=(BeeperMode)byte8;
generalSettings.beeperMode = (GeneralSettings::BeeperMode)byte8;
byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16);
if (ok)
generalSettings.beeperLength=byte8;
byte8=(int8_t)HapticSet.mid(0,2).toUInt(&ok,16);
if (ok)
generalSettings.hapticMode=(BeeperMode)byte8;
generalSettings.hapticMode=(GeneralSettings::BeeperMode)byte8;
byte8=(int8_t)HapticSet.mid(2,2).toInt(&ok,16);
if (ok)
generalSettings.hapticStrength=byte8;

View file

@ -553,7 +553,7 @@ void GeneralSetupPanel::on_alarmwarnChkB_stateChanged(int )
void GeneralSetupPanel::on_beeperCB_currentIndexChanged(int index)
{
generalSettings.beeperMode = (BeeperMode)(index-2);
generalSettings.beeperMode = (GeneralSettings::BeeperMode)(index-2);
emit modified();
}
@ -565,7 +565,7 @@ void GeneralSetupPanel::on_displayTypeCB_currentIndexChanged(int index)
void GeneralSetupPanel::on_hapticmodeCB_currentIndexChanged(int index)
{
generalSettings.hapticMode = (BeeperMode)(index-2);
generalSettings.hapticMode = (GeneralSettings::BeeperMode)(index-2);
emit modified();
}

View file

@ -412,11 +412,9 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
}
for (int i=-GetCurrentFirmware()->getCapability(SwitchesPositions); i<0; i++) {
if (IS_TARANIS(GetCurrentFirmware()->getBoard()) && !generalSettings.switchPositionAllowedTaranis(i))
continue;
item = RawSwitch(SWITCH_TYPE_SWITCH, i);
if (IS_TARANIS(GetCurrentFirmware()->getBoard())) {
//hide up and down for !SH and !SF, because they are redundant (!SFup == SFdown)
if (item.toString().contains("H") || item.toString().contains("F")) continue;
}
b->addItem(item.toString(), item.toValue());
if (item == value) b->setCurrentIndex(b->count()-1);
}
@ -435,6 +433,8 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
}
for (int i=1; i<=GetCurrentFirmware()->getCapability(SwitchesPositions); i++) {
if (IS_TARANIS(GetCurrentFirmware()->getBoard()) && !generalSettings.switchPositionAllowedTaranis(i))
continue;
item = RawSwitch(SWITCH_TYPE_SWITCH, i);
b->addItem(item.toString(), item.toValue());
if (item == value) b->setCurrentIndex(b->count()-1);

View file

@ -458,10 +458,17 @@ SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & gen
}
// Startup switches warnings
for (int i=0; i<firmware->getCapability(Switches)-1; i++) {
for (int i=0; i<firmware->getCapability(Switches); i++) {
if (!IS_TARANIS(firmware->getBoard()) && i==firmware->getCapability(Switches)-1)
continue;
QLabel * label = new QLabel(this);
QSlider * slider = new QSlider(this);
QCheckBox * cb = new QCheckBox(this);
if (IS_TARANIS(firmware->getBoard()) && !generalSettings.isSwitchWarningAllowedTaranis(i)) {
label->hide();
slider->hide();
cb->hide();
}
slider->setProperty("index", i+1);
slider->setOrientation(Qt::Vertical);
slider->setMinimum(0);
@ -474,7 +481,7 @@ SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & gen
slider->setMaximumSize(QSize(50, 50));
if (IS_TARANIS(board)) {
label->setText(switchesX9D[i]);
slider->setMaximum(i==5 ? 1 : 2);
slider->setMaximum((i==5 || i>=7) ? 1 : 2);
}
else {
label->setText(switches9X[i]);
@ -677,17 +684,21 @@ void SetupPanel::updateStartupSwitches()
unsigned int switchStates = model->switchWarningStates;
for (int i=0; i<firmware->getCapability(Switches)-1; i++) {
for (int i=0; i<firmware->getCapability(Switches); i++) {
QSlider * slider = startupSwitchesSliders[i];
QCheckBox * cb = startupSwitchesCheckboxes[i];
bool enabled = !(model->nSwToWarn & (1 << i));
bool enabled = !(model->switchWarningEnable & (1 << i));
slider->setEnabled(enabled);
cb->setChecked(enabled);
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
slider->setValue(i==5 ? (switchStates & 0x3)/2 : switchStates & 0x3);
slider->setValue((i==5 || i>=7) ? (switchStates & 0x3)/2 : switchStates & 0x3);
switchStates >>= 2;
}
else {
if (i == firmware->getCapability(Switches)-1) {
// Trainer switch, no switch warning
continue;
}
slider->setValue(i==0 ? switchStates & 0x3 : switchStates & 0x1);
switchStates >>= (i==0 ? 2 : 1);
}
@ -704,7 +715,7 @@ void SetupPanel::startupSwitchEdited(int value)
int index = sender()->property("index").toInt();
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
if (index == 6) {
if (index == 6 || index >= 8) {
shift = (index - 1) * 2;
mask = 0x02 << shift;
shift++;
@ -741,9 +752,9 @@ void SetupPanel::startupSwitchToggled(bool checked)
int index = sender()->property("index").toInt()-1;
if (checked)
model->nSwToWarn &= ~(1 << index);
model->switchWarningEnable &= ~(1 << index);
else
model->nSwToWarn |= (1 << index);
model->switchWarningEnable |= (1 << index);
updateStartupSwitches();
emit modified();

View file

@ -12,6 +12,7 @@ set(shared_HDRS
autocombobox.h
autodoublespinbox.h
autohexspinbox.h
autolineedit.h
genericpanel.h
hexspinbox.h
verticalscrollarea.h

View file

@ -2,7 +2,7 @@
#define AUTOCOMBOBOX_H_
#include <QComboBox>
#include "modeledit/modeledit.h"
#include "genericpanel.h"
class AutoComboBox: public QComboBox
{
@ -35,7 +35,7 @@ class AutoComboBox: public QComboBox
lock = false;
}
void setField(unsigned int & field, ModelPanel * panel=NULL)
void setField(unsigned int & field, GenericPanel * panel=NULL)
{
this->field = (int *)&field;
this->panel = panel;
@ -46,7 +46,7 @@ class AutoComboBox: public QComboBox
}
}
void setField(int & field, ModelPanel * panel=NULL)
void setField(int & field, GenericPanel * panel=NULL)
{
this->field = &field;
this->panel = panel;
@ -70,7 +70,7 @@ class AutoComboBox: public QComboBox
protected:
int * field;
ModelPanel * panel;
GenericPanel * panel;
bool lock;
};

View file

@ -0,0 +1,60 @@
#ifndef AUTOLINEEDIT_H_
#define AUTOLINEEDIT_H_
#include <QLineEdit>
#include <QRegExpValidator>
#include "genericpanel.h"
#define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*"
class AutoLineEdit: public QLineEdit
{
Q_OBJECT
public:
explicit AutoLineEdit(QWidget *parent = 0):
QLineEdit(parent),
field(NULL),
panel(NULL),
lock(false)
{
QRegExp rx(CHAR_FOR_NAMES_REGEX);
setValidator(new QRegExpValidator(rx, this));
connect(this, SIGNAL(editingFinished()), this, SLOT(onEdited()));
}
void setField(char * field, int len, GenericPanel * panel=NULL)
{
this->field = field;
this->panel = panel;
setMaxLength(len);
updateValue();
}
void updateValue()
{
lock = true;
if (field) {
setText(field);
}
lock = false;
}
protected slots:
void onEdited()
{
if (field && !lock) {
strcpy(field, text().toAscii());
if (panel) {
emit panel->modified();
}
}
}
protected:
char * field;
GenericPanel * panel;
bool lock;
};
#endif /* AUTOLINEEDIT_H_ */

View file

@ -17,6 +17,7 @@ class GenericPanel : public QWidget
friend class AutoDoubleSpinBox;
friend class AutoCheckBox;
friend class AutoHexSpinBox;
friend class AutoLineEdit;
public:
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware);

View file

@ -90,6 +90,20 @@
#define AVR_FIELD(x) x;
#endif
#if defined(PCBSTD)
#define N_PCBSTD_FIELD(x)
#else
#define N_PCBSTD_FIELD(x) x;
#endif
#if defined(PCBTARANIS)
#define N_TARANIS_FIELD(x)
#define TARANIS_FIELD(x) x;
#else
#define N_TARANIS_FIELD(x) x;
#define TARANIS_FIELD(x)
#endif
#define NUM_STICKS 4
#if defined(PCBTARANIS)
@ -623,18 +637,6 @@ enum SwitchConfig {
#define LEN_SWITCH_NAME 3
#define LEN_ANA_NAME 3
#if defined(PCBSTD)
#define N_PCBSTD_FIELD(x)
#else
#define N_PCBSTD_FIELD(x) x;
#endif
#if defined(PCBTARANIS)
#define N_TARANIS_FIELD(x)
#else
#define N_TARANIS_FIELD(x) x;
#endif
#define ALTERNATE_VIEW 0x10
PACK(typedef struct t_EEGeneral {
uint8_t version;
@ -681,15 +683,15 @@ PACK(typedef struct t_EEGeneral {
EXTRA_GENERAL_FIELDS
ARM_FIELD(swarnstate_t switchUnlockStates)
TARANIS_FIELD(swarnstate_t switchUnlockStates)
ARM_FIELD(CustomFunctionData customFn[NUM_CFN])
ARM_FIELD(uint32_t switchConfig)
TARANIS_FIELD(uint32_t switchConfig)
ARM_FIELD(char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME])
TARANIS_FIELD(char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME])
ARM_FIELD(char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME])
TARANIS_FIELD(char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME])
}) EEGeneral;