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:
parent
1c764c4001
commit
acc124cacb
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user