feat(afhds3): iBUS2 support (#6914)

Co-authored-by: xlong <984929678@qq.com>
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
richardclli
2026-08-05 12:56:32 +10:00
committed by GitHub
co-authored by xlong Peter Feerick Claude Sonnet 5
parent 992096f4c9
commit 256dc98917
33 changed files with 1092 additions and 14 deletions
+150 -11
View File
@@ -34,9 +34,8 @@ static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT,
#define SET_DIRTY()
static const char* const _analog_outputs[] = { "PWM", "PPM" };
static const char* const _bus_types[] = { "iBUS OUT", "iBUS IN", "SBUS" };
static const char* const _v1_bus_types[] = { "PWM", "PPM", "SBUS", "iBUS IN", "iBUS OUT" };
static const char* const _bus_types[] = { "iBUS OUT", "iBUS IN", "SBUS"};
static const char* const _v1_bus_types[] = { "PWM", "PPM", "SBUS", "iBUS IN", "iBUS OUT", "iBUS2" };
static const char* const _v1_pwmfreq_types[] = { STR_ANALOG_SERVO, STR_DIGITAL_SERVO, "SR833HZ", "SFR1000HZ", STR_MULTI_CUSTOM };
static const char* const _v0_pwmfreq_types[] = { STR_ANALOG_SERVO, STR_DIGITAL_SERVO, STR_MULTI_CUSTOM };
@@ -123,6 +122,13 @@ PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx ) :
num_edit->show(pwmvalue_type == 2);
}
uint8_t GetDisplayPortType(uint8_t NP) {
if (NP == afhds3::SES_NPT_IBUS2_HUB_PORT)
return afhds3::SES_NPT_IBUS2;
else
return NP;
}
AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
{
cfg = afhds3::getConfig(moduleIdx);
@@ -159,7 +165,7 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
temp_str = STR_CH;
temp_str += " 1";
new StaticText(line, rect_t{}, temp_str );
new Choice(line, rect_t{}, _analog_outputs,
new Choice(line, rect_t{}, STR_FLYSKY_PULSE_PROTO,
afhds3::SES_ANALOG_OUTPUT_PWM, afhds3::SES_ANALOG_OUTPUT_PPM,
GET_SET_AND_SYNC(cfg, vCfg->AnalogOutput, afhds3::DirtyConfig::DC_RX_CMD_OUT_PWM_PPM_MODE));
@@ -196,8 +202,8 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
portName += 'A' + i;
new StaticText(line, rect_t{}, portName.c_str());
new Choice(line, rect_t{}, _v1_bus_types, afhds3::SES_NPT_PWM,
afhds3::SES_NPT_IBUS1_OUT,
GET_DEFAULT(vCfg->NewPortTypes[i]),
afhds3::SES_NPT_IBUS2,
GET_DEFAULT(GetDisplayPortType(vCfg->NewPortTypes[i])),
[=](int32_t newValue) {
if(!newValue)
{
@@ -206,14 +212,49 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
}
else {
uint8_t j = 0;
for ( j = 0; j < SES_NPT_NB_MAX_PORTS; j++) {
if ( vCfg->NewPortTypes[j]== newValue && i != j )
break;
bool isNewValueIBUS2 = (newValue == afhds3::SES_NPT_IBUS2 || newValue == afhds3::SES_NPT_IBUS2_HUB_PORT);
bool isNewValueIBUS1_IN = (newValue == afhds3::SES_NPT_IBUS1_IN);
bool isNewValueIBUS1_OUT = (newValue == afhds3::SES_NPT_IBUS1_OUT);
bool conflict = false;
for (j = 0; j < SES_NPT_NB_MAX_PORTS; j++) {
if (j == i) continue;
uint8_t existingType = vCfg->NewPortTypes[j];
bool isExistingIBUS1_IN = (existingType == afhds3::SES_NPT_IBUS1_IN);
bool isExistingIBUS1_OUT = (existingType == afhds3::SES_NPT_IBUS1_OUT);
bool isExistingIBUS2 = (existingType == afhds3::SES_NPT_IBUS2 || existingType == afhds3::SES_NPT_IBUS2_HUB_PORT);
// Check for mutual exclusivity of iBUS1 and iBUS2
if ((isNewValueIBUS1_IN || isNewValueIBUS1_OUT) && isExistingIBUS2) {
conflict = true;
break;
}
if (isNewValueIBUS2 && (isExistingIBUS1_IN || isExistingIBUS1_OUT)) {
conflict = true;
break;
}
// Check for iBUS1 conflicts in the same direction
if (isNewValueIBUS1_IN && isExistingIBUS1_IN) {
conflict = true;
break;
}
if (isNewValueIBUS1_OUT && isExistingIBUS1_OUT) {
conflict = true;
break;
}
// Check for duplicate entries of non-iBUS type
if (!isNewValueIBUS2 && !isNewValueIBUS1_IN && !isNewValueIBUS1_OUT &&
existingType == newValue) {
conflict = true;
break;
}
}
//The RX does not support two or more ports to output IBUS (the same is true for PPM and SBUS).
if(j==SES_NPT_NB_MAX_PORTS )
{
vCfg->NewPortTypes[i] = newValue;
if (!conflict)
vCfg->NewPortTypes[i] = newValue;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_PORT_TYPE_V1);
}
}
@@ -237,3 +278,101 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_RSSI_CHANNEL_SETUP);
});
}
AFHDS3_Sensors::AFHDS3_Sensors(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
{
cfg = afhds3::getConfig(moduleIdx);
std::string title =
moduleIdx == INTERNAL_MODULE ? STR_INTERNALRF : STR_EXTERNALRF;
header->setTitle(title);
title = "AFHDS3 (";
title += STR_TELEMETRY_SENSORS;
title += ")";
header->setTitle2(title);
body->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_TINY);
FlexGridLayout grid(col_dsc, row_dsc, PAD_TINY);
bool ibus2_mode = false;
if (cfg->version == 0) {
return;
}
auto vCfg = &cfg->v1;
for (uint8_t j = 0; j < SES_NPT_NB_MAX_PORTS; j++) {
if (vCfg->NewPortTypes[j] == afhds3::SES_NPT_IBUS2 || vCfg->NewPortTypes[j] == afhds3::SES_NPT_IBUS2_HUB_PORT) {
ibus2_mode = true;
break;
}
}
std::string temp_str;
auto line = body->newLine(grid);
if (!ibus2_mode) {
new StaticText(line, rect_t{}, STR_IBUS2_SENSORS_MODE_ONLY);
return;
}
if (cfg->others.sensorOnLine & (1 << afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_GPS))
{
temp_str = STR_IMU;
temp_str += " ";
temp_str += STR_CURRENTSENSOR;
new StaticText(line, rect_t{}, temp_str);
auto imu_btn = new TextButton(line, rect_t{}, STR_CALIBRATION);
imu_btn->setPressHandler([=]() -> uint8_t {
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_CALIB_GYRO);
return 0;
});
temp_str = STR_SENSOR_DIST;
temp_str += " ";
temp_str += STR_CURRENTSENSOR;
line = body->newLine(grid);
new StaticText(line, rect_t{}, temp_str);
auto dist_btn = new TextButton(line, rect_t{}, STR_RESET);
dist_btn->setPressHandler([=]() -> uint8_t {
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_CALIB_DIST);
return 0;
});
}
if (cfg->others.sensorOnLine & (1 << afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_GPS) || cfg->others.sensorOnLine & (1 << afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_PRES)) {
line = body->newLine(grid);
new StaticText(line, rect_t{}, STR_ALTSENSOR);
auto alt_btn = new TextButton(line, rect_t{}, STR_RESET);
alt_btn->setPressHandler([=]() -> uint8_t {
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_CALIB_ALT);
return 0;
});
}
// if (cfg->others.sensorOnLine & (1 << afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_RPM)) {
// temp_str = "RPM";
// temp_str += " ";
// temp_str += STR_CURRENTSENSOR;
// line = body->newLine(grid);
// new StaticText(line, rect_t{}, temp_str);
// new NumberEdit(line, rect_t{0, 0, EdgeTxStyles::EDIT_FLD_WIDTH_NARROW, 0}, 1, 12, GET_SET_DEFAULT(cfg->others.calibData[afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_RPM]));
// }
if (cfg->others.sensorOnLine & (1 << afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_IBC)) {
// temp_str = "IBC01";
// temp_str += " Auto ";
// temp_str += "Clear";
// line = body->newLine(grid);
// new StaticText(line, rect_t{}, temp_str);
// new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(cfg->others.calibData[afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_IBC]));
temp_str = "IBC01";
temp_str += " ";
temp_str += STR_CALIBRATION;
line = body->newLine(grid);
new StaticText(line, rect_t{}, temp_str);
auto edit = new NumberEdit(line, rect_t{0, 0, EdgeTxStyles::EDIT_FLD_WIDTH_NARROW, 0}, 0, 120, GET_SET_DEFAULT(cfg->others.calibData[afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_IBC]), PREC1);
edit->setSuffix("v");
}
}
@@ -31,3 +31,11 @@ class AFHDS3_Options : public Page
public:
AFHDS3_Options(uint8_t moduleIdx);
};
class AFHDS3_Sensors : public Page
{
afhds3::Config_u* cfg;
public:
AFHDS3_Sensors(uint8_t moduleIdx);
};
@@ -89,6 +89,11 @@ AFHDS3Settings::AFHDS3Settings(Window* parent, const FlexGridLayout& g,
return 0;
});
new TextButton(afhds3TypeForm, rect_t{}, STR_TELEMETRY_SENSORS, [=]() {
new AFHDS3_Sensors(moduleIdx);
return 0;
});
bool hasPowerOption = false;
int maxPower;
if (moduleIdx == INTERNAL_MODULE) {