feat(radio,cpn): Updates for new joystick system (#3400)

* Reduce RAM usage for advanced joystick system on radio:
- Don't allocate memory blocks unless joystick mode is being used.
Support multiple radio joystick configurations in Companion:
- Save configured joystick settings by joystick name in Companion settings.
- Save last joystick name used in each profile.
- Reload joystick settings by name when profile is changed.

* Only show configuration for used axes and buttons in Companion.
Send actual number of configured joystick buttons from radio in USB packet.

* Fix issue where USB joystick not recognised if no buttons configured.

* Fix compiler warnings.

* Remove debugging.

* Fix crash in Companion.

* Change channel 8 to type 'dial', workaround for Linux mapping issue.

---------

Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
This commit is contained in:
philmoz
2023-04-21 14:27:41 +10:00
committed by GitHub
co-authored by Phil Mitchell
parent 62a40f1c47
commit e1fe7fce89
10 changed files with 537 additions and 294 deletions
+105 -2
View File
@@ -63,6 +63,7 @@
#define MAX_JS_BUTTONS 32
#define MAX_COMPONENTS 10
#define MAX_COMPONENT_ASSETS 5
#define MAX_NAMED_JOYSTICKS 10
// It important that these function names are consistent everywhere.
#define PROP_FSIG_INIT_IMPL _init()
@@ -331,12 +332,22 @@ class JStickData: public CompStoreObj
public slots:
bool existsOnDisk();
public:
void clear() {
stick_axe(-1);
stick_med(-32768);
stick_max(32767);
stick_med(0);
stick_inv(0);
}
protected:
explicit JStickData();
void setIndex(int idx) { index = idx; }
inline QString propertyGroup() const override { return QStringLiteral("JsCalibration"); }
inline QString settingsPath() const override { return QString("%1/%2/").arg(propertyGroup()).arg(index); }
friend class AppData;
friend class NamedJSData;
private:
PROPERTY(int, stick_axe, -1)
@@ -348,22 +359,100 @@ class JStickData: public CompStoreObj
int index;
};
//! \brief JButtonData class stores properties related to each joystick button (button number).
class JButtonData: public CompStoreObj
{
Q_OBJECT
public slots:
bool existsOnDisk();
public:
void clear() {
button_idx(-1);
}
protected:
explicit JButtonData();
void setIndex(int idx) { index = idx; }
inline QString propertyGroup() const override { return QStringLiteral("JsButton"); }
inline QString settingsPath() const override { return QString("%1/%2/").arg(propertyGroup()).arg(index); }
friend class AppData;
friend class NamedJSData;
private:
PROPERTY(int, button_idx, -1)
PROPERTY(int, button_inv, 0)
int index;
};
//! \brief NamedJStickData class stores properties related to each joystick axis (calibration/assignment/direction).
class NamedJStickData: public CompStoreObj
{
Q_OBJECT
public slots:
bool existsOnDisk();
protected:
explicit NamedJStickData();
void setIndex(int idx, int nmIdx) { index = idx; namedIdx = nmIdx; }
inline QString propertyGroup() const override { return QStringLiteral("NamedJSData/%1").arg(namedIdx); }
inline QString settingsPath() const override { return QString("%1/JsCalibration/%2/").arg(propertyGroup()).arg(index); }
friend class AppData;
friend class NamedJSData;
private:
PROPERTY(int, stick_axe, -1)
PROPERTY(int, stick_min, -32768)
PROPERTY(int, stick_med, 0)
PROPERTY(int, stick_max, 32767)
PROPERTY(int, stick_inv, 0)
int namedIdx;
int index;
};
//! \brief NamedJButtonData class stores properties related to each joystick button (button number).
class NamedJButtonData: public CompStoreObj
{
Q_OBJECT
public slots:
bool existsOnDisk();
protected:
explicit NamedJButtonData();
void setIndex(int idx, int nmIdx) { index = idx; namedIdx = nmIdx; }
inline QString propertyGroup() const override { return QStringLiteral("NamedJSData/%1").arg(namedIdx); }
inline QString settingsPath() const override { return QString("%1/JsButton/%2/").arg(propertyGroup()).arg(index); }
friend class AppData;
friend class NamedJSData;
private:
PROPERTY(int, button_idx, -1)
int namedIdx;
int index;
};
class NamedJSData: public CompStoreObj
{
Q_OBJECT
public slots:
bool existsOnDisk();
protected:
explicit NamedJSData();
void setIndex(int idx) { index = idx; }
inline QString propertyGroup() const override { return QStringLiteral("NamedJSData"); }
inline QString settingsPath() const override { return QString("%1/%2/").arg(propertyGroup()).arg(index); }
friend class AppData;
public:
NamedJStickData joystick[MAX_JS_AXES];
NamedJButtonData jsButton[MAX_JS_BUTTONS];
private:
PROPERTYSTRD(jsName, "")
PROPERTY(unsigned int, jsLastUsed, 0)
int index;
};
@@ -432,6 +521,8 @@ class Profile: public CompStoreObj
PROPERTY4(int, txCurrentCalibration, "currentCalib", 0)
PROPERTY4(int, txVoltageCalibration, "VbatCalib", 0)
PROPERTYSTRD(jsName, "")
int index;
static const QStringList fwVarsList() //! for resetFwVariables()... TODO: make this go away
@@ -615,9 +706,19 @@ class AppData: public CompStoreObj
Profile profile[MAX_PROFILES];
JStickData joystick[MAX_JS_AXES];
JButtonData jsButton[MAX_JS_BUTTONS];
NamedJSData namedJS[MAX_NAMED_JOYSTICKS];
FwRevision fwRev;
ComponentData component[MAX_COMPONENTS];
void clearJSData() {
for (int i = 0; i < MAX_JS_AXES; i += 1)
joystick[i].clear();
for (int i = 0; i < MAX_JS_BUTTONS; i += 1)
jsButton[i].clear();
}
void saveNamedJS();
void loadNamedJS();
signals:
void currentProfileChanged();
@@ -625,6 +726,9 @@ class AppData: public CompStoreObj
inline QString propertyGroup() const override { return QStringLiteral("General"); }
inline QString settingsPath() const override { return QString(); }
void saveNamedJS(int i);
void loadNamedJS(int i);
private:
PROPERTY_META(int, sessionId, 0) // currently active radio profile ID, NOT saved to persistent storage -- Initialize before profileId!
@@ -679,7 +783,6 @@ class AppData: public CompStoreObj
PROPERTY4(int, embedSplashes, "embedded_splashes", 0)
PROPERTY4(int, fwServerFails, "fwserver", 0)
PROPERTY4(int, iconSize, "icon_size", 2)
PROPERTY4(int, jsCtrl, "js_ctrl", 0)
PROPERTY4(int, historySize, "history_size", 10)
PROPERTY (int, generalEditTab, 0)
PROPERTY (int, theme, 1)