gkrellm Windfarm support

Michael Buesch <[email protected]>
Newsgroups gmane.comp.gnome.apps.gkrellm
Message-ID <[email protected]>
Hi, this is a patch to add Windfarm support to GKrellm.

Windfarm is the Temperature/Voltage management system
in the PowerMac G5.

Please consider for inclusion.

Signed-off-by: Michael Buesch <[email protected]>

Index: gkrellm-2.2.9/src/sysdeps/linux.c
===================================================================
--- gkrellm-2.2.9.orig/src/sysdeps/linux.c	2006-03-30 00:23:37.000000000 +0200
+++ gkrellm-2.2.9/src/sysdeps/linux.c	2006-07-20 21:37:06.000000000 +0200
@@ -4,6 +4,8 @@
 |  Author:  Bill Wilson    [email protected]
 |  Latest versions might be found at:  http://gkrellm.net
 |
+|  Windfarm code written by Michael Buesch <[email protected]>
+|
 |  This program is free software which I release under the GNU General Public
 |  License. You may redistribute and/or modify this program under the terms
 |  of that license as published by the Free Software Foundation; either
@@ -1889,6 +1891,7 @@
 #define	SENSORS_DIR			"/proc/sys/dev/sensors"
 #define SYSFS_I2C_DIR		"/sys/bus/i2c/devices"
 #define UNINORTH_DIR       "/sys/devices/temperatures"
+#define WINDFARM_DIR		"/sys/devices/platform/windfarm.%d"
 
   /* mbmon and hddtemp sensor interfaces are handled in sensors-common.c
   */
@@ -1898,6 +1901,7 @@
 #define	NVIDIA_SETTINGS_INTERFACE	3
 #define IBM_ACPI_INTERFACE		4
 #define UNINORTH_INTERFACE    5
+#define WINDFARM_INTERFACE		6
 
 #define IBM_ACPI_FAN_FILE	"/proc/acpi/ibm/fan"
 #define IBM_ACPI_THERMAL	"/proc/acpi/ibm/thermal"
@@ -2131,7 +2135,7 @@
 #endif
 		}
 
-    if (interface == UNINORTH_INTERFACE)
+    if (interface == UNINORTH_INTERFACE || interface == WINDFARM_INTERFACE)
         {
         if ((f = fopen(sensor_path, "r")))
             {
@@ -2139,6 +2143,7 @@
             fclose(f);
             return TRUE;
             }
+	return FALSE;
         }
 
 	if ((f = fopen(sensor_path, "r")) == NULL)
@@ -2195,6 +2200,17 @@
 		return gkrellm_sys_sensors_mbmon_get_value(sensor_path, fan);
 		}
 
+	if (interface == WINDFARM_INTERFACE) {
+		f = fopen(sensor_path, "r");
+		if (f) {
+			fscanf(f, "%d", &n);
+			fclose(f);
+			*fan = n;
+			result = TRUE;
+		}
+		return result;
+	}
+
 	if ((f = fopen(sensor_path, "r")) == NULL)
 		return FALSE;
 	fgets(buf, sizeof(buf), f);
@@ -2219,6 +2235,7 @@
 	gchar	buf[64];
 	gfloat	V, t[3];
 	gint	n;
+	gboolean	result = FALSE;
 
 	if (interface == MBMON_INTERFACE)
 		{
@@ -2226,6 +2243,16 @@
 		return gkrellm_sys_sensors_mbmon_get_value(sensor_path, volt);
 		}
 
+	if (interface == WINDFARM_INTERFACE) {
+		f = fopen(sensor_path, "r");
+		if (f) {
+			fscanf(f, "%f", volt);
+			fclose(f);
+			result = TRUE;
+		}
+		return result;
+	}
+
 	if ((f = fopen(sensor_path, "r")) == NULL)
 		return FALSE;
 	fgets(buf, sizeof(buf), f);
@@ -2450,10 +2477,10 @@
 	GDir			*dir, *chip_dir;
 	VoltDefault		*voltdefault;
 	gint			id = 0;
-	gint			type, voltdefaultsize;
+	gint			type, voltdefaultsize, cnt;
 	gfloat			factor, offset;
 	gchar			*name, *chip_name, *fixed_chip_name, *path, *default_label;
