diff --git a/library.properties b/library.properties index 5ac192a..01816d9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun AS7331 Arduino Library -version=2.0.0 +version=2.1.0 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=An Arduino library to make use of the Qwiic and Qwiic Mini AS7331 Spectral UV Sensor diff --git a/src/SparkFun_AS7331.h b/src/SparkFun_AS7331.h index 76d3a22..1555e03 100644 --- a/src/SparkFun_AS7331.h +++ b/src/SparkFun_AS7331.h @@ -50,7 +50,7 @@ class SfeAS7331ArdI2C : public SfeAS7331Driver if(!isConnected()) return false; - return SfeAS7331Driver::begin(address); + return SfeAS7331Driver::begin(); } /// @brief Checks to see if the AS7331 is connected. @@ -63,6 +63,34 @@ class SfeAS7331ArdI2C : public SfeAS7331Driver return (kDefaultAS7331DeviceID == getDeviceID()); } + /// @brief Sets the address that the bus uses to communicate with the sensor. + /// @param deviceAddress Device address to use. + /// @return True if a valid address is set. + bool setDeviceAddress(const uint8_t &deviceAddress) + { + switch(deviceAddress) + { + // If it's any of the allowed addresses, set it. + case kDefaultAS7331Addr: + case kSecondaryAS7331Addr: + case kTertiaryAS7331Addr: + case kQuaternaryAS7331Addr: + _theI2CBus.setAddress(deviceAddress); + break; + default: // If it's invalid, return false. + return false; + break; + } + return true; + } + + /// @brief Gets the currently configured device address. + /// @return device address. + uint8_t getDeviceAddress(void) + { + return _theI2CBus.address(); + } + private: sfeTkArdI2C _theI2CBus; }; diff --git a/src/sfeAS7331.cpp b/src/sfeAS7331.cpp index 7e168a0..97158df 100644 --- a/src/sfeAS7331.cpp +++ b/src/sfeAS7331.cpp @@ -1,6 +1,6 @@ #include "sfeAS7331.h" -bool SfeAS7331Driver::begin(const uint8_t &deviceAddress, sfeTkIBus *theBus) +bool SfeAS7331Driver::begin(sfeTkIBus *theBus) { // Nullptr check. if (!_theBus && !theBus) @@ -10,10 +10,6 @@ bool SfeAS7331Driver::begin(const uint8_t &deviceAddress, sfeTkIBus *theBus) if (theBus != nullptr) setCommunicationBus(theBus); - // If the address passed in isn't the default, set the new address. - if (kDefaultAS7331Addr != deviceAddress) - setDeviceAddress(deviceAddress); - // Get the device setup and ready. return runDefaultSetup(); } @@ -65,27 +61,6 @@ void SfeAS7331Driver::setCommunicationBus(sfeTkIBus *theBus) _theBus = theBus; } -void SfeAS7331Driver::setDeviceAddress(const uint8_t &deviceAddress) -{ - switch(deviceAddress) - { - // If it's any of the allowed addresses, set it. - case kDefaultAS7331Addr: - case kSecondaryAS7331Addr: - case kTertiaryAS7331Addr: - case kQuaternaryAS7331Addr: - _devAddress = deviceAddress; - break; - default: // Default to doing nothing. - break; - } -} - -uint8_t SfeAS7331Driver::getDeviceAddress(void) -{ - return _devAddress; -} - bool SfeAS7331Driver::runDefaultSetup(const bool &runSoftReset) { // Nullptr check. diff --git a/src/sfeAS7331.h b/src/sfeAS7331.h index a441ccf..e3a1447 100644 --- a/src/sfeAS7331.h +++ b/src/sfeAS7331.h @@ -276,8 +276,8 @@ class SfeAS7331Driver public: // Default initialization values based on the datasheet. See SfeAS7331Driver::setDefaultSettings for // an explanation of the values. - SfeAS7331Driver(uint8_t address = kDefaultAS7331Addr) - : _devAddress{address}, _theBus{nullptr}, _breakTime{25}, _numEdges{1}, _readyPinMode{false}, + SfeAS7331Driver() + : _theBus{nullptr}, _breakTime{25}, _numEdges{1}, _readyPinMode{false}, _dividerEnabled{false}, _tempConvEnabled{true}, _indexMode{true}, _standbyState{false}, _startState{false}, _powerDownEnableState{true}, _opMode{DEVICE_MODE_CFG}, _sensorGain{GAIN_2}, _cclk{CCLK_1_024_MHZ}, _mmode{MEAS_MODE_CMD}, _conversionTime{TIME_64MS}, _dividerRange{DIV_2}, _uva{0.0f}, _uvb{0.0f}, _uvc{0.0f}, @@ -287,10 +287,9 @@ class SfeAS7331Driver /// @brief This method is called to initialize the AS7331 device through the /// specified bus. - /// @param deviceAddress I2C address for the device. /// @param theBus Pointer to the bus object. /// @return True if successful, false if it fails. - bool begin(const uint8_t &deviceAddress = kDefaultAS7331Addr, sfeTkIBus *theBus = nullptr); + bool begin(sfeTkIBus *theBus = nullptr); /// @brief Requests the device ID from the sensor. /// @return The device ID of the sensor. @@ -300,14 +299,6 @@ class SfeAS7331Driver /// @param theBus Bus to set as the communication devie. void setCommunicationBus(sfeTkIBus *theBus); - /// @brief Sets the address that the bus uses to communicate with the sensor. - /// @param deviceAddress Device address to use. - void setDeviceAddress(const uint8_t &deviceAddress); - - /// @brief Gets the currently configured device address. - /// @return device address. - uint8_t getDeviceAddress(void); - /// @brief Helper class that sets up the sensor and state in the POR /// configuration. /// @param runSoftReset Flag that runs the soft reset function to reset the @@ -660,7 +651,6 @@ class SfeAS7331Driver void setDefaultSettings(void); sfeTkIBus *_theBus; // Pointer to bus device. - uint8_t _devAddress; // Device's I2C address. uint8_t _breakTime; // Local config value. Value is in us/8. EX: _breakTime = 20 means 20*8 = 160us. uint8_t _numEdges; // Local config value. Edges seen on SYN pin before ending conversion in SYND mode.