Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions companion/src/datamodels/compounditemmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,62 @@ void FlexSwitchesItemModel::update(const int event)
}
}

//
// ControlSourceItemModel
//

ControlSourceItemModel::ControlSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData,
Firmware * firmware, const Boards * const board, const Board::Type boardType) :
AbstractDynamicItemModel(generalSettings, modelData, firmware, board, boardType)
{
setId(IMID_ControlSource);
setUpdateMask(IMUE_Hardware);

// Descending source direction: inverted (!) sources
addItems(SOURCE_TYPE_SWITCH, -board->getCapability(Board::Switches));
addItems(SOURCE_TYPE_INPUT, -board->getCapability(Board::Inputs), -board->getCapability(Board::Sticks));

// Ascending source direction (including zero)
addItems(SOURCE_TYPE_NONE, 1);
addItems(SOURCE_TYPE_INPUT, board->getCapability(Board::Inputs), board->getCapability(Board::Sticks));
addItems(SOURCE_TYPE_SWITCH, board->getCapability(Board::Switches));
}

void ControlSourceItemModel::setDynamicItemData(QStandardItem * item, const RawSource & src) const
{
item->setText(src.toString(modelData, generalSettings, boardType));
item->setData(src.isAvailable(modelData, generalSettings, boardType, RawSource::AVAILABLE_CONTROLSRC), IMDR_Available);
}

void ControlSourceItemModel::addItems(const RawSourceType & type, int count, const int start)
{
const int idxAdj = (type == SOURCE_TYPE_NONE ? -1 : 0);

int first = start + count < 0 ? start + count : start + 1;
int last = start + count < 0 ? start : start + count + 1;

for (int i = first; i < last; ++i) {
const RawSource src = RawSource(type, i + idxAdj);
QStandardItem * modelItem = new QStandardItem();
modelItem->setData(src.toValue(), IMDR_Id);
modelItem->setData(type, IMDR_Type);
setDynamicItemData(modelItem, src);
appendRow(modelItem);
}
}

void ControlSourceItemModel::update(const int event)
{
if (doUpdate(event)) {
emit aboutToBeUpdated();

for (int i = 0; i < rowCount(); ++i)
setDynamicItemData(item(i), RawSource(item(i)->data(IMDR_Id).toInt()));

emit updateComplete();
}
}

//
// CompoundItemModelFactory
//
Expand Down Expand Up @@ -722,6 +778,9 @@ void CompoundItemModelFactory::addItemModel(const int id)
case AbstractItemModel::IMID_FlexSwitches:
registerItemModel(new FlexSwitchesItemModel(generalSettings, modelData, firmware, board, boardType));
break;
case AbstractItemModel::IMID_ControlSource:
registerItemModel(new ControlSourceItemModel(generalSettings, modelData, firmware, board, boardType));
break;
default:
qDebug() << "Error: unknown item model: id";
break;
Expand Down
18 changes: 18 additions & 0 deletions companion/src/datamodels/compounditemmodels.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AbstractItemModel: public QStandardItemModel
IMID_CurveRefType,
IMID_CurveRefFunc,
IMID_FlexSwitches,
IMID_ControlSource,
IMID_ReservedCount,
IMID_Custom
};
Expand Down Expand Up @@ -81,6 +82,7 @@ class AbstractItemModel: public QStandardItemModel
IMUE_Timers = 1 << 9,
IMUE_Modules = 1 << 10,
IMUE_FunctionSwitches = 1 << 11,
IMUE_Hardware = 1 << 12,
IMUE_All = IMUE_SystemRefresh | IMUE_Channels | IMUE_Curves | IMUE_FlightModes | IMUE_GVars | IMUE_Inputs |
IMUE_LogicalSwitches | IMUE_Scripts | IMUE_TeleSensors | IMUE_Timers | IMUE_Modules | IMUE_FunctionSwitches
};
Expand Down Expand Up @@ -349,6 +351,22 @@ class FlexSwitchesItemModel: public AbstractDynamicItemModel
virtual void setDynamicItemData(QStandardItem * item, const int value) const;
};

class ControlSourceItemModel: public AbstractDynamicItemModel
{
Q_OBJECT
public:
explicit ControlSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData,
Firmware * firmware, const Boards * const board, const Board::Type boardType);
virtual ~ControlSourceItemModel() {};

public slots:
virtual void update(const int event = IMUE_SystemRefresh) override;

