fix(cpn): profile radio settings management and use (#6654)
This commit is contained in:
@@ -112,6 +112,7 @@ void YamlStickConfig::copy(GeneralSettings::InputConfig* rhs) const
|
||||
{
|
||||
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Inputs); i++) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,6 +270,8 @@ class Firmware
|
||||
|
||||
virtual bool isAvailable(PulsesProtocol proto, int port=0) = 0;
|
||||
|
||||
virtual QString getLanguage() const = 0;
|
||||
|
||||
const int getFlashSize();
|
||||
|
||||
static Firmware * getFirmwareForId(const QString & id);
|
||||
|
||||
@@ -196,31 +196,9 @@ void GeneralSettings::clear()
|
||||
|
||||
void GeneralSettings::init()
|
||||
{
|
||||
Firmware * firmware = Firmware::getCurrentVariant();
|
||||
Board::Type board = firmware->getBoard();
|
||||
|
||||
// vBatWarn is voltage in 100mV, vBatMin is in 100mV but with -9V offset, vBatMax has a -12V offset
|
||||
Board::Type board = Firmware::getCurrentVariant()->getBoard();
|
||||
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))
|
||||
strcpy(bluetoothName, "t16");
|
||||
else if (IS_FLYSKY_NV14(board))
|
||||
@@ -240,110 +218,29 @@ void GeneralSettings::init()
|
||||
else if (IS_TARANIS_X9E(board) || IS_TARANIS_SMALL(board))
|
||||
strcpy(bluetoothName, "taranis");
|
||||
|
||||
ttsLanguage[0] = 'e';
|
||||
ttsLanguage[1] = 'n';
|
||||
contrast = IS_TARANIS(board) ? 25 : 0;
|
||||
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();
|
||||
stickMode = g.profile[g.sessionId()].defaultMode();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
backgroundVolume = 1;
|
||||
speakerVolume = 12;
|
||||
wavVolume = 2;
|
||||
|
||||
hatsMode = HATSMODE_SWITCHABLE;
|
||||
inactivityTimer = 10;
|
||||
internalModule = g.profile[g.sessionId()].defaultInternalModule();
|
||||
|
||||
if (IS_FLYSKY_NV14(board) || IS_FAMILY_PL18(board))
|
||||
stickDeadZone = 2;
|
||||
QString lang = getCurrentFirmware()->getLanguage();
|
||||
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)
|
||||
@@ -1019,3 +916,47 @@ void GeneralSettings::switchConfigClear()
|
||||
for (int i = 0; i < CPN_MAX_SWITCHES; i++)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ constexpr char AIM_GS_UARTSAMPLEMODE[] {"gs.uartsamplemode"};
|
||||
constexpr char AIM_GS_HATSMODE[] {"gs.hatsmode"};
|
||||
constexpr char AIM_GS_STICKMODE[] {"gs.stickmode"};
|
||||
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_SRC[] {"trainermix.src"};
|
||||
@@ -215,6 +216,15 @@ class GeneralSettings {
|
||||
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(); }
|
||||
void clear();
|
||||
void init();
|
||||
@@ -399,6 +409,7 @@ class GeneralSettings {
|
||||
bool isSwitchFlex(int index) const;
|
||||
bool isSwitchFunc(int index) const;
|
||||
bool unassignedInputFlexSwitches() const;
|
||||
static bool isBacklightModeAvailable(int index);
|
||||
|
||||
QString antennaModeToString() const;
|
||||
QString bluetoothModeToString() const;
|
||||
@@ -408,6 +419,7 @@ class GeneralSettings {
|
||||
QString hatsModeToString() const;
|
||||
QString stickModeToString() const;
|
||||
QString templateSetupToString() const;
|
||||
QString backlightModeToString() const;
|
||||
|
||||
static QString antennaModeToString(int value);
|
||||
static QString bluetoothModeToString(int value);
|
||||
@@ -419,6 +431,7 @@ class GeneralSettings {
|
||||
static QString hatsModeToString(int value);
|
||||
static QString stickModeToString(int value);
|
||||
static QString templateSetupToString(int value, bool isBoardAir);
|
||||
static QString backlightModeToString(int value);
|
||||
|
||||
static AbstractStaticItemModel * antennaModeItemModel(bool model_setup = false);
|
||||
static AbstractStaticItemModel * bluetoothModeItemModel();
|
||||
@@ -429,6 +442,7 @@ class GeneralSettings {
|
||||
static AbstractStaticItemModel * hatsModeItemModel(bool radio_setup = true);
|
||||
static AbstractStaticItemModel * stickModeItemModel();
|
||||
static AbstractStaticItemModel * templateSetupItemModel();
|
||||
static AbstractStaticItemModel * backlightModeItemModel();
|
||||
|
||||
void validateFlexSwitches();
|
||||
};
|
||||
|
||||
@@ -391,6 +391,12 @@ QString OpenTxFirmware::getReleaseNotesUrl()
|
||||
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
|
||||
// NOTE: "recognized" build options are defined in /radio/util/fwoptions.py
|
||||
|
||||
|
||||
@@ -91,6 +91,8 @@ class OpenTxFirmware: public Firmware
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual QString getLanguage() const override;
|
||||
|
||||
protected:
|
||||
|
||||
QString getFirmwareBaseUrl() { return ""; } // depreciated;
|
||||
|
||||
Reference in New Issue
Block a user