欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

batterypdd.c

pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
C
第 1 页 / 共 2 页
字号:
                ( TEXT( "BatteryPDDGetStatus: (%dmV) %dmV\t%d'C \r\n" ),
                    previous_voltage, voltage,
                    temperature ) );

    if (OnAC)
    {
        pstatus->ACLineStatus   = AC_LINE_ONLINE;
        pstatus->BatteryFlag    = BATTERY_FLAG_NO_BATTERY;
        voltage_percent         = 100.0;
    }
    else /** !OnAC */
    {
        pstatus->ACLineStatus            = AC_LINE_OFFLINE;

        voltage_percent = (float)( previous_voltage -
            WM_BATTERY_MINIMUM_VOLTAGE) /
            (WM_BATTERY_MAXIMUM_VOLTAGE - WM_BATTERY_MINIMUM_VOLTAGE );
        if ( voltage_percent >= WM_BATTERY_HIGH_CUTOFF )
        {
            pstatus->BatteryFlag        = BATTERY_FLAG_HIGH;
        }
        else if ( ( voltage_percent < WM_BATTERY_HIGH_CUTOFF ) &&
                  ( voltage_percent >= WM_BATTERY_LOW_CUTOFF ) )
        {
            pstatus->BatteryFlag        = BATTERY_FLAG_LOW;
        }
        else /** if voltage_percent <= WM_BATTERY_LOW_CUTOFF */
        {
            pstatus->BatteryFlag        = BATTERY_FLAG_CRITICAL;
        }
        pstatus->BatteryLifePercent     = (byte)(voltage_percent * 100);
    }

    pstatus->Reserved1                  = 0;
    pstatus->BatteryLifeTime            = BATTERY_LIFE_UNKNOWN;
    pstatus->BatteryFullLifeTime        = BATTERY_LIFE_UNKNOWN;
    pstatus->Reserved2                  = 0;
    pstatus->BackupBatteryFlag          = BATTERY_FLAG_NO_BATTERY;
    pstatus->BackupBatteryLifePercent   = BATTERY_PERCENTAGE_UNKNOWN ;
    pstatus->Reserved3                  = 0;
    pstatus->BackupBatteryLifeTime      = BATTERY_LIFE_UNKNOWN;
    pstatus->BackupBatteryFullLifeTime  = BATTERY_LIFE_UNKNOWN;
    pstatus->BatteryChemistry           = BATTERY_CHEMISTRY_UNKNOWN;
    pstatus->BatteryVoltage             = voltage;
    pstatus->BatteryCurrent             = 0;
    pstatus->BatteryAverageCurrent      = 0;
    pstatus->BatteryAverageInterval     = 0;
    pstatus->BatterymAHourConsumed      = 0;
    pstatus->BatteryTemperature         = temperature;
    pstatus->BackupBatteryVoltage       = 0;
    *pfBatteriesChangedSinceLastCall    = FALSE;

    DEBUGMSG( ZONE_FUNCTION,
            ( TEXT( "Successfully completed BatteryPDDGetStatus...\r\n" ) ) );
    return TRUE;

#if WM_BATTERY_MONITOR_TEMPERATURE
    error_switchfailed:
        DEBUGMSG( ZONE_ERROR, ( TEXT( "Switching ADC failed: %hs\r\n" ),
            WMStatusText( status ) ) );
        return FALSE;
#endif /* WM_BATTERY_MONITOR_TEMPERATURE */

    error_volt_samplefailed:
        DEBUGMSG( ZONE_ERROR, ( TEXT("BMON Voltage sample failed: %hs\r\n"),
            WMStatusText( status ) ) );
#if WM_DEVICE_POWER_DEBUG
    {
        NKDbgPrintfW(TEXT("-BatteryPDDGetStatus() ERROR: BMON Voltage sample failed\r\n") );
    }
#endif
        return FALSE;
