fix(cpn): profile radio settings management and use (#6654)

This commit is contained in:
Neil Horne
2025-10-18 20:42:44 +10:00
committed by GitHub
parent f4ecf03a9e
commit 2fe2c6cbe8
16 changed files with 186 additions and 405 deletions
+3 -2
View File
@@ -215,7 +215,6 @@ void AppPreferencesDialog::accept()
} }
Firmware::setCurrentVariant(newFw); Firmware::setCurrentVariant(newFw);
profile.fwName(""); profile.fwName("");
profile.resetFwVariables();
profile.fwType(newFw->getId()); profile.fwType(newFw->getId());
fwchange = true; fwchange = true;
} }
@@ -362,7 +361,8 @@ void AppPreferencesDialog::initSettings()
ui->profileNameLE->setText(profile.name()); ui->profileNameLE->setText(profile.name());
QString hwSettings; QString hwSettings;
if (profile.stickPotCalib() == "" ) {
if (profile.generalSettings().isEmpty()) {
hwSettings = tr("EMPTY: No radio settings stored in profile"); hwSettings = tr("EMPTY: No radio settings stored in profile");
} }
else { else {
@@ -372,6 +372,7 @@ void AppPreferencesDialog::initSettings()
else else
hwSettings = tr("AVAILABLE: Radio settings stored %1").arg(str); hwSettings = tr("AVAILABLE: Radio settings stored %1").arg(str);
} }
ui->lblGeneralSettings->setText(hwSettings); ui->lblGeneralSettings->setText(hwSettings);
ui->chkPromptSDSync->setChecked(profile.runSDSync()); ui->chkPromptSDSync->setChecked(profile.runSDSync());
ui->lblRadioColorSample->setPalette(QPalette(profile.radioSimCaseColor())); ui->lblRadioColorSample->setPalette(QPalette(profile.radioSimCaseColor()));
+3 -3
View File
@@ -35,7 +35,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="profileTab"> <widget class="QWidget" name="profileTab">
<attribute name="title"> <attribute name="title">
@@ -94,7 +94,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>General Settings</string> <string>Radio Settings</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -522,7 +522,7 @@ Mode 4:
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string notr="true">General Settings Label</string> <string notr="true">Radio Settings Label</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -112,6 +112,7 @@ void YamlStickConfig::copy(GeneralSettings::InputConfig* rhs) const
{ {
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Inputs); i++) { for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Inputs); i++) {
if (config[i].type == (unsigned int)Board::AIT_STICK) { if (config[i].type == (unsigned int)Board::AIT_STICK) {
rhs[i].inverted = config[i].inverted;
memcpy(rhs[i].name, config[i].name, sizeof(HARDWARE_NAME_LEN)); memcpy(rhs[i].name, config[i].name, sizeof(HARDWARE_NAME_LEN));
} }
} }
@@ -270,6 +270,8 @@ class Firmware
virtual bool isAvailable(PulsesProtocol proto, int port=0) = 0; virtual bool isAvailable(PulsesProtocol proto, int port=0) = 0;
virtual QString getLanguage() const = 0;
const int getFlashSize(); const int getFlashSize();
static Firmware * getFirmwareForId(const QString & id); static Firmware * getFirmwareForId(const QString & id);
+63 -122
View File
@@ -196,31 +196,9 @@ void GeneralSettings::clear()
void GeneralSettings::init() void GeneralSettings::init()
{ {
Firmware * firmware = Firmware::getCurrentVariant(); Board::Type board = Firmware::getCurrentVariant()->getBoard();
Board::Type board = firmware->getBoard();
// vBatWarn is voltage in 100mV, vBatMin is in 100mV but with -9V offset, vBatMax has a -12V offset
Boards::getBattRange(board, vBatMin, vBatMax, vBatWarn); Boards::getBattRange(board, vBatMin, vBatMax, vBatWarn);
backlightMode = 3; // keys and sticks
backlightDelay = 2; // 2 * 5 = 10 secs
inactivityTimer = 10;
hatsMode = HATSMODE_SWITCHABLE;
// backlightBright = 0; // 0 = 100%
if (IS_FAMILY_HORUS_OR_T16(board)) {
backlightOffBright = 20;
}
speakerVolume = 12;
wavVolume = 2;
backgroundVolume = 1;
if (IS_TARANIS(board))
contrast = 25;
if (IS_JUMPER_T16(board)) if (IS_JUMPER_T16(board))
strcpy(bluetoothName, "t16"); strcpy(bluetoothName, "t16");
else if (IS_FLYSKY_NV14(board)) else if (IS_FLYSKY_NV14(board))
@@ -240,110 +218,29 @@ void GeneralSettings::init()
else if (IS_TARANIS_X9E(board) || IS_TARANIS_SMALL(board)) else if (IS_TARANIS_X9E(board) || IS_TARANIS_SMALL(board))
strcpy(bluetoothName, "taranis"); strcpy(bluetoothName, "taranis");
ttsLanguage[0] = 'e'; contrast = IS_TARANIS(board) ? 25 : 0;
ttsLanguage[1] = 'n'; backlightBright = 0; // 0 = 100%
backlightDelay = 2; // 2 * 5 = 10 secs
backlightMode = BACKLIGHT_MODE_KEYSCTRL;
backlightOffBright = IS_FAMILY_HORUS_OR_T16(board) ? 20 : 0;
templateSetup = g.profile[g.sessionId()].channelOrder(); backgroundVolume = 1;
stickMode = g.profile[g.sessionId()].defaultMode(); speakerVolume = 12;
wavVolume = 2;
QString t_calib = g.profile[g.sessionId()].stickPotCalib();
if (!t_calib.isEmpty()) {
QString t_trainercalib=g.profile[g.sessionId()].trainerCalib();
int8_t t_txVoltageCalibration=(int8_t)g.profile[g.sessionId()].txVoltageCalibration();
int8_t t_txCurrentCalibration=(int8_t)g.profile[g.sessionId()].txCurrentCalibration();
int8_t t_PPM_Multiplier=(int8_t)g.profile[g.sessionId()].ppmMultiplier();
uint8_t t_stickMode=(uint8_t)g.profile[g.sessionId()].gsStickMode();
uint8_t t_vBatWarn=(uint8_t)g.profile[g.sessionId()].vBatWarn();
QString t_DisplaySet=g.profile[g.sessionId()].display();
QString t_BeeperSet=g.profile[g.sessionId()].beeper();
QString t_HapticSet=g.profile[g.sessionId()].haptic();
QString t_SpeakerSet=g.profile[g.sessionId()].speaker();
QString t_CountrySet=g.profile[g.sessionId()].countryCode();
if ((t_calib.length() == (Boards::getInputsCalibrated() * 12)) && (t_trainercalib.length() == 16)) {
QString Byte;
int16_t byte16;
bool ok;
for (int i = 0; i < Boards::getCapability(board, Board::Inputs); i++) {
if (Boards::isInputCalibrated(i)) {
Byte = t_calib.mid(i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) inputConfig[i].calib.mid = byte16;
Byte = t_calib.mid(4 + i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) inputConfig[i].calib.spanNeg = byte16;
Byte = t_calib.mid(8 + i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) inputConfig[i].calib.spanPos = byte16;
}
}
for (int i = 0; i < Boards::getCapability(board, Board::Sticks); i++) {
Byte = t_trainercalib.mid(i * 4, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) trainer.calib[i] = byte16;
}
txCurrentCalibration = t_txCurrentCalibration;
txVoltageCalibration = t_txVoltageCalibration;
vBatWarn = t_vBatWarn;
PPM_Multiplier = t_PPM_Multiplier;
stickMode = t_stickMode;
}
if ((t_DisplaySet.length()==6) && (t_BeeperSet.length()==4) && (t_HapticSet.length()==6) && (t_SpeakerSet.length()==6)) {
uint8_t byte8u;
int8_t byte8;
bool ok;
byte8=(int8_t)t_DisplaySet.mid(0,2).toInt(&ok,16);
if (ok)
optrexDisplay=(byte8==1 ? true : false);
byte8u=(uint8_t)t_DisplaySet.mid(2,2).toUInt(&ok,16);
if (ok)
contrast=byte8u;
byte8u=(uint8_t)t_DisplaySet.mid(4,2).toUInt(&ok,16);
if (ok)
backlightBright=byte8u;
byte8=(int8_t)t_BeeperSet.mid(0,2).toUInt(&ok,16);
if (ok)
beeperMode=(BeeperMode)byte8;
byte8=(int8_t)t_BeeperSet.mid(2,2).toInt(&ok,16);
if (ok)
beeperLength=byte8;
byte8=(int8_t)t_HapticSet.mid(0,2).toUInt(&ok,16);
if (ok)
hapticMode=(BeeperMode)byte8;
byte8=(int8_t)t_HapticSet.mid(2,2).toInt(&ok,16);
if (ok)
hapticStrength=byte8;
byte8=(int8_t)t_HapticSet.mid(4,2).toInt(&ok,16);
if (ok)
hapticLength=byte8;
byte8u=(uint8_t)t_SpeakerSet.mid(0,2).toUInt(&ok,16);
if (ok)
speakerMode=byte8u;
byte8u=(uint8_t)t_SpeakerSet.mid(2,2).toUInt(&ok,16);
if (ok)
speakerPitch=byte8u;
byte8u=(uint8_t)t_SpeakerSet.mid(4,2).toUInt(&ok,16);
if (ok)
speakerVolume=byte8u;
if (t_CountrySet.length()==6) {
byte8u=(uint8_t)t_CountrySet.mid(0,2).toUInt(&ok,16);
if (ok)
countryCode=byte8u;
byte8u=(uint8_t)t_CountrySet.mid(2,2).toUInt(&ok,16);
if (ok)
imperial=byte8u;
QString chars = t_CountrySet.mid(4, 2);
ttsLanguage[0] = chars[0].toLatin1();
ttsLanguage[1] = chars[1].toLatin1();
}
}
}
hatsMode = HATSMODE_SWITCHABLE;
inactivityTimer = 10;
internalModule = g.profile[g.sessionId()].defaultInternalModule(); internalModule = g.profile[g.sessionId()].defaultInternalModule();
if (IS_FLYSKY_NV14(board) || IS_FAMILY_PL18(board)) QString lang = getCurrentFirmware()->getLanguage();
stickDeadZone = 2; if (lang.size() > 1)
memcpy(ttsLanguage, lang.toLatin1().data(), 2);
else {
ttsLanguage[0] = 'e';
ttsLanguage[1] = 'n';
}
stickDeadZone = (IS_FLYSKY_NV14(board) || IS_FAMILY_PL18(board)) ? 2 : 0;
} }
void GeneralSettings::setDefaultControlTypes(Board::Type board) void GeneralSettings::setDefaultControlTypes(Board::Type board)
@@ -1019,3 +916,47 @@ void GeneralSettings::switchConfigClear()
for (int i = 0; i < CPN_MAX_SWITCHES; i++) for (int i = 0; i < CPN_MAX_SWITCHES; i++)
switchConfig[i] = SwitchConfig(); switchConfig[i] = SwitchConfig();
} }
bool GeneralSettings::isBacklightModeAvailable(int index)
{
int start = (Boards::getCapability(getCurrentFirmware()->getBoard(), Board::LcdDepth) >= 8) ? 1 : 0;
return index >= start;
}
QString GeneralSettings::backlightModeToString() const
{
return backlightModeToString(stickMode);
}
// static
QString GeneralSettings::backlightModeToString(int value)
{
switch(value) {
case BACKLIGHT_MODE_OFF:
return tr("OFF");
case BACKLIGHT_MODE_KEYS:
return tr("Keys");
case BACKLIGHT_MODE_CTRL:
return tr("Controls");
case BACKLIGHT_MODE_KEYSCTRL:
return tr("Keys + Controls");
case BACKLIGHT_MODE_ON:
return tr("ON");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}
// static
AbstractStaticItemModel * GeneralSettings::backlightModeItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName(AIM_GS_BACKLIGHTMODE);
for (int i = 0; i < BACKLIGHT_MODE_COUNT; i++) {
mdl->appendToItemList(backlightModeToString(i), i, isBacklightModeAvailable(i));
}
mdl->loadItemList();
return mdl;
}
+14
View File
@@ -46,6 +46,7 @@ constexpr char AIM_GS_UARTSAMPLEMODE[] {"gs.uartsamplemode"};
constexpr char AIM_GS_HATSMODE[] {"gs.hatsmode"}; constexpr char AIM_GS_HATSMODE[] {"gs.hatsmode"};
constexpr char AIM_GS_STICKMODE[] {"gs.stickmode"}; constexpr char AIM_GS_STICKMODE[] {"gs.stickmode"};
constexpr char AIM_GS_TEMPLATESETUP[] {"gs.templatesetup"}; constexpr char AIM_GS_TEMPLATESETUP[] {"gs.templatesetup"};
constexpr char AIM_GS_BACKLIGHTMODE[] {"gs.backlightmode"};
constexpr char AIM_TRAINERMIX_MODE[] {"trainermix.mode"}; constexpr char AIM_TRAINERMIX_MODE[] {"trainermix.mode"};
constexpr char AIM_TRAINERMIX_SRC[] {"trainermix.src"}; constexpr char AIM_TRAINERMIX_SRC[] {"trainermix.src"};
@@ -215,6 +216,15 @@ class GeneralSettings {
RadioTypeContextSurface = 1 << 2, RadioTypeContextSurface = 1 << 2,
}; };
enum BacklightMode {
BACKLIGHT_MODE_OFF,
BACKLIGHT_MODE_KEYS,
BACKLIGHT_MODE_CTRL,
BACKLIGHT_MODE_KEYSCTRL,
BACKLIGHT_MODE_ON,
BACKLIGHT_MODE_COUNT,
};
GeneralSettings() { clear(); } GeneralSettings() { clear(); }
void clear(); void clear();
void init(); void init();
@@ -399,6 +409,7 @@ class GeneralSettings {
bool isSwitchFlex(int index) const; bool isSwitchFlex(int index) const;
bool isSwitchFunc(int index) const; bool isSwitchFunc(int index) const;
bool unassignedInputFlexSwitches() const; bool unassignedInputFlexSwitches() const;
static bool isBacklightModeAvailable(int index);
QString antennaModeToString() const; QString antennaModeToString() const;
QString bluetoothModeToString() const; QString bluetoothModeToString() const;
@@ -408,6 +419,7 @@ class GeneralSettings {
QString hatsModeToString() const; QString hatsModeToString() const;
QString stickModeToString() const; QString stickModeToString() const;
QString templateSetupToString() const; QString templateSetupToString() const;
QString backlightModeToString() const;
static QString antennaModeToString(int value); static QString antennaModeToString(int value);
static QString bluetoothModeToString(int value); static QString bluetoothModeToString(int value);
@@ -419,6 +431,7 @@ class GeneralSettings {
static QString hatsModeToString(int value); static QString hatsModeToString(int value);
static QString stickModeToString(int value); static QString stickModeToString(int value);
static QString templateSetupToString(int value, bool isBoardAir); static QString templateSetupToString(int value, bool isBoardAir);
static QString backlightModeToString(int value);
static AbstractStaticItemModel * antennaModeItemModel(bool model_setup = false); static AbstractStaticItemModel * antennaModeItemModel(bool model_setup = false);
static AbstractStaticItemModel * bluetoothModeItemModel(); static AbstractStaticItemModel * bluetoothModeItemModel();
@@ -429,6 +442,7 @@ class GeneralSettings {
static AbstractStaticItemModel * hatsModeItemModel(bool radio_setup = true); static AbstractStaticItemModel * hatsModeItemModel(bool radio_setup = true);
static AbstractStaticItemModel * stickModeItemModel(); static AbstractStaticItemModel * stickModeItemModel();
static AbstractStaticItemModel * templateSetupItemModel(); static AbstractStaticItemModel * templateSetupItemModel();
static AbstractStaticItemModel * backlightModeItemModel();
void validateFlexSwitches(); void validateFlexSwitches();
}; };
@@ -391,6 +391,12 @@ QString OpenTxFirmware::getReleaseNotesUrl()
return QString("%1/downloads").arg(EDGETX_HOME_PAGE_URL); return QString("%1/downloads").arg(EDGETX_HOME_PAGE_URL);
} }
QString OpenTxFirmware::getLanguage() const
{
QStringList strl = getId().split('-');
return strl.size() > 2 ? strl.at(2) : QString();
}
// Firmware registrations // Firmware registrations
// NOTE: "recognized" build options are defined in /radio/util/fwoptions.py // NOTE: "recognized" build options are defined in /radio/util/fwoptions.py
@@ -91,6 +91,8 @@ class OpenTxFirmware: public Firmware
return false; return false;
} }
virtual QString getLanguage() const override;
protected: protected:
QString getFirmwareBaseUrl() { return ""; } // depreciated; QString getFirmwareBaseUrl() { return ""; } // depreciated;
+48 -207
View File
@@ -31,6 +31,7 @@
#include "generaloptions.h" #include "generaloptions.h"
#include "scrollarea.h" #include "scrollarea.h"
#include "compounditemmodels.h" #include "compounditemmodels.h"
#include "firmwares/edgetx/edgetxinterface.h"
GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * firmware) : GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * firmware) :
QDialog(parent), QDialog(parent),
@@ -40,23 +41,8 @@ GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * fir
{ {
ui->setupUi(this); ui->setupUi(this);
this->setWindowIcon(CompanionIcon("open.png")); this->setWindowIcon(CompanionIcon("open.png"));
ui->btnLoadSettings->setDisabled(g.currentProfile().generalSettings().isEmpty());
QString firmware_id = g.profile[g.id()].fwType(); ui->btnClearSettings->setDisabled(g.currentProfile().generalSettings().isEmpty());
QString name=g.profile[g.id()].name();
if (name.isEmpty()) {
ui->calstore_PB->setDisabled(true);
}
ui->profile_CB->clear();
for (int i = 0; i < MAX_PROFILES; ++i) {
QString name=g.profile[i].name();
if (!name.isEmpty()) {
ui->profile_CB->addItem(name, i);
if (i == g.id()) {
ui->profile_CB->setCurrentIndex(ui->profile_CB->count() - 1);
}
}
}
editorItemModels = new CompoundItemModelFactory(&generalSettings, nullptr); editorItemModels = new CompoundItemModelFactory(&generalSettings, nullptr);
// tabs created below expect these item models to be pre-registered // tabs created below expect these item models to be pre-registered
@@ -112,207 +98,62 @@ void GeneralEdit::on_tabWidget_currentChanged(int index)
panels[index]->update(); panels[index]->update();
} }
void GeneralEdit::on_calretrieve_PB_clicked() void GeneralEdit::on_btnLoadSettings_clicked()
{ {
Board::Type board = getCurrentBoard(); if (QMessageBox::question(this, tr("Profile Radio Settings"),
int profile_id = ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt(); tr("WARNING: Loading settings from profile is irreversable.\n\nAre you sure?"),
QString calib = g.profile[profile_id].stickPotCalib(); QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
int ttlSticks = getBoardCapability(board, Board::Sticks); return;
int ttlInputs = getBoardCapability(board, Board::Inputs);
int ttlSwitches = getBoardCapability(board, Board::Switches); QByteArray data = g.currentProfile().generalSettings();
if (calib.isEmpty()) {
try {
if (!loadRadioSettingsFromYaml(generalSettings, data)) {
QMessageBox::critical(this, tr("Profile Radio Settings"), tr("Unable to load settings from profile!"));
return;
}
} catch(const std::runtime_error& e) {
QMessageBox::critical(this, tr("Profile Radio Settings"),
tr("Unable to load settings from profile!") + ":\n" + QString(e.what()));
return; return;
} }
else {
QString trainercalib = g.profile[profile_id].trainerCalib();
QString hwtypes = g.profile[profile_id].controlTypes();
QString controlNames = g.profile[profile_id].controlNames();
int8_t txVoltageCalibration = (int8_t)g.profile[profile_id].txVoltageCalibration();
int8_t txCurrentCalibration = (int8_t)g.profile[profile_id].txCurrentCalibration();
int8_t PPM_Multiplier = (int8_t)g.profile[profile_id].ppmMultiplier();
uint8_t GSStickMode = (uint8_t)g.profile[profile_id].gsStickMode();
uint8_t vBatWarn = (uint8_t)g.profile[profile_id].vBatWarn();
QString DisplaySet = g.profile[profile_id].display();
QString BeeperSet = g.profile[profile_id].beeper();
QString HapticSet = g.profile[profile_id].haptic();
QString SpeakerSet = g.profile[profile_id].speaker();
QString CountrySet = g.profile[profile_id].countryCode();
if ((calib.length() == (Boards::getInputsCalibrated() * 12)) && (trainercalib.length() == 16)) { on_tabWidget_currentChanged(ui->tabWidget->currentIndex());
QString Byte; QMessageBox::information(this, tr("Profile Radio Settings"),
int16_t byte16; tr("Settings successfully loaded.") + "\n\n" +
bool ok; tr("The Radio Settings window will now be closed for the settings to take effect"));
for (int i = 0; i < ttlInputs; i++) {
if (Boards::isInputCalibrated(i)) {
Byte = calib.mid(i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.inputConfig[i].calib.mid = byte16;
Byte = calib.mid(4 + i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.inputConfig[i].calib.spanNeg = byte16;
Byte = calib.mid(8 + i * 12, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.inputConfig[i].calib.spanPos = byte16;
}
}
for (int i = 0; i < ttlSticks; i++) {
Byte = trainercalib.mid(i * 4, 4);
byte16 = (int16_t)Byte.toInt(&ok, 16);
if (ok) generalSettings.trainer.calib[i] = byte16;
}
generalSettings.txCurrentCalibration = txCurrentCalibration;
generalSettings.txVoltageCalibration = txVoltageCalibration;
generalSettings.vBatWarn=vBatWarn;
if (getCurrentFirmware()->getCapability(HasBatMeterRange)) {
generalSettings.vBatMin = (int8_t) g.profile[profile_id].vBatMin();
generalSettings.vBatMax = (int8_t) g.profile[profile_id].vBatMax();
}
generalSettings.PPM_Multiplier = PPM_Multiplier;
} else {
QMessageBox::critical(this, CPN_STR_TTL_WARNING, tr("Wrong data in profile, radio calibration was not retrieved"));
}
if (hwtypes.length() == ttlSwitches + ttlInputs) {
QString Byte;
int16_t byte16;
QByteArray qba;
bool ok;
for (int i = 0; i < ttlSwitches; i++) {
Byte = hwtypes.mid(i, 1);
byte16 = (int16_t)Byte.toInt(&ok, 16);
qba = controlNames.mid(3 * i, 3).toLatin1();
if (ok) {
generalSettings.switchConfig[i].type = (Board::SwitchType)byte16;
strcpy(generalSettings.switchConfig[i].name, qba.data());
}
}
for (int i = 0; i < getBoardCapability(board, Board::Inputs); i++) {
Byte = hwtypes.mid(i + ttlSwitches, 1);
byte16 = (int16_t)Byte.toInt(&ok, 16);
qba = controlNames.mid(3 * (i + ttlSwitches), 3).toLatin1();
if (ok) {
generalSettings.inputConfig[i].flexType = (Board::FlexType)byte16;
strcpy(generalSettings.inputConfig[i].name, qba.data());
}
}
} else {
QMessageBox::critical(this, CPN_STR_TTL_WARNING, tr("Wrong data in profile, Switch/pot config not retrieved"));
}
if ((DisplaySet.length()==6) && (BeeperSet.length()==4) && (HapticSet.length()==6) && (SpeakerSet.length()==6)) {
generalSettings.stickMode=GSStickMode;
uint8_t byte8u;
int8_t byte8;
QString chars;
bool ok;
byte8 = (int8_t)DisplaySet.mid(0,2).toInt(&ok, 16);
if (ok) generalSettings.optrexDisplay = (byte8 == 1 ? true : false);
byte8u = (uint8_t)DisplaySet.mid(2,2).toUInt(&ok, 16);
if (ok) generalSettings.contrast = byte8u;
byte8u = (uint8_t)DisplaySet.mid(4,2).toUInt(&ok, 16);
if (ok) generalSettings.backlightBright = byte8u;
byte8 = (int8_t)BeeperSet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.beeperMode = (GeneralSettings::BeeperMode)byte8;
byte8 = (int8_t)BeeperSet.mid(2,2).toInt(&ok, 16);
if (ok) generalSettings.beeperLength = byte8;
byte8 = (int8_t)HapticSet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.hapticMode = (GeneralSettings::BeeperMode)byte8;
byte8 = (int8_t)HapticSet.mid(2,2).toInt(&ok, 16);
if (ok) generalSettings.hapticStrength = byte8;
byte8 = (int8_t)HapticSet.mid(4,2).toInt(&ok, 16);
if (ok) generalSettings.hapticLength = byte8;
byte8u = (uint8_t)SpeakerSet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.speakerMode = byte8u;
byte8u = (uint8_t)SpeakerSet.mid(2,2).toUInt(&ok, 16);
if (ok) generalSettings.speakerPitch = byte8u;
byte8u = (uint8_t)SpeakerSet.mid(4,2).toUInt(&ok, 16);
if (ok) generalSettings.speakerVolume = byte8u;
if (CountrySet.length() == 6) {
byte8u = (uint8_t)CountrySet.mid(0,2).toUInt(&ok, 16);
if (ok) generalSettings.countryCode = byte8u;
byte8u = (uint8_t)CountrySet.mid(2,2).toUInt(&ok, 16);
if (ok) generalSettings.imperial = byte8u;
chars = CountrySet.mid(4,2);
generalSettings.ttsLanguage[0] = chars[0].toLatin1();
generalSettings.ttsLanguage[1] = chars[1].toLatin1();
}
}
else {
QMessageBox::critical(this, CPN_STR_TTL_WARNING, tr("Wrong data in profile, hw related parameters were not retrieved"));
}
}
emit modified(); emit modified();
accept();
} }
void GeneralEdit::on_calstore_PB_clicked() void GeneralEdit::on_btnSaveSettings_clicked()
{ {
Board::Type board = getCurrentBoard(); if (QMessageBox::question(this, tr("Profile Radio Settings"),
int profile_id = ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt(); tr("WARNING: Saving settings to the profile is irreversable.\n\nAre you sure?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
QString name = g.profile[profile_id].name();
if (name.isEmpty()) {
ui->calstore_PB->setDisabled(true);
return; return;
}
else {
QString calib = g.profile[profile_id].stickPotCalib();
QString hwtypes = g.profile[profile_id].controlTypes();
QString controlNames = g.profile[profile_id].controlNames();
if (!(calib.isEmpty())) {
int ret = QMessageBox::question(this, CPN_STR_APP_NAME,
tr("Do you want to store calibration in %1 profile<br>overwriting existing calibration?").arg(name) ,
QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No) {
return;
}
}
int ttlSticks = getBoardCapability(board, Board::Sticks); QByteArray data;
int ttlInputs = getBoardCapability(board, Board::Inputs); writeRadioSettingsToYaml(generalSettings, data);
int ttlSwitches = getBoardCapability(board, Board::Switches); g.currentProfile().generalSettings(data);
calib.clear(); QDateTime dateTime = QDateTime::currentDateTime();
g.currentProfile().timeStamp(dateTime.toString("yyyy-MM-dd hh:mm"));
ui->btnLoadSettings->setEnabled(true);
ui->btnClearSettings->setEnabled(true);
QMessageBox::information(this, tr("Save Radio Settings to Profile"), tr("Settings saved to profile."));
}
for (int i = 0; i < ttlInputs; i++) { void GeneralEdit::on_btnClearSettings_clicked()
if (Boards::isInputCalibrated(i)) { {
calib.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].calib.mid, 4, 16, QChar('0'))); if (QMessageBox::question(this, tr("Profile Radio Settings"),
calib.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].calib.spanNeg, 4, 16, QChar('0'))); tr("WARNING: Clearing settings from the profile is irreversable.\n\nAre you sure?"),
calib.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].calib.spanPos, 4, 16, QChar('0'))); QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
} return;
}
g.profile[profile_id].stickPotCalib( calib );
calib.clear();
for (int i = 0; i < ttlSticks; i++) {
calib.append(QString("%1").arg((uint16_t)generalSettings.trainer.calib[i], 4, 16, QChar('0')));
}
g.profile[profile_id].trainerCalib( calib );
hwtypes.clear();
controlNames.clear();
for (int i = 0; i < ttlSwitches; i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.switchConfig[i].type, 1));
controlNames.append(QString("%1").arg(generalSettings.switchConfig[i].name, -3));
}
for (int i = 0; i < ttlInputs; i++) {
hwtypes.append(QString("%1").arg((uint16_t)generalSettings.inputConfig[i].flexType, 1));
controlNames.append(QString("%1").arg(generalSettings.inputConfig[i].name, -3));
}
g.profile[profile_id].controlTypes( hwtypes );
g.profile[profile_id].controlNames( controlNames );
g.profile[profile_id].txVoltageCalibration( generalSettings.txVoltageCalibration );
g.profile[profile_id].txCurrentCalibration( generalSettings.txCurrentCalibration );
g.profile[profile_id].vBatWarn( generalSettings.vBatWarn );
if (getCurrentFirmware()->getCapability(HasBatMeterRange)) {
g.profile[profile_id].vBatMin( generalSettings.vBatMin );
g.profile[profile_id].vBatMax( generalSettings.vBatMax );
}
g.profile[profile_id].ppmMultiplier( generalSettings.PPM_Multiplier );
g.profile[profile_id].gsStickMode( generalSettings.stickMode );
g.profile[profile_id].display( QString("%1%2%3").arg((generalSettings.optrexDisplay ? 1:0), 2, 16, QChar('0')).arg((uint8_t)generalSettings.contrast, 2, 16, QChar('0')).arg((uint8_t)generalSettings.backlightBright, 2, 16, QChar('0')) );
g.profile[profile_id].beeper( QString("%1%2").arg(((uint8_t)generalSettings.beeperMode), 2, 16, QChar('0')).arg((uint8_t)generalSettings.beeperLength, 2, 16, QChar('0')));
g.profile[profile_id].haptic( QString("%1%2%3").arg(((uint8_t)generalSettings.hapticMode), 2, 16, QChar('0')).arg((int8_t)generalSettings.hapticStrength, 2, 16, QChar('0')).arg((uint8_t)generalSettings.hapticLength, 2, 16, QChar('0')));
g.profile[profile_id].speaker( QString("%1%2%3").arg((uint8_t)generalSettings.speakerMode, 2, 16, QChar('0')).arg((uint8_t)generalSettings.speakerPitch, 2, 16, QChar('0')).arg((uint8_t)generalSettings.speakerVolume, 2, 16, QChar('0')));
g.profile[profile_id].countryCode( QString("%1%2%3").arg((uint8_t)generalSettings.countryCode, 2, 16, QChar('0')).arg((uint8_t)generalSettings.imperial, 2, 16, QChar('0')).arg(generalSettings.ttsLanguage));
QDateTime dateTime = QDateTime::currentDateTime(); g.currentProfile().generalSettings(QByteArray());
g.profile[profile_id].timeStamp(dateTime.toString("yyyy-MM-dd hh:mm")); g.currentProfile().timeStamp(QString());
QMessageBox::information(this, CPN_STR_APP_NAME, tr("Calibration and HW parameters saved.")); ui->btnLoadSettings->setEnabled(false);
} ui->btnClearSettings->setEnabled(false);
QMessageBox::information(this, tr("Profile Radio Settings"), tr("Settings cleared from profile."));
} }
+3 -2
View File
@@ -69,8 +69,9 @@ class GeneralEdit : public QDialog
private slots: private slots:
void onTabModified(); void onTabModified();
void on_tabWidget_currentChanged(int index); void on_tabWidget_currentChanged(int index);
void on_calretrieve_PB_clicked(); void on_btnClearSettings_clicked();
void on_calstore_PB_clicked(); void on_btnLoadSettings_clicked();
void on_btnSaveSettings_clicked();
private: private:
Firmware * firmware; Firmware * firmware;
+33 -16
View File
@@ -17,7 +17,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Radio settings</string> <string>Radio Settings</string>
</property> </property>
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
@@ -32,19 +32,26 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::Panel</enum> <enum>QFrame::Shape::Panel</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Shadow::Raised</enum>
</property> </property>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_6" rowstretch="0,0"> <layout class="QGridLayout" name="gridLayout_6" rowstretch="0">
<item row="1" column="1"> <item row="0" column="2">
<widget class="QPushButton" name="calretrieve_PB"> <widget class="QPushButton" name="btnClearSettings">
<property name="text">
<string>Clear settings from profile</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="btnSaveSettings">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@@ -52,17 +59,17 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Retrieve calib. and hw settings from profile</string> <string>Store settings in profile</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="0" column="1">
<spacer name="horizontalSpacer_5"> <spacer name="horizontalSpacer_5">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Orientation::Horizontal</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Policy::Expanding</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@@ -72,8 +79,8 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="3"> <item row="0" column="0">
<widget class="QPushButton" name="calstore_PB"> <widget class="QPushButton" name="btnLoadSettings">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@@ -81,12 +88,22 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Store calib. and hw settings in selected profile</string> <string>Load settings from profile</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" colspan="5"> <item row="0" column="3">
<widget class="QComboBox" name="profile_CB"/> <spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</item> </item>
+4 -17
View File
@@ -29,6 +29,7 @@
constexpr char FIM_HATSMODE[] {"Hats Mode"}; constexpr char FIM_HATSMODE[] {"Hats Mode"};
constexpr char FIM_STICKMODE[] {"Stick Mode"}; constexpr char FIM_STICKMODE[] {"Stick Mode"};
constexpr char FIM_TEMPLATESETUP[] {"Template Setup"}; constexpr char FIM_TEMPLATESETUP[] {"Template Setup"};
constexpr char FIM_BACKLIGHTMODE[] {"Backlight Mode"};
GeneralSetupPanel::GeneralSetupPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware): GeneralSetupPanel::GeneralSetupPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
GeneralPanel(parent, generalSettings, firmware), GeneralPanel(parent, generalSettings, firmware),
@@ -46,6 +47,7 @@ ui(new Ui::GeneralSetup)
Boards::isAir(board) ? GeneralSettings::RadioTypeContextAir : Boards::isAir(board) ? GeneralSettings::RadioTypeContextAir :
GeneralSettings::RadioTypeContextSurface), GeneralSettings::RadioTypeContextSurface),
FIM_TEMPLATESETUP); FIM_TEMPLATESETUP);
panelFilteredModels->registerItemModel(new FilteredItemModel(GeneralSettings::backlightModeItemModel()), FIM_BACKLIGHTMODE);
QLabel *pmsl[] = {ui->ro_label, ui->ro1_label, ui->ro2_label, ui->ro3_label, ui->ro4_label, ui->ro5_label, ui->ro6_label, ui->ro7_label, ui->ro8_label, NULL}; QLabel *pmsl[] = {ui->ro_label, ui->ro1_label, ui->ro2_label, ui->ro3_label, ui->ro4_label, ui->ro5_label, ui->ro6_label, ui->ro7_label, ui->ro8_label, NULL};
QSlider *tpmsld[] = {ui->chkSA, ui->chkSB, ui->chkSC, ui->chkSD, ui->chkSE, ui->chkSF, ui->chkSG, ui->chkSH, NULL}; QSlider *tpmsld[] = {ui->chkSA, ui->chkSB, ui->chkSC, ui->chkSD, ui->chkSE, ui->chkSF, ui->chkSG, ui->chkSH, NULL};
@@ -91,7 +93,8 @@ ui(new Ui::GeneralSetup)
lock = true; lock = true;
populateBacklightCB(); ui->backlightswCB->setModel(panelFilteredModels->getItemModel(FIM_BACKLIGHTMODE));
ui->backlightswCB->setCurrentIndex(ui->backlightswCB->findData(generalSettings.backlightMode));
if (!firmware->getCapability(MultiLangVoice)) { if (!firmware->getCapability(MultiLangVoice)) {
ui->VoiceLang_label->hide(); ui->VoiceLang_label->hide();
@@ -379,22 +382,6 @@ void GeneralSetupPanel::on_timezoneLE_textEdited(const QString &text)
} }
} }
void GeneralSetupPanel::populateBacklightCB()
{
QComboBox * b = ui->backlightswCB;
const QStringList strings = { tr("OFF"), tr("Keys"), tr("Controls"), tr("Keys + Controls"), tr("ON") };
b->clear();
int startValue = (Boards::getCapability(firmware->getBoard(), Board::LcdDepth) >= 8) ? 1 : 0;
for (int i = startValue; i < strings.size(); i++) {
b->addItem(strings[i], 0);
if (generalSettings.backlightMode == i) {
b->setCurrentIndex(b->count() - 1);
}
}
}
void GeneralSetupPanel::populateVoiceLangCB() void GeneralSetupPanel::populateVoiceLangCB()
{ {
QComboBox * b = ui->voiceLang_CB; QComboBox * b = ui->voiceLang_CB;
-1
View File
@@ -111,7 +111,6 @@ class GeneralSetupPanel : public GeneralPanel
void showLabelSelectOptions(); void showLabelSelectOptions();
void setValues(); void setValues();
void populateBacklightCB();
void populateVoiceLangCB(); void populateVoiceLangCB();
void updateVarioPitchRange(); void updateVarioPitchRange();
}; };
+1
View File
@@ -142,6 +142,7 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
if (count > 0) { if (count > 0) {
addLabel(""); addLabel("");
addLabel(tr("Name")); addLabel(tr("Name"));
addLabel(tr("Invert"));
addParams(); addParams();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
addStick(i); addStick(i);
-6
View File
@@ -329,12 +329,6 @@ bool Profile::existsOnDisk()
return m_settings.contains(settingsPath() % "Name"); return m_settings.contains(settingsPath() % "Name");
} }
void Profile::resetFwVariables()
{
for (const QString & name : fwVarsList())
CompStoreObj::resetProperty(this, name);
}
// ** ComponentAssetData class******************** // ** ComponentAssetData class********************
ComponentAssetData::ComponentAssetData() : CompStoreObj(), index(-1) ComponentAssetData::ComponentAssetData() : CompStoreObj(), index(-1)
+3 -29
View File
@@ -471,7 +471,6 @@ class Profile: public CompStoreObj
public slots: public slots:
bool existsOnDisk(); bool existsOnDisk();
void resetFwVariables();
protected: protected:
explicit Profile(); explicit Profile();
@@ -506,38 +505,13 @@ class Profile: public CompStoreObj
PROPERTY(bool, telemSimResetRssiOnStop, false) PROPERTY(bool, telemSimResetRssiOnStop, false)
PROPERTY(QColor, radioSimCaseColor, QColor(Qt::black)) PROPERTY(QColor, radioSimCaseColor, QColor(Qt::black))
// Firmware Variables // General settings
PROPERTYSTR2(beeper, "Beeper") PROPERTYQBA(generalSettings)
PROPERTYSTR2(countryCode, "countryCode") PROPERTYSTR2(timeStamp, "TimeStamp")
PROPERTYSTR2(display, "Display")
PROPERTYSTR2(haptic, "Haptic")
PROPERTYSTR2(speaker, "Speaker")
PROPERTYSTR2(stickPotCalib, "StickPotCalib")
PROPERTYSTR2(timeStamp, "TimeStamp")
PROPERTYSTR2(trainerCalib, "TrainerCalib")
PROPERTYSTR2(controlTypes, "ControlTypes")
PROPERTYSTR2(controlNames, "ControlNames")
PROPERTY4(int, gsStickMode, "GSStickMode", 0)
PROPERTY4(int, ppmMultiplier, "PPM_Multiplier", 0)
PROPERTY4(int, vBatWarn, "vBatWarn", 0) // not a typo.. vBat vs. Vbat
PROPERTY4(int, vBatMin, "VbatMin", 0)
PROPERTY4(int, vBatMax, "VbatMax", 0)
PROPERTY4(int, txCurrentCalibration, "currentCalib", 0)
PROPERTY4(int, txVoltageCalibration, "VbatCalib", 0)
PROPERTYSTRD(jsName, "") PROPERTYSTRD(jsName, "")
int index; int index;
static const QStringList fwVarsList() //! for resetFwVariables()... TODO: make this go away
{
static const QStringList list({
"Beeper", "countryCode", "Display", "Haptic", "Speaker", "TimeStamp", "TrainerCalib", "StickPotCalib",
"ControlTypes", "ControlNames", "GSStickMode", "PPM_Multiplier", "vBatWarn", "VbatMin", "VbatMax", "currentCalib", "VbatCalib"
});
return list;
}
}; };
//! \brief ComponentAssetData class stores properties related to each updateable component. //! \brief ComponentAssetData class stores properties related to each updateable component.