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!
Revision 4:e61b2723d2cf, committed 2013-09-16
- Comitter:
- neilt6
- Date:
- Mon Sep 16 22:02:40 2013 +0000
- Parent:
- 3:32087cca331f
- Child:
- 5:ffce4fe12ed1
- Commit message:
- Added new function for reading the state of charge measurement as an integer, added float and int operator overrides for state of charge measurements, improved example
Changed in this revision
MAX17048.cpp | Show annotated file Show diff for this revision Revisions of this file |
MAX17048.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAX17048.cpp Wed Aug 28 17:53:53 2013 +0000 +++ b/MAX17048.cpp Mon Sep 16 22:02:40 2013 +0000 @@ -466,6 +466,15 @@ return value * 0.00390625; } +int MAX17048::socInt(void) +{ + //Read the 16-bit raw SOC value + unsigned short value = read(REG_SOC); + + //Return only the top byte + return value >> 8; +} + float MAX17048::crate(void) { //Read the 16-bit raw C/Rate value
--- a/MAX17048.h Wed Aug 28 17:53:53 2013 +0000 +++ b/MAX17048.h Mon Sep 16 22:02:40 2013 +0000 @@ -36,17 +36,14 @@ * printf("Device detected!\n"); * * while (1) { - * //Read the cell voltage - * float vcell = gauge.vcell(); - * - * //Print the cell voltage - * printf("Vcell = %f\n", vcell); + * //Print the current state of charge + * printf("SOC = %f%%\n", (float)gauge); * * //Sleep for 0.5 seconds * wait(0.5); * } * } else { - * printf("Device not detected!\n"); + * error("Device not detected!\n"); * } * } * @endcode @@ -286,18 +283,42 @@ */ float vcell(void); - /** Get the current state of charge measurement of the MAX17048 + /** Get the current state of charge measurement of the MAX17048 as a float * * @returns The state of charge measurement as a float. */ float soc(void); + /** Get the current state of charge measurement of the MAX17048 as an int + * + * @returns The state of charge measurement as an int. + */ + int socInt(void); + /** Get the current C rate measurement of the MAX17048 * * @returns The C rate measurement as a float. */ float crate(void); +#ifdef MBED_OPERATORS + /** A shorthand for soc() + * + * @returns The state of charge measurement as a float. + */ + operator float() { + return soc(); + } + + /** A shorthand for socInt() + * + * @returns The state of charge measurement as an int. + */ + operator int() { + return socInt(); + } +#endif + private: //I2C register addresses enum Register {