예제 #1
0
CBatteryCommonInfo::CBatteryCommonInfo() : iBatteryStatus(NULL), iBatteryChargingStatus(NULL), iCapacityBars(NULL), iUsbConnected(EFalse),iChargingON(EFalse)
{
#ifdef SYMBIAN_3_PLATFORM
    iBatteryStatus = CPubSubKeyHandler::New(KPSUidHWRMPowerState, KHWRMBatteryStatus,*this );
    iBatteryChargingStatus = CPubSubKeyHandler::New(KPSUidHWRMPowerState, KHWRMChargingStatus,*this);
    iCapacityBars = CPubSubKeyHandler::New(KPSUidHWRMPowerState, KHWRMBatteryLevel,*this );
    iBatteryStatData=iRemainingCapacityBars=-1; //Assigning each to error code
    if (iBatteryChargingStatus)
    {
        TInt chargingState = iBatteryChargingStatus->GetValue();
        switch(chargingState)
        {
        case EChargingStatusCharging:
        case EChargingStatusAlmostComplete:
        case EChargingStatusChargingContinued:
            iChargingON = ETrue;
            break ;
        case EChargingStatusNotConnected:
        case EChargingStatusChargingComplete:
        case EChargingStatusNotCharging:
        default :
            iChargingON = EFalse;
            break;
        }

        if ( iChargingON )
        {
            RUsb usbMan;
            if ( KErrNone == usbMan.Connect() )
            {
                TUsbDeviceState deviceState (EUsbDeviceStateUndefined );
                usbMan.GetDeviceState(deviceState);
                if ( EUsbDeviceStateConfigured == deviceState )
                    iUsbConnected = ETrue;
            }
        }
    }
    if (iBatteryStatus)
        iBatteryStatData = iBatteryStatus->GetValue();
    if (iCapacityBars)
        iRemainingCapacityBars = iCapacityBars->GetValue();
#else
    iRemainingCapacityBars = -1;
    iPreviousUsbConnected = EFalse;
    iBatteryStatData = -1;
#endif
}
예제 #2
0
void CBatteryCommonInfo::CommanSignalHandler( const TUid aCategory, const TUint aKey )
{
#ifdef SYMBIAN_3_PLATFORM
    if ( KPSUidHWRMPowerState == aCategory )
    {
        switch ( aKey )
        {
        case KHWRMBatteryStatus :
            if (iBatteryStatus)
            {
                iBatteryStatData = iBatteryStatus->GetValue();
                foreach (MBatteryInfoObserver *observer, iObservers)
                {
                    observer->changedBatteryStatus();
                }
            }
            break;
        case KHWRMChargingStatus :
            //Get Charge Status
            if (iBatteryChargingStatus)
            {
                TInt chargeStatus = iBatteryChargingStatus->GetValue();
                switch (chargeStatus)
                {
                case EChargingStatusCharging:
                case EChargingStatusAlmostComplete:
                case EChargingStatusChargingContinued:
                    iChargingON = ETrue;
                    break ;
                case EChargingStatusNotConnected:
                case EChargingStatusChargingComplete:
                case EChargingStatusNotCharging:
                default :
                    iChargingON = EFalse;
                    break;
                }
                //  Get Charger Type
                RUsb usbMan;
                if ( KErrNone == usbMan.Connect() )
                {
                    TUsbDeviceState deviceState (EUsbDeviceStateUndefined );
                    usbMan.GetDeviceState(deviceState);
                    if ( EUsbDeviceStateConfigured == deviceState )
                        iUsbConnected = ETrue;
                    else
                        iUsbConnected =  EFalse;
                }

                foreach (MBatteryInfoObserver *observer, iObservers)
                {
                    observer->changedChargingState();
                    observer->changedChargerType();
                }
            }
            break;
        case KHWRMBatteryLevel :
            if (iCapacityBars)
            {
                iRemainingCapacityBars = iCapacityBars->GetValue();
                foreach (MBatteryInfoObserver *observer, iObservers)
                {
                    observer->changedRemainingCapacityBars();
                }
            }
            break;
        default :
            break ; //do Nothing
        }
    }