feat: Add support for SpaceMouse mod (6D input knob) (#1853)

Use `-DSPACEMOUSE=YES` CMake option to activate on Horus color targets.
Co-authored-by: Niel Horne (elecpower), Raphael Coeffic (raphaelcoeffic) and Peter Feerick (pfeerick).
This commit is contained in:
Risto
2022-09-18 09:23:48 +02:00
committed by GitHub
co-authored by Niel Horne (elecpower), Raphael Coeffic (raphaelcoeffic) and Peter Feerick (pfeerick).
parent 3765e678b9
commit 9dc4065525
42 changed files with 491 additions and 47 deletions
+1
View File
@@ -48,6 +48,7 @@
#define CPN_MAX_SENSORS 60
#define CPN_MAX_SCRIPTS 9
#define CPN_MAX_SCRIPT_INPUTS 10
#define CPN_MAX_SPACEMOUSE 6
#define CPN_STR_APP_NAME QCoreApplication::translate("Companion", "EdgeTX Companion")
#define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading
@@ -112,6 +112,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
addItems(SOURCE_TYPE_VIRTUAL_INPUT, RawSource::InputsGroup, firmware->getCapability(VirtualInputs));
addItems(SOURCE_TYPE_STICK, RawSource::SourcesGroup, board->getCapability(Board::MaxAnalogs));
addItems(SOURCE_TYPE_TRIM, RawSource::TrimsGroup, board->getCapability(Board::NumTrims));
addItems(SOURCE_TYPE_SPACEMOUSE, RawSource::SourcesGroup, CPN_MAX_SPACEMOUSE);
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, 1);
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, board->getCapability(Board::Switches));
addItems(SOURCE_TYPE_FUNCTIONSWITCH, RawSource::SwitchesGroup, board->getCapability(Board::FunctionSwitches));
@@ -83,6 +83,7 @@ const YamlLookupTable uartModeLut = {
{ GeneralSettings::AUX_SERIAL_CLI, "CLI" },
{ GeneralSettings::AUX_SERIAL_GPS, "GPS" },
{ GeneralSettings::AUX_SERIAL_DEBUG, "DEBUG" },
{ GeneralSettings::AUX_SERIAL_SPACEMOUSE, "SPACEMOUSE" },
};
const YamlLookupTable antennaModeLut = {
@@ -21,6 +21,16 @@
#include "yaml_rawsource.h"
#include "eeprominterface.h"
static const YamlLookupTable spacemouseLut = {
{ 0, "SPACEMOUSE_A" },
{ 1, "SPACEMOUSE_B" },
{ 2, "SPACEMOUSE_C" },
{ 3, "SPACEMOUSE_D" },
{ 4, "SPACEMOUSE_E" },
{ 5, "SPACEMOUSE_F" },
};
std::string YamlRawSourceEncode(const RawSource& rhs)
{
std::string src_str;
@@ -97,6 +107,11 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
src_str += std::to_string(rhs.index / 3);
src_str += ")";
break;
case SOURCE_TYPE_SPACEMOUSE:
src_str = "SPACEMOUSE_";
c += rhs.index;
src_str += c;
break;
default:
src_str = "NONE";
break;
@@ -165,7 +180,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
val[0] == 'f' &&
val[1] == 's' &&
val[2] == '(') {
std::stringstream src(src_str.substr(3));
int fs = 0;
src >> fs;
@@ -259,6 +274,15 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
rhs.index = sp_idx;
}
if (node.IsScalar() && node.as<std::string>().size() == 12 && node.as<std::string>().substr(0, 11) == "SPACEMOUSE_") {
int sm_idx;
node >> spacemouseLut >> sm_idx;
if (sm_idx >= 0) {
rhs.type = SOURCE_TYPE_SPACEMOUSE;
rhs.index = sm_idx;
}
}
if (node.IsScalar() && node.as<std::string>() == "MAX") {
rhs.type = SOURCE_TYPE_MAX;
rhs.index = 0;
+5 -2
View File
@@ -501,6 +501,8 @@ QString GeneralSettings::serialModeToString(int value)
return tr("GPS");
case AUX_SERIAL_DEBUG:
return tr("Debug");
case AUX_SERIAL_SPACEMOUSE:
return tr("SpaceMouse");
default:
return CPN_STR_UNKNOWN_ITEM;
}
@@ -576,8 +578,9 @@ AbstractStaticItemModel * GeneralSettings::serialModeItemModel(int port_nr)
if (port_nr == SP_VCP &&
(i == AUX_SERIAL_TELE_IN ||
i == AUX_SERIAL_SBUS_TRAINER ||
i == AUX_SERIAL_GPS)) {
// These 3 are disabled on VCP
i == AUX_SERIAL_GPS ||
i == AUX_SERIAL_SPACEMOUSE)) {
// These are disabled on VCP
continue;
}
mdl->appendToItemList(serialModeToString(i), i);
@@ -141,6 +141,7 @@ class GeneralSettings {
AUX_SERIAL_CLI,
AUX_SERIAL_GPS,
AUX_SERIAL_DEBUG,
AUX_SERIAL_SPACEMOUSE,
AUX_SERIAL_COUNT
};
+9
View File
@@ -248,6 +248,9 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
else
return GVarData().nameToString(index);
case SOURCE_TYPE_SPACEMOUSE:
return tr("sm%1").arg(QChar('A' + index));
default:
return QString(CPN_STR_UNKNOWN_ITEM);
}
@@ -352,6 +355,12 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings
if (type == SOURCE_TYPE_TRIM && index >= b.getCapability(Board::NumTrims))
return false;
if (type == SOURCE_TYPE_SPACEMOUSE &&
(index >= CPN_MAX_SPACEMOUSE ||
(!(gs->serialPort[GeneralSettings::SP_AUX1] == GeneralSettings::AUX_SERIAL_SPACEMOUSE ||
gs->serialPort[GeneralSettings::SP_AUX2] == GeneralSettings::AUX_SERIAL_SPACEMOUSE))))
return false;
return true;
}
+1
View File
@@ -177,6 +177,7 @@ enum RawSourceType {
SOURCE_TYPE_GVAR,
SOURCE_TYPE_SPECIAL,
SOURCE_TYPE_TELEMETRY,
SOURCE_TYPE_SPACEMOUSE,
MAX_SOURCE_TYPE
};