#if WM_BATTERY_MONITOR_TEMPERATURE
    error_temp_samplefailed:
        DEBUGMSG( ZONE_ERROR, ( TEXT("BMON Temp sample failed: %hs\r\n"),
            WMStatusText( status ) ) );
#endif /* WM_BATTERY_MONITOR_TEMPERATURE */
        return FALSE;
}

/******************************************************************************
 * Function: BatteryPDDInitialize                                         *//**
 *
 * @brief  This function enables the battery PDD to perform hardware-specific
 *         initialization.
 *
 * @param pszRegistryContext  Pointer to the battery driver's device key that
 *                            is passed to the battery driver as the first
 *                            parameter of its Init entry point.
 *
 * @return Boolean that indicates success.
 *
 *****************************************************************************/
BOOL WINAPI BatteryPDDInitialize( LPCTSTR pszRegistryContext )
{
    WMSTATUS status = WMS_NO_SUPPORTED_DEVICE;

    DEBUGMSG( ZONE_FUNCTION,
            ( TEXT( "Entering BatteryPDDInitialise...\r\n" ) ) );
    #if WM_I2S
        /** Check if present on I2S primary. */
        status = WMOpenBatteryDevice
            ( WM_DEV_I2S_PRIMARY, &handle_BatteryDevice );
        if ( WM_SUCCESS( status ) )
        {
            DEBUGMSG( ZONE_INIT, ( TEXT
            ( "AuxADC for Battery found on primary I2S device\r\n" ) ) );
        }
        if ( status == WMS_CODEC_NOT_READY ||
             status == WMS_NO_SUPPORTED_DEVICE )
        {
            /** Not on primary, check if present on I2S secondary. */
            status = WMOpenBatteryDevice
                ( WM_DEV_I2S_SECONDARY, &handle_BatteryDevice );
            if ( WM_SUCCESS( status ) )
            {
                DEBUGMSG( ZONE_INIT, ( TEXT
                ( "AuxADC for Battery found on secondary I2S device\r\n" ) ) );
            }
        }
    #endif /** WM_I2S */
    #if WM_AC97
        if ( status == WMS_CODEC_NOT_READY ||
             status == WMS_NO_SUPPORTED_DEVICE )
        {
            /** Not on I2S, check if present on AC97 primary. */
            status = WMOpenBatteryDevice
                ( WM_DEV_AC97_PRIMARY, &handle_BatteryDevice );
            if ( WM_SUCCESS( status ) )
            {
                DEBUGMSG( ZONE_INIT, ( TEXT
                ( "AuxADC for Battery found on primary AC97 device\r\n" ) ) );
            }
        }
        if ( status == WMS_CODEC_NOT_READY || status == WMS_NO_SUPPORTED_DEVICE )
        {
            /** Not on AC97 primary, check if present on AC97 secondary. */
            status = WMOpenBatteryDevice
                ( WM_DEV_AC97_SECONDARY, &handle_BatteryDevice );
            if ( WM_SUCCESS( status ) )
            {
                DEBUGMSG( ZONE_INIT, ( TEXT
                ( "AuxADC for Battery found on secondary AC97 device\r\n" ) ) );
            }
        }
    #endif /** WM_AC97 */

    if ( WM_ERROR( status ) )
    {
        goto error_batterylocatefailed;
    }

    status = WMAuxADCPowerUp( handle_BatteryDevice, WM_POWER_AUXADC );
    if ( WM_ERROR( status ) )
    {
        goto error_batterypowerupfailed;
    }

    status = WMAuxADCSelect( handle_BatteryDevice, WM_BATTERY_ADC_BMON );
    if ( WM_ERROR( status ) )
    {
        goto error_batteryselectfailed;
    }

    status = WMAuxADCStart( handle_BatteryDevice, WM_BATTERY_ADC_BMON );
    if ( WM_ERROR( status ) )
    {
        goto error_batterystartfailed;
    }

    DEBUGMSG(ZONE_INIT, (TEXT
        ( "AuxADC Battery Link is initialised sucessfully \r\n" ) ) );
    DEBUGMSG(ZONE_FUNCTION, (TEXT
        ( "Successfully completed BatteryPDDInitialise...\r\n") ) );
    return TRUE;

    error_batterystartfailed:
        DEBUGMSG(ZONE_ERROR, (TEXT
                ( "AuxADC Battery Link not started \r\n" ) ) );
        goto error_batterypowerok;

    error_batteryselectfailed:
        DEBUGMSG(ZONE_ERROR, (TEXT
                ( "AuxADC Battery Link not selected \r\n" ) ) );

    error_batterypowerok:
        WMAuxADCPowerDown( handle_BatteryDevice, WM_POWER_AUXADC );

    error_batterypowerupfailed:
        DEBUGMSG(ZONE_ERROR, (TEXT
                ( "AuxADC Battery Link not initialised \r\n" ) ) );
            return FALSE;

    error_batterylocatefailed:
        /**
         * Nothing found on AC97 or I2S, or something really went wrong nothing
         * much we can do except tell the user why.
         */
        DEBUGMSG( ZONE_ERROR,
                   ( TEXT("AuxADC for Battery locate failed: %hs\r\n"),
                     WMStatusText( status ) ) );
            return FALSE;
}

