Refactoring. CAUTION: ERASE your EEPROM again!
This commit is contained in:
@@ -110,6 +110,76 @@ void Pxx1Pulses<PxxTransport>::addExtraFlags(uint8_t module)
|
||||
PxxTransport::addByte(extra_flags);
|
||||
}
|
||||
|
||||
template <class PxxTransport>
|
||||
void Pxx1Pulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, uint8_t sendUpperChannels)
|
||||
{
|
||||
uint16_t pulseValue = 0;
|
||||
uint16_t pulseValueLow = 0;
|
||||
|
||||
for (int8_t i=0; i<8; i++) {
|
||||
if (sendFailsafe) {
|
||||
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
|
||||
pulseValue = (i < sendUpperChannels ? 4095 : 2047);
|
||||
}
|
||||
else if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) {
|
||||
pulseValue = (i < sendUpperChannels ? 2048 : 0);
|
||||
}
|
||||
else {
|
||||
if (i < sendUpperChannels) {
|
||||
int16_t failsafeValue = g_model.failsafeChannels[8+i];
|
||||
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
|
||||
pulseValue = 4095;
|
||||
}
|
||||
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
|
||||
pulseValue = 2048;
|
||||
}
|
||||
else {
|
||||
failsafeValue += 2*PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
|
||||
pulseValue = limit(2049, (failsafeValue * 512 / 682) + 3072, 4094);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int16_t failsafeValue = g_model.failsafeChannels[i];
|
||||
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
|
||||
pulseValue = 2047;
|
||||
}
|
||||
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
|
||||
pulseValue = 0;
|
||||
}
|
||||
else {
|
||||
failsafeValue += 2*PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
|
||||
pulseValue = limit(1, (failsafeValue * 512 / 682) + 1024, 2046);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (i < sendUpperChannels) {
|
||||
int channel = 8 + g_model.moduleData[port].channelsStart + i;
|
||||
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
|
||||
pulseValue = limit(2049, (value * 512 / 682) + 3072, 4094);
|
||||
}
|
||||
else if (i < sentModuleChannels(port)) {
|
||||
int channel = g_model.moduleData[port].channelsStart + i;
|
||||
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
|
||||
pulseValue = limit(1, (value * 512 / 682) + 1024, 2046);
|
||||
}
|
||||
else {
|
||||
pulseValue = 1024;
|
||||
}
|
||||
}
|
||||
|
||||
if (i & 1) {
|
||||
PxxTransport::addByte(pulseValueLow); // Low byte of channel
|
||||
PxxTransport::addByte(((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4)); // 4 bits each from 2 channels
|
||||
PxxTransport::addByte(pulseValue >> 4); // High byte of channel
|
||||
}
|
||||
else {
|
||||
pulseValueLow = pulseValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class PxxTransport>
|
||||
void Pxx1Pulses<PxxTransport>::add8ChannelsFrame(uint8_t module, uint8_t sendUpperChannels)
|
||||
{
|
||||
@@ -128,7 +198,7 @@ void Pxx1Pulses<PxxTransport>::add8ChannelsFrame(uint8_t module, uint8_t sendUpp
|
||||
PxxTransport::addByte(0);
|
||||
|
||||
// Channels
|
||||
PxxPulses<PxxTransport>::addChannels(module, flag1 & PXX_SEND_FAILSAFE, sendUpperChannels);
|
||||
addChannels(module, flag1 & PXX_SEND_FAILSAFE, sendUpperChannels);
|
||||
|
||||
// Extra flags
|
||||
addExtraFlags(module);
|
||||
|
||||
Reference in New Issue
Block a user