Skip to content
Draft
1 change: 1 addition & 0 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ enum TelemetryProtocol
PROTOCOL_TELEMETRY_CROSSFIRE,
PROTOCOL_TELEMETRY_SPEKTRUM,
PROTOCOL_TELEMETRY_FLYSKY_IBUS,
PROTOCOL_TELEMETRY_FLYSKY_IBUS2,
PROTOCOL_TELEMETRY_HITEC,
PROTOCOL_TELEMETRY_HOTT,
PROTOCOL_TELEMETRY_MLINK,
Expand Down
160 changes: 151 additions & 9 deletions radio/src/gui/colorlcd/module/afhds3_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,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 };

Expand Down Expand Up @@ -118,6 +118,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);
Expand Down Expand Up @@ -191,8 +198,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)
{
Expand All @@ -201,14 +208,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);
}
}
Expand All @@ -232,3 +274,103 @@ 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 += "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) {
temp_str = "Only in the iBUS2 mode can the sensors be set.";
new StaticText(line, rect_t{}, temp_str);
return;
}

if (cfg->others.sensorOnLine & (1 << afhds3::DirtyIbus2Sensor::IBUS2_SENSOR_GPS))
{
temp_str = STR_IMU;
temp_str += " ";
temp_str += TR_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 = "DIST";
temp_str += " ";
temp_str += TR_CURRENTSENSOR;
line = body->newLine(grid);
new StaticText(line, rect_t{}, temp_str);
auto dist_btn = new TextButton(line, rect_t{}, TR_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)) {
temp_str = TR_ALTSENSOR;
line = body->newLine(grid);
new StaticText(line, rect_t{}, temp_str);
auto alt_btn = new TextButton(line, rect_t{}, TR_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 += TR_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 += "Calib";
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");
}
}
8 changes: 8 additions & 0 deletions radio/src/gui/colorlcd/module/afhds3_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
5 changes: 5 additions & 0 deletions radio/src/gui/colorlcd/module/afhds3_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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) {
Expand Down
Loading