-
Notifications
You must be signed in to change notification settings - Fork 10
/
LiFuelGauge.h
executable file
·72 lines (64 loc) · 2.01 KB
/
LiFuelGauge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Name: LiFuelGauge
* Author: Nick Lamprianidis <nlamprian@gmail.com>
* Version: 1.0
* Description: A library for interfacing the MAXIM MAX17043/MAX17044
* Li+ fuel gauges. These ICs report the relative state of charge
* of the connected Lithium Ion Polymer battery, and the library
* can help you configure them and communicate with them
* Source: https://github.com/nlamprian/LiFuelGauge
* License: Copyright (c) 2014 Nick Lamprianidis
* This library is licensed under the MIT license
* http://www.opensource.org/licenses/mit-license.php
*
* Filename: LiFuelGauge.h
* File description: Definitions and methods for the LiFuelGauge library
*/
#ifndef LiFuelGauge_h
#define LiFuelGauge_h
#include <Arduino.h>
#include <Wire.h>
// MAX1704X register addresses
const uint8_t MAX1704X_ADDR = 0x36;
const uint8_t MAX1704X_VCELL_ADDR = 0x02;
const uint8_t MAX1704X_SOC_ADDR = 0x04;
const uint8_t MAX1704X_MODE_ADDR = 0x06;
const uint8_t MAX1704X_VERSION_ADDR = 0x08;
const uint8_t MAX1704X_CONFIG_ADDR = 0x0C;
const uint8_t MAX1704X_RCOMP_ADDR = 0x0C;
const uint8_t MAX1704X_ATHRD_ADDR = 0x0D;
const uint8_t MAX1704X_COMMAND_ADDR = 0xFE;
// Signature of the ISR for the ALERT Interrupt
typedef void (*func)();
// Names of the two supported ICs
// Used for reporting the correct voltage measurement (see getVoltage method)
enum gaugeType
{
MAX17043 = 1,
MAX17044 = 2
};
// Class for interfacing the MAX17043/MAX17044 Li+ fuel gauges
class LiFuelGauge
{
public:
LiFuelGauge(gaugeType ic);
LiFuelGauge(gaugeType ic, uint8_t intr, func f);
double getVoltage();
double getSOC();
uint16_t getVersion();
uint8_t getCompensation();
uint8_t getAlertThreshold();
uint8_t setCompensation(uint8_t comp);
uint8_t setAlertThreshold(uint8_t thrd);
uint8_t clearAlertInterrupt();
uint8_t sleep();
uint8_t wake();
boolean sleeping();
uint8_t quickStart();
uint8_t reset();
private:
gaugeType _ic;
func _f;
uint8_t getStatus();
};
#endif // LiFuelGauge