Skip to content

Commit 056973f

Browse files
authored
Merge pull request #3 from sparkfun/work
Make setting device address actually do something.
2 parents fa3eb7a + dc395ce commit 056973f

File tree

4 files changed

+34
-41
lines changed

4 files changed

+34
-41
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun AS7331 Arduino Library
2-
version=2.0.0
2+
version=2.1.0
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=An Arduino library to make use of the Qwiic and Qwiic Mini AS7331 Spectral UV Sensor

src/SparkFun_AS7331.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SfeAS7331ArdI2C : public SfeAS7331Driver
5050
if(!isConnected())
5151
return false;
5252

53-
return SfeAS7331Driver::begin(address);
53+
return SfeAS7331Driver::begin();
5454
}
5555

5656
/// @brief Checks to see if the AS7331 is connected.
@@ -63,6 +63,34 @@ class SfeAS7331ArdI2C : public SfeAS7331Driver
6363
return (kDefaultAS7331DeviceID == getDeviceID());
6464
}
6565

66+
/// @brief Sets the address that the bus uses to communicate with the sensor.
67+
/// @param deviceAddress Device address to use.
68+
/// @return True if a valid address is set.
69+
bool setDeviceAddress(const uint8_t &deviceAddress)
70+
{
71+
switch(deviceAddress)
72+
{
73+
// If it's any of the allowed addresses, set it.
74+
case kDefaultAS7331Addr:
75+
case kSecondaryAS7331Addr:
76+
case kTertiaryAS7331Addr:
77+
case kQuaternaryAS7331Addr:
78+
_theI2CBus.setAddress(deviceAddress);
79+
break;
80+
default: // If it's invalid, return false.
81+
return false;
82+
break;
83+
}
84+
return true;
85+
}
86+
87+
/// @brief Gets the currently configured device address.
88+
/// @return device address.
89+
uint8_t getDeviceAddress(void)
90+
{
91+
return _theI2CBus.address();
92+
}
93+
6694
private:
6795
sfeTkArdI2C _theI2CBus;
6896
};

src/sfeAS7331.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "sfeAS7331.h"
22

3-
bool SfeAS7331Driver::begin(const uint8_t &deviceAddress, sfeTkIBus *theBus)
3+
bool SfeAS7331Driver::begin(sfeTkIBus *theBus)
44
{
55
// Nullptr check.
66
if (!_theBus && !theBus)
@@ -10,10 +10,6 @@ bool SfeAS7331Driver::begin(const uint8_t &deviceAddress, sfeTkIBus *theBus)
1010
if (theBus != nullptr)
1111
setCommunicationBus(theBus);
1212

13-
// If the address passed in isn't the default, set the new address.
14-
if (kDefaultAS7331Addr != deviceAddress)
15-
setDeviceAddress(deviceAddress);
16-
1713
// Get the device setup and ready.
1814
return runDefaultSetup();
1915
}
@@ -65,27 +61,6 @@ void SfeAS7331Driver::setCommunicationBus(sfeTkIBus *theBus)
6561
_theBus = theBus;
6662
}
6763

68-
void SfeAS7331Driver::setDeviceAddress(const uint8_t &deviceAddress)
69-
{
70-
switch(deviceAddress)
71-
{
72-
// If it's any of the allowed addresses, set it.
73-
case kDefaultAS7331Addr:
74-
case kSecondaryAS7331Addr:
75-
case kTertiaryAS7331Addr:
76-
case kQuaternaryAS7331Addr:
77-
_devAddress = deviceAddress;
78-
break;
79-
default: // Default to doing nothing.
80-
break;
81-
}
82-
}
83-
84-
uint8_t SfeAS7331Driver::getDeviceAddress(void)
85-
{
86-
return _devAddress;
87-
}
88-
8964
bool SfeAS7331Driver::runDefaultSetup(const bool &runSoftReset)
9065
{
9166
// Nullptr check.

src/sfeAS7331.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ class SfeAS7331Driver
276276
public:
277277
// Default initialization values based on the datasheet. See SfeAS7331Driver::setDefaultSettings for
278278
// an explanation of the values.
279-
SfeAS7331Driver(uint8_t address = kDefaultAS7331Addr)
280-
: _devAddress{address}, _theBus{nullptr}, _breakTime{25}, _numEdges{1}, _readyPinMode{false},
279+
SfeAS7331Driver()
280+
: _theBus{nullptr}, _breakTime{25}, _numEdges{1}, _readyPinMode{false},
281281
_dividerEnabled{false}, _tempConvEnabled{true}, _indexMode{true}, _standbyState{false}, _startState{false},
282282
_powerDownEnableState{true}, _opMode{DEVICE_MODE_CFG}, _sensorGain{GAIN_2}, _cclk{CCLK_1_024_MHZ},
283283
_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
287287

288288
/// @brief This method is called to initialize the AS7331 device through the
289289
/// specified bus.
290-
/// @param deviceAddress I2C address for the device.
291290
/// @param theBus Pointer to the bus object.
292291
/// @return True if successful, false if it fails.
293-
bool begin(const uint8_t &deviceAddress = kDefaultAS7331Addr, sfeTkIBus *theBus = nullptr);
292+
bool begin(sfeTkIBus *theBus = nullptr);
294293

295294
/// @brief Requests the device ID from the sensor.
296295
/// @return The device ID of the sensor.
@@ -300,14 +299,6 @@ class SfeAS7331Driver
300299
/// @param theBus Bus to set as the communication devie.
301300
void setCommunicationBus(sfeTkIBus *theBus);
302301

303-
/// @brief Sets the address that the bus uses to communicate with the sensor.
304-
/// @param deviceAddress Device address to use.
305-
void setDeviceAddress(const uint8_t &deviceAddress);
306-
307-
/// @brief Gets the currently configured device address.
308-
/// @return device address.
309-
uint8_t getDeviceAddress(void);
310-
311302
/// @brief Helper class that sets up the sensor and state in the POR
312303
/// configuration.
313304
/// @param runSoftReset Flag that runs the soft reset function to reset the
@@ -660,7 +651,6 @@ class SfeAS7331Driver
660651
void setDefaultSettings(void);
661652

662653
sfeTkIBus *_theBus; // Pointer to bus device.
663-
uint8_t _devAddress; // Device's I2C address.
664654

665655
uint8_t _breakTime; // Local config value. Value is in us/8. EX: _breakTime = 20 means 20*8 = 160us.
666656
uint8_t _numEdges; // Local config value. Edges seen on SYN pin before ending conversion in SYND mode.

0 commit comments

Comments
 (0)