aboutsummaryrefslogtreecommitdiff
path: root/cpu.cpp
blob: 86d8643e323ede982d210d11a7f8f79f2a6d1cfc (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "cpu.h"

int16_t cpuUsageGlobal = defaultValue;
int16_t cpuUsage[8] = {defaultValue, defaultValue, defaultValue,defaultValue, defaultValue, defaultValue, defaultValue, defaultValue};
int16_t cpuTempGlobal = defaultValue;
int16_t cpuTemp[8] = {defaultValue, defaultValue, defaultValue,defaultValue, defaultValue, defaultValue, defaultValue, defaultValue};
uint32_t ramFree = defaultValue;
uint32_t ramMax = defaultValue;
String OS = "";
String KernelVer = "";
String Uptime = "";

static int8_t extractArray(String &command, int16_t *array)
{
    int8_t startIndex = 1, lastIndex;
    int8_t index = 0;
    bool needStop = false;
    while(index < 8)
    {
      lastIndex = command.indexOf(",", startIndex);
      if(lastIndex == -1)
      {
        lastIndex = command.length() - 1;
        needStop = true;
      }

      array[index++] = command.substring(startIndex, lastIndex).toInt();
      if(needStop)
        break;
      startIndex = lastIndex +1;
    }
    return index;
}

int8_t setCpuTemp(String command)
{
  if(command.substring(0, 1) == "[")
  {
    extractArray(command, cpuTemp);
  }
  else
  {
    cpuTempGlobal = command.toInt();
  }
  return 0;
}

int8_t setCpuUsage(String command)
{
  if(command.substring(0, 1) == "[")
  {
    extractArray(command, cpuUsage);
  }
  else
  {
    cpuUsageGlobal = command.toInt();
  }
  return 0;
}

int8_t setRamMax(String command)
{
  ramMax = command.toInt();
  return 0;
}

int8_t setRamFree(String command)
{
  ramFree = command.toInt();
  return 0;
}