-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathmain.c
More file actions
745 lines (631 loc) · 21.8 KB
/
main.c
File metadata and controls
745 lines (631 loc) · 21.8 KB
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/*
* main.c - T-962 reflow controller
*
* Copyright (C) 2014 Werner Johansson, wj@unifiedengineering.se
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LPC214x.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "serial.h"
#include "advancedcmd.h"
#include "lcd.h"
#include "io.h"
#include "sched.h"
#include "onewire.h"
#include "adc.h"
#include "i2c.h"
#include "rtc.h"
#include "eeprom.h"
#include "keypad.h"
#include "reflow.h"
#include "reflow_profiles.h"
#include "sensor.h"
#include "buzzer.h"
#include "nvstorage.h"
#include "version.h"
#include "vic.h"
#include "max31855.h"
#include "systemfan.h"
#include "setup.h"
extern uint8_t logobmp[];
extern uint8_t stopbmp[];
extern uint8_t selectbmp[];
extern uint8_t editbmp[];
extern uint8_t f3editbmp[];
// No version.c file generated for LPCXpresso builds, fall back to this
__attribute__((weak)) const char* Version_GetGitVersion(void) {
return "no version info";
}
static char* format_about = \
"\nT-962-controller open source firmware (%s)" \
"\n" \
"\nSee https://github.com/UnifiedEngineering/T-962-improvement for more details." \
"\n" \
"\nInitializing improved reflow oven...";
static char* help_text = \
"\nT-962-controller serial interface.\n\n" \
" about Show about + debug information\n" \
" bake <setpoint> Enter Bake mode with setpoint\n" \
" bake <setpoint> <time> Enter Bake mode with setpoint for <time> seconds\n" \
" set OpMode <mode> Set Operational Mode (0-AMBIENT, 1-MAXTEMPOVERRIDE, 2-SPLIT)\n" \
" set OpThresh <thresh> Set MAXTEMPOVERRIDE or SPLIT mode threshold in C (0-255)\n" \
" get OpMode Get Operational Mode\n" \
" get OpThresh Get MAXTEMPOVERRIDE or SPLIT mode threshold in C\n" \
" help Display help text\n" \
" list profiles List available reflow profiles\n" \
" list settings List machine settings\n" \
" quiet No logging in standby mode\n" \
" reflow Start reflow with selected profile\n" \
" setting <id> <value> Set setting id to value\n" \
" select profile <id> Select reflow profile by id\n" \
" stop Exit reflow or bake mode\n" \
" values Dump currently measured values\n" \
"\n";
static int32_t Main_Work(void);
int main(void) {
char buf[22];
int len;
IO_JumpBootloader();
PLLCFG = (1 << 5) | (4 << 0); //PLL MSEL=0x4 (+1), PSEL=0x1 (/2) so 11.0592*5 = 55.296MHz, Fcco = (2x55.296)*2 = 221MHz which is within 156 to 320MHz
PLLCON = 0x01;
PLLFEED = 0xaa;
PLLFEED = 0x55; // Feed complete
while (!(PLLSTAT & (1 << 10))); // Wait for PLL to lock
PLLCON = 0x03;
PLLFEED = 0xaa;
PLLFEED = 0x55; // Feed complete
VPBDIV = 0x01; // APB runs at the same frequency as the CPU (55.296MHz)
MAMTIM = 0x03; // 3 cycles flash access recommended >40MHz
MAMCR = 0x02; // Fully enable memory accelerator
VIC_Init();
Sched_Init();
IO_Init();
Set_Heater(0);
Set_Fan(0);
Serial_Init();
printf(format_about, Version_GetGitVersion());
I2C_Init();
EEPROM_Init();
NV_Init();
LCD_Init();
LCD_BMPDisplay(logobmp, 0, 0);
IO_InitWatchdog();
IO_PrintResetReason();
len = IO_Partinfo(buf, sizeof(buf), "%s rev %c");
LCD_disp_str((uint8_t*)buf, len, 0, 64 - 6, FONT6X6);
printf("\nRunning on an %s", buf);
len = snprintf(buf, sizeof(buf), "%s", Version_GetGitVersion());
LCD_disp_str((uint8_t*)buf, len, 128 - (len * 6), 0, FONT6X6);
LCD_FB_Update();
Keypad_Init();
Buzzer_Init();
ADC_Init();
RTC_Init();
OneWire_Init();
SPI_TC_Init();
Reflow_Init();
SystemFan_Init();
printf("\nCurrent Operational Mode: "); Sensor_printOpMode(); printf("\n");
printf("Current Operational Mode Threshold: %u C\n", Sensor_getOpModeThreshold());
Sched_SetWorkfunc(MAIN_WORK, Main_Work);
Sched_SetState(MAIN_WORK, 1, TICKS_SECS(2)); // Enable in 2 seconds
Buzzer_Beep(BUZZ_1KHZ, 255, TICKS_MS(100));
while (1) {
#ifdef ENABLE_SLEEP
int32_t sleeptime;
sleeptime = Sched_Do(0); // No fast-forward support
//printf("\n%d ticks 'til next activity"),sleeptime);
#else
Sched_Do(0); // No fast-forward support
#endif
}
return 0;
}
typedef enum eMainMode {
MAIN_HOME = 0,
MAIN_ABOUT,
MAIN_SETUP,
MAIN_BAKE,
MAIN_SELECT_PROFILE,
MAIN_EDIT_PROFILE,
MAIN_REFLOW
} MainMode_t;
static int32_t Main_Work(void) {
static MainMode_t mode = MAIN_HOME;
static uint16_t setpoint = 0;
if (setpoint == 0) {
Reflow_LoadSetpoint();
setpoint = Reflow_GetSetpoint();
}
static int timer = 0;
// profile editing
static uint8_t profile_time_idx = 0;
static uint8_t current_edit_profile;
int32_t retval = TICKS_MS(500);
char buf[22];
int len;
uint32_t keyspressed = Keypad_Get();
char serial_cmd[255] = "";
char* cmd_select_profile = "select profile %d";
char* cmd_bake = "bake %d %d";
char* cmd_dump_profile = "dump profile %d";
char* cmd_setting = "setting %d %f";
char* cmd_setOpMode = "set OpMode %d";
char* cmd_setOpModeThresh = "set OpThresh %d";
advancedSerialCMD advCmd = { 0 };
if (uart_chkAdvCmd(&advCmd)) {
switch (advCmd.cmd) {
case SetEEProfileCmd:
{
EEProfileCMD EEcmd;
memcpy(&EEcmd, &advCmd.data, sizeof(advCmd.data));
if (EEcmd.profileNum == 1 || EEcmd.profileNum == 2) {
printf("\nSetting EE profile %d:\n ", advCmd.data[0]);
Reflow_SelectEEProfileIdx(EEcmd.profileNum);
for (unsigned char i = 0; i < NUMPROFILETEMPS; ++i) {
Reflow_SetSetpointAtIdx(i, EEcmd.tempData[i]);
}
Reflow_SaveEEProfile();
if (EEcmd.profileNum == 1) Reflow_DumpProfile(5); //CUSTOM#1
else Reflow_DumpProfile(6); //CUSTOM#2
}
else {
printf("\nOnly EEPROM profile 1 and 2 are supported for this command.\n");
}
//reset advCmd
//memset(&advCmd, 0, sizeof(advCmd));
break;
}
//Add more advanced commands here
//case ...
default: {
printf("\nUnknown Advanced Command entered.\n");
//memset(&advCmd, 0, sizeof(advCmd));
uart_rxflush();
}
}
} else if (uart_available() > 3) {
int len = uart_readline(serial_cmd, 255);
if (len > 0) {
int param, param1;
float paramF;
if (strcmp(serial_cmd, "about") == 0) {
printf(format_about, Version_GetGitVersion());
len = IO_Partinfo(buf, sizeof(buf), "\nPart number: %s rev %c\n");
printf(buf);
EEPROM_Dump();
printf("\nSensor values:\n");
Sensor_ListAll();
} else if (strcmp(serial_cmd, "help") == 0 || strcmp(serial_cmd, "?") == 0) {
printf(help_text);
} else if (strcmp(serial_cmd, "list profiles") == 0) {
printf("\nReflow profiles available:\n");
Reflow_ListProfiles();
printf("\n");
} else if (strcmp(serial_cmd, "reflow") == 0) {
printf("\nStarting reflow with profile: %s\n", Reflow_GetProfileName());
mode = MAIN_HOME;
// this is a bit dirty, but with the least code duplication.
keyspressed = KEY_S;
} else if (strcmp(serial_cmd, "list settings") == 0) {
printf("\nCurrent settings:\n\n");
for (int i = 0; i < Setup_getNumItems() ; i++) {
printf("%d: ", i);
Setup_printFormattedValue(i);
printf("\n");
}
} else if (strcmp(serial_cmd, "stop") == 0) {
printf("\nStopping bake/reflow");
mode = MAIN_HOME;
Reflow_SetMode(REFLOW_STANDBY);
retval = 0;
} else if (strcmp(serial_cmd, "quiet") == 0) {
Reflow_ToggleStandbyLogging();
printf("\nToggled standby logging\n");
} else if (strcmp(serial_cmd, "values") == 0) {
printf("\nActual measured values:\n");
Sensor_ListAll();
printf("\n");
} else if (strcmp(serial_cmd, "get OpMode") == 0) {
printf("\nCurrent Operational Mode: "); Sensor_printOpMode(); printf("\n");
} else if (strcmp(serial_cmd, "get OpThresh") == 0) {
printf("\nCurrent Operational Mode Threshold: %u C\n", Sensor_getOpModeThreshold());
} else if (sscanf(serial_cmd, cmd_setOpMode, ¶m) > 0) {
// set operational mode
if (param > 2 || param < 0) {
printf("\nOnly options are 0-2. See Help.\n");
} else {
Sensor_setOpMode((OperationMode_t)param);
printf("\nOperational Mode Set: "); Sensor_printOpMode(); printf("\n");
}
} else if (sscanf(serial_cmd, cmd_setOpModeThresh, ¶m) > 0) {
// set operational mode threshold
if (param > 255 || param < 0) {
printf("\nOnly options are 0-255\n");
} else {
Sensor_setOpModeThreshold((uint8_t)param);
printf("\nOperational Mode Threshold Set: %d C\n", param);
}
} else if (sscanf(serial_cmd, cmd_select_profile, ¶m) > 0) {
// select profile
Reflow_SelectProfileIdx(param);
printf("\nSelected profile %d: %s\n", param, Reflow_GetProfileName());
} else if (sscanf(serial_cmd, cmd_bake, ¶m, ¶m1) > 0) {
if (param < SETPOINT_MIN) {
printf("\nSetpoint must be >= %ddegC\n", SETPOINT_MIN);
param = SETPOINT_MIN;
}
if (param > SETPOINT_MAX) {
printf("\nSetpont must be <= %ddegC\n", SETPOINT_MAX);
param = SETPOINT_MAX;
}
if (param1 < 1) {
printf("\nTimer must be greater than 0\n");
param1 = 1;
}
if (param1 < BAKE_TIMER_MAX) {
printf("\nStarting bake with setpoint %ddegC for %ds after reaching setpoint\n", param, param1);
timer = param1;
Reflow_SetBakeTimer(timer);
} else {
printf("\nStarting bake with setpoint %ddegC\n", param);
}
setpoint = param;
Reflow_SetSetpoint(setpoint);
mode = MAIN_BAKE;
Reflow_SetMode(REFLOW_BAKE);
} else if (sscanf(serial_cmd, cmd_dump_profile, ¶m) > 0) {
printf("\nDumping profile %d: %s\n ", param, Reflow_GetProfileName());
Reflow_DumpProfile(param);
} else if (sscanf(serial_cmd, cmd_setting, ¶m, ¶mF) > 0) {
Setup_setRealValue(param, paramF);
printf("\nAdjusted setting: ");
Setup_printFormattedValue(param);
} else {
printf("\nCannot understand command, ? for help\n");
}
}
}
// main menu state machine
if (mode == MAIN_SETUP) {
static uint8_t selected = 0;
int y = 0;
int keyrepeataccel = keyspressed >> 17; // Divide the value by 2
if (keyrepeataccel < 1) keyrepeataccel = 1;
if (keyrepeataccel > 30) keyrepeataccel = 30;
if (keyspressed & KEY_F1) {
if (selected > 0) { // Prev row
selected--;
} else { // wrap
selected = Setup_getNumItems() - 1;
}
}
if (keyspressed & KEY_F2) {
if (selected < (Setup_getNumItems() - 1)) { // Next row
selected++;
} else { // wrap
selected = 0;
}
}
if (keyspressed & KEY_F3) {
Setup_decreaseValue(selected, keyrepeataccel);
}
if (keyspressed & KEY_F4) {
Setup_increaseValue(selected, keyrepeataccel);
}
LCD_FB_Clear();
len = snprintf(buf, sizeof(buf), "Setup/calibration");
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), y, FONT6X6);
y += 7;
for (int i = 0; i < Setup_getNumItems() ; i++) {
len = Setup_snprintFormattedValue(buf, sizeof(buf), i);
LCD_disp_str((uint8_t*)buf, len, 0, y, FONT6X6 | (selected == i) ? INVERT : 0);
y += 7;
}
// buttons
y = 64 - 7;
LCD_disp_str((uint8_t*)" < ", 3, 0, y, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)" > ", 3, 20, y, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)" - ", 3, 45, y, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)" + ", 3, 65, y, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)" DONE ", 6, 91, y, FONT6X6 | INVERT);
// Leave setup
if (keyspressed & KEY_S) {
mode = MAIN_HOME;
Reflow_SetMode(REFLOW_STANDBY);
retval = 0; // Force immediate refresh
}
} else if (mode == MAIN_ABOUT) {
LCD_FB_Clear();
LCD_BMPDisplay(logobmp, 0, 0);
len = snprintf(buf, sizeof(buf), "T-962 controller");
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), 0, FONT6X6);
len = snprintf(buf, sizeof(buf), "%s", Version_GetGitVersion());
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), 64 - 6, FONT6X6);
LCD_BMPDisplay(stopbmp, 127 - 17, 0);
// Leave about with any key.
if (keyspressed & KEY_ANY) {
mode = MAIN_HOME;
retval = 0; // Force immediate refresh
}
} else if (mode == MAIN_REFLOW) {
uint32_t ticks = RTC_Read();
len = snprintf(buf, sizeof(buf), "%03u", Reflow_GetSetpoint());
LCD_disp_str((uint8_t*)"SET", 3, 110, 7, FONT6X6);
LCD_disp_str((uint8_t*)buf, len, 110, 13, FONT6X6);
len = snprintf(buf, sizeof(buf), "%03u", Reflow_GetActualTemp());
LCD_disp_str((uint8_t*)"ACT", 3, 110, 20, FONT6X6);
LCD_disp_str((uint8_t*)buf, len, 110, 26, FONT6X6);
len = snprintf(buf, sizeof(buf), "%03u", (unsigned int)ticks);
LCD_disp_str((uint8_t*)"RUN", 3, 110, 33, FONT6X6);
LCD_disp_str((uint8_t*)buf, len, 110, 39, FONT6X6);
// Abort reflow
if (Reflow_IsDone() || keyspressed & KEY_S) {
printf("\nReflow %s\n", (Reflow_IsDone() ? "done" : "interrupted by keypress"));
if (Reflow_IsDone()) {
Buzzer_Beep(BUZZ_1KHZ, 255, TICKS_MS(100) * NV_GetConfig(REFLOW_BEEP_DONE_LEN));
}
mode = MAIN_HOME;
Reflow_SetMode(REFLOW_STANDBY);
retval = 0; // Force immediate refresh
}
} else if (mode == MAIN_SELECT_PROFILE) {
int curprofile = Reflow_GetProfileIdx();
LCD_FB_Clear();
// Prev profile
if (keyspressed & KEY_F1) {
curprofile--;
}
// Next profile
if (keyspressed & KEY_F2) {
curprofile++;
}
Reflow_SelectProfileIdx(curprofile);
Reflow_PlotProfile(-1);
LCD_BMPDisplay(selectbmp, 127 - 17, 0);
int eeidx = Reflow_GetEEProfileIdx();
if (eeidx) { // Display edit button
LCD_BMPDisplay(f3editbmp, 127 - 17, 29);
}
len = snprintf(buf, sizeof(buf), "%s", Reflow_GetProfileName());
LCD_disp_str((uint8_t*)buf, len, 13, 0, FONT6X6);
if (eeidx && keyspressed & KEY_F3) { // Edit ee profile
mode = MAIN_EDIT_PROFILE;
current_edit_profile = eeidx;
retval = 0; // Force immediate refresh
}
// Select current profile
if (keyspressed & KEY_S) {
mode = MAIN_HOME;
retval = 0; // Force immediate refresh
}
} else if (mode == MAIN_BAKE) {
LCD_FB_Clear();
LCD_disp_str((uint8_t*)"MANUAL/BAKE MODE", 16, 0, 0, FONT6X6);
int keyrepeataccel = keyspressed >> 17; // Divide the value by 2
if (keyrepeataccel < 1) keyrepeataccel = 1;
if (keyrepeataccel > 30) keyrepeataccel = 30;
// Setpoint-
if (keyspressed & KEY_F1) {
setpoint -= keyrepeataccel;
if (setpoint < SETPOINT_MIN) setpoint = SETPOINT_MIN;
}
// Setpoint+
if (keyspressed & KEY_F2) {
setpoint += keyrepeataccel;
if (setpoint > SETPOINT_MAX) setpoint = SETPOINT_MAX;
}
// timer --
if (keyspressed & KEY_F3) {
if (timer - keyrepeataccel < 0) {
// infinite bake
timer = -1;
} else {
timer -= keyrepeataccel;
}
}
// timer ++
if (keyspressed & KEY_F4) {
timer += keyrepeataccel;
}
int y = 10;
// display F1 button only if setpoint can be decreased
char f1function = ' ';
if (setpoint > SETPOINT_MIN) {
LCD_disp_str((uint8_t*)"F1", 2, 0, y, FONT6X6 | INVERT);
f1function = '-';
}
// display F2 button only if setpoint can be increased
char f2function = ' ';
if (setpoint < SETPOINT_MAX) {
LCD_disp_str((uint8_t*)"F2", 2, LCD_ALIGN_RIGHT(2), y, FONT6X6 | INVERT);
f2function = '+';
}
len = snprintf(buf, sizeof(buf), "%c SETPOINT %d` %c", f1function, (int)setpoint, f2function);
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), y, FONT6X6);
y = 18;
if (timer == 0) {
len = snprintf(buf, sizeof(buf), "inf TIMER stop +");
} else if (timer < 0) {
len = snprintf(buf, sizeof(buf), "no timer stop");
} else {
len = snprintf(buf, sizeof(buf), "- TIMER %3d:%02d +", timer / 60, timer % 60);
}
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), y, FONT6X6);
if (timer >= 0) {
LCD_disp_str((uint8_t*)"F3", 2, 0, y, FONT6X6 | INVERT);
}
LCD_disp_str((uint8_t*)"F4", 2, LCD_ALIGN_RIGHT(2), y, FONT6X6 | INVERT);
y = 26;
if (timer > 0) {
int time_left = Reflow_GetTimeLeft();
if (Reflow_IsPreheating()) {
len = snprintf(buf, sizeof(buf), "PREHEAT");
} else if (Reflow_IsDone() || time_left < 0) {
len = snprintf(buf, sizeof(buf), "DONE");
} else {
len = snprintf(buf, sizeof(buf), "%d:%02d", time_left / 60, time_left % 60);
}
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_RIGHT(len), y, FONT6X6);
}
len = snprintf(buf, sizeof(buf), "ACT %3.1f`", Sensor_GetTemp(TC_AVERAGE));
LCD_disp_str((uint8_t*)buf, len, 0, y, FONT6X6);
y = 34;
len = snprintf(buf, sizeof(buf), " L %3.1f`", Sensor_GetTemp(TC_LEFT));
LCD_disp_str((uint8_t*)buf, len, 0, y, FONT6X6);
len = snprintf(buf, sizeof(buf), " R %3.1f`", Sensor_GetTemp(TC_RIGHT));
LCD_disp_str((uint8_t*)buf, len, LCD_CENTER, y, FONT6X6);
if (Sensor_IsValid(TC_EXTRA1) || Sensor_IsValid(TC_EXTRA2)) {
y = 42;
if (Sensor_IsValid(TC_EXTRA1)) {
len = snprintf(buf, sizeof(buf), " X1 %3.1f`", Sensor_GetTemp(TC_EXTRA1));
LCD_disp_str((uint8_t*)buf, len, 0, y, FONT6X6);
}
if (Sensor_IsValid(TC_EXTRA2)) {
len = snprintf(buf, sizeof(buf), " X2 %3.1f`", Sensor_GetTemp(TC_EXTRA2));
LCD_disp_str((uint8_t*)buf, len, LCD_CENTER, y, FONT6X6);
}
}
y = 50;
len = snprintf(buf, sizeof(buf), "COLDJUNCTION");
LCD_disp_str((uint8_t*)buf, len, 0, y, FONT6X6);
y += 8;
if (Sensor_IsValid(TC_COLD_JUNCTION)) {
len = snprintf(buf, sizeof(buf), "%3.1f`", Sensor_GetTemp(TC_COLD_JUNCTION));
} else {
len = snprintf(buf, sizeof(buf), "NOT PRESENT");
}
LCD_disp_str((uint8_t*)buf, len, (12 * 6) - (len * 6), y, FONT6X6);
LCD_BMPDisplay(stopbmp, 127 - 17, 0);
Reflow_SetSetpoint(setpoint);
if (timer > 0 && Reflow_IsDone()) {
Buzzer_Beep(BUZZ_1KHZ, 255, TICKS_MS(100) * NV_GetConfig(REFLOW_BEEP_DONE_LEN));
Reflow_SetBakeTimer(0);
Reflow_SetMode(REFLOW_STANDBY);
}
if (keyspressed & KEY_F3 || keyspressed & KEY_F4) {
if (timer == 0) {
Reflow_SetMode(REFLOW_STANDBY);
} else {
if (timer == -1) {
Reflow_SetBakeTimer(0);
} else if (timer > 0) {
Reflow_SetBakeTimer(timer);
printf("\nSetting bake timer to %d\n", timer);
}
Reflow_SetMode(REFLOW_BAKE);
}
}
// Abort bake
if (keyspressed & KEY_S) {
printf("\nEnd bake mode by keypress\n");
mode = MAIN_HOME;
Reflow_SetBakeTimer(0);
Reflow_SetMode(REFLOW_STANDBY);
retval = 0; // Force immediate refresh
}
} else if (mode == MAIN_EDIT_PROFILE) { // Edit ee1 or 2
LCD_FB_Clear();
int keyrepeataccel = keyspressed >> 17; // Divide the value by 2
if (keyrepeataccel < 1) keyrepeataccel = 1;
if (keyrepeataccel > 30) keyrepeataccel = 30;
int16_t cursetpoint;
Reflow_SelectEEProfileIdx(current_edit_profile);
if (keyspressed & KEY_F1 && profile_time_idx > 0) { // Prev time
profile_time_idx--;
}
if (keyspressed & KEY_F2 && profile_time_idx < 47) { // Next time
profile_time_idx++;
}
cursetpoint = Reflow_GetSetpointAtIdx(profile_time_idx);
if (keyspressed & KEY_F3) { // Decrease setpoint
cursetpoint -= keyrepeataccel;
}
if (keyspressed & KEY_F4) { // Increase setpoint
cursetpoint += keyrepeataccel;
}
if (cursetpoint < 0) cursetpoint = 0;
if (cursetpoint > SETPOINT_MAX) cursetpoint = SETPOINT_MAX;
Reflow_SetSetpointAtIdx(profile_time_idx, cursetpoint);
Reflow_PlotProfile(profile_time_idx);
LCD_BMPDisplay(editbmp, 127 - 17, 0);
len = snprintf(buf, sizeof(buf), "%02u0s %03u`", profile_time_idx, cursetpoint);
LCD_disp_str((uint8_t*)buf, len, 13, 0, FONT6X6);
// Done editing
if (keyspressed & KEY_S) {
Reflow_SaveEEProfile();
mode = MAIN_HOME;
retval = 0; // Force immediate refresh
}
} else { // Main menu
LCD_FB_Clear();
len = snprintf(buf, sizeof(buf),"MAIN MENU");
LCD_disp_str((uint8_t*)buf, len, 0, 6 * 0, FONT6X6);
LCD_disp_str((uint8_t*)"F1", 2, 0, 8 * 1, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)"ABOUT", 5, 14, 8 * 1, FONT6X6);
LCD_disp_str((uint8_t*)"F2", 2, 0, 8 * 2, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)"SETUP", 5, 14, 8 * 2, FONT6X6);
LCD_disp_str((uint8_t*)"F3", 2, 0, 8 * 3, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)"BAKE/MANUAL MODE", 16, 14, 8 * 3, FONT6X6);
LCD_disp_str((uint8_t*)"F4", 2, 0, 8 * 4, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)"SELECT PROFILE", 14, 14, 8 * 4, FONT6X6);
LCD_disp_str((uint8_t*)"S", 1, 3, 8 * 5, FONT6X6 | INVERT);
LCD_disp_str((uint8_t*)"RUN REFLOW PROFILE", 18, 14, 8 * 5, FONT6X6);
len = snprintf(buf, sizeof(buf), "%s", Reflow_GetProfileName());
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), 8 * 6, FONT6X6 | INVERT);
len = snprintf(buf,sizeof(buf), "OVEN TEMPERATURE %d`", Reflow_GetActualTemp());
LCD_disp_str((uint8_t*)buf, len, LCD_ALIGN_CENTER(len), 64 - 6, FONT6X6);
// Make sure reflow complete beep is silenced when pressing any key
if (keyspressed) {
Buzzer_Beep(BUZZ_NONE, 0, 0);
}
// About
if (keyspressed & KEY_F1) {
mode = MAIN_ABOUT;
retval = 0; // Force immediate refresh
}
if (keyspressed & KEY_F2) { // Setup/cal
mode = MAIN_SETUP;
Reflow_SetMode(REFLOW_STANDBYFAN);
retval = 0; // Force immediate refresh
}
// Bake mode
if (keyspressed & KEY_F3) {
mode = MAIN_BAKE;
Reflow_Init();
retval = 0; // Force immediate refresh
}
// Select profile
if (keyspressed & KEY_F4) {
mode = MAIN_SELECT_PROFILE;
retval = 0; // Force immediate refresh
}
// Start reflow
if (keyspressed & KEY_S) {
mode = MAIN_REFLOW;
LCD_FB_Clear();
printf("\nStarting reflow with profile: %s", Reflow_GetProfileName());
Reflow_Init();
Reflow_PlotProfile(-1);
LCD_BMPDisplay(stopbmp, 127 - 17, 0);
len = snprintf(buf, sizeof(buf), "%s", Reflow_GetProfileName());
LCD_disp_str((uint8_t*)buf, len, 13, 0, FONT6X6);
Reflow_SetMode(REFLOW_REFLOW);
retval = 0; // Force immediate refresh
}
}
LCD_FB_Update();
return retval;
}