]> git.sur5r.net Git - i3/i3status/commitdiff
Merge getting thermal zone temperature from atsutane, thanks!
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 22 May 2009 19:24:28 +0000 (21:24 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 22 May 2009 19:24:28 +0000 (21:24 +0200)
debian/changelog
i3status.1
i3status.c
i3status.conf
i3status.h

index f7a0b057975108507810536e7b29ce98c535a3c3..dbdaf9beaca4ff787533a1fa8ed5f0ae17550b74 100644 (file)
@@ -1,3 +1,9 @@
+i3status (1.1-1) unstable; urgency=low
+
+  * Implement getting temperature from thermal zones (Thanks atsutane)
+
+ -- Michael Stapelberg <michael@stapelberg.de>  Fri, 22 May 2009 21:23:44 +0200
+
 i3status (1.0-1) unstable; urgency=low
 
   * Initial release
index 417dc7c634edf330fcdb9424beb91da11fd71df6..facd04359e6a5e8cc985b226986dea64b402ed98 100644 (file)
@@ -90,6 +90,11 @@ red/green.
 Get current speed of the ethernet interface using the same mechanism as
 ethtool. You need to start i3status with root privileges to use this.
 
+.TP
+.B get_cpu_temperature
+Gets the temperature of the first thermal zone or the specified thermal zone
+(if any). Use it to display your CPU temperature.
+
 .TP
 .B normcolors
 Specifies the colors for background/border in the same format (html colorcodes)
@@ -122,6 +127,7 @@ System-wide configuration file.
 \&order run,wlan,eth,battery,load,time
 \&normcolors #000000 #333333
 \&color
+\&get_cpu_temperature
 .Ve
 
 .SH MOUNTING WMII'S PSEUDO FILESYSTEM
@@ -143,8 +149,10 @@ this, please fix it and send me a patch.
 .BR date (1),
 .BR glob (3)
 
-.SH AUTHOR
+.SH AUTHORS
 Michael Stapelberg <michael+i3status at stapelberg dot de>
 
+Thorsten Toepper <atsutane at freethoughts dot de>
+
 .SH WEBSITE
 See http://i3.zekjur.net/i3status for the newest release.
index c04a70dfde6b3a046079dc3dfac89f154190198e..ad4384f49f685f656e73d23a900a8a75481bc386 100644 (file)
@@ -5,6 +5,7 @@
  *
  *
  * Copyright © 2008-2009 Michael Stapelberg and contributors
+ * Copyright © 2009 Thorsten Toepper <atsutane at freethoughts dot de>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without modification,
@@ -88,6 +89,8 @@ static char *wmii_path;
 static const char *time_format;
 static bool use_colors;
 static bool get_ethspeed;
+static bool get_cpu_temperature;
+static char *thermal_zone;
 static const char *wmii_normcolors = "#222222 #333333";
 static char order[MAX_ORDER][2];
 static const char **run_watches;
@@ -200,6 +203,8 @@ static void setup(void) {
                 create_file(concat(order[ORDER_WLAN],"wlan"));
         if (eth_interface)
                 create_file(concat(order[ORDER_ETH],"eth"));
+        if (get_cpu_temperature)
+                create_file(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature"));
         create_file(concat(order[ORDER_LOAD],"load"));
         if (time_format)
                 create_file(concat(order[ORDER_TIME],"time"));
@@ -479,6 +484,33 @@ static char *get_eth_info() {
         return part;
 }
 
+/*
+ * Reads the CPU temperature from /sys/class/thermal/thermal_zone0/temp and
+ * returns the temperature in degree celcius.
+ *
+ */
+static char *get_cpu_temperature_info() {
+        static char part[16];
+        char buf[16];
+        int temp;
+        int fd;
+
+        memset(buf, 0, sizeof(buf));
+        memset(part, 0, sizeof(part));
+
+        if ((fd = open(thermal_zone, O_RDONLY)) == -1)
+                die("Could not open %s\n", thermal_zone);
+        (void)read(fd, buf, sizeof(buf));
+        (void)close(fd);
+
+        if (sscanf(buf, "%d", &temp) != 1)
+                (void)snprintf(part, sizeof(part), "T: ? C");
+        else
+                (void)snprintf(part, sizeof(part), "T: %d C", (temp/1000));
+
+        return part;
+}
+
 /*
  * Checks if the PID in path is still valid by checking:
  *  (Linux) if /proc/<pid> exists
@@ -572,7 +604,16 @@ static int load_configuration(const char *configfile) {
                         use_colors = true;
                 OPT("get_ethspeed")
                         get_ethspeed = true;
-                OPT("normcolors")
+                OPT("get_cpu_temperature") {
+                        get_cpu_temperature = true;
+                        if (strlen(dest_value) > 0) {
+                                if (asprintf(&thermal_zone, "/sys/class/thermal/thermal_zone%d/temp", atoi(dest_value)) == -1)
+                                        die("Could not build thermal_zone path\n");
+                        } else {
+                                 if (asprintf(&thermal_zone, "/sys/class/thermal/thermal_zone0/temp") == -1)
+                                        die("Could not build thermal_zone path\n");
+                        }
+                } OPT("normcolors")
                         wmii_normcolors = strdup(dest_value);
                 OPT("interval")
                         interval = atoi(dest_value);
@@ -621,6 +662,7 @@ static int load_configuration(const char *configfile) {
                                 SET_ORDER("wlan", ORDER_WLAN);
                                 SET_ORDER("eth", ORDER_ETH);
                                 SET_ORDER("battery", ORDER_BATTERY);
+                                SET_ORDER("cpu_temperature", ORDER_CPU_TEMPERATURE);
                                 SET_ORDER("load", ORDER_LOAD);
                                 SET_ORDER("time", ORDER_TIME);
                                 token = walk;
@@ -697,6 +739,8 @@ int main(int argc, char *argv[]) {
                 SIMPLEQ_FOREACH(current_battery, &batteries, batteries) {
                         write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info(current_battery), false);
                 }
+                if (get_cpu_temperature)
+                        write_to_statusbar(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature"), get_cpu_temperature_info(), false);
 
                 /* Get load */
 #ifdef LINUX
index 4b204b08b0383b441c4f6914a46d4b83cfc6a29e..7410d1acef9b613b35cb8e210c2fd43035cd5cee 100644 (file)
@@ -25,3 +25,6 @@ color
 
 # Checks ethernet interface speed (this needs root privileges)
 get_ethspeed
+
+# Checks core temperature
+get_cpu_temperature
index 2d6ce815d6a9dd1a3df802824b81740a1e427832..77deb1ce746eafb6cf33285d660cbd55efe5bd61 100644 (file)
@@ -1,4 +1,4 @@
 #define BEGINS_WITH(haystack, needle) (strncmp(haystack, needle, strlen(needle)) == 0)
 
 typedef enum { CS_DISCHARGING, CS_CHARGING, CS_FULL } charging_status_t;
-enum { ORDER_RUN, ORDER_WLAN, ORDER_ETH, ORDER_BATTERY, ORDER_LOAD, ORDER_TIME, MAX_ORDER };
+enum { ORDER_RUN, ORDER_WLAN, ORDER_ETH, ORDER_BATTERY, ORDER_CPU_TEMPERATURE, ORDER_LOAD, ORDER_TIME, MAX_ORDER };