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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user