feat: special function to push customisable switches (#5497)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
elecpower
parent
40449bf730
commit
d417228677
@@ -468,6 +468,22 @@ int BoardJson::getSwitchTagNum(const SwitchesTable * switches, int index)
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int BoardJson::getSwitchTypeOffset(Board::SwitchType type)
|
||||
{
|
||||
return getSwitchTypeOffset(m_switches, type);
|
||||
}
|
||||
|
||||
// static
|
||||
int BoardJson::getSwitchTypeOffset(const SwitchesTable * switches, Board::SwitchType type)
|
||||
{
|
||||
for (int i = 0; i < (int)switches->size(); i++) {
|
||||
if (type == switches->at(i).type)
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int BoardJson::getSwitchYamlIndex(const QString val, YamlLookupType ylt) const
|
||||
{
|
||||
for (int i = 0; i < (int)m_switches->size(); i++) {
|
||||
|
||||
@@ -41,7 +41,7 @@ class BoardJson
|
||||
};
|
||||
|
||||
struct InputDefn {
|
||||
Board::AnalogInputType type = AIT_NONE;
|
||||
Board::AnalogInputType type = AIT_NONE;
|
||||
std::string tag = "";
|
||||
std::string name = "";
|
||||
std::string shortName = "";
|
||||
@@ -61,7 +61,7 @@ class BoardJson
|
||||
};
|
||||
|
||||
struct SwitchDefn {
|
||||
Board::SwitchType type = Board::SWITCH_NOT_AVAILABLE;
|
||||
Board::SwitchType type = Board::SWITCH_NOT_AVAILABLE;
|
||||
std::string tag = "";
|
||||
std::string name = "";
|
||||
int flags = 0;
|
||||
@@ -77,8 +77,8 @@ class BoardJson
|
||||
typedef std::vector<SwitchDefn> SwitchesTable;
|
||||
|
||||
struct TrimDefn {
|
||||
std::string tag = "";
|
||||
std::string name = "";
|
||||
std::string tag = "";
|
||||
std::string name = "";
|
||||
Board::LookupValueType cfgYaml = Board::LVT_TAG;
|
||||
Board::LookupValueType refYaml = Board::LVT_NAME;
|
||||
|
||||
@@ -124,6 +124,7 @@ class BoardJson
|
||||
const QString getSwitchName(int index) const;
|
||||
const QString getSwitchTag(int index) const;
|
||||
const int getSwitchTagNum(int index) const;
|
||||
const int getSwitchTypeOffset(Board::SwitchType type);
|
||||
const int getSwitchYamlIndex(const QString val, YamlLookupType ylt) const;
|
||||
const QString getSwitchYamlName(int index, YamlLookupType ylt) const;
|
||||
|
||||
@@ -183,6 +184,7 @@ private:
|
||||
static QString getSwitchName(const SwitchesTable * switches, int index);
|
||||
static QString getSwitchTag(const SwitchesTable * switches, int index);
|
||||
static int getSwitchTagNum(const SwitchesTable * switches, int index);
|
||||
static int getSwitchTypeOffset(const SwitchesTable * switches, Board::SwitchType type);
|
||||
|
||||
static int getTrimIndex(const TrimsTable * trims, QString val, Board::LookupValueType lvt);
|
||||
static QString getTrimName(const TrimsTable * trims, int index);
|
||||
|
||||
@@ -954,6 +954,11 @@ int Boards::getSwitchTagNum(int index, Board::Type board)
|
||||
return getBoardJson(board)->getSwitchTagNum(index);
|
||||
}
|
||||
|
||||
int Boards::getSwitchTypeOffset(Board::SwitchType type, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getSwitchTypeOffset(type);
|
||||
}
|
||||
|
||||
int Boards::getSwitchYamlIndex(QString val, int ylt, Board::Type board)
|
||||
{
|
||||
return getBoardJson(board)->getSwitchYamlIndex(val, (BoardJson::YamlLookupType)ylt);
|
||||
|
||||
@@ -352,6 +352,7 @@ class Boards
|
||||
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);
|
||||
static int getSwitchTypeOffset(Board::SwitchType type, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static int getSwitchYamlIndex(QString val, int ylt, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
static QString getSwitchYamlName(int index, int ylt, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
|
||||
|
||||
@@ -132,6 +132,10 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
|
||||
return tr("RGB leds");
|
||||
else if (func == FuncLCDtoVideo)
|
||||
return tr("LCD to Video");
|
||||
else if (func >= FuncPushCustomSwitch1 && func <= FuncPushCustomSwitchLast) {
|
||||
const int idx = Boards::getSwitchTypeOffset(Board::SWITCH_FUNC) + func - FuncPushCustomSwitch1 + 1;
|
||||
return tr("Push Custom Switch %1").arg(RawSource(SOURCE_TYPE_SWITCH, idx).toString(model));
|
||||
}
|
||||
else {
|
||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
||||
}
|
||||
@@ -146,7 +150,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
if ((func >= FuncOverrideCH1 && func <= FuncOverrideCHLast) || func == FuncSetScreen) {
|
||||
return QString("%1").arg(param);
|
||||
}
|
||||
else if (func == FuncLogs) {
|
||||
else if (func == FuncLogs || (func >= FuncPushCustomSwitch1 && func <= FuncPushCustomSwitchLast)) {
|
||||
return QString("%1").arg(param / 10.0) + tr("s");
|
||||
}
|
||||
else if (func == FuncPlaySound) {
|
||||
@@ -260,7 +264,8 @@ bool CustomFunctionData::isFuncAvailable(const int index, const ModelData * mode
|
||||
((index == FuncSetScreen && !Boards::getCapability(fw->getBoard(), Board::HasColorLcd))) ||
|
||||
((index == FuncDisableAudioAmp && !Boards::getCapability(fw->getBoard(), Board::HasAudioMuteGPIO))) ||
|
||||
((index == FuncRGBLed && !Boards::getCapability(fw->getBoard(), Board::HasLedStripGPIO))) ||
|
||||
((index == FuncLCDtoVideo && !IS_FATFISH_F16(fw->getBoard())))
|
||||
((index == FuncLCDtoVideo && !IS_FATFISH_F16(fw->getBoard()))) ||
|
||||
((index >= FuncPushCustomSwitch1 && index <= FuncPushCustomSwitchLast) && !Boards::getCapability(fw->getBoard(), Board::FunctionSwitches))
|
||||
);
|
||||
return !ret;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ enum AssignFunc {
|
||||
FuncDisableAudioAmp,
|
||||
FuncRGBLed,
|
||||
FuncLCDtoVideo,
|
||||
FuncPushCustomSwitch1,
|
||||
FuncPushCustomSwitchLast = FuncPushCustomSwitch1 + CPN_MAX_SWITCHES_FUNCTION - 1,
|
||||
FuncCount,
|
||||
FuncReserve = -1
|
||||
};
|
||||
|
||||
@@ -63,6 +63,7 @@ static const YamlLookupTable customFnLut = {
|
||||
{ FuncDisableAudioAmp, "DISABLE_AUDIO_AMP" },
|
||||
{ FuncRGBLed, "RGB_LED" },
|
||||
{ FuncLCDtoVideo, "LCD_TO_VIDEO" },
|
||||
{ FuncPushCustomSwitch1, "PUSH_CUST_SWITCH" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable trainerLut = {
|
||||
@@ -124,7 +125,8 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
|
||||
|
||||
int fn = rhs.func;
|
||||
int p1 = 0;
|
||||
if(fn >= FuncOverrideCH1 && fn <= FuncOverrideCHLast) {
|
||||
|
||||
if (fn >= FuncOverrideCH1 && fn <= FuncOverrideCHLast) {
|
||||
p1 = fn - (int)FuncOverrideCH1;
|
||||
fn = (int)FuncOverrideCH1;
|
||||
} else if (fn >= FuncTrainer && fn <= FuncTrainerChannels) {
|
||||
@@ -142,7 +144,11 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
|
||||
} else if (fn >= FuncBindInternalModule && fn <= FuncBindExternalModule) {
|
||||
p1 = fn - (int)FuncBindInternalModule;
|
||||
fn = (int)FuncBindInternalModule;
|
||||
} else if (fn >= FuncPushCustomSwitch1 && fn <= FuncPushCustomSwitchLast) {
|
||||
p1 = fn - (int)FuncPushCustomSwitch1;
|
||||
fn = (int)FuncPushCustomSwitch1;
|
||||
}
|
||||
|
||||
node["func"] = LookupValue(customFnLut, fn);
|
||||
|
||||
bool add_comma = true;
|
||||
@@ -217,6 +223,11 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
|
||||
case FuncSetScreen:
|
||||
def += std::to_string(rhs.param);
|
||||
break;
|
||||
case FuncPushCustomSwitch1:
|
||||
def += std::to_string(p1);
|
||||
def += ",";
|
||||
def += std::to_string(rhs.param);
|
||||
break;
|
||||
default:
|
||||
add_comma = false;
|
||||
break;
|
||||
@@ -264,18 +275,18 @@ bool convert<CustomFunctionData>::decode(const Node& node,
|
||||
|
||||
switch(rhs.func) {
|
||||
case FuncOverrideCH1: {
|
||||
int ch=0;
|
||||
def >> ch;
|
||||
rhs.func = (AssignFunc)((int)rhs.func + ch);
|
||||
def.ignore();
|
||||
def >> rhs.param;
|
||||
int ch=0;
|
||||
def >> ch;
|
||||
rhs.func = (AssignFunc)((int)rhs.func + ch);
|
||||
def.ignore();
|
||||
def >> rhs.param;
|
||||
} break;
|
||||
case FuncTrainer: {
|
||||
std::string value_str;
|
||||
getline(def, value_str, ',');
|
||||
int value=0;
|
||||
Node(value_str) >> trainerLut >> value;
|
||||
rhs.func = (AssignFunc)((int)rhs.func + value);
|
||||
std::string value_str;
|
||||
getline(def, value_str, ',');
|
||||
int value=0;
|
||||
Node(value_str) >> trainerLut >> value;
|
||||
rhs.func = (AssignFunc)((int)rhs.func + value);
|
||||
} break;
|
||||
case FuncPlaySound: {
|
||||
std::string snd;
|
||||
@@ -379,6 +390,15 @@ bool convert<CustomFunctionData>::decode(const Node& node,
|
||||
def >> param;
|
||||
rhs.param = param;
|
||||
} break;
|
||||
case FuncPushCustomSwitch1: {
|
||||
int sw = 0;
|
||||
def >> sw;
|
||||
rhs.func = (AssignFunc)((int)rhs.func + sw);
|
||||
def.ignore();
|
||||
int param = 0;
|
||||
def >> param;
|
||||
rhs.param = param;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -194,9 +194,10 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
|
||||
case SOURCE_TYPE_SWITCH:
|
||||
dfltName = Boards::getSwitchInfo(index - 1, board).name.c_str();
|
||||
if (Boards::isSwitchFunc(index - 1, board)) {
|
||||
if (model && index <= CPN_MAX_SWITCHES_FUNCTION) {
|
||||
if (model) {
|
||||
int fsindex = Boards::getSwitchTagNum(index - 1, board) - 1;
|
||||
custName = QString(model->functionSwitchNames[fsindex]).trimmed();
|
||||
if (fsindex >= 0 && fsindex < CPN_MAX_SWITCHES_FUNCTION)
|
||||
custName = QString(model->functionSwitchNames[fsindex]).trimmed();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -398,7 +398,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM;
|
||||
}
|
||||
}
|
||||
else if (func == FuncLogs) {
|
||||
else if (func == FuncLogs || (func >= FuncPushCustomSwitch1 && func <= FuncPushCustomSwitchLast)) {
|
||||
fswtchParam[i]->setDecimals(1);
|
||||
fswtchParam[i]->setMinimum(0);
|
||||
fswtchParam[i]->setMaximum(25.5);
|
||||
|
||||
Reference in New Issue
Block a user