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:
parent
6514fd95c7
commit
a72c657e21
@ -89,7 +89,7 @@ static bool okToArm(void);
|
|||||||
static bool validInputRange(int16_t min, int16_t max, uint16_t value);
|
static bool validInputRange(int16_t min, int16_t max, uint16_t value);
|
||||||
|
|
||||||
#define RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP 12
|
#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 {
|
struct rcvr_activity_fsm {
|
||||||
ManualControlSettingsChannelGroupsOptions group;
|
ManualControlSettingsChannelGroupsOptions group;
|
||||||
uint16_t prev[RCVR_ACTIVITY_MONITOR_CHANNELS_PER_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;
|
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;
|
bool activity_updated = false;
|
||||||
|
|
||||||
if (fsm->group >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
/* Compare the current value to the previous sampled value */
|
||||||
/* 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 */
|
|
||||||
for (uint8_t channel = 0;
|
for (uint8_t channel = 0;
|
||||||
channel < RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP;
|
channel < RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP;
|
||||||
channel++) {
|
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 delta;
|
||||||
uint16_t prev = fsm->prev[channel];
|
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) {
|
if (curr > prev) {
|
||||||
delta = curr - prev;
|
delta = curr - prev;
|
||||||
} else {
|
} else {
|
||||||
@ -412,31 +404,61 @@ static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm)
|
|||||||
activity_updated = true;
|
activity_updated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (++fsm->sample_count < 2) {
|
|
||||||
return (activity_updated);
|
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 */
|
/* Reset the sample counter */
|
||||||
fsm->sample_count = 0;
|
fsm->sample_count = 0;
|
||||||
|
|
||||||
/*
|
/* Find the next active group, but limit search so we can't loop forever here */
|
||||||
* Group Completed
|
for (uint8_t i = 0; i < MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE; i++) {
|
||||||
*/
|
/* Move to the next group */
|
||||||
|
fsm->group++;
|
||||||
group_completed:
|
if (fsm->group >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
||||||
/* Start over at channel zero */
|
/* Wrap back to the first group */
|
||||||
if (++fsm->group < MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
|
|
||||||
return (activity_updated);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* All groups completed
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Start over at group zero */
|
|
||||||
fsm->group = 0;
|
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);
|
return (activity_updated);
|
||||||
}
|
}
|
||||||
|
@ -542,7 +542,7 @@ void ConfigInputWidget::identifyControls()
|
|||||||
++debounce;
|
++debounce;
|
||||||
lastChannel.group= currentChannel.group;
|
lastChannel.group= currentChannel.group;
|
||||||
lastChannel.number=currentChannel.number;
|
lastChannel.number=currentChannel.number;
|
||||||
if(!usedChannels.contains(lastChannel) && debounce>5)
|
if(!usedChannels.contains(lastChannel) && debounce>1)
|
||||||
{
|
{
|
||||||
debounce=0;
|
debounce=0;
|
||||||
usedChannels.append(lastChannel);
|
usedChannels.append(lastChannel);
|
||||||
|
Loading…
Reference in New Issue
Block a user