1 | /* ----------------------------------------------------------------------- * |
---|
2 | * |
---|
3 | * Pportions of this file taken from the dmidecode project |
---|
4 | * |
---|
5 | * Copyright (C) 2000-2002 Alan Cox <alan@redhat.com> |
---|
6 | * Copyright (C) 2002-2008 Jean Delvare <khali@linux-fr.org> |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
21 | * |
---|
22 | * For the avoidance of doubt the "preferred form" of this code is one which |
---|
23 | * is in an open unpatent encumbered format. Where cryptographic key signing |
---|
24 | * forms part of the process of creating an executable the information |
---|
25 | * including keys needed to generate an equivalently functional executable |
---|
26 | * are deemed to be part of the source code. |
---|
27 | */ |
---|
28 | |
---|
29 | #include <dmi/dmi.h> |
---|
30 | #include <stdio.h> |
---|
31 | const char *dmi_battery_chemistry(uint8_t code) |
---|
32 | { |
---|
33 | /* 3.3.23.1 */ |
---|
34 | static const char *chemistry[] = { |
---|
35 | "Other", /* 0x01 */ |
---|
36 | "Unknown", |
---|
37 | "Lead Acid", |
---|
38 | "Nickel Cadmium", |
---|
39 | "Nickel Metal Hydride", |
---|
40 | "Lithium Ion", |
---|
41 | "Zinc Air", |
---|
42 | "Lithium Polymer" /* 0x08 */ |
---|
43 | }; |
---|
44 | |
---|
45 | if (code >= 0x01 && code <= 0x08) |
---|
46 | return chemistry[code - 0x01]; |
---|
47 | return out_of_spec; |
---|
48 | } |
---|
49 | |
---|
50 | void dmi_battery_capacity(uint16_t code, uint8_t multiplier, char *capacity) |
---|
51 | { |
---|
52 | if (code == 0) |
---|
53 | sprintf(capacity, "%s", "Unknown"); |
---|
54 | else |
---|
55 | sprintf(capacity, "%u mWh", code * multiplier); |
---|
56 | } |
---|
57 | |
---|
58 | void dmi_battery_voltage(uint16_t code, char *voltage) |
---|
59 | { |
---|
60 | if (code == 0) |
---|
61 | sprintf(voltage, "%s", "Unknown"); |
---|
62 | else |
---|
63 | sprintf(voltage, "%u mV", code); |
---|
64 | } |
---|
65 | |
---|
66 | void dmi_battery_maximum_error(uint8_t code, char *error) |
---|
67 | { |
---|
68 | if (code == 0xFF) |
---|
69 | sprintf(error, "%s", "Unknown"); |
---|
70 | else |
---|
71 | sprintf(error, "%u%%", code); |
---|
72 | } |
---|