STC3115 Arduino I2C Driver
STC3115 Gas Gauge I2C Driver for Arduino
 All Classes Functions
STC3115.h
1 #ifndef STC3115_DRIVER_COMPONENT_H
2 #define STC3115_DRIVER_COMPONENT_H
3 
4 #include <Arduino.h>
5 #include "STC3115_constants.h"
6 #include "STC3115_types.h"
7 #include "STC3115_registers.h"
8 #include "STC3115I2CCore.h"
9 
10 #define BATT_CAPACITY 610
11 #define BATT_RINT 200
12 #define VMODE MIXED_MODE
13 #define ALM_EN 0
14 #define ALM_SOC 10
15 #define ALM_VBAT 3600
16 #define RSENSE 50
17 #define APP_EOC_CURRENT 75
18 #define APP_CUTOFF_VOLTAGE 3000
19 
20 class STC3115 : public STC3115I2CCore {
21 public:
22 
23  STC3115(uint8_t address = 0x70);
24  virtual ~STC3115();
25 
26  bool begin(int batteryCapacity = BATT_CAPACITY, int rSense = RSENSE);
27  int getTemperature();
28  int getVoltage();
29  int getCurrent();
30  int getChargeValue();
31  int getSOC();
32  int getOCV();
33  int getRemainingTime();
34 
35  int getChipID();
36  int getStatus();
37 
38  void enableDebugging(Stream* stream = NULL);
39  void disableDebugging();
40 
41  int getRunningCounter();
42  bool readBatteryData();
43  static int convert(short value, unsigned short factor);
44 
45  bool reset();
46  bool stop();
47  bool powerDown();
48 
49  void run();
50  bool startPowerSavingMode();
51  bool stopPowerSavingMode();
52 
53  bool isBatteryDetected();
54 
55  STC3115ConfigData config;
56 protected:
57  void initConfig(int battCapacity, int rSense);
58  int calculateCRC8RAM(uint8_t* data, size_t length);
59  void initRAM();
60  bool readRAMData();
61  int updateRAMCRC8();
62  bool writeRAMData();
63  bool startup();
64  bool restore();
65  void setParamAndRun();
66 
67  STC3115BatteryData batteryData;
68  STC3115RAMData ramData;
69 
70  bool debugEnabled;
71  Stream* debugStream;
72 };
73 
74 #endif
STC3115 configuration structure.
Definition: STC3115_types.h:11
bool writeRAMData()
Write data from internal structure to STC3115 RAM.
Definition: STC3115.cpp:142
int updateRAMCRC8()
Update STC3115 RAM CRC8 value.
Definition: STC3115.cpp:105
bool begin(int batteryCapacity=BATT_CAPACITY, int rSense=RSENSE)
Initialize the STC3115 Gas Gauge chip.
Definition: STC3115.cpp:27
bool isBatteryDetected()
Check whether the battery is detected or not.
Definition: STC3115.cpp:636
STC3115 battery measurement data structure.
Definition: STC3115_types.h:27
int getSOC()
Get SOC of the battery.
Definition: STC3115.cpp:322
void run()
Gradually update battery status on the internal structure & RAM. This function should be called insid...
Definition: STC3115.cpp:504
int getRunningCounter()
Get the STC3115 conversion counter value.
Definition: STC3115.cpp:349
void initRAM()
Initialize STC3115 RAM data.
Definition: STC3115.cpp:77
static int convert(short value, unsigned short factor)
Convert measurement data with given factor.
Definition: STC3115.cpp:445
int getChipID()
Get the chip ID from STC3115.
Definition: STC3115.cpp:64
int getTemperature()
Get temperature of the battery. Temperature unit is celcius.
Definition: STC3115.cpp:295
void setParamAndRun()
Write configuration to STC3115 registers.
Definition: STC3115.cpp:206
void initConfig(int battCapacity, int rSense)
Initialize STC3115 config default values.
Definition: STC3115.cpp:150
bool restore()
Restore SOC value from RAM and run.
Definition: STC3115.cpp:279
bool readBatteryData()
Read battery measurement data in one go.
Definition: STC3115.cpp:369
int getCurrent()
Get battery current.
Definition: STC3115.cpp:313
STC3115(uint8_t address=0x70)
Initialize STC3115 I2C driver with given address.
Definition: STC3115.cpp:12
Definition: STC3115I2CCore.h:7
int getChargeValue()
Get the remaining capacity in mAh unit.
Definition: STC3115.cpp:331
STC3115 RAM data internal structure.
Definition: STC3115_types.h:45
bool readRAMData()
Read STC3115 RAM data and store it to an internal structure.
Definition: STC3115.cpp:95
int calculateCRC8RAM(uint8_t *data, size_t length)
Calculate the CRC8 of a buffer.
Definition: STC3115.cpp:119
bool startPowerSavingMode()
Start power saving mode.
Definition: STC3115.cpp:605
bool powerDown()
Power down the gauge.
Definition: STC3115.cpp:479
int getStatus()
Get STC3115 status.
Definition: STC3115.cpp:183
bool startup()
Write SOC data to STC3115 and run.
Definition: STC3115.cpp:247
int getVoltage()
Get battery voltage.
Definition: STC3115.cpp:304
bool stopPowerSavingMode()
Stop power saving mode.
Definition: STC3115.cpp:619
bool stop()
Store last reading data to RAM and then stop the gauge.
Definition: STC3115.cpp:490
int getOCV()
Get OCV of the battery.
Definition: STC3115.cpp:340
Definition: STC3115.h:20
bool reset()
Reset gauge.
Definition: STC3115.cpp:458