aboutsummaryrefslogtreecommitdiff
path: root/sysmon.ino
diff options
context:
space:
mode:
Diffstat (limited to 'sysmon.ino')
-rw-r--r--sysmon.ino128
1 files changed, 62 insertions, 66 deletions
diff --git a/sysmon.ino b/sysmon.ino
index b854bfd..34b9499 100644
--- a/sysmon.ino
+++ b/sysmon.ino
@@ -6,17 +6,17 @@
#include "datetimeHandler.h"
#include "gfx_1.h"
-#define TFT_DC D4
+#define TFT_DC D4
#define TFT_CS D2
#define TFT_RESET D3
#define DHTPIN D8
-#define DHTTYPE DHT22
+#define DHTTYPE DHT22
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
DHT dht(DHTPIN, DHTTYPE);
-static uint32_t tempTime = 0;
-static uint32_t rtcTime = 0;
+static uint32_t tempTime = 0;
+static uint32_t rtcTime = 0;
static uint32_t displayTime = 0;
void setup() {
@@ -26,76 +26,73 @@ void setup() {
}
void update(String command) {
- int delimiterIndex = command.indexOf('=');
- // Serial.println(command);
- if (delimiterIndex != -1) {
- String key = command.substring(0, delimiterIndex);
- String value = command.substring(delimiterIndex + 1);
- Serial.print(key);
+ if (!isnan(dht.readTemperature())) {
+ localHum = dht.readHumidity();
+ localTemp = dht.readTemperature() - 4;
+ }
- // Check the key and assign the corresponding value
- if (key.equals("CpuTemp")) {
- setCpuTemp(value);
- Serial.print("Received CPU temperature: ");
- Serial.println(value);
- // gfx1_udpate();
- } else if (key.equals("CpuUsage")) {
- setCpuUsage(value);
- Serial.print("Received CPU usage: ");
- Serial.println(value);
- // gfx1_udpate();
- } else if (key.equals("RamFree")) {
- setRamFree(value);
- Serial.print("Received Ram free: ");
- Serial.println(value);
- // gfx1_udpate();
- } else if (key.equals("RamMax")) {
- setRamMax(value);
- Serial.print("Received Ram max: ");
- Serial.println(value);
- // gfx1_udpate();
- } else if (key.equals("Time")) {
- setTime(value);
- Serial.print("Received Time: ");
- Serial.println(value);
- // gfx1_udpate();
- }
+ String keys[] = { "CpuTemp", "CpuUsage", "RamMax", "RamFree", "Time", "OS", "Kernel", "Uptime" };
+ String values[] = { "", "", "", "", "", "", "", "" };
+
+ for (int i = 0; i < std::size(keys); i++) {
+
+ int index = command.indexOf(keys[i]);
+
+ if (index != -1) {
+ String value = command.substring(index + keys[i].length() + 1, command.indexOf(",", index + keys[i].length() + 1));
+ values[i] = value;
+ }
+ }
+
+ for (int i = 0; i < std::size(values); i++) {
+ Serial.print(keys[i]);
+ Serial.print(" = ");
+ Serial.println(values[i]);
+ switch (i) {
+ case 0:
+ if (values[i] != "")
+ setCpuTemp(values[i]);
+ break;
+ case 1:
+ if (values[i] != "")
+ setCpuUsage(values[i]);
+ break;
+ case 2:
+ if (values[i] != "")
+ setRamMax(values[i]);
+ break;
+ case 3:
+ if (values[i] != "")
+ setRamFree(values[i]);
+ break;
+ case 4:
+ if (values[i] != "")
+ setTime(values[i]);
+ break;
+ case 5:
+ if (values[i] != "")
+ OS = values[i];
+ break;
+ case 6:
+ if (values[i] != "")
+ KernelVer = values[i];
+ break;
+ case 7:
+ if (values[i] != "")
+ Uptime = values[i];
+ break;
}
- gfx1_refresh = true;
- gfx1_udpate();
+ }
+ gfx1_udpate();
}
void loop() {
- Serial.println("Enter data:");
- // while (Serial.available() == 0) {}
String command = Serial.readString();
- command.trim();
- Serial.println(command);
-
- if(!isnan(dht.readTemperature()))
- {
- localHum = dht.readHumidity();
- localTemp = dht.readTemperature() - 4;
- Serial.println(localTemp);
- gfx1_refresh = true;
- gfx1_udpate();
- }
- // else
- // {
- // localHum = 255;
- // localTemp = 255;
- // }
-
+ command.trim();
update(command);
- // delay(1000);
-
- // if ( currentTime > displayTime ) {
- // displayTime = currentTime + 100000;
- // }
}
-void initHardware()
-{
+void initHardware() {
pinMode(TFT_RESET, OUTPUT);
digitalWrite(TFT_RESET, LOW);
delay(1000);
@@ -104,5 +101,4 @@ void initHardware()
tft.begin();
tft.setRotation(3);
dht.begin();
- // delay(3000);
} \ No newline at end of file