diff options
Diffstat (limited to 'hardinfo2')
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 | ||||
-rw-r--r-- | hardinfo2/callbacks.c | 1 | ||||
-rw-r--r-- | hardinfo2/devices.c | 16 | ||||
-rw-r--r-- | hardinfo2/pixmaps/battery.png | bin | 0 -> 1059 bytes |
12 files changed, 183 insertions, 2 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 diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index da193c47..b04043d2 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -58,6 +58,7 @@ void cb_about() "SHA1 implementation by Steve Raid", "Blowfish implementation by Paul Kocher", "Some code partly based on x86cpucaps by Osamu Kayasono", + "Artwork by the GNOME Project and Tango Project", NULL }; diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c index 1180a092..d5a1cefd 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/devices.c @@ -29,6 +29,7 @@ enum { DEVICES_PCI, DEVICES_USB, DEVICES_PRINTERS, + DEVICES_BATTERY, DEVICES_INPUT, DEVICES_STORAGE, } Entries; @@ -38,6 +39,7 @@ static ModuleEntry hi_entries[] = { {"PCI Devices", "devices.png"}, {"USB Devices", "usb.png"}, {"Printers", "printer.png"}, + {"Battery", "battery.png"}, {"Input Devices", "keyboard.png"}, {"Storage", "hdd.png"}, }; @@ -48,11 +50,12 @@ static gchar *printer_list = NULL; static gchar *pci_list = ""; static gchar *input_list = NULL; static gchar *storage_list = ""; +static gchar *battery_list = NULL; #define WALK_UNTIL(x) while((*buf != '\0') && (*buf != x)) buf++ #define GET_STR(field_name,ptr) \ - if (strstr(tmp[0], field_name)) { \ + if (!ptr && strstr(tmp[0], field_name)) { \ ptr = g_markup_escape_text(g_strstrip(tmp[1]), strlen(tmp[1])); \ g_strfreev(tmp); \ continue; \ @@ -66,6 +69,7 @@ static gchar *storage_list = ""; #include <arch/this/inputdevices.h> #include <arch/this/usb.h> #include <arch/this/storage.h> +#include <arch/this/battery.h> static void detect_devices(void) @@ -92,6 +96,9 @@ detect_devices(void) shell_status_update("Scanning SCSI devices..."); scan_scsi(); + + shell_status_update("Scanning batteries..."); + scan_battery(); } gchar * @@ -108,6 +115,9 @@ void hi_reload(gint entry) { switch (entry) { + case DEVICES_BATTERY: + scan_battery(); + break; case DEVICES_INPUT: scan_inputdevices(); break; @@ -138,6 +148,10 @@ hi_info(gint entry) } switch (entry) { + case DEVICES_BATTERY: + return g_strdup_printf("%s\n" + "[$ShellParam$]\n" + "ReloadInterval=4000\n", battery_list); case DEVICES_KERNEL_MODULES: return g_strdup_printf("[Loaded Modules]\n" "%s" diff --git a/hardinfo2/pixmaps/battery.png b/hardinfo2/pixmaps/battery.png Binary files differnew file mode 100644 index 00000000..ad456749 --- /dev/null +++ b/hardinfo2/pixmaps/battery.png |