Skip to content

Commit a7e297e

Browse files
author
philmoz
committed
Add ability to set source for backlight / brightness control.
1 parent d51c2e7 commit a7e297e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+812
-374
lines changed

companion/src/datamodels/compounditemmodels.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,62 @@ void FlexSwitchesItemModel::update(const int event)
667667
}
668668
}
669669

670+
//
671+
// ControlSourceItemModel
672+
//
673+
674+
ControlSourceItemModel::ControlSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData,
675+
Firmware * firmware, const Boards * const board, const Board::Type boardType) :
676+
AbstractDynamicItemModel(generalSettings, modelData, firmware, board, boardType)
677+
{
678+
setId(IMID_ControlSource);
679+
setUpdateMask(IMUE_Hardware);
680+
681+
// Descending source direction: inverted (!) sources
682+
addItems(SOURCE_TYPE_SWITCH, -board->getCapability(Board::Switches));
683+
addItems(SOURCE_TYPE_INPUT, -board->getCapability(Board::Inputs), -board->getCapability(Board::Sticks));
684+
685+
// Ascending source direction (including zero)
686+
addItems(SOURCE_TYPE_NONE, 1);
687+
addItems(SOURCE_TYPE_INPUT, board->getCapability(Board::Inputs), board->getCapability(Board::Sticks));
688+
addItems(SOURCE_TYPE_SWITCH, board->getCapability(Board::Switches));
689+
}
690+
691+
void ControlSourceItemModel::setDynamicItemData(QStandardItem * item, const RawSource & src) const
692+
{
693+
item->setText(src.toString(modelData, generalSettings, boardType));
694+
item->setData(src.isAvailable(modelData, generalSettings, boardType, RawSource::AVAILABLE_CONTROLSRC), IMDR_Available);
695+
}
696+
697+
void ControlSourceItemModel::addItems(const RawSourceType & type, int count, const int start)
698+
{
699+
const int idxAdj = (type == SOURCE_TYPE_NONE ? -1 : 0);
700+
701+
int first = start + count < 0 ? start + count : start + 1;
702+
int last = start + count < 0 ? start : start + count + 1;
703+
704+
for (int i = first; i < last; ++i) {
705+
const RawSource src = RawSource(type, i + idxAdj);
706+
QStandardItem * modelItem = new QStandardItem();
707+
modelItem->setData(src.toValue(), IMDR_Id);
708+
modelItem->setData(type, IMDR_Type);
709+
setDynamicItemData(modelItem, src);
710+
appendRow(modelItem);
711+
}
712+
}
713+
714+
void ControlSourceItemModel::update(const int event)
715+
{
716+
if (doUpdate(event)) {
717+
emit aboutToBeUpdated();
718+
719+
for (int i = 0; i < rowCount(); ++i)
720+
setDynamicItemData(item(i), RawSource(item(i)->data(IMDR_Id).toInt()));
721+
722+
emit updateComplete();
723+
}
724+
}
725+
670726
//
671727
// CompoundItemModelFactory
672728
//
@@ -722,6 +778,9 @@ void CompoundItemModelFactory::addItemModel(const int id)
722778
case AbstractItemModel::IMID_FlexSwitches:
723779
registerItemModel(new FlexSwitchesItemModel(generalSettings, modelData, firmware, board, boardType));
724780
break;
781+
case AbstractItemModel::IMID_ControlSource:
782+
registerItemModel(new ControlSourceItemModel(generalSettings, modelData, firmware, board, boardType));
783+
break;
725784
default:
726785
qDebug() << "Error: unknown item model: id";
727786
break;

companion/src/datamodels/compounditemmodels.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class AbstractItemModel: public QStandardItemModel
4747
IMID_CurveRefType,
4848
IMID_CurveRefFunc,
4949
IMID_FlexSwitches,
50+
IMID_ControlSource,
5051
IMID_ReservedCount,
5152
IMID_Custom
5253
};
@@ -81,6 +82,7 @@ class AbstractItemModel: public QStandardItemModel
8182
IMUE_Timers = 1 << 9,
8283
IMUE_Modules = 1 << 10,
8384
IMUE_FunctionSwitches = 1 << 11,
85+
IMUE_Hardware = 1 << 12,
8486
IMUE_All = IMUE_SystemRefresh | IMUE_Channels | IMUE_Curves | IMUE_FlightModes | IMUE_GVars | IMUE_Inputs |
8587
IMUE_LogicalSwitches | IMUE_Scripts | IMUE_TeleSensors | IMUE_Timers | IMUE_Modules | IMUE_FunctionSwitches
8688
};
@@ -349,6 +351,22 @@ class FlexSwitchesItemModel: public AbstractDynamicItemModel
349351
virtual void setDynamicItemData(QStandardItem * item, const int value) const;
350352
};
351353

354+
class ControlSourceItemModel: public AbstractDynamicItemModel
355+
{
356+
Q_OBJECT
357+
public:
358+
explicit ControlSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData,
359+
Firmware * firmware, const Boards * const board, const Board::Type boardType);
360+
virtual ~ControlSourceItemModel() {};
361+
362+
public slots:
363+
virtual void update(const int event = IMUE_SystemRefresh) override;
364+
365+
protected:
366+
virtual void setDynamicItemData(QStandardItem * item, const RawSource & src) const;
367+
void addItems(const RawSourceType & type, int count, const int start = 0);
368+
};
369+
352370

353371
//
354372
// CompoundItemModelFactory

companion/src/firmwares/boardjson.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ bool BoardJson::isInputFlex(const InputDefn & defn)
752752
return defn.type == Board::AIT_FLEX;
753753
}
754754

