Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AFHDS3): Sync UI with Flysky AFHDS3 module stored settings #3501

Merged
merged 15 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions companion/src/firmwares/edgetx/yaml_moduledata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
// ghost:
// raw12bits: 0

// FRM303 (as of PR3501)
// type: TYPE_FLYSKY
// subType: AFHDS3
// channelsStart: 0
// channelsCount: 18
// failsafeMode: NOT_SET
// mod:
// afhds3:
// emi: 2
// telemetry: 1
// phyMode: 2
// reserved: 0
// rfPower: 1

static const YamlLookupTable protocolLut = {
{ PULSES_OFF, "TYPE_NONE" },
{ PULSES_PPM, "TYPE_PPM" },
Expand Down Expand Up @@ -97,6 +111,11 @@ static const YamlLookupTable dsmLut = {
{ 2, "DSMX" },
};

static const YamlLookupTable afhdsLut = {
{ 0, "AFHDS3" },
{ 1, "AFHDS2A" } // could be complete nonsense, CHECK IT!
};

static const YamlLookupTable failsafeLut = {
{ FAILSAFE_NOT_SET, "NOT_SET" },
{ FAILSAFE_HOLD, "HOLD" },
Expand Down Expand Up @@ -156,6 +175,10 @@ Node convert<ModuleData>::encode(const ModuleData& rhs)
st_str += std::to_string(subType);
node["subType"] = st_str;
} break;
case PULSES_AFHDS3: {
node["subType"] = LookupValue(afhdsLut, subtype);
break;
}
}

node["channelsStart"] = rhs.channelsStart;
Expand Down Expand Up @@ -223,7 +246,17 @@ Node convert<ModuleData>::encode(const ModuleData& rhs)
dsmp["flags"] = rhs.dsmp.flags;
mod["dsmp"] = dsmp;
} break;
// TODO: afhds3, flysky
// TODO: flysky
// TODO: afhds3
case PULSES_AFHDS3: {
Node afhds3;
afhds3["emi"] = rhs.afhds3.emi;
afhds3["telemetry"] = rhs.afhds3.telemetry;
afhds3["phyMode"] = rhs.afhds3.phyMode;
afhds3["reserved"] = rhs.afhds3.reserved;
afhds3["rfPower"] = rhs.afhds3.rfPower;
mod["afhds3"] = afhds3;
} break;
default: {
Node ppm;
ppm["delay"] = exportPpmDelay(rhs.ppm.delay);
Expand Down Expand Up @@ -348,9 +381,15 @@ bool convert<ModuleData>::decode(const Node& node, ModuleData& rhs)
Node dsmp = mod["dsmp"];
dsmp["flags"] >> rhs.dsmp.flags;
} else if (mod["flysky"]) {
//TODO
// TODO: flysky
} else if (mod["afhds3"]) {
//TODO
// TODO: afhds3
Node afhds3 = mod["afhds3"];
afhds3["emi"] >> rhs.afhds3.emi;
afhds3["telemetry"] >> rhs.afhds3.telemetry;
afhds3["phyMode"] >> rhs.afhds3.phyMode;
afhds3["reserved"] >> rhs.afhds3.reserved;
afhds3["rfPower"] >> rhs.afhds3.rfPower;
}
}

Expand Down
4 changes: 4 additions & 0 deletions companion/src/firmwares/moduledata.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class ModuleData {
struct Afhds3 {
unsigned int rxFreq;
unsigned int rfPower;
unsigned int emi;
unsigned int telemetry;
unsigned int phyMode;
unsigned int reserved;
} afhds3;

struct PXX {
Expand Down
1 change: 1 addition & 0 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ PACK(struct ModuleData {
uint8_t telemetry:1;
uint8_t phyMode:3;
uint8_t reserved:2;
uint8_t rfPower;
} afhds3);
NOBACKUP(struct {
uint8_t raw12bits:1;
Expand Down
58 changes: 37 additions & 21 deletions radio/src/gui/colorlcd/afhds3_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx, uint8_
setFlexLayout(LV_FLEX_FLOW_ROW);
lv_obj_set_width(lvobj, LV_SIZE_CONTENT);
uint16_t &pwmvalue_type = _v1_pwmvalue_type[moduleIdx][channelIdx];
auto vCfg = &afhds3::getConfig(moduleIdx)->v1;
auto cfg = afhds3::getConfig(moduleIdx);
auto vCfg = &cfg->v1;
if( 0xff ==pwmvalue_type )
{
if ( 50 == vCfg->PWMFrequenciesV1.PWMFrequencies[channelIdx] ) pwmvalue_type = 0;
Expand All @@ -96,12 +97,14 @@ PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx, uint8_
[=,&pwmvalue_type](int32_t newValue) {
pwmvalue_type=newValue;
vCfg->PWMFrequenciesV1.PWMFrequencies[channelIdx] = _v1_index2pwmvalue[newValue];
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V1);
});
auto num_edit = new NumberEdit(this, rect_t{}, 50, 400,
[=,&pwmvalue_type] { return (pwmvalue_type==4?vCfg->PWMFrequenciesV1.PWMFrequencies[channelIdx]:50); },
[=](int16_t newVal) {
vCfg->PWMFrequenciesV1.PWMFrequencies[channelIdx] = newVal;
});
auto num_edit = new NumberEdit(this, rect_t{}, 50, 400,
[=,&pwmvalue_type] { return (pwmvalue_type==4?vCfg->PWMFrequenciesV1.PWMFrequencies[channelIdx]:50); },
[=](int16_t newVal) {
vCfg->PWMFrequenciesV1.PWMFrequencies[channelIdx] = newVal;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V1);
});
c_obj = choice->getLvObj();
auto btn_obj = num_edit->getLvObj();
lv_obj_add_event_cb(c_obj, pwmfreq_changed, LV_EVENT_VALUE_CHANGED, btn_obj);
Expand All @@ -114,7 +117,8 @@ PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx ) :
setFlexLayout(LV_FLEX_FLOW_ROW);
lv_obj_set_width(lvobj, LV_SIZE_CONTENT);
uint16_t &pwmvalue_type = _v1_pwmvalue_type[moduleIdx][0];
auto vCfg = &afhds3::getConfig(moduleIdx)->v0;
auto cfg = afhds3::getConfig(moduleIdx);
auto vCfg = &cfg->v0;
if( 0xff ==pwmvalue_type )
{
if ( 50 == (vCfg->PWMFrequency.Frequency&0x7fff) ) pwmvalue_type = 0;
Expand All @@ -124,16 +128,18 @@ PWMfrequencyChoice::PWMfrequencyChoice(Window* parent, uint8_t moduleIdx ) :
auto choice = new Choice(this, rect_t{}, _v0_pwmfreq_types, 0, 2,
[=,&pwmvalue_type]{
return pwmvalue_type;
},
},
[=,&pwmvalue_type](int32_t newValue) {
pwmvalue_type=newValue;
vCfg->PWMFrequency.Frequency = _v0_index2pwmvalue[newValue];
});
auto num_edit = new NumberEdit(this, rect_t{}, 50, 400,
[=,&pwmvalue_type] { return (pwmvalue_type==2?vCfg->PWMFrequency.Frequency&0x7fff:50); },
[=](int16_t newVal) {
vCfg->PWMFrequency.Frequency = newVal;
});
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V0);
});
auto num_edit = new NumberEdit(this, rect_t{}, 50, 400,
[=,&pwmvalue_type] { return (pwmvalue_type==2?vCfg->PWMFrequency.Frequency&0x7fff:50); },
[=](int16_t newVal) {
vCfg->PWMFrequency.Frequency = newVal;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V0);
});
c_obj = choice->getLvObj();
auto btn_obj = num_edit->getLvObj();
lv_obj_add_event_cb(c_obj, pwmfreq_changedV0, LV_EVENT_VALUE_CHANGED, btn_obj);
Expand All @@ -145,8 +151,6 @@ void PWMfrequencyChoice::update() const
lv_event_send(c_obj, LV_EVENT_VALUE_CHANGED, nullptr);
}



AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
{
cfg = afhds3::getConfig(moduleIdx);
Expand Down Expand Up @@ -179,20 +183,21 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
temp_str += " ";
temp_str += STR_SYNC;
new StaticText(line, rect_t{}, temp_str);
new CheckBox(line, rect_t{}, GET_SET_DEFAULT(vCfg->PWMFrequency.Synchronized));
new CheckBox(line, rect_t{}, GET_SET_AND_SYNC(cfg, vCfg->PWMFrequency.Synchronized,
afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V0));
line = form->newLine(&grid);

temp_str = STR_CH;
temp_str += " 1";
new StaticText(line, rect_t{}, temp_str );
new Choice(line, rect_t{}, _analog_outputs,
afhds3::SES_ANALOG_OUTPUT_PWM, afhds3::SES_ANALOG_OUTPUT_PPM,
GET_SET_DEFAULT(vCfg->AnalogOutput));
GET_SET_AND_SYNC(cfg, vCfg->AnalogOutput, afhds3::DirtyConfig::DC_RX_CMD_OUT_PWM_PPM_MODE));

line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SERIAL_BUS);
new Choice(line, rect_t{}, _bus_types, 0, 2,
GET_SET_DEFAULT(cfg->BusType.ExternalBusType));
GET_SET_AND_SYNC(cfg, cfg->others.ExternalBusType, afhds3::DirtyConfig::DC_RX_CMD_BUS_TYPE_V0));
} else {
auto vCfg = &cfg->v1;
for (uint8_t i = 0; i < channel_num[vCfg->PhyMode]; i++) {
Expand All @@ -212,6 +217,7 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
[=](uint8_t newVal) {
vCfg->PWMFrequenciesV1.Synchronized &= ~(1<<i);
vCfg->PWMFrequenciesV1.Synchronized |= (newVal?1:0)<<i;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_FREQUENCY_V1);
});
}

Expand All @@ -225,15 +231,22 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
GET_DEFAULT(vCfg->NewPortTypes[i]),
[=](int32_t newValue) {
if(!newValue)
{
vCfg->NewPortTypes[i] = newValue;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_PORT_TYPE_V1);
}
else {
uint8_t j = 0;
for ( j = 0; j < SES_NPT_NB_MAX_PORTS; j++) {
if ( vCfg->NewPortTypes[j]== newValue && i != j )
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(j==SES_NPT_NB_MAX_PORTS )
{
vCfg->NewPortTypes[i] = newValue;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_PORT_TYPE_V1);
}
}
});
}
Expand All @@ -250,5 +263,8 @@ AFHDS3_Options::AFHDS3_Options(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
new Choice(line, rect_t{}, signed_strength_ch,
0, channel_num[cfg->v1.PhyMode],
[=] { return cfg->v1.SignalStrengthRCChannelNb==0xff?0:cfg->v1.SignalStrengthRCChannelNb+1; },
[=](int32_t newValue) { newValue?cfg->v1.SignalStrengthRCChannelNb = newValue-1:cfg->v1.SignalStrengthRCChannelNb=0xff;});
[=](int32_t newValue) {
newValue?cfg->v1.SignalStrengthRCChannelNb = newValue-1:cfg->v1.SignalStrengthRCChannelNb=0xff;
DIRTY_CMD(cfg, afhds3::DirtyConfig::DC_RX_CMD_RSSI_CHANNEL_SETUP);
});
}
Loading