1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-25 09:15:21 +03:00

[Companion] Refactoring - fixes the X9E=>X7 conversion segfault

This commit is contained in:
Bertrand Songis 2017-01-24 20:08:48 +01:00
parent 8f970fdbbf
commit 57aafeb062
19 changed files with 289 additions and 208 deletions

View file

@ -112,6 +112,7 @@ add_subdirectory(thirdparty/qxtcommandoptions)
############# Common lib ###############
set(common_SRCS
boards.cpp
eeprominterface.cpp
radiodata.cpp
firmwares/er9x/er9xeeprom.cpp

97
companion/src/boards.cpp Normal file
View file

@ -0,0 +1,97 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "boards.h"
#include "macros.h"
int getEEpromSize(BoardEnum board)
{
switch (board) {
case BOARD_STOCK:
return EESIZE_STOCK;
case BOARD_M128:
return EESIZE_M128;
case BOARD_MEGA2560:
case BOARD_GRUVIN9X:
return EESIZE_GRUVIN9X;
case BOARD_SKY9X:
return EESIZE_SKY9X;
case BOARD_9XRPRO:
case BOARD_AR9X:
return EESIZE_9XRPRO;
case BOARD_TARANIS_X7:
case BOARD_TARANIS_X9D:
case BOARD_TARANIS_X9DP:
case BOARD_TARANIS_X9E:
case BOARD_FLAMENCO:
return EESIZE_TARANIS;
default:
return 0; // unlimited
}
}
SwitchInfo getSwitchInfo(BoardEnum board, unsigned index)
{
if (IS_TARANIS_X7(board)) {
const SwitchInfo switches[] = {{SWITCH_3POS, "SA"},
{SWITCH_3POS, "SB"},
{SWITCH_3POS, "SC"},
{SWITCH_3POS, "SD"},
{SWITCH_2POS, "SF"},
{SWITCH_TOGGLE, "SH"}};
if (index < DIM(switches))
return switches[index];
}
else if (IS_HORUS_OR_TARANIS(board)) {
const SwitchInfo switches[] = {{SWITCH_3POS, "SA"},
{SWITCH_3POS, "SB"},
{SWITCH_3POS, "SC"},
{SWITCH_3POS, "SD"},
{SWITCH_3POS, "SE"},
{SWITCH_2POS, "SF"},
{SWITCH_3POS, "SG"},
{SWITCH_TOGGLE, "SH"},
{SWITCH_3POS, "SI"},
{SWITCH_3POS, "SJ"},
{SWITCH_3POS, "SK"},
{SWITCH_3POS, "SL"},
{SWITCH_3POS, "SM"},
{SWITCH_3POS, "SN"},
{SWITCH_3POS, "SO"},
{SWITCH_3POS, "SP"},
{SWITCH_3POS, "SQ"},
{SWITCH_3POS, "SR"}};
if (index < DIM(switches))
return switches[index];
}
else {
const SwitchInfo switches[] = {{SWITCH_2POS, "THR"},
{SWITCH_2POS, "RUD"},
{SWITCH_2POS, "ELE"},
{SWITCH_3POS, "3POS"},
{SWITCH_2POS, "AIL"},
{SWITCH_2POS, "GEA"},
{SWITCH_TOGGLE, "TRN"}};
if (index < DIM(switches))
return switches[index];
}
return {SWITCH_NOT_AVAILABLE, "???"};
}

106
companion/src/boards.h Normal file
View file

@ -0,0 +1,106 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _BOARDS_H_
#define _BOARDS_H_
// TODO create a Board class with all these functions
enum BoardEnum {
BOARD_STOCK,
BOARD_M128,
BOARD_MEGA2560,
BOARD_GRUVIN9X,
BOARD_SKY9X,
BOARD_9XRPRO,
BOARD_AR9X,
BOARD_TARANIS_X7,
BOARD_TARANIS_X9D,
BOARD_TARANIS_X9DP,
BOARD_TARANIS_X9E,
BOARD_FLAMENCO,
BOARD_HORUS,
BOARD_UNKNOWN = -1
};
enum PotConfig {
POT_NONE,
POT_WITH_DETENT,
POT_MULTIPOS_SWITCH,
POT_WITHOUT_DETENT
};
enum SliderConfig {
SLIDER_NONE,
SLIDER_WITH_DETENT
};
enum SwitchConfig {
SWITCH_NOT_AVAILABLE,
SWITCH_TOGGLE,
SWITCH_2POS,
SWITCH_3POS
};
struct SwitchInfo {
SwitchConfig config;
const char * name;
};
// TODO remove all those constants
#define EESIZE_STOCK 2048
#define EESIZE_M128 4096
#define EESIZE_GRUVIN9X 4096
#define EESIZE_TARANIS (32*1024)
#define EESIZE_SKY9X (128*4096)
#define EESIZE_9XRPRO (128*4096)
#define EESIZE_MAX EESIZE_9XRPRO
// TODO remove all those constants
#define FSIZE_STOCK (64*1024)
#define FSIZE_M128 (128*1024)
#define FSIZE_GRUVIN9X (256*1024)
#define FSIZE_TARANIS (512*1024)
#define FSIZE_SKY9X (256*1024)
#define FSIZE_9XRPRO (512*1024)
#define FSIZE_HORUS (2048*1024)
#define FSIZE_MAX FSIZE_HORUS
int getEEpromSize(BoardEnum board);
SwitchInfo getSwitchInfo(BoardEnum board, unsigned index);
#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128)
#define IS_STOCK(board) (board==BOARD_STOCK)
#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560)
#define IS_SKY9X(board) (board==BOARD_SKY9X || board==BOARD_9XRPRO || board==BOARD_AR9X)
#define IS_9XRPRO(board) (board==BOARD_9XRPRO)
#define IS_TARANIS_X7(board) (board==BOARD_TARANIS_X7)
#define IS_TARANIS_X9(board) (board==BOARD_TARANIS_X9D || board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E)
#define IS_TARANIS_PLUS(board) (board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E)
#define IS_TARANIS_X9E(board) (board==BOARD_TARANIS_X9E)
#define IS_TARANIS(board) (IS_TARANIS_X9(board) || IS_TARANIS_X7(board))
#define IS_HORUS(board) (board==BOARD_HORUS)
#define IS_HORUS_OR_TARANIS(board) (IS_HORUS(board) || IS_TARANIS(board))
#define IS_FLAMENCO(board) (board==BOARD_FLAMENCO)
#define IS_STM32(board) (IS_TARANIS(board) || IS_HORUS(board) || IS_FLAMENCO(board))
#define IS_ARM(board) (IS_STM32(board) || IS_SKY9X(board))
#define HAS_LARGE_LCD(board) (IS_HORUS(board) || (IS_TARANIS(board) && !IS_TARANIS_X7(board)))
#endif // _BOARDS_H_

View file

@ -21,23 +21,6 @@
#ifndef _CONSTANTS_H_
#define _CONSTANTS_H_
enum BoardEnum {
BOARD_STOCK,
BOARD_M128,
BOARD_MEGA2560,
BOARD_GRUVIN9X,
BOARD_SKY9X,
BOARD_9XRPRO,
BOARD_AR9X,
BOARD_TARANIS_X7,
BOARD_TARANIS_X9D,
BOARD_TARANIS_X9DP,
BOARD_TARANIS_X9E,
BOARD_FLAMENCO,
BOARD_HORUS,
BOARD_UNKNOWN = -1
};
#define CPN_MAX_MODELS 60
#define CPN_MAX_TIMERS 3
#define CPN_MAX_FLIGHT_MODES 9

View file

@ -24,8 +24,6 @@
#include "customdebug.h"
#include <QBitArray>
#define DIM(arr) (sizeof((arr))/sizeof((arr)[0]))
class DataField {
public:
DataField(const char *name=""):

View file

@ -27,6 +27,7 @@
#include "helpers.h"
#include "wizarddata.h"
#include "firmwareinterface.h"
#include "macros.h"
#include <stdio.h>
#include <list>
#include <float.h>
@ -36,32 +37,6 @@
std::list<QString> EEPROMWarnings;
int getEEpromSize(BoardEnum board)
{
switch (board) {
case BOARD_STOCK:
return EESIZE_STOCK;
case BOARD_M128:
return EESIZE_M128;
case BOARD_MEGA2560:
case BOARD_GRUVIN9X:
return EESIZE_GRUVIN9X;
case BOARD_SKY9X:
return EESIZE_SKY9X;
case BOARD_9XRPRO:
case BOARD_AR9X:
return EESIZE_9XRPRO;
case BOARD_TARANIS_X7:
case BOARD_TARANIS_X9D:
case BOARD_TARANIS_X9DP:
case BOARD_TARANIS_X9E:
case BOARD_FLAMENCO:
return EESIZE_TARANIS;
default:
return 0; // unlimited
}
}
const uint8_t chout_ar[] = { // First number is 0..23 -> template setup, Second is relevant channel out
1,2,3,4 , 1,2,4,3 , 1,3,2,4 , 1,3,4,2 , 1,4,2,3 , 1,4,3,2,
2,1,3,4 , 2,1,4,3 , 2,3,1,4 , 2,3,4,1 , 2,4,1,3 , 2,4,3,1,
@ -575,7 +550,7 @@ QString RawSource::toString(const ModelData * model) const
case SOURCE_TYPE_MAX:
return QObject::tr("MAX");
case SOURCE_TYPE_SWITCH:
return getCurrentFirmware()->getSwitch(index).name;
return getSwitchInfo(getCurrentBoard(), index).name;
case SOURCE_TYPE_CUSTOM_SWITCH:
return QObject::tr("L%1").arg(index+1);
case SOURCE_TYPE_CYC:
@ -617,8 +592,12 @@ bool RawSource::isSlider() const
index < CPN_MAX_STICKS+getCurrentFirmware()->getCapability(Pots)+getCurrentFirmware()->getCapability(Sliders));
}
QString RawSwitch::toString() const
QString RawSwitch::toString(BoardEnum board) const
{
if (board == BOARD_UNKNOWN) {
board = getCurrentBoard();
}
static const QString switches9X[] = {
QString("THR"), QString("RUD"), QString("ELE"),
QString("ID0"), QString("ID1"), QString("ID2"),
@ -655,14 +634,13 @@ QString RawSwitch::toString() const
return QString("!") + RawSwitch(type, -index).toString();
}
else {
BoardEnum board = getCurrentBoard();
switch(type) {
case SWITCH_TYPE_SWITCH:
if (IS_HORUS_OR_TARANIS(board)) {
div_t qr = div(index-1, 3);
Firmware::Switch sw = getCurrentFirmware()->getSwitch(qr.quot);
SwitchInfo switchInfo = getSwitchInfo(board, qr.quot);
const char * positions[] = { ARROW_UP, "-", ARROW_DOWN };
return QString(sw.name) + QString(positions[qr.rem]);
return QString(switchInfo.name) + QString(positions[qr.rem]);
}
else {
return CHECK_IN_ARRAY(switches9X, index - 1);
@ -1097,7 +1075,7 @@ GeneralSettings::GeneralSettings()
BoardEnum board = firmware->getBoard();
for (int i=0; i<firmware->getCapability(FactoryInstalledSwitches); i++) {
switchConfig[i] = firmware->getSwitch(i).type;
switchConfig[i] = getSwitchInfo(board, i).config;
}
if (IS_HORUS(board)) {

View file

@ -29,40 +29,6 @@
#include <iostream>
#include <QDebug>
#define EESIZE_STOCK 2048
#define EESIZE_M128 4096
#define EESIZE_GRUVIN9X 4096
#define EESIZE_TARANIS (32*1024)
#define EESIZE_SKY9X (128*4096)
#define EESIZE_9XRPRO (128*4096)
#define EESIZE_MAX EESIZE_9XRPRO
#define FSIZE_STOCK (64*1024)
#define FSIZE_M128 (128*1024)
#define FSIZE_GRUVIN9X (256*1024)
#define FSIZE_TARANIS (512*1024)
#define FSIZE_SKY9X (256*1024)
#define FSIZE_9XRPRO (512*1024)
#define FSIZE_HORUS (2048*1024)
#define FSIZE_MAX FSIZE_HORUS
#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128)
#define IS_STOCK(board) (board==BOARD_STOCK)
#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560)
#define IS_SKY9X(board) (board==BOARD_SKY9X || board==BOARD_9XRPRO || board==BOARD_AR9X)
#define IS_9XRPRO(board) (board==BOARD_9XRPRO)
#define IS_TARANIS_X7(board) (board==BOARD_TARANIS_X7)
#define IS_TARANIS_X9(board) (board==BOARD_TARANIS_X9D || board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E)
#define IS_TARANIS_PLUS(board) (board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E)
#define IS_TARANIS_X9E(board) (board==BOARD_TARANIS_X9E)
#define IS_TARANIS(board) (IS_TARANIS_X9(board) || IS_TARANIS_X7(board))
#define IS_HORUS(board) (board==BOARD_HORUS)
#define IS_HORUS_OR_TARANIS(board) (IS_HORUS(board) || IS_TARANIS(board))
#define IS_FLAMENCO(board) (board==BOARD_FLAMENCO)
#define IS_STM32(board) (IS_TARANIS(board) || IS_HORUS(board) || IS_FLAMENCO(board))
#define IS_ARM(board) (IS_STM32(board) || IS_SKY9X(board))
#define HAS_LARGE_LCD(board) (IS_HORUS(board) || (IS_TARANIS(board) && board != BOARD_TARANIS_X7))
QString RotaryEncoderString(int index);
const uint8_t modn12x3[4][4]= {
@ -217,8 +183,6 @@ class EEPROMInterface
};
int getEEpromSize(BoardEnum board);
extern std::list<QString> EEPROMWarnings;
/* EEPROM string conversion functions */
@ -364,13 +328,6 @@ class Firmware {
virtual int getCapability(Capability) = 0;
struct Switch {
GeneralSettings::SwitchConfig type;
const char * name;
};
virtual Switch getSwitch(unsigned int index) = 0;
virtual QString getAnalogInputName(unsigned int index) = 0;
virtual QTime getMaxTimerStart() = 0;

View file

@ -416,9 +416,10 @@ class SwitchField: public ConversionField< SignedField<N> > {
public:
SwitchField(RawSwitch & sw, BoardEnum board, unsigned int version, unsigned long flags=0):
ConversionField< SignedField<N> >(_switch, SwitchesConversionTable::getInstance(board, version, flags), QObject::tr("Switch").toLatin1(),
QObject::tr("Switch ").toLatin1()+ sw.toString()+ QObject::tr(" cannot be exported on this board!").toLatin1()),
QObject::tr("Switch ").toLatin1()+ sw.toString(board) + QObject::tr(" cannot be exported on this board!").toLatin1()),
sw(sw),
_switch(0)
_switch(0),
board(board)
{
}
@ -436,12 +437,13 @@ class SwitchField: public ConversionField< SignedField<N> > {
{
ConversionField< SignedField<N> >::afterImport();
sw = RawSwitch(_switch);
eepromImportDebug() << QString("imported %1: %2").arg(ConversionField< SignedField<N> >::internalField.getName()).arg(sw.toString());
eepromImportDebug() << QString("imported %1: %2").arg(ConversionField< SignedField<N> >::internalField.getName()).arg(sw.toString(board));
}
protected:
RawSwitch & sw;
int _switch;
BoardEnum board;
};
class TelemetrySourcesConversionTable: public ConversionTable {
@ -3814,7 +3816,7 @@ void OpenTxGeneralData::beforeExport()
void OpenTxGeneralData::afterImport()
{
if (IS_TARANIS(board) && version < 217) {
generalData.potConfig[0] = GeneralSettings::POT_WITH_DETENT;
generalData.potConfig[1] = GeneralSettings::POT_WITH_DETENT;
generalData.potConfig[0] = POT_WITH_DETENT;
generalData.potConfig[1] = POT_WITH_DETENT;
}
}

View file

@ -818,51 +818,6 @@ QString OpenTxFirmware::getAnalogInputName(unsigned int index)
}
}
Firmware::Switch OpenTxFirmware::getSwitch(unsigned int index)
{
typedef GeneralSettings::SwitchConfig sc;
if (board == BOARD_TARANIS_X7) {
const Switch switches[] = {{sc::SWITCH_3POS, "SA"},
{sc::SWITCH_3POS, "SB"},
{sc::SWITCH_3POS, "SC"},
{sc::SWITCH_3POS, "SD"},
{sc::SWITCH_2POS, "SF"},
{sc::SWITCH_TOGGLE, "SH"}};
return switches[index];
}
else if (IS_HORUS_OR_TARANIS(board)) {
const Switch switches[] = {{sc::SWITCH_3POS, "SA"},
{sc::SWITCH_3POS, "SB"},
{sc::SWITCH_3POS, "SC"},
{sc::SWITCH_3POS, "SD"},
{sc::SWITCH_3POS, "SE"},
{sc::SWITCH_2POS, "SF"},
{sc::SWITCH_3POS, "SG"},
{sc::SWITCH_TOGGLE, "SH"},
{sc::SWITCH_3POS, "SI"},
{sc::SWITCH_3POS, "SJ"},
{sc::SWITCH_3POS, "SK"},
{sc::SWITCH_3POS, "SL"},
{sc::SWITCH_3POS, "SM"},
{sc::SWITCH_3POS, "SN"},
{sc::SWITCH_3POS, "SO"},
{sc::SWITCH_3POS, "SP"},
{sc::SWITCH_3POS, "SQ"},
{sc::SWITCH_3POS, "SR"}};
return switches[index];
}
else {
const Switch switches[] = {{sc::SWITCH_2POS, "THR"},
{sc::SWITCH_2POS, "RUD"},
{sc::SWITCH_2POS, "ELE"},
{sc::SWITCH_3POS, "3POS"},
{sc::SWITCH_2POS, "AIL"},
{sc::SWITCH_2POS, "GEA"},
{sc::SWITCH_TOGGLE, "TRN"}};
return switches[index];
}
}
QTime OpenTxFirmware::getMaxTimerStart()
{
if (IS_HORUS_OR_TARANIS(board))

View file

@ -131,8 +131,6 @@ class OpenTxFirmware: public Firmware
virtual int getCapability(Capability);
virtual Switch getSwitch(unsigned int index);
virtual QString getAnalogInputName(unsigned int index);
virtual QTime getMaxTimerStart();

View file

@ -24,11 +24,12 @@
void HardwarePanel::setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos = true)
{
if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Switches)) {
type->addItem(tr("None"), GeneralSettings::SWITCH_NONE);
type->addItem(tr("2 Positions Toggle"), GeneralSettings::SWITCH_TOGGLE);
type->addItem(tr("2 Positions"), GeneralSettings::SWITCH_2POS);
if (threePos)
type->addItem(tr("3 Positions"), GeneralSettings::SWITCH_3POS);
type->addItem(tr("None"), SWITCH_NONE);
type->addItem(tr("2 Positions Toggle"), SWITCH_TOGGLE);
type->addItem(tr("2 Positions"), SWITCH_2POS);
if (threePos) {
type->addItem(tr("3 Positions"), SWITCH_3POS);
}
name->setField(generalSettings.switchName[index], 3, this);
type->setField(generalSettings.switchConfig[index], this);
}
@ -43,10 +44,10 @@ void HardwarePanel::setupPotConfig(int index, QLabel *label, AutoLineEdit *name,
{
if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Pots)) {
label->setText(RawSource(SOURCE_TYPE_STICK, CPN_MAX_STICKS+index).toString());
type->addItem(tr("None"), GeneralSettings::POT_NONE);
type->addItem(tr("Pot with detent"), GeneralSettings::POT_WITH_DETENT);
type->addItem(tr("Multipos switch"), GeneralSettings::POT_MULTIPOS_SWITCH);
type->addItem(tr("Pot without detent"), GeneralSettings::POT_WITHOUT_DETENT);
type->addItem(tr("None"), POT_NONE);
type->addItem(tr("Pot with detent"), POT_WITH_DETENT);
type->addItem(tr("Multipos switch"), POT_MULTIPOS_SWITCH);
type->addItem(tr("Pot without detent"), POT_WITHOUT_DETENT);
name->setField(generalSettings.potName[index], 3, this);
type->setField(generalSettings.potConfig[index], this);
}
@ -61,8 +62,8 @@ void HardwarePanel::setupSliderConfig(int index, QLabel *label, AutoLineEdit *na
{
if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Sliders)) {
label->setText(RawSource(SOURCE_TYPE_STICK, CPN_MAX_STICKS+firmware->getCapability(Pots)+index).toString());
type->addItem(tr("None"), GeneralSettings::SLIDER_NONE);
type->addItem(tr("Slider with detent"), GeneralSettings::SLIDER_WITH_DETENT);
type->addItem(tr("None"), SLIDER_NONE);
type->addItem(tr("Slider with detent"), SLIDER_WITH_DETENT);
name->setField(generalSettings.sliderName[index], 3, this);
type->setField(generalSettings.sliderConfig[index], this);
}

View file

@ -413,7 +413,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
}
for (int i=getCurrentFirmware()->getCapability(MultiposPots)-1; i>=0; i--) {
if (generalSettings.potConfig[i] == GeneralSettings::POT_MULTIPOS_SWITCH) {
if (generalSettings.potConfig[i] == POT_MULTIPOS_SWITCH) {
for (int j=-getCurrentFirmware()->getCapability(MultiposPotsPositions); j<0; j++) {
item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, -i*getCurrentFirmware()->getCapability(MultiposPotsPositions)+j);
b->addItem(item.toString(), item.toValue());
@ -454,7 +454,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin
}
for (int i=0; i<getCurrentFirmware()->getCapability(MultiposPots); i++) {
if (generalSettings.potConfig[i] == GeneralSettings::POT_MULTIPOS_SWITCH) {
if (generalSettings.potConfig[i] == POT_MULTIPOS_SWITCH) {
for (int j=1; j<=getCurrentFirmware()->getCapability(MultiposPotsPositions); j++) {
item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i*getCurrentFirmware()->getCapability(MultiposPotsPositions)+j);
b->addItem(item.toString(), item.toValue());

26
companion/src/macros.h Normal file
View file

@ -0,0 +1,26 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _MACROS_H_
#define _MACROS_H_
#define DIM(arr) (sizeof((arr))/sizeof((arr)[0]))
#endif // _MACROS_H_

View file

@ -709,11 +709,11 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
// Startup switches warnings
for (int i=0; i<firmware->getCapability(Switches); i++) {
Firmware::Switch sw = firmware->getSwitch(i);
SwitchInfo switchInfo = getSwitchInfo(board, i);
if (IS_HORUS_OR_TARANIS(board)) {
sw.type = GeneralSettings::SwitchConfig(generalSettings.switchConfig[i]);
switchInfo.config = SwitchConfig(generalSettings.switchConfig[i]);
}
if (sw.type == GeneralSettings::SWITCH_NONE || sw.type == GeneralSettings::SWITCH_TOGGLE) {
if (switchInfo.config == SWITCH_NOT_AVAILABLE || switchInfo.config == SWITCH_TOGGLE) {
continue;
}
QLabel * label = new QLabel(this);
@ -729,8 +729,8 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
slider->setSingleStep(1);
slider->setPageStep(1);
slider->setTickInterval(1);
label->setText(sw.name);
slider->setMaximum(sw.type == GeneralSettings::SWITCH_3POS ? 2 : 1);
label->setText(switchInfo.name);
slider->setMaximum(switchInfo.config == SWITCH_3POS ? 2 : 1);
cb->setProperty("index", i);
ui->switchesStartupLayout->addWidget(label, 0, i+1);
ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter);
@ -960,7 +960,7 @@ void SetupPanel::updateStartupSwitches()
bool enabled = !(model->switchWarningEnable & (1 << index));
if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
value = (switchStates >> 2*index) & 0x03;
if (generalSettings.switchConfig[index] != GeneralSettings::SWITCH_3POS && value == 2) {
if (generalSettings.switchConfig[index] != SWITCH_3POS && value == 2) {
value = 1;
}
}
@ -999,7 +999,7 @@ void SetupPanel::startupSwitchEdited(int value)
model->switchWarningStates &= ~mask;
if (IS_HORUS_OR_TARANIS(firmware->getBoard()) && generalSettings.switchConfig[index] != GeneralSettings::SWITCH_3POS) {
if (IS_HORUS_OR_TARANIS(firmware->getBoard()) && generalSettings.switchConfig[index] != SWITCH_3POS) {
if (value == 1) {
value = 2;
}

View file

@ -1,6 +1,7 @@
#ifndef _RADIODATA_H_
#define _RADIODATA_H_
#include "boards.h"
#include "constants.h"
#include <QString>
#include <QComboBox>
@ -289,7 +290,7 @@ class RawSwitch {
return index >= 0 ? (type * 256 + index) : -(type * 256 - index);
}
QString toString() const;
QString toString(BoardEnum board = BOARD_UNKNOWN) const;
bool operator== ( const RawSwitch& other) {
return (this->type == other.type) && (this->index == other.index);
@ -1128,25 +1129,6 @@ class GeneralSettings {
BEEPER_ALL = 1
};
enum PotConfig {
POT_NONE,
POT_WITH_DETENT,
POT_MULTIPOS_SWITCH,
POT_WITHOUT_DETENT
};
enum SliderConfig {
SLIDER_NONE,
SLIDER_WITH_DETENT
};
enum SwitchConfig {
SWITCH_NONE,
SWITCH_TOGGLE,
SWITCH_2POS,
SWITCH_3POS
};
GeneralSettings();
void convert(BoardEnum before, BoardEnum after);

View file

@ -334,17 +334,17 @@ void SimulatorDialog::setupRadioWidgets()
// Now set up new widgets.
// switches
Firmware::Switch swinfo;
SwitchInfo switchInfo;
// FIXME : CPN_MAX_SWITCHES == 32 but GeneralSettings::switchConfig[18] !!
for (i = 0; i < firmware->getCapability(Capability(Switches)) && i < 18 /*CPN_MAX_SWITCHES*/; ++i) {
if (radioSettings.switchConfig[i] == GeneralSettings::SWITCH_NONE)
if (radioSettings.switchConfig[i] == SWITCH_NONE)
continue;
if ((wname = QString(radioSettings.switchName[i])).isEmpty()) {
swinfo = firmware->getSwitch(i);
wname = QString(swinfo.name);
switchInfo = getSwitchInfo(board, i);
wname = QString(switchInfo.name);
}
RadioSwitchWidget * sw = new RadioSwitchWidget(GeneralSettings::SwitchConfig(radioSettings.switchConfig[i]), wname, 0, ui->radioWidgetsHT);
RadioSwitchWidget * sw = new RadioSwitchWidget(SwitchConfig(radioSettings.switchConfig[i]), wname, 0, ui->radioWidgetsHT);
sw->setIndex(i);
ui->radioWidgetsHTLayout->addWidget(sw);
switches.append(sw);
@ -361,7 +361,7 @@ void SimulatorDialog::setupRadioWidgets()
if ((wname = QString(radioSettings.potName[i])).isEmpty())
wname = firmware->getAnalogInputName(4 + aIdx + i);
RadioKnobWidget * pot = new RadioKnobWidget(GeneralSettings::PotConfig(radioSettings.potConfig[i]), wname, 0, ui->radioWidgetsHT);
RadioKnobWidget * pot = new RadioKnobWidget(PotConfig(radioSettings.potConfig[i]), wname, 0, ui->radioWidgetsHT);
pot->setIndex(aIdx + i);
// FIXME : total hack here -- this needs to follow the exception in radio/src/mixer.cpp:evalInputs()
if (i == 0 && IS_TARANIS(board) && !IS_TARANIS_X7(board))

View file

@ -21,6 +21,7 @@
#ifndef _SIMULATORINTERFACE_H_
#define _SIMULATORINTERFACE_H_
#include "boards.h"
#include "constants.h"
#include <inttypes.h>
#include <QString>

View file

@ -35,15 +35,13 @@ class RadioKnobWidget : public RadioWidget
public:
using potType_t = GeneralSettings::PotConfig;
explicit RadioKnobWidget(potType_t type = potType_t::POT_WITH_DETENT, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
explicit RadioKnobWidget(PotConfig type = POT_WITH_DETENT, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
RadioWidget(parent, f),
m_potType(type)
{
init();
}
explicit RadioKnobWidget(potType_t type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
explicit RadioKnobWidget(PotConfig type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
RadioWidget(labelText, value, parent, f),
m_potType(type)
{
@ -65,20 +63,19 @@ class RadioKnobWidget : public RadioWidget
private:
potType_t m_potType;
PotConfig m_potType;
class KnobWidget : public QDial
{
friend class RadioKnobWidget;
using potType_t = RadioKnobWidget::potType_t;
public:
explicit KnobWidget(potType_t type, QWidget * parent = 0):
explicit KnobWidget(PotConfig type, QWidget * parent = 0):
QDial(parent),
m_type(type),
m_positions(type == potType_t::POT_MULTIPOS_SWITCH ? 5 : 0)
m_positions(type == POT_MULTIPOS_SWITCH ? 5 : 0)
{
setToolTip(tr("Right-double-click to reset to center."));
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@ -117,7 +114,7 @@ class RadioKnobWidget : public RadioWidget
QDial::mousePressEvent(event);
}
potType_t m_type;
PotConfig m_type;
quint8 m_positions;
};

View file

@ -32,17 +32,16 @@ class RadioSwitchWidget : public RadioWidget
Q_OBJECT
public:
typedef GeneralSettings::SwitchConfig swType_t;
explicit RadioSwitchWidget(swType_t type = swType_t::SWITCH_3POS, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
explicit RadioSwitchWidget(SwitchConfig type = SWITCH_3POS, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
RadioWidget(parent, f),
swType(type)
switchConfig(type)
{
init();
}
explicit RadioSwitchWidget(swType_t type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
explicit RadioSwitchWidget(SwitchConfig type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
RadioWidget(labelText, value, parent, f),
swType(type)
switchConfig(type)
{
init();
}
@ -59,7 +58,7 @@ class RadioSwitchWidget : public RadioWidget
sl->setInvertedControls(true);
sl->setTickPosition(QSlider::TicksBothSides);
sl->setPageStep(1);
sl->setMinimum((swType == swType_t::SWITCH_3POS ? -1 : 0));
sl->setMinimum((switchConfig == SWITCH_3POS ? -1 : 0));
sl->setMaximum(1);
sl->setTickInterval(1);
sl->setValue(m_value);
@ -71,7 +70,7 @@ class RadioSwitchWidget : public RadioWidget
}
private:
swType_t swType;
SwitchConfig switchConfig;
};