diff options
Diffstat (limited to 'hardinfo2/arch/linux')
l--------- | hardinfo2/arch/linux/armv4l/battery.h | 1 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/battery.h | 129 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/sensors.h | 32 | ||||
l--------- | hardinfo2/arch/linux/m68k/battery.h | 1 | ||||
l--------- | hardinfo2/arch/linux/mips/battery.h | 1 | ||||
l--------- | hardinfo2/arch/linux/parisc/battery.h | 1 | ||||
l--------- | hardinfo2/arch/linux/ppc/battery.h | 1 | ||||
l--------- | hardinfo2/arch/linux/sparc/battery.h | 1 | ||||
l--------- | hardinfo2/arch/linux/x86/battery.h | 1 |
9 files changed, 167 insertions, 1 deletions
diff --git a/hardinfo2/arch/linux/armv4l/battery.h b/hardinfo2/arch/linux/armv4l/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/armv4l/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file diff --git a/hardinfo2/arch/linux/common/battery.h b/hardinfo2/arch/linux/common/battery.h new file mode 100644 index 00000000..dc003459 --- /dev/null +++ b/hardinfo2/arch/linux/common/battery.h @@ -0,0 +1,129 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +static void +scan_battery(void) +{ + gchar *acpi_path; + + gchar *present = NULL; + gchar *capacity = NULL; + gchar *technology = NULL; + gchar *voltage = NULL; + gchar *model = NULL, *serial = NULL, *type = NULL; + gchar *state = NULL, *rate = NULL; + gchar *remaining = NULL; + + if (battery_list) { + g_free(battery_list); + } + battery_list = g_strdup(""); + + acpi_path = g_strdup("/proc/acpi/battery"); + if (g_file_test(acpi_path, G_FILE_TEST_EXISTS)) { + GDir *acpi; + + if ((acpi = g_dir_open(acpi_path, 0, NULL))) { + const gchar *entry; + + while ((entry = g_dir_read_name(acpi))) { + gchar *path = g_strdup_printf("%s/%s/info", acpi_path, entry); + FILE *f; + gchar buffer[256]; + gdouble charge_rate = 1.0; + + f = fopen(path, "r"); + g_free(path); + + if (!f) + goto cleanup; + + while (fgets(buffer, 256, f)) { + gchar **tmp = g_strsplit(buffer, ":", 2); + + GET_STR("present", present); + GET_STR("design capacity", capacity); + GET_STR("battery technology", technology); + GET_STR("design voltage", voltage); + GET_STR("model number", model); + GET_STR("serial number", serial); + GET_STR("battery type", type); + + g_strfreev(tmp); + } + fclose(f); + + path = g_strdup_printf("%s/%s/state", acpi_path, entry); + f = fopen(path, "r"); + g_free(path); + + if (!f) + goto cleanup; + + while (fgets(buffer, 256, f)) { + gchar **tmp = g_strsplit(buffer, ":", 2); + + GET_STR("charging state", state); + GET_STR("present rate", rate); + GET_STR("remaining capacity", remaining); + + g_strfreev(tmp); + } + + fclose(f); + + if (g_str_equal(present, "yes")) { + charge_rate = atof(remaining) / atof(capacity); + + battery_list = g_strdup_printf("%s\n[Battery: %s]\n" + "State=%s (load: %s)\n" + "Capacity=%s / %s (%.2f%%)\n" + "Battery Technology=%s (%s)\n" + "Model Number=%s\n" + "Serial Number=%s\n", + battery_list, + entry, + state, rate, + remaining, capacity, charge_rate * 100.0, + technology, type, + model, + serial); + } + + cleanup: + g_free(present); + g_free(capacity); + g_free(technology); + g_free(type); + g_free(model); + g_free(serial); + g_free(state); + g_free(remaining); + g_free(rate); + + present = capacity = technology = type = \ + model = serial = state = remaining = rate = NULL; + } + + g_dir_close(acpi); + } + } + + g_free(acpi_path); + +} diff --git a/hardinfo2/arch/linux/common/sensors.h b/hardinfo2/arch/linux/common/sensors.h index ef834de2..af707076 100644 --- a/hardinfo2/arch/linux/common/sensors.h +++ b/hardinfo2/arch/linux/common/sensors.h @@ -232,6 +232,36 @@ read_sensors(void) path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", ++hwmon); } - g_free(path_hwmon); + g_free(path_hwmon); + + path_hwmon = g_strdup("/proc/acpi/thermal_zone"); + if (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { + GDir *tz; + + if ((tz = g_dir_open(path_hwmon, 0, NULL))) { + const gchar *entry; + + sensors = g_strdup_printf("%s\n[ACPI Thermal Zone]\n", sensors); + while ((entry = g_dir_read_name(tz))) { + gchar *path = g_strdup_printf("%s/%s/temperature", path_hwmon, entry); + gchar *contents; + + if (g_file_get_contents(path, &contents, NULL, NULL)) { + int temperature; + + sscanf(contents, "temperature: %d C", &temperature); + + sensors = g_strdup_printf("%s\n%s=%d\302\260C\n", + sensors, entry, temperature); + + g_free(contents); + } + } + + g_dir_close(tz); + } + } + + g_free(path_hwmon); } diff --git a/hardinfo2/arch/linux/m68k/battery.h b/hardinfo2/arch/linux/m68k/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/m68k/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file diff --git a/hardinfo2/arch/linux/mips/battery.h b/hardinfo2/arch/linux/mips/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/mips/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file diff --git a/hardinfo2/arch/linux/parisc/battery.h b/hardinfo2/arch/linux/parisc/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/parisc/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file diff --git a/hardinfo2/arch/linux/ppc/battery.h b/hardinfo2/arch/linux/ppc/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/ppc/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file diff --git a/hardinfo2/arch/linux/sparc/battery.h b/hardinfo2/arch/linux/sparc/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/sparc/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file diff --git a/hardinfo2/arch/linux/x86/battery.h b/hardinfo2/arch/linux/x86/battery.h new file mode 120000 index 00000000..317622f3 --- /dev/null +++ b/hardinfo2/arch/linux/x86/battery.h @@ -0,0 +1 @@ +../../linux/battery.h
\ No newline at end of file |