blob: b854bfd69284ec41fefdd28f54bf3b1945a92637 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <XPT2046_Touchscreen.h>
#include "DHT.h"
#include "cpu.h"
#include "datetimeHandler.h"
#include "gfx_1.h"
#define TFT_DC D4
#define TFT_CS D2
#define TFT_RESET D3
#define DHTPIN D8
#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 displayTime = 0;
void setup() {
Serial.begin(9600);
initHardware();
gfx1_layout();
}
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);
// 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();
}
}
gfx1_refresh = true;
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;
// }
update(command);
// delay(1000);
// if ( currentTime > displayTime ) {
// displayTime = currentTime + 100000;
// }
}
void initHardware()
{
pinMode(TFT_RESET, OUTPUT);
digitalWrite(TFT_RESET, LOW);
delay(1000);
digitalWrite(TFT_RESET, HIGH);
delay(1000);
tft.begin();
tft.setRotation(3);
dht.begin();
// delay(3000);
}
|