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
@@ -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;