-
Notifications
You must be signed in to change notification settings - Fork 1
/
breweryController.ino
executable file
·916 lines (696 loc) · 18.8 KB
/
breweryController.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
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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
#include <Encoder.h>
#include <TimerOne.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <SD.h>
#include <LiquidCrystal.h>
#include "fileStream.h"
#include "recipe.h"
#include "jsonsp.h"
#define ENCODER_USE_INTERRUPTS
//typedef RotaryEncoder Enc;
typedef Encoder Enc;
#define RECIPE_MAX_STAGES 20
#define TIME_PERIOD_FOR_LONG_PUSH 2000
#define LOG_FILE_NAME F("/logs/log.txt")
#define RECIPE_DIR F("/recipe/")
//-------define pins ------------------------------------
#define J1_PIN A4
#define J2_PIN 8
#define ENCODER_SW_PIN A5
#define ENCODER_DT_PIN 2
#define ENCODER_CLK_PIN 3
#define LCD_PIN_RS 5
#define LCD_PIN_RW 6
#define LCD_PIN_EN 7
#define LCD_PIN_D4 A0
#define LCD_PIN_D5 A1
#define LCD_PIN_D6 A2
#define LCD_PIN_D7 A3
#define DS18B20_PIN 9
#define BEEPER_PIN 4
//-------define Key names for json file -----------------
#define RECIPE_NAME "name"
#define RECIPE_PHASES "Phases"
#define RECIPE_PHASE_NAME "Name"
#define RECIPE_PHASE_INCREASE_TEMPERATURE "IncT"
#define RECIPE_PHASE_MAINTAIN_TEMPERATURE "MaintainT"
#define RECIPE_PHASE_KEY_EVENT "KeyEvent"
#define FAIL_T_TIME 2
#define FAIL_TEMPERATURE 1
//DS18b20
OneWire oneWire(DS18B20_PIN);
DallasTemperature t_sensor(&oneWire);
DeviceAddress sensor1;
Enc myEnc(2, 3);
Recipe<RECIPE_MAX_STAGES> *recipe = 0;
//LiquidCrystal lcd(LCD_PIN_RS, LCD_PIN_RW, LCD_PIN_EN, LCD_PIN_D0, LCD_PIN_D1, LCD_PIN_D2, LCD_PIN_D3, LCD_PIN_D4, LCD_PIN_D5, LCD_PIN_D6, LCD_PIN_D7);
LiquidCrystal lcd(LCD_PIN_RS, LCD_PIN_RW, LCD_PIN_EN, LCD_PIN_D4, LCD_PIN_D5, LCD_PIN_D6, LCD_PIN_D7);
int currentPhase = 0;
bool isHeat = true;
bool isStart = true;
bool mustStop = false;
bool keyPressed = false;
bool isFailed = false;
float currentTemperature = 0;
int timePassed = 11;
unsigned long startTime;
#define HYSTERESIS 1
#define PRE_OFF 0
void setup() {
lcd.begin(20,4);
//lcd.print("hello");
pinMode (ENCODER_SW_PIN, INPUT_PULLUP);
pinMode (J1_PIN, OUTPUT);
pinMode (J2_PIN, OUTPUT);
digitalWrite (J1_PIN, HIGH);
digitalWrite (J2_PIN, HIGH);
pinMode (BEEPER_PIN, OUTPUT);
//Serial.begin(9600);
//Serial.println(freeRam());
//for (int i = 0; i < 8; ++i)
// Serial.println(sensor1[i]);
t_sensor.begin();
t_sensor.getAddress(sensor1, 0);
t_sensor.setResolution(12);
//for (int i = 0; i < 8; ++i)
//Serial.println(sensor1[i]);
lcd.clear();
lcd.print(F("Initializing SD card"));
if (!SD.begin(10)) {
lcd.setCursor(0, 1);
lcd.print(F("initialization fail"));
lcd.setCursor(3, 2);
lcd.print(F("insert SD card"));
lcd.setCursor(2, 3);
lcd.print(F("and reset device"));
while (true){
}
}
/*
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
}
Serial.println("initialization done.");
*/
//Serial.println(freeRam());
}
/*
String addSpace(const String& s1){
String s = s1;
int l = s.length();
if ( l <= 20 )
l = 20 - l;
else
return s.substring(0, 19);
for (int i = 0; i < l; ++i)
s += ' ';
return s;
}
*/
void printCurrentStatus(){
lcd.clear();
//const char sp[] = " ";
//lcd.setCursor(0,0);
//lcd.print(sp);
lcd.setCursor(0,0);
lcd.print(recipe->name());
//Serial.println(recipe->name());
//lcd.setCursor(0,1);
//lcd.print(sp);
lcd.setCursor(0,1);
lcd.print( recipe->phases_[currentPhase].name() );
//lcd.print(freeRam());
//lcd.setCursor(0,2);
//lcd.print(sp);
lcd.setCursor(0,2);
lcd.print( F("T=") );
lcd.print( currentTemperature );
lcd.print( F("C, Aim=") );
lcd.print( recipe->phases_[currentPhase].incT_ );
lcd.print( F("C") );
//lcd.setCursor(0,3);
//lcd.print(sp);
lcd.setCursor(0,3);
if ( isHeat) {
lcd.print( F("Heating ") );
lcd.print( timePassed );
lcd.print( F(" min.") );
}else{
lcd.print( timePassed );
lcd.print( F(" min. (") );
lcd.print( recipe->phases_[currentPhase].maintainT_ );
lcd.print( F(" min.)") );
}
}
int freeRam (){
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
bool parseJsonObj(inputStream& str){
Jsonsp par(str);
//Serial.println("start parsing");
//Serial.println(freeRam());
int numberOfPhases;
//Serial.println(freeRam());
recipe->size_ = 0;
if ( par[RECIPE_NAME].objType() == 3 )
recipe->setName( par[RECIPE_NAME].asString() );
else
return false;
if ( par[RECIPE_PHASES].objType() == 2 ){
numberOfPhases = par[RECIPE_PHASES].size();
if (numberOfPhases < 1 || numberOfPhases > 20)
return false;
}
for (int i = 0; i < numberOfPhases; ++i){
//int y = par[RECIPE_PHASES][i].objType();
Jsonsp phase = par[RECIPE_PHASES][i];
if ( phase.objType() == 1 ){
if ( phase[RECIPE_PHASE_NAME].objType() == 3 )
recipe->phases_[i].setName( phase[RECIPE_PHASE_NAME].asString() );
else
return false;
if ( phase[RECIPE_PHASE_INCREASE_TEMPERATURE].objType() == 3 )
recipe->phases_[i].incT_ = phase[RECIPE_PHASE_INCREASE_TEMPERATURE].asInt();
else
recipe->phases_[i].incT_ = 0;
if ( phase[RECIPE_PHASE_MAINTAIN_TEMPERATURE].objType() == 3 )
recipe->phases_[i].maintainT_ = phase[RECIPE_PHASE_MAINTAIN_TEMPERATURE].asInt();
else
recipe->phases_[i].maintainT_ = 0;
if ( phase[RECIPE_PHASE_KEY_EVENT].objType() == 3 )
recipe->phases_[i].keyEvent_ = phase[RECIPE_PHASE_KEY_EVENT].asBool();
else
recipe->phases_[i].keyEvent_ = false;
//Serial.println(freeRam());
}
++recipe->size_;
}
/*
Serial.println(freeRam());
Serial.println(recipe->size_);
Serial.println(recipe->name());
for (int i = 0; i < recipe->size_; ++i){
Serial.print(recipe->phases_[i].name());
Serial.print(F(" "));
Serial.print(recipe->phases_[i].incT_);
Serial.print(F(" "));
Serial.print(recipe->phases_[i].maintainT_);
Serial.print(F(" "));
Serial.println(recipe->phases_[i].keyEvent_);
}
Serial.flush();
Serial.println(freeRam());
*/
return true;
}
String loadRecipe(){
//Serial.println(freeRam());
//RotaryEncoder myEnc(ENCODER_CLK_PIN, ENCODER_DT_PIN);
//Serial.println((int)myEnc.clkPin_);
//Serial.println((int)myEnc.dt_pin_);
lcd.clear();
// Enc myEnc(2, 3);
#define ARRAY_SIZE 30
#define startEEPROMAdress 512
//char files[ARRAY_SIZE][13] = {0};
char fileName[13] = {0};
byte arraySize = 0;
byte startPos = 0;
byte cursorPos = 0;
if ( !SD.exists(RECIPE_DIR) )
SD.mkdir(RECIPE_DIR);
File rootDir = SD.open(RECIPE_DIR);
rootDir.rewindDirectory();
for (int i = 0; i < ARRAY_SIZE; ++i){
File parseFile = rootDir.openNextFile();
if ( !parseFile ){
parseFile.close();
break;
}
//Serial.println(parseFile.name());
if ( parseFile.isDirectory() ){
parseFile.close();
continue;
}
strcpy(fileName, parseFile.name());
EEPROM.put(startEEPROMAdress+arraySize*sizeof(fileName), fileName);
parseFile.close();
++arraySize;
}
rootDir.close();
//Serial.println(freeRam());
//Serial.flush();
lcd.setCursor(0,0);
lcd.print(F("Change file :"));
//lcd.print(freeRam());
//lcd.print(arraySize);
if (arraySize == 0) {
lcd.setCursor(0,1);
lcd.print(F(" no files"));
while (true){
}
}
byte choice = 0;
bool firstRun = true;
while (true){
int res = myEnc.read();//EncoderI.getEncoderTurn();
int res2 = getButtonEvent();
if (res2 != 0){
choice = startPos+cursorPos;
break;
}
if (res or firstRun){
firstRun = false;
if ( (cursorPos + res) > 2 ){
if ( (startPos + cursorPos + res) < arraySize ){
startPos += res;
}
}else if ( (cursorPos + res) < 0 ){
if ( (startPos + cursorPos + res) >= 0 ){
startPos += res;
}
}else {
if ( (cursorPos + res) < arraySize)
cursorPos += res;
}
for (int i = 0; i < 3; ++i){
if ( (startPos + i) >= arraySize )
break;
lcd.setCursor(0, i+1);
lcd.print(F(" "));
EEPROM.get(startEEPROMAdress + sizeof(fileName) * (startPos+i), fileName);
byte t = (20 - strlen(fileName) )/2;
lcd.setCursor(t,i+1);
lcd.print(fileName);
if (cursorPos == i){
lcd.setCursor(0, i+1);
lcd.print(F(" ["));
lcd.setCursor(17, i+1);
lcd.print(F("]"));
}
}
myEnc.write(0);
}
}
//delay(100);
EEPROM.get(startEEPROMAdress + sizeof(fileName) * choice, fileName);
String s = RECIPE_DIR;
s += fileName;
//delete[] &files;
return s;
}
void logger(String str, bool saveTime = true){
if ( !SD.exists(F("/logs")) )
SD.mkdir(F("/logs"));
File logFile = SD.open(LOG_FILE_NAME, FILE_WRITE);
if (saveTime){
unsigned long cTime = (millis() - startTime) / 1000;
logFile.print(cTime/60, 10);
logFile.print(F(":"));
//logFile.print(F(" min., "));
//logFile.print(cTime%60, 10);
//logFile.print(F(" sec. : "));
}
logFile.println(str);
logFile.close();
}
void shortBeep(){
digitalWrite(BEEPER_PIN, HIGH);
delay(100);
digitalWrite(BEEPER_PIN, LOW);
}
void longBeep(){
digitalWrite(BEEPER_PIN, HIGH);
delay(1000);
digitalWrite(BEEPER_PIN, LOW);
}
String readline(File & file){
char c;
char readChar;
String buf = "";
while ( (c = file.read(&readChar, 1)) ){
if ( readChar == '\r' ){
file.read(readChar, 1);
break;
}
buf += readChar;
}
return buf;
}
void showLog(){
//lcd.print(freeRam() );
//delay(1000);
File logFile2 = SD.open(LOG_FILE_NAME, FILE_READ);
/*
if (! logFile2){
logFile2.close();
return;
}
*/
int fPos[30] = {0};
int lineNumber = 0;
for (int i = 0; i < 30; ++i){
int p = logFile2.position();
String s = readline(logFile2);
//Serial.println(s);
if ( s != "" ){
fPos[i] = p;
++lineNumber;
}
else
break;
}
//Serial.println(lineNumber);
bool isFirst = true;
int startPos = 0;
//lcd.print((bool)logFile);
//delay(1000);
while (true){
int res = myEnc.read();
int key = getButtonEvent();
if ( key != 0 )
break;
if ( res || isFirst ){
isFirst = false;
if (res > 1)
res = 1;
if (res < -1)
res = -1;
myEnc.write(0);
if ( ( (startPos+res) >= 0 ) && ( (startPos+res) <= (lineNumber-4) ) )
startPos += res;
lcd.clear();
for (int i = 0; i < 4; ++i){
if ( (startPos+i) >= lineNumber )
break;
logFile2.seek(fPos[startPos+i]);
String s = readline(logFile2);
lcd.setCursor(0,i);
lcd.print(s);
}
}
}
logFile2.close();
}
void stopRegulator(){
Timer1.stop();
digitalWrite(J1_PIN, HIGH);
digitalWrite(J2_PIN, HIGH);
mustStop = true;
}
void regulatorMenu(){
char items[3][13] = {"Cancel","Show log", "Stop brewing"};
byte pos = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Menu:"));
for (int i = 0; i < 3; ++i){
byte len = strlen(items[i]);
lcd.setCursor((20-len)/2, i+1);
lcd.print(items[i]);
}
lcd.setCursor(2,1+pos);
lcd.print("[");
lcd.setCursor(18,1+pos);
lcd.print("]");
while (true){
int res = myEnc.read();
int key = getButtonEvent();
if (res){
//Serial.println(res);
if (res > 1)
res = 1;
if (res < -1)
res = -1;
myEnc.write(0);
if ( ( (pos+res) <= 2 ) and ( (pos+res) >= 0 ) )
pos += res;
for (int i = 0; i < 3; ++i){
lcd.setCursor(2,i+1);
lcd.print(" ");
lcd.setCursor(18,i+1);
lcd.print(" ");
}
lcd.setCursor(2,1+pos);
lcd.print("[");
lcd.setCursor(18,1+pos);
lcd.print("]");
}
if ( key != 0 ){
if (pos == 2){
if ( confirmation(F("Stop brewing."), "") ){
logger(F("stopped by user."));
stopRegulator();
break;
}
}
if (pos == 1){
showLog();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Menu:"));
for (int i = 0; i < 3; ++i){
byte len = strlen(items[i]);
lcd.setCursor((20-len)/2, i+1);
lcd.print(items[i]);
}
lcd.setCursor(2,1+pos);
lcd.print("[");
lcd.setCursor(18,1+pos);
lcd.print("]");
}
if (pos == 0)
return;
}
}
}
void startRegulator(){
timePassed = 0;
SD.remove(LOG_FILE_NAME);
//Serial.println(freeRam());
delay(300);
mustStop = false;
isStart = true;
keyPressed = false;
isHeat = recipe->phases_[0].incT_;
startTime = millis();
logger(F(" started."));
logger(recipe->name(), false);
Timer1.initialize(100000);
Timer1.attachInterrupt(regulator);
//Serial.println(freeRam());
while (! mustStop){
if ( isFailed) {
faildIncreaseT();
isFailed = false;
}
printCurrentStatus();
switch ( getButtonEvent() ){
case (0) :
break;
case (1) :
keyPressed = true;
break;
case (2) :
regulatorMenu();
break;
}
delay(50);
}
}
void faildIncreaseT(){
logger(F("Temp. inc. faild"));
//stopRegulator();
lcd.clear();
lcd.print(F(" Temp. increasing"));
lcd.setCursor(5,1);
lcd.print(F("is failed."));
lcd.setCursor(5,2);
//lcd.print(freeRam());
longBeep();
delay(1000);
longBeep();
}
void regulator(){
t_sensor.setWaitForConversion(false);
t_sensor.requestTemperaturesByAddress(sensor1);
t_sensor.setWaitForConversion(true);
//Serial.println(t_sensor.isConnected(sensor1));
currentTemperature = t_sensor.getTempC(sensor1);
//Serial.println(currentTemperature);
static float oldT = currentTemperature;
static unsigned long timeOfOldT = millis();
static unsigned long startPhaseTime = millis();
unsigned long cTime = millis();
if (isStart){
startPhaseTime = cTime;
oldT = currentTemperature;
timeOfOldT =cTime;
isStart = false;
}
timePassed = (cTime-startPhaseTime)/1000/60;
unsigned long timeFI = (cTime-timeOfOldT)/1000/60;
if ( isHeat ){
if ( (timeFI) >= FAIL_T_TIME){
if ( (currentTemperature - oldT) <= FAIL_TEMPERATURE ){
// stop Regulator
isFailed = true;;
//return;
}
oldT = currentTemperature;
timeOfOldT = cTime;
}
if ( currentTemperature <= recipe->phases_[currentPhase].incT_ )
digitalWrite(J1_PIN, LOW);
else{
digitalWrite(J1_PIN, HIGH);
isHeat = false;
timeOfOldT = cTime;
startPhaseTime = cTime;
shortBeep();
logger(F("heating finished"));
logger(recipe->phases_[currentPhase].name(), false);
}
}else{
if ( currentTemperature >= recipe->phases_[currentPhase].incT_ )
digitalWrite(J2_PIN, HIGH);
if ( currentTemperature <= (recipe->phases_[currentPhase].incT_-HYSTERESIS) )
digitalWrite(J2_PIN, LOW);
//byte workTime = (startTime - millis()) * 1000 * 60;
if ( (recipe->phases_[currentPhase].maintainT_ != 0) && ( timePassed >= recipe->phases_[currentPhase].maintainT_ ) ){
logger(F("maintain finished"));
logger(recipe->phases_[currentPhase].name(), false);
++currentPhase;
if ( currentPhase >= recipe->size() ){
stopRegulator();
}
isHeat = recipe->phases_[currentPhase].incT_;
digitalWrite(J2_PIN, HIGH);
timeOfOldT = cTime;
startPhaseTime = cTime;
shortBeep();
}
if ( recipe->phases_[currentPhase].keyEvent_ && keyPressed){
keyPressed = false;
logger(F("maintain finished"));
logger(recipe->phases_[currentPhase].name(), false);
++currentPhase;
if ( currentPhase >= recipe->size() ){
stopRegulator();
}
isHeat = recipe->phases_[currentPhase].incT_;
digitalWrite(J2_PIN, HIGH);
timeOfOldT = cTime;
startPhaseTime = cTime;
shortBeep();
}
}
//Serial.println("R");
}
bool confirmation(String str1, String str2){
//Enc myEnc(2, 3);
const char yes_no[2][4] = {"No", "Yes"};
//RotaryEncoder myEnc(ENCODER_CLK_PIN, ENCODER_DT_PIN);
byte pos = 1;
lcd.clear();
int startPos = (20-str1.length())/2;
lcd.setCursor(startPos, 0);
lcd.print(str1);
startPos = (20-str2.length())/2;
lcd.setCursor(startPos, 1);
lcd.print(str2);
lcd.setCursor(9,2);
lcd.print(yes_no[0]);
lcd.setCursor(9,3);
lcd.print(yes_no[1]);
lcd.setCursor(7,2+pos);
lcd.print("[");
lcd.setCursor(14,2+pos);
lcd.print("]");
while (true){
int res = myEnc.read();//EncoderI.getEncoderTurn();
int res2 = getButtonEvent();
if (res2 != 0){
return pos;
}
if (res){
if ( ( (pos+res) <= 1 ) and ( (pos+res) >= 0 ) )
pos += res;
lcd.setCursor(7,2);
lcd.print(" ");
lcd.setCursor(14,2);
lcd.print(" ");
lcd.setCursor(7,3);
lcd.print(" ");
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(7,2+pos);
lcd.print("[");
lcd.setCursor(14,2+pos);
lcd.print("]");
myEnc.write(0);
}
}
}
void loop() {
if (recipe == 0)
recipe = new Recipe<RECIPE_MAX_STAGES>();
else{
delete recipe;
recipe = new Recipe<RECIPE_MAX_STAGES>();
}
//Serial.println(sizeof(myEnc));
//Serial.print("before load");
//Serial.println(freeRam());
File f;
String fileName = loadRecipe();
//Serial.print("after load");
//Serial.println(freeRam());
//Serial.print("before parse");
//Serial.println(sizeof(lcd));
//Serial.flush();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(F(" Loading recipe ..."));
f = SD.open(fileName, FILE_READ);
//Serial.println(sizeof(String));
FileStream fstream(&f);
//Serial.println(freeRam());
bool result = parseJsonObj(fstream);
f.close();
if (not result){
lcd.setCursor(0,1);
lcd.print(F(" Uncorrect format."));
longBeep();
delay(3000);
return;
}
//Serial.print("after parse");
//Serial.println(freeRam());
if (! confirmation(F("Start recipe"), recipe->name()) )
return;
startRegulator();
showLog();
delay(3000);
}
byte getButtonEvent(){
static byte oldStatus = digitalRead(ENCODER_SW_PIN);
byte newStatus = digitalRead(ENCODER_SW_PIN);
static unsigned long pushedTime = 0;
byte res = 0;
if ( oldStatus == HIGH && newStatus == LOW ){
pushedTime = millis();
}
if ( oldStatus == LOW && newStatus == HIGH ){
if ( (millis() - pushedTime) > TIME_PERIOD_FOR_LONG_PUSH )
res = 2;
else
res = 1;
}
oldStatus = newStatus;
return res;
}