protected:
virtual void setDynamicItemData(QStandardItem * item, const RawSource & src) const;
void addItems(const RawSourceType & type, int count, const int start = 0);
};


//
// CompoundItemModelFactory
Expand Down
10 changes: 10 additions & 0 deletions companion/src/firmwares/boardjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,11 @@ bool BoardJson::isInputFlex(const InputDefn & defn)
return defn.type == Board::AIT_FLEX;
}

const bool BoardJson::isInputFlexGyroAxis(int index) const
{
return (index >=0 && index < (int)m_inputs->size()) ? isInputFlexGyroAxis(m_inputs->at(index)) : false;
}

// static
bool BoardJson::isInputFlexGyroAxis(const InputDefn & defn)
{
Expand All @@ -761,6 +766,11 @@ bool BoardJson::isInputFlexGyroAxis(const InputDefn & defn)
val[0] == 'T' && val[1] == 'I' && val[2] == 'L' && val[3] == 'T' && val[4] == '_' && (val[5] == 'X' || val[5] == 'Y'));
}

const bool BoardJson::isInputFlexJoystickAxis(int index) const
{
return (index >=0 && index < (int)m_inputs->size()) ? isInputFlexJoystickAxis(m_inputs->at(index)) : false;
}

// static
bool BoardJson::isInputFlexJoystickAxis(const InputDefn & defn)
{
Expand Down
2 changes: 2 additions & 0 deletions companion/src/firmwares/boardjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class BoardJson
const bool isInputCalibrated(int index) const;
const bool isInputConfigurable(int index) const;
const bool isInputIgnored(int index) const;
const bool isInputFlexGyroAxis(int index) const;
const bool isInputFlexJoystickAxis(int index) const;
const bool isInputFlexPot(int index) const;
const bool isInputFlexSwitch(int index) const;
const bool isInputStick(int index) const;
Expand Down
5 changes: 5 additions & 0 deletions companion/src/firmwares/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,11 @@ bool Boards::isInputConfigurable(int index, Board::Type board)
return getBoardJson(board)->isInputConfigurable(index);
}

bool Boards::isInputGyroAxis(int index, Board::Type board)
{
return getBoardJson(board)->isInputFlexGyroAxis(index);
}

bool Boards::isInputIgnored(int index, Board::Type board)
{
return getBoardJson(board)->isInputIgnored(index);
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class Boards
static bool isInputAvailable(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputCalibrated(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputConfigurable(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputGyroAxis(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputIgnored(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputPot(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputStick(int index, Board::Type board = Board::BOARD_UNKNOWN);
Expand Down
7 changes: 7 additions & 0 deletions companion/src/firmwares/edgetx/yaml_generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "yaml_calibdata.h"
#include "yaml_switchconfig.h"
#include "yaml_moduledata.h"
#include "yaml_rawsource.h"

#include "eeprominterface.h"
#include "edgetxinterface.h"
Expand Down Expand Up @@ -370,6 +371,9 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
if (hasColorLcd)
node["selectedTheme"] = rhs.selectedTheme;

node["backlightSrc"] = rhs.backlightSrc;
node["volumeSrc"] = rhs.volumeSrc;

// Radio level tabs control (global settings)
if (hasColorLcd)
node["radioThemesDisabled"] = (int)rhs.radioThemesDisabled;
Expand Down Expand Up @@ -686,6 +690,9 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)

node["selectedTheme"] >> rhs.selectedTheme;

node["backlightSrc"] >> rhs.backlightSrc;
node["volumeSrc"] >> rhs.volumeSrc;

// Radio level tabs control (global settings)
node["radioThemesDisabled"] >> rhs.radioThemesDisabled;
node["radioGFDisabled"] >> rhs.radioGFDisabled;
Expand Down
5 changes: 5 additions & 0 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ void GeneralSettings::convert(RadioDataConversionState & cstate)
customFn[i].convert(cstate.withComponentIndex(i));
}

cstate.setComponent("");
cstate.setSubComp(tr("Backlight Source"));
backlightSrc.convert(cstate);
cstate.setSubComp(tr("Volume Source"));
volumeSrc.convert(cstate);
}

QString GeneralSettings::antennaModeToString() const
Expand Down
3 changes: 3 additions & 0 deletions companion/src/firmwares/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ class GeneralSettings {

char selectedTheme[SELECTED_THEME_NAME_LEN + 1];

RawSource backlightSrc;
RawSource volumeSrc;

// Radio level tabs control (global settings)
bool radioThemesDisabled;
bool radioGFDisabled;
Expand Down
9 changes: 8 additions & 1 deletion companion/src/firmwares/rawsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ bool RawSource::isStick(Board::Type board) const
return false;
}

bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const
bool RawSource::isAvailable(const ModelData * const model,
const GeneralSettings * const gs,
Board::Type board,
const int flags) const
{
if (type == SOURCE_TYPE_NONE && index == 0)
return true;
Expand Down Expand Up @@ -392,6 +395,10 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings
gs->serialPort[GeneralSettings::SP_AUX2] == GeneralSettings::AUX_SERIAL_SPACEMOUSE))))
return false;

if (type == SOURCE_TYPE_INPUT && (flags & AVAILABLE_CONTROLSRC) &&
Boards::isInputGyroAxis(abs(index) - 1, board))
return false;

return true;
}

