aboutsummaryrefslogtreecommitdiffstats
path: root/status/temp.c
diff options
context:
space:
mode:
Diffstat (limited to 'status/temp.c')
-rw-r--r--status/temp.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/status/temp.c b/status/temp.c
new file mode 100644
index 0000000..d35f6b3
--- /dev/null
+++ b/status/temp.c
@@ -0,0 +1,74 @@
+#include "kconfig.h"
+#include "dwmstatus.h"
+
+#define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp"
+
+int print_temp( bbuf *buf)
+{
+ ASSERT( buf != NULL );
+
+ int str_size=0;
+ if ( buf->size < 1 )
+ {
+ buf->size = 1024;
+ buf->str = malloc( buf->size );
+ }
+
+ uint32_t temp=0;
+ FILE *f = fopen(TEMP_PATH,"r");
+
+ ASSERT( f != NULL );
+
+ fscanf( f, "%u\n", &temp );
+ temp /= 1000;
+ //printf("%u\n",temp);
+
+ fclose( f );
+
+ ASSERT( temp < 110 );
+
+#ifdef CONFIG_STATUS_UTF8
+ buf->str[0] = 0xef;
+ buf->str[1] = 0xa3;
+ buf->str[2] = 0x87;
+ str_size = 3;
+#endif
+
+#ifdef CONFIG_STATUS_FMT_PANGO
+ //seperate by color temp
+ // RED - very hot - >80
+ // GREEN - normal temp - 50-80
+ // BLUE - cold - <50
+ if ( temp < 50 )
+ {
+ #ifdef CONFIG_STATUS_UTF8
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "<span color=\"#3366ff\">%u</span>C ", temp );
+ #else
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:<span color=\"#3366ff\">%u</span>C ", temp );
+ #endif
+ } else if ( temp < 80 )
+ {
+ #ifdef CONFIG_STATUS_UTF8
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "<span color=\"#33ff66\">%u</span>C ", temp );
+ #else
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:<span color=\"#33ff66\">%u</span>C ", temp );
+ #endif
+ } else
+ {
+ #ifdef CONFIG_STATUS_UTF8
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "<span color=\"#ff6633\">%u</span>C ", temp );
+ #else
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:<span color=\"#ff6633\">%u</span>C ", temp );
+ #endif
+ }
+#else
+ #ifdef CONFIG_STATUS_UTF8
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "%uC ", temp );
+ #else
+ snprintf( &buf->str[str_size], buf->size-1-str_size, "TEMP:%uC ", temp );
+ #endif
+ //snprintf( buf->str, buf->size-1, "\xc2\xae%uC ", temp/1000 );
+#endif
+
+ return 0;
+}