Beispiel #1
0
bool getACStatus()
{
	IOService * batteryDevice = getBatteryDevice();
	
	if (NULL != batteryDevice)
	{
		OSObject * obj = batteryDevice->getProperty("ExternalConnected");
		OSBoolean * status = OSDynamicCast(OSBoolean, obj);
        if (status)
            return status->getValue();
	}
    return true;
}
Beispiel #2
0
static void checkACStatusThread(thread_call_param_t	param0,
                           thread_call_param_t	param1)
{
    int i=0;
    const int retryTimes = 10;
    
    while (!isStatusThreadCanCancel && i<retryTimes) {
        if(NULL == commmonBatteryDevice)
        {
            IOLog("Can't find battery device, retry %d...\n", retryTimes-i);
            commmonBatteryDevice = getBatteryDevice();
            IOSleep(3000);
            i++;
            continue;
        }
        
		OSObject * obj = commmonBatteryDevice->getProperty("ExternalConnected");
		OSBoolean * status = OSDynamicCast(OSBoolean, obj);
        if (!status)
        {
            IOLog("Battery status get failed.\n");
            break;
        }
        if(ACStatusChangedCallback)
        {
            bool batStatus = status->getValue();
            if(batStatus != ACStatus)
            {
                //IOLog("Battery status changed.\n");
                ACStatus = batStatus;
                ACStatusChangedCallback(batStatus);
            }
        }
        else
            ACStatus = status->getValue();
        
        IOSleep(ACStatus?1000:5000);//1s=1000ms
    }
    
    if(i == 10)
        IOLog("Can't find battery device, exit.\n");
    else
        IOLog("Battery thread cancelled.\n");
    isStatusThreadCancelled = true;
}
bool ACPIBacklightPanel::getACStatus()
{
    DbgLog("%s::%s()\n", this->getName(),__FUNCTION__);
    
	IOService * batteryDevice = getBatteryDevice();
	
	if (NULL != batteryDevice)
	{
		OSObject * obj = batteryDevice->getProperty("ExternalConnected");
		OSBoolean * status = OSDynamicCast(OSBoolean, obj);
        if (status)
        {
            DbgLog("%s: getACStatus() AC is %d\n", this->getName(), status->getValue());
            return status->getValue();
        }
        else
            DbgLog("%s: getACStatus() unable to get \"ExternalConnected\" property\n", this->getName());
	}
    return true;
}