File tree Expand file tree Collapse file tree 4 files changed +26
-7
lines changed Expand file tree Collapse file tree 4 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ SFE_MAX17043 KEYWORD1
1212# Methods and Functions (KEYWORD2)
1313#######################################
1414
15+ setDevice KEYWORD2
16+ setWirePort KEYWORD2
1517begin KEYWORD2
1618isConnected KEYWORD2
1719enableDebugging KEYWORD2
Original file line number Diff line number Diff line change 11name =SparkFun MAX1704x Fuel Gauge Arduino Library
2- version =1.0.3
2+ version =1.0.4
33author =SparkFun Electronics <
[email protected] >
44maintainer =SparkFun Electronics <sparkfun.com>
55sentence =Arduino library for the MAX17043/44/48/49 fuel gauges
Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ Distributed as-is; no warranty is given.
2323SFE_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
Original file line number Diff line number Diff line change @@ -133,11 +133,17 @@ class SFE_MAX1704X
133133public:
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
You can’t perform that action at this time.
0 commit comments