Skip to content

Commit

Permalink
Implemented proper logic for number of channels (incl. start channel)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Mar 21, 2022
1 parent ae29df9 commit 53ee863
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
5 changes: 4 additions & 1 deletion radio/src/gui/colorlcd/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,10 @@ class ModuleWindow : public FormGroup {
});
bindButton->setCheckHandler([=]() {
if (moduleState[moduleIdx].mode != MODULE_MODE_BIND) {
bindButton->check(false);
if (bindButton->checked()) {
bindButton->check(false);
this->invalidate();
}
}
#if defined(MULTIMODULE)
if (isModuleMultimodule(moduleIdx) &&
Expand Down
9 changes: 5 additions & 4 deletions radio/src/gui/gui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ inline uint8_t MODULE_CHANNELS_ROWS(int moduleIdx)
return 1;
else
return 0;
}
else if (isModuleDSM2(moduleIdx) || isModuleCrossfire(moduleIdx) || isModuleGhost(moduleIdx) || isModuleSBUS(moduleIdx)) {
} else if (isModuleDSM2(moduleIdx) || isModuleCrossfire(moduleIdx) ||
isModuleGhost(moduleIdx) || isModuleSBUS(moduleIdx) ||
isModuleDSMP(moduleIdx)) {
// fixed number of channels
return 0;
}
else {
} else {
return 1;
}
}
Expand Down
20 changes: 11 additions & 9 deletions radio/src/pulses/dsm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ void setupPulsesLemonDSMP()
reset_dsm2_buffer();

const auto& md = g_model.moduleData[EXTERNAL_MODULE];
// TODO: sanetize 'channels'

uint8_t start_channel = md.channelsStart;
auto channels = md.getChannelsCount();
auto flags = md.dsmp.flags;
auto flags = md.dsmp.flags & 0x3F;

// Force setup packet in Bind mode.
auto module_mode = getModuleMode(EXTERNAL_MODULE);
Expand Down Expand Up @@ -170,35 +171,36 @@ void setupPulsesLemonDSMP()

} else {

uint8_t start_channel = 0;
uint8_t current_channel = 0;
if (pass == 2) {
start_channel += 7;
current_channel += 7;
}

// Send channels
for (int i=0; i<7; i++) {

uint8_t channel = start_channel + i;
if (channel < channels) {
if (current_channel < channels) {

uint8_t channel = start_channel + current_channel;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
uint16_t pulse;

// Use 11-bit ?
if (flags & (1 << 2)) {
pulse = limit(0, ((value*349)>>9)+1024, 2047) | (channel << 11);
pulse = limit(0, ((value*349)>>9)+1024, 2047) | (current_channel << 11);
} else {
pulse = limit(0, ((value*13)>>5)+512, 1023) | (channel << 10);
pulse = limit(0, ((value*13)>>5)+512, 1023) | (current_channel << 10);
}

sendByteDSMP( pulse >> 8 );
sendByteDSMP( pulse & 0xFF );
} else {
// Outside of announced number of channels:
// -> send invalid values
// -> send invalid value
sendByteDSMP( 0xFF );
sendByteDSMP( 0xFF );
}
current_channel++;
}
}

Expand Down
5 changes: 5 additions & 0 deletions radio/src/pulses/modules_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ inline int8_t maxModuleChannels_M8(uint8_t moduleIdx)
return 10;
} else if (isModuleMultimoduleDSM2(moduleIdx)) {
return 4; // 12 channels
} else if (isModuleDSMP(moduleIdx) &&
(g_model.moduleData[moduleIdx].dsmp.flags != 0)) {
return g_model.moduleData[moduleIdx].channelsCount;
} else {
return maxChannelsModules_M8[g_model.moduleData[moduleIdx].type];
}
Expand All @@ -495,6 +498,8 @@ inline int8_t minModuleChannels(uint8_t idx)
return GHOST_CHANNELS_COUNT;
else if (isModuleSBUS(idx))
return 16;
else if (isModuleDSMP(idx))
return maxModuleChannels(idx);
else
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/telemetry/spektrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void processDSMBindPacket(uint8_t module, const uint8_t *packet)
if (g_model.moduleData[module].type == MODULE_TYPE_LEMON_DSMP) {

// save flags
g_model.moduleData[module].dsmp.flags = packet[0] & 0x3F;
g_model.moduleData[module].dsmp.flags = packet[0];

// save number of channels
uint8_t channels = packet[2];
Expand Down

0 comments on commit 53ee863

Please sign in to comment.