From 72625d99710e28ffc9b356bf4b83429db41413e8 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 6 Sep 2011 16:35:28 -0500 Subject: [PATCH] PiOS RCVR: Make the public API use a 1 based indexing for channel numbers. This may or may not get into next, but if so anyone following it MUST reconfigure their inputs. --- flight/Modules/ManualControl/manualcontrol.c | 13 +++++++------ flight/PiOS/Common/pios_rcvr.c | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index eab3605be..95b519037 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -398,8 +398,9 @@ static void resetRcvrActivity(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); + for (uint8_t channel = 1; channel <= max_channels; channel++) { + // Subtract 1 because channels are 1 indexed + samples[channel - 1] = PIOS_RCVR_Read(rcvr_id, channel); } } @@ -408,12 +409,12 @@ static bool updateRcvrActivityCompare(uint32_t rcvr_id, struct rcvr_activity_fsm bool activity_updated = false; /* Compare the current value to the previous sampled value */ - for (uint8_t channel = 0; - channel < RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP; + for (uint8_t channel = 1; + channel <= RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP; channel++) { uint16_t delta; - uint16_t prev = fsm->prev[channel]; - uint16_t curr = PIOS_RCVR_Read(rcvr_id, channel); + uint16_t prev = fsm->prev[channel - 1]; // Subtract 1 because channels are 1 indexed + uint16_t curr = PIOS_RCVR_Read(rcvr_id, channel); if (curr > prev) { delta = curr - prev; } else { diff --git a/flight/PiOS/Common/pios_rcvr.c b/flight/PiOS/Common/pios_rcvr.c index 02778bad4..0f3988d7f 100644 --- a/flight/PiOS/Common/pios_rcvr.c +++ b/flight/PiOS/Common/pios_rcvr.c @@ -87,6 +87,12 @@ out_fail: */ int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel) { + // Publicly facing API uses channel 1 for first channel + if(channel == 0) + return PIOS_RCVR_INVALID; + else + channel--; + if (rcvr_id == 0) return PIOS_RCVR_NODRIVER;