summaryrefslogtreecommitdiff
path: root/src/status/temp.c
blob: c102fcd776585c25de77759af53aa8e62fbf3ccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#include "common.h"
#include "tools.h"


void status_temp(GlobalData *g, char *title, char *sysfile)
{
  StatusItem s;
  char text[16] = { 0 };

  char stline[16];
  ssize_t stlen;


  statusitem_init(&s);
  s.text = text;

  stlen = fileRead(stline, sizeof(stline), sysfile);
  if (stlen <= 0) {
    return;
  }

  /*
   * Read a valid value?
   * Sometimes we get garbage from sysfs...
   */
  if (stlen < 6 || stlen > 7) {
    s.color = "red";
    snprintf(text, sizeof(text), "%sERROR", title);
  } else {
    stline[stlen - 4] = '\0';

    s.color = "#FF33FF";
    snprintf(text, sizeof(text), "%s%s°C", title, stline);
  }

  line_append_item(g, &s);
}