Expand Down
11 changes: 10 additions & 1 deletion companion/src/firmwares/rawsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ class RawSource {
AllSourceGroups = InputSourceGroups | GVarsGroup | TelemGroup | ScriptsGroup
};

// flags to refine isAvailable
enum AvailableFlags {
AVAILABLE_ALL,
AVAILABLE_CONTROLSRC = 0x001
};

RawSource() { clear(); }

explicit RawSource(int value):
Expand All @@ -272,7 +278,10 @@ class RawSource {
RawSourceRange getRange(const ModelData * model, const GeneralSettings & settings, unsigned int flags=0) const;
bool isStick(Board::Type board = Board::BOARD_UNKNOWN) const;
bool isTimeBased(Board::Type board = Board::BOARD_UNKNOWN) const;
bool isAvailable(const ModelData * const model = nullptr, const GeneralSettings * const gs = nullptr, Board::Type board = Board::BOARD_UNKNOWN) const;
bool isAvailable(const ModelData * const model = nullptr,
const GeneralSettings * const gs = nullptr,
Board::Type board = Board::BOARD_UNKNOWN,
const int flags = 0) const;
bool isSet() const { return type != SOURCE_TYPE_NONE || index != 0; }
void clear() { type = SOURCE_TYPE_NONE; index = 0; }
static StringTagMappingTable getSpecialTypesLookupTable();
Expand Down
3 changes: 2 additions & 1 deletion companion/src/generaledit/generaledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * fir
editorItemModels->addItemModel(AbstractItemModel::IMID_RawSwitch);
editorItemModels->addItemModel(AbstractItemModel::IMID_CustomFuncAction);
editorItemModels->addItemModel(AbstractItemModel::IMID_CustomFuncResetParam);
editorItemModels->addItemModel(AbstractItemModel::IMID_ControlSource);

addTab(new GeneralSetupPanel(this, generalSettings, firmware), tr("Setup"));
addTab(new GeneralSetupPanel(this, generalSettings, firmware, editorItemModels), tr("Setup"));
addTab(new CustomFunctionsPanel(this, nullptr, generalSettings, firmware, editorItemModels), tr("Global Functions"));
addTab(new TrainerPanel(this, generalSettings, firmware, editorItemModels), tr("Trainer"));
auto hwpnl = new HardwarePanel(this, generalSettings, firmware, editorItemModels);
Expand Down
38 changes: 34 additions & 4 deletions companion/src/generaledit/generalsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,31 @@
#include "filtereditemmodels.h"
#include "autocombobox.h"
#include "namevalidator.h"
#include "helpers.h"

constexpr char FIM_HATSMODE[] {"Hats Mode"};
constexpr char FIM_STICKMODE[] {"Stick Mode"};
constexpr char FIM_TEMPLATESETUP[] {"Template Setup"};
constexpr char FIM_BACKLIGHTMODE[] {"Backlight Mode"};
constexpr char FIM_CONTROLSRC[] {"Control Source"};

GeneralSetupPanel::GeneralSetupPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
GeneralSetupPanel::GeneralSetupPanel(QWidget * parent, GeneralSettings & generalSettings,
Firmware * firmware, CompoundItemModelFactory * sharedItemModels):
GeneralPanel(parent, generalSettings, firmware),
ui(new Ui::GeneralSetup)
{
ui->setupUi(this);

Board::Type board = firmware->getBoard();

panelFilteredModels = new FilteredItemModelFactory();

panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::hatsModeItemModel()), FIM_HATSMODE);
panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::stickModeItemModel()), FIM_STICKMODE);
panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::templateSetupItemModel(),
Boards::isAir(board) ? GeneralSettings::RadioTypeContextAir :
GeneralSettings::RadioTypeContextSurface),
FIM_TEMPLATESETUP);
panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::backlightModeItemModel()), FIM_BACKLIGHTMODE);
panelFilteredModels->registerItemModel(new FilteredItemModel(sharedItemModels->getItemModel(AbstractItemModel::IMID_ControlSource)),
FIM_CONTROLSRC);

