# HG changeset patch # User Stiletto # Date 1418229053 -14400 # Node ID ae09261c22e36096ad5ff26443c4cbcdbcaefc1d # Parent ad3d40f11f6dc4220379cecc68343b95e07d6c6c Temperature applet diff -r ad3d40f11f6d -r ae09261c22e3 status-temp/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-temp/Makefile Wed Dec 10 20:30:53 2014 +0400 @@ -0,0 +1,9 @@ +include ../config.mk +include config.mk + +OUT = status-temp +SRC = temp.c +OBJ = ${SRC:.c=.o} +CONFIG = config.h + +include ../Makefile.status.inc diff -r ad3d40f11f6d -r ae09261c22e3 status-temp/config.def.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-temp/config.def.h Wed Dec 10 20:30:53 2014 +0400 @@ -0,0 +1,10 @@ +#define UPDATE_PERIOD 10 + +#define GREEN_VALUE 30 +#define ORANGE_VALUE 55 +#define RED_VALUE 60 + +// Uncomment if you want temperature indicator to flash when higher than certain value +//#define FLASH_AFTER 60 + +#define LOCALE "" diff -r ad3d40f11f6d -r ae09261c22e3 status-temp/config.mk diff -r ad3d40f11f6d -r ae09261c22e3 status-temp/temp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/status-temp/temp.c Wed Dec 10 20:30:53 2014 +0400 @@ -0,0 +1,107 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" + + +int catint(char *name) { + FILE* f = fopen(name, "r"); + int i = 0; + if (fscanf(f, "%d", &i) != 1) + i = -1; + fclose(f); + return i; +} + +char *color_stop; +char *color_red; +char *color_orange; +char *color_green; +char *color_none; + +char *color(int low,int mid,int rev,int value) { + if (value>mid) { + return rev ? color_red : color_green; + } else if (value>low) { + return color_orange; + } + return rev ? color_green : color_red; +} + +int main(int argc, char *argv[]) { + if (argc<=2) { + fprintf(stderr, "Usage: %s [sensor2] ...\n", argv[0]); + fflush(stderr); + return 1; + } + + char *color; + if (!strcmp(argv[1],"term")) { + color_stop = "\x1b[0m"; + color_red = "\x1b[1;31m"; + color_green = "\x1b[1;32m"; + color_orange = "\x1b[1;33m"; + color_none = color_stop; + } else if (!strcmp(argv[1],"pango")) { + color_stop = ""; + color_red = ""; + color_green = ""; + color_orange = ""; + color_none = ""; + } else { + color_stop = color_red = color_green = color_orange = color_none = ""; + } + + int sleeptime = UPDATE_PERIOD; + int alertflash = 1; + while (1) { + int i; + int maxtemp = 0; + for (i=2;i maxtemp) + maxtemp = temp; + } + + float ctemp = maxtemp/1000; + + if (ctemp <= GREEN_VALUE) + color = color_green; + else if (ctemp >= RED_VALUE) + color = color_red; + else if (ctemp >= ORANGE_VALUE) + color = color_orange; + else + color = color_none; + +#ifdef FLASH_AFTER + if (ctemp >= FLASH_AFTER) { + sleeptime = 1; + alertflash = !alertflash; + } else { + sleeptime = UPDATE_PERIOD; + alertflash = 1; + } +#endif + if (alertflash) { + printf("%s%2.1f%s\n",color, ctemp, color_stop); + } else { + int len = snprintf(NULL, 0, "%2.1f", ctemp); + for (i=0; i