Skip to content

Commit

Permalink
Merge pull request #8 from porrey/ESP-32-Support
Browse files Browse the repository at this point in the history
Esp 32 support
  • Loading branch information
porrey authored May 30, 2021
2 parents d0fef77 + 45d86f2 commit 067e2e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=MAX1704X
version=1.2.1
author=Daniel Porrey <[email protected]>
maintainer=Daniel Porrey <[email protected]>
version=1.2.2
author=Daniel Porrey
maintainer=Daniel Porrey
sentence=Arduino library for MAX17043/MAX17044 lithium ion battery fuel gauge.
paragraph=Provides a simple interface for monitoring battery charge levels. Works with any device using the Maxmim MAX17043 or MAX17044 chip such as the SparkFun LiPo Fuel Gauge.
category=Sensors
url=https://github.com/porrey/MAX1704X
architectures=*
architectures=*
10 changes: 7 additions & 3 deletions src/MAX1704X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ MAX1704X::MAX1704X(float voltageIncrement)

void MAX1704X::begin()
{
this->begin(true, I2C_DEFAULT_ADDRESS);
this->_address = I2C_DEFAULT_ADDRESS;
this->begin(true, this->_address);
}

void MAX1704X::begin(bool initializeWire)
{
this->begin(initializeWire, I2C_DEFAULT_ADDRESS);
this->_address = I2C_DEFAULT_ADDRESS;
this->begin(initializeWire, this->_address);
}

void MAX1704X::begin(bool initializeWire, uint8_t address)
Expand All @@ -49,7 +51,7 @@ void MAX1704X::begin(bool initializeWire, uint8_t address)
}
}

#if defined(ESP8266)
#if defined(ESP8266) || defined(ESP32)
void MAX1704X::begin(int sda, int scl)
{
Wire.begin(sda, scl);
Expand Down Expand Up @@ -130,6 +132,7 @@ bool MAX1704X::sleep()
uint16_t value = this->readRegister16(REGISTER_CONFIG);
setBit(value, 7);
this->writeRegister16(REGISTER_CONFIG, value);
return this->isSleeping();
}

bool MAX1704X::isSleeping()
Expand All @@ -146,6 +149,7 @@ bool MAX1704X::wake()
uint16_t value = this->readRegister16(REGISTER_CONFIG);
clearBit(value, 7);
this->writeRegister16(REGISTER_CONFIG, value);
return !this->isSleeping();
}

void MAX1704X::reset()
Expand Down
20 changes: 10 additions & 10 deletions src/MAX1704X.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ class MAX1704X
void begin();
void begin(bool);
void begin(bool, uint8_t);
#if defined(ESP8266)
void begin(int sda, int scl);
void begin(int sda, int scl, uint8_t);
#if defined(ESP8266) || defined(ESP32)
void begin(int, int);
void begin(int, int, uint8_t);
#endif
uint8_t address();
uint16_t adc();
float voltage();
float percent();
uint16_t version();
uint8_t compensation();
void compensation(uint8_t data);
void compensation(uint8_t);
bool sleep();
bool isSleeping();
bool wake();
Expand All @@ -69,16 +69,16 @@ class MAX1704X
bool alertIsActive();
void clearAlert();
uint8_t getThreshold();
void setThreshold(uint8_t threshold);
void setThreshold(uint8_t);

protected:
TwoWire *_wire;
uint8_t _address;
float _voltageIncrement;
uint8_t thresholdToConfig(uint8_t threshold);
uint8_t configToThreshold(uint8_t config);
uint16_t readRegister16(uint8_t registerId);
void writeRegisterId(uint8_t registerId);
void writeRegister16(uint8_t registerId, uint16_t data);
uint8_t thresholdToConfig(uint8_t);
uint8_t configToThreshold(uint8_t);
uint16_t readRegister16(uint8_t);
void writeRegisterId(uint8_t);
void writeRegister16(uint8_t, uint16_t);
};
#endif

0 comments on commit 067e2e6

Please sign in to comment.