Skip to content

Commit

Permalink
Validate general settings
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Feb 23, 2024
1 parent 081bef8 commit 9475603
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion companion/src/firmwares/edgetx/yaml_generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@

#include <QMessageBox>

void YamlValidateNames(GeneralSettings& gs, Board::Type board)
{
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
YamlValidateName(gs.inputConfig[i].name, board);
}

for (int i = 0; i < CPN_MAX_SWITCHES; i++) {
YamlValidateName(gs.switchConfig[i].name, board);
}
}

const YamlLookupTable beeperModeLut = {
{ GeneralSettings::BEEPER_QUIET, "mode_quiet" },
{ GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" },
Expand Down Expand Up @@ -589,7 +600,8 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["labelMultiMode"] >> rhs.labelMultiMode;
node["favMultiMode"] >> rhs.favMultiMode;

// fix ups
// perform integrity checks and fix-ups
YamlValidateNames(rhs, fw->getBoard());
rhs.validateFlexSwitches();

return true;
Expand Down
5 changes: 5 additions & 0 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "eeprominterface.h"
#include "radiodataconversionstate.h"
#include "compounditemmodels.h"
#include "yaml_ops.h"

const uint8_t chout_ar[] = { // First number is 0..23 -> template setup, Second is relevant channel out
1,2,3,4 , 1,2,4,3 , 1,3,2,4 , 1,3,4,2 , 1,4,2,3 , 1,4,3,2,
Expand Down Expand Up @@ -836,13 +837,15 @@ bool GeneralSettings::convertLegacyConfiguration(Board::Type board)
{
for (int i = 0; i < CPN_MAX_STICKS && i < Boards::getCapability(board, Board::Sticks); i++) {
inputConfig[i].type = Board::AIT_STICK;
YamlValidateName(stickName[i], board);
strncpy(inputConfig[i].name, stickName[i], HARDWARE_NAME_LEN);
}

for (int i = 0; i < CPN_MAX_POTS && i < Boards::getCapability(board, Board::Pots); i++) {
int idx = Boards::getInputPotIndex(i, board);
if (idx >= 0) {
inputConfig[idx].type = Board::AIT_FLEX;
YamlValidateName(potName[i], board);
strncpy(inputConfig[idx].name, potName[i], HARDWARE_NAME_LEN);
int ft = std::stoi(DataHelpers::getStringTagMappingTag(potTypesConversionTable, potConfig[i]));
if (ft > -1)
Expand All @@ -854,6 +857,7 @@ bool GeneralSettings::convertLegacyConfiguration(Board::Type board)
int idx = Boards::getInputSliderIndex(i, board);
if (idx >= 0) {
inputConfig[idx].type = Board::AIT_FLEX;
YamlValidateName(sliderName[i], board);
strncpy(inputConfig[idx].name, sliderName[i], HARDWARE_NAME_LEN);
int ft = std::stoi(DataHelpers::getStringTagMappingTag(sliderTypesConversionTable, sliderConfig[i]));
if (ft > -1)
Expand All @@ -869,6 +873,7 @@ bool GeneralSettings::convertLegacyConfiguration(Board::Type board)

for (int i = 0; i < CPN_MAX_SWITCHES && i < Boards::getCapability(board, Board::Switches); i++) {
switchConfig[i].type = (Board::SwitchType)swtchConfig[i];
YamlValidateName(swtchName[i], board);
strncpy(switchConfig[i].name, swtchName[i], HARDWARE_NAME_LEN);
}

Expand Down

0 comments on commit 9475603

Please sign in to comment.