--- Begin Message ---
Package: wmtemp
Version: 0.0.6-3
Severity: wishlist
On my (most?) laptop(s) wmtemp won't work because lm-sensors finds no chip.
But the acpi thermal zone
has temps and trip points for alarms. It would be nice for wmtemp to use
these as alternative to
lm-sensors. I made the modifications and attach the patch file.
-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.32-5-686 (SMP w/1 CPU core)
Locale: LANG=en_US.ISO-8859-15, LC_CTYPE=en_US.ISO-8859-15
(charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/dash
Versions of packages wmtemp depends on:
ii libc6 2.11.2-1 Embedded GNU C Library: Shared
lib
ii libsensors3 1:2.10.8-2 library to read
temperature/voltag
ii libx11-6 2:1.3.3-3 X11 client-side library
ii libxext6 2:1.1.1-3 X11 miscellaneous extension
librar
ii libxpm4 1:3.5.8-1 X11 pixmap library
ii lm-sensors 1:3.1.2-6 utilities to read
temperature/volt
wmtemp recommends no packages.
wmtemp suggests no packages.
-- no debconf information
diff -Naur wmtemp.orig//main.c wmtemp.new//main.c
--- wmtemp.orig//main.c 2008-04-28 04:18:38.000000000 -0500
+++ wmtemp.new//main.c 2010-09-26 08:51:24.000000000 -0500
@@ -23,6 +23,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
+ 09/25/2010 HVW Modified to use acpi if no lm-sensors chip found
+
*/
#include <stdlib.h>
@@ -66,11 +68,14 @@
static void parse_arguments(int argc, char **argv);
static void print_help(char *prog);
+int use_acpi;
+
int main(int argc, char **argv)
{
XEvent event;
XpmColorSymbol colors[2] = { {"Back0", NULL, 0}, {"Back1", NULL, 0} };
int ncolor = 0;
+ use_acpi = 0;
/* Parse CommandLine */
parse_arguments(argc, argv);
@@ -92,8 +97,12 @@
backlight_off_xpm = celcius_off_xpm;
}
- /* Initialize Application */
- temp_init(configfile);
+ /* Initialize Application */
+ temp_init(configfile);
+
+ if ( use_acpi == 1 )
+ get_acpi_trip_points(&alarm_cpu, &alarm_sys);
+
dockapp_open_window(display_name, PACKAGE, SIZE, SIZE, argc, argv);
dockapp_set_eventmask(ButtonPressMask);
@@ -234,9 +243,10 @@
}
/* redraw digit */
- temp_getusage(&cpu_temp, &sys_temp);
- draw_cpudigit(cpu_temp);
- draw_sysdigit(sys_temp);
+// temp_getusage(&cpu_temp, &sys_temp);
+ get_acpi_trip_points(&cpu_temp, &sys_temp);
+ draw_cpudigit(cpu_temp);
+ draw_sysdigit(sys_temp);
/* show */
dockapp_copy2window(pixmap);
diff -Naur wmtemp.orig//temp.c wmtemp.new//temp.c
--- wmtemp.orig//temp.c 2004-03-09 03:31:30.000000000 -0600
+++ wmtemp.new//temp.c 2010-09-25 16:24:55.000000000 -0500
@@ -2,11 +2,13 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#include <ctype.h>
#include <sensors.h>
#include "temp.h"
static FILE *f = NULL;
+static FILE *acpi = NULL;
static char sensors = 0;
static const sensors_chip_name *chip_name = NULL;
@@ -14,6 +16,10 @@
char *cpu_feature_name = "temp1";
char *sys_feature_name = "temp2";
+char *acpi_sys_temperature = "/proc/acpi/thermal_zone/TZS1/temperature";
+char *acpi_sys_trip_pts = "/proc/acpi/thermal_zone/TZS1/trip_points";
+char *acpi_cpu_temperature = "/proc/acpi/thermal_zone/TZS0/temperature";
+char *acpi_cpu_trip_pts = "/proc/acpi/thermal_zone/TZS0/trip_points";
temperature_t t_type = CELCIUS;
@@ -38,14 +44,25 @@
f = fopen(filename, "r");
if (f == NULL) {
- fprintf(stderr, "could not open configfile %s: %s\n", filename,
- strerror(errno));
+ if ( try_acpid() == 1 ) {
+// fprintf(stderr, "could not open configfile %s: %s, but acpi is active\n", filename,strerror(errno));
+ use_acpi = 1;
+ }
+ else {
+ fprintf(stderr, "could not open configfile %s: %s, and acpi is not active\n", filename,strerror(errno));
exit(1);
+ }
}
if (sensors_init(f)) {
- fprintf(stderr, "could not initialize sensors\n");
+ if ( try_acpid() == 1 ) {
+// fprintf(stderr, "could not initialize sensors, but acpi is active\n");
+ use_acpi = 1;
+ }
+ else {
+ fprintf(stderr, "could not initialize sensors, and acpi is not active\n");
exit(1);
+ }
}
sensors = 1;
@@ -68,14 +85,21 @@
}
if (chip_name == NULL) {
- fprintf(stderr, "could not find a suitable chip\n");
+ if ( try_acpid() == 1 ) {
+// fprintf(stderr, "could not find a suitable chip, but acpi is active\n");
+ use_acpi = 1;
+ }
+ else {
+ fprintf(stderr, "could not find a suitable chip, and acpi is not active\n");
exit(1);
+ }
}
}
void temp_getusage(unsigned int *cpu_temp, unsigned int *sys_temp) {
double cpu, sys;
+ if ( use_acpi == 0 ) {
sensors_get_feature(*chip_name, cpu_feature, &cpu);
sensors_get_feature(*chip_name, sys_feature, &sys);
@@ -86,7 +110,140 @@
cpu = TO_KELVIN(cpu);
sys = TO_KELVIN(sys);
}
+ }
+ else {
+ get_acpid_temps(&cpu, &sys);
+ }
*cpu_temp = (unsigned int)(cpu);
*sys_temp = (unsigned int)(sys);
}
+
+int try_acpid(void)
+/* returns 1 on success 0 on failure */
+{
+ acpi = fopen(acpi_cpu_temperature, "r");
+ if (acpi == NULL)
+ return 0;
+ fclose(acpi);
+ acpi = fopen(acpi_cpu_trip_pts, "r");
+ if (acpi == NULL)
+ return 0;
+ fclose(acpi);
+ return 1;
+}
+
+
+void get_acpid_temps(double *cpu_temp, double *sys_temp)
+{
+
+ char buff[1024],
+ *p,
+ *q;
+ int x,y;
+ x = 0;y = 0;
+ FILE *fp;
+ if ( (fp = fopen (acpi_cpu_temperature, "r")) ) {
+ while (fgets(buff, 1024, fp)) {
+ if ( (q = strrchr(buff, '\n')) ) *q-- = '\0';
+ for (p=buff; *p && isspace(*p); p++) ;
+ if (strstr(p, "temperature") == p) {
+ while (*p && *p != ':') p++;
+ while (*p && *p == ':') p++;
+ x = atof(p);
+ }
+ }
+ fclose(fp);
+ }
+ if ( (fp = fopen (acpi_sys_temperature, "r")) ) {
+ while (fgets(buff, 1024, fp)) {
+ if ( (q = strrchr(buff, '\n')) ) *q-- = '\0';
+ for (p=buff; *p && isspace(*p); p++) ;
+ if (strstr(p, "temperature") == p) {
+ while (*p && *p != ':') p++;
+ while (*p && *p == ':') p++;
+ y = atof(p);
+ }
+ }
+ fclose(fp);
+ }
+ *cpu_temp = x;
+ *sys_temp = y;
+// printf("%f %f\n",x,y);
+// exit(0);
+}
+
+void get_acpi_trip_points(unsigned int *alarm_cpu, unsigned int *alarm_sys)
+{
+
+ char buff[1024],
+ *p,
+ *q;
+ int x,y;
+ x = 0;y = 0;
+ FILE *fp;
+//critical (S5): 100 C
+//passive: 95 C: tc1=4 tc2=3 tsp=150 devices=CPU0
+ if ( (fp = fopen (acpi_cpu_trip_pts, "r")) ) {
+ while (fgets(buff, 1024, fp)) {
+// printf("%s\n",buff);
+ if ( (q = strrchr(buff, '\n')) ) *q-- = '\0';
+ for (p=buff; *p && isspace(*p); p++) ;
+ if (strstr(p, "passive") == p) {
+ while (*p && *p != ':') p++;
+ while (*p && *p == ':') p++;
+ x = atoi(p);
+ }
+ }
+ fclose(fp);
+ }
+//critical (S5): 70 C
+ if ( (fp = fopen (acpi_sys_trip_pts, "r")) ) {
+ while (fgets(buff, 1024, fp)) {
+ if ( (q = strrchr(buff, '\n')) ) *q-- = '\0';
+ for (p=buff; *p && isspace(*p); p++) ;
+ if (strstr(p, "critical") == p) {
+ while (*p && *p != ':') p++;
+ while (*p && *p == ':') p++;
+ y = atoi(p);
+ }
+ }
+ fclose(fp);
+ }
+ *alarm_cpu = x;
+ *alarm_sys = y;
+// printf("cpu = %d sys = %d\n",x,y);
+// exit(0);
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -Naur wmtemp.orig//temp.h wmtemp.new//temp.h
--- wmtemp.orig//temp.h 2004-03-11 17:04:27.000000000 -0600
+++ wmtemp.new//temp.h 2010-09-25 15:49:52.000000000 -0500
@@ -2,7 +2,7 @@
#define SHO_TEMP_H
#define PACKAGE "wmtemp"
-#define VERSION "0.0.4"
+#define VERSION "0.0.4-hvw"
#define TO_FAHRENHEIT(t) (((double)(t) * 1.8) + 32.0)
#define TO_KELVIN(t) ((double)(t) + 273.0)
@@ -16,7 +16,13 @@
extern temperature_t t_type;
+extern int use_acpi;
+
void temp_init(const char *filename);
void temp_getusage(unsigned int *cpu_temp, unsigned int *sys_temp);
+int try_acpid(void);
+void get_acpid_temps(double *cpu_temp, double *sys_temp);
+void get_acpi_trip_points(unsigned int *alarm_cpu, unsigned int *alarm_sys);
+
#endif
--- End Message ---