forked from nanomonkey/KS_100kW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.pde
844 lines (828 loc) · 21.6 KB
/
Display.pde
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
void DoDisplay() {
boolean disp_alt; // Var for alternating value display
char buf[20];
char choice[5] = " ";
char menu1[] = "NEXT ADV + - ";
if (millis() % 4000 > 2000) {
disp_alt = false;
}
else {
disp_alt = true;
}
switch (display_state) {
case DISPLAY_SPLASH:
//Row 0
Disp_RC(0,0);
if (GCU_version == V2) {
Disp_PutStr(" KS GCU V 2.0 ");
}
else if (GCU_version == V3) {
Disp_PutStr(" KS PCU V 3.0 ");
}
//Row 1
Disp_RC(1,0);
Disp_PutStr("www.allpowerlabs.org");
//Row 2
Disp_RC(2,0);
sprintf(buf, " %s ", CODE_VERSION);
Disp_PutStr(buf);
//Row 3
Disp_RC(3,0);
Disp_PutStr(" ");
Disp_CursOff();
//Transition out after delay
if (millis()-display_state_entered>2000) {
TransitionDisplay(DISPLAY_REACTOR);
}
break;
case DISPLAY_REACTOR:
Disp_CursOff();
//Row 0
Disp_RC(0, 0);
if (millis()-transition_entered<2000) {
transition_message.toCharArray(buf,21);
Disp_PutStr(buf);
}
else {
if (disp_alt) {
sprintf(buf, "Trest%4i ", Temp_Data[T_REST1]);
}
else {
sprintf(buf, "Trest%s", T_rest1Level[TempLevelName]);
}
Disp_PutStr(buf);
Disp_RC(0, 11);
if (disp_alt) {
sprintf(buf, "Pcomb%4i", Press[P_COMB] / 25);
} else {
sprintf(buf, "Log# %4i", data_log_num);
}
Disp_PutStr(buf);
}
//Row 1
Disp_RC(1, 0);
if (disp_alt) {
sprintf(buf, "Tred1%4i ", Temp_Data[T_RED1]);
} else {
sprintf(buf, "Tred1%s", T_red1Level[TempLevelName]);
}
Disp_PutStr(buf);
Disp_RC(1, 11);
if (disp_alt) {
sprintf(buf, "Preac%4i", Press[P_REACTOR] / 25);
} else {
sprintf(buf, "Time %4i", millis()/1000);
}
Disp_PutStr(buf);
//Row 2
Disp_RC(2,0);
Disp_PutStr("CARBAFGI "); //Conveyor, Rotary Valve, Boot, Auger, Fuel Switch, Grate, Ignitor - Header
Disp_RC(2, 11);
if (disp_alt) {
sprintf(buf, "Pfilt%4i", Press[P_FILTER] / 25);
}
else {
sprintf(buf, "Fuel %4i", int(ceil(mixture_input*100)));
}
Disp_PutStr(buf);
//Row 3
if (millis() % 4000 > 2000 & alarm != ALARM_NONE) {
Disp_RC(3,0);
Disp_PutStr(display_alarm[alarm]);
}
// else {
// Disp_RC(3,0);
// if (AUGER_RUNNING) {
// sprintf(buf, "Aug On%3i ", auger_on_length);
// }
// else {
// sprintf(buf, "AugOff%3i ", auger_off_length);
// }
// Disp_PutStr(buf);
// sprintf(buf, " ");
// //if (disp_alt) {
// // sprintf(buf, "Hz %4i", int(CalculatePeriodHertz()));
// //} else {
// // sprintf(buf, "Batt%5i", int(battery_voltage*10));
// // //sprintf(buf, "Pow %5i", int(CalculatePulsePower()));
// //}
// Disp_RC(3, 11);
// Disp_PutStr(buf);
// }
else {
Disp_RC(3,0);
GetFuelFeedStates();
display_string.toCharArray(buf, 11);
Disp_PutStr(buf);
}
Disp_RC(3,11);
if (disp_alt) {
if (P_reactorLevel != OFF) {
//the value only means anything if the pressures are high enough, otherwise it is just noise
sprintf(buf, "Pratio%3i", int(pRatioReactor*100)); //pressure ratio
Disp_PutStr(buf);
}
else {
Disp_PutStr("Pratio --");
}
} else {
sprintf(buf, "FuelS%4i", int(ceil(mixture_setpoint*100.0)));
Disp_PutStr(buf);
}
break;
case DISPLAY_ENGINE:
// Disp_CursOff();
// Disp_RC(0,0);
////#if T_ENG_COOLANT != ABSENT
//// sprintf(buf, "Tcool%4i ", Temp_Data[T_ENG_COOLANT]);
////#else
// sprintf(buf, "Tcool NA ");
////#endif
// Disp_PutStr(buf);
// Disp_RC(0,11);
// Disp_PutStr(" ");
// //Row 1
// Disp_RC(1,0);
// Disp_PutStr(" ");
// //Row 2
// Disp_RC(2,0);
// Disp_PutStr(" ");
// //Row 3
// Disp_RC(3,0);
// Disp_PutStr(" ");
// Disp_CursOff();
break;
case DISPLAY_TESTING:
Disp_CursOff();
item_count = 1;
//Row 0
Disp_RC(0,0);
Disp_PutStr("Testing ");
//Row 1
Disp_RC(1,0);
sprintf(buf, "Test:%-15s", TestingStateName[testing_state]);
Disp_PutStr(buf);
//Row 2
Disp_RC(2,0);
switch (testing_state) {
case TESTING_ANA_EO2:
sprintf(buf, "Value: %4i ", int(analogRead(ANA_EO2)));
break;
case TESTING_ANA_FO2:
sprintf(buf, "Value: %4i ", int(analogRead(ANA_FO2)));
break;
case TESTING_ANA_FUEL_SWITCH:
sprintf(buf, "Value: %4i ", int(analogRead(ANA_FUEL_SWITCH)));
break;
case TESTING_ANA_POT1:
sprintf(buf, "Value: %4i ", int(analogRead(ANA_POT1)));
break;
case TESTING_ANA_POT2:
sprintf(buf, "Value: %4i ", int(analogRead(ANA_POT2)));
break;
default:
sprintf(buf," ");
}
Disp_PutStr(buf);
//Row 3
switch (cur_item) {
case 1: // Testing
if (key == 2) {
GoToNextTestingState(); //first testing state
}
Disp_RC(3,0);
Disp_PutStr("NEXT TEST ");
break;
default:
Disp_RC(3,0);
Disp_PutStr("NEXT ");
}
break;
case DISPLAY_MIXTURE:
double P,I;
item_count = 4;
P=mixture.GetP_Param();
I=mixture.GetI_Param();
Disp_RC(0,0);
sprintf(buf, "FuelSet%3i ", int(ceil(mixture_setpoint*100.0)));
Disp_PutStr(buf);
Disp_RC(0,11);
sprintf(buf, "Fuel %3i", int(ceil(mixture_input*100.0)));
Disp_PutStr(buf);
//Row 1
Disp_RC(1,0);
sprintf(buf, "P %3i ", int(ceil(mixture.GetP_Param()*100.0)));
Disp_PutStr(buf);
Disp_RC(1,11);
sprintf(buf, "I %3i", int(ceil(mixture.GetI_Param()*100.0)));
Disp_PutStr(buf);
Disp_RC(2,0);
sprintf(buf, "Out %3i ", int(ceil(mixture_output*100)));
Disp_PutStr(buf);
Disp_RC(2,11);
sprintf(buf, " ");
Disp_PutStr(buf);
switch (cur_item) {
case 1: // mixture setpoint
if (key == 2) {
//mixture_setpoint += 0.2;
//WriteMixture();
}
if (key == 3) {
//mixture_setpoint -= 0.2;
//WriteMixture();
}
Disp_RC(0,0);
Disp_CursOn();
Disp_RC(3,0);
Disp_PutStr("NEXT ADV ");
break;
case 2: //mixture reading
Disp_RC(3,0);
Disp_PutStr("NEXT ADV ");
Disp_RC(0,11);
Disp_CursOn();
break;
case 3: //mixture P
if (key == 2) {
P += 0.01;
WriteMixture();
}
if (key == 3) {
P -= 0.01;
WriteMixture();
}
mixture.SetTunings(P,I,0);
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(1,0);
Disp_CursOn();
break;
case 4: //mixture I
if (key == 2) {
I += 0.1;
WriteMixture();
}
if (key == 3) {
I -= 0.1;
WriteMixture();
}
mixture.SetTunings(P,I,0);
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(1,11);
Disp_CursOn();
break;
}
break;
//Pressure PID:
case DISPLAY_PRESSURE_PID:
double pP,pI;
item_count = 4;
pP=pressure_PID.GetP_Param();
pI=pressure_PID.GetI_Param();
Disp_RC(0,0);
sprintf(buf, "PcSet%4i ", int(pressure_setpoint));
Disp_PutStr(buf);
Disp_RC(0,11);
sprintf(buf, "Pin%6i", int(pressure_input));
Disp_PutStr(buf);
//Row 1
Disp_RC(1,0);
sprintf(buf, "P %3i ", int(ceil(pressure_PID.GetP_Param()*50)));
Disp_PutStr(buf);
Disp_RC(1,11);
sprintf(buf, "I %3i", int(ceil(pressure_PID.GetI_Param()*5)));
Disp_PutStr(buf);
Disp_RC(2,0);
sprintf(buf, "PIDout:%4i", int(pressure_output));
Disp_PutStr(buf);
switch (cur_item) {
case 1: // Pressure_PID setpoint
if (key == 2) {
pressure_setpoint += .02;
WritePressurePID();
}
if (key == 3) {
pressure_setpoint -= .02;
WritePressurePID();
}
Disp_RC(0,0);
Disp_CursOn();
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
break;
case 2: //Pcomb reading
Disp_RC(3,0);
Disp_PutStr("NEXT ADV ");
Disp_RC(0,11);
Disp_CursOn();
break;
case 3: //Pressure_PID P
if (key == 2) {
pP += .02;
WritePressurePID();
}
if (key == 3) {
pP -= .02;
WritePressurePID();
}
pressure_PID.SetTunings(pP,pI,0);
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(1,0);
Disp_CursOn();
break;
case 4: //Pressure_PID I
if (key == 2) {
pI += .2;
WritePressurePID();
}
if (key == 3) {
pI -= .2;
WritePressurePID();
}
pressure_PID.SetTunings(pP,pI,0);
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(1,11);
Disp_CursOn();
break;
}
break;
case DISPLAY_GRATE:
int vmin,vmax;
item_count = 4;
Disp_RC(0,0);
sprintf(buf, "GraMin%3i ", grate_min_interval);
Disp_PutStr(buf);
Disp_RC(0,11);
sprintf(buf, "GraMax%3i", grate_max_interval);
Disp_PutStr(buf);
//Row 1
Disp_RC(1,0);
sprintf(buf, "GraLen%3i ", grate_on_interval);
Disp_PutStr(buf);
Disp_RC(1,11);
if (grate_state == GRATE_OFF) {
Disp_PutStr("Grate Off");
}
else {
Disp_PutStr("Grate On");
}
Disp_RC(2,0);
Disp_PutStr(" ");
switch (cur_item) {
case 1: // Grate Min Interval
vmin = max(0,grate_on_interval);
vmax = grate_max_interval;
if (key == 2) {
grate_min_interval += 3;
grate_min_interval = constrain(grate_min_interval,vmin,vmax);
CalculateGrate();
WriteGrate();
}
if (key == 3) {
grate_min_interval -= 3;
grate_min_interval = constrain(grate_min_interval,vmin,vmax);
CalculateGrate();
WriteGrate();
}
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(0,0);
Disp_CursOn();
break;
case 2: //Grate Interval
vmin = max(grate_on_interval,grate_min_interval);
vmax = 255*3;
if (key == 2) {
grate_max_interval += 3;
grate_max_interval = constrain(grate_max_interval,vmin,vmax);
CalculateGrate();
WriteGrate();
}
if (key == 3) {
grate_max_interval -= 3;
grate_max_interval = constrain(grate_max_interval,vmin,vmax);
CalculateGrate();
WriteGrate();
}
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(0,11);
Disp_CursOn();
break;
case 3: //Grate On Interval
vmin = 0;
vmax = min(grate_min_interval,255);
if (key == 2) {
grate_on_interval += 1;
grate_on_interval = constrain(grate_on_interval,vmin,vmax);
CalculateGrate();
WriteGrate();
}
if (key == 3) {
grate_on_interval -= 1;
grate_on_interval = constrain(grate_on_interval,vmin,vmax);
CalculateGrate();
WriteGrate();
}
Disp_RC(3,0);
Disp_PutStr("NEXT ADV + - ");
Disp_RC(1,0);
Disp_CursOn();
break;
case 4: //Grate
if (key == 2) {
grate_state = GRATE_OFF;
}
grate_val = GRATE_SHAKE_CROSS;
Disp_RC(3,0);
Disp_PutStr("NEXT ADV OFF ON ");
Disp_RC(1,11);
Disp_CursOn();
break;
}
break;
case DISPLAY_SERVO: //need to add constraints for min and max?
item_count = 2;
testing_state = TESTING_SERVO; //necessary so that there isn't any conflicting servo writes
Disp_RC(0,0);
sprintf(buf, "ServoMin%3i", int(throttle_valve_closed));
Disp_PutStr(buf);
Disp_RC(0,11);
sprintf(buf, " Max %3i", int(throttle_valve_open));
Disp_PutStr(buf);
//Row 1
Disp_RC(1,0);
Disp_PutStr(" Careful of Sides! ");
Disp_RC(2,0);
Disp_PutStr(" ");
switch (cur_item) {
case 1: // Servo Min
Servo_Mixture.write(throttle_valve_closed);
if (key == 2) {
if (throttle_valve_closed + 1 < throttle_valve_open){
throttle_valve_closed += 1;
}
}
if (key == 3) {
throttle_valve_closed -= 1;
}
Disp_RC(3,0);
Disp_PutStr(menu1);
Disp_RC(0,0);
Disp_CursOn();
break;
case 2: //Servo Max
Servo_Mixture.write(throttle_valve_open);
if (key == 2) {
throttle_valve_open += 1;
}
if (key == 3) {
if (throttle_valve_open - 1 > throttle_valve_closed) {
throttle_valve_open -= 1;
}
}
Disp_RC(3,0);
Disp_PutStr(menu1);
Disp_RC(0,11);
Disp_CursOn();
break;
}
break;
case DISPLAY_CONFIG:
Disp_CursOff();
item_count = sizeof(Config_Choices)/sizeof(Config_Choices[0]);
if (config_changed == false){
config_var = getConfig(cur_item);
}
if (config_var == 255){ //EEPROM default state, not a valid choice. Loops choice back to zero.
config_var = 0;
}
if (config_var == -1){ //keeps values from being negative
config_var = 254;
}
Disp_RC(0,0);
Disp_PutStr(" Configurations ");
Disp_RC(1,0);
if (Config_Choices[cur_item-1] == "+ - "){
sprintf(buf, "%s:%3i", Configuration[cur_item-1], config_var);
} else if (Config_Choices[cur_item-1] == "+5 -5 "){
sprintf(buf, "%s:%3i", Configuration[cur_item-1], 5*config_var);
} else {
if (config_var == 0){
choice[0] = Config_Choices[cur_item-1][0];
choice[1] = Config_Choices[cur_item-1][1];
choice[2] = Config_Choices[cur_item-1][2];
choice[3] = Config_Choices[cur_item-1][3];
} else {
choice[0] = Config_Choices[cur_item-1][4];
choice[1] = Config_Choices[cur_item-1][5];
choice[2] = Config_Choices[cur_item-1][6];
choice[3] = Config_Choices[cur_item-1][7];
}
sprintf(buf, "%s:%s", Configuration[cur_item-1], choice);
}
Disp_PutStr(buf);
Disp_RC(2,0);
Disp_PutStr("ADV to save choice ");
Disp_RC(3,0);
sprintf(buf, "NEXT ADV %s", Config_Choices[cur_item-1]);
Disp_PutStr(buf);
if (Config_Choices[cur_item-1] == "+ - "){
if (key == 2) {
if (config_max[cur_item-1] >= config_var + 1){
config_var += 1;
config_changed = true;
}
}
if (key == 3) {
if (config_min[cur_item-1] <= config_var - 1){
config_var -= 1;
config_changed = true;
}
}
} else if (Config_Choices[cur_item-1] == "+5 -5 "){
if (key == 2) {
if (config_max[cur_item-1] >= config_var + 1){
config_var += 1;
config_changed = true;
}
}
if (key == 3) {
if (config_min[cur_item-1] <= config_var - 1){
config_var -= 1;
config_changed = true;
}
}
} else {
if (key == 2) {
config_var = 0;
config_changed = true;
}
if (key == 3) {
config_var = 1;
config_changed = true;
}
}
break;
// case DISPLAY_TEMP2:
// break;
// case DISPLAY_FETS:
// break;
}
key = -1; //important, must clear key to read new input
}
void TransitionDisplay(int new_state) {
//Enter
display_state_entered = millis();
switch (new_state) {
case DISPLAY_SPLASH:
break;
case DISPLAY_REACTOR:
break;
case DISPLAY_ENGINE:
break;
case DISPLAY_MIXTURE:
cur_item = 1;
break;
case DISPLAY_PRESSURE_PID:
cur_item = 1;
break;
case DISPLAY_GRATE:
cur_item = 1;
break;
case DISPLAY_TESTING:
cur_item = 1;
break;
case DISPLAY_SERVO:
cur_item = 1;
break;
case DISPLAY_CONFIG:
cur_item = 1;
config_changed = false;
break;
}
display_state=new_state;
}
void DoKeyInput() {
int k;
k = Kpd_GetKeyAsync();
if (key == -1) { //only update key if it has been cleared
key = k;
}
if (key == 0) {
switch (display_state) {
case DISPLAY_SPLASH:
TransitionDisplay(DISPLAY_REACTOR);
break;
case DISPLAY_REACTOR:
TransitionDisplay(DISPLAY_MIXTURE);
break;
case DISPLAY_ENGINE:
TransitionDisplay(DISPLAY_REACTOR);
break;
case DISPLAY_MIXTURE:
TransitionDisplay(DISPLAY_PRESSURE_PID);
break;
case DISPLAY_PRESSURE_PID:
TransitionDisplay(DISPLAY_GRATE);
break;
case DISPLAY_GRATE:
if (engine_state == ENGINE_OFF) {
TransitionDisplay(DISPLAY_TESTING);
}
else {
TransitionDisplay(DISPLAY_REACTOR);
}
break;
case DISPLAY_TESTING:
if (engine_state == ENGINE_OFF){
TransitionDisplay(DISPLAY_SERVO);
} else {
TransitionDisplay(DISPLAY_REACTOR);
TransitionTesting(TESTING_OFF);
}
break;
case DISPLAY_SERVO:
WriteServo();
TransitionTesting(TESTING_OFF);
TransitionDisplay(DISPLAY_CONFIG); //assume that engine state is off because we are already in DISPLAY_SERVO
break;
case DISPLAY_CONFIG:
TransitionDisplay(DISPLAY_REACTOR);
break;
}
key = -1; //key caught
}
if (key == 1) {
if (display_state == DISPLAY_CONFIG and config_changed == true){
saveConfig(cur_item, config_var);
update_config_var(cur_item);
config_changed = false;
}
cur_item++;
//Serial.println("cur_item++");
if (cur_item>item_count) {
cur_item = 1;
}
key = -1; //key caught
}
}
void DoHeartBeat() {
if (millis() % 50 > 5) {
bitSet(PORTJ, 7);
}
else {
bitClear(PORTJ, 7);
}
//PORTJ ^= 0x80; // toggle the heartbeat LED
}
void TransitionMessage(String t_message) {
transition_message = t_message;
transition_entered = millis();
}
void GetFuelFeedStates(){ //CRBAGF
display_string = "";
//Conveyor
switch (conveyor_state) {
case CONVEYOR_OFF:
display_string += "-";
break;
case CONVEYOR_ON:
display_string += "+";
break;
case CONVEYOR_REVERSING:
display_string += "R";
break;
}
//Hopper Agitator
switch (hopper_agitator_state) {
case HOPPER_AGITATOR_OFF:
display_string += "-";
break;
case HOPPER_AGITATOR_ON_PULSE:
display_string += "+";
break;
case HOPPER_AGITATOR_ON_PAUSE:
display_string += "P";
break;
}
//Rotary Valve
switch (rotaryvalve_state) {
case ROTARYVALVE_OFF:
display_string += "-";
break;
case ROTARYVALVE_ON:
display_string += "+";
break;
case ROTARYVALVE_STARTING:
display_string += "S";
break;
case ROTARYVALVE_STOPPING:
display_string += "P";
break;
case ROTARYVALVE_OVERCURRENT:
display_string += "!";
break;
case ROTARYVALVE_REVERSING:
display_string += "<";
break;
}
//Boot
switch(boot_state){
case EMPTY:
display_string += "E";
break;
case MID:
display_string += "M";
break;
case FULL:
display_string += "F";
break;
case UNKNOWN:
display_string += "U";
break;
}
//Auger
switch(auger_state) {
case AUGER_STOPPED:
display_string += "-";
break;
case AUGER_ON:
display_string += "+";
break;
case AUGER_REVERSING:
display_string += "R";
break;
default:
display_string += " ";
break;
}
//Fuel Feed Switch
if (fuel_demand){
display_string += "E";
} else {
display_string += "F";
}
//Grate
if (grate_state == GRATE_ON){
display_string += "+";
} else {
display_string += "-";
}
//Ignitor
if (ignitor_on == true) {
display_string += "+";
} else {
display_string += "-";
}
display_string += " ";
}
void saveConfig(int item, int state){ //EEPROM: 0-499 for internal states, 500-999 for configurable states, 1000-4000 for data logging configurations.
int old_state = EEPROM.read(499+item);
if(state != old_state){
EEPROM.write(499+item, state);
delay(5); //ensure that value is not read until EERPROM has been fully written (~3.3ms)
}
}
int getConfig(int item){
int value;
value = int(EEPROM.read(499+item));
if (value == 255){ //values hasn't been saved yet to EEPROM, go with default value saved in defaults[]
value = defaults[item-1];
EEPROM.write(499+item, value);
}
config_changed = true;
return value;
}
void update_config_var(int var_num){
switch (var_num) {
case 1:
CANbus_speed = getConfig(1);
break;
case 2:
PR_LOW_boundary = getConfig(2)/100.0;
//float pRatioReactorLevelBoundary[3][2] = {{PR_HIGH_boundary, 1.0}, {PR_LOW_boundary, 0.6 }, {0.0, PR_LOW_boundary} };
//PR_HIGH = 0, PR_CORRECT = 1, PR_LOW = 2
pRatioReactorLevelBoundary[PR_CORRECT][0] = PR_LOW_boundary;
pRatioReactorLevelBoundary[PR_LOW][1] = PR_LOW_boundary;
break;
case 3:
PR_HIGH_boundary = getConfig(3)/100.0;
pRatioReactorLevelBoundary[PR_HIGH][0] = PR_HIGH_boundary;
break;
case 4:
PID_Control = getConfig(4);
InitMixture();
break;
}
}
void resetConfig() { //sets EEPROM configs back to untouched state...
int default_count = sizeof(defaults)/sizeof(int);
for (int i=0; i < default_count; i++){
EEPROM.write(500+i, defaults[i]);
}
}