212 #include <LiquidCrystal.h> 233 #define LTC2947_I2C_MODE_ENABLE 237 #ifdef LTC2947_I2C_MODE_ENABLE 238 #undef LTC2947_SPI_MODE_ENABLE 242 #define SCREEN_UPDATE_TIME 1000UL 243 #define LABEL_DELAY 2000UL 244 #define SPLASH_SCREEN_DELAY 3000UL 246 #define USER_SEL_GRP1_COUNT 9 248 #define USER_SEL_GRP1_CYCLE_COUNT 8 250 #define USER_SEL_GRP2_COUNT 7 252 #define USER_SEL_GRP2_CYCLE_COUNT 6 254 #define USERGROUPCYCLETIMERRELOAD 3 256 #define MEAS_LABEL00 F("I V") 257 #define MEAS_LABEL01 F("P TEMP") 258 #define MEAS_LABEL10 F("C1 VDVCC") 259 #define MEAS_LABEL11 F("E1 TB1") 260 #define MEAS_LABEL20 F("C2 VDVCC") 261 #define MEAS_LABEL21 F("E2 TB2") 262 #define MEAS_LABEL30 F("IMIN IMAX") 263 #define MEAS_LABEL31 F("PMIN PMAX") 264 #define MEAS_LABEL40 F("VMIN VMAX") 265 #define MEAS_LABEL41 F("TMIN TMAX") 266 #define MEAS_LABEL50 F("TMIN TMAX") 267 #define MEAS_LABEL51 F("VDMIN VDMAX") 268 #define MEAS_LABEL60 F("CYCLE ALL") 269 #define MEAS_LABEL61 F("measurements") 302 Serial.begin(115200);
305 #ifdef LTC2947_SPI_MODE_ENABLE 337 Serial.print(F(
"No "));
338 Serial.println(F(
"LCD found! Enter l or m for options."));
350 boolean lastPageSelect;
357 boolean showHeader =
false;
425 #ifdef LTC2947_AUTO_READ_STATUS 456 float I, P, V, TEMP, VCC;
470 boolean limitTempCharacters = P <= -100.0;
480 boolean signC =
true, signE =
true;
481 #ifndef LTC2947_READ_SIGNED_ACCUS 530 PRINTSCREEN2(signE ? -E : E, signE && (E >= 1e2) ? 1 : 2);
537 PRINTSCREEN2(signE ? -E : E, signE && (E >= 1e5) ? 2 : 3);
544 PRINTSCREEN2(signE ? -E : E, signE && (E >= 1e8) ? 1 : 2);
556 else if (TB < 60.0 * 60.0)
559 uint16_t intSec = TB;
565 else if (TB < 60.0 * 60.0 * 24.0)
568 uint16_t intMin = TB / 60.0;
574 else if (TB < 60.0 * 60.0 * 24.0 * 99.0)
577 uint16_t inthour = TB / (60.0 * 60.0);
621 boolean limitTempCharacters = floatHelp <= -100.0;
626 limitTempCharacters = floatHelp <= -100.0;
637 boolean limitTempCharacters = floatHelp <= -100.0;
642 limitTempCharacters = floatHelp <= -100.0;
801 unsigned long currentMillis = millis();
811 else if (cmd ==
'i' || cmd ==
'I')
815 if (currentMillis < ms)
817 currentMillis = millis();
839 int8_t key = lcd->
button();
986 Serial.print(F(
"0:"));
988 Serial.print(F(
" "));
990 Serial.print(F(
"1:"));
992 Serial.print(F(
" "));
994 Serial.print(F(
"2:"));
996 Serial.print(F(
" "));
998 Serial.print(F(
"3:"));
1000 Serial.print(F(
" "));
1002 Serial.print(F(
"4:"));
1004 Serial.print(F(
" "));
1006 Serial.print(F(
"5:"));
1008 Serial.print(F(
" "));
1010 Serial.print(F(
"6:"));
1012 Serial.print(F(
" "));
1014 Serial.println(F(
"enter 0-6, any other to cancel"));
1039 Serial.println(F(
"canceled"));
1048 Serial.println(F(
"0:STATUS"));
1049 Serial.println(F(
"1:STATVT"));
1050 Serial.println(F(
"2:STATIP"));
1051 Serial.println(F(
"3:STATC"));
1052 Serial.println(F(
"4:STATE"));
1053 Serial.println(F(
"5:STATCEOF"));
1054 Serial.println(F(
"6:STATTB"));
1055 Serial.println(F(
"7:STATVDVCC"));
1056 Serial.println(F(
"8:CYCLE ALL"));
1057 Serial.println(F(
"enter 0-8, any other to cancel"));
1086 Serial.println(F(
"canceled"));
#define LTC2947_REG_STATTB
#define LTC2947_BM_TBCTL_PRE_0
#define SPLASH_SCREEN_DELAY
static uint8_t userGroupCycleTimer
The user group cycle timer.
byte statusRegs[8]
array to store all status / alert registers
#define LTC2947_I2C_ADDR_LL
boolean dc590Busy
DC590 busy check.
#define LTC2947_BM_STATC_C1L
unsigned long nextUpdateTime
The next update time.
#define LTC2947_OFFS_TEMPMAX
#define LTC2947_REG_STATE
#define LTC2947_BM_STATUS_ADCERR
#define NEWLINE()
print newline
#define LTC2947_BM_STATTB_TB1TH
#define LTC2947_BM_STATIP_PL
char get_char()
Gets the character.
#define LTC2947_BM_TBCTL_DIV_0
void LTC2947_Read_I_P_V_TEMP_VCC(float *I, float *P, float *V, float *TEMP, float *VCC)
Reads current (I), power (P), voltage (V), temperature (TEMP) and supply voltage (VCC) from the devic...
#define LTC2947_BM_STATC_C2L
static uint8_t userSelGroup2
User selection of the second group.
#define LTC2947_BM_STATIP_IL
#define LTC2947_BM_STATTB_TB2TH
static int8_t LTC2947_RD_BYTES(uint8_t REG_ADDR, uint8_t LENGTH, uint8_t *BYTES)
read multiple bytes via I2C/SPI
void LTC2947_InitSPI()
Initializes the LTC2947 library for SPI mode operation.
boolean statusRegsRead
flag is asserted once after all status registers were read.
boolean userInput()
processes the user input from LCD keypad shield
#define LTC2947_BM_STATVT_VH
#define LTC2947_REG_STATUS
static void setup()
general initialization
void LTC2947_Read_C_E_TB(boolean accuSet1, double *C, double *E, double *TB)
Reads charge (C), energy (E) and time (TB) from the device.
#define LTC2947_BM_STATVDVCC_VDVCCH
#define LTC2947_BM_STATC_C2H
#define USER_SEL_GRP2_CYCLE_COUNT
Menu Group 2 cycle count: RAW, ACCU1, ACCU2, Track1, Track2, Track3.
#define LTC2947_BM_STATC_C1H
#define LTC2947_BM_STATIP_IH
void LTC2947_Read_Abs_C_E_TB(boolean accuSet1, double *C, boolean *signC, double *E, boolean *signE, double *TB)
Reads charge (C), energy (E) and time (TB) from the device.
Header File for Linduino Libraries and Demo Code.
boolean DelayAndCheckSerialData(unsigned long ms)
Delay and check serial data.
#define LTC2947_BM_STATE_E2H
#define LTC2947_LSB_VDVCCMIN
static void processCommands(char command)
#define LTC2947_LSB_FACTOR_MILLI_HOURS
void spi_enable(uint8_t spi_clock_divider)
Setup the processor for hardware SPI communication.
#define LTC2947_BM_STATUS_TBERR
#define LTC2947_BM_STATVT_FANH
#define LTC2947_BM_STATVT_TEMPH
void LTC2947_SetPageSelect(boolean page)
write LTC2947's page control register to selected one of two memory pages
#define LTC2947_BM_STATE_E1L
#define LTC2947_BM_STATUS_UVLOA
#define PRINTSCREEN(A)
print value / text
boolean flagClear
flag to store actions from user input.
#define LTC2947_REG_STATIP
union LT_union_int32_4bytes data
#define LTC2947_VAL_VDVCC
static void loop()
main loop
static void DelayAndProcessInputs(unsigned long ms)
Delay and process input commands either from serial port or from keypad.
boolean userGroup1Cycle
group 1 cycle enable
#define USERGROUPCYCLETIMERRELOAD
defines how many cycles a single measurement group will be displayed on the LCD in case of "cycle all...
#define LTC2947_BM_STATCEOF_E1OF
#define LTC2947_BM_STATUS_PORA
static void update()
update LTC2947 measurement results
#define LTC2947_BM_STATUS_UVLOD
#define LTC2947_LSB_TEMPMAX
#define LTC2947_BM_STATTB_TB1OF
#define LTC2947_BM_STATUS_UPDATE
#define LTC2947_BM_STATCEOF_E2OF
#define LTC2947_BM_OPCTL_RST
int16_t LTC2947_2BytesToInt16(byte *bytes)
converts an array of 2 bytes to 16-bit signed integer
#define CLEAR_SCREEN()
clear screen
#define LTC2947_REG_TBCTL
#define LTC2947_REG_STATVT
boolean CheckSerialData()
Determines if serial data is available and stores data in the queue.
#define LTC2947_BM_STATCEOF_C1OF
#define LTC2947_BM_OPCTL_CLR
#define bitMaskSetChk(value, bitMask)
LCDKeypad * lcd
pointer to the LCD keypad object
boolean userGroupSelect
selected group 1: false, 2: true
#define LTC2947_BM_STATE_E1H
void LTC2947_InitI2C(uint8_t slvAddr)
Initializes the LTC2947 library for I2C mode operation and configures the slave address see defines L...
#define LTC2947_VAL_TEMPMAX
boolean userGroup2Cycle
group 2 cycle enable
#define LTC2947_OFFS_TEMPMIN
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
#define LTC2947_BM_STATVT_VL
#define LTC2947_LSB_VDVCC
boolean tinyDC590B(char command)
process commands received via serial interface.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC2947_BM_STATCEOF_C2OF
#define LTC2947_BM_STATE_E2L
#define SCREENSETCURSOR(A, B)
move cursor
#define bitMaskClrChk(value, bitMask)
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
boolean EnableSerialOutput
#define LTC2947_REG_OPCTL
#define LTC2947_REG_STATC
#define LTC2947_REG_STATVDVCC
#define USER_SEL_GRP2_COUNT
Menu group 2 count: RAW, ACCU1, ACCU2, Track1, Track2, Track3, "Cycle meas.".
#define LTC2947_LSB_TEMPMIN
#define LTC2947_BM_STATVT_TEMPL
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
LTC2947: LTC2947 a high-precision power and energy monitor with an internal sense resistor supporting...
static int8_t LTC2947_WR_BYTE(uint8_t REG_ADDR, uint8_t VALUE)
write single byte via I2C
#define LTC2947_BM_STATVDVCC_VDVCCL
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
boolean LTC2947_GetCurrentPageSelect()
reads LTC2947's page control register to determine the currently selected memory page ...
#define LTC2947_REG_STATCEOF
#define LTC2947_BM_STATTB_TB2OF
#define LTC2947_BM_OPCTL_CONT
#define LTC2947_BM_STATIP_PH
static uint8_t userSelGroup1
User selection of the first group.
#define LTC2947_BM_STATVT_FANL
#define LTC2947_BM_STATUS_UVLOSTBY
double LTC2947_BytesToDouble(uint8_t *bytes, uint8_t length, boolean sig, double lsb)
Converts a signed or unsigned value of arbitrary number of bytes to a floating point number...
#define USER_SEL_GRP1_CYCLE_COUNT
Menu Group 1 cycle count: STATUS STATVT STATIP STATC STATE STATCEOF STATTB STATVDVCC.
#define WRITE_DEGREE_C()
Macros used to print simultaneously on LCD and serial port.
#define PRINTSCREEN2(A, B)
print formatted value
#define LTC2947_LSB_VDVCCMAX
#define SCREEN_UPDATE_TIME
Only one mode is possible at a time.
static int8_t LTC2947_RD_BYTE(uint8_t REG_ADDR, uint8_t *RESULT)
read single byte via I2C/SPI
#define USER_SEL_GRP1_COUNT
Menu Group 1 count: STATUS STATVT STATIP STATC STATE STATCEOF STATTB STATVDVCC "CYCLE stats"...
static int8_t previousKey
The previous key.