feat: simple global control for backlight/brightness and volume (#6684)

This commit is contained in:
philmoz
2026-01-04 17:56:50 +10:00
committed by GitHub
parent 586a567b0b
commit e80406b274
71 changed files with 812 additions and 374 deletions
@@ -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
//
@@ -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;
@@ -47,6 +47,7 @@ class AbstractItemModel: public QStandardItemModel
IMID_CurveRefType,
IMID_CurveRefFunc,
IMID_FlexSwitches,
IMID_ControlSource,
IMID_ReservedCount,
IMID_Custom
};
@@ -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
};
@@ -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
+10
View File
@@ -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)
{
@@ -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)
{
+2
View File
@@ -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;
+5
View File
@@ -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);
+1
View File
@@ -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);
@@ -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"
@@ -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;
@@ -694,6 +698,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;
@@ -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
@@ -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;
+8 -1
View File
@@ -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;
@@ -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;
}
+10 -1
View File
@@ -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):
@@ -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();
+2 -1
View File
@@ -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);
+34 -4
View File
@@ -25,22 +25,22 @@
#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(),
@@ -48,6 +48,8 @@ ui(new Ui::GeneralSetup)
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};
@@ -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));
@@ -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) {
+3 -1
View File
@@ -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:
@@ -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);
+24 -2
View File
@@ -651,6 +651,10 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="volumeCtrl_CB">
</widget>
</item>
<item row="14" column="1">
<widget class="QSpinBox" name="BLBright_SB">
<property name="maximum">
@@ -722,13 +726,20 @@
</property>
</widget>
</item>
<item row="16" column="0">
<item row="15" column="0">
<widget class="QLabel" name="label_OFFBright">
<property name="text">
<string>Backlight OFF Brightness</string>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QLabel" name="label_BrightCtrl">
<property name="text">
<string>Backlight Control</string>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QComboBox" name="backlightswCB">
<property name="toolTip">
@@ -932,7 +943,7 @@
</property>
</widget>
</item>
<item row="16" column="1">
<item row="15" column="1">
<widget class="QSpinBox" name="OFFBright_SB">
<property name="minimum">
<number>5</number>
@@ -942,6 +953,10 @@
</property>
</widget>
</item>
<item row="16" column="1">
<widget class="QComboBox" name="brightCtrl_CB">
</widget>
</item>
<item row="19" column="0">
<widget class="QLabel" name="stickReverseLB">
<property name="sizePolicy">
@@ -1147,6 +1162,13 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_volumeCtrl">
<property name="text">
<string>Volume Control</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="speakerPitchSB">
<property name="toolTip">
+22 -3
View File
@@ -365,6 +365,10 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
addParams();
}
connect(this, &HardwarePanel::inputFlexTypeChanged, [=](AutoComboBox *cb, int index)
{ setFlexTypeModel(cb, index); }
);
connect(this, &HardwarePanel::refreshItemModels, [=]() { updateItemModels(); });
addVSpring(grid, 0, grid->rowCount());
addHSpring(grid, grid->columnCount(), 0);
disableMouseScrolling();
@@ -446,6 +450,7 @@ void HardwarePanel::addFlex(int index)
name->setValidator(new NameValidator(board, this));
name->setField(config.name, HARDWARE_NAME_LEN, this);
params->append(name);
connect(name, &AutoLineEdit::editingFinished, [=] () { emit refreshItemModels(); });
AutoComboBox *type = new AutoComboBox(this);
setFlexTypeModel(type, index);
@@ -465,11 +470,10 @@ void HardwarePanel::addFlex(int index)
} else {
invertToggles[index - Boards::getCapability(board, Board::Sticks)]->show();
}
emit InputFlexTypeChanged();
emit inputFlexTypeChanged(type, index);
emit refreshItemModels();
});
connect(this, &HardwarePanel::InputFlexTypeChanged, [=]() { setFlexTypeModel(type, index); });
params->append(type);
AutoCheckBox *inverted = new AutoCheckBox(this);
@@ -508,6 +512,7 @@ void HardwarePanel::addSwitch(int index)
name->setValidator(new NameValidator(board, this));
name->setField(config.name, HARDWARE_NAME_LEN, this);
params->append(name);
connect(name, &AutoLineEdit::editingFinished, [=] () { emit refreshItemModels(); });
AutoComboBox *input = nullptr;
@@ -538,6 +543,12 @@ void HardwarePanel::addSwitch(int index)
type->setField(config.type, this);
params->append(type);
if (!generalSettings.isSwitchFunc(index)) {
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
emit refreshItemModels();
});
}
if (generalSettings.isSwitchFlex(index)) {
connect(input, &AutoComboBox::currentDataChanged, [=] (int val) {
if (val < 0) {
@@ -547,6 +558,8 @@ void HardwarePanel::addSwitch(int index)
}
else
type->setModel(tabFilteredModels->getItemModel(FIM_SWITCHTYPE3POS));
emit refreshItemModels();
});
}
@@ -562,6 +575,7 @@ void HardwarePanel::addSwitch(int index)
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
start->setEnabled(val == Board::SWITCH_2POS);
emit refreshItemModels();
});
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
@@ -677,3 +691,8 @@ void HardwarePanel::updateSerialPortUSBVCP()
view->setRowHidden(i, false);
}
}
void HardwarePanel::updateItemModels()
{
editorItemModels->update(AbstractItemModel::IMUE_Hardware);
}
+3 -1
View File
@@ -41,7 +41,8 @@ class HardwarePanel : public GeneralPanel
signals:
void internalModuleChanged();
void InputFlexTypeChanged();
void inputFlexTypeChanged(AutoComboBox *cb, int index);
void refreshItemModels();
private slots:
void on_internalModuleChanged();
@@ -73,4 +74,5 @@ class HardwarePanel : public GeneralPanel
void setFlexTypeModel(AutoComboBox * cb, int index);
void updateSerialPortUSBVCP();
void updateItemModels();
};