From 61d649e7ac685561d76c008bc23130f4b77305d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Mar 2012 18:31:09 +1100 Subject: [PATCH] AP_ADC: added new_data_available() interface returns true if more samples are available --- libraries/AP_ADC/AP_ADC.h | 3 +++ libraries/AP_ADC/AP_ADC_ADS7844.cpp | 14 ++++++++++++++ libraries/AP_ADC/AP_ADC_ADS7844.h | 4 ++++ libraries/AP_ADC/AP_ADC_HIL.cpp | 6 ++++++ libraries/AP_ADC/AP_ADC_HIL.h | 3 +++ 5 files changed, 30 insertions(+) diff --git a/libraries/AP_ADC/AP_ADC.h b/libraries/AP_ADC/AP_ADC.h index 8bebead3fc..5e6b2d0909 100644 --- a/libraries/AP_ADC/AP_ADC.h +++ b/libraries/AP_ADC/AP_ADC.h @@ -40,6 +40,9 @@ class AP_ADC */ virtual uint32_t Ch6(const uint8_t *channel_numbers, uint16_t *result) = 0; + // check if Ch6() can return new data + virtual bool new_data_available(const uint8_t *channel_numbers) = 0; + private: }; diff --git a/libraries/AP_ADC/AP_ADC_ADS7844.cpp b/libraries/AP_ADC/AP_ADC_ADS7844.cpp index 6e65527519..f216f5a895 100644 --- a/libraries/AP_ADC/AP_ADC_ADS7844.cpp +++ b/libraries/AP_ADC/AP_ADC_ADS7844.cpp @@ -185,6 +185,20 @@ float AP_ADC_ADS7844::Ch(uint8_t ch_num) return ((float)sum)/count; } +// see if Ch6() can return new data +bool AP_ADC_ADS7844::new_data_available(const uint8_t *channel_numbers) +{ + uint8_t i; + + for (i=0; i<6; i++) { + if (_count[channel_numbers[i]] == 0) { + return false; + } + } + return true; +} + + // Read 6 channel values // this assumes that the counts for all of the 6 channels are // equal. This will only be true if we always consistently access a diff --git a/libraries/AP_ADC/AP_ADC_ADS7844.h b/libraries/AP_ADC/AP_ADC_ADS7844.h index 2bd8235b57..73be670b3b 100644 --- a/libraries/AP_ADC/AP_ADC_ADS7844.h +++ b/libraries/AP_ADC/AP_ADC_ADS7844.h @@ -29,6 +29,10 @@ class AP_ADC_ADS7844 : public AP_ADC // Read 6 sensors at once uint32_t Ch6(const uint8_t *channel_numbers, uint16_t *result); + + // check if Ch6 would block + bool new_data_available(const uint8_t *channel_numbers); + bool filter_result; private: diff --git a/libraries/AP_ADC/AP_ADC_HIL.cpp b/libraries/AP_ADC/AP_ADC_HIL.cpp index 80488682ab..e443941642 100644 --- a/libraries/AP_ADC/AP_ADC_HIL.cpp +++ b/libraries/AP_ADC/AP_ADC_HIL.cpp @@ -82,3 +82,9 @@ void AP_ADC_HIL::setHIL(int16_t p, int16_t q, int16_t r, int16_t gyroTemp, // differential pressure setPressure(diffPress); } + +// see if new data is available +bool AP_ADC_HIL::new_data_available(const uint8_t *channel_numbers) +{ + return true; +} diff --git a/libraries/AP_ADC/AP_ADC_HIL.h b/libraries/AP_ADC/AP_ADC_HIL.h index f7bcde465c..d9c53f6fdb 100644 --- a/libraries/AP_ADC/AP_ADC_HIL.h +++ b/libraries/AP_ADC/AP_ADC_HIL.h @@ -38,6 +38,9 @@ class AP_ADC_HIL : public AP_ADC // Read 6 sensors at once uint32_t Ch6(const uint8_t *channel_numbers, uint16_t *result); + // see if Ch6 would block + bool new_data_available(const uint8_t *channel_numbers); + /// // Set the adc raw values given the current rotations rates, // temps, accels, and pressures