small bit of style cleanup; added additional checks to see if a battery was damaged or it is just an empty slot
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41319 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
/*
|
||||
* Copyright 2004-2011, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef POWER_MANAGMENT_H
|
||||
#define POWER_MANAGMENT_H
|
||||
|
||||
|
||||
#include <Drivers.h>
|
||||
|
||||
|
||||
// io controls
|
||||
enum {
|
||||
enum {
|
||||
// ioctl response with kMagicFreqID
|
||||
IDENTIFY_DEVICE = B_DEVICE_OP_CODES_END + 20001,
|
||||
|
||||
|
||||
// CPU Frequence:
|
||||
// get a list of freq_info, the list is terminated with a element with
|
||||
// frequency = 0
|
||||
@@ -20,13 +26,13 @@ enum {
|
||||
WATCH_CPU_FREQ,
|
||||
// stop all watching ioctl, ioctl return B_ERROR
|
||||
STOP_WATCHING_CPU_FREQ,
|
||||
|
||||
|
||||
GET_BATTERY_INFO,
|
||||
GET_EXTENDED_BATTERY_INFO,
|
||||
WATCH_BATTERY,
|
||||
STOP_WATCHING_BATTERY
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// CPU Frequence:
|
||||
// magic id returned by IDENTIFY_DEVICE
|
||||
@@ -35,6 +41,7 @@ const uint32 kMagicFreqID = 48921;
|
||||
|
||||
#define MAX_CPU_FREQUENCY_STATES 10
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16 frequency; // [Mhz]
|
||||
uint16 volts;
|
||||
@@ -47,6 +54,8 @@ typedef struct {
|
||||
// magic id returned by IDENTIFY_DEVICE
|
||||
const uint32 kMagicACPIBatteryID = 17822;
|
||||
|
||||
|
||||
// Our known battery states
|
||||
#define BATTERY_DISCHARGING 0x01
|
||||
#define BATTERY_CHARGING 0x02
|
||||
#define BATTERY_CRITICAL_STATE 0x04
|
||||
@@ -73,7 +82,7 @@ typedef struct {
|
||||
char model_number[32];
|
||||
char serial_number[32];
|
||||
char type[32];
|
||||
char oem_info[32];
|
||||
char oem_info[32];
|
||||
} acpi_extended_battery_info;
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ ReadBatteryStatus(battery_driver_cookie* cookie, acpi_battery_info* batteryStatu
|
||||
|
||||
pointer = object->data.package.objects;
|
||||
batteryStatus->state = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||
? pointer->data.integer : BATTERY_CRITICAL_STATE;
|
||||
? pointer->data.integer : BATTERY_CRITICAL_STATE;
|
||||
|
||||
pointer++;
|
||||
batteryStatus->current_rate = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||
@@ -75,19 +75,21 @@ ReadBatteryStatus(battery_driver_cookie* cookie, acpi_battery_info* batteryStatu
|
||||
? pointer->data.integer : -1;
|
||||
|
||||
/* If key values are all < 0, it is likely that the battery slot is empty
|
||||
or the battery is damaged. Set BATTERY_CRITICAL_STATE */
|
||||
* or the battery is damaged. Set BATTERY_CRITICAL_STATE
|
||||
*/
|
||||
if (batteryStatus->voltage < 0
|
||||
&& batteryStatus->current_rate < 0
|
||||
&& batteryStatus->capacity < 0) {
|
||||
batteryStatus->state = BATTERY_CRITICAL_STATE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
exit:
|
||||
free(buffer.pointer);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ReadBatteryInfo(battery_driver_cookie* cookie,
|
||||
acpi_extended_battery_info* batteryInfo)
|
||||
|
||||
@@ -136,8 +136,14 @@ BatteryInfoView::_FillStringList()
|
||||
fontString->string = B_TRANSLATE("Battery charging");
|
||||
else if (fBatteryInfo.state & BATTERY_DISCHARGING)
|
||||
fontString->string = B_TRANSLATE("Battery discharging");
|
||||
else if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
|
||||
else if (fBatteryInfo.state & BATTERY_CRITICAL_STATE
|
||||
&& strcmp(fBatteryExtendedInfo.model_number, "")
|
||||
&& strcmp(fBatteryExtendedInfo.serial_number, "")
|
||||
&& strcmp(fBatteryExtendedInfo.type, "")
|
||||
&& strcmp(fBatteryExtendedInfo.oem_info, ""))
|
||||
fontString->string = B_TRANSLATE("Empty battery slot");
|
||||
else if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
|
||||
fontString->string = B_TRANSLATE("Damaged battery");
|
||||
else
|
||||
fontString->string = B_TRANSLATE("Battery unused");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user