//test.c: demonstration program using the BQ gauge and i2c interface

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "bq.h"

	
int main() {
	
	char* buf;
	char* bufrd;
	char* bufwr;
	int cnt;
	bq_dataram dr;
	
	printf("Hello World\n");
	
	//Initialize the BQ interface
	initbq();

	//write example data to address 0x02 (AtRate)
	buf = malloc(2);
	buf[0] = 0x9C;
	buf[1] = 0xFF;
	cnt = 2;
	
	//write the data
	writebq(0x02,buf,cnt);
	
	memset(buf,0,2);
	
	// read from the same address
	readbq(0x02,buf,cnt);
	
	//tell the user what we read
	printf("Data Read: %hx %hx\n",buf[0],buf[1]);
	
	//read the entire data RAM
	memset(&dr,0,sizeof(bq_dataram));
	readbqdataram(&dr);
	
	//print the results
	printf("AtRate: %x\n",dr.AtRate);
	printf("AtRateTTE: %x\n",dr.AtRateTTE);
	printf("AvailEnergy: %x\n",dr.AvailEnergy);
	printf("AvgCurr: %x\n",dr.AvgCurr);
	printf("AvgPow: %x\n",dr.AvgPow);
	printf("Control: %x\n",dr.Control);
	printf("CycleCnt: %x\n",dr.CycleCnt);
	printf("Flags: %x\n",dr.Flags);
	printf("FullAvailCap: %x\n",dr.FullAvailCap);
	printf("FullChgCap: %x\n",dr.FullChgCap);
	printf("MaxLoadCurr: %x\n",dr.MaxLoadCurr);
	printf("MaxLoadTTE: %x\n",dr.MaxLoadTTE);
	printf("NomAvailCap: %x\n",dr.NomAvailCap);
	printf("RemCap: %x\n",dr.RemCap);
	printf("StateOfChg: %x\n",dr.StateOfChg);
	printf("StbyCurr: %x\n",dr.StbyCurr);
	printf("StbyTTE: %x\n",dr.StbyTTE);
	printf("Temp: %x\n",dr.Temp);
	printf("TTE: %x\n",dr.TTE);
	printf("TTEAtConstPow: %x\n",dr.TTEAtConstPow);
	printf("TTF: %x\n",dr.TTF);
	printf("Voltage: %x\n",dr.Voltage);

	// close the interface
	closebq();

	free(buf);
	return 0;
}