-	gchar			*vref, *sensor_path, *sensor_name, id_name[128];
+	gchar			*vref, *sensor_path, *sensor_name, id_name[128], pbuf[128];
 	struct lconv	*lc;
 
 	lc = localeconv();
@@ -2598,6 +2625,92 @@
         }
 
 
+	/* Windfarm (PowerMac G5, others?)) */
+	cnt = 0;
+	do {
+		snprintf(pbuf, sizeof(pbuf), WINDFARM_DIR, cnt++);
+		if ((dir = g_dir_open(pbuf, 0, NULL)) != NULL) {
+			while ((sensor_name = (gchar *) g_dir_read_name(dir)) != NULL) {
+				sensor_path = g_build_filename(pbuf, sensor_name, NULL);
+				if (strncmp(sensor_name, "cpu-temp-", 9) == 0) {
+					sscanf(sensor_name + 9, "%d", &id);
+					snprintf(id_name, sizeof(id_name), "CPU %d", id);
+					gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE,
+								   sensor_path,
+								   id_name, id, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, id_name);
+				} else if (strcmp(sensor_name, "backside-temp") == 0) {
+					gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE,
+								   sensor_path,
+								   "Backside", 0, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, "Backside");
+				} else if (strcmp(sensor_name, "backside-fan") == 0) {
+					gkrellm_sensors_add_sensor(SENSOR_FAN,
+								   sensor_path,
+								   "Backside", 0, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, "Backside");
+				} else if (strncmp(sensor_name, "cpu-front-fan-", 14) == 0) {
+					sscanf(sensor_name + 14, "%d", &id);
+					snprintf(id_name, sizeof(id_name), "CPU Front %d", id);
+					gkrellm_sensors_add_sensor(SENSOR_FAN,
+								   sensor_path,
+								   id_name, id, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, id_name);
+				} else if (strncmp(sensor_name, "cpu-rear-fan-", 13) == 0) {
+					sscanf(sensor_name + 13, "%d", &id);
+					snprintf(id_name, sizeof(id_name), "CPU Rear %d", id);
+					gkrellm_sensors_add_sensor(SENSOR_FAN,
+								   sensor_path,
+								   id_name, id, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, id_name);
+				} else if (strncmp(sensor_name, "cpu-pump-", 9) == 0) {
+					/* <johill> well, a fan is just an airpump too, right ;) */
+					sscanf(sensor_name + 9, "%d", &id);
+					snprintf(id_name, sizeof(id_name), "CPU Pump %d", id);
+					gkrellm_sensors_add_sensor(SENSOR_FAN,
+								   sensor_path,
+								   id_name, id, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, id_name);
+				} else if (strcmp(sensor_name, "hd-temp") == 0) {
+					gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE,
+								   sensor_path,
+								   "Harddisk", 0, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, "Harddisk");
+				} else if (strcmp(sensor_name, "slots-fan") == 0) {
+					gkrellm_sensors_add_sensor(SENSOR_FAN,
+								   sensor_path,
+								   "Slots", 0, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, "Slots");
+				} else if (strcmp(sensor_name, "drive-bay-fan") == 0) {
+					gkrellm_sensors_add_sensor(SENSOR_FAN,
+								   sensor_path,
+								   "Drive Bay", 0, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, "Drive Bay");
+				} else if (strncmp(sensor_name, "cpu-voltage-", 12) == 0) {
+					sscanf(sensor_name + 12, "%d", &id);
+					snprintf(id_name, sizeof(id_name), "CPU %d", id);
+					gkrellm_sensors_add_sensor(SENSOR_VOLTAGE,
+								   sensor_path,
+								   id_name, id, 0,
+								   WINDFARM_INTERFACE,
+								   1.0, 0.0, NULL, id_name);
+				}
+				g_free(sensor_path);
+			}
+			g_dir_close(dir);
+		}
+	} while (dir != NULL);
+
+
 	if ((dir = g_dir_open(SENSORS_DIR, 0, NULL)) == NULL)
 		{
 		sysfs_sensors_init();


-- 
Greetings Michael.
_______________________________________________
Gkrellm mailing list
[email protected]
http://lists.jutley.org/cgi-bin/mailman/listinfo/gkrellm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.