Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cpn): Default calibration values for 6POS switch. #4271

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ void GeneralSettings::clear()

void GeneralSettings::init()
{
for (int i = 0; i < CPN_MAX_ANALOGS; ++i) {
calibMid[i] = 0x200;
calibSpanNeg[i] = 0x180;
calibSpanPos[i] = 0x180;
}

Firmware * firmware = Firmware::getCurrentVariant();
Board::Type board = firmware->getBoard();

Expand Down Expand Up @@ -125,6 +119,18 @@ void GeneralSettings::init()

setDefaultControlTypes(board);

for (int i = 0; i < CPN_MAX_ANALOGS; ++i) {
if ((i >= CPN_MAX_STICKS) && (i < CPN_MAX_STICKS + CPN_MAX_POTS) && (potConfig[i-CPN_MAX_STICKS] == Board::POT_MULTIPOS_SWITCH)) {
calibMid[i] = 773;;
calibSpanNeg[i] = 5388;
calibSpanPos[i] = 9758;
} else {
calibMid[i] = 0x200;
calibSpanNeg[i] = 0x180;
calibSpanPos[i] = 0x180;
}
}

backlightMode = 3; // keys and sticks
backlightDelay = 2; // 2 * 5 = 10 secs
inactivityTimer = 10;
Expand Down Expand Up @@ -689,6 +695,21 @@ QString GeneralSettings::hatsModeToString() const
return hatsModeToString(hatsMode);
}

bool GeneralSettings::fix6POSCalibration()
{
bool changed = false;
// Fix default 6POS calibration
for (int i = CPN_MAX_STICKS; i < CPN_MAX_STICKS+CPN_MAX_POTS; i += 1) {
if ((potConfig[i-CPN_MAX_STICKS] == Board::POT_MULTIPOS_SWITCH) && (calibMid[i] == 0x200) && (calibSpanNeg[i] == 0x180) && (calibSpanPos[i] == 0x180)) {
calibMid[i] = 773;;
calibSpanNeg[i] = 5388;
calibSpanPos[i] = 9758;
changed = true;
}
}
return changed;
}

// static
QString GeneralSettings::hatsModeToString(int value)
{
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class GeneralSettings {
int getDefaultStick(unsigned int channel) const;
RawSource getDefaultSource(unsigned int channel) const;
int getDefaultChannel(unsigned int stick) const;
bool fix6POSCalibration();

char semver[8 + 1];
unsigned int version;
Expand Down
6 changes: 6 additions & 0 deletions companion/src/mdichild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,9 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile)
setCurrentFile(filename);
}

if (radioData.generalSettings.fix6POSCalibration())
setModified();

// set after successful import
if (getStorageType(filename) == STORAGE_TYPE_YML)
setModified();
Expand Down Expand Up @@ -1664,6 +1667,9 @@ void MdiChild::openModelTemplate(int row)
QMessageBox::warning(this, CPN_STR_TTL_WARNING, warning);
}

if (radioData.generalSettings.fix6POSCalibration())
setModified();

radioData.models[row] = data.models[0];

// reset module bindings
Expand Down