示例#1
0
int Platform_BatteryChargePercentage(void) {
	int BattFull,BattRemain;
	if (Platform_BatterySupported()==FALSE) return 0;
	BattFull = get_battery_value(FULLCHARGE);
	BattRemain = get_battery_value(REMAININGCHARGE);
	if (BattFull > 0 && BattRemain > 0) {
		BattRemain = BattRemain * 100 / BattFull;
		if (BattRemain < 0) BattRemain = 0;
		if (BattRemain > 100) BattRemain = 100;
		return BattRemain;
	}
	return 0;
}
示例#2
0
/*-------------------------------   ----------------------------*/
void system_battery_detect()
{
    static uint32_t detect_count = 0;
    uint8_t battery_level;
    
    // check every 2 minutes 
     if(detect_count == 1)
     {
         battery_detect_start();
     }
     
     if(battery_is_available() == true)
     {         
         battery_level = get_battery_value();
         battery_detect_stop();
         set_battery_level(battery_level);
         xprintf("             level = %d \r\n", battery_level);
         
         if(get_battery_level() < 20)
             system_low_battery();
                  
     }
         
    if(detect_count > 1500000*120)
    {
        xprintf(" time on..\r\n");
        detect_count = 0;
    }
    detect_count++;
}
示例#3
0
文件: main.c 项目: CorBiNO/Atomwear
/**@brief Function for performing battery measurement and updating the Battery Level characteristic
 *        in Battery Service.
 */
static void battery_level_update(void)
{
    uint32_t err_code;
    uint8_t  battery_level;
	
	battery_detect_start();
	while(!battery_is_available());
	
	battery_level = get_battery_value();
	battery_detect_stop();
	
// 	xprintf("...battery_level = %d% \r\n", battery_level);
	
// 	if(battery_level < 20)
// 		system_low_battery(); 
	
    err_code = ble_bas_battery_level_update(&m_bas, battery_level);
    if ((err_code != NRF_SUCCESS) &&
        (err_code != NRF_ERROR_INVALID_STATE) &&
        (err_code != BLE_ERROR_NO_TX_BUFFERS) &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
    )
    {
        APP_ERROR_HANDLER(err_code);
    }
}