fix: Companion not reading/writing B&W telemetry screens correctly (#1562)
This commit is contained in:
@@ -637,7 +637,11 @@ struct convert<FrSkyLineData> {
|
|||||||
static Node encode(const FrSkyLineData& rhs)
|
static Node encode(const FrSkyLineData& rhs)
|
||||||
{
|
{
|
||||||
Node node, sources;
|
Node node, sources;
|
||||||
sources = encode_array(rhs.source);
|
for (int i = 0; i < getCurrentFirmware()->getCapability(TelemetryCustomScreensFieldsPerLine); i++) {
|
||||||
|
if (rhs.source[i].isSet()) {
|
||||||
|
sources[std::to_string(i)]["val"] = rhs.source[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (sources && sources.IsMap()) {
|
if (sources && sources.IsMap()) {
|
||||||
node["sources"] = sources;
|
node["sources"] = sources;
|
||||||
}
|
}
|
||||||
@@ -664,18 +668,30 @@ struct convert<FrSkyScreenData> {
|
|||||||
{
|
{
|
||||||
Node node;
|
Node node;
|
||||||
node["type"] = LookupValue(screenTypeLut, rhs.type);
|
node["type"] = LookupValue(screenTypeLut, rhs.type);
|
||||||
switch(rhs.type) {
|
if (rhs.type != TELEMETRY_SCREEN_NONE) {
|
||||||
case TELEMETRY_SCREEN_NONE:
|
Node cfg;
|
||||||
break;
|
switch(rhs.type) {
|
||||||
case TELEMETRY_SCREEN_NUMBERS:
|
case TELEMETRY_SCREEN_NUMBERS: {
|
||||||
node["lines"] = encode_array(rhs.body.lines);
|
Node lines;
|
||||||
break;
|
for (int i = 0; i < getCurrentFirmware()->getCapability(TelemetryCustomScreensLines); i++) {
|
||||||
case TELEMETRY_SCREEN_BARS:
|
lines[std::to_string(i)] = rhs.body.lines[i];
|
||||||
node["bars"] = encode_array(rhs.body.bars);
|
}
|
||||||
break;
|
cfg["lines"] = lines;
|
||||||
case TELEMETRY_SCREEN_SCRIPT:
|
} break;
|
||||||
node["script"]["file"] = rhs.body.script.filename;
|
case TELEMETRY_SCREEN_BARS: {
|
||||||
break;
|
Node bars;
|
||||||
|
for (int i = 0; i < getCurrentFirmware()->getCapability(TelemetryCustomScreensBars); i++) {
|
||||||
|
bars[std::to_string(i)] = rhs.body.bars[i];
|
||||||
|
}
|
||||||
|
cfg["bars"] = bars;
|
||||||
|
} break;
|
||||||
|
case TELEMETRY_SCREEN_SCRIPT:
|
||||||
|
cfg["script"]["file"] = rhs.body.script.filename;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (cfg && cfg.IsMap()) {
|
||||||
|
node["u"] = cfg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -683,23 +699,38 @@ struct convert<FrSkyScreenData> {
|
|||||||
static bool decode(const Node& node, FrSkyScreenData& rhs)
|
static bool decode(const Node& node, FrSkyScreenData& rhs)
|
||||||
{
|
{
|
||||||
node["type"] >> screenTypeLut >> rhs.type;
|
node["type"] >> screenTypeLut >> rhs.type;
|
||||||
switch(rhs.type) {
|
if (rhs.type == TELEMETRY_SCREEN_NONE) return true;
|
||||||
case TELEMETRY_SCREEN_NONE:
|
|
||||||
return true;
|
if (node["u"]) { // radio outputs generic u to indicate union field
|
||||||
case TELEMETRY_SCREEN_NUMBERS:
|
const auto& cfg = node["u"];
|
||||||
node["lines"] >> rhs.body.lines;
|
if (cfg && cfg.IsMap()) {
|
||||||
break;
|
switch(rhs.type) {
|
||||||
case TELEMETRY_SCREEN_BARS:
|
case TELEMETRY_SCREEN_NUMBERS:
|
||||||
node["bars"] >> rhs.body.bars;
|
if (cfg["lines"]) {
|
||||||
break;
|
const auto& lines = cfg["lines"];
|
||||||
case TELEMETRY_SCREEN_SCRIPT:
|
if (lines && lines.IsMap()) {
|
||||||
if (node["script"]) {
|
lines >> rhs.body.lines;
|
||||||
const auto& script = node["script"];
|
}
|
||||||
if (script && script.IsMap()) {
|
}
|
||||||
script["file"] >> rhs.body.script.filename;
|
break;
|
||||||
|
case TELEMETRY_SCREEN_BARS:
|
||||||
|
if (cfg["bars"]) {
|
||||||
|
const auto& bars = cfg["bars"];
|
||||||
|
if (bars && bars.IsMap()) {
|
||||||
|
bars >> rhs.body.bars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TELEMETRY_SCREEN_SCRIPT:
|
||||||
|
if (cfg["script"]) {
|
||||||
|
const auto& script = cfg["script"];
|
||||||
|
if (script && script.IsMap()) {
|
||||||
|
script["file"] >> rhs.body.script.filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user