Skip to content

Commit b7a60ab

Browse files
authored
Merge pull request #11 from sparkfun/release_candidate
v1.0.4: add setDevice and setWirePort
2 parents 2976f76 + 636247f commit b7a60ab

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SFE_MAX17043 KEYWORD1
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414

15+
setDevice KEYWORD2
16+
setWirePort KEYWORD2
1517
begin KEYWORD2
1618
isConnected KEYWORD2
1719
enableDebugging KEYWORD2

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun MAX1704x Fuel Gauge Arduino Library
2-
version=1.0.3
2+
version=1.0.4
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Arduino library for the MAX17043/44/48/49 fuel gauges

src/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ Distributed as-is; no warranty is given.
2323
SFE_MAX1704X::SFE_MAX1704X(sfe_max1704x_devices_e device)
2424
{
2525
// Constructor
26+
setDevice(device);
27+
}
2628

29+
// Change the device type if required. Do this after instantiation but before .begin
30+
void SFE_MAX1704X::setDevice(sfe_max1704x_devices_e device)
31+
{
2732
// Record the device type
2833
_device = device;
2934

@@ -45,9 +50,9 @@ SFE_MAX1704X::SFE_MAX1704X(sfe_max1704x_devices_e device)
4550
}
4651
}
4752

48-
boolean SFE_MAX1704X::begin(TwoWire &wirePort)
53+
bool SFE_MAX1704X::begin(TwoWire &wirePort)
4954
{
50-
_i2cPort = &wirePort; //Grab which port the user wants us to use
55+
setWirePort(wirePort); //Grab which port the user wants us to use
5156

5257
if (isConnected() == false)
5358
{
@@ -63,8 +68,14 @@ boolean SFE_MAX1704X::begin(TwoWire &wirePort)
6368
return (true);
6469
}
6570

71+
// Allow _i2CPort to be set manually, so that isConnected can be called before .begin if required
72+
void SFE_MAX1704X::setWirePort(TwoWire &wirePort)
73+
{
74+
_i2cPort = &wirePort; //Grab which port the user wants us to use
75+
}
76+
6677
//Returns true if device is present
67-
boolean SFE_MAX1704X::isConnected(void)
78+
bool SFE_MAX1704X::isConnected(void)
6879
{
6980
//Updated to resolve issue #4 Dec 27th 2021
7081
//Also avoid using the standard "if device answers on _deviceAddress" test

src/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,17 @@ class SFE_MAX1704X
133133
public:
134134
SFE_MAX1704X(sfe_max1704x_devices_e device = MAX1704X_MAX17043); // Default to the 5V MAX17043
135135

136+
// Change the device type if required. Do this after instantiation but before .begin
137+
void setDevice(sfe_max1704x_devices_e device);
138+
139+
// Allow _i2CPort to be set manually, so that isConnected can be called before .begin if required
140+
void setWirePort(TwoWire &wirePort);
141+
136142
// begin() - Initializes the MAX17043.
137-
boolean begin(TwoWire &wirePort = Wire); //Returns true if module is detected
143+
bool begin(TwoWire &wirePort = Wire); //Returns true if module is detected
138144

139145
//Returns true if device is present
140-
boolean isConnected(void);
146+
bool isConnected(void);
141147

142148
// Debug
143149
void enableDebugging(Stream &debugPort = Serial); // enable debug messages
@@ -381,7 +387,7 @@ class SFE_MAX1704X
381387

382388
#if MAX1704X_ENABLE_DEBUGLOG
383389
Stream *_debugPort; //The stream to send debug messages to if enabled. Usually Serial.
384-
boolean _printDebug = false; //Flag to print debugging variables
390+
bool _printDebug = false; //Flag to print debugging variables
385391
#endif // if MAX1704X_ENABLE_DEBUGLOG
386392

387393
// Clear the specified bit(s) in the MAX17048/49 status register

0 commit comments

Comments
 (0)