refactor(cpn): Support JSON radio hardware definitions (#4406)
This commit is contained in:
@@ -43,7 +43,7 @@ enum BacklightMode {
|
||||
e_backlight_mode_off = 0,
|
||||
e_backlight_mode_keys = 1,
|
||||
e_backlight_mode_sticks = 2,
|
||||
e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks,
|
||||
e_backlight_mode_all = e_backlight_mode_keys + e_backlight_mode_sticks,
|
||||
e_backlight_mode_on
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
|
||||
std::string strboard = fw->getFlavour().toStdString();
|
||||
node["board"] = strboard;
|
||||
|
||||
YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
||||
YamlCalibData calib(rhs.inputConfig);
|
||||
node["calib"] = calib;
|
||||
|
||||
node["currModel"] = rhs.currModelIndex;
|
||||
@@ -263,49 +263,27 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
|
||||
}
|
||||
|
||||
Node sticksConfig;
|
||||
sticksConfig = YamlStickConfig(rhs.stickName);
|
||||
sticksConfig = YamlStickConfig(rhs.inputConfig);
|
||||
if (sticksConfig && sticksConfig.IsMap()) {
|
||||
node["sticksConfig"] = sticksConfig;
|
||||
}
|
||||
|
||||
Node potsConfig;
|
||||
potsConfig = YamlPotConfig(rhs.inputConfig);
|
||||
if (potsConfig && potsConfig.IsMap()) {
|
||||
node["potsConfig"] = potsConfig;
|
||||
}
|
||||
|
||||
Node switchConfig;
|
||||
switchConfig = YamlSwitchConfig(rhs.switchName, rhs.switchConfig);
|
||||
switchConfig = YamlSwitchConfig(rhs.switchConfig);
|
||||
if (switchConfig && switchConfig.IsMap()) {
|
||||
node["switchConfig"] = switchConfig;
|
||||
}
|
||||
|
||||
// TODO revisit when Companion refactored for adc
|
||||
// adc encoding requires pots and sliders to be merged in a prescribed sequence as defined in radio json
|
||||
int maxPots = CPN_MAX_POTS + CPN_MAX_SLIDERS;
|
||||
char potName[maxPots][HARDWARE_NAME_LEN + 1];
|
||||
unsigned int potConfig[maxPots];
|
||||
|
||||
const int sticks = Boards::getCapability(board, Board::Sticks);
|
||||
int adcoffset = sticks;
|
||||
int seq = 0;
|
||||
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::Pots); i++) {
|
||||
seq = getCurrentFirmware()->getAnalogInputSeqADC(adcoffset + i) - sticks;
|
||||
if (seq >= 0 && seq < maxPots) {
|
||||
strcpy(potName[seq], rhs.potName[i]);
|
||||
potConfig[seq] = rhs.potConfig[i];
|
||||
}
|
||||
}
|
||||
|
||||
adcoffset += Boards::getCapability(board, Board::Pots);
|
||||
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::Sliders); i++) {
|
||||
seq = getCurrentFirmware()->getAnalogInputSeqADC(adcoffset + i) - sticks;
|
||||
if (seq >= 0 && seq < maxPots) {
|
||||
strcpy(potName[seq], rhs.sliderName[i]);
|
||||
potConfig[seq] = ((rhs.sliderConfig[i] == Board::SLIDER_WITH_DETENT) ? Board::POT_SLIDER_WITH_DETENT : Board::POT_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
Node potsConfig;
|
||||
potsConfig = YamlPotConfig(potName, potConfig);
|
||||
if (potsConfig && potsConfig.IsMap()) {
|
||||
node["potsConfig"] = potsConfig;
|
||||
Node flexSwitches;
|
||||
flexSwitches = YamlSwitchesFlex(rhs.switchConfig);
|
||||
if (flexSwitches && flexSwitches.IsMap()) {
|
||||
node["flexSwitches"] = flexSwitches;
|
||||
}
|
||||
|
||||
node["ownerRegistrationID"] = rhs.registrationId;
|
||||
@@ -323,6 +301,7 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
|
||||
// Radio level tabs control (global settings)
|
||||
if (hasColorLcd)
|
||||
node["radioThemesDisabled"] = (int)rhs.radioThemesDisabled;
|
||||
|
||||
node["radioGFDisabled"] = (int)rhs.radioGFDisabled;
|
||||
node["radioTrainerDisabled"] = (int)rhs.radioTrainerDisabled;
|
||||
// Model level tabs control (global setting)
|
||||
@@ -389,7 +368,6 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
|
||||
node["board"] >> flavour;
|
||||
|
||||
auto fw = getCurrentFirmware();
|
||||
auto board = fw->getBoard();
|
||||
|
||||
qDebug() << "Settings version:" << rhs.semver << "File flavour:" << flavour.c_str() << "Firmware flavour:" << fw->getFlavour();
|
||||
|
||||
@@ -419,7 +397,7 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
|
||||
|
||||
YamlCalibData calib;
|
||||
node["calib"] >> calib;
|
||||
calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
||||
calib.copy(rhs.inputConfig);
|
||||
|
||||
node["currModel"] >> rhs.currModelIndex;
|
||||
node["currModelFilename"] >> rhs.currModelFilename;
|
||||
@@ -547,39 +525,29 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
|
||||
|
||||
YamlStickConfig stickConfig;
|
||||
node["sticksConfig"] >> stickConfig;
|
||||
stickConfig.copy(rhs.stickName);
|
||||
|
||||
YamlSwitchConfig switchConfig;
|
||||
node["switchConfig"] >> switchConfig;
|
||||
switchConfig.copy(rhs.switchName, rhs.switchConfig);
|
||||
|
||||
// TODO: revisit when Companion refactored to support adc
|
||||
// adc pots and sliders decoded into a single array but Compapanion has separate arrays
|
||||
int maxPots = CPN_MAX_POTS + CPN_MAX_SLIDERS; // must match YamlPotConfig declaration
|
||||
char potName[maxPots][HARDWARE_NAME_LEN + 1];
|
||||
unsigned int potConfig[maxPots];
|
||||
stickConfig.copy(rhs.inputConfig);
|
||||
|
||||
YamlPotConfig potsConfig;
|
||||
node["potsConfig"] >> potsConfig;
|
||||
potsConfig.copy(potName, potConfig);
|
||||
potsConfig.copy(rhs.inputConfig);
|
||||
|
||||
int numPots = Boards::getCapability(board, Board::Pots);
|
||||
|
||||
for (int i = 0; i < numPots; i++) {
|
||||
strcpy(rhs.potName[i], potName[i]);
|
||||
rhs.potConfig[i] = potConfig[i];
|
||||
}
|
||||
|
||||
if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
|
||||
// for parsing pre v2.10 config - this is not encoded
|
||||
if (node["slidersConfig"]) {
|
||||
YamlSliderConfig slidersConfig;
|
||||
node["slidersConfig"] >> slidersConfig;
|
||||
slidersConfig.copy(rhs.sliderName, rhs.sliderConfig);
|
||||
slidersConfig.copy(rhs.inputConfig);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < Boards::getCapability(board, Board::Sliders); i++) {
|
||||
strcpy(rhs.sliderName[i], potName[numPots + i]);
|
||||
rhs.sliderConfig[i] = ((potConfig[numPots + i] == Board::POT_SLIDER_WITH_DETENT) ? Board::SLIDER_WITH_DETENT : Board::SLIDER_NONE);
|
||||
}
|
||||
|
||||
YamlSwitchConfig switchConfig;
|
||||
node["switchConfig"] >> switchConfig;
|
||||
switchConfig.copy(rhs.switchConfig);
|
||||
|
||||
// MUST be parsed after switchConfig
|
||||
if (node["flexSwitches"]) {
|
||||
YamlSwitchesFlex flexSwitches;
|
||||
node["flexSwitches"] >> flexSwitches;
|
||||
// merge
|
||||
flexSwitches.copy(rhs.switchConfig);
|
||||
}
|
||||
|
||||
node["ownerRegistrationID"] >> rhs.registrationId;
|
||||
@@ -612,6 +580,9 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
|
||||
node["modelCustomScriptsDisabled"] >> rhs.modelCustomScriptsDisabled;
|
||||
node["modelTelemetryDisabled"] >> rhs.modelTelemetryDisabled;
|
||||
|
||||
// fix ups
|
||||
rhs.validateFlexSwitches();
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace YAML
|
||||
|
||||
Reference in New Issue
Block a user