Use Boards for trim switches
This commit is contained in:
committed by
Raphael Coeffic
parent
609604d141
commit
1c7bece090
@@ -757,3 +757,30 @@ StringTagMappingTable Boards::getSwitchesLookupTable(Board::Type board)
|
|||||||
|
|
||||||
return tbl;
|
return tbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
StringTagMappingTable Boards::getTrimSwitchesLookupTable(Board::Type board)
|
||||||
|
{
|
||||||
|
StringTagMappingTable tbl;
|
||||||
|
|
||||||
|
tbl.insert(tbl.end(), {
|
||||||
|
{std::to_string(TRIM_SW_LH_DEC), "TrimRudLeft"},
|
||||||
|
{std::to_string(TRIM_SW_LH_INC), "TrimRudRight"},
|
||||||
|
{std::to_string(TRIM_SW_LV_DEC), "TrimEleDown"},
|
||||||
|
{std::to_string(TRIM_SW_LV_INC), "TrimEleUp"},
|
||||||
|
{std::to_string(TRIM_SW_RV_DEC), "TrimThrDown"},
|
||||||
|
{std::to_string(TRIM_SW_RV_INC), "TrimThrUp"},
|
||||||
|
{std::to_string(TRIM_SW_RH_DEC), "TrimAilLeft"},
|
||||||
|
{std::to_string(TRIM_SW_RH_INC), "TrimAilRight"},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (getCapability(board, Board::NumTrims) > 4)
|
||||||
|
tbl.insert(tbl.end(), {
|
||||||
|
{std::to_string(TRIM_SW_T5_DEC), "TrimT5Down"},
|
||||||
|
{std::to_string(TRIM_SW_T5_INC), "TrimT5Up"},
|
||||||
|
{std::to_string(TRIM_SW_T6_DEC), "TrimT6Down"},
|
||||||
|
{std::to_string(TRIM_SW_T6_INC), "TrimT6Up"},
|
||||||
|
});
|
||||||
|
|
||||||
|
return tbl;
|
||||||
|
}
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ class Boards
|
|||||||
static AbstractStaticItemModel * potTypeItemModel();
|
static AbstractStaticItemModel * potTypeItemModel();
|
||||||
static AbstractStaticItemModel * sliderTypeItemModel();
|
static AbstractStaticItemModel * sliderTypeItemModel();
|
||||||
static AbstractStaticItemModel * switchTypeItemModel();
|
static AbstractStaticItemModel * switchTypeItemModel();
|
||||||
|
static StringTagMappingTable getTrimSwitchesLookupTable(Board::Type board);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
@@ -21,22 +21,6 @@
|
|||||||
#include "yaml_rawswitch.h"
|
#include "yaml_rawswitch.h"
|
||||||
#include "eeprominterface.h"
|
#include "eeprominterface.h"
|
||||||
|
|
||||||
// TODO: use lookup of trims in Boards ???
|
|
||||||
const YamlLookupTable trimSwitchLut = {
|
|
||||||
{ 0, "TrimRudLeft" },
|
|
||||||
{ 1, "TrimRudRight" },
|
|
||||||
{ 2, "TrimEleDown" },
|
|
||||||
{ 3, "TrimEleUp" },
|
|
||||||
{ 4, "TrimThrDown" },
|
|
||||||
{ 5, "TrimThrUp" },
|
|
||||||
{ 6, "TrimAilLeft" },
|
|
||||||
{ 7, "TrimAilRight" },
|
|
||||||
{ 8, "TrimT5Down" },
|
|
||||||
{ 9, "TrimT5Up" },
|
|
||||||
{ 10, "TrimT6Down" },
|
|
||||||
{ 11, "TrimT6Up" },
|
|
||||||
};
|
|
||||||
|
|
||||||
const YamlLookupTable switchTypeLut = {
|
const YamlLookupTable switchTypeLut = {
|
||||||
{ SWITCH_TYPE_NONE, "NONE" },
|
{ SWITCH_TYPE_NONE, "NONE" },
|
||||||
{ SWITCH_TYPE_ON, "ON" },
|
{ SWITCH_TYPE_ON, "ON" },
|
||||||
@@ -75,8 +59,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SWITCH_TYPE_TRIM:
|
case SWITCH_TYPE_TRIM:
|
||||||
// TODO: use lookup of trims in Boards ???
|
sw_str += getCurrentFirmware()->getTrimSwitchesTag(sval);
|
||||||
sw_str += YAML::LookupValue(trimSwitchLut, sval);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SWITCH_TYPE_FLIGHT_MODE:
|
case SWITCH_TYPE_FLIGHT_MODE:
|
||||||
@@ -134,10 +117,12 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
|
|||||||
std::stoi(sw_str.substr(1, val_len - 1)) - 1);
|
std::stoi(sw_str.substr(1, val_len - 1)) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (sw_str.substr(0, 3) == std::string("Trim")) {
|
} else if (sw_str.substr(0, 4) == std::string("Trim")) {
|
||||||
// TODO: use lookup of trims in Boards ???
|
int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str.c_str());
|
||||||
rhs.type = SWITCH_TYPE_TRIM;
|
if (tsw_idx >= 0) {
|
||||||
YAML::Node(sw_str) >> trimSwitchLut >> rhs.index;
|
rhs.type = SWITCH_TYPE_TRIM;
|
||||||
|
rhs.index = tsw_idx;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (val_len >= 3 && val[0] == 'S' &&
|
} else if (val_len >= 3 && val[0] == 'S' &&
|
||||||
(val[1] >= 'A' && val[1] <= 'Z') &&
|
(val[1] >= 'A' && val[1] <= 'Z') &&
|
||||||
|
|||||||
@@ -230,3 +230,29 @@ std::string Firmware::getSwitchesTag(unsigned int index)
|
|||||||
|
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Firmware::getTrimSwitchesIndex(const char * tag)
|
||||||
|
{
|
||||||
|
const StringTagMappingTable& lut = trimSwitchesLookupTable;
|
||||||
|
|
||||||
|
auto it =
|
||||||
|
find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) {
|
||||||
|
if (elmt.tag == tag) return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != lut.end()) {
|
||||||
|
return it - lut.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Firmware::getTrimSwitchesTag(unsigned int index)
|
||||||
|
{
|
||||||
|
const StringTagMappingTable& lut = trimSwitchesLookupTable;
|
||||||
|
if (index < lut.size())
|
||||||
|
return lut[index].tag;
|
||||||
|
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|||||||
@@ -292,7 +292,8 @@ class Firmware
|
|||||||
base(base),
|
base(base),
|
||||||
eepromInterface(nullptr),
|
eepromInterface(nullptr),
|
||||||
analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)),
|
analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)),
|
||||||
switchesLookupTable(Boards::getSwitchesLookupTable(board))
|
switchesLookupTable(Boards::getSwitchesLookupTable(board)),
|
||||||
|
trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,10 +412,17 @@ class Firmware
|
|||||||
return &switchesLookupTable;
|
return &switchesLookupTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StringTagMappingTable* getTrimSwitchesLookupTable()
|
||||||
|
{
|
||||||
|
return &trimSwitchesLookupTable;
|
||||||
|
}
|
||||||
|
|
||||||
int getAnalogInputIndex(const char * tag);
|
int getAnalogInputIndex(const char * tag);
|
||||||
std::string getAnalogInputTag(unsigned int index);
|
std::string getAnalogInputTag(unsigned int index);
|
||||||
int getSwitchesIndex(const char * tag);
|
int getSwitchesIndex(const char * tag);
|
||||||
std::string getSwitchesTag(unsigned int index);
|
std::string getSwitchesTag(unsigned int index);
|
||||||
|
int getTrimSwitchesIndex(const char * tag);
|
||||||
|
std::string getTrimSwitchesTag(unsigned int index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString id;
|
QString id;
|
||||||
@@ -425,6 +433,7 @@ class Firmware
|
|||||||
EEPROMInterface * eepromInterface;
|
EEPROMInterface * eepromInterface;
|
||||||
const StringTagMappingTable analogInputNamesLookupTable;
|
const StringTagMappingTable analogInputNamesLookupTable;
|
||||||
const StringTagMappingTable switchesLookupTable;
|
const StringTagMappingTable switchesLookupTable;
|
||||||
|
const StringTagMappingTable trimSwitchesLookupTable;
|
||||||
QList<const char *> languages;
|
QList<const char *> languages;
|
||||||
//QList<const char *> ttslanguages;
|
//QList<const char *> ttslanguages;
|
||||||
OptionsList opts;
|
OptionsList opts;
|
||||||
|
|||||||
Reference in New Issue
Block a user