Skip to content

Commit

Permalink
Fix default calibration values for 6POS switch set by Companion.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Oct 31, 2023
1 parent b6a691f commit ff42b04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
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

0 comments on commit ff42b04

Please sign in to comment.