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

feat(cpn): add support for surface radios inc Radiomaster MT12 #5381

Merged
merged 36 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5c8bb8e
feat(cpn): add surface radios inc Radiomaster MT12
elecpower Aug 4, 2024
e7dee5c
add all modes for surface albeit they are the same mapping
elecpower Aug 5, 2024
b8b19dd
Load keys hwdef and add get function
elecpower Aug 5, 2024
f22a732
Sim radio output gv section FM or DM headings
elecpower Aug 5, 2024
89206cc
Simulator map surface controls gui widgets and data indexes
elecpower Aug 8, 2024
aeb575d
Fix drive modes T3 and T4 position to match radio
elecpower Aug 8, 2024
3214984
Improve trim names in lists and fix trim order in throttle trim list
elecpower Aug 8, 2024
2d9619d
Add keep in sync with companion note
elecpower Aug 8, 2024
ebd2ab3
Add missing copyright and change header guards to pragma and generic poc
elecpower Aug 9, 2024
756ce50
Generic sim layout reduce button size
elecpower Aug 9, 2024
5dc719f
Sim add push button support
elecpower Aug 9, 2024
f914528
Blink sim push buttons on click or key press
elecpower Aug 10, 2024
f4066c8
Increase push button highlight time and housekeeping
elecpower Aug 11, 2024
db5ba7a
Fix compile
elecpower Aug 11, 2024
f8cc3f0
Code clean up
elecpower Aug 11, 2024
7d9aea4
New addMouseActions and options for which side buttons and fix their …
elecpower Sep 14, 2024
46c9b5d
Fix surface trim labels
elecpower Sep 14, 2024
2d9b767
Fix hide neg func switch groups for radios that do not support
elecpower Sep 14, 2024
ff02454
Fix hide CYC sources when noheli option set
elecpower Sep 14, 2024
93157e2
Fix abbreviate telemetry switch to tele for consistency
elecpower Sep 16, 2024
a38cca3
Fix trainer sources
elecpower Sep 16, 2024
ccdd70d
Fix add 2 flex switches
elecpower Sep 16, 2024
50ebb6c
Fix add AUX1 to hardware
elecpower Sep 16, 2024
2fe5f22
Move b&w 128 invert lcd from general to hardware setup to mirror firm…
elecpower Sep 17, 2024
0bda50d
Fix surface throttle source TH
elecpower Sep 17, 2024
0cb93f2
Fix throttle source list only display available items and add custom …
elecpower Sep 17, 2024
2794b38
Fix throttle source
elecpower Sep 17, 2024
15fd9a2
Add trim prefix to trim switches
elecpower Sep 17, 2024
09aee2f
Fix yaml decode of ST source
elecpower Sep 17, 2024
5471f4c
Simulator window title flight or Drive mode
elecpower Sep 18, 2024
d671d69
Simulator housekeeping
elecpower Sep 18, 2024
d20252c
Simulator re-orientate throttle from horizontal to vertical
elecpower Sep 20, 2024
0eb1d3d
Workaround for unused axis % labels
elecpower Sep 21, 2024
cd28489
Fix generic sim button text clipping
elecpower Sep 22, 2024
3c5f583
Fix from rebase
elecpower Sep 24, 2024
1e2c405
chore: build mt12 simulator
pfeerick Sep 26, 2024
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
44 changes: 36 additions & 8 deletions companion/src/apppreferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,27 @@
#include "joystickdialog.h"
#endif
#include "moduledata.h"
#include "compounditemmodels.h"
#include "filtereditemmodels.h"
#include "updates/updatefactories.h"
#include "updates/updateoptionsdialog.h"

#include <QAbstractItemModel>
constexpr char FIM_TEMPLATESETUP[] {"Template Setup"};

