~ubuntu-branches/debian/sid/hal/sid

« back to all changes in this revision

Viewing changes to hald/util_pm.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 * CVSID: $Id$
3
2
 *
4
 
 * utili_pm.c - Various Powermanagement related utilities
 
3
 * util_pm.c - Various power management related utilities that do not need
 
4
 *             to use HalDevice. This is suitable to use in addons and probers.
5
5
 *
6
6
 * Copyright (C) 2005 Richard Hughes <richard@hughsie.com>
7
7
 * Copyright (C) 2005 Danny Kukawka <danny.kukawka@web.de>
70
70
            strcasecmp (type, "pbac") == 0) {
71
71
                return "lead-acid";
72
72
        }
73
 
        if (strcasecmp (type, "lip") == 0) {
 
73
        if (strcasecmp (type, "lip") == 0 ||
 
74
            strcasecmp (type, "lipo") == 0) {
74
75
                return "lithium-polymer";
75
76
        }
76
77
        if (strcasecmp (type, "nimh") == 0) {
77
78
                return "nickel-metal-hydride";
78
79
        }
 
80
        if (strcasecmp (type, "lifo") == 0) {
 
81
                return "lithium-iron-phosphate";
 
82
        }
79
83
        return "unknown";
80
84
}
81
85
 
82
86
/**  
83
 
 *  util_compute_percentage_charge:
84
 
 *  @id:                 Optional ID given to this battery. Unused at present.
85
 
 *  @chargeLevel:        The current charge level of the battery (typically mWh)
86
 
 *  @chargeLastFull:     The last "full" charge of the battery (typically mWh)
87
 
 *  Returns:             Percentage, -1 if invalid
88
 
 *
89
 
 *  Given all the required parameters, this function will return the percentage
90
 
 *  charge remaining. There are lots of checks here as ACPI is often broken.
91
 
 */
92
 
int 
93
 
util_compute_percentage_charge (const char *id,
94
 
                             int chargeLevel,
95
 
                             int chargeLastFull)
96
 
{
97
 
        int percentage;
98
 
        /* make sure we have chargelevel */
99
 
        if (chargeLevel <= 0) {
100
 
                HAL_WARNING (("chargeLevel %i, returning -1!", chargeLevel));
101
 
                return -1;
102
 
        }
103
 
        /* make sure not division by zero */
104
 
        if (chargeLastFull > 0)
105
 
                percentage = ((double) chargeLevel / (double) chargeLastFull) * 100;
106
 
        else {
107
 
                HAL_WARNING (("chargeLastFull %i, percentage returning -1!", chargeLastFull));
108
 
                return -1;
109
 
        }
110
 
        /* Some bios's will report this higher than 100, limit it here */
111
 
        if (percentage > 100) {
112
 
                HAL_WARNING (("Percentage %i, returning 100!", percentage));
113
 
                return 100;
114
 
        }
115
 
        /* Something really isn't right if we get a negative... */
116
 
        if (percentage < 0) {
117
 
                HAL_WARNING (("Percentage %i, returning -1!", percentage));
118
 
                return -1;
119
 
        }
120
 
        return percentage;
121
 
}
122
 
 
123
 
/**  
124
87
 *  util_compute_time_remaining:
125
88
 *  @id:                 Optional ID given to this battery. Unused at present.
126
89
 *  @chargeRate:         The "rate" (typically mW)