Exemplo n.º 1
0
void ZMConsole::updateStatus()
{
    m_updateTimer->stop();
    getDaemonStatus();
    getMonitorStatus();
    m_updateTimer->start(STATUS_UPDATE_TIME);
}
Exemplo n.º 2
0
static
void checkBatteryStatus(void){
	GPIO2DATA ^= _BV(0); /* led0 on */
	if(getMonitorStatus() == 1) wakeBq29312a();
	writeBQ29312A(FUNCTION_CTL, VMEN); /* enable voltage monitoring */
	/* -------------------------------------------- */
	//writeBQ29312A(CELL_SEL, 0b00001100);
	//systickDelay(1);
	//battery.vref = (float)((float)adcRead(1) * (float)(3.3/1024));
	//writeBQ29312A(CELL_SEL, VC4_5);
	//systickDelay(1);
	//battery.vo4_5 = (float)((float)adcRead(1) * (float)(3.3/1024));
	//writeBQ29312A(CELL_SEL, 0b00001000);
	//systickDelay(1);
	//battery.voutr = (float)((float)adcRead(1) * (float)(3.3/1024));
	/* -------------------------------------------- */

	/* Measure Cell Voltage */
	writeBQ29312A(CELL_SEL, VC4_5);
	systickDelay(1);
	battery.adcf[0] = (float)adcRead(1) * (float)(3.3/1024);
	writeBQ29312A(CELL_SEL, VC4_3);
	systickDelay(1);
	battery.adcf[1] = (float)adcRead(1) * (float)(3.3/1024);
	writeBQ29312A(CELL_SEL, VC3_2);
	systickDelay(1);
	battery.adcf[2] = (float)adcRead(1) * (float)(3.3/1024);

	writeBQ29312A(FUNCTION_CTL, VMEN | PACKOUT);
	//uint8_t chgFet = getFetState(FET_CHG);
	//setChgFet(0);
	//setChgPin(0); // chg circuit on
	systickDelay(8);
	battery.adcf[3] = (float)adcRead(1) * (float)(3.3/1024);
	//setChgPin(1); // chg curcuit off
	//setChgFet(chgFet);

	/* Covert Cell Voltage from adc value *but this value is little inaccuracy */
	battery.vcellf[0] = (0.975 - battery.adcf[0]) / 0.15;
	battery.vcellf[1] = (0.975 - battery.adcf[1]) / 0.15;
	battery.vcellf[2] = (0.975 - battery.adcf[2]) / 0.15;
	battery.vcellf[3] = battery.adcf[3] * 25;

	//battery.vcellf[0] = (float)(-0.15 * battery.adcf[0] + 0.975);

	//battery.kact = (battery.vo4_5 - battery.voutr) / battery.vref;
	//battery.vosact = (battery.vo4_5 - battery.vref) / (1 + battery.kact);

	//battery.res = (battery.adcf[0] - battery.vcellf[0]) / battery.kact;
	//float res = (vref + ( 1 + kact ) * vosact - adcf[0] ) / kact - ( vo4_5 - adcf[0] ) / kact;
	//float res = (-adcf[0] + vref ) / kact;


	/* Check DC_in status */
	if(battery.vcellf[3] > 12.6){
		/* DC connected */
		dc.stat = 1;
		GPIO2DATA &= ~(_BV(9)); /* led9 on */
	}else{
		/* DC disconnected */
		dc.stat = 0;
		GPIO2DATA |= _BV(9); /* led9 off */
	}

	/* When DCin is disconnect. CHG FET set to ON for reduce the voltage drop */
	if(dc.stat == 0) setChgFet(1);
	if(dc.stat == 1) setChgFet(0);

	//if(dc.stat == 1){
	//	setDsgFet(0);
	//}

	/* Low voltage alert */
	if(
		(battery.vcellf[0] <= 3.6) ||
		(battery.vcellf[1] <= 3.6) ||
		(battery.vcellf[2] <= 3.6)
	)
	{
		battery.batlow = 1;
		GPIO2DATA |= _BV(0); // led0 off
	}
	else
	{
		battery.batlow = 0;
	}

	/* Low voltage shutdown */
	if(
		(battery.vcellf[0] <= 3.4) ||
		(battery.vcellf[1] <= 3.4) ||
		(battery.vcellf[2] <= 3.4)
	)
	{
		setDCDC(0);
		setDsgFet(0);
		sleepBq29312a();
		shipBq29312a(); /* BQ29312A enter ShipMode. The way to return to NormalMode is only HardwareReset */
		__disable_irq();
		/* Todo: lpc1114 will enter deepsleep mode */
	}
	else
	{
		setDCDC(1);
		setDsgFet(1);
	}

	battery.checkBattery = 0;
}