feat(radio): refactor of switch handling to better support customisable switches (#6095)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
3djc
elecpower
parent
28833f42e6
commit
0c8c39b134
@@ -40,7 +40,7 @@
|
||||
#define CPN_MAX_TRIMS Board::TRIM_AXIS_COUNT
|
||||
#define CPN_MAX_CYC 3
|
||||
#define CPN_MAX_SWITCHES_FLEX 4 // v2.10 cmake parameter FLEXSW
|
||||
#define CPN_MAX_SWITCHES_FUNCTION 6
|
||||
#define CPN_MAX_SWITCHES_FUNCTION 8
|
||||
#define CPN_MAX_SWITCHES_STD 20
|
||||
#define CPN_MAX_SWITCHES (CPN_MAX_SWITCHES_STD + CPN_MAX_SWITCHES_FLEX + CPN_MAX_SWITCHES_FUNCTION)
|
||||
#define CPN_MAX_SENSORS 60
|
||||
@@ -48,7 +48,6 @@
|
||||
#define CPN_MAX_SCRIPT_INPUTS 10
|
||||
#define CPN_MAX_SPACEMOUSE 6
|
||||
#define CPN_MAX_INPUTS 32 // v2.10 replaces CPN_MAX_ANALOGS - the value is abitary as radio ADC refactor is still a WIP
|
||||
#define CPN_MAX_FUNCTIONSWITCH_GROUP 3
|
||||
|
||||
// pre v2.10
|
||||
#define CPN_MAX_POTS 8
|
||||
|
||||
@@ -107,6 +107,8 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
|
||||
setId(IMID_RawSource);
|
||||
setUpdateMask(IMUE_All &~ (IMUE_Curves | IMUE_Scripts));
|
||||
|
||||
int groups = board->getCapability(Board::FunctionSwitchGroups);
|
||||
|
||||
// Descending source direction: inverted (!) sources
|
||||
addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, -firmware->getCapability(Sensors) * 3);
|
||||
addItems(SOURCE_TYPE_TIMER, RawSource::TelemGroup, -firmware->getCapability(Timers));
|
||||
@@ -116,8 +118,8 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
|
||||
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, -firmware->getCapability(TrainerInputs));
|
||||
addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, -CPN_MAX_CYC);
|
||||
addItems(SOURCE_TYPE_CUSTOM_SWITCH, RawSource::SwitchesGroup, -firmware->getCapability(LogicalSwitches));
|
||||
if (modelData)
|
||||
addItems(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, RawSource::SourcesGroup, -CPN_MAX_FUNCTIONSWITCH_GROUP);
|
||||
if (modelData && groups > 0)
|
||||
addItems(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, RawSource::SourcesGroup, -groups);
|
||||
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, -board->getCapability(Board::Switches));
|
||||
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, -1);
|
||||
addItems(SOURCE_TYPE_MIN, RawSource::SourcesGroup, -1);
|
||||
@@ -139,8 +141,8 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
|
||||
addItems(SOURCE_TYPE_MIN, RawSource::SourcesGroup, 1);
|
||||
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, 1);
|
||||
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, board->getCapability(Board::Switches));
|
||||
if (modelData)
|
||||
addItems(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, RawSource::SourcesGroup, CPN_MAX_FUNCTIONSWITCH_GROUP);
|
||||
if (modelData && groups > 0)
|
||||
addItems(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, RawSource::SourcesGroup, groups);
|
||||
addItems(SOURCE_TYPE_CUSTOM_SWITCH, RawSource::SwitchesGroup, firmware->getCapability(LogicalSwitches));
|
||||
addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, CPN_MAX_CYC);
|
||||
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, firmware->getCapability(TrainerInputs));
|
||||
|
||||
@@ -50,7 +50,6 @@ static const StringTagMappingTable switchTypesLookupTable = {
|
||||
{std::to_string(Board::SWITCH_TOGGLE), "TOGGLE"},
|
||||
{std::to_string(Board::SWITCH_2POS), "2POS"},
|
||||
{std::to_string(Board::SWITCH_3POS), "3POS"},
|
||||
{std::to_string(Board::SWITCH_FUNC), "FSWITCH"},
|
||||
{std::to_string(Board::SWITCH_ADC), "ADC"},
|
||||
};
|
||||
|
||||
@@ -443,6 +442,24 @@ const int BoardJson::getSwitchIndex(const QString val, Board::LookupValueType lv
|
||||
return getSwitchIndex(m_switches, val, lvt);
|
||||
}
|
||||
|
||||
const int BoardJson::getCFSIndexForSwitch(int sw) const
|
||||
{
|
||||
if (sw < (int)m_switches->size() && m_switches->at(sw).isCustomSwitch)
|
||||
return m_switches->at(sw).customSwitchIdx;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int BoardJson::getSwitchIndexForCFS(int cfsIdx) const
|
||||
{
|
||||
for (int i = 0; i < (int)m_switches->size(); i++) {
|
||||
if (m_switches->at(i).isCustomSwitch && m_switches->at(i).customSwitchIdx == cfsIdx)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// static
|
||||
int BoardJson::getSwitchIndex(const SwitchesTable * switches, QString val, Board::LookupValueType lvt)
|
||||
{
|
||||
@@ -772,7 +789,7 @@ const bool BoardJson::isSwitchConfigurable(int index) const
|
||||
{
|
||||
if (index >= 0 && index < getCapability(Board::Switches)) {
|
||||
SwitchDefn &defn = m_switches->at(index);
|
||||
if (isSwitchStd(defn))
|
||||
if (isSwitchStd(defn) || isSwitchFunc(defn))
|
||||
return true;
|
||||
|
||||
if (isSwitchFlex(defn)) {
|
||||
@@ -813,7 +830,7 @@ const bool BoardJson::isSwitchFunc(int index) const
|
||||
// static
|
||||
bool BoardJson::isSwitchFunc(const SwitchDefn & defn)
|
||||
{
|
||||
return defn.type == Board::SWITCH_FUNC;
|
||||
return defn.customSwitchIdx >= 0;
|
||||
}
|
||||
|
||||
bool BoardJson::loadDefinition()
|
||||
@@ -996,6 +1013,12 @@ bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs
|
||||
sw.display.y = (unsigned int)d.at(1).toInt(0);
|
||||
}
|
||||
|
||||
if (!o.value("is_cfs").isUndefined())
|
||||
sw.isCustomSwitch = o.value("is_cfs").toBool();
|
||||
|
||||
if (!o.value("cfs_idx").isUndefined())
|
||||
sw.customSwitchIdx = o.value("cfs_idx").toInt();
|
||||
|
||||
// special handing for ADC
|
||||
if (sw.type == Board::SWITCH_ADC) {
|
||||
if (sw.dflt == Board::SWITCH_TOGGLE) {
|
||||
|
||||
@@ -61,13 +61,15 @@ class BoardJson
|
||||
};
|
||||
|
||||
struct SwitchDefn {
|
||||
Board::SwitchType type = Board::SWITCH_NOT_AVAILABLE;
|
||||
std::string tag = "";
|
||||
Board::SwitchType type = Board::SWITCH_NOT_AVAILABLE;
|
||||
std::string name = "";
|
||||
int flags = 0;
|
||||
bool inverted = false;
|
||||
Board::SwitchType dflt = Board::SWITCH_NOT_AVAILABLE;
|
||||
Display display;
|
||||
bool isCustomSwitch = false;
|
||||
int customSwitchIdx = -1;
|
||||
Board::LookupValueType cfgYaml = Board::LVT_TAG;
|
||||
Board::LookupValueType refYaml = Board::LVT_NAME;
|
||||
|
||||
@@ -137,6 +139,8 @@ class BoardJson
|
||||
const int getKeyIndex(const QString key) const;
|
||||
|
||||
const int getSwitchIndex(const QString val, Board::LookupValueType lvt) const;
|
||||
const int getCFSIndexForSwitch(int sw) const;
|
||||
const int getSwitchIndexForCFS(int customSwitchIdx) const;
|
||||
const Board::SwitchInfo getSwitchInfo(int index) const;
|
||||
const QString getSwitchName(int index) const;
|
||||
const QString getSwitchTag(int index) const;
|
||||
|
||||
@@ -315,6 +315,12 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)
|
||||
else
|
||||
return getCapability(board, Board::Switches);
|
||||
|
||||
case FunctionSwitchGroups:
|
||||
if (getCapability(board, FunctionSwitches)) {
|
||||
return IS_RADIOMASTER_GX12(board) ? 4 : 3;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case HasAudioMuteGPIO:
|
||||
// All color lcd (including NV14 and EL18) except Horus X12S
|
||||
// TX12, TX12MK2, ZORRO, BOXER, T8, TLITE, TPRO, LR3PRO, COMMANDO8
|
||||
@@ -406,7 +412,7 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)
|
||||
return IS_RADIOMASTER_MT12(board);
|
||||
|
||||
case FunctionSwitchColors:
|
||||
return IS_RADIOMASTER_GX12(board);
|
||||
return IS_RADIOMASTER_GX12(board) || IS_FLYSKY_ST16(board);
|
||||
|
||||
default:
|
||||
return getBoardJson(board)->getCapability(capability);
|
||||
@@ -679,6 +685,8 @@ QString Boards::switchTypeToString(int value)
|
||||
return tr("2 Positions");
|
||||
case SWITCH_3POS:
|
||||
return tr("3 Positions");
|
||||
case SWITCH_GLOBAL:
|
||||
return tr("Global");
|
||||
case SWITCH_FUNC:
|
||||
return tr("Function");
|
||||
default:
|
||||
@@ -692,7 +700,7 @@ AbstractStaticItemModel * Boards::switchTypeItemModel()
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_BOARDS_SWITCH_TYPE);
|
||||
|
||||
for (int i = 0; i < SWITCH_FUNC; i++) { // Function not required in lists
|
||||
for (int i = 0; i < SWITCH_GLOBAL; i++) { // Function not required in lists
|
||||
mdl->appendToItemList(switchTypeToString(i), i, true, 0,
|
||||
(i == SWITCH_NOT_AVAILABLE ? SwitchTypeFlagNone : (i < SWITCH_3POS ? SwitchTypeFlag2Pos : SwitchTypeFlag3Pos)));
|
||||
}
|
||||
@@ -1046,6 +1054,16 @@ int Boards::getSwitchIndex(QString val, Board::LookupValueType lvt, Board::Type
|
||||
return getBoardJson(board)->getSwitchIndex(val, lvt);
|
||||
}
|
||||
|
||||
int Boards::getCFSIndexForSwitch(int swIdx, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getCFSIndexForSwitch(swIdx);
|
||||
}
|
||||
|
||||
int Boards::getSwitchIndexForCFS(int cfsIdx, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getSwitchIndexForCFS(cfsIdx);
|
||||
}
|
||||
|
||||
QString Boards::getSwitchName(int index, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getSwitchName(index);
|
||||
|
||||
@@ -119,6 +119,7 @@ namespace Board {
|
||||
SWITCH_TOGGLE,
|
||||
SWITCH_2POS,
|
||||
SWITCH_3POS,
|
||||
SWITCH_GLOBAL,
|
||||
SWITCH_FUNC,
|
||||
SWITCH_ADC,
|
||||
SWITCH_TYPE_COUNT
|
||||
@@ -212,6 +213,7 @@ namespace Board {
|
||||
FlexSwitches,
|
||||
FunctionSwitches,
|
||||
FunctionSwitchColors,
|
||||
FunctionSwitchGroups,
|
||||
Gyros,
|
||||
GyroAxes,
|
||||
HasAudioMuteGPIO,
|
||||
@@ -426,6 +428,8 @@ class Boards
|
||||
|
||||
static Board::SwitchInfo getSwitchInfo(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getSwitchIndex(QString val, Board::LookupValueType lvt, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getCFSIndexForSwitch(int swIdx, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getSwitchIndexForCFS(int cfsIdx, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static QString getSwitchName(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static QString getSwitchTag(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getSwitchTagNum(int index, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
|
||||
@@ -262,7 +262,7 @@ bool CustomFunctionData::isFuncAvailable(const int index, const ModelData * mode
|
||||
((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars)) ||
|
||||
((index == FuncDisableTouch) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
|
||||
((index == FuncDisableAudioAmp && !Boards::getCapability(fw->getBoard(), Board::HasAudioMuteGPIO))) ||
|
||||
((index == FuncRGBLed && !Boards::getCapability(fw->getBoard(), Board::HasLedStripGPIO))) ||
|
||||
((index == FuncRGBLed && !(Boards::getCapability(fw->getBoard(), Board::HasLedStripGPIO) || Boards::getCapability(fw->getBoard(), Board::FunctionSwitchColors)))) ||
|
||||
((index == FuncLCDtoVideo && !IS_FATFISH_F16(fw->getBoard()))) ||
|
||||
((index >= FuncPushCustomSwitch1 && index <= FuncPushCustomSwitchLast) && !Boards::getCapability(fw->getBoard(), Board::FunctionSwitches))
|
||||
);
|
||||
|
||||
@@ -602,7 +602,8 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
|
||||
// however when parsing saved settings set all switches to None and override with parsed values
|
||||
// thus any switches not parsed will be None rather than the default
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES; i++) {
|
||||
rhs.switchConfig[i].type = Board::SWITCH_NOT_AVAILABLE;
|
||||
if (Boards::getCFSIndexForSwitch(i) < 0)
|
||||
rhs.switchConfig[i].type = Board::SWITCH_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (node["switchConfig"]) {
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
#include "yaml_sensordata.h"
|
||||
#include "yaml_screendata.h"
|
||||
#include "yaml_usbjoystickdata.h"
|
||||
#include "yaml_switchconfig.h"
|
||||
|
||||
#include "boardjson.h"
|
||||
#include "modeldata.h"
|
||||
#include "output_data.h"
|
||||
#include "eeprominterface.h"
|
||||
@@ -73,7 +75,7 @@ void YamlValidateLabelsNames(ModelData& model, Board::Type board)
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i++) {
|
||||
YamlValidateName(model.functionSwitchNames[i], board);
|
||||
YamlValidateName(model.customSwitches[i].name, board);
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
|
||||
@@ -149,6 +151,25 @@ static const YamlLookupTable hatsModeLut = {
|
||||
{ GeneralSettings::HATSMODE_GLOBAL, "GLOBAL" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable cfsSwitchConfig = {
|
||||
{ 0, "NONE" },
|
||||
{ 1, "TOGGLE" },
|
||||
{ 2, "2POS" },
|
||||
{ 3, "3POS" },
|
||||
{ 4, "GLOBAL" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable cfsSwitchStart = {
|
||||
{ 0, "START_OFF" },
|
||||
{ 1, "START_ON" },
|
||||
{ 2, "START_PREVIOUS" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable cfsSwitchLuaOverride = {
|
||||
{ 0, "OFF" },
|
||||
{ 1, "ON" },
|
||||
};
|
||||
|
||||
struct YamlTrim {
|
||||
int mode = 0;
|
||||
int ref = 0;
|
||||
@@ -283,27 +304,24 @@ struct YamlSwitchWarning {
|
||||
static constexpr size_t MASK_LEN = 2;
|
||||
static constexpr size_t MASK = (1 << MASK_LEN) - 1;
|
||||
|
||||
unsigned int enabled;
|
||||
|
||||
YamlSwitchWarning() = default;
|
||||
|
||||
YamlSwitchWarning(YAML::Node& node, uint64_t cpn_value, unsigned int switchWarningEnable)
|
||||
: enabled(~switchWarningEnable)
|
||||
YamlSwitchWarning(YAML::Node& node, uint64_t cpn_value)
|
||||
{
|
||||
uint64_t states = cpn_value;
|
||||
|
||||
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
|
||||
if (!Boards::isSwitchFunc(i) && (enabled & (1 << i))) {
|
||||
if (states & MASK) {
|
||||
std::string posn;
|
||||
|
||||
switch(states & MASK) {
|
||||
case 0:
|
||||
case 1:
|
||||
posn = "up";
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
posn = "mid";
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
posn = "down";
|
||||
break;
|
||||
}
|
||||
@@ -318,7 +336,6 @@ struct YamlSwitchWarning {
|
||||
uint64_t toCpn(const YAML::Node &warn)
|
||||
{
|
||||
uint64_t states = 0;
|
||||
enabled = 0;
|
||||
|
||||
if (warn.IsMap()) {
|
||||
for (const auto& sw : warn) {
|
||||
@@ -336,14 +353,13 @@ struct YamlSwitchWarning {
|
||||
int value = 0;
|
||||
|
||||
if (posn == "up")
|
||||
value = 0;
|
||||
else if (posn == "mid")
|
||||
value = 1;
|
||||
else if (posn == "down")
|
||||
else if (posn == "mid")
|
||||
value = 2;
|
||||
else if (posn == "down")
|
||||
value = 3;
|
||||
|
||||
states |= ((uint64_t)value << (index * MASK_LEN));
|
||||
enabled |= (1 << index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,32 +376,30 @@ struct YamlSwitchWarningState {
|
||||
static constexpr size_t MASK = (1 << MASK_LEN) - 1;
|
||||
|
||||
std::string src_str;
|
||||
unsigned int enabled;
|
||||
|
||||
YamlSwitchWarningState() = default;
|
||||
|
||||
YamlSwitchWarningState(uint64_t cpn_value, unsigned int switchWarningEnable)
|
||||
: enabled(~switchWarningEnable)
|
||||
YamlSwitchWarningState(uint64_t cpn_value)
|
||||
{
|
||||
uint64_t states = cpn_value;
|
||||
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
|
||||
//TODO: exclude 2-pos toggle from switch warnings
|
||||
if (enabled & (1 << i)) {
|
||||
if (states & MASK) {
|
||||
std::string tag = Boards::getSwitchTag(i).toStdString();
|
||||
const char *sw = tag.data();
|
||||
|
||||
if (tag.size() >= 2 && sw[0] == 'S') {
|
||||
ss << sw[1];
|
||||
switch(states & MASK) {
|
||||
case 0:
|
||||
case 1:
|
||||
ss << 'u';
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
ss << '-';
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
ss << 'd';
|
||||
break;
|
||||
}
|
||||
@@ -400,7 +414,6 @@ struct YamlSwitchWarningState {
|
||||
uint64_t toCpn()
|
||||
{
|
||||
uint64_t states = 0;
|
||||
enabled = 0;
|
||||
|
||||
std::stringstream ss(src_str);
|
||||
while (!ss.eof()) {
|
||||
@@ -422,20 +435,19 @@ struct YamlSwitchWarningState {
|
||||
int value = 0;
|
||||
switch(s) {
|
||||
case 'u':
|
||||
value = 0;
|
||||
break;
|
||||
case '-':
|
||||
value = 1;
|
||||
break;
|
||||
case 'd':
|
||||
case '-':
|
||||
value = 2;
|
||||
break;
|
||||
case 'd':
|
||||
value = 3;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
states |= ((uint64_t)value << (index * MASK_LEN));
|
||||
enabled |= (1 << index);
|
||||
}
|
||||
|
||||
return states;
|
||||
@@ -955,6 +967,47 @@ struct convert<FrSkyScreenData> {
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<customSwitch> {
|
||||
static Node encode(const customSwitch& rhs);
|
||||
static bool decode(const Node& node, customSwitch& rhs);
|
||||
};
|
||||
|
||||
Node convert<customSwitch>::encode(const customSwitch& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["type"] = cfsSwitchConfig << rhs.type;
|
||||
node["group"] = rhs.group;
|
||||
node["start"] = cfsSwitchStart << rhs.start;
|
||||
node["state"] = rhs.state;
|
||||
node["name"] = rhs.name;
|
||||
if (Boards::getCapability(getCurrentBoard(), Board::FunctionSwitchColors)) {
|
||||
node["onColorLuaOverride"] = cfsSwitchLuaOverride << rhs.onColorLuaOverride;
|
||||
node["offColorLuaOverride"] = cfsSwitchLuaOverride << rhs.offColorLuaOverride;
|
||||
node["onColor"] = rhs.onColor;
|
||||
node["offColor"] = rhs.offColor;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<customSwitch>::decode(const Node& node, customSwitch& rhs)
|
||||
{
|
||||
if (!node.IsMap()) return false;
|
||||
|
||||
unsigned type;
|
||||
node["type"] >> cfsSwitchConfig >> type;
|
||||
rhs.type = (Board::SwitchType)type;
|
||||
node["group"] >> rhs.group;
|
||||
node["start"] >> cfsSwitchStart >> rhs.start;
|
||||
node["state"] >> rhs.state;
|
||||
node["name"] >> rhs.name;
|
||||
node["onColorLuaOverride"] >> cfsSwitchLuaOverride >> rhs.onColorLuaOverride;
|
||||
node["offColorLuaOverride"] >> cfsSwitchLuaOverride >> rhs.offColorLuaOverride;
|
||||
node["onColor"] >> rhs.onColor;
|
||||
node["offColor"] >> rhs.offColor;
|
||||
return true;
|
||||
}
|
||||
|
||||
Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
{
|
||||
modelSettingsVersion = SemanticVersion(VERSION);
|
||||
@@ -1076,7 +1129,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
node["thrTraceSrc"] = thrTrace.src;
|
||||
|
||||
Node sw_warn;
|
||||
YamlSwitchWarning switchWarning(sw_warn, rhs.switchWarningStates, rhs.switchWarningEnable);
|
||||
YamlSwitchWarning switchWarning(sw_warn, rhs.switchWarningStates);
|
||||
if (sw_warn && sw_warn.IsMap()) {
|
||||
node["switchWarning"] = sw_warn;
|
||||
}
|
||||
@@ -1194,29 +1247,16 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
node["modelRegistrationID"] = rhs.registrationId;
|
||||
node["hatsMode"] = hatsModeLut << rhs.hatsMode;
|
||||
|
||||
if (Boards::getCapability(board, Board::FunctionSwitches)) {
|
||||
node["functionSwitchConfig"] = rhs.functionSwitchConfig;
|
||||
node["functionSwitchGroup"] = rhs.functionSwitchGroup;
|
||||
node["functionSwitchStartConfig"] = rhs.functionSwitchStartConfig;
|
||||
node["functionSwitchLogicalState"] = rhs.functionSwitchLogicalState;
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i++) {
|
||||
if (strlen(rhs.functionSwitchNames[i]) > 0) {
|
||||
node["switchNames"][std::to_string(i)]["val"] = rhs.functionSwitchNames[i];
|
||||
}
|
||||
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
|
||||
if (funcSwCnt) {
|
||||
for (int i = 0; i < funcSwCnt; i += 1) {
|
||||
int sw = Boards::getSwitchIndexForCFS(i);
|
||||
std::string tag = Boards::getSwitchYamlName(sw, BoardJson::YLT_CONFIG).toStdString();
|
||||
node["customSwitches"][tag] = rhs.customSwitches[i];
|
||||
}
|
||||
|
||||
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
|
||||
node["functionSwitchLedONColor"][std::to_string(i)]["r"] = rhs.functionSwitchLedONColor[i].r;
|
||||
node["functionSwitchLedONColor"][std::to_string(i)]["g"] = rhs.functionSwitchLedONColor[i].g;
|
||||
node["functionSwitchLedONColor"][std::to_string(i)]["b"] = rhs.functionSwitchLedONColor[i].b;
|
||||
}
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)]["r"] = rhs.functionSwitchLedOFFColor[i].r;
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)]["g"] = rhs.functionSwitchLedOFFColor[i].g;
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)]["b"] = rhs.functionSwitchLedOFFColor[i].b;
|
||||
}
|
||||
for (int i = 1; i < 4; i += 1) {
|
||||
node["cfsGroupOn"][std::to_string(i)]["v"] = rhs.cfsGroupOn[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1351,16 +1391,13 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
||||
if (node["switchWarning"]) {
|
||||
YamlSwitchWarning switchWarning;
|
||||
rhs.switchWarningStates = switchWarning.toCpn(node["switchWarning"]);
|
||||
rhs.switchWarningEnable = ~switchWarning.enabled;
|
||||
}
|
||||
else if (node["switchWarningState"]) { // depreciated
|
||||
YamlSwitchWarningState switchWarningState;
|
||||
node["switchWarningState"] >> switchWarningState.src_str;
|
||||
rhs.switchWarningStates = switchWarningState.toCpn();
|
||||
rhs.switchWarningEnable = ~switchWarningState.enabled;
|
||||
} else {
|
||||
rhs.switchWarningStates = 0;
|
||||
rhs.switchWarningEnable = ~0;
|
||||
}
|
||||
|
||||
node["thrTrimSw"] >> rhs.thrTrimSwitch;
|
||||
@@ -1481,26 +1518,77 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
||||
node["modelRegistrationID"] >> rhs.registrationId;
|
||||
node["hatsMode"] >> hatsModeLut >> rhs.hatsMode;
|
||||
|
||||
node["functionSwitchConfig"] >> rhs.functionSwitchConfig;
|
||||
node["functionSwitchGroup"] >> rhs.functionSwitchGroup;
|
||||
node["functionSwitchStartConfig"] >> rhs.functionSwitchStartConfig;
|
||||
node["functionSwitchLogicalState"] >> rhs.functionSwitchLogicalState;
|
||||
node["switchNames"] >> rhs.functionSwitchNames;
|
||||
rhs.setDefaultFunctionSwitches(Boards::getCapability(board, Board::FunctionSwitches));
|
||||
|
||||
if (node["functionSwitchConfig"]) {
|
||||
uint16_t v;
|
||||
node["functionSwitchConfig"] >> v;
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
rhs.customSwitches[i].type = (Board::SwitchType)(v & 3);
|
||||
v >>= 2;
|
||||
}
|
||||
}
|
||||
if (node["functionSwitchGroup"]) {
|
||||
uint16_t v;
|
||||
node["functionSwitchGroup"] >> v;
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
rhs.customSwitches[i].group = v & 3;
|
||||
v >>= 2;
|
||||
}
|
||||
for (int i = 0; i < 4; i += 1) {
|
||||
rhs.cfsGroupOn[i] = v & 1;
|
||||
v >>= 1;
|
||||
}
|
||||
}
|
||||
if (node["functionSwitchStartConfig"]) {
|
||||
uint16_t v;
|
||||
node["functionSwitchStartConfig"] >> v;
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
rhs.customSwitches[i].start = v & 3;
|
||||
v >>= 2;
|
||||
}
|
||||
}
|
||||
if (node["functionSwitchLogicalState"]) {
|
||||
uint16_t v;
|
||||
node["functionSwitchLogicalState"] >> v;
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
rhs.customSwitches[i].state = v & 1;
|
||||
v >>= 1;
|
||||
}
|
||||
}
|
||||
if (node["switchNames"]) {
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
if (node["switchNames"][std::to_string(i)]) {
|
||||
node["switchNames"][std::to_string(i)]["val"] >> rhs.customSwitches[i].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node["functionSwitchLedONColor"]) {
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
if (node["functionSwitchLedONColor"][std::to_string(i)]) {
|
||||
node["functionSwitchLedONColor"][std::to_string(i)]["r"] >> rhs.functionSwitchLedONColor[i].r;
|
||||
node["functionSwitchLedONColor"][std::to_string(i)]["g"] >> rhs.functionSwitchLedONColor[i].g;
|
||||
node["functionSwitchLedONColor"][std::to_string(i)]["b"] >> rhs.functionSwitchLedONColor[i].b;
|
||||
node["functionSwitchLedONColor"][std::to_string(i)] >> rhs.customSwitches[i].onColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node["functionSwitchLedOFFColor"]) {
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES_FUNCTION; i += 1) {
|
||||
for (int i = 0; i < 6; i += 1) {
|
||||
if (node["functionSwitchLedOFFColor"][std::to_string(i)]) {
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)]["r"] >> rhs.functionSwitchLedOFFColor[i].r;
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)]["g"] >> rhs.functionSwitchLedOFFColor[i].g;
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)]["b"] >> rhs.functionSwitchLedOFFColor[i].b;
|
||||
node["functionSwitchLedOFFColor"][std::to_string(i)] >> rhs.customSwitches[i].offColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
|
||||
if (node["customSwitches"]) {
|
||||
for (int i = 0; i < funcSwCnt; i += 1) {
|
||||
int sw = Boards::getSwitchIndexForCFS(i);
|
||||
std::string tag = Boards::getSwitchYamlName(sw, BoardJson::YLT_CONFIG).toStdString();
|
||||
node["customSwitches"][tag] >> rhs.customSwitches[i];
|
||||
}
|
||||
}
|
||||
if (node["cfsGroupOn"]) {
|
||||
for (int i = 1; i < 4; i += 1) {
|
||||
if (node["cfsGroupOn"][std::to_string(i)]) {
|
||||
node["cfsGroupOn"][std::to_string(i)]["v"] >> rhs.cfsGroupOn[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
#include "boardjson.h"
|
||||
|
||||
const YamlLookupTable switchConfigLut = {
|
||||
{Board::SWITCH_NOT_AVAILABLE, "NONE"},
|
||||
{Board::SWITCH_TOGGLE, "TOGGLE"},
|
||||
{Board::SWITCH_2POS, "2POS"},
|
||||
{Board::SWITCH_3POS, "3POS"},
|
||||
{Board::SWITCH_GLOBAL, "GLOBAL"},
|
||||
{Board::SWITCH_NOT_AVAILABLE, "none"},
|
||||
{Board::SWITCH_TOGGLE, "toggle"},
|
||||
{Board::SWITCH_2POS, "2pos"},
|
||||
@@ -117,8 +122,13 @@ YamlSwitchConfig::YamlSwitchConfig(const GeneralSettings::SwitchConfig* rhs)
|
||||
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
|
||||
config[i].tag = Boards::getSwitchYamlName(i, BoardJson::YLT_CONFIG).toStdString();
|
||||
config[i].type = rhs[i].type;
|
||||
config[i].start = rhs[i].start;
|
||||
memcpy(config[i].name, rhs[i].name, sizeof(HARDWARE_NAME_LEN));
|
||||
// config[i].inverted = rhs[i].inverted;
|
||||
config[i].onColorLuaOverride = rhs[i].onColorLuaOverride;
|
||||
config[i].offColorLuaOverride = rhs[i].offColorLuaOverride;
|
||||
config[i].onColor = rhs[i].onColor;
|
||||
config[i].offColor = rhs[i].offColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +138,12 @@ void YamlSwitchConfig::copy(GeneralSettings::SwitchConfig* rhs) const
|
||||
if (config[i].type != (unsigned int)Board::SWITCH_NOT_AVAILABLE) {
|
||||
memcpy(rhs[i].name, config[i].name, sizeof(HARDWARE_NAME_LEN));
|
||||
rhs[i].type = (Board::SwitchType)config[i].type;
|
||||
rhs[i].start = config[i].start;
|
||||
// rhs[i].inverted = config[i].inverted;
|
||||
rhs[i].onColorLuaOverride = config[i].onColorLuaOverride;
|
||||
rhs[i].offColorLuaOverride = config[i].offColorLuaOverride;
|
||||
rhs[i].onColor = config[i].onColor;
|
||||
rhs[i].offColor = config[i].offColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,11 +206,32 @@ bool convert<InputConfig>::decode(const Node& node, InputConfig& rhs)
|
||||
return true;
|
||||
}
|
||||
|
||||
static const YamlLookupTable cfsSwitchStart = {
|
||||
{ 0, "START_OFF" },
|
||||
{ 1, "START_ON" },
|
||||
{ 2, "START_PREVIOUS" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable cfsSwitchLuaOverride = {
|
||||
{ 0, "OFF" },
|
||||
{ 1, "ON" },
|
||||
};
|
||||
|
||||
Node convert<SwitchConfig>::encode(const SwitchConfig& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["type"] = switchConfigLut << rhs.type;
|
||||
node["name"] = rhs.name;
|
||||
if (Boards::getCapability(getCurrentBoard(), Board::FunctionSwitches)) {
|
||||
int idx = Boards::getSwitchYamlIndex(rhs.tag.c_str(), BoardJson::YLT_REF);
|
||||
if (Boards::isSwitchFunc(idx, getCurrentBoard())) {
|
||||
node["start"] = cfsSwitchStart << rhs.start;
|
||||
node["onColorLuaOverride"] = cfsSwitchLuaOverride << rhs.onColorLuaOverride;
|
||||
node["offColorLuaOverride"] = cfsSwitchLuaOverride << rhs.offColorLuaOverride;
|
||||
node["onColor"] = rhs.onColor;
|
||||
node["offColor"] = rhs.offColor;
|
||||
}
|
||||
}
|
||||
// node["inv"] = (int)rhs.inverted; in hwdef json but not implemented in radio yaml
|
||||
return node;
|
||||
}
|
||||
@@ -206,7 +242,12 @@ bool convert<SwitchConfig>::decode(const Node& node, SwitchConfig& rhs)
|
||||
|
||||
node["type"] >> switchConfigLut >> rhs.type;
|
||||
node["name"] >> rhs.name;
|
||||
node["start"] >> cfsSwitchStart >> rhs.start;
|
||||
// node["inv"] >> rhs.inverted; in hwdef json but not implemented in radio yaml
|
||||
node["onColorLuaOverride"] >> cfsSwitchLuaOverride >> rhs.onColorLuaOverride;
|
||||
node["offColorLuaOverride"] >> cfsSwitchLuaOverride >> rhs.offColorLuaOverride;
|
||||
node["onColor"] >> rhs.onColor;
|
||||
node["offColor"] >> rhs.offColor;
|
||||
|
||||
if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
|
||||
int idx = Boards::getSwitchYamlIndex(rhs.tag.c_str(), BoardJson::YLT_CONFIG);
|
||||
@@ -420,4 +461,21 @@ bool convert<YamlSwitchesFlex>::decode(const Node& node, YamlSwitchesFlex& rhs)
|
||||
return true;
|
||||
}
|
||||
|
||||
Node convert<RGBLedColor>::encode(const RGBLedColor& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["r"] = rhs.r;
|
||||
node["g"] = rhs.g;
|
||||
node["b"] = rhs.b;
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<RGBLedColor>::decode(const Node& node, RGBLedColor& rhs)
|
||||
{
|
||||
node["r"] >> rhs.r;
|
||||
node["g"] >> rhs.g;
|
||||
node["b"] >> rhs.b;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace YAML
|
||||
|
||||
@@ -69,7 +69,12 @@ struct SwitchConfig {
|
||||
std::string tag = std::string();
|
||||
char name[HARDWARE_NAME_LEN + 1] = {'\0'};
|
||||
unsigned int type = 0;
|
||||
int start = 0;
|
||||
bool inverted = false;
|
||||
unsigned int onColorLuaOverride = false;
|
||||
unsigned int offColorLuaOverride = false;
|
||||
RGBLedColor onColor;
|
||||
RGBLedColor offColor;
|
||||
};
|
||||
|
||||
ENCODE_DECODE_CONFIG(SwitchConfig)
|
||||
@@ -87,3 +92,12 @@ INPUT_SWITCH_CONFIG(YamlSliderConfig, CPN_MAX_INPUTS, InputConfig, InputConfig)
|
||||
INPUT_SWITCH_CONFIG(YamlStickConfig, CPN_MAX_INPUTS, InputConfig, InputConfig)
|
||||
INPUT_SWITCH_CONFIG(YamlSwitchConfig, CPN_MAX_SWITCHES, SwitchConfig, SwitchConfig)
|
||||
INPUT_SWITCH_CONFIG(YamlSwitchesFlex, CPN_MAX_SWITCHES_FLEX, SwitchFlex, SwitchConfig)
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
template <>
|
||||
struct convert<RGBLedColor> {
|
||||
static Node encode(const RGBLedColor& rhs);
|
||||
static bool decode(const Node& node, RGBLedColor& rhs);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -170,6 +170,11 @@ bool GeneralSettings::isSwitchFlex(int index) const
|
||||
return Boards::isSwitchFlex(index);
|
||||
}
|
||||
|
||||
bool GeneralSettings::isSwitchFunc(int index) const
|
||||
{
|
||||
return Boards::isSwitchFunc(index);
|
||||
}
|
||||
|
||||
bool GeneralSettings::unassignedInputFlexSwitches() const
|
||||
{
|
||||
Board::Type board = getCurrentBoard();
|
||||
@@ -372,6 +377,10 @@ void GeneralSettings::setDefaultControlTypes(Board::Type board)
|
||||
switchConfig[i].type = info.dflt;
|
||||
switchConfig[i].inverted = info.inverted;
|
||||
switchConfig[i].inputIdx = SWITCH_INPUTINDEX_NONE;
|
||||
if (Boards::isSwitchFunc(i)) {
|
||||
switchConfig[i].start = ModelData::FUNC_SWITCH_START_PREVIOUS;
|
||||
switchConfig[i].onColor.setColor(255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
|
||||
@@ -61,6 +61,17 @@ enum UartModes {
|
||||
UART_MODE_DEBUG
|
||||
};
|
||||
|
||||
class RGBLedColor {
|
||||
public:
|
||||
RGBLedColor() { clear(); }
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(RGBLedColor)); }
|
||||
void setColor(int red, int green, int blue) { r = red; g = green; b = blue; }
|
||||
QColor getQColor() { return QColor(r, g, b); }
|
||||
};
|
||||
|
||||
class TrainerMix {
|
||||
Q_DECLARE_TR_FUNCTIONS(TrainerMix)
|
||||
|
||||
@@ -362,6 +373,12 @@ class GeneralSettings {
|
||||
Board::SwitchType type;
|
||||
bool inverted;
|
||||
int inputIdx; // used if switch tag = FLn, value -1 = none selected
|
||||
// CFS settings
|
||||
unsigned int start;
|
||||
unsigned int onColorLuaOverride;
|
||||
unsigned int offColorLuaOverride;
|
||||
RGBLedColor onColor;
|
||||
RGBLedColor offColor;
|
||||
};
|
||||
|
||||
SwitchConfig switchConfig[CPN_MAX_SWITCHES];
|
||||
@@ -377,6 +394,7 @@ class GeneralSettings {
|
||||
bool isInputFlexSwitchAvailable(int index) const;
|
||||
bool isSwitchAvailable(int index) const;
|
||||
bool isSwitchFlex(int index) const;
|
||||
bool isSwitchFunc(int index) const;
|
||||
bool unassignedInputFlexSwitches() const;
|
||||
|
||||
QString antennaModeToString() const;
|
||||
|
||||
@@ -223,8 +223,13 @@ void ModelData::setDefaultFunctionSwitches(int functionSwitchCount)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < functionSwitchCount; i++) {
|
||||
setFuncSwitchConfig(i, Board::SWITCH_2POS);
|
||||
setFuncSwitchGroup(i, 1);
|
||||
customSwitches[i].type = Board::SWITCH_GLOBAL;
|
||||
customSwitches[i].group = 0;
|
||||
customSwitches[i].start = ModelData::FUNC_SWITCH_START_PREVIOUS;
|
||||
customSwitches[i].state = 0;
|
||||
customSwitches[i].name[0] = 0;
|
||||
customSwitches[i].onColor.setColor(255, 255, 255);
|
||||
customSwitches[i].offColor.setColor(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,20 +394,18 @@ int ModelData::getChannelsMax(bool forceExtendedLimits) const
|
||||
return 100;
|
||||
}
|
||||
|
||||
bool ModelData::isFunctionSwitchPositionAvailable(int index) const
|
||||
bool ModelData::isFunctionSwitchPositionAvailable(int swIndex, int swPos, const GeneralSettings * const gs) const
|
||||
{
|
||||
if (index == 0)
|
||||
return true;
|
||||
|
||||
div_t qr = div(abs(index) - 1, 3);
|
||||
int fs = getFuncSwitchConfig(qr.quot);
|
||||
|
||||
if (qr.rem == 1) {
|
||||
if (swPos == 1)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return fs != Board::SWITCH_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
int fsindex = Boards::getCFSIndexForSwitch(swIndex);
|
||||
int fs = getFuncSwitchConfig(fsindex);
|
||||
|
||||
if (fs == Board::SWITCH_GLOBAL)
|
||||
return gs->switchConfig[swIndex].type != Board::SWITCH_NOT_AVAILABLE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModelData::isFunctionSwitchSourceAllowed(int index) const
|
||||
@@ -1747,30 +1750,32 @@ AbstractStaticItemModel * ModelData::trainerModeItemModel(const GeneralSettings
|
||||
return mdl;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchConfig(unsigned int index) const
|
||||
Board::SwitchType ModelData::getFuncSwitchConfig(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchConfig, index, 2);
|
||||
return customSwitches[index].type;
|
||||
else
|
||||
return FUNC_SWITCH_CONFIG_NONE;
|
||||
return Board::SWITCH_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
void ModelData::setFuncSwitchConfig(unsigned int index, unsigned int value)
|
||||
void ModelData::setFuncSwitchConfig(unsigned int index, Board::SwitchType value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchConfig, value, index, 2);
|
||||
customSwitches[index].type = value;
|
||||
}
|
||||
|
||||
// static
|
||||
QString ModelData::funcSwitchConfigToString(unsigned int value)
|
||||
{
|
||||
switch (value) {
|
||||
case FUNC_SWITCH_CONFIG_NONE:
|
||||
case Board::SWITCH_NOT_AVAILABLE:
|
||||
return tr("NONE");
|
||||
case FUNC_SWITCH_CONFIG_TOGGLE:
|
||||
case Board::SWITCH_TOGGLE:
|
||||
return tr("TOGGLE");
|
||||
case FUNC_SWITCH_CONFIG_2POS:
|
||||
case Board::SWITCH_2POS:
|
||||
return tr("2POS");
|
||||
case Board::SWITCH_GLOBAL:
|
||||
return tr("Global");
|
||||
default:
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
@@ -1781,7 +1786,7 @@ AbstractStaticItemModel * ModelData::funcSwitchConfigItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName(AIM_MODELDATA_FUNCSWITCHCONFIG);
|
||||
for (unsigned int i = FUNC_SWITCH_CONFIG_FIRST; i <= FUNC_SWITCH_CONFIG_LAST; i++) {
|
||||
for (unsigned int i = Board::SWITCH_NOT_AVAILABLE; i <= Board::SWITCH_GLOBAL; i++) {
|
||||
mdl->appendToItemList(funcSwitchConfigToString(i), i);
|
||||
}
|
||||
mdl->loadItemList();
|
||||
@@ -1809,7 +1814,7 @@ AbstractStaticItemModel * ModelData::funcSwitchGroupsModel()
|
||||
mdl->setName(AIM_MODELDATA_FUNCSWITCHGROUPS);
|
||||
|
||||
mdl->appendToItemList(tr("---"), 0);
|
||||
for (unsigned int i = 1; i <= 3; i += 1) {
|
||||
for (unsigned int i = 1; i <= Boards::getCapability(getCurrentBoard(), Board::FunctionSwitchGroups); i += 1) {
|
||||
mdl->appendToItemList(tr("Group ") + QString::number(i), i);
|
||||
}
|
||||
|
||||
@@ -1820,7 +1825,7 @@ AbstractStaticItemModel * ModelData::funcSwitchGroupsModel()
|
||||
unsigned int ModelData::getFuncSwitchGroup(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchGroup, index, 2);
|
||||
return customSwitches[index].group;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
@@ -1828,14 +1833,13 @@ unsigned int ModelData::getFuncSwitchGroup(unsigned int index) const
|
||||
void ModelData::setFuncSwitchGroup(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchGroup, value, index, 2);
|
||||
customSwitches[index].group = value;
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchAlwaysOnGroup(unsigned int group) const
|
||||
{
|
||||
if (group > 0 && group < 4) {
|
||||
unsigned int switchcnt = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches);
|
||||
return Helpers::getBitmappedValue(functionSwitchGroup, group, 1, 2 * switchcnt);
|
||||
if (group > 0 && group <= Boards::getCapability(getCurrentBoard(), Board::FunctionSwitchGroups)) {
|
||||
return cfsGroupOn[group];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
@@ -1851,16 +1855,15 @@ unsigned int ModelData::getFuncSwitchAlwaysOnGroupForSwitch(unsigned int index)
|
||||
|
||||
void ModelData::setFuncSwitchAlwaysOnGroup(unsigned int group, unsigned int value)
|
||||
{
|
||||
if (group > 0 && group < 4) {
|
||||
unsigned int switchcnt = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches);
|
||||
Helpers::setBitmappedValue(functionSwitchGroup, value, group, 1, 2 * switchcnt);
|
||||
if (group > 0 && group <= Boards::getCapability(getCurrentBoard(), Board::FunctionSwitchGroups)) {
|
||||
cfsGroupOn[group] = value;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int ModelData::getFuncSwitchStart(unsigned int index) const
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
return Helpers::getBitmappedValue(functionSwitchStartConfig, index, 2);
|
||||
return customSwitches[index].start;
|
||||
else
|
||||
return FUNC_SWITCH_START_OFF;
|
||||
}
|
||||
@@ -1868,7 +1871,7 @@ unsigned int ModelData::getFuncSwitchStart(unsigned int index) const
|
||||
void ModelData::setFuncSwitchStart(unsigned int index, unsigned int value)
|
||||
{
|
||||
if (index < CPN_MAX_SWITCHES_FUNCTION)
|
||||
Helpers::setBitmappedValue(functionSwitchStartConfig, value, index, 2);
|
||||
customSwitches[index].start = value;
|
||||
}
|
||||
|
||||
int ModelData::getFuncGroupSwitchCount(unsigned int group, int switchcnt) const
|
||||
@@ -1916,7 +1919,7 @@ void ModelData::setGroupSwitchState(uint8_t group, int switchcnt)
|
||||
if (getFuncSwitchAlwaysOnGroup(group)) {
|
||||
for (int j = 0; j < switchcnt; j += 1) {
|
||||
if (getFuncSwitchGroup(j) == group) {
|
||||
setFuncSwitchConfig(j, FUNC_SWITCH_CONFIG_2POS); // Toggle not valid
|
||||
setFuncSwitchConfig(j, Board::SWITCH_2POS); // Toggle not valid
|
||||
}
|
||||
}
|
||||
if (getFuncGroupSwitchStart(group, switchcnt) == (unsigned int)switchcnt + 1) {
|
||||
@@ -2026,3 +2029,16 @@ int ModelData::getInputLine(int index) const
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
const Board::SwitchType ModelData::getSwitchType(int sw, const GeneralSettings & gs) const
|
||||
{
|
||||
if (sw < 0 || sw >= Boards::getCapability(getCurrentBoard(), Board::Switches))
|
||||
return Board::SWITCH_NOT_AVAILABLE;
|
||||
|
||||
if (Boards::isSwitchFunc(sw)) {
|
||||
int fsIndex = Boards::getCFSIndexForSwitch(sw);
|
||||
if (customSwitches[fsIndex].type != Board::SWITCH_GLOBAL)
|
||||
return customSwitches[fsIndex].type;
|
||||
}
|
||||
return gs.switchConfig[sw].type;
|
||||
}
|
||||
|
||||
@@ -104,13 +104,19 @@ class USBJoystickChData {
|
||||
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(USBJoystickChData)); }
|
||||
};
|
||||
|
||||
class RGBLedColor {
|
||||
class customSwitch {
|
||||
public:
|
||||
RGBLedColor() { clear(); }
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(RGBLedColor)); }
|
||||
customSwitch() { clear(); }
|
||||
Board::SwitchType type;
|
||||
unsigned int group;
|
||||
unsigned int start;
|
||||
unsigned int state;
|
||||
char name[HARDWARE_NAME_LEN + 1];
|
||||
unsigned int onColorLuaOverride;
|
||||
unsigned int offColorLuaOverride;
|
||||
RGBLedColor onColor;
|
||||
RGBLedColor offColor;
|
||||
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(customSwitch)); }
|
||||
};
|
||||
|
||||
class ModelData {
|
||||
@@ -171,7 +177,6 @@ class ModelData {
|
||||
SwashRingData swashRingData;
|
||||
unsigned int thrTraceSrc;
|
||||
uint64_t switchWarningStates;
|
||||
unsigned int switchWarningEnable;
|
||||
unsigned int thrTrimSwitch;
|
||||
unsigned int potsWarningMode;
|
||||
bool potsWarnEnabled[CPN_MAX_INPUTS];
|
||||
@@ -220,30 +225,17 @@ class ModelData {
|
||||
unsigned int modelCustomScriptsDisabled;
|
||||
unsigned int modelTelemetryDisabled;
|
||||
|
||||
enum FunctionSwitchConfig {
|
||||
FUNC_SWITCH_CONFIG_NONE,
|
||||
FUNC_SWITCH_CONFIG_FIRST = FUNC_SWITCH_CONFIG_NONE,
|
||||
FUNC_SWITCH_CONFIG_TOGGLE,
|
||||
FUNC_SWITCH_CONFIG_2POS,
|
||||
FUNC_SWITCH_CONFIG_LAST = FUNC_SWITCH_CONFIG_2POS
|
||||
};
|
||||
|
||||
enum FunctionSwitchStart {
|
||||
FUNC_SWITCH_START_ON,
|
||||
FUNC_SWITCH_START_FIRST = FUNC_SWITCH_START_ON,
|
||||
FUNC_SWITCH_START_OFF,
|
||||
FUNC_SWITCH_START_FIRST = FUNC_SWITCH_START_OFF,
|
||||
FUNC_SWITCH_START_ON,
|
||||
FUNC_SWITCH_START_PREVIOUS,
|
||||
FUNC_SWITCH_START_LAST = FUNC_SWITCH_START_PREVIOUS
|
||||
};
|
||||
|
||||
// Function switches
|
||||
unsigned int functionSwitchConfig;
|
||||
unsigned int functionSwitchGroup;
|
||||
unsigned int functionSwitchStartConfig;
|
||||
unsigned int functionSwitchLogicalState;
|
||||
char functionSwitchNames[CPN_MAX_SWITCHES_FUNCTION][HARDWARE_NAME_LEN + 1];
|
||||
RGBLedColor functionSwitchLedONColor[CPN_MAX_SWITCHES_FUNCTION];
|
||||
RGBLedColor functionSwitchLedOFFColor[CPN_MAX_SWITCHES_FUNCTION];
|
||||
customSwitch customSwitches[CPN_MAX_SWITCHES_FUNCTION];
|
||||
unsigned int cfsGroupOn[4];
|
||||
|
||||
// Custom USB joytsick mapping
|
||||
unsigned int usbJoystickExtMode;
|
||||
@@ -287,9 +279,11 @@ class ModelData {
|
||||
int getChannelsMax(bool forceExtendedLimits=false) const;
|
||||
|
||||
bool isAvailable(const RawSwitch & swtch) const;
|
||||
bool isFunctionSwitchPositionAvailable(int index) const;
|
||||
bool isFunctionSwitchPositionAvailable(int swIndex, int swPos, const GeneralSettings * const gs) const;
|
||||
bool isFunctionSwitchSourceAllowed(int index) const;
|
||||
|
||||
const Board::SwitchType getSwitchType(int sw, const GeneralSettings & gs) const;
|
||||
|
||||
enum ReferenceUpdateAction {
|
||||
REF_UPD_ACT_CLEAR,
|
||||
REF_UPD_ACT_SHIFT,
|
||||
@@ -344,8 +338,8 @@ class ModelData {
|
||||
static QString trainerModeToString(const int value);
|
||||
bool isTrainerModeAvailable(const GeneralSettings & generalSettings, const Firmware * firmware, const int value);
|
||||
AbstractStaticItemModel * trainerModeItemModel(const GeneralSettings & generalSettings, const Firmware * firmware);
|
||||
unsigned int getFuncSwitchConfig(unsigned int index) const;
|
||||
void setFuncSwitchConfig(unsigned int index, unsigned int value);
|
||||
Board::SwitchType getFuncSwitchConfig(unsigned int index) const;
|
||||
void setFuncSwitchConfig(unsigned int index, Board::SwitchType value);
|
||||
static QString funcSwitchConfigToString(unsigned int value);
|
||||
static AbstractStaticItemModel * funcSwitchConfigItemModel();
|
||||
static AbstractStaticItemModel * funcSwitchGroupStartSwitchModel(int switchcnt);
|
||||
|
||||
@@ -203,7 +203,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
|
||||
if (model) {
|
||||
int fsindex = Boards::getSwitchTagNum(index - 1, board) - 1;
|
||||
if (fsindex >= 0 && fsindex < CPN_MAX_SWITCHES_FUNCTION)
|
||||
custName = QString(model->functionSwitchNames[fsindex]).trimmed();
|
||||
custName = QString(model->customSwitches[fsindex].name).trimmed();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -93,7 +93,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
|
||||
if (Boards::isSwitchFunc(qr.quot, board)) {
|
||||
if (modelData) {
|
||||
int fsindex = Boards::getSwitchTagNum(qr.quot, board) - 1;
|
||||
custName = QString(modelData->functionSwitchNames[fsindex]).trimmed();
|
||||
custName = QString(modelData->customSwitches[fsindex].name).trimmed();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -205,8 +205,7 @@ bool RawSwitch::isAvailable(const ModelData * const model, const GeneralSettings
|
||||
|
||||
if (model) {
|
||||
if (type == SWITCH_TYPE_SWITCH && b.isSwitchFunc(sw.quot, board)) {
|
||||
int fsindex = (((Boards::getSwitchTagNum(sw.quot, board) - 1) * 3) + sw.rem + 1) * ( index < 0 ? -1 : 1);
|
||||
return model->isFunctionSwitchPositionAvailable(fsindex);
|
||||
return model->isFunctionSwitchPositionAvailable(sw.quot, sw.rem, gs);
|
||||
}
|
||||
else
|
||||
return model->isAvailable(*this);
|
||||
|
||||
@@ -140,6 +140,9 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
|
||||
|
||||
count = Boards::getCapability(board, Board::Sticks);
|
||||
if (count > 0) {
|
||||
addLabel("");
|
||||
addLabel(tr("Name"));
|
||||
addParams();
|
||||
for (int i = 0; i < count; i++) {
|
||||
addStick(i);
|
||||
}
|
||||
@@ -158,22 +161,46 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
|
||||
|
||||
if (count > 0) {
|
||||
addSection(tr("Pots"));
|
||||
addLabel("");
|
||||
addLabel(tr("Name"));
|
||||
addLabel(tr("Type"));
|
||||
addLabel(tr("Invert"));
|
||||
addParams();
|
||||
for (int i = Boards::getCapability(board, Board::Sticks); i < count; i++) {
|
||||
if (Boards::isInputConfigurable(i, board))
|
||||
addFlex(i);
|
||||
}
|
||||
}
|
||||
|
||||
count = Boards::getCapability(board, Board::Switches);
|
||||
if (Boards::getCapability(board, Board::Switches)) {
|
||||
addSection(tr("Switches"));
|
||||
|
||||
if (count) {
|
||||
addLabel("");
|
||||
addLabel(tr("Name"));
|
||||
addLabel(tr("Type"));
|
||||
addParams();
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES; i++) {
|
||||
if (Boards::isSwitchConfigurable(i, board) && !generalSettings.isSwitchFunc(i) && !generalSettings.isSwitchFlex(i))
|
||||
addSwitch(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (Boards::getCapability(board, Board::FlexSwitches)) {
|
||||
// All values except -1 (None) are mutually exclusive
|
||||
exclFlexSwitchesGroup = new ExclusiveComboGroup(
|
||||
this, [=](const QVariant &value) { return value == -1; });
|
||||
|
||||
addSection(tr("Switches"));
|
||||
for (int i = 0; i < count && i < CPN_MAX_SWITCHES; i++) {
|
||||
if (Boards::isSwitchConfigurable(i, board))
|
||||
addSection(tr("Flex Switches"));
|
||||
|
||||
addLabel("");
|
||||
addLabel(tr("Name"));
|
||||
addLabel(tr("Source"));
|
||||
addLabel(tr("Type"));
|
||||
addParams();
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES; i++) {
|
||||
if (Boards::isSwitchConfigurable(i, board) && generalSettings.isSwitchFlex(i))
|
||||
addSwitch(i);
|
||||
}
|
||||
|
||||
@@ -184,6 +211,27 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
|
||||
}
|
||||
}
|
||||
|
||||
if (Boards::getCapability(board, Board::FunctionSwitches)) {
|
||||
addSection(tr("Customisable Switches"));
|
||||
|
||||
addLabel("");
|
||||
addLabel(tr("Name"));
|
||||
addLabel(tr("Type"));
|
||||
addLabel(tr("Start"));
|
||||
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
|
||||
addLabel(tr("Off color"));
|
||||
addLabel(tr("Lua override"));
|
||||
addLabel(tr("On color"));
|
||||
addLabel(tr("Lua override"));
|
||||
}
|
||||
addParams();
|
||||
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES; i++) {
|
||||
if (Boards::isSwitchConfigurable(i, board) && generalSettings.isSwitchFunc(i))
|
||||
addSwitch(i);
|
||||
}
|
||||
}
|
||||
|
||||
addLine();
|
||||
|
||||
if (Boards::getCapability(board, Board::HasRTC)) {
|
||||
@@ -502,7 +550,9 @@ void HardwarePanel::addSwitch(int index)
|
||||
GeneralSettings::SwitchConfig &config = generalSettings.switchConfig[index];
|
||||
Board::SwitchInfo info = Boards::getSwitchInfo(index);
|
||||
|
||||
addLabel(Boards::getSwitchName(index));
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(Boards::getSwitchName(index));
|
||||
params->append(label);
|
||||
|
||||
AutoLineEdit *name = new AutoLineEdit(this);
|
||||
name->setValidator(new NameValidator(board, this));
|
||||
@@ -550,6 +600,76 @@ void HardwarePanel::addSwitch(int index)
|
||||
});
|
||||
}
|
||||
|
||||
if (generalSettings.isSwitchFunc(index)) {
|
||||
AutoComboBox *start = new AutoComboBox(this);
|
||||
start->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
AbstractStaticItemModel *fsStart = ModelData::funcSwitchStartItemModel();
|
||||
start->setModel(fsStart);
|
||||
int & swstart = (int &)config.start;
|
||||
start->setField(swstart, this);
|
||||
start->setEnabled(config.type == Board::SWITCH_2POS);
|
||||
params->append(start);
|
||||
|
||||
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
|
||||
start->setEnabled(val == Board::SWITCH_2POS);
|
||||
});
|
||||
|
||||
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
|
||||
const QString qss = QString("border-style: outset; border-width: 2px; border-radius: 5px; border-color: darkgrey; padding: 2px; background-color: %1;");
|
||||
QPushButton * btnOffColor = new QPushButton();
|
||||
QColor off = generalSettings.switchConfig[index].offColor.getQColor();
|
||||
btnOffColor->setStyleSheet(QString(qss).arg(off.name()));
|
||||
connect(btnOffColor, &QPushButton::clicked, [=]() {
|
||||
QColorDialog *dlg = new QColorDialog();
|
||||
QColor color = dlg->getColor(generalSettings.switchConfig[index].offColor.getQColor());
|
||||
if (color.isValid()) {
|
||||
generalSettings.switchConfig[index].offColor.setColor(color.red(), color.green(), color.blue());
|
||||
btnOffColor->setStyleSheet(QString(qss).arg(color.name()));
|
||||
emit modified();
|
||||
}
|
||||
});
|
||||
params->append(btnOffColor);
|
||||
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
|
||||
btnOffColor->setEnabled(val != Board::SWITCH_NOT_AVAILABLE); });
|
||||
|
||||
QCheckBox * cbOffLuaOverride = new QCheckBox(this);
|
||||
cbOffLuaOverride->setChecked(generalSettings.switchConfig[index].offColorLuaOverride);
|
||||
connect(cbOffLuaOverride, &QCheckBox::toggled, [=](int value) {
|
||||
generalSettings.switchConfig[index].offColorLuaOverride = value;
|
||||
emit modified();
|
||||
});
|
||||
params->append(cbOffLuaOverride);
|
||||
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
|
||||
cbOffLuaOverride->setEnabled(val != Board::SWITCH_NOT_AVAILABLE); });
|
||||
|
||||
QPushButton * btnOnColor = new QPushButton(tr(""));
|
||||
QColor on = generalSettings.switchConfig[index].onColor.getQColor();
|
||||
btnOnColor->setStyleSheet(QString(qss).arg(on.name()));
|
||||
connect(btnOnColor, &QPushButton::clicked, [=]() {
|
||||
QColorDialog *dlg = new QColorDialog();
|
||||
QColor color = dlg->getColor(generalSettings.switchConfig[index].onColor.getQColor());
|
||||
if (color.isValid()) {
|
||||
generalSettings.switchConfig[index].onColor.setColor(color.red(), color.green(), color.blue());
|
||||
btnOnColor->setStyleSheet(QString(qss).arg(color.name()));
|
||||
emit modified();
|
||||
}
|
||||
});
|
||||
params->append(btnOnColor);
|
||||
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
|
||||
btnOnColor->setEnabled(val != Board::SWITCH_NOT_AVAILABLE); });
|
||||
|
||||
QCheckBox * cbOnLuaOverride = new QCheckBox(this);
|
||||
cbOnLuaOverride->setChecked(generalSettings.switchConfig[index].onColorLuaOverride);
|
||||
connect(cbOnLuaOverride, &QCheckBox::toggled, [=](int value) {
|
||||
generalSettings.switchConfig[index].onColorLuaOverride = value;
|
||||
emit modified();
|
||||
});
|
||||
params->append(cbOnLuaOverride);
|
||||
connect(type, &AutoComboBox::currentDataChanged, [=] (int val) {
|
||||
cbOnLuaOverride->setEnabled(val != Board::SWITCH_NOT_AVAILABLE); });
|
||||
}
|
||||
}
|
||||
|
||||
addParams();
|
||||
}
|
||||
|
||||
@@ -557,7 +677,7 @@ void HardwarePanel::addLabel(QString text)
|
||||
{
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(text);
|
||||
grid->addWidget(label, row, 0);
|
||||
params->append(label);
|
||||
}
|
||||
|
||||
void HardwarePanel::addLine()
|
||||
@@ -572,22 +692,18 @@ void HardwarePanel::addLine()
|
||||
|
||||
void HardwarePanel::addParams()
|
||||
{
|
||||
int col = 0;
|
||||
QGridLayout *subgrid = new QGridLayout();
|
||||
|
||||
for (int i = 0; i < params->size(); i++) {
|
||||
subgrid->addWidget(params->at(i), 0, col++);
|
||||
grid->addWidget(params->at(i), row, i);
|
||||
}
|
||||
|
||||
addHSpring(subgrid, col, 0);
|
||||
grid->addLayout(subgrid, row++, 1);
|
||||
row += 1;
|
||||
params->clear();
|
||||
}
|
||||
|
||||
void HardwarePanel::addSection(QString text)
|
||||
{
|
||||
addLabel(QString("<b>%1</b>").arg(text));
|
||||
row++;
|
||||
addParams();
|
||||
}
|
||||
|
||||
void HardwarePanel::updateSerialPortUSBVCP()
|
||||
|
||||
@@ -219,12 +219,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
|
||||
// Startup switches warnings
|
||||
for (int i = 0; i < Boards::getBoardCapability(board, Board::Switches); i++) {
|
||||
GeneralSettings::SwitchConfig &swcfg = generalSettings.switchConfig[i];
|
||||
|
||||
if (Boards::isSwitchFunc(i, board) || !generalSettings.isSwitchAvailable(i) || swcfg.type == Board::SWITCH_TOGGLE) {
|
||||
model.switchWarningEnable |= (1 << i);
|
||||
continue;
|
||||
}
|
||||
Board::SwitchType swType = model.getSwitchType(i, generalSettings);
|
||||
|
||||
RawSource src(RawSourceType::SOURCE_TYPE_SWITCH, i + 1);
|
||||
QLabel * label = new QLabel(this);
|
||||
@@ -242,7 +237,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
slider->setPageStep(1);
|
||||
slider->setTickInterval(1);
|
||||
label->setText(src.toString(&model, &generalSettings));
|
||||
slider->setMaximum(swcfg.type == Board::SWITCH_3POS ? 2 : 1);
|
||||
slider->setMaximum(swType == Board::SWITCH_3POS ? 2 : 1);
|
||||
cb->setProperty("index", i);
|
||||
ui->switchesStartupLayout->addWidget(label, 0, i + 1);
|
||||
ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter);
|
||||
@@ -252,6 +247,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
ui->switchesStartupLayout->setAlignment(cb, Qt::AlignCenter);
|
||||
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(startupSwitchEdited(int)));
|
||||
connect(cb, SIGNAL(toggled(bool)), this, SLOT(startupSwitchToggled(bool)));
|
||||
startupSwitchesLabels << label;
|
||||
startupSwitchesSliders << slider;
|
||||
startupSwitchesCheckboxes << cb;
|
||||
QWidget::setTabOrder(prevFocus, slider);
|
||||
@@ -338,6 +334,12 @@ SetupPanel::~SetupPanel()
|
||||
delete panelItemModels;
|
||||
}
|
||||
|
||||
bool SetupPanel::canSwitchHaveWarning(int sw)
|
||||
{
|
||||
Board::SwitchType type = model->getSwitchType(sw, generalSettings);
|
||||
return (type == Board::SWITCH_2POS) || (type == Board::SWITCH_3POS);
|
||||
}
|
||||
|
||||
void SetupPanel::on_extendedLimits_toggled(bool checked)
|
||||
{
|
||||
model->extendedLimits = checked;
|
||||
@@ -510,23 +512,20 @@ void SetupPanel::updateStartupSwitches()
|
||||
uint64_t value;
|
||||
|
||||
for (int i = 0; i < startupSwitchesSliders.size(); i++) {
|
||||
QLabel * label = startupSwitchesLabels[i];
|
||||
QSlider * slider = startupSwitchesSliders[i];
|
||||
QCheckBox * cb = startupSwitchesCheckboxes[i];
|
||||
int index = slider->property("index").toInt();
|
||||
bool enabled = !(model->switchWarningEnable & (1 << index));
|
||||
if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
|
||||
value = (switchStates >> (2 * index)) & 0x03;
|
||||
if (generalSettings.switchConfig[index].type != Board::SWITCH_3POS && value == 2) {
|
||||
value = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = (i == 0 ? switchStates & 0x3 : switchStates & 0x1);
|
||||
switchStates >>= (i == 0 ? 2 : 1);
|
||||
}
|
||||
slider->setValue(value);
|
||||
value = (switchStates >> (2 * index)) & 0x03;
|
||||
bool enabled = value != 0;
|
||||
if (model->getSwitchType(i, generalSettings) == Board::SWITCH_2POS && value == 3) value = 2;
|
||||
slider->setValue((value > 0) ? value - 1 : 0);
|
||||
slider->setEnabled(enabled);
|
||||
cb->setChecked(enabled);
|
||||
bool vis = canSwitchHaveWarning(i);
|
||||
label->setVisible(vis);
|
||||
slider->setVisible(vis);
|
||||
cb->setVisible(vis);
|
||||
}
|
||||
|
||||
lock = false;
|
||||
@@ -539,31 +538,14 @@ void SetupPanel::startupSwitchEdited(int value)
|
||||
uint64_t mask;
|
||||
int index = sender()->property("index").toInt();
|
||||
|
||||
if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
|
||||
shift = index * 2;
|
||||
mask = 0x03ull << shift;
|
||||
}
|
||||
else {
|
||||
if (index == 0) {
|
||||
mask = 0x03;
|
||||
}
|
||||
else {
|
||||
shift = index + 1;
|
||||
mask = 0x01ull << shift;
|
||||
}
|
||||
}
|
||||
shift = index * 2;
|
||||
mask = 0x03ull << shift;
|
||||
|
||||
model->switchWarningStates &= ~mask;
|
||||
|
||||
if (IS_HORUS_OR_TARANIS(firmware->getBoard()) && generalSettings.switchConfig[index].type != Board::SWITCH_3POS) {
|
||||
if (value == 1) {
|
||||
value = 2;
|
||||
}
|
||||
}
|
||||
if (model->getSwitchType(index, generalSettings) == Board::SWITCH_2POS && value == 1) value = 2;
|
||||
|
||||
if (value) {
|
||||
model->switchWarningStates |= ((uint64_t)value << shift);
|
||||
}
|
||||
model->switchWarningStates |= ((uint64_t)(value + 1) << shift);
|
||||
|
||||
updateStartupSwitches();
|
||||
emit modified();
|
||||
@@ -576,9 +558,9 @@ void SetupPanel::startupSwitchToggled(bool checked)
|
||||
int index = sender()->property("index").toInt();
|
||||
|
||||
if (checked)
|
||||
model->switchWarningEnable &= ~(1 << index);
|
||||
model->switchWarningStates |= (1 << (index * 2));
|
||||
else
|
||||
model->switchWarningEnable |= (1 << index);
|
||||
model->switchWarningStates &= ~(3 << (index * 2));
|
||||
|
||||
updateStartupSwitches();
|
||||
emit modified();
|
||||
@@ -866,5 +848,6 @@ void SetupPanel::onModuleUpdateItemModels()
|
||||
|
||||
void SetupPanel::onFunctionSwitchesUpdateItemModels()
|
||||
{
|
||||
updateStartupSwitches();
|
||||
sharedItemModels->update(AbstractItemModel::IMUE_FunctionSwitches);
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ class SetupPanel : public ModelPanel
|
||||
|
||||
private:
|
||||
Ui::Setup *ui;
|
||||
QVector<QLabel *> startupSwitchesLabels;
|
||||
QVector<QSlider *> startupSwitchesSliders;
|
||||
QVector<QCheckBox *> startupSwitchesCheckboxes;
|
||||
QVector<QCheckBox *> potWarningCheckboxes;
|
||||
@@ -97,6 +98,7 @@ class SetupPanel : public ModelPanel
|
||||
TimerPanel * timers[CPN_MAX_TIMERS];
|
||||
FunctionSwitchesPanel * funcswitches;
|
||||
|
||||
bool canSwitchHaveWarning(int sw);
|
||||
void updateStartupSwitches();
|
||||
void updatePotWarnings();
|
||||
void updateBeepCenter();
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "ui_setup_function_switches.h"
|
||||
#include "namevalidator.h"
|
||||
#include "autolineedit.h"
|
||||
#include <QColorDialog>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
@@ -42,13 +43,16 @@ bool FilteredGroupSwitchesModel::filterAcceptsRow(int sourceRow, const QModelInd
|
||||
bool FilteredSwitchGroupsModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
if (sourceRow == 0) return true;
|
||||
if (m_model->getFuncSwitchConfig(m_switch) == ModelData::FUNC_SWITCH_CONFIG_NONE) return false;
|
||||
if (m_model->getFuncSwitchConfig(m_switch) == Board::SWITCH_NOT_AVAILABLE) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FilteredSwitchConfigsModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
if (sourceRow == ModelData::FUNC_SWITCH_CONFIG_NONE || sourceRow == ModelData::FUNC_SWITCH_CONFIG_2POS) return true;
|
||||
if (sourceRow == Board::SWITCH_3POS)
|
||||
return false;
|
||||
if (sourceRow == Board::SWITCH_NOT_AVAILABLE || sourceRow == Board::SWITCH_2POS || sourceRow == Board::SWITCH_GLOBAL)
|
||||
return true;
|
||||
return !m_model->getFuncSwitchAlwaysOnGroupForSwitch(m_switch);
|
||||
}
|
||||
|
||||
@@ -70,51 +74,122 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
||||
|
||||
fsGroupStart = ModelData::funcSwitchGroupStartSwitchModel(switchcnt);
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
QLabel * lblSwitchId = new QLabel(this);
|
||||
lblSwitchId->setText(tr("SW%1").arg(i + 1));
|
||||
|
||||
AutoLineEdit * aleName = new AutoLineEdit(this);
|
||||
aleName->setProperty("index", i);
|
||||
aleName->setValidator(new NameValidator(board, this));
|
||||
aleName->setField((char *)model.functionSwitchNames[i], 3);
|
||||
|
||||
QComboBox * cboConfig = new QComboBox(this);
|
||||
cboConfig->setProperty("index", i);
|
||||
auto configFilter = new FilteredSwitchConfigsModel(fsConfig, i, &model);
|
||||
cboConfig->setModel(configFilter);
|
||||
filterSwitchConfigs << configFilter;
|
||||
|
||||
QComboBox * cboStartPosn = new QComboBox(this);
|
||||
cboStartPosn->setProperty("index", i);
|
||||
cboStartPosn->setModel(fsStart);
|
||||
|
||||
QComboBox * cboGroup = new QComboBox(this);
|
||||
cboGroup->setProperty("index", i);
|
||||
auto groupFilter = new FilteredSwitchGroupsModel(fsGroups, i, &model);
|
||||
cboGroup->setModel(groupFilter);
|
||||
filterSwitchGroups << groupFilter;
|
||||
|
||||
int row = 0;
|
||||
int coloffset = 1;
|
||||
ui->gridSwitches->addWidget(lblSwitchId, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(aleName, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboConfig, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboStartPosn, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboGroup, row++, i + coloffset);
|
||||
|
||||
connect(aleName, &AutoLineEdit::currentDataChanged, this, &FunctionSwitchesPanel::on_nameEditingFinished);
|
||||
connect(cboConfig, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_configCurrentIndexChanged);
|
||||
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_startPosnCurrentIndexChanged);
|
||||
connect(cboGroup, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||
|
||||
aleNames << aleName;
|
||||
cboConfigs << cboConfig;
|
||||
cboStartupPosns << cboStartPosn;
|
||||
cboGroups << cboGroup;
|
||||
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
|
||||
QLabel * lblOffColor = new QLabel(this);
|
||||
lblOffColor->setText(tr("Off color"));
|
||||
ui->gridSwitches->addWidget(lblOffColor, 5, 0);
|
||||
QLabel * lblOffLua = new QLabel(this);
|
||||
lblOffLua->setText(tr(" Allow Lua override"));
|
||||
ui->gridSwitches->addWidget(lblOffLua, 6, 0);
|
||||
QLabel * lblOnColor = new QLabel(this);
|
||||
lblOnColor->setText(tr("On color"));
|
||||
ui->gridSwitches->addWidget(lblOnColor, 7, 0);
|
||||
QLabel * lblOnLua = new QLabel(this);
|
||||
lblOnLua->setText(tr(" Allow Lua override"));
|
||||
ui->gridSwitches->addWidget(lblOnLua, 8, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i += 1) {
|
||||
for (int sw = 0, col = 0; sw < Boards::getCapability(board, Board::Switches); sw++) {
|
||||
int i = Boards::getCFSIndexForSwitch(sw);
|
||||
if (i >= 0) {
|
||||
QLabel * lblSwitchId = new QLabel(this);
|
||||
lblSwitchId->setText(Boards::getSwitchName(sw));
|
||||
|
||||
AutoLineEdit * aleName = new AutoLineEdit(this);
|
||||
aleName->setProperty("index", i);
|
||||
aleName->setValidator(new NameValidator(board, this));
|
||||
aleName->setField((char *)model.customSwitches[i].name, 3);
|
||||
|
||||
QComboBox * cboConfig = new QComboBox(this);
|
||||
cboConfig->setProperty("index", i);
|
||||
auto configFilter = new FilteredSwitchConfigsModel(fsConfig, i, &model);
|
||||
cboConfig->setModel(configFilter);
|
||||
filterSwitchConfigs << configFilter;
|
||||
|
||||
QComboBox * cboStartPosn = new QComboBox(this);
|
||||
cboStartPosn->setProperty("index", i);
|
||||
cboStartPosn->setModel(fsStart);
|
||||
|
||||
QComboBox * cboGroup = new QComboBox(this);
|
||||
cboGroup->setProperty("index", i);
|
||||
auto groupFilter = new FilteredSwitchGroupsModel(fsGroups, i, &model);
|
||||
cboGroup->setModel(groupFilter);
|
||||
filterSwitchGroups << groupFilter;
|
||||
|
||||
int row = 0;
|
||||
int coloffset = 1;
|
||||
ui->gridSwitches->addWidget(lblSwitchId, row++, col + coloffset);
|
||||
ui->gridSwitches->addWidget(aleName, row++, col + coloffset);
|
||||
ui->gridSwitches->addWidget(cboConfig, row++, col + coloffset);
|
||||
ui->gridSwitches->addWidget(cboStartPosn, row++, col + coloffset);
|
||||
ui->gridSwitches->addWidget(cboGroup, row++, col + coloffset);
|
||||
|
||||
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
|
||||
const QString qss = QString("border-style: outset; border-width: 2px; border-radius: 5px; border-color: darkgrey; padding: 2px; background-color: %1;");
|
||||
QPushButton * btnOffColor = new QPushButton(tr(""));
|
||||
QColor off = this->model->customSwitches[i].offColor.getQColor();
|
||||
btnOffColor->setStyleSheet(QString(qss).arg(off.name()));
|
||||
connect(btnOffColor, &QPushButton::clicked, [=]() {
|
||||
QColorDialog *dlg = new QColorDialog();
|
||||
QColor color = dlg->getColor(this->model->customSwitches[i].offColor.getQColor());
|
||||
if (color.isValid()) {
|
||||
this->model->customSwitches[i].offColor.setColor(color.red(), color.green(), color.blue());
|
||||
btnOffColor->setStyleSheet(QString(qss).arg(color.name()));
|
||||
emit modified();
|
||||
}
|
||||
});
|
||||
ui->gridSwitches->addWidget(btnOffColor, row++, col + coloffset);
|
||||
btnOffColors << btnOffColor;
|
||||
|
||||
QCheckBox * cbOffLuaOverride = new QCheckBox(this);
|
||||
cbOffLuaOverride->setChecked(this->model->customSwitches[i].offColorLuaOverride);
|
||||
connect(cbOffLuaOverride, &QCheckBox::toggled, [=](int value) {
|
||||
this->model->customSwitches[i].offColorLuaOverride = value;
|
||||
emit modified();
|
||||
});
|
||||
ui->gridSwitches->addWidget(cbOffLuaOverride, row++, col + coloffset);
|
||||
cbOffLuaOverrides << cbOffLuaOverride;
|
||||
|
||||
QPushButton * btnOnColor = new QPushButton(tr(""));
|
||||
QColor on = this->model->customSwitches[i].onColor.getQColor();
|
||||
btnOnColor->setStyleSheet(QString(qss).arg(on.name()));
|
||||
connect(btnOnColor, &QPushButton::clicked, [=]() {
|
||||
QColorDialog *dlg = new QColorDialog();
|
||||
QColor color = dlg->getColor(this->model->customSwitches[i].onColor.getQColor());
|
||||
if (color.isValid()) {
|
||||
this->model->customSwitches[i].onColor.setColor(color.red(), color.green(), color.blue());
|
||||
btnOnColor->setStyleSheet(QString(qss).arg(color.name()));
|
||||
emit modified();
|
||||
}
|
||||
});
|
||||
ui->gridSwitches->addWidget(btnOnColor, row++, col + coloffset);
|
||||
btnOnColors << btnOnColor;
|
||||
|
||||
QCheckBox * cbOnLuaOverride = new QCheckBox(this);
|
||||
cbOnLuaOverride->setChecked(this->model->customSwitches[i].onColorLuaOverride);
|
||||
connect(cbOnLuaOverride, &QCheckBox::toggled, [=](int value) {
|
||||
this->model->customSwitches[i].onColorLuaOverride = value;
|
||||
emit modified();
|
||||
});
|
||||
ui->gridSwitches->addWidget(cbOnLuaOverride, row++, col + coloffset);
|
||||
cbOnLuaOverrides << cbOnLuaOverride;
|
||||
}
|
||||
|
||||
connect(aleName, &AutoLineEdit::currentDataChanged, this, &FunctionSwitchesPanel::on_nameEditingFinished);
|
||||
connect(cboConfig, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_configCurrentIndexChanged);
|
||||
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_startPosnCurrentIndexChanged);
|
||||
connect(cboGroup, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||
|
||||
aleNames << aleName;
|
||||
cboConfigs << cboConfig;
|
||||
cboStartupPosns << cboStartPosn;
|
||||
cboGroups << cboGroup;
|
||||
|
||||
col += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::FunctionSwitchGroups); i += 1) {
|
||||
QLabel * lblGroupId = new QLabel(this);
|
||||
lblGroupId->setText(tr("Group %1").arg(i + 1));
|
||||
|
||||
@@ -154,22 +229,37 @@ void FunctionSwitchesPanel::update()
|
||||
{
|
||||
lock = true;
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
filterSwitchConfigs[i]->invalidate();
|
||||
filterSwitchGroups[i]->invalidate();
|
||||
Board::Type board = firmware->getBoard();
|
||||
|
||||
aleNames[i]->update();
|
||||
cboConfigs[i]->setCurrentIndex(filterSwitchConfigs[i]->mapFromSource(fsConfig->index(model->getFuncSwitchConfig(i), 0)).row());
|
||||
cboStartupPosns[i]->setCurrentIndex(model->getFuncSwitchStart(i));
|
||||
unsigned int grp = model->getFuncSwitchGroup(i);
|
||||
cboGroups[i]->setCurrentIndex(grp);
|
||||
for (int sw = 0, col = 0; sw < Boards::getCapability(firmware->getBoard(), Board::Switches); sw++) {
|
||||
int i = Boards::getCFSIndexForSwitch(sw);
|
||||
if (i >= 0) {
|
||||
filterSwitchConfigs[col]->invalidate();
|
||||
filterSwitchGroups[col]->invalidate();
|
||||
|
||||
cboStartupPosns[i]->setEnabled(cboConfigs[i]->currentIndex() >= ModelData::FUNC_SWITCH_CONFIG_2POS && (grp == 0));
|
||||
unsigned int cfg = model->getFuncSwitchConfig(i);
|
||||
unsigned int grp = model->getFuncSwitchGroup(i);
|
||||
|
||||
cboGroups[i]->setEnabled(cboConfigs[i]->currentIndex() >= ModelData::FUNC_SWITCH_CONFIG_TOGGLE);
|
||||
aleNames[col]->update();
|
||||
cboConfigs[col]->setCurrentIndex(filterSwitchConfigs[col]->mapFromSource(fsConfig->index(cfg, 0)).row());
|
||||
cboStartupPosns[col]->setCurrentIndex(model->getFuncSwitchStart(i));
|
||||
cboGroups[col]->setCurrentIndex(grp);
|
||||
|
||||
cboStartupPosns[col]->setEnabled(cfg == Board::SWITCH_2POS && (grp == 0));
|
||||
cboGroups[col]->setEnabled(cfg >= Board::SWITCH_TOGGLE && cfg < Board::SWITCH_GLOBAL);
|
||||
|
||||
if (Boards::getCapability(board, Board::FunctionSwitchColors)) {
|
||||
btnOffColors[col]->setEnabled(cfg != Board::SWITCH_NOT_AVAILABLE && cfg != Board::SWITCH_GLOBAL);
|
||||
cbOffLuaOverrides[col]->setEnabled(cfg != Board::SWITCH_NOT_AVAILABLE && cfg != Board::SWITCH_GLOBAL);
|
||||
btnOnColors[col]->setEnabled(cfg != Board::SWITCH_NOT_AVAILABLE && cfg != Board::SWITCH_GLOBAL);
|
||||
cbOnLuaOverrides[col]->setEnabled(cfg != Board::SWITCH_NOT_AVAILABLE && cfg != Board::SWITCH_GLOBAL);
|
||||
}
|
||||
|
||||
col += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i += 1) {
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::FunctionSwitchGroups); i += 1) {
|
||||
filterGroupSwitches[i]->invalidate();
|
||||
|
||||
model->setGroupSwitchState(i + 1, switchcnt);
|
||||
@@ -200,10 +290,10 @@ void FunctionSwitchesPanel::on_configCurrentIndexChanged(int index)
|
||||
unsigned int sw = sender()->property("index").toInt(&ok);
|
||||
unsigned int config = filterSwitchConfigs[sw]->mapToSource(filterSwitchConfigs[sw]->index(index, 0)).row();
|
||||
if (ok && model->getFuncSwitchConfig(sw) != config) {
|
||||
model->setFuncSwitchConfig(sw, config);
|
||||
if (config != ModelData::FUNC_SWITCH_CONFIG_2POS) {
|
||||
model->setFuncSwitchConfig(sw, (Board::SwitchType)config);
|
||||
if (config != Board::SWITCH_2POS && config != Board::SWITCH_GLOBAL) {
|
||||
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||
if ((config == ModelData::FUNC_SWITCH_CONFIG_NONE) || model->getFuncSwitchAlwaysOnGroupForSwitch(sw))
|
||||
if ((config == Board::SWITCH_NOT_AVAILABLE) || model->getFuncSwitchAlwaysOnGroupForSwitch(sw))
|
||||
model->setFuncSwitchGroup(sw, 0);
|
||||
}
|
||||
update();
|
||||
@@ -270,8 +360,8 @@ void FunctionSwitchesPanel::on_groupChanged(int value)
|
||||
if (ok && model->getFuncSwitchGroup(sw) != grp) {
|
||||
unsigned oldGrp = model->getFuncSwitchGroup(sw);
|
||||
if (model->getFuncSwitchAlwaysOnGroup(grp)) {
|
||||
if (model->getFuncSwitchConfig(sw) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE)
|
||||
model->setFuncSwitchConfig(sw, ModelData::FUNC_SWITCH_CONFIG_2POS);
|
||||
if (model->getFuncSwitchConfig(sw) == Board::SWITCH_TOGGLE)
|
||||
model->setFuncSwitchConfig(sw, Board::SWITCH_2POS);
|
||||
}
|
||||
if ((grp == 0) || (model->getFuncGroupSwitchStart(grp, switchcnt) == 0))
|
||||
model->setFuncSwitchStart(sw, ModelData::FUNC_SWITCH_START_PREVIOUS);
|
||||
@@ -304,8 +394,8 @@ void FunctionSwitchesPanel::on_alwaysOnGroupChanged(int value)
|
||||
model->setFuncSwitchAlwaysOnGroup(grp, (unsigned int)value);
|
||||
if (value) {
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
if (((int)model->getFuncSwitchGroup(i) == grp) && (model->getFuncSwitchConfig(i) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE))
|
||||
model->setFuncSwitchConfig(i, ModelData::FUNC_SWITCH_CONFIG_2POS);
|
||||
if (((int)model->getFuncSwitchGroup(i) == grp) && (model->getFuncSwitchConfig(i) == Board::SWITCH_TOGGLE))
|
||||
model->setFuncSwitchConfig(i, Board::SWITCH_2POS);
|
||||
}
|
||||
if ((int)model->getFuncGroupSwitchStart(grp, switchcnt) == switchcnt + 1) {
|
||||
for (int i = 0; i < switchcnt; i += 1) {
|
||||
|
||||
@@ -157,6 +157,10 @@ class FunctionSwitchesPanel : public ModelPanel
|
||||
QVector<QComboBox *> cboGroups;
|
||||
QVector<QCheckBox *> cbAlwaysOnGroups;
|
||||
QVector<QComboBox *> cboGroupStartupPosns;
|
||||
QVector<QPushButton *> btnOffColors;
|
||||
QVector<QCheckBox *> cbOffLuaOverrides;
|
||||
QVector<QPushButton *> btnOnColors;
|
||||
QVector<QCheckBox *> cbOnLuaOverrides;
|
||||
QVector<FilteredGroupSwitchesModel *> filterGroupSwitches;
|
||||
QVector<FilteredSwitchGroupsModel *> filterSwitchGroups;
|
||||
QVector<FilteredSwitchConfigsModel *> filterSwitchConfigs;
|
||||
|
||||
@@ -765,20 +765,13 @@ QString ModelPrinter::printSwitchWarnings()
|
||||
uint64_t value;
|
||||
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::Switches); i++) {
|
||||
Board::SwitchInfo switchInfo = Boards::getSwitchInfo(i);
|
||||
if (switchInfo.type == Board::SWITCH_NOT_AVAILABLE || switchInfo.type == Board::SWITCH_TOGGLE) {
|
||||
Board::SwitchType type = model.getSwitchType(i, generalSettings);
|
||||
if (type != Board::SWITCH_2POS && type != Board::SWITCH_3POS) {
|
||||
continue;
|
||||
}
|
||||
if (!(model.switchWarningEnable & (1 << i))) {
|
||||
if (IS_HORUS_OR_TARANIS(board)) {
|
||||
value = (switchStates >> (2 * i)) & 0x03;
|
||||
}
|
||||
else {
|
||||
value = (i == 0 ? switchStates & 0x3 : switchStates & 0x1);
|
||||
switchStates >>= (i == 0 ? 2 : 1);
|
||||
}
|
||||
str += RawSwitch(SWITCH_TYPE_SWITCH, 1 + i * 3 + value).toString(board, &generalSettings, &model);
|
||||
}
|
||||
value = (switchStates >> (2 * i)) & 0x03;
|
||||
if (value > 0)
|
||||
str += RawSwitch(SWITCH_TYPE_SWITCH, i * 3 + value).toString(board, &generalSettings, &model);
|
||||
}
|
||||
return (str.isEmpty() ? tr("None") : str.join(" ")) ;
|
||||
}
|
||||
|
||||
@@ -975,7 +975,7 @@ QString MultiModelPrinter::printFunctionSwitches()
|
||||
columns.appendRowStart(tr("Name"), 20);
|
||||
|
||||
for (int i = 0; i < numFS; i++) {
|
||||
COMPARECELLWIDTH(model->functionSwitchNames[i], colwidth);
|
||||
COMPARECELLWIDTH(model->customSwitches[i].name, colwidth);
|
||||
}
|
||||
|
||||
columns.appendRowEnd();
|
||||
|
||||
@@ -193,6 +193,7 @@ class SimulatorInterface : public QObject
|
||||
void auxSerialStart(const quint8 port_num);
|
||||
void auxSerialStop(const quint8 port_num);
|
||||
void txBatteryVoltageChanged(const int voltage);
|
||||
void fsColorChange(quint8 index, qint32 color);
|
||||
};
|
||||
|
||||
class SimulatorFactory {
|
||||
|
||||
@@ -519,6 +519,9 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
case RadioWidget::RADIO_WIDGET_KNOB :
|
||||
ui->radioWidgetsHTLayout->removeWidget(rw);
|
||||
break;
|
||||
case RadioWidget::RADIO_WIDGET_FUNC_SWITCH:
|
||||
ui->radioWidgetsCSLayout->removeWidget(rw);
|
||||
break;
|
||||
case RadioWidget::RADIO_WIDGET_FADER :
|
||||
case RadioWidget::RADIO_WIDGET_TRIM :
|
||||
ui->VCGridLayout->removeWidget(rw);
|
||||
@@ -534,22 +537,36 @@ void SimulatorWidget::setupRadioWidgets()
|
||||
|
||||
// Now set up new widgets.
|
||||
|
||||
// switches
|
||||
Board::SwitchType swcfg;
|
||||
for (i = 0; i < ttlSwitches; ++i) {
|
||||
if (!radioSettings.isSwitchAvailable(i) || Boards::isSwitchFunc(i))
|
||||
continue;
|
||||
|
||||
swcfg = Board::SwitchType(radioSettings.switchConfig[i].type);
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_SWITCH, i + 1).toString(nullptr, &radioSettings, Board::BOARD_UNKNOWN, false);
|
||||
RadioSwitchWidget * sw = new RadioSwitchWidget(swcfg, wname, -1, ui->radioWidgetsHT);
|
||||
sw->setIndex(i);
|
||||
ui->radioWidgetsHTLayout->addWidget(sw);
|
||||
|
||||
m_radioWidgets.append(sw);
|
||||
if (!Boards::getCapability(m_board, Board::FunctionSwitches)) {
|
||||
ui->radioWidgetsCS->hide();
|
||||
}
|
||||
|
||||
midpos = (int)floorf(m_radioWidgets.size() / 2.0f);
|
||||
// switches
|
||||
int swCnt = 0;
|
||||
for (i = 0; i < ttlSwitches; ++i) {
|
||||
if (radioSettings.isSwitchAvailable(i)) {
|
||||
wname = RawSource(RawSourceType::SOURCE_TYPE_SWITCH, i + 1).toString(nullptr, &radioSettings, Board::BOARD_UNKNOWN, false);
|
||||
RadioWidget * sw;
|
||||
Board::SwitchType swcfg;
|
||||
|
||||
if (Boards::isSwitchFunc(i)) {
|
||||
swcfg = Board::SWITCH_2POS; // TODO: get this from model settings
|
||||
sw = new RadioFuncSwitchWidget(simulator, swcfg, wname, -1, ui->radioWidgetsCS);
|
||||
ui->radioWidgetsCSLayout->addWidget(sw);
|
||||
} else {
|
||||
swcfg = Board::SwitchType(radioSettings.switchConfig[i].type);
|
||||
sw = new RadioSwitchWidget(swcfg, wname, -1, ui->radioWidgetsHT);
|
||||
ui->radioWidgetsHTLayout->addWidget(sw);
|
||||
swCnt += 1;
|
||||
}
|
||||
|
||||
sw->setIndex(i);
|
||||
|
||||
m_radioWidgets.append(sw);
|
||||
}
|
||||
}
|
||||
|
||||
midpos = (int)floorf(swCnt / 2.0f);
|
||||
|
||||
// pots in middle of switches
|
||||
for (i = 0; i < ttlInputs; ++i) {
|
||||
@@ -746,7 +763,7 @@ void SimulatorWidget::onPhaseChanged(qint32 phase, const QString & name)
|
||||
|
||||
void SimulatorWidget::onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, int index, int value)
|
||||
{
|
||||
//qDebug() << type << index << value;
|
||||
// qDebug() << type << index << value;
|
||||
if (!simulator || index < 0)
|
||||
return;
|
||||
|
||||
@@ -765,6 +782,10 @@ void SimulatorWidget::onRadioWidgetValueChange(const RadioWidget::RadioWidgetTyp
|
||||
inpType = SimulatorInterface::INPUT_SRC_SWITCH;
|
||||
break;
|
||||
|
||||
case RadioWidget::RADIO_WIDGET_FUNC_SWITCH:
|
||||
inpType = SimulatorInterface::INPUT_SRC_SWITCH;
|
||||
break;
|
||||
|
||||
case RadioWidget::RADIO_WIDGET_KNOB :
|
||||
inpType = SimulatorInterface::INPUT_SRC_KNOB;
|
||||
break;
|
||||
|
||||
@@ -114,7 +114,43 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="1" column="0" colspan="2" alignment="Qt::AlignBottom">
|
||||
<widget class="QFrame" name="radioWidgetsCS">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="midLineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="radioWidgetsCSLayout">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QFrame" name="controlsLower">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
#include "radiowidget.h"
|
||||
#include "boards.h"
|
||||
#include "simulator.h"
|
||||
#include "simulatorinterface.h"
|
||||
|
||||
#include <QSlider>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
|
||||
@@ -143,5 +145,62 @@ class RadioSwitchWidget : public RadioWidget
|
||||
|
||||
QSlider * m_slider;
|
||||
quint16 m_stepSize;
|
||||
};
|
||||
|
||||
class RadioFuncSwitchWidget : public RadioWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit RadioFuncSwitchWidget(SimulatorInterface *simulator, Board::SwitchType type, const QString & labelText, int value, QWidget * parent, Qt::WindowFlags f = Qt::WindowFlags()) :
|
||||
RadioWidget(labelText, value, parent, f)
|
||||
{
|
||||
init(simulator, type);
|
||||
}
|
||||
|
||||
void init(SimulatorInterface *simulator, Board::SwitchType swType)
|
||||
{
|
||||
m_type = RADIO_WIDGET_FUNC_SWITCH;
|
||||
|
||||
m_button = new QPushButton("");
|
||||
m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
m_button->setFixedWidth(30);
|
||||
|
||||
setWidget(m_button);
|
||||
|
||||
// TODO: connect custom function switches to model data?
|
||||
|
||||
connect(m_button, &QPushButton::pressed, this, &RadioFuncSwitchWidget::onPressed);
|
||||
connect(m_button, &QPushButton::released, this, &RadioFuncSwitchWidget::onReleased);
|
||||
connect(this, &RadioWidget::valueChanged, m_button, [=](int value) {
|
||||
m_value = value;
|
||||
});
|
||||
connect(simulator, &SimulatorInterface::fsColorChange, this, &RadioFuncSwitchWidget::onFsColorChange);
|
||||
}
|
||||
|
||||
void onPressed()
|
||||
{
|
||||
setValue(1);
|
||||
}
|
||||
|
||||
void onReleased()
|
||||
{
|
||||
setValue(-1);
|
||||
}
|
||||
|
||||
private slots:
|
||||
void onFsColorChange(quint8 index, qint32 color)
|
||||
{
|
||||
if (index == m_index && color != lastColor) {
|
||||
lastColor = color;
|
||||
QColor c = QColor((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
|
||||
QString qss = QString("background-color: %1; border: none;").arg(c.name());
|
||||
m_button->setStyleSheet(qss);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QPushButton * m_button;
|
||||
qint32 lastColor = -1;
|
||||
};
|
||||
|
||||
@@ -46,6 +46,7 @@ class RadioWidget : public QWidget
|
||||
RADIO_WIDGET_TRIM, // trim axis, usually 2 buttons & slider
|
||||
RADIO_WIDGET_STICK, // actually one axis of a stick
|
||||
RADIO_WIDGET_KEY, // UI key/pushbutton
|
||||
RADIO_WIDGET_FUNC_SWITCH,
|
||||
RADIO_WIDGET_ENUM_COUNT
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <math.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class OpenTxTest : public testing::Test
|
||||
class EdgeTxTest : public testing::Test
|
||||
{
|
||||
protected: // You should make the members protected s.t. they can be
|
||||
// accessed from sub-classes.
|
||||
|
||||
@@ -91,6 +91,7 @@ WizMix::operator ModelData()
|
||||
model.used = true;
|
||||
model.moduleData[0].modelId = modelId;
|
||||
model.setDefaultInputs(settings);
|
||||
model.setDefaultFunctionSwitches(Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches));
|
||||
|
||||
int mixIndex = 0;
|
||||
int timerIndex = 0;
|
||||
|
||||
Reference in New Issue
Block a user