1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP-1625: DSM: more robust detection of resolution

This allows switching back and forth between 10 and 11 bit
code which prevents getting locked up in one or the other.
It also avoids a situation that can cause an infinite
recursion.

This changeset is cherry-picked from TauLabs (b7eaf87502085666d9738ae16c66170f187f3981).
Thanks to Taulabs for improving OpenPilot's DSM autodetect feature.
This commit is contained in:
Mathieu Rondonneau 2014-12-30 21:29:06 -08:00
parent 1c764c4001
commit acc124cacb
2 changed files with 28 additions and 4 deletions

View File

@ -213,12 +213,24 @@ static int PIOS_DSM_UnrollChannels(struct pios_dsm_dev *dsm_dev)
/* extract and save the channel value */
uint8_t channel_num = (word >> resolution) & 0x0f;
if (channel_num < PIOS_DSM_NUM_INPUTS) {
if (channel_log & (1 << channel_num)) {
/* Found duplicate! */
/* Update resolution and restart processing the current frame. */
/* Found duplicate. This should happen when in 11 bit */
/* mode and the data is 10 bits */
if (resolution == 10)
return -1;
resolution = 10;
return PIOS_DSM_UnrollChannels(dsm_dev);
}
if ((channel_log & 0xFF) == 0x55) {
/* This pattern indicates 10 bit pattern */
if (resolution == 11)
return -1;
resolution = 11;
return PIOS_DSM_UnrollChannels(dsm_dev);
}
state->channel_data[channel_num] = (word & mask);
/* keep track of this channel */
channel_log |= (1 << channel_num);

View File

@ -215,12 +215,24 @@ static int PIOS_DSM_UnrollChannels(struct pios_dsm_dev *dsm_dev)
/* extract and save the channel value */
uint8_t channel_num = (word >> resolution) & 0x0f;
if (channel_num < PIOS_DSM_NUM_INPUTS) {
if (channel_log & (1 << channel_num)) {
/* Found duplicate! */
/* Update resolution and restart processing the current frame. */
/* Found duplicate. This should happen when in 11 bit */
/* mode and the data is 10 bits */
if (resolution == 10)
return -1;
resolution = 10;
return PIOS_DSM_UnrollChannels(dsm_dev);
}
if ((channel_log & 0xFF) == 0x55) {
/* This pattern indicates 10 bit pattern */
if (resolution == 11)
return -1;
resolution = 11;
return PIOS_DSM_UnrollChannels(dsm_dev);
}
state->channel_data[channel_num] = (word & mask);
/* keep track of this channel */
channel_log |= (1 << channel_num);