AppPreferencesDialog::AppPreferencesDialog(QWidget * parent, UpdateFactories * factories) :
QDialog(parent),
ui(new Ui::AppPreferencesDialog),
updateLock(false),
mainWinHasDirtyChild(false),
factories(factories)
factories(factories),
panelItemModels(nullptr)
{
ui->setupUi(this);
setWindowIcon(CompanionIcon("apppreferences.png"));
ui->tabWidget->setCurrentIndex(0);

panelItemModels = new FilteredItemModelFactory();
panelItemModels->registerItemModel(new FilteredItemModel(GeneralSettings::templateSetupItemModel()), FIM_TEMPLATESETUP);

initSettings();
connect(ui->boardCB, SIGNAL(currentIndexChanged(int)), this, SLOT(onBaseFirmwareChanged()));
connect(ui->opt_appDebugLog, &QCheckBox::toggled, this, &AppPreferencesDialog::toggleAppLogSettings);
Expand All @@ -65,6 +69,7 @@ AppPreferencesDialog::AppPreferencesDialog(QWidget * parent, UpdateFactories * f
AppPreferencesDialog::~AppPreferencesDialog()
{
delete ui;
delete panelItemModels;
}

void AppPreferencesDialog::setMainWinHasDirtyChild(bool value)
Expand Down Expand Up @@ -156,8 +161,8 @@ void AppPreferencesDialog::accept()

profile.defaultInternalModule(ui->defaultInternalModuleCB->currentData().toInt());
profile.externalModuleSize(ui->externalModuleSizeCB->currentData().toInt());
profile.channelOrder(ui->channelorderCB->currentIndex());
profile.defaultMode(ui->stickmodeCB->currentIndex());
profile.channelOrder(ui->channelorderCB->currentData().toInt());
profile.defaultMode(ui->stickmodeCB->currentData().toInt());
profile.burnFirmware(ui->burnFirmware->isChecked());
profile.sdPath(ui->sdPath->text());
profile.pBackupDir(ui->profilebackupPath->text());
Expand Down Expand Up @@ -305,8 +310,12 @@ void AppPreferencesDialog::initSettings()
ui->defaultInternalModuleCB->setCurrentIndex(ui->defaultInternalModuleCB->findData(profile.defaultInternalModule()));
ui->externalModuleSizeCB->setModel(Boards::externalModuleSizeItemModel());
ui->externalModuleSizeCB->setCurrentIndex(ui->externalModuleSizeCB->findData(profile.externalModuleSize()));
ui->channelorderCB->setCurrentIndex(profile.channelOrder());
ui->stickmodeCB->setCurrentIndex(profile.defaultMode());
panelItemModels->getItemModel(FIM_TEMPLATESETUP)->setFilterFlags(Boards::isAir() ? GeneralSettings::RadioTypeContextAir :
GeneralSettings::RadioTypeContextSurface);
ui->channelorderCB->setModel(panelItemModels->getItemModel(FIM_TEMPLATESETUP));
ui->channelorderCB->setCurrentIndex(ui->channelorderCB->findData(profile.channelOrder()));
ui->stickmodeCB->setModel(GeneralSettings::stickModeItemModel());
ui->stickmodeCB->setCurrentIndex(ui->stickmodeCB->findData(profile.defaultMode()));
ui->sdPath->setText(profile.sdPath());
if (!profile.pBackupDir().isEmpty()) {
if (QDir(profile.pBackupDir()).exists()) {
Expand All @@ -321,6 +330,11 @@ void AppPreferencesDialog::initSettings()
ui->pbackupEnable->setDisabled(true);
}

if (Boards::isSurface()) {
ui->stickmodeLabel->hide();
ui->stickmodeCB->hide();
}

ui->profileNameLE->setText(profile.name());

QString hwSettings;
Expand Down Expand Up @@ -649,7 +663,8 @@ bool AppPreferencesDialog::displayImage(const QString & fileName)
return false;

ui->imageLabel->setPixmap(makePixMap(image));
ui->imageLabel->setFixedSize(getCurrentFirmware()->getCapability(LcdWidth), getCurrentFirmware()->getCapability(LcdHeight));
ui->imageLabel->setFixedSize(Boards::getCapability(getCurrentBoard(), Board::LcdWidth),
Boards::getCapability(getCurrentBoard(), Board::LcdHeight));
return true;
}

Expand Down Expand Up @@ -690,6 +705,19 @@ void AppPreferencesDialog::onBaseFirmwareChanged()
profile.externalModuleSize(Boards::getDefaultExternalModuleSize(newfw->getBoard()));
ui->externalModuleSizeCB->setModel(Boards::externalModuleSizeItemModel());
ui->externalModuleSizeCB->setCurrentIndex(ui->externalModuleSizeCB->findData(profile.externalModuleSize()));

if (Boards::isSurface()) {
profile.defaultMode(1);
ui->stickmodeLabel->hide();
ui->stickmodeCB->hide();
profile.channelOrder(0);
}

ui->stickmodeCB->setCurrentIndex(ui->stickmodeCB->findData(profile.defaultMode()));
panelItemModels->getItemModel(FIM_TEMPLATESETUP)->setFilterFlags(Boards::isAir() ? GeneralSettings::RadioTypeContextAir :
GeneralSettings::RadioTypeContextSurface);
ui->channelorderCB->setCurrentIndex(ui->channelorderCB->findData(profile.channelOrder()));

}

Firmware *AppPreferencesDialog::getBaseFirmware() const
Expand Down
4 changes: 4 additions & 0 deletions companion/src/apppreferencesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <QCheckBox>
#include <QComboBox>

class FilteredItemModelFactory;

namespace Ui {
class AppPreferencesDialog;
}
Expand Down Expand Up @@ -95,6 +97,8 @@ class AppPreferencesDialog : public QDialog
QComboBox *cboReleaseChannel[MAX_COMPONENTS];
QPushButton *btnComponentOptions[MAX_COMPONENTS];

FilteredItemModelFactory *panelItemModels;

void loadUpdatesTab();

};
4 changes: 2 additions & 2 deletions companion/src/apppreferencesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ Mode 4:
</widget>
</item>
<item row="15" column="0">
<widget class="QLabel" name="label_14">
<widget class="QLabel" name="stickmodeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -676,7 +676,7 @@ Mode 4:
</widget>
</item>
<item row="16" column="0">
<widget class="QLabel" name="label_13">
<widget class="QLabel" name="channelorderLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand Down
4 changes: 2 additions & 2 deletions companion/src/datamodels/compounditemmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ ThrottleSourceItemModel::ThrottleSourceItemModel(const GeneralSettings * const g
if (!modelData)
return;

setUpdateMask(IMUE_Timers | IMUE_Inputs | IMUE_TeleSensors);
setUpdateMask(IMUE_Channels);

for (int i = 0; i < modelData->thrTraceSrcCount(); i++) {
QStandardItem * modelItem = new QStandardItem();
Expand All @@ -407,7 +407,7 @@ ThrottleSourceItemModel::ThrottleSourceItemModel(const GeneralSettings * const g

void ThrottleSourceItemModel::setDynamicItemData(QStandardItem * item, const int value) const
{
item->setText(modelData->thrTraceSrcToString(value));
item->setText(modelData->thrTraceSrcToString(generalSettings, value));
item->setData(modelData->isThrTraceSrcAvailable(generalSettings, value), IMDR_Available);
}

Expand Down
87 changes: 81 additions & 6 deletions companion/src/firmwares/boardjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ BoardJson::BoardJson(Board::Type board, QString hwdefn) :
m_inputs(new InputsTable),
m_switches(new SwitchesTable),
m_trims(new TrimsTable),
m_keys(new KeysTable),
m_inputCnt({0, 0, 0, 0, 0, 0, 0, 0, 0}),
m_switchCnt({0, 0, 0})
{
Expand All @@ -79,10 +80,12 @@ BoardJson::~BoardJson()
delete m_inputs;
delete m_switches;
delete m_trims;
delete m_keys;
}

// static
void BoardJson::afterLoadFixups(Board::Type board, InputsTable * inputs, SwitchesTable * switches)
void BoardJson::afterLoadFixups(Board::Type board, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims)
{
// TODO json files do not contain gyro defs
// Radio cmake directive IMU is currently used
Expand Down Expand Up @@ -114,8 +117,8 @@ void BoardJson::afterLoadFixups(Board::Type board, InputsTable * inputs, Switche
}
}

// Flex switches are not listed in json file
int count = IS_RADIOMASTER_TX16S(board) ? 2 : 0;
// Flex switches are not listed in json file for these radios
int count = IS_RADIOMASTER_TX16S(board) || IS_RADIOMASTER_MT12(board) ? 2 : 0;

for (int i = 1; i <= count; i++) {
QString tag = QString("FL%1").arg(i);
Expand Down Expand Up @@ -164,6 +167,9 @@ const int BoardJson::getCapability(const Board::Capability capability) const
case Board::InputSwitches:
return m_inputCnt.switches;

case Board::Keys:
return m_keys->size();

case Board::MultiposPots:
// assumes every input has potential to be one
// index used for mapping 6 pos switches back to input
Expand Down Expand Up @@ -332,6 +338,14 @@ const int BoardJson::getInputSliderIndex(int index)
return -1;
}

const int BoardJson::getInputThrottleIndex()
{
if (getCapability(Board::Sticks) > 0)
return getInputTagOffset(m_inputs, Boards::getCapability(m_board, Board::Air) ? "RV" : "TH");

return -1;
}

const int BoardJson::getInputTypeOffset(Board::AnalogInputType type)
{
return getInputTypeOffset(m_inputs, type);
Expand Down Expand Up @@ -371,6 +385,42 @@ Board::InputInfo BoardJson::getInputInfo(const InputsTable * inputs, int index)
return info;
}

const int BoardJson::getKeyIndex(const QString key) const
{
return getKeyIndex(m_keys, key);
}

// static
int BoardJson::getKeyIndex(const KeysTable * keys, QString key)
{
for (int i = 0; i < (int)keys->size(); i++) {
if (keys->at(i).key.c_str() == key)
return i;
}

return -1;
}

const Board::KeyInfo BoardJson::getKeyInfo(int index) const
{
return getKeyInfo(m_keys, index);
}

// static
Board::KeyInfo BoardJson::getKeyInfo(const KeysTable * keys, int index)
{
Board::KeyInfo info;

if (index >= 0 && index < (int)keys->size()) {
KeyDefn defn = keys->at(index);
info.name = defn.name;
info.key = defn.key;
info.label = defn.label;
}

return info;
}

// static
int BoardJson::getNumericSuffix(const std::string str)
{
Expand Down Expand Up @@ -771,10 +821,10 @@ bool BoardJson::loadDefinition()
if (m_board == Board::BOARD_UNKNOWN)
return true;

if (!loadFile(m_board, m_hwdefn, m_inputs, m_switches, m_trims))
if (!loadFile(m_board, m_hwdefn, m_inputs, m_switches, m_keys, m_trims))
return false;

afterLoadFixups(m_board, m_inputs, m_switches);
afterLoadFixups(m_board, m_inputs, m_switches, m_keys, m_trims);

setInputCounts(m_inputs, m_inputCnt);
setSwitchCounts(m_switches, m_switchCnt);
Expand All @@ -795,6 +845,7 @@ bool BoardJson::loadDefinition()
"flex inputs:" << getCapability(Board::FlexInputs) <<
"input switches:" << getCapability(Board::InputSwitches) <<
"trims:" << getCapability(Board::NumTrims) <<
"keys:" << getCapability(Board::Keys) <<
"std switches:" << getCapability(Board::StandardSwitches) <<
"flex switches:" << getCapability(Board::FlexSwitches) <<
"func switches:" << getCapability(Board::FunctionSwitches) <<
Expand All @@ -805,7 +856,8 @@ bool BoardJson::loadDefinition()
}

// static
bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches, TrimsTable * trims)
bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims)
{
if (board == Board::BOARD_UNKNOWN) {
return false;
Expand Down Expand Up @@ -952,6 +1004,29 @@ bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs
}
}

if (obj.value("keys").isArray()) {
const QJsonArray &kys = obj.value("keys").toArray();

for (const QJsonValue &key : kys)
{
if (key.isObject()) {
const QJsonObject &o = key.toObject();
KeyDefn k;

if (!o.value("name").isUndefined()) {
k.name = o.value("name").toString().toStdString();
k.key = o.value("key").toString().toStdString();
k.label = o.value("label").toString().toStdString();
k.tag = k.name;
}

keys->insert(keys->end(), k);

// qDebug() << "name:" << k.name.c_str() << "key:" << k.key.c_str() << "label:" << k.label.c_str();
}
}
}

if (obj.value("trims").isArray()) {
const QJsonArray &trms = obj.value("trims").toArray();

Expand Down
27 changes: 25 additions & 2 deletions companion/src/firmwares/boardjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ class BoardJson

typedef std::vector<SwitchDefn> SwitchesTable;

struct KeyDefn {
std::string tag = "";
std::string name = "";
std::string key = "";
std::string label = "";
Board::LookupValueType cfgYaml = Board::LVT_TAG;
Board::LookupValueType refYaml = Board::LVT_NAME;

KeyDefn() = default;
};

typedef std::vector<KeyDefn> KeysTable;

struct TrimDefn {
std::string tag = "";
std::string name = "";
Expand Down Expand Up @@ -106,6 +119,7 @@ class BoardJson
const int getInputSliderIndex(int index);
const QString getInputTag(int index) const;
const int getInputTagOffset(QString tag);
const int getInputThrottleIndex();
const int getInputTypeOffset(Board::AnalogInputType type);
const int getInputYamlIndex(const QString val, YamlLookupType ylt) const;
const QString getInputYamlName(int index, YamlLookupType ylt) const;
Expand All @@ -119,6 +133,9 @@ class BoardJson
const bool isInputStick(int index) const;
const bool isInputSwitch(int index) const;

const Board::KeyInfo getKeyInfo(int index) const;
const int getKeyIndex(const QString key) const;

const int getSwitchIndex(const QString val, Board::LookupValueType lvt) const;
const Board::SwitchInfo getSwitchInfo(int index) const;
const QString getSwitchName(int index) const;
Expand All @@ -144,6 +161,7 @@ class BoardJson
InputsTable *m_inputs;
SwitchesTable *m_switches;
TrimsTable *m_trims;
KeysTable *m_keys;

struct InputCounts {
unsigned int flexGyroAxes;
Expand All @@ -167,8 +185,10 @@ class BoardJson

SwitchCounts m_switchCnt;

static bool loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches, TrimsTable * trims);
static void afterLoadFixups(Board::Type board, InputsTable * inputs, SwitchesTable * switches);
static bool loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims);
static void afterLoadFixups(Board::Type board, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims);

static int getInputsCalibrated(const InputsTable * inputs);

Expand All @@ -179,6 +199,9 @@ class BoardJson
static int getInputTagOffset(const InputsTable * inputs, QString tag);
static int getInputTypeOffset(const InputsTable * inputs, Board::AnalogInputType type);

static int getKeyIndex(const KeysTable * keys, QString key);
static Board::KeyInfo getKeyInfo(const KeysTable * keys, int index);

static int getSwitchIndex(const SwitchesTable * switches, QString val, Board::LookupValueType lvt);
static Board::SwitchInfo getSwitchInfo(const SwitchesTable * switches, int index);
static QString getSwitchName(const SwitchesTable * switches, int index);
Expand Down
Loading
Loading