From bc476e19873918709fa5c26d4ade88dcd19e4d50 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 18 Nov 2016 14:12:43 -0200 Subject: [PATCH] AP_ADC: fix ADS1115 instantiation This can't be called on constructor since hal may not be initialized at that time. --- libraries/AP_ADC/AP_ADC_ADS1115.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/AP_ADC/AP_ADC_ADS1115.cpp b/libraries/AP_ADC/AP_ADC_ADS1115.cpp index f1a35412e5..4bc5d8af5f 100644 --- a/libraries/AP_ADC/AP_ADC_ADS1115.cpp +++ b/libraries/AP_ADC/AP_ADC_ADS1115.cpp @@ -109,7 +109,7 @@ static const uint16_t mux_table[ADS1115_CHANNELS_COUNT] = { AP_ADC_ADS1115::AP_ADC_ADS1115() - : _dev(hal.i2c_mgr->get_device(ADS1115_I2C_BUS, ADS1115_I2C_ADDR)) + : _dev{} , _gain(ADS1115_PGA_4P096) , _channel_to_read(0) { @@ -123,6 +123,11 @@ AP_ADC_ADS1115::~AP_ADC_ADS1115() bool AP_ADC_ADS1115::init() { + _dev = hal.i2c_mgr->get_device(ADS1115_I2C_BUS, ADS1115_I2C_ADDR); + if (!_dev) { + return false; + } + _gain = ADS1115_PGA_4P096; _dev->register_periodic_callback(100000, FUNCTOR_BIND_MEMBER(&AP_ADC_ADS1115::_update, bool));