feat(v16): add CI1302 voice control (VGR/VFL, motion control, menu navigation) (#7501)

Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
helloradiosky
2026-09-20 11:48:49 +10:00
committed by GitHub
co-authored by Peter Feerick Claude Sonnet 5
parent f364c6ef63
commit 4aa9a258ee
26 changed files with 1625 additions and 13 deletions
+22 -1
View File
@@ -135,7 +135,8 @@ void BoardJson::afterLoadFixups(Board::Type board, InputsTable * inputs, Switche
}
// Flex switches are not listed in json file for these radios
int count = IS_RADIOMASTER_TX16S(board) || IS_RADIOMASTER_MT12(board) ? 2 : 0;
int count = IS_RADIOMASTER_TX16S(board) || IS_RADIOMASTER_MT12(board) ||
IS_HELLORADIOSKY_V16(board) ? 2 : 0;
for (int i = 1; i <= count; i++) {
QString tag = QString("FL%1").arg(i);
@@ -146,6 +147,26 @@ void BoardJson::afterLoadFixups(Board::Type board, InputsTable * inputs, Switche
switches->insert(switches->end(), defn);
}
}
// CI1302 voice control virtual switches are not listed in json file
// They must follow the flex switches above: firmware indexes them at
// switchGetMaxSwitches() + MAX_FLEX_SWITCHES
// VGR (voice gear) is a 2POS switch, VFL (voice flap) is 3POS -- see
// isTwoPosVoiceSwitch() in radio/src/drivers/CI1302.cpp
if (IS_HELLORADIOSKY_V16(board)) {
for (const auto &sw : {std::make_pair(QStringLiteral("VGR"), Board::SWITCH_2POS),
std::make_pair(QStringLiteral("VFL"), Board::SWITCH_3POS)}) {
const QString &tag = sw.first;
if (getSwitchIndex(switches, tag, Board::LVT_TAG) < 0) {
SwitchDefn defn;
defn.tag = tag.toStdString();
defn.name = defn.tag;
defn.type = sw.second;
defn.dflt = sw.second;
switches->insert(switches->end(), defn);
}
}
}
}
// called from Boards::getCapability if no capability match
@@ -180,7 +180,10 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
val[val_len - 1] >= '0' && val[val_len - 1] <= '2') ||
(val_len >= 3 && val[0] == 'S' &&
val[1] >= 'A' && val[1] <= 'Z' &&
val[2] >= '0' && val[2] <= '2')) {
val[2] >= '0' && val[2] <= '2') ||
(val_len == 4 &&
(sw_str_tmp.substr(0, 3) == "VGR" || sw_str_tmp.substr(0, 3) == "VFL") &&
val[3] >= '0' && val[3] <= '2')) {
std::string tmp = sw_str_tmp.substr(0, val_len - 1);
+18 -5
View File
@@ -193,7 +193,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
};
static const QString special[] = {
"", tr("Batt"), tr("Time"), tr("GPS"), tr("Reserved1"), tr("Reserved2"), tr("Reserved3"), tr("Reserved4")
"", tr("Batt"), tr("Time"), tr("GPS"), tr("VGR"), tr("VFL"), tr("Reserved3"), tr("Reserved4")
};
static const QString rotary[] = { "", tr("REa"), tr("REb") };
@@ -355,8 +355,21 @@ bool RawSource::isAvailable(const ModelData * const model,
if (type == SOURCE_TYPE_SWITCH && abs(index) > b.getCapability(Board::Switches))
return false;
if (type == SOURCE_TYPE_SPECIAL && abs(index) >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED)
return false;
if (type == SOURCE_TYPE_SPECIAL && abs(index) >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED) {
// RESERVED1/2 are used as the CI1302 voice control VGR/VFL sources on this board
bool isVoiceSource = IS_HELLORADIOSKY_V16(board) &&
abs(index) <= SOURCE_TYPE_SPECIAL_RESERVED2;
if (!isVoiceSource)
return false;
// None on the Hardware Switches screen disables VGR/VFL as a source too
if (gs) {
QString tag = (abs(index) == SOURCE_TYPE_SPECIAL_RESERVED1) ? "VGR" : "VFL";
int swIdx = Boards::getSwitchIndex(tag, Board::LVT_TAG, board);
if (swIdx >= 0 && gs->switchConfig[swIdx].type == Board::SWITCH_NOT_AVAILABLE)
return false;
}
}
if (type == SOURCE_TYPE_TIMER && abs(index) > CPN_MAX_TIMERS)
return false;
@@ -475,8 +488,8 @@ tbl.insert(tbl.end(), {
{std::to_string(SOURCE_TYPE_SPECIAL_TX_BATT), "TX_VOLTAGE"},
{std::to_string(SOURCE_TYPE_SPECIAL_TX_TIME), "TX_TIME"},
{std::to_string(SOURCE_TYPE_SPECIAL_TX_GPS), "TX_GPS"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED1), "RESERVED1"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED2), "RESERVED2"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED1), "VGR"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED2), "VFL"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED3), "RESERVED3"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED4), "RESERVED4"},
});
@@ -0,0 +1,291 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
// CI1302 voice-control (VGR/VFL) source and switch coverage for the
// HelloRadioSky V16 board. Companion reimplements the firmware's YAML
// grammar independently, so these are the only guard against VGR/VFL
// silently decoding to NONE and getting lost on save.
#include "gtests.h"
#include <QByteArray>
#include "firmwares/eeprominterface.h"
#include "firmwares/edgetx/edgetxinterface.h"
#include "firmwares/edgetx/yaml_rawsource.h"
#include "firmwares/edgetx/yaml_rawswitch.h"
#include "firmwares/boardjson.h"
#include "firmwares/generalsettings.h"
#include "firmwares/mixdata.h"
namespace {
ModelData roundTrip(const ModelData& in, QByteArray& yamlOut)
{
writeModelToYaml(in, yamlOut);
ModelData out;
out.clear();
loadModelFromYaml(out, yamlOut);
return out;
}
class VoiceControlV16 : public ::testing::Test
{
protected:
void SetUp() override
{
Firmware::setCurrentVariant(Firmware::getFirmwareForFlavour("v16"));
ASSERT_NE(getCurrentFirmware(), nullptr)
<< "v16 (HelloRadioSky V16) firmware must be registered for this test";
ASSERT_TRUE(IS_HELLORADIOSKY_V16(getCurrentBoard()));
}
};
class VoiceControlOtherBoard : public ::testing::Test
{
protected:
void SetUp() override
{
Firmware::setCurrentVariant(Firmware::getFirmwareForFlavour("tx16s"));
ASSERT_NE(getCurrentFirmware(), nullptr)
<< "tx16s firmware must be registered for this test";
}
};
} // namespace
// VGR/VFL reuse the SOURCE_TYPE_SPECIAL RESERVED1/RESERVED2 slots; yaml tags
// must match the firmware's exactly ("VGR"/"VFL").
TEST_F(VoiceControlV16, MixSrcEncodeDecodeRoundTrips)
{
const RawSource vgr(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED1);
const RawSource vfl(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED2);
EXPECT_EQ(YamlRawSourceEncode(vgr), "VGR");
EXPECT_EQ(YamlRawSourceEncode(vfl), "VFL");
RawSource vgrBack = YamlRawSourceDecode("VGR");
EXPECT_EQ(vgrBack.type, SOURCE_TYPE_SPECIAL);
EXPECT_EQ(vgrBack.index, SOURCE_TYPE_SPECIAL_RESERVED1);
RawSource vflBack = YamlRawSourceDecode("VFL");
EXPECT_EQ(vflBack.type, SOURCE_TYPE_SPECIAL);
EXPECT_EQ(vflBack.index, SOURCE_TYPE_SPECIAL_RESERVED2);
}
// VGR/VFL are offered on the V16 board; RESERVED3/4 stay excluded.
TEST_F(VoiceControlV16, MixSrcAvailableOnlyForVoiceReservedSlots)
{
Board::Type board = getCurrentBoard();
const RawSource vgr(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED1);
const RawSource vfl(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED2);
const RawSource reserved3(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED3);
const RawSource reserved4(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED4);
EXPECT_TRUE(vgr.isAvailable(nullptr, nullptr, board));
EXPECT_TRUE(vfl.isAvailable(nullptr, nullptr, board));
EXPECT_FALSE(reserved3.isAvailable(nullptr, nullptr, board));
EXPECT_FALSE(reserved4.isAvailable(nullptr, nullptr, board));
}
// A mix already using VGR as its source must not keep tracking it once the
// user disables VGR on the Hardware Switches screen.
TEST_F(VoiceControlV16, MixSrcNotAvailableWhenSwitchDisabled)
{
Board::Type board = getCurrentBoard();
int vgrIdx = Boards::getSwitchYamlIndex(QStringLiteral("VGR"), BoardJson::YLT_REF, board);
ASSERT_GE(vgrIdx, 0);
const RawSource vgr(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED1);
const RawSource vfl(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED2);
GeneralSettings gs;
EXPECT_TRUE(vgr.isAvailable(nullptr, &gs, board));
gs.switchConfig[vgrIdx].type = Board::SWITCH_NOT_AVAILABLE;
EXPECT_FALSE(vgr.isAvailable(nullptr, &gs, board));
EXPECT_TRUE(vfl.isAvailable(nullptr, &gs, board));
}
// VGR/VFL must not leak into other radios' source pickers.
TEST_F(VoiceControlOtherBoard, MixSrcNotAvailableOnOtherBoards)
{
Board::Type board = getCurrentBoard();
ASSERT_FALSE(IS_HELLORADIOSKY_V16(board));
const RawSource vgr(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED1);
const RawSource vfl(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED2);
EXPECT_FALSE(vgr.isAvailable(nullptr, nullptr, board));
EXPECT_FALSE(vfl.isAvailable(nullptr, nullptr, board));
}
// Look the base switch index up rather than hardcoding it, since it depends
// on how many physical switches precede VGR/VFL in the table.
TEST_F(VoiceControlV16, SwitchEncodeDecodeRoundTrips)
{
Board::Type board = getCurrentBoard();
for (const QString& tag : {QStringLiteral("VGR"), QStringLiteral("VFL")}) {
int swIdx = Boards::getSwitchYamlIndex(tag, BoardJson::YLT_REF, board);
ASSERT_GE(swIdx, 0) << tag.toStdString() << " switch not registered for this board";
for (int pos = 0; pos < 3; pos++) {
RawSwitch rs(SWITCH_TYPE_SWITCH, swIdx * 3 + pos + 1);
std::string expected = QString(tag + QString::number(pos)).toStdString();
EXPECT_EQ(YamlRawSwitchEncode(rs), expected);
RawSwitch back = YamlRawSwitchDecode(expected);
EXPECT_TRUE(back == rs) << "round-trip mismatch for " << expected;
}
}
}
// A model using VGR as a mix source and VFL2 as its switch must survive a
// full YAML round-trip unchanged.
TEST_F(VoiceControlV16, ModelUsingVoiceSourceAndSwitchRoundTrips)
{
Board::Type board = getCurrentBoard();
int vflIdx = Boards::getSwitchYamlIndex(QStringLiteral("VFL"), BoardJson::YLT_REF, board);
ASSERT_GE(vflIdx, 0);
ModelData m;
m.clear();
m.used = true;
m.mixData[0].destCh = 1;
m.mixData[0].weight = 100;
m.mixData[0].srcRaw = RawSource(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_RESERVED1); // VGR
m.mixData[0].swtch = RawSwitch(SWITCH_TYPE_SWITCH, vflIdx * 3 + 2 + 1); // VFL2
QByteArray y1;
ModelData m2 = roundTrip(m, y1);
EXPECT_EQ(m2.mixData[0].destCh, m.mixData[0].destCh);
EXPECT_EQ(m2.mixData[0].srcRaw.type, m.mixData[0].srcRaw.type);
EXPECT_EQ(m2.mixData[0].srcRaw.index, m.mixData[0].srcRaw.index);
EXPECT_TRUE(m2.mixData[0].swtch == m.mixData[0].swtch)
<< "VFL2 switch was lost/changed on round-trip";
// Fixed point: re-serialising the reloaded model must not lose it either.
QByteArray y2;
ModelData m3 = roundTrip(m2, y2);
EXPECT_EQ(m3.mixData[0].srcRaw.index, m2.mixData[0].srcRaw.index);
EXPECT_TRUE(m3.mixData[0].swtch == m2.mixData[0].swtch);
}
// Simulator switch widgets address switches by index, so these must match
// firmware's initVoiceMappedSwitches() (radio/src/drivers/CI1302.cpp):
// switchGetMaxSwitches() + MAX_FLEX_SWITCHES, where V16 has 10 physical
// switches and 2 flex switches.
TEST_F(VoiceControlV16, VoiceSwitchIndexesFollowFlexSwitches)
{
Board::Type board = getCurrentBoard();
EXPECT_EQ(Boards::getCapability(board, Board::FlexSwitches), 2);
EXPECT_EQ(Boards::getSwitchYamlIndex(QStringLiteral("FL1"), BoardJson::YLT_REF, board), 10);
EXPECT_EQ(Boards::getSwitchYamlIndex(QStringLiteral("FL2"), BoardJson::YLT_REF, board), 11);
EXPECT_EQ(Boards::getSwitchYamlIndex(QStringLiteral("VGR"), BoardJson::YLT_REF, board), 12);
EXPECT_EQ(Boards::getSwitchYamlIndex(QStringLiteral("VFL"), BoardJson::YLT_REF, board), 13);
}
// VGR (voice gear) is a 2POS switch on real hardware -- see
// isTwoPosVoiceSwitch()/VSW_GEAR in radio/src/drivers/CI1302.cpp -- VFL
// (voice flap) is 3POS.
TEST_F(VoiceControlV16, VgrIsTwoPosVflIsThreePos)
{
Board::Type board = getCurrentBoard();
int vgrIdx = Boards::getSwitchYamlIndex(QStringLiteral("VGR"), BoardJson::YLT_REF, board);
int vflIdx = Boards::getSwitchYamlIndex(QStringLiteral("VFL"), BoardJson::YLT_REF, board);
ASSERT_GE(vgrIdx, 0);
ASSERT_GE(vflIdx, 0);
EXPECT_EQ(Boards::getSwitchInfo(vgrIdx, board).dflt, Board::SWITCH_2POS);
EXPECT_EQ(Boards::getSwitchInfo(vflIdx, board).dflt, Board::SWITCH_3POS);
}
// Firmware (radio/src/drivers/CI1302.cpp, CI1302_voiceSwitchSetDefaults())
// now default-initialises and genuinely persists VGR/VFL's type like any
// other switch, and its own settings.yml always includes an explicit entry
// for them (switchIsActive() already covers switchGetMaxAllSwitches()).
// A real device's file therefore always states VGR/VFL's type explicitly
// -- Companion must round-trip whatever value is there, including an
// explicit NONE if the user disabled one on the radio.
TEST_F(VoiceControlV16, GeneralSettingsRoundTripHonoursVoiceSwitchType)
{
Board::Type board = getCurrentBoard();
int vgrIdx = Boards::getSwitchYamlIndex(QStringLiteral("VGR"), BoardJson::YLT_REF, board);
int vflIdx = Boards::getSwitchYamlIndex(QStringLiteral("VFL"), BoardJson::YLT_REF, board);
ASSERT_GE(vgrIdx, 0);
ASSERT_GE(vflIdx, 0);
const QByteArray deviceYaml =
"board: v16\n"
"switchConfig:\n"
" SA:\n"
" type: 3POS\n"
" VGR:\n"
" type: NONE\n"
" VFL:\n"
" type: 3POS\n";
GeneralSettings gs;
ASSERT_TRUE(loadRadioSettingsFromYaml(gs, deviceYaml));
EXPECT_EQ(gs.switchConfig[vgrIdx].type, Board::SWITCH_NOT_AVAILABLE)
<< "the user disabled VGR on the radio; Companion must not resurrect it";
EXPECT_EQ(gs.switchConfig[vflIdx].type, Board::SWITCH_3POS);
RawSwitch vgrUp(SWITCH_TYPE_SWITCH, vgrIdx * 3 + 0 + 1);
RawSwitch vflUp(SWITCH_TYPE_SWITCH, vflIdx * 3 + 0 + 1);
RawSwitch vflMid(SWITCH_TYPE_SWITCH, vflIdx * 3 + 1 + 1);
RawSwitch vflDown(SWITCH_TYPE_SWITCH, vflIdx * 3 + 2 + 1);
EXPECT_FALSE(vgrUp.isAvailable(nullptr, &gs, board))
<< "VGR is configured NONE; it must not appear in the switches picker";
EXPECT_TRUE(vflUp.isAvailable(nullptr, &gs, board));
EXPECT_TRUE(vflMid.isAvailable(nullptr, &gs, board))
<< "VFL is a 3POS switch; all 3 positions must be available in the switches picker";
EXPECT_TRUE(vflDown.isAvailable(nullptr, &gs, board));
}
// A device's settings.yml with no switchConfig entry at all for VGR/VFL
// (e.g. hand-written, or predating the firmware default-init fix) falls
// back to None, same as it would for any other switch missing from the
// file -- there's no special-casing left for these two on the Companion side.
TEST_F(VoiceControlV16, GeneralSettingsRoundTripDefaultsMissingVoiceSwitchesToNone)
{
Board::Type board = getCurrentBoard();
int vgrIdx = Boards::getSwitchYamlIndex(QStringLiteral("VGR"), BoardJson::YLT_REF, board);
ASSERT_GE(vgrIdx, 0);
const QByteArray deviceYaml =
"board: v16\n"
"switchConfig:\n"
" SA:\n"
" type: 3POS\n";
GeneralSettings gs;
ASSERT_TRUE(loadRadioSettingsFromYaml(gs, deviceYaml));
EXPECT_EQ(gs.switchConfig[vgrIdx].type, Board::SWITCH_NOT_AVAILABLE);
}