Adafruit LC709203F Library
Adafruit_LC709203F.h
Go to the documentation of this file.
1 
17 #ifndef _ADAFRUIT_LC709203F_H
18 #define _ADAFRUIT_LC709203F_H
19 
20 #include "Arduino.h"
21 #include <Adafruit_I2CDevice.h>
22 
23 #define LC709203F_I2CADDR_DEFAULT 0x0B
24 #define LC709203F_CMD_THERMISTORB 0x06
25 #define LC709203F_CMD_INITRSOC 0x07
26 #define LC709203F_CMD_CELLTEMPERATURE 0x08
27 #define LC709203F_CMD_CELLVOLTAGE 0x09
28 #define LC709203F_CMD_APA 0x0B
29 #define LC709203F_CMD_RSOC 0x0D
30 #define LC709203F_CMD_CELLITE 0x0F
31 #define LC709203F_CMD_ICVERSION 0x11
32 #define LC709203F_CMD_BATTPROF 0x12
33 #define LC709203F_CMD_ALARMRSOC 0x13
34 #define LC709203F_CMD_ALARMVOLT 0x14
35 #define LC709203F_CMD_POWERMODE 0x15
36 #define LC709203F_CMD_STATUSBIT 0x16
37 #define LC709203F_CMD_PARAMETER 0x1A
38 
39 
40 typedef enum {
41  LC709203F_TEMPERATURE_I2C = 0x0000,
42  LC709203F_TEMPERATURE_THERMISTOR = 0x0001,
44 
46 typedef enum {
47  LC709203F_POWER_OPERATE = 0x0001,
48  LC709203F_POWER_SLEEP = 0x0002,
50 
52 typedef enum {
53  LC709203F_APA_100MAH = 0x08,
54  LC709203F_APA_200MAH = 0x0B,
55  LC709203F_APA_500MAH = 0x10,
56  LC709203F_APA_1000MAH = 0x19,
57  LC709203F_APA_2000MAH = 0x2D,
58  LC709203F_APA_3000MAH = 0x36,
60 
66 public:
69 
70  bool begin(TwoWire *wire = &Wire);
71  bool initRSOC(void);
72 
75  bool setPackAPA(uint8_t apa_value);
76 
77  uint16_t getICversion(void);
78  float cellVoltage(void);
79  float cellPercent(void);
80 
81  uint16_t getThermistorB(void);
82  bool setThermistorB(uint16_t b);
83 
84  uint16_t getBattProfile(void);
85  bool setBattProfile(uint16_t b);
86 
88  float getCellTemperature(void);
89 
90  bool setAlarmRSOC(uint8_t percent);
91  bool setAlarmVoltage(float voltage);
92 
93 protected:
94  Adafruit_I2CDevice *i2c_dev = NULL;
95  bool readWord(uint8_t address, uint16_t *data);
96  bool writeWord(uint8_t command, uint16_t data);
97 };
98 
99 #endif
lc709203_tempmode_t
Definition: Adafruit_LC709203F.h:40
bool setTemperatureMode(lc709203_tempmode_t t)
Set the temperature mode (external or internal)
Definition: Adafruit_LC709203F.cpp:141
Adafruit_I2CDevice * i2c_dev
Pointer to I2C bus interface.
Definition: Adafruit_LC709203F.h:94
bool setPackSize(lc709203_adjustment_t apa)
Set the approximate pack size, helps RSOC calculation.
Definition: Adafruit_LC709203F.cpp:150
bool readWord(uint8_t address, uint16_t *data)
Helper that reads 16 bits of CRC data from the chip. Note this function performs a CRC on data that i...
Definition: Adafruit_LC709203F.cpp:237
bool setAlarmVoltage(float voltage)
Set the alarm pin to respond to a battery voltage level.
Definition: Adafruit_LC709203F.cpp:177
bool initRSOC(void)
Initialize the RSOC algorithm.
Definition: Adafruit_LC709203F.cpp:100
bool setThermistorB(uint16_t b)
Set the thermistor B value (e.g. 3950)
Definition: Adafruit_LC709203F.cpp:206
Class that stores state and functions for interacting with the LC709203F I2C battery monitor...
Definition: Adafruit_LC709203F.h:65
uint16_t getBattProfile(void)
Get the battery profile parameter.
Definition: Adafruit_LC709203F.cpp:214
bool setPackAPA(uint8_t apa_value)
Set battery APA value, per LC709203F datasheet.
Definition: Adafruit_LC709203F.cpp:159
bool begin(TwoWire *wire=&Wire)
Sets up the hardware and initializes I2C.
Definition: Adafruit_LC709203F.cpp:52
uint16_t getICversion(void)
Get IC LSI version.
Definition: Adafruit_LC709203F.cpp:90
bool writeWord(uint8_t command, uint16_t data)
Helper that writes 16 bits of CRC data to the chip. Note this function performs a CRC on data that in...
Definition: Adafruit_LC709203F.cpp:267
bool setPowerMode(lc709203_powermode_t t)
Set the power mode, LC709203F_POWER_OPERATE or LC709203F_POWER_SLEEP.
Definition: Adafruit_LC709203F.cpp:187
bool setAlarmRSOC(uint8_t percent)
Set the alarm pin to respond to an RSOC percentage level.
Definition: Adafruit_LC709203F.cpp:168
uint16_t getThermistorB(void)
Get the thermistor B value (e.g. 3950)
Definition: Adafruit_LC709203F.cpp:195
Adafruit_LC709203F()
Instantiates a new LC709203F class.
Definition: Adafruit_LC709203F.cpp:42
float cellPercent(void)
Get battery state in percent (0-100%)
Definition: Adafruit_LC709203F.cpp:118
float cellVoltage(void)
Get battery voltage.
Definition: Adafruit_LC709203F.cpp:108
lc709203_powermode_t
Definition: Adafruit_LC709203F.h:46
float getCellTemperature(void)
Get battery thermistor temperature.
Definition: Adafruit_LC709203F.cpp:128
lc709203_adjustment_t
Definition: Adafruit_LC709203F.h:52
bool setBattProfile(uint16_t b)
Set the battery profile parameter.
Definition: Adafruit_LC709203F.cpp:225