-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayModule.cpp
executable file
·119 lines (112 loc) · 3.97 KB
/
DisplayModule.cpp
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
109
110
111
112
113
114
115
116
117
118
119
/*
Class for DisplayModule
*/
#include "DisplayModule.h"
#define SERIAL_DEBUG 0
DisplayModule::DisplayModule(int8_t csPin, int8_t dcPin, int8_t rstPin)
: tft(csPin, dcPin, rstPin)
{
peepBufferIndex = 0;
};
DisplayModule::~DisplayModule() {};
void DisplayModule::startDisp() {
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(3);
}
void DisplayModule::PrintMainScreen() {}
void DisplayModule::clearDisp() {
tft.fillScreen(ILI9341_BLACK);
}
void DisplayModule::printStartMsg() {
printTft(startMsg, 0, 0, ILI9341_GREEN, ILI9341_BLACK, 3, true);
}
void DisplayModule::printWifiStart() {
clearDisp();
printTft(connWifi, 0, 0, ILI9341_YELLOW, ILI9341_BLACK, 2, true);
}
void DisplayModule::printWifiFail() {
printTft( wifiConnError, 0, 0, ILI9341_RED, ILI9341_BLACK, 2, true);
}
void DisplayModule::printLdrMode() {
clearDisp();
printTft(ldrMode, 0, 0, ILI9341_RED, ILI9341_BLACK, 3, true);
}
void DisplayModule::printTft(String msg, int x, int y, int fgColor, int bgColor, int size, bool newline) {
tft.setTextColor(fgColor, bgColor);
tft.setTextSize(size);
if (x > -1) {
tft.setCursor(x, y);
}
if (newline) {
tft.println(msg);
#if SERIAL_DEBUG
Serial.println(msg);
#endif
} else {
tft.print(msg);
#if SERIAL_DEBUG
Serial.print(msg);
#endif
}
}
void DisplayModule::printTime(String fTime) {
printTft(fTime, -1, 0, ILI9341_BLUE, ILI9341_BLACK, 2, true);
}
void DisplayModule::printTftSimple(String msg, bool newline) {
printTft(msg, -1, -1, ILI9341_YELLOW, ILI9341_BLACK, 2, newline);
}
int DisplayModule::defaultScreen() {
//clearDisp();
tft.fillRoundRect(0, 0, 320, 52, 5, ILI9341_YELLOW);
tft.drawRoundRect(0, 0, 320, 52, 5, ILI9341_DARKCYAN);
String header = " Hentry Status";
String timeRow = "Current Time:";
String positionRow = "Door position:";
String stateRow = "Door state:";
String nextRow = "Next:";
printTft(header, 0, 2, ILI9341_DARKCYAN, ILI9341_YELLOW ,3, true);
printTft(timeRow, 0, 60, ILI9341_GREEN, ILI9341_BLACK, 2, true);
printTft(positionRow, 0, 83, ILI9341_GREEN, ILI9341_BLACK, 2, true);
printTft(stateRow, 0, 106, ILI9341_GREEN, ILI9341_BLACK, 2, true);
printTft(nextRow, 0, 129, ILI9341_GREEN, ILI9341_BLACK, 2, true);
printTft(tempRow, 0, 152, ILI9341_GREEN, ILI9341_BLACK, 2, true);
return DEFAULT_SCREEN;
}
void DisplayModule::defaultOverlay(String charge, String fTime, String pos, String state, String sch, String tmp) {
printTft(charge,110, 26, ILI9341_DARKCYAN, ILI9341_YELLOW ,3, true);
printTft(fTime, 155, 55, ILI9341_GREEN, ILI9341_BLACK, 3, false);
printTft(tmp, 154, 152, ILI9341_GREEN, ILI9341_BLACK, 2, true);
}
void DisplayModule::updatDefTime(String fTime) {}
void DisplayModule::printPeep(int p) {
tft.fillRoundRect(0, 175, 320, 65, 5, ILI9341_BLACK);
tft.drawRoundRect(0, 175, 320, 65, 5, ILI9341_YELLOW);
tft.setTextColor(ILI9341_ORANGE);
tft.setTextSize(1);
peepBufferIndex = p;
tft.setCursor(0, 180);
tft.print(peepBuffer[peepBufferIndex]); tft.println(" __/\/ ");
tft.print(peepBuffer[peepBufferIndex]); tft.println(" /.__.\\ ");
tft.print(peepBuffer[peepBufferIndex]); tft.println(" \\ \\/ / ");
tft.print(peepBuffer[peepBufferIndex]); tft.println(" `__/ \\ ");
tft.print(peepBuffer[peepBufferIndex]); tft.println(" \\- ) ");
tft.print(peepBuffer[peepBufferIndex]); tft.println(" \\_____/ ");
tft.print(peepBuffer[peepBufferIndex]); tft.println("_____|_|____ ");
tft.print(peepBuffer[peepBufferIndex]); tft.println(" \" \" ");
/*
* Based on the screen, disp the function
*/
tft.setTextSize(4);
switch(p){
case DOOR_OPEN_SCREEN:
printTft(sOpen, 100, 194, ILI9341_RED, ILI9341_BLACK, 4, false);
break;
case DOOR_CLOSE_SCREEN:
printTft(sClose, 124, 194, ILI9341_RED, ILI9341_BLACK, 4, false);
break;
}
}
void DisplayModule::setPeepBuffer(int i) {
peepBufferIndex = abs(i % 4);
}