Ignore:
Timestamp:
Aug 30, 2014, 8:24:36 PM (11 years ago)
Author:
pr
Message:

ACPI power off changes from David.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/acpih.c

    r414 r416  
    1717
    1818/*
    19  *      Copyright (C) 2006-2013 Paul Ratcliffe.
     19 *      Copyright (C) 2006-2014 Paul Ratcliffe.
    2020 *      This file is part of the "XWorkplace helpers" source package.
    2121 *      This is free software; you can redistribute it and/or modify
     
    7979 *@@ acpihOpen:
    8080 *      resolves the ACPI entrypoints and loads the ACPI DLL.
     81 *
     82 *@@changed V1.0.10 (2014-08-30) [dazarewicz]: Call ACPI start API func.
    8183 */
    8284
     
    140142        G_ulCount++;
    141143
    142         // @@added V1.0.9 (2012-12-10) [slevine]: use AcpiTkPrepareToSleep rather than workaround
    143         /* This function does not exist in older versions of acpi
    144          * As a result the shutdown attempt will usually hang because
    145          * the required code has not been committed into memory.
    146          */
    147         if (pAcpiTkPrepareToSleep)
    148             pAcpiTkPrepareToSleep(ACPI_STATE_S5);
    149 
    150144        return(pAcpiStartApi(phACPI));
    151145    }
     146}
     147
     148/*
     149 *@@ acpihPrepareToSleep:
     150 *      Prepares the system to sleep or power off
     151 *
     152 *@@added V1.0.10 (2014-08-30) [dazarewicz]
     153 */
     154
     155VOID acpihPrepareToSleep(UCHAR ucState)
     156{
     157    // @@added V1.0.9 (2012-12-10) [slevine]: use AcpiTkPrepareToSleep rather than workaround
     158    /* This function does not exist in older versions of acpi
     159     * As a result the shutdown attempt will usually hang because
     160     * the required code has not been committed into memory.
     161     */
     162    if (pAcpiTkPrepareToSleep)
     163        pAcpiTkPrepareToSleep(ucState);
    152164}
    153165
     
    196208 *      Code provided by David Azarewicz
    197209 *@@added V1.0.9 (2012-02-20) [slevine]: code from David Azarewicz
    198  */
    199 
    200 #define AE_DEPTH AE_OK
    201 
    202 ACPI_STATUS AcpiCallbackWidget( ACPI_HANDLE ObjHandle, UINT32 NestingLevel, void *Context, void **ReturnValue )
     210 *@@changed V1.0.10 (2014-08-30) [dazarewicz]: release resources correctly
     211 */
     212
     213ACPI_STATUS APIENTRY AcpiCallbackWidget( ACPI_HANDLE ObjHandle, UINT32 NestingLevel, void *Context, void **ReturnValue )
    203214{
    204215    ACPI_DEVICE_INFO *pDevInfo = NULL;
    205     ACPI_STATUS Status = pAcpiTkGetObjectInfoAlloc(ObjHandle, &pDevInfo);
    206 
    207     if (Status == AE_OK)
     216
     217    if (pAcpiTkGetObjectInfoAlloc( ObjHandle, &pDevInfo ) != AE_OK)
     218        return AE_OK;
     219
     220    do
    208221    {
    209222        if (pDevInfo->Type != ACPI_TYPE_DEVICE)
    210             return AE_DEPTH;
     223            break;
    211224
    212225        if (!(pDevInfo->Valid & ACPI_VALID_HID))
    213             return AE_DEPTH;
     226            break;
    214227
    215228        if (!pDevInfo->HardwareId.String)
    216             return AE_DEPTH;
     229            break;
    217230
    218231        if (strncmp(pDevInfo->HardwareId.String, "ACPI0003", 8) == 0)
    219232        { /* AC Power */
    220             Status = pAcpiTkGetHandle(ObjHandle, "_PSR", &G_ahAC);
    221             if (Status)
     233            if (pAcpiTkGetHandle(ObjHandle, "_PSR", &G_ahAC))
    222234                G_ahAC = 0;
    223235
    224             return AE_DEPTH;
     236            break;
    225237        }
    226238
     
    230242                G_ahBat[G_uiBatteryCount++] = ObjHandle;
    231243
    232             return AE_DEPTH;
    233         }
    234     }
     244            break;
     245        }
     246    } while (0);
    235247
    236248    if (pDevInfo)
     
    246258 *      Code provided by David Azarewicz
    247259 *@@added V1.0.9 (2012-02-20) [slevine]: code from David Azarewicz
     260 *@@changed V1.0.10 (2014-08-30) [dazarewicz]: tidies
    248261 */
    249262
     
    326339        Obj = (ACPI_OBJECT *)Obj[0].Package.Elements;   // Battery info package
    327340        LastFull = (UINT32)OBJ_VALUE(2);
    328         if (LastFull == 0xffffffff)
    329         {
    330             G_ahBat[uiI] = 0;
    331             continue;
    332         }
    333341
    334342        Result.Length = sizeof(Object);
     
    344352        Obj = Result.Pointer;
    345353        Obj = (ACPI_OBJECT *)Obj[0].Package.Elements;   // Battery status package
    346 
    347         // If voltage known
    348         if ((UINT32)OBJ_VALUE(2) != 0xffffffff)
    349             BRemaining = (UINT32)OBJ_VALUE(2);
     354        BRemaining = (UINT32)OBJ_VALUE(2);
    350355
    351356        // If battery units are mWh or mAh
    352357        // If not, it is a percentage
    353         if ((UINT32)OBJ_VALUE(0) != 0xffffffff)
     358        if (    (LastFull != 0xffffffff)
     359             && (BRemaining != 0xffffffff)
     360           )
    354361        {
    355362            if (BRemaining > (LastFull >> 1)) // > 50% is high. < 50% is low
     
    370377                fChanged = TRUE;
    371378            }
    372         }
    373 
    374         ulTmp = (BRemaining*100) / LastFull;
    375         if (ulTmp > 100)
    376             ulTmp = 100;
    377 
    378         if (pApm->bBatteryLife != ulTmp)
    379         {
    380             pApm->bBatteryLife = (BYTE) ulTmp;
    381             fChanged = TRUE;
     379
     380            ulTmp = (BRemaining*100) / LastFull;
     381            if (ulTmp > 100)
     382                ulTmp = 100;
     383
     384            if (pApm->bBatteryLife != ulTmp)
     385            {
     386                pApm->bBatteryLife = (BYTE) ulTmp;
     387                fChanged = TRUE;
     388            }
    382389        }
    383390    }
Note: See TracChangeset for help on using the changeset viewer.