Skip to content

Commit 6d787a0

Browse files
committed
getConfigurationRegister: change pointer to reference
1 parent efb80b1 commit 6d787a0

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/SparkFun_ADS1219.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool SfeADS1219Driver::setConversionMode(const ads1219_conversion_mode_config_t
6565
sfe_ads1219_reg_cfg_t config;
6666
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
6767
return false;
68-
config.cm = (uint8_t)mode; // Modify (only) the conversion mode
68+
config.cm = (uint8_t)mode; // Modify (only) the conversion mode
6969
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
7070
}
7171

@@ -76,7 +76,7 @@ bool SfeADS1219Driver::setInputMultiplexer(const ads1219_input_multiplexer_confi
7676
sfe_ads1219_reg_cfg_t config;
7777
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
7878
return false;
79-
config.mux = (uint8_t)mux; // Modify (only) the input multiplexer
79+
config.mux = (uint8_t)mux; // Modify (only) the input multiplexer
8080
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
8181
}
8282

@@ -87,8 +87,8 @@ bool SfeADS1219Driver::setGain(const ads1219_gain_config_t gain)
8787
sfe_ads1219_reg_cfg_t config;
8888
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
8989
return false;
90-
config.gain = (uint8_t)gain; // Modify (only) the gain
91-
_adcGain = gain; // Update the local copy of the gain for voltage conversion
90+
config.gain = (uint8_t)gain; // Modify (only) the gain
91+
_adcGain = gain; // Update the local copy of the gain for voltage conversion
9292
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
9393
}
9494

@@ -99,7 +99,7 @@ bool SfeADS1219Driver::setDataRate(const ads1219_data_rate_config_t rate)
9999
sfe_ads1219_reg_cfg_t config;
100100
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
101101
return false;
102-
config.dr = (uint8_t)rate; // Modify (only) the data rate
102+
config.dr = (uint8_t)rate; // Modify (only) the data rate
103103
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
104104
}
105105

@@ -110,7 +110,7 @@ bool SfeADS1219Driver::setVoltageReference(const ads1219_vref_config_t vRef)
110110
sfe_ads1219_reg_cfg_t config;
111111
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
112112
return false;
113-
config.vref = (uint8_t)vRef; // Modify (only) the voltage reference
113+
config.vref = (uint8_t)vRef; // Modify (only) the voltage reference
114114
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
115115
}
116116

@@ -126,7 +126,8 @@ bool SfeADS1219Driver::readConversion()
126126
if (result)
127127
{
128128
// Data is 3-bytes (24-bits), big-endian (MSB first).
129-
union {
129+
union
130+
{
130131
int32_t i32;
131132
uint32_t u32;
132133
} iu32; // Use a union to avoid signed / unsigned ambiguity
@@ -174,18 +175,19 @@ bool SfeADS1219Driver::dataReady(void)
174175
}
175176

176177
/// @brief Read the ADS1219 Configuration Register into a sfe_ads1219_reg_cfg_t struct.
177-
/// @param config Pointer to the sfe_ads1219_reg_cfg_t struct to hold the register contents.
178+
/// @param config Reference of a sfe_ads1219_reg_cfg_t struct to hold the register contents.
178179
/// @return True if successful, false otherwise.
179-
bool SfeADS1219Driver::getConfigurationRegister(sfe_ads1219_reg_cfg_t *config)
180+
bool SfeADS1219Driver::getConfigurationRegister(sfe_ads1219_reg_cfg_t &config)
180181
{
181-
return (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config->byte) == kSTkErrOk); // Read the config register
182+
return (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) == kSTkErrOk); // Read the config register
182183
}
183184

184185
/// @brief Write a sfe_ads1219_reg_cfg_t struct into the ADS1219 Configuration Register.
185186
/// @param config A sfe_ads1219_reg_cfg_t struct holding the register contents.
186187
/// @return True if successful, false otherwise.
187188
bool SfeADS1219Driver::setConfigurationRegister(sfe_ads1219_reg_cfg_t config)
188189
{
190+
_adcGain = config.gain; // Update the local copy of the gain for voltage conversion
189191
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
190192
}
191193

src/SparkFun_ADS1219.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class SfeADS1219Driver
199199
/// @param referenceVoltageMillivolts Usually the internal 2.048V reference voltage.
200200
/// But the user can override with (REFP - REFN) when using the external reference.
201201
/// @return The voltage in millivolts
202-
float getConversionMillivolts(float referenceVoltageMillivolts = 2048);
202+
float getConversionMillivolts(float referenceVoltageMillivolts = 2048.0);
203203

204204
/// @brief Return the raw conversion result which was read by readConversion.
205205
/// @return The raw signed conversion result. 24-bit (2's complement).
@@ -211,9 +211,9 @@ class SfeADS1219Driver
211211
bool dataReady(void);
212212

213213
/// @brief Read the ADS1219 Configuration Register into a sfe_ads1219_reg_cfg_t struct.
214-
/// @param config Pointer to the sfe_ads1219_reg_cfg_t struct to hold the register contents.
214+
/// @param config Reference of a sfe_ads1219_reg_cfg_t struct to hold the register contents.
215215
/// @return True if successful, false otherwise.
216-
bool getConfigurationRegister(sfe_ads1219_reg_cfg_t *config);
216+
bool getConfigurationRegister(sfe_ads1219_reg_cfg_t &config);
217217

218218
/// @brief Write a sfe_ads1219_reg_cfg_t struct into the ADS1219 Configuration Register.
219219
/// @param config A sfe_ads1219_reg_cfg_t struct holding the register contents.

0 commit comments

Comments
 (0)