Changeset 443
- Timestamp:
- Feb 20, 2019, 7:55:27 AM (6 years ago)
- Location:
- branches/branch-1-0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1-0/include/helpers/acpih.h
r429 r443 66 66 67 67 VOID APIENTRY acpihClose(ACPI_API_HANDLE *phACPI); 68 typedef APIRET APIENTRY ACPIHCLOSE(ACPI_API_HANDLE *phACPI); 69 typedef ACPIHCLOSE *PACPIHCLOSE; 68 70 69 71 //@added V1.0.10 (2014-08-30) [dazarewicz] … … 74 76 typedef APIRET APIENTRY ACPIHGETPOWERSTATUS(PAPM, PBOOL); 75 77 typedef ACPIHGETPOWERSTATUS *PACPIHGETPOWERSTATUS; 78 79 ULONG APIENTRY acpihGetCpuTemp(ACPI_API_HANDLE *phACPI); 80 typedef ULONG APIENTRY ACPIHGETCPUTEMP(ACPI_API_HANDLE *phACPI); 81 typedef ACPIHGETCPUTEMP *PACPIHGETCPUTEMP; 76 82 77 83 BOOL acpihHasBattery(VOID); -
branches/branch-1-0/src/helpers/acpih.c
r438 r443 54 54 // @@added V1.0.9 (2012-02-20) [slevine]: additional ACPI support, code from David Azarewicz 55 55 ACPI_HANDLE G_ahAC = 0; 56 ACPI_HANDLE G_ahTemp = 0; 57 ULONG G_uiTempWalked = 0; 56 58 #define MAX_BATTERY_COUNT 4 57 ACPI_HANDLE G_ahBat[MAX_BATTERY_COUNT]; 59 struct _gahbat_ { 60 ACPI_HANDLE ahBat; 61 ULONG ulLastFull; 62 } G_Bat[MAX_BATTERY_COUNT]; 58 63 ULONG G_uiBatteryCount = 0; 59 64 ULONG G_uiAlreadyWalked = 0; … … 202 207 } 203 208 209 // VAC 3.08 long long compatibility support 210 #ifdef INCL_LONGLONG // VAC 3.6.5 - compiler supports long long 211 #define OBJECT_VALUE(index) (Object[index].Integer.Value) 212 #define OBJ_VALUE(index) (pObj[index].Integer.Value) 213 #else // VAC 3.08 - compiler does not support long long 214 #define OBJECT_VALUE(index) (Object[index].Integer.Value.ulLo) 215 #define OBJ_VALUE(index) (pObj[index].Integer.Value.ulLo) 216 #endif 204 217 205 218 /** … … 214 227 { 215 228 ACPI_DEVICE_INFO *pDevInfo = NULL; 229 ACPI_BUFFER Buffer; 230 ACPI_OBJECT *pObj, Object[25]; 216 231 217 232 if (pAcpiTkGetObjectInfoAlloc( ObjHandle, &pDevInfo ) != AE_OK) … … 240 255 { /* Smart battery */ 241 256 if (G_uiBatteryCount < MAX_BATTERY_COUNT) 242 G_ahBat[G_uiBatteryCount++] = ObjHandle; 257 { 258 G_Bat[G_uiBatteryCount].ahBat = ObjHandle; 259 G_Bat[G_uiBatteryCount].ulLastFull = 0xffffffff; 260 261 /* Get static battery inFormation */ 262 Buffer.Length = sizeof(Object); 263 Buffer.Pointer = Object; 264 if (pAcpiTkEvaluateObject(ObjHandle, "_BIX", NULL, &Buffer) == AE_OK) 265 { 266 pObj = Buffer.Pointer; 267 pObj = (ACPI_OBJECT *)pObj[0].Package.Elements; 268 G_Bat[G_uiBatteryCount].ulLastFull = (UINT32)OBJ_VALUE(3); 269 } 270 else 271 { 272 Buffer.Length = sizeof(Object); 273 Buffer.Pointer = Object; 274 if (pAcpiTkEvaluateObject(ObjHandle, "_BIF", NULL, &Buffer) == AE_OK) 275 { 276 pObj = Buffer.Pointer; 277 pObj = (ACPI_OBJECT *)pObj[0].Package.Elements; 278 G_Bat[G_uiBatteryCount].ulLastFull = (UINT32)OBJ_VALUE(2); 279 } 280 } 281 282 G_uiBatteryCount++; 283 } 243 284 244 285 break; … … 265 306 ACPI_STATUS Status; 266 307 ACPI_BUFFER Result; 267 ACPI_OBJECT * Obj, Object[20];308 ACPI_OBJECT *pObj, Object[20]; 268 309 UINT32 uiI; 269 ULONG ulTmp, BRemaining , LastFull;310 ULONG ulTmp, BRemaining; 270 311 BOOL fChanged; 271 312 … … 292 333 fChanged = FALSE; 293 334 294 // VAC 3.08 long long compatibility support295 #ifdef INCL_LONGLONG // VAC 3.6.5 - compiler supports long long296 #define OBJECT_VALUE(index) (Object[index].Integer.Value)297 #define OBJ_VALUE(index) (Obj[index].Integer.Value)298 #else // VAC 3.08 - compiler does not support long long299 #define OBJECT_VALUE(index) (Object[index].Integer.Value.ulLo)300 #define OBJ_VALUE(index) (Obj[index].Integer.Value.ulLo)301 #endif302 303 335 if (G_ahAC) 304 336 { … … 323 355 for (uiI=0; uiI < G_uiBatteryCount; uiI++) 324 356 { 325 if (G_ ahBat[uiI]== 0)357 if (G_Bat[uiI].ahBat == 0) 326 358 continue; 327 328 Result.Length = sizeof(Object); 329 Result.Pointer = Object; 330 // Get battery info 331 Status = pAcpiTkEvaluateObject(G_ahBat[uiI], "_BIF", NULL, &Result); 332 if (Status != AE_OK) 333 { 334 G_ahBat[uiI] = 0; 359 if (G_Bat[uiI].ulLastFull == 0xffffffff) 335 360 continue; 336 }337 338 Obj = Result.Pointer;339 Obj = (ACPI_OBJECT *)Obj[0].Package.Elements; // Battery info package340 LastFull = (UINT32)OBJ_VALUE(2);341 361 342 362 Result.Length = sizeof(Object); 343 363 Result.Pointer = Object; 344 364 // Get battery status 345 Status = pAcpiTkEvaluateObject(G_ ahBat[uiI], "_BST", NULL, &Result);365 Status = pAcpiTkEvaluateObject(G_Bat[uiI].ahBat, "_BST", NULL, &Result); 346 366 if (Status != AE_OK) 347 367 { 348 G_ ahBat[uiI]= 0;368 G_Bat[uiI].ahBat = 0; 349 369 continue; 350 370 } 351 371 352 Obj = Result.Pointer;353 Obj = (ACPI_OBJECT *)Obj[0].Package.Elements; // Battery status package372 pObj = Result.Pointer; 373 pObj = (ACPI_OBJECT *)pObj[0].Package.Elements; // Battery status package 354 374 BRemaining = (UINT32)OBJ_VALUE(2); 355 375 356 376 // If battery units are mWh or mAh 357 377 // If not, it is a percentage 358 if ( (LastFull != 0xffffffff) 359 && (BRemaining != 0xffffffff) 360 ) 378 if (BRemaining == 0xffffffff) 379 continue; 380 381 if (BRemaining > (G_Bat[uiI].ulLastFull >> 1)) // > 50% is high. < 50% is low 382 ulTmp = 1; // High 383 else 384 ulTmp = 2; // Low 385 386 if (OBJ_VALUE(0) & 4) 387 ulTmp = 2; // Critical 388 389 // If battery charging - it can't be critical 390 if (OBJ_VALUE(0) & 2) 391 ulTmp = 3; // Charging 392 393 if (pApm->bBatteryStatus != ulTmp) 361 394 { 362 if (BRemaining > (LastFull >> 1)) // > 50% is high. < 50% is low 363 ulTmp = 1; // High 364 else 365 ulTmp = 2; // Low 366 367 if (OBJ_VALUE(0) & 4) 368 ulTmp = 2; // Critical 369 370 // If battery charging - it can't be critical 371 if (OBJ_VALUE(0) & 2) 372 ulTmp = 3; // Charging 373 374 if (pApm->bBatteryStatus != ulTmp) 375 { 376 pApm->bBatteryStatus = (BYTE)ulTmp; 377 fChanged = TRUE; 378 } 379 380 ulTmp = 0; 381 if (LastFull) 382 ulTmp = (BRemaining*100) / LastFull; 383 if (ulTmp > 100) 384 ulTmp = 100; 385 386 if (pApm->bBatteryLife != ulTmp) 387 { 388 pApm->bBatteryLife = (BYTE) ulTmp; 389 fChanged = TRUE; 390 } 395 pApm->bBatteryStatus = (BYTE)ulTmp; 396 fChanged = TRUE; 397 } 398 399 ulTmp = 0; 400 if (G_Bat[uiI].ulLastFull) 401 ulTmp = (BRemaining*100) / G_Bat[uiI].ulLastFull; 402 if (ulTmp > 100) 403 ulTmp = 100; 404 405 if (pApm->bBatteryLife != ulTmp) 406 { 407 pApm->bBatteryLife = (BYTE) ulTmp; 408 fChanged = TRUE; 391 409 } 392 410 } … … 397 415 pApm->fAlreadyRead = FALSE; 398 416 return 0; 417 } 399 418 400 419 #undef OBJECT_VALUE 401 420 #undef OBJ_VALUE 402 }403 421 404 422 /* … … 428 446 } 429 447 448 /** 449 *@@ AcpiCallbackTemperature: 450 * ACPI callback helper for CPU Temperature 451 * Code provided by David Azarewicz 452 */ 453 454 ACPI_STATUS APIENTRY AcpiCallbackTemperature( ACPI_HANDLE ObjHandle, UINT32 NestingLevel, void *Context, void **ReturnValue ) 455 { 456 if (G_ahTemp) 457 return AE_OK; 458 459 if (pAcpiTkGetHandle(ObjHandle, "_TMP", &G_ahTemp)) 460 G_ahTemp = 0; 461 462 return AE_OK; 463 } 464 465 /* 466 *@@ acpihGetCpuTemp: 467 * Code provided by David Azarewicz. 468 */ 469 ULONG acpihGetCpuTemp(ACPI_API_HANDLE *phACPI) 470 { 471 ACPI_STATUS Status; 472 ACPI_BUFFER Result; 473 ACPI_OBJECT Object; 474 ULONG ulTemp = 0; 475 476 /* Make sure all the functions we need have valid pointers. */ 477 if ( (pAcpiTkWalkNamespace == NULL) 478 || (pAcpiTkGetHandle == NULL) 479 || (pAcpiTkEvaluateObject == NULL) 480 ) 481 return 1; 482 483 if (!G_uiTempWalked) 484 { 485 Status = pAcpiTkWalkNamespace(ACPI_TYPE_THERMAL, ACPI_ROOT_OBJECT, 486 ACPI_UINT32_MAX, AcpiCallbackTemperature, 487 NULL, NULL); 488 G_uiTempWalked = 1; 489 } 490 491 if (G_ahTemp) 492 { 493 Result.Length = sizeof(Object); 494 Result.Pointer = &Object; 495 Status = pAcpiTkEvaluateObject(G_ahTemp, NULL, NULL, &Result); 496 if (Status == AE_OK) 497 ulTemp = (Object.Integer.Value - 2732) / 10; 498 } 499 500 return ulTemp; 501 } 502
Note:
See TracChangeset
for help on using the changeset viewer.