-
Notifications
You must be signed in to change notification settings - Fork 1
/
bb_tasks.ino
415 lines (350 loc) · 10.3 KB
/
bb_tasks.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
char* sc1_get_selected_case_name(int8_t id)
{
// 1 byte id, 1 byte sec, 1 byte msec, 20 byte name
static char casename[20] = {0};
// Search id of all 20 cases
for (int i = 0; i < 20; i++)
{
if (EEPROM[i * 23] == id)
{
for (int j = 0; j < 20; j++)
{
// Copy 20 characters of casename to variable
casename[j] = EEPROM[i * 23 + 3 + j];
}
break;
}
}
return casename;
}
uint8_t sc1_get_selected_case_time_sec(void)
{
// 1 byte id, 1 byte sec, 1 byte msec, 20 byte name
uint8_t id = SC1_STATE.selected_id;
uint8_t sec = 0;
// Search for id
for (int i = 0; i < 20; i++)
{
if (EEPROM[i * 23] == id)
{
sec = EEPROM[i * 23 + 1];
break;
}
}
return sec;
}
uint8_t sc1_get_selected_case_time_msec(void)
{
// 1 byte id, 1 byte sec, 1 byte msec, 20 byte name
uint8_t id = SC1_STATE.selected_id;
uint8_t msec = 0;
// Search for id
for (int i = 0; i < 20; i++)
{
if (EEPROM[i * 23] == id)
{
msec = EEPROM[i * 23 + 1];
break;
}
}
return msec;
}
void sc1_draw_list(void)
{
char *casename;
// Erase table
tft.fillRect(10, 40, 260, 145, ILI9341_BLACK);
// Draw table
tft.drawRect(10, 40, 260, 145, ILI9341_WHITE);
tft.drawFastHLine(10, 88, 260, ILI9341_WHITE);
tft.drawFastHLine(10, 136, 260, ILI9341_WHITE);
// Draw text
tft.setFont(&TFT_SC1_TXT1_TXT_FONT);
tft.setTextSize(1);
tft.setTextColor(TFT_SC1_TXT1_TXT_CLR);
// Selected case
casename = sc1_get_selected_case_name(SC1_STATE.selected_id);
tft.setCursor(TFT_SC1_TXT1_TXT_X, TFT_SC1_TXT1_TXT_Y);
tft.println(casename);
if (SC1_STATE.selected_id > 0)
{
// Top case
casename = sc1_get_selected_case_name(SC1_STATE.selected_id - 1);
tft.setCursor(TFT_SC1_TXT2_TXT_X, TFT_SC1_TXT2_TXT_Y);
tft.println(casename);
}
if (SC1_STATE.selected_id < SC1_STATE.max_cases - 1)
{
// Bottom case
casename = sc1_get_selected_case_name(SC1_STATE.selected_id + 1);
tft.setCursor(TFT_SC1_TXT3_TXT_X, TFT_SC1_TXT3_TXT_Y);
tft.println(casename);
}
}
void sc2_draw_time(void)
{
int16_t x1, y1;
uint16_t w, h;
// erase previous time
tft.getTextBounds(TFT_SC2_TXT1_TXT, TFT_SC2_TXT1_TXT_X, TFT_SC2_TXT1_TXT_Y, &x1, &y1, &w, &h);
tft.fillRect(x1, y1, w, h, ILI9341_BLACK);
// draw new time
tft.setFont(&TFT_SC2_TXT1_TXT_FONT);
tft.setTextSize(1);
tft.setTextColor(TFT_SC2_TXT1_TXT_CLR);
tft.setCursor(TFT_SC2_TXT1_TXT_X, TFT_SC2_TXT1_TXT_Y);
tft.print("Time: ");
tft.print(MACHINE_STATE.case_time_sec);
tft.print(".");
tft.print(MACHINE_STATE.case_time_msec);
tft.print(" sec");
}
void sc2_draw_count(void)
{
int16_t x1, y1;
uint16_t w, h;
// erase previous count
tft.getTextBounds(TFT_SC2_TXT2_TXT, TFT_SC2_TXT2_TXT_X, TFT_SC2_TXT2_TXT_Y, &x1, &y1, &w, &h);
tft.fillRect(x1, y1, w, h, ILI9341_BLACK);
// draw new count
tft.setFont(&TFT_SC2_TXT2_TXT_FONT);
tft.setTextSize(1);
tft.setTextColor(TFT_SC2_TXT2_TXT_CLR);
tft.setCursor(TFT_SC2_TXT2_TXT_X, TFT_SC2_TXT2_TXT_Y);
tft.print("Count: ");
tft.println(SC2_STATE.count);
}
void sc3_add_case(void)
{
// Search for empty locaition
for (int i = 0; i < 20; i++)
{
if (EEPROM[i * 23] == 0xff)
{
// Write case ID
EEPROM[i * 23] = SC1_STATE.max_cases;
SC1_STATE.max_cases += 1;
EEPROM[SC1_MAX_CASES_ADDR] = SC1_STATE.max_cases;
// Write sec, msec
EEPROM[i * 23 + 1] = SC3_STATE.sec;
EEPROM[i * 23 + 2] = SC3_STATE.msec;
// Write case name
for (int i = 0; i < 14; i++)
{
EEPROM[i * 23 + 3 + i] = SC3_STATE.casename[i];
}
EEPROM[i * 23 + 3 + 14] = 0;
break;
}
}
}
void sc3_run_test(void)
{
}
void sc3_update_time(void)
{
int16_t x1, y1;
uint16_t w, h;
// erase sec msec times
tft.getTextBounds("00", TFT_SC3_TXT1_TXT_X, TFT_SC3_TXT1_TXT_Y, &x1, &y1, &w, &h);
tft.fillRect(x1, y1, w, h, ILI9341_BLACK);
tft.getTextBounds("0", TFT_SC3_TXT2_TXT_X, TFT_SC3_TXT2_TXT_Y, &x1, &y1, &w, &h);
tft.fillRect(x1, y1, w, h, ILI9341_BLACK);
// draw sec, msec time
tft.setFont(&TFT_SC3_TXT1_TXT_FONT);
tft.setTextSize(1);
tft.setTextColor(TFT_SC3_TXT1_TXT_CLR);
tft.setCursor(TFT_SC3_TXT1_TXT_X, TFT_SC3_TXT1_TXT_Y);
tft.println(SC3_STATE.sec);
tft.setTextColor(TFT_SC3_TXT2_TXT_CLR);
tft.setCursor(TFT_SC3_TXT2_TXT_X, TFT_SC3_TXT2_TXT_Y);
tft.println(SC3_STATE.msec);
}
void sc4_pause_annealing(void)
{
tft.setFont(&TFT_SC4_BTN2_TXT_FONT);
tft.setTextSize(1);
if (MACHINE_STATE.ann_state = 2)
{
// write pause in bg color
tft.setTextColor(TFT_SC4_BTN2_FILL_CLR);
tft.setCursor(TFT_SC4_BTN2_TXT_X, TFT_SC4_BTN2_TXT_Y);
tft.println(TFT_SC4_BTN2_TXT);
// write start in main color
tft.setTextColor(TFT_SC4_BTN2_TXT_CLR);
tft.setCursor(TFT_SC4_BTN2_TXT_X, TFT_SC4_BTN2_TXT_Y);
tft.println("START");
// pause annealing
MACHINE_STATE.ann_state = 2;
}
else
{
// write start in bg color
tft.setTextColor(TFT_SC4_BTN2_FILL_CLR);
tft.setCursor(TFT_SC4_BTN2_TXT_X, TFT_SC4_BTN2_TXT_Y);
tft.println("start");
// write pause in main color
tft.setTextColor(TFT_SC4_BTN2_TXT_CLR);
tft.setCursor(TFT_SC4_BTN2_TXT_X, TFT_SC4_BTN2_TXT_Y);
tft.println(TFT_SC4_BTN2_TXT);
// Start annealing
MACHINE_STATE.ann_state = 1;
}
}
void sc4_update_case(void)
{
if (SC4_STATE.save_enabled)
{
SC4_STATE.save_enabled = false;
// update time of current case in EEPROM
for (int i = 0; i < 20; i++)
{
if (MACHINE_STATE.case_id == EEPROM[i * 23])
{
EEPROM[i * 23 + 1] = SC4_STATE.sec;
EEPROM[i * 23 + 2] = SC4_STATE.msec;
break;
}
}
}
}
void sc4_update_time(void)
{
int16_t x1, y1;
uint16_t w, h;
// erase sec msec times
tft.getTextBounds("00", TFT_SC4_TXT1_TXT_X, TFT_SC4_TXT1_TXT_Y, &x1, &y1, &w, &h);
tft.fillRect(x1, y1, w, h, ILI9341_BLACK);
tft.getTextBounds("0", TFT_SC4_TXT2_TXT_X, TFT_SC4_TXT2_TXT_Y, &x1, &y1, &w, &h);
tft.fillRect(x1, y1, w, h, ILI9341_BLACK);
// draw sec, msec time
tft.setFont(&TFT_SC4_BTN2_TXT_FONT);
tft.setTextSize(1);
tft.setTextColor(TFT_SC4_TXT1_TXT_CLR);
tft.setCursor(TFT_SC4_TXT1_TXT_X, TFT_SC4_TXT1_TXT_Y);
tft.println(SC4_STATE.sec);
tft.setTextColor(TFT_SC4_TXT2_TXT_CLR);
tft.setCursor(TFT_SC4_TXT2_TXT_X, TFT_SC4_TXT2_TXT_Y);
tft.println(SC4_STATE.msec);
// update global struct
MACHINE_STATE.case_time_sec = SC4_STATE.sec;
MACHINE_STATE.case_time_msec = SC4_STATE.msec;
// enable save button
SC4_STATE.save_enabled = true;
}
void sc4_draw_count(void)
{
}
void sc5_clear_textbox(void)
{
strcpy(SC5_STATE.textbox, "");
tft.fillRect(
TFT_SCKEY_TXT1_RECT_X + 1,
TFT_SCKEY_TXT1_RECT_Y + 1,
TFT_SCKEY_TXT1_RECT_XLEN - 2,
TFT_SCKEY_TXT1_RECT_YLEN - 2,
TFT_SCKEY_TXT1_FILL_CLR);
}
void sc5_update_textbox(int row, int col)
{
char key[2] = {0};
if (row == 2)
{
if (col == 0)
{
// < pressed
if (SC5_STATE.keyboard_page <= 0) SC5_STATE.keyboard_page = 2;
else SC5_STATE.keyboard_page -= 1;
sc5_draw_keys(SC5_STATE.keyboard_page);
}
else if (col == 5)
{
// > pressed
if (SC5_STATE.keyboard_page >= 2) SC5_STATE.keyboard_page = 0;
else SC5_STATE.keyboard_page += 1;
sc5_draw_keys(SC5_STATE.keyboard_page);
}
return;
}
else if (row < 2)
{
key[0] = 'A' + (col + row * 6 + SC5_STATE.keyboard_page * 12);
if (key[0] > 'Z')
{
key[0] = key[0] - 'Z' + '0' - 1;
}
strcat(SC5_STATE.textbox, key);
tft.setFont(&TFT_SCKEY_TXT1_TXT_FONT);
tft.setTextSize(1);
tft.setTextColor(TFT_SCKEY_TXT1_TXT_CLR);
tft.setCursor(TFT_SCKEY_TXT1_TXT_X, TFT_SCKEY_TXT1_TXT_Y);
tft.println(SC5_STATE.textbox);
}
}
void sc5_draw_keys(uint8_t keyboard_page)
{
char key[2] = {0};
SCREEN_TEXT_Params textParams;
for (int row = 0; row < TFT_SCKEY_BTN_ROWS - 1; row++)
{
for (int col = 0; col < TFT_SCKEY_BTN_COLUMNS; col++)
{
tft_screen_text_params_init(&textParams);
key[0] = 'A' + (col + row * 6 + keyboard_page * 12);
if (key[0] > 'Z')
{
key[0] = key[0] - 'Z' + '0' - 1;
}
textParams.text_x = TFT_SCKEY_BTN_RECT_X + (col * TFT_SCKEY_BTN_GAP_X) + TFT_SCKEY_BTN_TXT_X_OFFSET;
textParams.text_y = TFT_SCKEY_BTN_RECT_Y + (row * TFT_SCKEY_BTN_GAP_Y) + TFT_SCKEY_BTN_TXT_Y_OFFSET;
textParams.text = key;
textParams.text_font = &TFT_SCKEY_BTN_TXT_FONT;
textParams.rect_x = TFT_SCKEY_BTN_RECT_X + (col * TFT_SCKEY_BTN_GAP_X);
textParams.rect_y = TFT_SCKEY_BTN_RECT_Y + (row * TFT_SCKEY_BTN_GAP_Y);
textParams.rect_x_len = TFT_SCKEY_BTN1_RECT_XLEN;
textParams.rect_y_len = TFT_SCKEY_BTN1_RECT_YLEN;
textParams.rect_thickness = TFT_SCKEY_BTN_RECT_THICK;
textParams.fill_en = TFT_SCKEY_BTN_FILL_EN;
textParams.round_en = TFT_SCKEY_BTN_ROUND_EN;
textParams.fill_color = TFT_SCKEY_BTN_FILL_CLR;
textParams.rect_color = TFT_SCKEY_BTN_RECT_CLR;
textParams.text_color = TFT_SCKEY_BTN_TXT_CLR;
tft_draw_text(textParams);
}
}
}
void sc8_delete_case(int8_t case_id)
{
// 1 byte id, 1 byte sec, 1 byte msec, 20 byte name
// Write 0xff as id for case_id
for (int i = 0; i < 20; i++)
{
int8_t eeprom_id = EEPROM[i * 23];
if (eeprom_id == case_id)
{
// Erase case ID
EEPROM.update(i * 23, 0xff);
SC1_STATE.max_cases -= 1;
EEPROM[SC1_MAX_CASES_ADDR] = SC1_STATE.max_cases;
}
else if (eeprom_id > case_id && eeprom_id < 20)
{
EEPROM[i * 23] = eeprom_id - 1;
}
}
}
void sc8_stop_annealing(void)
{
MACHINE_STATE.ann_state = 0;
}
void sc6_repeat_annealing(void)
{
// !Set count back to full
// Start annealing
MACHINE_STATE.ann_state = 1;
}
void sc7_retry_annealing(void)
{
// Start annealing
MACHINE_STATE.ann_state = 1;
}