755+
const bool BoardJson::isInputFlexGyroAxis(int index) const
756+
{
757+
return (index >=0 && index < (int)m_inputs->size()) ? isInputFlexGyroAxis(m_inputs->at(index)) : false;
758+
}
759+
755760
// static
756761
bool BoardJson::isInputFlexGyroAxis(const InputDefn & defn)
757762
{
@@ -761,6 +766,11 @@ bool BoardJson::isInputFlexGyroAxis(const InputDefn & defn)
761766
val[0] == 'T' && val[1] == 'I' && val[2] == 'L' && val[3] == 'T' && val[4] == '_' && (val[5] == 'X' || val[5] == 'Y'));
762767
}
763768

769+
const bool BoardJson::isInputFlexJoystickAxis(int index) const
770+
{
771+
return (index >=0 && index < (int)m_inputs->size()) ? isInputFlexJoystickAxis(m_inputs->at(index)) : false;
772+
}
773+
764774
// static
765775
bool BoardJson::isInputFlexJoystickAxis(const InputDefn & defn)
766776
{

companion/src/firmwares/boardjson.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class BoardJson
130130
const bool isInputCalibrated(int index) const;
131131
const bool isInputConfigurable(int index) const;
132132
const bool isInputIgnored(int index) const;
133+
const bool isInputFlexGyroAxis(int index) const;
134+
const bool isInputFlexJoystickAxis(int index) const;
133135
const bool isInputFlexPot(int index) const;
134136
const bool isInputFlexSwitch(int index) const;
135137
const bool isInputStick(int index) const;

companion/src/firmwares/boards.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,11 @@ bool Boards::isInputConfigurable(int index, Board::Type board)
11591159
return getBoardJson(board)->isInputConfigurable(index);
11601160
}
11611161

1162+
bool Boards::isInputGyroAxis(int index, Board::Type board)
1163+
{
1164+
return getBoardJson(board)->isInputFlexGyroAxis(index);
1165+
}
1166+
11621167
bool Boards::isInputIgnored(int index, Board::Type board)
11631168
{
11641169
return getBoardJson(board)->isInputIgnored(index);

companion/src/firmwares/boards.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ class Boards
454454
static bool isInputAvailable(int index, Board::Type board = Board::BOARD_UNKNOWN);
455455
static bool isInputCalibrated(int index, Board::Type board = Board::BOARD_UNKNOWN);
456456
static bool isInputConfigurable(int index, Board::Type board = Board::BOARD_UNKNOWN);
457+
static bool isInputGyroAxis(int index, Board::Type board = Board::BOARD_UNKNOWN);
457458
static bool isInputIgnored(int index, Board::Type board = Board::BOARD_UNKNOWN);
458459
static bool isInputPot(int index, Board::Type board = Board::BOARD_UNKNOWN);
459460
static bool isInputStick(int index, Board::Type board = Board::BOARD_UNKNOWN);

companion/src/firmwares/edgetx/yaml_generalsettings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "yaml_calibdata.h"
2626
#include "yaml_switchconfig.h"
2727
#include "yaml_moduledata.h"
28+
#include "yaml_rawsource.h"
2829

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

374+
node["backlightSrc"] = rhs.backlightSrc;
375+
node["volumeSrc"] = rhs.volumeSrc;
376+
373377
// Radio level tabs control (global settings)
374378
if (hasColorLcd)
375379
node["radioThemesDisabled"] = (int)rhs.radioThemesDisabled;
@@ -686,6 +690,9 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
686690

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

693+
node["backlightSrc"] >> rhs.backlightSrc;
694+
node["volumeSrc"] >> rhs.volumeSrc;
695+
689696
// Radio level tabs control (global settings)
690697
node["radioThemesDisabled"] >> rhs.radioThemesDisabled;
691698
node["radioGFDisabled"] >> rhs.radioGFDisabled;

companion/src/firmwares/generalsettings.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ void GeneralSettings::convert(RadioDataConversionState & cstate)
432432
customFn[i].convert(cstate.withComponentIndex(i));
433433
}
434434

435+
cstate.setComponent("");
436+
cstate.setSubComp(tr("Backlight Source"));
437+
backlightSrc.convert(cstate);
438+
cstate.setSubComp(tr("Volume Source"));
439+
volumeSrc.convert(cstate);
435440
}
436441

437442
QString GeneralSettings::antennaModeToString() const

companion/src/firmwares/generalsettings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ class GeneralSettings {
394394

395395
char selectedTheme[SELECTED_THEME_NAME_LEN + 1];
396396

397+
RawSource backlightSrc;
398+
RawSource volumeSrc;
399+
397400
// Radio level tabs control (global settings)
398401
bool radioThemesDisabled;
399402
bool radioGFDisabled;

companion/src/firmwares/rawsource.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ bool RawSource::isStick(Board::Type board) const
280280
return false;
281281
}
282282

283-
bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const
283+
bool RawSource::isAvailable(const ModelData * const model,
284+
const GeneralSettings * const gs,
285+
Board::Type board,
286+
const int flags) const
284287
{
285288
if (type == SOURCE_TYPE_NONE && index == 0)
286289
return true;
@@ -392,6 +395,10 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings
392395
gs->serialPort[GeneralSettings::SP_AUX2] == GeneralSettings::AUX_SERIAL_SPACEMOUSE))))
393396
return false;
394397

398+
if (type == SOURCE_TYPE_INPUT && (flags & AVAILABLE_CONTROLSRC) &&
399+
Boards::isInputGyroAxis(abs(index) - 1, board))
400+
return false;
401+
395402
return true;
396403
}
397404

0 commit comments

Comments
 (0)