From 087b1fa196e1fffe6b3bab1d4630da2f8df7b1e7 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 17 Dec 2012 16:32:51 -0800 Subject: [PATCH] AP_HAL_AVR: AnalogIn returns new ADCSource each time a channel is requested * fixes a bug where multiple sources created as pin -1, then change to appropriate pin on mavlink messages. Make treat each creation as distinct object. --- libraries/AP_HAL_AVR/AnalogIn.h | 1 - libraries/AP_HAL_AVR/AnalogIn_Common.cpp | 11 +---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/libraries/AP_HAL_AVR/AnalogIn.h b/libraries/AP_HAL_AVR/AnalogIn.h index b2a750d924..e60b3c6205 100644 --- a/libraries/AP_HAL_AVR/AnalogIn.h +++ b/libraries/AP_HAL_AVR/AnalogIn.h @@ -55,7 +55,6 @@ public: AP_HAL::AnalogSource* channel(int16_t n, float prescale); protected: - static ADCSource* _find_or_create_channel(int16_t num, float scale); static ADCSource* _create_channel(int16_t num, float scale); static void _register_channel(ADCSource*); static void _timer_event(uint32_t); diff --git a/libraries/AP_HAL_AVR/AnalogIn_Common.cpp b/libraries/AP_HAL_AVR/AnalogIn_Common.cpp index 92b10258d5..4a289f4b01 100644 --- a/libraries/AP_HAL_AVR/AnalogIn_Common.cpp +++ b/libraries/AP_HAL_AVR/AnalogIn_Common.cpp @@ -31,15 +31,6 @@ void AVRAnalogIn::init(void* machtnichts) { _register_channel(&_vcc); } -ADCSource* AVRAnalogIn::_find_or_create_channel(int16_t pin, float scale) { - for(int16_t i = 0; i < _num_channels; i++) { - if (_channels[i]->_pin == pin) { - return _channels[i]; - } - } - return _create_channel(pin, scale); -} - ADCSource* AVRAnalogIn::_create_channel(int16_t chnum, float scale) { ADCSource *ch = new ADCSource(chnum, scale); _register_channel(ch); @@ -121,7 +112,7 @@ AP_HAL::AnalogSource* AVRAnalogIn::channel(int16_t ch, float scale) { if (ch == ANALOG_INPUT_BOARD_VCC) { return &_vcc; } else { - return _find_or_create_channel(ch, scale); + return _create_channel(ch, scale); } }