A feature complete driver for the MAX17048 lithium fuel gauge from Maxim.
Dependents: MAX17048_HelloWorld ECGAFE_copy MAX17048_HelloWorld Orion_newPCB_test_LV ... more
Now fully tested!
Diff: MAX17048.h
- Revision:
- 7:bf6972a21c61
- Parent:
- 5:ffce4fe12ed1
- Child:
- 8:65c889800b3a
--- a/MAX17048.h Thu Nov 07 18:23:02 2013 +0000 +++ b/MAX17048.h Tue Nov 12 17:48:11 2013 +0000 @@ -35,6 +35,9 @@ * if (gauge.open()) { * printf("Device detected!\n"); * + * //Load the default compensation value + * gauge.compensation(MAX17048::RCOMP0); + * * while (1) { * //Print the current state of charge * printf("SOC = %f%%\n", (float)gauge); @@ -51,6 +54,10 @@ class MAX17048 { public: + /** The default compensation value for the MAX17048 + */ + static const int RCOMP0 = 0x97; + /** Represents the different alert flags for the MAX17048 */ enum AlertFlags { @@ -69,7 +76,7 @@ */ MAX17048(PinName sda, PinName scl); - /** Probe for the MAX17048 and load the default RCOMP value if present + /** Probe for the MAX17048 and indicate if it's present on the bus * * @returns * 'true' if the device exists on the bus, @@ -137,7 +144,19 @@ */ unsigned short version(); - /** Set the cell temperature compensation of the MAX17048 + /** Get the current compensation value of the MAX17048 + * + * @returns The current compensation value as an unsigned char (0 to 255). + */ + char compensation(); + + /** Set the compensation value of the MAX17048 + * + * @param rcomp The new compensation value as an unsigned char (0 to 255). + */ + void compensation(char rcomp); + + /** Set the compensation value of the MAX17048 from the current cell temperature * * @param temp The current cell temperature in °C. */ @@ -333,8 +352,7 @@ }; //Member constants - static const int m_ADDR = (0x36 << 1); - static const int m_RCOMP0 = 0x97; + static const int m_ADDR = (0x36 << 1); //Member variables I2C m_I2C; @@ -342,7 +360,6 @@ //Internal functions unsigned short read(char reg); void write(char reg, unsigned short data); - void writeRCOMP(char rcomp); }; #endif