1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

rcvr activity: Speed up activity acquisition

Activity detection logic can now move through
the active receivers more quickly.
This commit is contained in:
Stacey Sheldon 2011-08-24 08:49:34 -04:00
parent 6514fd95c7
commit a72c657e21
2 changed files with 92 additions and 70 deletions

View File

@ -89,7 +89,7 @@ static bool okToArm(void);
static bool validInputRange(int16_t min, int16_t max, uint16_t value);
#define RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP 12
#define RCVR_ACTIVITY_MONITOR_MIN_RANGE 5
#define RCVR_ACTIVITY_MONITOR_MIN_RANGE 10
struct rcvr_activity_fsm {
ManualControlSettingsChannelGroupsOptions group;
uint16_t prev[RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP];
@ -347,31 +347,23 @@ static void resetRcvrActivity(struct rcvr_activity_fsm * fsm)
fsm->sample_count = 0;
}
static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm)
static void updateRcvrActivitySample(uint32_t rcvr_id, uint16_t samples[], uint8_t max_channels) {
for (uint8_t channel = 0; channel < max_channels; channel++) {
samples[channel] = PIOS_RCVR_Read(rcvr_id, channel);
}
}
static bool updateRcvrActivityCompare(uint32_t rcvr_id, struct rcvr_activity_fsm * fsm)
{
bool activity_updated = false;
if (fsm->group >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
/* We're out of range, reset things */
resetRcvrActivity(fsm);
}
extern uint32_t pios_rcvr_group_map[];
if (!pios_rcvr_group_map[fsm->group]) {
/* Unbound group, skip it */
goto group_completed;
}
/* Sample the channel */
/* Compare the current value to the previous sampled value */
for (uint8_t channel = 0;
channel < RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP;
channel++) {
if (fsm->sample_count == 0) {
fsm->prev[channel] = PIOS_RCVR_Read(pios_rcvr_group_map[fsm->group], channel);
} else {
uint16_t delta;
uint16_t prev = fsm->prev[channel];
uint16_t curr = PIOS_RCVR_Read(pios_rcvr_group_map[fsm->group], channel);
uint16_t curr = PIOS_RCVR_Read(rcvr_id, channel);
if (curr > prev) {
delta = curr - prev;
} else {
@ -412,31 +404,61 @@ static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm)
activity_updated = true;
}
}
}
if (++fsm->sample_count < 2) {
return (activity_updated);
}
static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm)
{
bool activity_updated = false;
if (fsm->group >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
/* We're out of range, reset things */
resetRcvrActivity(fsm);
}
extern uint32_t pios_rcvr_group_map[];
if (!pios_rcvr_group_map[fsm->group]) {
/* Unbound group, skip it */
goto group_completed;
}
if (fsm->sample_count == 0) {
/* Take a sample of each channel in this group */
updateRcvrActivitySample(pios_rcvr_group_map[fsm->group],
fsm->prev,
NELEMENTS(fsm->prev));
fsm->sample_count++;
return (false);
}
/* Compare with previous sample */
activity_updated = updateRcvrActivityCompare(pios_rcvr_group_map[fsm->group], fsm);
group_completed:
/* Reset the sample counter */
fsm->sample_count = 0;
/*
* Group Completed
*/
group_completed:
/* Start over at channel zero */
if (++fsm->group < MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
return (activity_updated);
}
/*
* All groups completed
*/
/* Start over at group zero */
/* Find the next active group, but limit search so we can't loop forever here */
for (uint8_t i = 0; i < MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE; i++) {
/* Move to the next group */
fsm->group++;
if (fsm->group >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
/* Wrap back to the first group */
fsm->group = 0;
}
if (pios_rcvr_group_map[fsm->group]) {
/*
* Found an active group, take a sample here to avoid an
* extra 20ms delay in the main thread so we can speed up
* this algorithm.
*/
updateRcvrActivitySample(pios_rcvr_group_map[fsm->group],
fsm->prev,
NELEMENTS(fsm->prev));
fsm->sample_count++;
break;
}
}
return (activity_updated);
}

View File

@ -542,7 +542,7 @@ void ConfigInputWidget::identifyControls()
++debounce;
lastChannel.group= currentChannel.group;
lastChannel.number=currentChannel.number;
if(!usedChannels.contains(lastChannel) && debounce>5)
if(!usedChannels.contains(lastChannel) && debounce>1)
{
debounce=0;
usedChannels.append(lastChannel);