QLabel *pmsl[] = {ui->ro_label, ui->ro1_label, ui->ro2_label, ui->ro3_label, ui->ro4_label, ui->ro5_label, ui->ro6_label, ui->ro7_label, ui->ro8_label, NULL};
QSlider *tpmsld[] = {ui->chkSA, ui->chkSB, ui->chkSC, ui->chkSD, ui->chkSE, ui->chkSF, ui->chkSG, ui->chkSH, NULL};
Expand Down Expand Up @@ -93,6 +95,18 @@ ui(new Ui::GeneralSetup)

lock = true;

ui->volumeCtrl_CB->setSizeAdjustPolicy(QComboBox::AdjustToContents);
ui->volumeCtrl_CB->setModel(panelFilteredModels->getItemModel(FIM_CONTROLSRC));
ui->volumeCtrl_CB->setCurrentIndex(ui->volumeCtrl_CB->findData(generalSettings.volumeSrc.toValue()));
if (ui->volumeCtrl_CB->currentIndex() < 0 && generalSettings.volumeSrc.toValue() == 0)
ui->volumeCtrl_CB->setCurrentIndex(Helpers::getFirstPosValueIndex(ui->volumeCtrl_CB));

ui->brightCtrl_CB->setSizeAdjustPolicy(QComboBox::AdjustToContents);
ui->brightCtrl_CB->setModel(panelFilteredModels->getItemModel(FIM_CONTROLSRC));
ui->brightCtrl_CB->setCurrentIndex(ui->brightCtrl_CB->findData(generalSettings.backlightSrc.toValue()));
if (ui->brightCtrl_CB->currentIndex() < 0 && generalSettings.backlightSrc.toValue() == 0)
ui->brightCtrl_CB->setCurrentIndex(Helpers::getFirstPosValueIndex(ui->brightCtrl_CB));

ui->backlightswCB->setModel(panelFilteredModels->getItemModel(FIM_BACKLIGHTMODE));
ui->backlightswCB->setCurrentIndex(ui->backlightswCB->findData(generalSettings.backlightMode));

Expand Down Expand Up @@ -729,6 +743,22 @@ void GeneralSetupPanel::on_OFFBright_SB_editingFinished()
}
}

void GeneralSetupPanel::on_volumeCtrl_CB_currentIndexChanged(int index)
{
if (!lock) {
generalSettings.volumeSrc = RawSource(ui->volumeCtrl_CB->itemData(ui->volumeCtrl_CB->currentIndex()).toInt());
emit modified();
}
}

void GeneralSetupPanel::on_brightCtrl_CB_currentIndexChanged(int index)
{
if (!lock) {
generalSettings.backlightSrc = RawSource(ui->brightCtrl_CB->itemData(ui->brightCtrl_CB->currentIndex()).toInt());
emit modified();
}
}

void GeneralSetupPanel::on_volume_SL_valueChanged()
{
if (!lock) {
Expand Down
4 changes: 3 additions & 1 deletion companion/src/generaledit/generalsetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GeneralSetupPanel : public GeneralPanel
Q_OBJECT

public:
GeneralSetupPanel(QWidget *parent, GeneralSettings & generalSettings, Firmware * firmware);
GeneralSetupPanel(QWidget *parent, GeneralSettings & generalSettings, Firmware * firmware, CompoundItemModelFactory * sharedItemModels);
virtual ~GeneralSetupPanel();

private slots:
Expand All @@ -47,6 +47,8 @@ class GeneralSetupPanel : public GeneralPanel
void on_displayTypeCB_currentIndexChanged(int index);
void on_BLBright_SB_editingFinished();
void on_OFFBright_SB_editingFinished();
void on_brightCtrl_CB_currentIndexChanged(int index);
void on_volumeCtrl_CB_currentIndexChanged(int index);
void on_countrycode_CB_currentIndexChanged(int index);
void on_units_CB_currentIndexChanged(int index);
void on_ppm_units_CB_currentIndexChanged(int index);
Expand Down
Loading
Loading