This commit is contained in:
Bertrand Songis
2015-10-14 23:47:26 +02:00
parent d0f6c59b8a
commit 0bf2a204e2
+47 -30
View File
@@ -173,7 +173,7 @@ void putPcmHead(unsigned int port)
void setupPulsesPXX(unsigned int port) void setupPulsesPXX(unsigned int port)
{ {
uint16_t chan=0, chan_low=0; uint16_t pulseValue=0, pulseValueLow=0;
modulePulsesData[port].pxx.ptr = modulePulsesData[port].pxx.pulses; modulePulsesData[port].pxx.ptr = modulePulsesData[port].pxx.pulses;
modulePulsesData[port].pxx.pcmValue = 0 ; modulePulsesData[port].pxx.pcmValue = 0 ;
@@ -224,56 +224,73 @@ void setupPulsesPXX(unsigned int port)
for (int i=0; i<8; i++) { for (int i=0; i<8; i++) {
if (flag1 & PXX_SEND_FAILSAFE) { if (flag1 & PXX_SEND_FAILSAFE) {
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) { if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
chan = (i < sendUpperChannels ? 4095 : 2047); pulseValue = (i < sendUpperChannels ? 4095 : 2047);
} }
else if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) { else if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) {
chan = (i < sendUpperChannels ? 2048 : 0); pulseValue = (i < sendUpperChannels ? 2048 : 0);
} }
else { else {
if (i < sendUpperChannels) { if (i < sendUpperChannels) {
int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[8+g_model.moduleData[port].channelsStart+i]; int channel = 8 + g_model.moduleData[port].channelsStart + i;
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[channel];
chan = 4095; if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) pulseValue = 4095;
chan = 2048; }
else else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
chan = limit(2049, PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (failsafeValue * 512 / 682) + 3072, 4094); pulseValue = 2048;
}
else {
failsafeValue += 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(2049, (failsafeValue * 512 / 682) + 3072, 4094);
}
} }
else { else {
int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[g_model.moduleData[port].channelsStart+i]; int channel = g_model.moduleData[port].channelsStart + i;
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[channel];
chan = 2047; if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) pulseValue = 2047;
chan = 0; }
else else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
chan = limit(1, PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (failsafeValue * 512 / 682) + 1024, 2046); pulseValue = 0;
}
else {
failsafeValue += 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(1, (failsafeValue * 512 / 682) + 1024, 2046);
}
} }
} }
} }
else { else {
if (i < sendUpperChannels) if (i < sendUpperChannels) {
chan = limit(2049, PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (channelOutputs[8+g_model.moduleData[port].channelsStart+i] * 512 / 682) + 3072, 4094); int channel = 8 + g_model.moduleData[port].channelsStart + i;
else if (i < NUM_CHANNELS(port)) int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
chan = limit(1, PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (channelOutputs[g_model.moduleData[port].channelsStart+i] * 512 / 682) + 1024, 2046); pulseValue = limit(2049, (value * 512 / 682) + 3072, 4094);
else }
chan = 1024; else if (i < NUM_CHANNELS(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) { if (i & 1) {
putPcmByte(chan_low, port); // Low byte of channel putPcmByte(pulseValueLow, port); // Low byte of channel
putPcmByte(((chan_low >> 8) & 0x0F) | (chan << 4), port); // 4 bits each from 2 channels putPcmByte(((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4), port); // 4 bits each from 2 channels
putPcmByte(chan >> 4, port); // High byte of channel putPcmByte(pulseValue >> 4, port); // High byte of channel
} }
else { else {
chan_low = chan; pulseValueLow = pulseValue;
} }
} }
/* CRC16 */ /* CRC16 */
putPcmByte(0, port); putPcmByte(0, port);
chan = modulePulsesData[port].pxx.pcmCrc; pulseValue = modulePulsesData[port].pxx.pcmCrc;
putPcmByte(chan>>8, port); putPcmByte(pulseValue>>8, port);
putPcmByte(chan, port); putPcmByte(pulseValue, port);
/* Sync */ /* Sync */
putPcmHead(port); putPcmHead(port);