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:
@@ -266,6 +266,36 @@ bool JButtonData::existsOnDisk()
|
||||
return (m_settings.value(settingsPath() % button_idx_key(), -1).toInt() > -1);
|
||||
}
|
||||
|
||||
NamedJStickData::NamedJStickData() : CompStoreObj(), index(-1)
|
||||
{
|
||||
CompStoreObj::addObjectMapping(propertyGroup(), this);
|
||||
}
|
||||
|
||||
bool NamedJStickData::existsOnDisk()
|
||||
{
|
||||
return (m_settings.value(settingsPath() % stick_axe_key(), -1).toInt() > -1);
|
||||
}
|
||||
|
||||
NamedJButtonData::NamedJButtonData() : CompStoreObj(), index(-1)
|
||||
{
|
||||
CompStoreObj::addObjectMapping(propertyGroup(), this);
|
||||
}
|
||||
|
||||
bool NamedJButtonData::existsOnDisk()
|
||||
{
|
||||
return (m_settings.value(settingsPath() % button_idx_key(), -1).toInt() > -1);
|
||||
}
|
||||
|
||||
NamedJSData::NamedJSData() : CompStoreObj(), index(-1)
|
||||
{
|
||||
CompStoreObj::addObjectMapping(propertyGroup(), this);
|
||||
}
|
||||
|
||||
bool NamedJSData::existsOnDisk()
|
||||
{
|
||||
return (m_settings.value(settingsPath() % jsName(), -1).toInt() > -1);
|
||||
}
|
||||
|
||||
|
||||
// ** Profile class********************
|
||||
|
||||
@@ -411,6 +441,13 @@ AppData::AppData() :
|
||||
joystick[i].setIndex(i);
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].setIndex(i);
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i++) {
|
||||
namedJS[i].setIndex(i);
|
||||
for (int a = 0; a < MAX_JS_AXES; a += 1)
|
||||
namedJS[i].joystick[a].setIndex(a, i);
|
||||
for (int b = 0; b < MAX_JS_BUTTONS; b += 1)
|
||||
namedJS[i].jsButton[b].setIndex(b, i);
|
||||
}
|
||||
|
||||
// Configure the updates
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
@@ -421,6 +458,74 @@ AppData::AppData() :
|
||||
}
|
||||
}
|
||||
|
||||
void AppData::saveNamedJS(int i)
|
||||
{
|
||||
namedJS[i].jsName(currentProfile().jsName());
|
||||
for (int a = 0; a < MAX_JS_AXES; a += 1) {
|
||||
namedJS[i].joystick[a].stick_axe(joystick[a].stick_axe());
|
||||
namedJS[i].joystick[a].stick_max(joystick[a].stick_max());
|
||||
namedJS[i].joystick[a].stick_med(joystick[a].stick_med());
|
||||
namedJS[i].joystick[a].stick_min(joystick[a].stick_min());
|
||||
namedJS[i].joystick[a].stick_min(joystick[a].stick_min());
|
||||
}
|
||||
for (int b = 0; b < MAX_JS_BUTTONS; b += 1) {
|
||||
namedJS[i].jsButton[b].button_idx(jsButton[b].button_idx());
|
||||
}
|
||||
namedJS[i].jsLastUsed(time(NULL));
|
||||
}
|
||||
|
||||
void AppData::saveNamedJS()
|
||||
{
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i += 1) {
|
||||
if (namedJS[i].jsName() == currentProfile().jsName()) {
|
||||
saveNamedJS(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i += 1) {
|
||||
if (namedJS[i].jsName() == "") {
|
||||
saveNamedJS(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int oldestTime = namedJS[0].jsLastUsed();
|
||||
int oldestN = 0;
|
||||
for (int i = 1; i < MAX_NAMED_JOYSTICKS; i += 1) {
|
||||
if (namedJS[i].jsLastUsed() < oldestTime) {
|
||||
oldestTime = namedJS[i].jsLastUsed();
|
||||
oldestN = i;
|
||||
}
|
||||
}
|
||||
saveNamedJS(oldestN);
|
||||
}
|
||||
|
||||
void AppData::loadNamedJS(int i)
|
||||
{
|
||||
for (int a = 0; a < MAX_JS_AXES; a += 1) {
|
||||
joystick[a].stick_axe(namedJS[i].joystick[a].stick_axe());
|
||||
joystick[a].stick_max(namedJS[i].joystick[a].stick_max());
|
||||
joystick[a].stick_med(namedJS[i].joystick[a].stick_med());
|
||||
joystick[a].stick_min(namedJS[i].joystick[a].stick_min());
|
||||
joystick[a].stick_min(namedJS[i].joystick[a].stick_min());
|
||||
}
|
||||
for (int b = 0; b < MAX_JS_BUTTONS; b += 1) {
|
||||
jsButton[b].button_idx(namedJS[i].jsButton[b].button_idx());
|
||||
}
|
||||
namedJS[i].jsLastUsed(time(NULL));
|
||||
}
|
||||
|
||||
void AppData::loadNamedJS()
|
||||
{
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i += 1) {
|
||||
if (namedJS[i].jsName() == currentProfile().jsName()) {
|
||||
loadNamedJS(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QString fmtHex(quint32 num)
|
||||
{
|
||||
return QString::number(num, 16).toUpper();
|
||||
@@ -452,7 +557,14 @@ void AppData::initAll()
|
||||
joystick[i].init();
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].init();
|
||||
// Initialize the updatess
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i++) {
|
||||
namedJS[i].init();
|
||||
for (int a = 0; a < MAX_JS_AXES; a += 1)
|
||||
namedJS[i].joystick[a].init();
|
||||
for (int b = 0; b < MAX_JS_BUTTONS; b += 1)
|
||||
namedJS[i].jsButton[b].init();
|
||||
}
|
||||
// Initialize the updates
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
component[i].init();
|
||||
for (int j = 0; j < MAX_COMPONENT_ASSETS; j++) {
|
||||
@@ -471,6 +583,13 @@ void AppData::resetAllSettings()
|
||||
joystick[i].resetAll();
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].resetAll();
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i++) {
|
||||
namedJS[i].resetAll();
|
||||
for (int a = 0; a < MAX_JS_AXES; a += 1)
|
||||
namedJS[i].joystick[a].resetAll();
|
||||
for (int b = 0; b < MAX_JS_BUTTONS; b += 1)
|
||||
namedJS[i].jsButton[b].resetAll();
|
||||
}
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
component[i].resetAll();
|
||||
for (int j = 0; j < MAX_COMPONENT_ASSETS; j++) {
|
||||
@@ -489,6 +608,13 @@ void AppData::storeAllSettings()
|
||||
joystick[i].storeAll();
|
||||
for (int i = 0; i < MAX_JS_BUTTONS; i++)
|
||||
jsButton[i].storeAll();
|
||||
for (int i = 0; i < MAX_NAMED_JOYSTICKS; i++) {
|
||||
namedJS[i].storeAll();
|
||||
for (int a = 0; a < MAX_JS_AXES; a += 1)
|
||||
namedJS[i].joystick[a].storeAll();
|
||||
for (int b = 0; b < MAX_JS_BUTTONS; b += 1)
|
||||
namedJS[i].jsButton[b].storeAll();
|
||||
}
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
component[i].storeAll();
|
||||
for (int j = 0; j < MAX_COMPONENT_ASSETS; j++)
|
||||
@@ -506,6 +632,7 @@ void AppData::sessionId(int index)
|
||||
if (index < 0 || index >= MAX_PROFILES || index == m_sessionId)
|
||||
return;
|
||||
m_sessionId = index;
|
||||
loadNamedJS();
|
||||
emit sessionIdChanged(index);
|
||||
emit currentProfileChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user