Change named colors to hex values
[sysstatus.git] / src / status / temp.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4
5 #include "common.h"
6 #include "tools.h"
7
8
9 void status_temp(GlobalData *g, char *title, char *sysfile)
10 {
11   StatusItem s;
12   char text[16] = { 0 };
13
14   char stline[16];
15   ssize_t stlen;
16
17
18   statusitem_init(&s);
19   s.text = text;
20
21   stlen = fileRead(stline, sizeof(stline), sysfile);
22   if (stlen <= 0) {
23     return;
24   }
25
26   /*
27    * Read a valid value?
28    * Sometimes we get garbage from sysfs...
29    */
30   if (stlen < 6 || stlen > 7) {
31     s.color = "#FF0000";  // red
32     snprintf(text, sizeof(text), "%sERROR", title);
33   } else {
34     stline[stlen - 4] = '\0';
35
36     s.color = "#FF33FF";
37     snprintf(text, sizeof(text), "%s%s°C", title, stline);
38   }
39
40   line_append_item(g, &s);
41 }