示例#1
0
void main()
{   
	uint32 last_ms;
	systemInit();
	//configure the P1_2 and P1_3 IO pins
	makeAllOutputs(LOW);
	//initialise Anlogue Input 0
	P0INP = 0x1;
	//initialise the USB port
	usbInit();

	usbComRequestLineStateChangeNotification(LineStateChangeCallback);
	
	last_ms = getMs();
	while (1)
	{
		boardService();
		usbComService();
		if((getMs()-last_ms) >=5000){
			LED_YELLOW_TOGGLE();
			printf("batteryPercent: %i\r\n", batteryPercent(adcRead(0 | ADC_REFERENCE_INTERNAL)));
			last_ms=getMs();
		}
	}
}
void EzxHardware::chargeUpdated()
{
  
  int charge_raw = batteryRaw();
  int charge_percent = batteryPercent(charge_raw);
  vsoEzxHardware.setAttribute("Battery/Raw", charge_raw);
  qLog(Hardware) << "Charge: raw =" << charge_raw << "; percent =" << charge_percent;

  bool cablePlugged = cable();

  if (cablePlugged)
    charger.setAvailability(QPowerSource::Available);
  else
    charger.setAvailability(QPowerSource::NotAvailable);

  battery.setCharge(charge_percent);
  battery.setCharging(cablePlugged && regulator() );

  vsoEzxHardware.setAttribute("Cable/Connected", cablePlugged );

  btimer->start(3000);
 
}