From 8f99a12374c73c6054e149607c257bf58a61413d Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 6 Dec 2012 17:35:59 -0800 Subject: [PATCH] AP_ADC_AnalogSource: fix for new AnalogIn interface --- .../AP_ADC_AnalogSource/AP_ADC_AnalogSource.cpp | 12 +++++++++++- libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.h | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.cpp b/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.cpp index 373268355b..d7debf0202 100644 --- a/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.cpp +++ b/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.cpp @@ -1,12 +1,22 @@ #include "AP_ADC_AnalogSource.h" -float AP_ADC_AnalogSource::read() { +/* Unfortunately we don't have a valid implementaton for read_latest - we + * only have access to the average from the ADC driver. Not really a big deal + * in our application currently. */ + +float AP_ADC_AnalogSource::read_latest() { + return read_average(); +} + +float AP_ADC_AnalogSource::read_average() { float fullscale = _adc->Ch(_ch); float scaled = _prescale * fullscale; return scaled; } + + void AP_ADC_AnalogSource::set_pin(uint8_t machtnichts) { /* it would be an error to call this * but for now we'll leave it a no-op. */ diff --git a/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.h b/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.h index 15dd6a5858..0ec792e778 100644 --- a/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.h +++ b/libraries/AP_ADC_AnalogSource/AP_ADC_AnalogSource.h @@ -11,7 +11,8 @@ public: AP_ADC_AnalogSource( AP_ADC * adc, uint8_t ch, float prescale = 1.0 ) : _adc(adc), _ch(ch), _prescale(prescale) {} - float read(void); + float read_average(void); + float read_latest(void); void set_pin(uint8_t); private: