summaryrefslogtreecommitdiff
path: root/src/status/fan.c
blob: 6b266784934ced88169db3ae2769d2480dc95c17 (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
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

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


void status_fan(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 > 5) {
    s.color = "red";
    snprintf(text, sizeof(text), "%sERROR", title);
  } else {
    stline[stlen - 1] = '\0';

    s.color = "#CCCCCC";
    snprintf(text, sizeof(text), "%s%s rpm", title, stline);
  }

  line_append_item(g, &s);
}