From 68596c6bd9729dbca4263f33f7941f18a82c8997 Mon Sep 17 00:00:00 2001 From: Daniel Joseph Antrim <daniel.joseph.antrim@cern.ch> Date: Fri, 7 May 2021 11:21:00 -0700 Subject: [PATCH] make ADS1015 ctor unambiguous --- src/libDevCom/ADS1015.cpp | 20 +++++++++----------- src/libDevCom/ADS1015.h | 30 +++++++++++++++++------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/libDevCom/ADS1015.cpp b/src/libDevCom/ADS1015.cpp index 4c04fd72..2a34eaf9 100644 --- a/src/libDevCom/ADS1015.cpp +++ b/src/libDevCom/ADS1015.cpp @@ -32,11 +32,9 @@ const std::map<ADS1015::Gain, ADS1015::FullScaleRange> ADS1015::gainToFSRMap = { {ADS1015::Gain::xSIXTEEN, ADS1015::FullScaleRange::FSR_0_256}}; ADS1015::ADS1015(std::shared_ptr<I2CCom> com) - : ADCDevice(std::make_shared<LinearCalibration>(fsrToValMap.at(m_fullscale_range), m_maxValue)) { + : ADCDevice(std::make_shared<LinearCalibration>( + fsrToValMap.at(m_fullscale_range), m_maxValue)) { m_com = com; - - m_fullscale_range = FullScaleRange::FSR_2_048; - m_channelMode = ChannelMode::SingleEnded; } ADS1015& ADS1015::setGain(Gain gain) { @@ -62,7 +60,6 @@ int32_t ADS1015::readCount() { } int32_t ADS1015::readCount(uint8_t channel) { - validateChannel(channel); uint16_t config = 0; @@ -190,7 +187,6 @@ void ADS1015::configStartConversion(uint16_t& config) { config |= static_cast<uint16_t>(Config::CONFIG_OS_SINGLE); } - bool ADS1015::conversionComplete() { uint16_t reg = m_com->read_reg16(static_cast<uint16_t>(Address::POINTER_CONFIG)); @@ -200,19 +196,21 @@ bool ADS1015::conversionComplete() { void ADS1015::validateChannel(uint8_t channel) { uint8_t max_channels; std::string mode; - switch(m_channelMode) { - case ChannelMode::SingleEnded : + switch (m_channelMode) { + case ChannelMode::SingleEnded: max_channels = 4; mode = "SingleEnded"; break; - case ChannelMode::Differential : + case ChannelMode::Differential: max_channels = 2; mode = "Differential"; break; }; - if(channel >= max_channels) { + if (channel >= max_channels) { std::stringstream e; - e << "Invalid channel (=" << static_cast<unsigned>(channel) << ") for ADS1015 channel mode (=" << mode << ") having " << static_cast<unsigned>(max_channels) << " maximum allowed channels"; + e << "Invalid channel (=" << static_cast<unsigned>(channel) + << ") for ADS1015 channel mode (=" << mode << ") having " + << static_cast<unsigned>(max_channels) << " maximum allowed channels"; throw std::out_of_range(e.str()); } } diff --git a/src/libDevCom/ADS1015.h b/src/libDevCom/ADS1015.h index b8a136c7..39550861 100644 --- a/src/libDevCom/ADS1015.h +++ b/src/libDevCom/ADS1015.h @@ -10,12 +10,13 @@ #include "ADCDevice.h" class I2CCom; +// clang-format off /** \brief ADS1015: Low-power, I2C compatible 4-channel 12-bit ADC * * The `ADS1015` class provides a driver for the Texas Instruments low-power, * I2C compatible 4-channel 12-bit ADC. Support for single-shot ADC conversions * is supported across all four channels in single-ended measurement mode. - * + * * [Datasheet](https://www.ti.com/lit/ds/symlink/ads1015.pdf). * * Support for differential measurements are supported in the following @@ -39,13 +40,14 @@ class I2CCom; * adc->setChannelMode(ADS1015::ChannelMode::Differential); * adc->read(); * - * Adjusting the programmable gain amplifier (PGA) of the ADS1015 device is achieved - * via either the `ADS1015::setGain` or `ADS1015::setFullScaleRange` methods. - * The two methods do the same thing, so there is only ever the need to call one - * of them. Each configuration of the PGA has an associated fullscale range (and LSB size), - * as described in Table 1 of the [datasheet](https://www.ti.com/lit/ds/symlink/ads1015.pdf). - * Changing the fullscale range is done via the `ADS1015::FullScaleRange` enumeration - * and changing the gain is done via the `ADS1015::Gain` enumeration: + * Adjusting the programmable gain amplifier (PGA) of the ADS1015 device is + * achieved via either the `ADS1015::setGain` or `ADS1015::setFullScaleRange` + * methods. The two methods do the same thing, so there is only ever the need to + * call one of them. Each configuration of the PGA has an associated fullscale + * range (and LSB size), as described in Table 1 of the + * [datasheet](https://www.ti.com/lit/ds/symlink/ads1015.pdf). Changing the + * fullscale range is done via the `ADS1015::FullScaleRange` enumeration and + * changing the gain is done via the `ADS1015::Gain` enumeration: * * adc->setFullScaleRange(ADS1015::FSR_0_512); * @@ -53,11 +55,13 @@ class I2CCom; * * adc->setGain(ADS1015::Gain::xEIGHT); * - * The default values for the gain and fullscale range of an instance of `ADS1015` are those - * of the default power-up state of the device: a gain of `ADS1015::Gain::XTWO`, - * corresponding to a fullscale range of 2.048 Volts (`ADS1015::FullScaleRange::FSR_2_048`). + * The default values for the gain and fullscale range of an instance of + * `ADS1015` are those of the default power-up state of the device: a gain of + * `ADS1015::Gain::XTWO`, corresponding to a fullscale range of 2.048 Volts + * (`ADS1015::FullScaleRange::FSR_2_048`). * */ +// clang-format on class ADS1015 : public ADCDevice { public: //! \brief Allowed convertible analog full scale ranges associated with each @@ -243,8 +247,8 @@ class ADS1015 : public ADCDevice { // 0x7ff). Only when performing differential measurements do you get the // full 12-bit resolution with the sign bit taking the 12th bit. static const uint32_t m_maxValue = 0x7FF; - FullScaleRange m_fullscale_range; // volts - ChannelMode m_channelMode; + FullScaleRange m_fullscale_range = FullScaleRange::FSR_2_048; // volts + ChannelMode m_channelMode = ChannelMode::SingleEnded; // some helper methods bool conversionComplete(); -- GitLab