/******************************************************************************
 * Function: BatteryPDDPowerHandler                                       *//**
 *
 * @brief  This power callback performs hardware-specific processing for the
 *         battery driver.
 *
 * @param bOff  Equals 'TRUE' if suspending, 'FALSE' if resuming.
 *
 *****************************************************************************/
void WINAPI BatteryPDDPowerHandler( BOOL bOff )
{
    WMSTATUS status;

    if ( !handle_BatteryDevice )
    {
        goto error_nobatteryhandle;
    }

    WMPreventSystemCalls( handle_BatteryDevice, TRUE );

    if ( bOff ) /** Suspending */
    {
        status = WMEnterSleep( handle_BatteryDevice );
        if ( WM_ERROR( status ) )
        {
            WMPreventSystemCalls( handle_BatteryDevice, FALSE );
            goto sleep;
        }
    }
    else /** Resuming */
    {
        status = WMLeaveSleep( handle_BatteryDevice );
        if ( WM_ERROR( status ) )
        {
            WMPreventSystemCalls( handle_BatteryDevice, FALSE );
            goto resume;
        }
    }

    WMPreventSystemCalls( handle_BatteryDevice, FALSE );
    return;

    error_nobatteryhandle:
        status = WMS_NO_SUPPORTED_DEVICE;
        WMPreventSystemCalls( handle_BatteryDevice, FALSE );
        return;
    sleep:
        return;

    resume:
        return;
}

 /******************************************************************************
 * Function: BatteryPDDResume                                              *//**
 *
 * @brief  This function performs hardware-specific battery processing in a
 *         thread context following system resume.
 *
 * (no parameters)
 *
 *****************************************************************************/
void WINAPI BatteryPDDResume(void)
{
    DEBUGMSG( ZONE_FUNCTION,
            ( TEXT( "Entering BatteryPDDResume...\r\n" ) ) );
    /** TODO: Possibly write some code more complex startup */
    DEBUGMSG( ZONE_FUNCTION,
            ( TEXT( "Successfully completed BatteryPDDResume...\r\n" ) ));
}

 /******************************************************************************
 * Function: BatteryPDDSupportsChangeNotification                          *//**
 *
 * @brief  This function indicates whether the battery driver can report whether
 *         the batteries were changed.
 *
 * (no parameters)
 *
 * @return  Returns TRUE to indicate that the pfBatteriesChangedSinceLastCall
 *          parameter value filled in by BatteryPDDGetStatus is valid. If there
 *          is no way to tell that the platform's batteries have been changed
 *          this function should return FALSE.
 *
 *****************************************************************************/
BOOL BatteryPDDSupportsChangeNotification()
{
    return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -