Implemented proper logic for number of channels (incl. start channel)

This commit is contained in:
Raphael Coeffic
2022-03-24 10:40:17 +01:00
committed by Raphael Coeffic
parent 9e40aaa215
commit 7922afd9ca
5 changed files with 26 additions and 15 deletions
+4 -1
View File
@@ -1129,7 +1129,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) &&
+5 -4
View File
@@ -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;
}
}
+11 -9
View File
@@ -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);
@@ -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++;
}
}
+5
View File
@@ -482,6 +482,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];
}
@@ -500,6 +503,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;
}
+1 -1
View File
@@ -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];