BQ28Z610 Driver
BQ28Z610 Battery fuel gauge device driver for Arduino
utils.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <Arduino.h>
32 #include <Wire.h>
33 
34 #include "globals.h"
35 
36 #define KELVIN_TO_CELSIUS(k) (k - 273.15)
37 
42 #define PGM_PRINT(s) Serial.print(stringFromProgmem(PSTR(s)))
43 
48 #define PGM_PRINTLN(s) Serial.println(stringFromProgmem(PSTR(s)))
49 
55 bool isAllowedRequestPayloadSize(int len);
56 
57 int sendCommand(byte command);
58 
68 int sendCommand(byte reg, word command);
69 
77 int sendData(byte reg, byte *data, int len);
78 
86 int requestBlock(byte *buf);
87 
88 byte requestByte();
89 
96 int requestBytes(byte *buf, int len);
97 
103 word requestWord();
104 
116 byte checksum(byte *data, byte len);
117 
125 bool validate(byte *data);
126 
139 word composeWord(byte *buf, int lowerByteIndex = 0, bool littleEndian = true);
140 
152 u32 composeDoubleWord(byte *buf);
153 
165 u32 composeValue(byte *buf, int from, int till);
166 
170 String stringFromProgmem(PGM_P stringPtr);
171 
175 void printBin(u32 val, int n, bool newLine = false);
176 
182 void printLongSplitBin(u32 val);
183 void printLongBin(u32 val, bool newLine = false);
184 void printWordBin(word val, bool newLine = false);
185 void printByteBin(byte val, bool newLine = false);
186 
190 void printLongHex(u32 val, bool newLine = false);
191 void printWordHex(word val, bool newLine = false);
192 void printWordHex(PGM_P caption, word val, bool newLine = true);
193 void printByteHex(byte val, bool newLine = false);
194 
199 void printBytesHex(byte *buf, int len);
200 
204 void printInteger(PGM_P caption, int value, bool newLine = true);
205 
209 void printInteger(PGM_P caption, int value, PGM_P units, bool newLine = true);
210 
214 void printInteger(int value, PGM_P units, bool newLine = false);
215 
216 void printFloat(float value, int format, PGM_P units, bool newLine = false);
217 void printFloat(PGM_P caption, float value, int format, PGM_P units);
218 void printFloat(PGM_P caption, float value, int format, PGM_P (*unitsFn)());
219 
224 void printPremil(PGM_P caption, int value, PGM_P units);
225 void printPremil(PGM_P caption, int value, PGM_P (*unitsFn)());
226 
230 void printFlag(PGM_P caption, u32 flags, int n);
231 
236 void printFlag(PGM_P caption, u32 flags, Flag (*flagFn)());
237 
241 void printFlag(PGM_P caption, u32 flags, Flag flag);
242 
246 void printFlag(u32 flags, Flag flag);
Global constants.
Structure that stores flag information.
Definition: flags.h:36
int sendData(byte reg, byte *data, int len)
Definition: utils.cpp:101
void printLongHex(u32 val, bool newLine=false)
Definition: utils.cpp:275
u32 composeDoubleWord(byte *buf)
Definition: utils.cpp:234
word composeWord(byte *buf, int lowerByteIndex=0, bool littleEndian=true)
Definition: utils.cpp:214
String stringFromProgmem(PGM_P stringPtr)
Definition: utils.cpp:266
u32 composeValue(byte *buf, int from, int till)
Definition: utils.cpp:249
void printInteger(PGM_P caption, int value, bool newLine=true)
Definition: utils.cpp:373
void printLongSplitBin(u32 val)
Definition: utils.cpp:325
int requestBlock(byte *buf)
Definition: utils.cpp:115
void printFlag(PGM_P caption, u32 flags, int n)
Definition: utils.cpp:406
int sendCommand(byte reg, word command)
Definition: utils.cpp:83
int requestBytes(byte *buf, int len)
Definition: utils.cpp:140
word requestWord()
Definition: utils.cpp:156
bool isAllowedRequestPayloadSize(int len)
Definition: utils.cpp:59
void printBytesHex(byte *buf, int len)
Definition: utils.cpp:301
void printBin(u32 val, int n, bool newLine=false)
Definition: utils.cpp:315
void printPremil(PGM_P caption, int value, PGM_P units)
Definition: utils.cpp:397
byte checksum(byte *data, byte len)
Definition: utils.cpp:173
bool validate(byte *data)
Definition: utils.cpp:184