This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.ino
200 lines (185 loc) · 6.24 KB
/
Display.ino
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
void initializeGraphics() {
//Serial.println("initialization done.");
//Serial.println("RA8875 start");
tft.begin(RA8875_800x480);
if (!tft.begin(RA8875_800x480)) {
//Serial.println("RA8875 Not Found!");
while (1);
}
//Serial.println("Found RA8875");
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.graphicsMode();
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
tft.graphicsMode();
tft.drawBitmap(160, 0, foodspan, 480, 480, RA8875_GREEN);
delay(1000);
tft.fillScreen(RA8875_WHITE);
updateGraphics();
}
void createText(int txt, int xcor, int ycor) {
//Serial.println("createText function is working : ");
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(0);
if (tagTable[txt].storageCategory == 0) {
//Serial.print("Fridge, ");
char string2[8] = "Fridge";
tft.textSetCursor(xcor + 15, ycor + 132);
tft.textWrite(string2);
} else if (tagTable[txt].storageCategory == 1) {
//Serial.print("Freezer ");
char string2[8] = "Freezer";
tft.textSetCursor(xcor + 15, ycor + 132);
tft.textWrite(string2);
}
if (tagTable[txt].cookedCategory == 0) {
//Serial.print("Raw, ");
char string2[8] = "Raw";
tft.textSetCursor(xcor + 15, ycor + 152);
tft.textWrite(string2);
} else if (tagTable[txt].cookedCategory == 1) {
//Serial.print("Cooked, ");
char string2[8] = "Cooked";
tft.textSetCursor(xcor + 15, ycor + 152);
tft.textWrite(string2);
} else if (tagTable[txt].cookedCategory == 2) {
//Serial.print("Misc, ");
char string2[8] = "Misc";
tft.textSetCursor(xcor + 15, ycor + 152);
tft.textWrite(string2);
}
if (tagTable[txt].foodCategory == 0) {
Serial.print("Produce, ");
char string2[8] = "Produce";
tft.textSetCursor(xcor + 15, ycor + 172);
tft.textWrite(string2);
} else if (tagTable[txt].foodCategory == 1) {
Serial.print("Meat, ");
char string2[8] = "Meat";
tft.textSetCursor(xcor + 15, ycor + 172);
tft.textWrite(string2);
} else if (tagTable[txt].foodCategory == 2) {
Serial.print("Dairy L, ");
char string2[8] = "Dairy L";
tft.textSetCursor(xcor + 15, ycor + 172);
tft.textWrite(string2);
} else if (tagTable[txt].foodCategory == 3) {
Serial.print("Dairy S, ");
char string2[8] = "Dairy S";
tft.textSetCursor(xcor + 15, ycor + 172);
tft.textWrite(string2);
} else if (tagTable[txt].foodCategory == 4) {
Serial.print("Other, ");
char string2[8] = "Other";
tft.textSetCursor(xcor + 15, ycor + 172);
tft.textWrite(string2);
}
char string100[20];
snprintf(string100, sizeof(string100), "%d days", (tagTable[txt].scanTime) );
tft.textSetCursor(xcor + 15, ycor + 192);
tft.textWrite(string100);
Serial.println("");
return;
}
void make(int x, int y)
{
tft.fillScreen(RA8875_WHITE);
int arrayA = 0;
int colourA = 0;
int alpha = -1;
for (int i = 0; i <= 214; i += 213) {
for (int j = 0; j < 613; j += 153) {
alpha += 1;
if (element_arr[alpha] != -1) {
Serial.print("element_arr[alpha]: ");
Serial.println(element_arr[alpha]);
Serial.print("Patterns : ");
arrayA = ((element_arr[alpha] - 1) / 10);
Serial.println(arrayA);
colourA = (element_arr[alpha]) % 10 == 0 ? 9 : (element_arr[alpha]) % 10 - 1;
Serial.print("ColourA is : ");
Serial.println(colourA);
if (arrayA == 0) {
tft.drawBitmap(x + j, y + i, array[0], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 1) {
tft.drawBitmap(x + j, y + i, array[1], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 2) {
tft.drawBitmap(x + j, y + i, array[2], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 3) {
tft.drawBitmap(x + j, y + i, array[3], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 4) {
tft.drawBitmap(x + j, y + i, array[4], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 5) {
tft.drawBitmap(x + j, y + i, array[5], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 6) {
tft.drawBitmap(x + j, y + i, array[6], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 7) {
tft.drawBitmap(x + j, y + i, array[7], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 8) {
tft.drawBitmap(x + j, y + i, array[8], 120, 120, pgm_read_word( &colour[colourA] ));
} else if (arrayA == 9) {
tft.drawBitmap(x + j, y + i, array[9], 120, 120, pgm_read_word( &colour[colourA] ));
}
tft.textMode();
if (element_arr[alpha] < 10) {
tft.textSetCursor(x + j + 49, y + i + 45);
} else {
tft.textSetCursor(x + j + 25, y + i + 45);
}
char string[5];
snprintf(string, sizeof(string), "%d", tagTable[element_arr[alpha]].patternID);
tft.textTransparent(RA8875_WHITE);
tft.textEnlarge(2);
tft.textWrite(string);
createText(element_arr[alpha], x + j, y + i);
tft.graphicsMode();
}
}
}
tft.textMode();
tft.textSetCursor(665, 440);
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(1);
char string5[9] = "Page 1/1";
tft.textWrite(string5);
// tft.textSetCursor(770, 440);
// char string1[7];
// snprintf(string1, sizeof(string1), "%d", (page + 1));
// tft.textWrite(string1);
tft.graphicsMode();
Serial.println("DONE");
}
void constr() {
Serial.println("Constructor initialized\n\n\n ///////////////// ");
activeTags = countActive();
for (int i = 0, j = 0; i < 10; a++) {
if (a >= 100) {
element_arr[i] = -1;
i++;
}
else if (tagTable[a].activeState == 1) {
element_arr[i] = tagTable[a].patternID;
i++;
}
}
Serial.println("/////////////////////////");
Serial.println("");
make(33, 30);
}
void updateGraphics() {
page = 0;
a = 1;
tft.graphicsMode();
constr();
}
int countActive() {
int counteractive = 0;
for (int i = 1; i <= 100; i++) {
if (tagTable[i].activeState == 1) {
counteractive++;
}
}
Serial.print("ACTIVE TAGS: "); Serial.println(counteractive);
return counteractive;
}