-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvnt_lda.pde
2298 lines (2032 loc) · 72 KB
/
vnt_lda.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
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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// control struct
// tallennus eprom
// mapedit
// adaptation
// map upload ctrl seq !m8x8010203040506...!
// 2011-06-28 Servo is disabled because they do not last long, use N75 or similiar
// REMINDER TO MYSELF: this is the most recent version: /Users/dmn/Documents/Arduino/vnt_lda/vnt_lda.pde
#include <avr/pgmspace.h>
#include <EEPROM.h>
//#include <Servo.h>
/*
// oma vanha setuppi
#define PIN_BUTTON A5
#define PIN_HEARTBEAT 13
#define PIN_MAP A1
#define PIN_TPS A0
#define PIN_RPM_TRIGGER 2
#define PIN_VNT_N75 9
#define PIN_LDA_N75 8
#define PIN_TEMP1 A2
#define PIN_TEMP2 A3
#define PIN_OUTPUT1 7
#define PIN_OUTPUT2 10
#define PIN_LCD_RS 11 // white // PINK +5V // GRAY gnd
#define PIN_LCD_ENABLE 12 // red
#define PIN_LCD_D4 3 // BLUE
#define PIN_LCD_D5 4 // YELLOW
#define PIN_LCD_D6 5 // GREEN
#define PIN_LCD_D7 6 // BROWN
*/
// new defaults
#define PIN_BUTTON A5
#define PIN_HEARTBEAT 13
#define PIN_MAP A1
#define PIN_TPS A0
#define PIN_RPM_TRIGGER 2
#define PIN_VNT_N75 9
#define PIN_LDA_N75 8
#define PIN_TEMP1 A2
#define PIN_TEMP2 A3
#define PIN_OUTPUT1 7
#define PIN_OUTPUT2 10
#define PIN_LCD_RS 11 // white // PINK +5V // GRAY gnd
#define PIN_LCD_ENABLE 12 // red
#define PIN_LCD_D4 3 // BLUE
#define PIN_LCD_D5 4 // YELLOW
#define PIN_LCD_D6 5 // GREEN
#define PIN_LCD_D7 6 // BROWN
#include <LiquidCrystal.h>
LiquidCrystal lcd(PIN_LCD_RS, PIN_LCD_ENABLE, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7);
// Calculate avarage values
#define AVG_MAX 15
#define STATUS_IDLE 1
#define STATUS_CRUISING 2
//Servo servoVnt;
//Servo servoLda;
#define MAP_AXIS_RPM 0xDE
#define MAP_AXIS_TPS 0xAD
#define MAP_AXIS_CBAR 0xDD
#define MAP_AXIS_CELSIUS 0xAA
#define MAP_AXIS_VOLTAGE 0xAB
#define MAP_AXIS_DUTY_CYCLE 0xAC
#define MAP_AXIS_RAW 0x0
unsigned char vntActuatorPressureRequestMap[] = {
'M','2','D',
0x8,0x8,0xDE,0xAD,0xDD, // 01 - new version
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
85,85,85,85,85,85,85,85,
00,00,00, // lastX,lastY,lastRet
};
unsigned char vntActuatorPositionLimitMap[] = {
'M','2','D',
0x8,0x8,0xDE,0xAD,0xAC,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
00,00,00, // lastX,lastY,lastRet
};
unsigned char ldaPositionMap[] = {
'M','2','D',
0x8,0x8,0xDE,0xDD,0xAC,
0,0,0,0, 0,0,0,0,
32,32,32,32, 32,32,32,32,
64,64,64,64, 64,64,64,64,
128,128,128,128, 128,128,128,128,
192,192,192,192, 192,192,192,192,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
255,255,255,255, 255,255,255,255,
00,00,00, // lastX,lastY,lastRet
};
// R1 = 2400ohm, R2 = old style Bosch temp sensor
unsigned char tempMap[] = {
'M','1','D',
0x8,0x1,0xAB,0x00,0xAA,
// values at -64,-32,0,32, 64,96,128,160 °C
175+64,120+64,90+64,62+64,44+64,30+64,6+64,-55+64,
// 255,227,179,109,51,19,9,0, Calculated from bosch reference, does not seems to be accurate?
00,00,00, // lastX,lastY,lastRet
};
// Use slighly logaritmic output positions instead of plain linear
/*unsigned char vntActuatorMovementRemap[] = {
'M','1','D',
0x8,0x0,0xDE,0xAD,0x00,
0,2,8,20,50,90,180,255
};
*/
unsigned char vntActuatorMovementRemap[] = {
'M','1','D',
0x8,0x1,0x0,0x00,0x00,
0,0,10,20,90,140,190,255,
00,00,00,
// 0x8,0x0,0xDE,0xAD,0x00,
//0,10,50,110, 130,140,176,255 // Slight S-shape
// 0,0,4,13,32,110,130,255
//0,0,0,0,30,90,170,255
};
// Also used in NVRAM data store magic header
prog_uchar versionString[] PROGMEM = "DmnDslCtrl v1.4.";
prog_uchar statusString1[] PROGMEM = " Active view: ";
#define MODE_VANESOPENIDLE 1
#define MODE_DUTYCYCLEMAP 2
#define MODE_VNTOUTPUTINVERTED 4
#define MODE_LDAOUTPUTINVERTED 8
#define MAIN_LOOP_DELAY (1000/20) // ms
#define TEMP_HYSTERESIS 3
// used for RPM counting
volatile unsigned long rpmLastTeethSeenTime = 0;
volatile unsigned long rpmNow = 0;
// contains configurable data. Can be stored in eeprom
struct settingsStruct {
int tpsMin;
int tpsMax;
int mapMin;
int mapMax;
int rpmMax;
int rpmTeethsPerRotation;
unsigned char vntMinDC;
unsigned char vntMaxDC;
unsigned char ldaMinDC;
unsigned char ldaMaxDC;
unsigned char mode;
unsigned char inDamp;
unsigned char outDamp;
unsigned char servoStabilizerThreshold;
unsigned char servoStabilizerSmoothValue;
int output1EnableTemp;
int output2EnableTemp;
};
settingsStruct settings;
// contains calculated output data. calculated each run of mainloop
struct controlsStruct {
// inputs
volatile int tpsInput;
unsigned char tpsCorrected;
volatile int mapInput;
unsigned char mapCorrected;
// outputs
unsigned char ldaPosition;
unsigned char ldaPositionRemapped;
unsigned char vntTargetPressure;
unsigned char vntPosition;
unsigned char vntPositionRemapped;
unsigned char vntPositionTarget;
// calculated value
volatile int rpmActual;
volatile unsigned char rpmCorrected;
unsigned char statusBits;
//bool idling;
int temp1;
int temp2;
char output1Enabled;
char output2Enabled;
unsigned char clipPos;
};
controlsStruct controls;
struct avgStruct {
unsigned char pos;
unsigned char size;
volatile unsigned int avgData[AVG_MAX];
};
avgStruct tpsAvg;
avgStruct mapAvg;
char buffer[100]; // general purpose buffer, mainly used for string storage when printing from flash
unsigned long lastPacketTime;
prog_uchar mapVisualitionHelp[] PROGMEM = "Top Left is 0,0 (press: L - toggle live mode)";
unsigned char page=0;
char *pages[] = {
"About","Adaptation","Actuator Fine-tune","Edit: vntActuatorPressureRequestMap","Edit: vntActuatorPositionLimitMap","Edit: ldaPositionMap","Edit: temperatureMap","Edit: vntActuatorMovementRemap","Export data","Output Tests"};
unsigned char *editorMaps[]={vntActuatorPressureRequestMap,vntActuatorPositionLimitMap,ldaPositionMap,tempMap,vntActuatorMovementRemap};
unsigned char clearScreen[] = {
27,'[','2','J',27,'[','H'};
prog_uchar ANSIclearEolAndLf[] PROGMEM = {
27,'[','K','\r','\n',0};
prog_uchar ANSIgoHome[] PROGMEM = {
27,'[','1',';','1','H',0};
prog_uchar ANSIclearEos[] PROGMEM = {
27,'[','J',0};
void setPwmFrequency(int pin, int divisor) {
byte mode;
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch(divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 64: mode = 0x03; break;
case 256: mode = 0x04; break;
case 1024: mode = 0x05; break;
default: return;
}
if(pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
} else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
} else if(pin == 3 || pin == 11) {
switch(divisor) {
case 1: mode = 0x01; break;
case 8: mode = 0x02; break;
case 32: mode = 0x03; break;
case 64: mode = 0x04; break;
case 128: mode = 0x05; break;
case 256: mode = 0x06; break;
case 1024: mode = 0x7; break;
default: return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
void setup() {
digitalWrite(PIN_HEARTBEAT,HIGH);
lcd.begin(16, 2);
// Print a message to the LCD.
strcpy_P(buffer, (PGM_P)&versionString);
lcd.print(buffer);
lcd.setCursor(0, 1);
Serial.begin(115200);
// Serial.begin(19200);
Serial.print("Boot:");
pinMode(PIN_HEARTBEAT,OUTPUT); // DEBUG led
pinMode(PIN_BUTTON,INPUT); // Reset switch
digitalWrite(PIN_BUTTON, HIGH); // activate pull up resistor
digitalWrite(PIN_RPM_TRIGGER,HIGH); // pullup for honeywell
attachInterrupt(0, rpmTrigger, RISING); // or falling!
setPwmFrequency(9, 64); // was 1024
// setPwmFrequency(9, 32); // was 1024
pinMode(PIN_OUTPUT1,OUTPUT);
pinMode(PIN_OUTPUT2,OUTPUT);
// servoLda.attach(PIN_LDA_SERVO);
// servoVnt.attach(PIN_VNT_SERVO);
digitalWrite(PIN_LDA_N75,LOW);
digitalWrite(PIN_VNT_N75,LOW);
lcd.print("Load:");
Serial.print("OK, Load:");
if (loadFromEEPROM(false) == false) {
Serial.print("skipped.");
lcd.print("skipped.");
loadDefaults();
delay(2000);
}
else {
Serial.println("OK");
lcd.print("OK.");
// sweep at startup using fixed settings (temp enable 2.9.2011 to figure out stuck n75)
controls.ldaPositionRemapped = 255;
controls.vntPositionRemapped = 255;
updateOutputValues(true);
delay(300);
controls.ldaPositionRemapped = 0;
controls.vntPositionRemapped = 0;
updateOutputValues(true);
delay(300);
}
Serial.println("\r\n");
Serial.write(clearScreen,sizeof(clearScreen));
tpsAvg.size=AVG_MAX;
mapAvg.size=AVG_MAX;
digitalWrite(PIN_HEARTBEAT,LOW);
pageAbout(1); // force output
}
void loadDefaults() {
memset(&settings,0,sizeof(settingsStruct));
settings.tpsMax = 1023;
settings.mapMax = 1023;
settings.rpmTeethsPerRotation = 6;
settings.rpmMax = 6000;
settings.vntMinDC = 100;
settings.vntMaxDC = 110;
settings.ldaMinDC = 100;
settings.ldaMaxDC = 110;
settings.mode = 0;
settings.inDamp = 20;
settings.outDamp = 20;
settings.servoStabilizerThreshold=70;
settings.servoStabilizerSmoothValue=14;
settings.output1EnableTemp = 85;
settings.output2EnableTemp = 85;
}
unsigned char mapValues(int raw,int mapMin,int mapMax) {
if (raw < mapMin)
return 0;
if (raw >= mapMax)
return 0xff;
return map(raw,mapMin,mapMax,0,255);
}
unsigned char mapValuesSqueeze(int raw,int mapMin,int mapMax) {
return map(raw,0,255,mapMin,mapMax);
}
unsigned char mapInterpolate(unsigned char p1,unsigned char p2, unsigned char pos) {
return (p1*(100-pos)+p2*pos)/100;
}
unsigned char mapLookUp(unsigned char *mapData,unsigned char x,unsigned char y) {
unsigned char isInterpolated = *(mapData+2);
unsigned char tableSizeX = *(mapData+3);
unsigned char tableSizeY = *(mapData+4);
unsigned char yPos;
*(mapData+8+tableSizeX*tableSizeY) = x;
*(mapData+8+tableSizeX*tableSizeY+1) = y;
if (tableSizeY) {
yPos = y / (256/(tableSizeY-1));
}
else {
yPos = 0;
}
unsigned char xPos = (x / (256/(tableSizeX-1)));
int ofs = 8; // skip headers
unsigned char p1 = *(mapData+ofs+(yPos*tableSizeX)+xPos);
unsigned char p2 = *(mapData+ofs+(yPos*tableSizeX)+(((xPos+1)>=tableSizeX)?xPos:xPos+1));
;
unsigned char p3 = *(mapData+ofs+((((yPos+1)>=tableSizeX)?yPos:yPos+1)*tableSizeX)+xPos);
unsigned char p4 = *(mapData+ofs+((((yPos+1)>=tableSizeX)?yPos:yPos+1)*tableSizeX)+(((xPos+1)>=tableSizeX)?xPos:xPos+1));
unsigned char ret;
if (isInterpolated == 'D') {
int amountX = (x % (256/(tableSizeX-1)))*(10000/(256/(tableSizeX-1)));
if (tableSizeY) {
// 2D
int amountY = (y % (256/(tableSizeY-1)))*(10000/(256/(tableSizeY-1)));
char y1 = mapInterpolate(p1,p2,amountX /100);
char y2 = mapInterpolate(p3,p4,amountX /100);
ret = mapInterpolate(y1,y2,amountY /100);
}
else {
// 1D
ret = mapInterpolate(p1,p2,amountX /100);
}
}
else {
ret = p1;
}
*(mapData+8+tableSizeX*tableSizeY+2) = ret;
return ret;
}
char mapDebugCharValue(unsigned char c) {
if (c<5) {
return ' ';
}
else if (c<20) {
return '.';
}
else if (c<60) {
return ':';
}
else if (c<128) {
return '!';
}
else if (c<180) {
return 'o';
}
else if (c<220) {
return 'O';
}
else {
return '@';
}
}
// Fetches and print string from flash to preserve some ram!
void printFromFlash(prog_uchar *str) {
strcpy_P(buffer, (PGM_P)str);
Serial.print(buffer);
}
int EEPROMwriteData(int offset, byte *ptr,int size) {
int i;
for (i = 0; i < size; i++)
EEPROM.write(offset++, *(ptr++));
return i;
}
int EEPROMreadData(int offset, byte *ptr,int size) {
int i;
for (i = 0; i < size; i++)
*(ptr++) = EEPROM.read(offset++);
return i;
}
void saveToEEPROM() {
int ofs=0;
// write magic header
strcpy_P(buffer, (PGM_P)&versionString);
ofs += EEPROMwriteData(0,(byte*)&buffer,strlen(buffer));
// write control struct
ofs += EEPROMwriteData(ofs,(byte*)&settings,sizeof(settingsStruct));
ofs += EEPROMwriteData(ofs,(byte*)&vntActuatorPressureRequestMap,sizeof(vntActuatorPressureRequestMap));
ofs += EEPROMwriteData(ofs,(byte*)&vntActuatorPositionLimitMap,sizeof(vntActuatorPositionLimitMap));
ofs += EEPROMwriteData(ofs,(byte*)&vntActuatorMovementRemap,sizeof(vntActuatorMovementRemap));
ofs += EEPROMwriteData(ofs,(byte*)&tempMap,sizeof(tempMap));
ofs += EEPROMwriteData(ofs,(byte*)&ldaPositionMap,sizeof(ldaPositionMap));
Serial.print(ofs,DEC);
Serial.print("SAVED");
delay(1000);
}
bool loadFromEEPROM(bool force) {
int ofs;
// if reset pin is active, no not load anything from eeprom
if (digitalRead(PIN_BUTTON) == 0) {
Serial.print("PIN_BUTTON active..");
delay(2000);
return false;
}
// Check magic header to prevent data corruption of blank board or wrong version save file
if (!force) {
strcpy_P(buffer, (PGM_P)&versionString);
for (ofs=0;ofs<strlen(buffer);ofs++) {
if (EEPROM.read(ofs) != buffer[ofs])
return false;
}
}
ofs = strlen(buffer);
ofs += EEPROMreadData(ofs,(byte*)&settings,sizeof(settingsStruct));
ofs += EEPROMreadData(ofs,(byte*)&vntActuatorPressureRequestMap,sizeof(vntActuatorPressureRequestMap));
ofs += EEPROMreadData(ofs,(byte*)&vntActuatorPositionLimitMap,sizeof(vntActuatorPositionLimitMap));
ofs += EEPROMreadData(ofs,(byte*)&vntActuatorMovementRemap,sizeof(vntActuatorMovementRemap));
ofs += EEPROMreadData(ofs,(byte*)&tempMap,sizeof(tempMap));
ofs += EEPROMreadData(ofs,(byte*)&ldaPositionMap,sizeof(ldaPositionMap));
return true;
}
int toBars(int raw) {
return raw*1.18; // defaults for 3bar map
}
int toTemperature( int rawValue) {
int ret = mapLookUp(tempMap,rawValue,0);
return ret-64;
}
int toVoltage(int raw) {
// mVolt
return int(raw*19.608);
}
int toRpm(int raw) {
return round(((float)settings.rpmMax/255)*(float)raw);
}
int toTps(int raw) {
// percent
return int(raw/2.55);
}
void printIntWithPadding(int val,unsigned char width,char padChar) {
// print enough leading zeroes!
memset(buffer,padChar,30);
// append string presentation of number to end
itoa(val,buffer+30,10);
// print string with given width
Serial.print(buffer+30+strlen(buffer+30)-width);
}
void printStringWithPadding(prog_uchar *str,unsigned char width,char padChar) {
// print enough leading zeroes!
memset(buffer,padChar,30);
// append string presentation of number to end
strcpy_P(buffer+30, (PGM_P)str);
// print string with given width
Serial.print(buffer+30+strlen(buffer+30)-width);
}
void printPads(unsigned char n, char padChar) {
memset(buffer,padChar,n);
buffer[n] = 0;
Serial.print(buffer);
}
// User interface functions
void pageHeader() {
//Serial.write(clearScreen,sizeof(clearScreen));
printFromFlash(ANSIgoHome);
printFromFlash(versionString);
printFromFlash(statusString1);
Serial.print(pages[page]);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(ANSIclearEolAndLf);
}
// Stored in the 32kB FLASH
prog_uchar aboutString1[] PROGMEM = "(c) 2011 Juho Pesonen. Visit http://dmn.kuulalaakeri.org/vnt-lda/";
prog_uchar aboutString2[] PROGMEM = "Press: <space> to jump next view, or press ...";
prog_uchar aboutString3[] PROGMEM = "Questions? Or feedback? Send mail to [email protected]";
prog_uchar aboutString4[] PROGMEM = "To upload new maps, visit the site and use the editor to create table.";
prog_uchar aboutString5[] PROGMEM = "Then paste table data to this terminal window.";
void pageAbout(char key) {
if (key) {
// update only if key pressed
pageHeader();
printFromFlash(aboutString1);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(aboutString2);
printFromFlash(ANSIclearEolAndLf);
for (char i=0;i<10;i++) {
printPads(11,' ');
Serial.print("<");
Serial.print(i,DEC);
Serial.print("> ");
Serial.print(pages[i]);
printFromFlash(ANSIclearEolAndLf);
}
printFromFlash(ANSIclearEolAndLf);
printFromFlash(aboutString3);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(aboutString4);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(aboutString5);
printFromFlash(ANSIclearEos);
}
}
// TPS input: 200 Corrected: 0 (low:200, high:788);
prog_uchar statusRPM[] PROGMEM = "RPM actual:";
prog_uchar statusCorrected[] PROGMEM = " Corrected:";
prog_uchar statusTPSinput[] PROGMEM = "TPS input:";
prog_uchar statusLow[] PROGMEM = ":";
prog_uchar statusMAPinput[] PROGMEM = "MAP input:";
prog_uchar statusVNTactOutput[] PROGMEM = "VNT actuator output:";
prog_uchar statusLDAactOutput[] PROGMEM = "LDA actuator output:";
prog_uchar statusHeader[] PROGMEM = "Sensor values and adaptation map limits (l=live, y=save, p/P=load, R=reset)";
// 0123456789012345678901234567890123456789012345678901234567890123456789
prog_uchar statusTableHeader[] PROGMEM = " Raw val. Corr.val. Map min. Map max. Mode";
prog_uchar statusRowTPS[] PROGMEM = "TPS";
prog_uchar statusRowMAP[] PROGMEM = "MAP";
prog_uchar statusRowRPM[] PROGMEM = "RPM";
prog_uchar statusVNTtargetDutyCycle[] PROGMEM = "VNT target dc.";
prog_uchar statusVNTactualDutyCycle[] PROGMEM = "VNT duty cycle";
prog_uchar statusVNTactualTargetPress[] PROGMEM = "VNT target press.";
prog_uchar statusLDAdutyCycle[] PROGMEM = "LDA duty cycle";
prog_uchar statusVNTtableStyle[] PROGMEM = "Vnt Table mode";
prog_uchar statusBits[] PROGMEM = "statusBits";
// 0123456789012345678901234567890123456789012345678901234567890123456789
prog_uchar statusVNTtableStyleDC[] PROGMEM = "Duty cycle";
prog_uchar statusVNTtableStyleMAP[] PROGMEM = "Target press.";
prog_uchar statusOpenAtIdle[] PROGMEM = "VNT open@idle";
prog_uchar statusNone[] PROGMEM = "-";
prog_uchar statusSelected[] PROGMEM = "[X]";
prog_uchar statusUnSelected[] PROGMEM = "[ ]";
prog_uchar statusLDAOutputInverted[] PROGMEM = "LDA Output Inverted K ";
prog_uchar statusVNTOutputInverted[] PROGMEM = "VNT Output Inverted J ";
prog_uchar statusTemp1[] PROGMEM = "Temp#1: ";
prog_uchar statusTemp2[] PROGMEM = "Temp#2: ";
prog_uchar statusC[] PROGMEM = "°C";
prog_uchar statusOn[] PROGMEM = " (on) ";
prog_uchar statusOff[] PROGMEM = " (off) ";
prog_uchar statusFooter[] PROGMEM = "To change adaptation value, press the letter after value.";
prog_uchar statusFooter2[] PROGMEM = "For example: q = decrease 'Map Low' for TPS / Q increase 'Map Low' for TPS";
char oldKey;
bool isLive = true;
void pageStatusAndAdaption(char key) {
int x = 1;
if (oldKey == key)
x = 10;
switch (key) {
case 'l':
case 'L':
isLive=!isLive;
break;
case 'i':
if (settings.inDamp-x>0) settings.inDamp -= x;
break;
case 'I':
if (settings.inDamp+x<AVG_MAX) settings.inDamp += x;
break;
case 'o':
if (settings.outDamp-x>0) settings.outDamp -= x;
break;
case 'O':
if (settings.outDamp+x<AVG_MAX) settings.outDamp += x;
break;
case 'q':
if (settings.tpsMin-x>0) settings.tpsMin -= x;
break;
case 'Q':
if (settings.tpsMin+x<settings.tpsMax) settings.tpsMin += x;
break;
case 'w':
if (settings.tpsMax-x>settings.tpsMin) settings.tpsMax -= x;
break;
case 'W':
if (settings.tpsMax+x<1024) settings.tpsMax += x;
break;
case 'a':
if (settings.mapMin-x>0) settings.mapMin -= x;
break;
case 'A':
if (settings.mapMin+x<settings.mapMax) settings.mapMin += x;
break;
case 's':
if (settings.mapMax-x>settings.mapMin) settings.mapMax -= x;
break;
case 'S':
if (settings.mapMax+x<1024) settings.mapMax += x;
break;
case 'f':
if (settings.rpmTeethsPerRotation>1) settings.rpmTeethsPerRotation -= 1;
break;
case 'F':
if (settings.rpmTeethsPerRotation<99) settings.rpmTeethsPerRotation += 1;
break;
case 'd':
if (settings.rpmMax-100>1000) settings.rpmMax -= 100;
break;
case 'D':
if (settings.rpmMax+100<9999) settings.rpmMax += 100;
break;
case 'z':
if (settings.vntMinDC-x>=0) settings.vntMinDC -= x;
break;
case 'Z':
if (settings.vntMinDC+x<settings.vntMaxDC) settings.vntMinDC += x;
break;
case 'x':
if (settings.vntMaxDC-x>settings.vntMinDC) settings.vntMaxDC -= x;
break;
case 'X':
if (settings.vntMaxDC+x<256) settings.vntMaxDC += x;
break;
case 'g':
if (settings.ldaMinDC-x>=0) settings.ldaMinDC -= x;
break;
case 'G':
if (settings.ldaMinDC+x<settings.ldaMaxDC) settings.ldaMinDC += x;
break;
case 'h':
if (settings.ldaMaxDC-x>settings.ldaMinDC) settings.ldaMaxDC -= x;
break;
case 'H':
if (settings.ldaMaxDC+x<256) settings.ldaMaxDC += x;
break;
case 'c':
case 'C':
settings.mode = settings.mode ^ MODE_VANESOPENIDLE;
break;
case 'm':
case 'M':
settings.mode = settings.mode ^ MODE_DUTYCYCLEMAP;
break;
case 'k':
case 'K':
settings.mode = settings.mode ^ MODE_LDAOUTPUTINVERTED;
break;
case 'j':
case 'J':
settings.mode = settings.mode ^ MODE_VNTOUTPUTINVERTED;
break;
case 'y':
saveToEEPROM();
break;
case 'p':
loadFromEEPROM(0);
break;
case 'P':
loadFromEEPROM(1);
break;
case 'R':
loadDefaults();
break;
}
if (key) {
lastPacketTime = millis();
}
oldKey = key;
if (!key && !isLive)
return;
// update always if live
pageHeader();
printFromFlash(statusHeader);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(statusTableHeader);
printFromFlash(ANSIclearEolAndLf);
printStringWithPadding(statusRowTPS,19,' ');
printPads(1,' ');
printIntWithPadding(controls.tpsInput,4,'0'); // RAW
printPads(6,' ');
printIntWithPadding(controls.tpsCorrected,3,'0'); // Corr.
printPads(7,' ');
printIntWithPadding(settings.tpsMin,4,'0'); // Map low
printPads(1,' ');
Serial.print("Q");
printPads(4,' ');
printIntWithPadding(settings.tpsMax,4,'0'); // Map high
Serial.print(" W");
printFromFlash(ANSIclearEolAndLf);
printStringWithPadding(statusRowMAP,19,' ');
printPads(1,' ');
printIntWithPadding(controls.mapInput,4,'0'); // RAW
printPads(6,' ');
printIntWithPadding(controls.mapCorrected,3,'0'); // Corr.
printPads(7,' ');
printIntWithPadding(settings.mapMin,4,'0'); // Map low
printPads(1,' ');
Serial.print("A");
printPads(4,' ');
printIntWithPadding(settings.mapMax,4,'0'); // Map high
Serial.print(" S");
printFromFlash(ANSIclearEolAndLf);
printStringWithPadding(statusRowRPM,19,' ');
printPads(1,' ');
printIntWithPadding(controls.rpmActual,4,'0'); // RAW
printPads(6,' ');
printIntWithPadding(controls.rpmCorrected,3,'0'); // Corrected
printPads(17,' ');
printIntWithPadding(settings.rpmMax,4,'0');
Serial.print(" D");
printPads(4,' ');
Serial.print("No.teeths=");
printIntWithPadding(settings.rpmTeethsPerRotation,2,'0');
Serial.print(" F");
printFromFlash(ANSIclearEolAndLf);
if (settings.mode & MODE_DUTYCYCLEMAP) {
printStringWithPadding(statusVNTactualDutyCycle,19,' ');
}
else {
printStringWithPadding(statusVNTactualTargetPress,19,' ');
}
printPads(1,' ');
printIntWithPadding(controls.vntTargetPressure,3,'0'); // target
printPads(7,' ');
printIntWithPadding(controls.vntPosition,3,'0'); // actual
Serial.print("/");
printIntWithPadding(controls.vntPositionRemapped,3,'0');
printPads(3,' ');
printIntWithPadding(settings.vntMinDC,3,'0');
Serial.print(" Z");
printPads(5,' ');
printIntWithPadding(settings.vntMaxDC,3,'0');
Serial.print(" X");
printPads(5,' ');
if (settings.mode & MODE_VANESOPENIDLE) {
printFromFlash(statusOpenAtIdle);
}
else {
printFromFlash(statusNone);
}
Serial.print(" C");
printFromFlash(ANSIclearEolAndLf);
printStringWithPadding(statusLDAdutyCycle,19,' ');
printPads(1,' ');
printIntWithPadding(controls.ldaPosition,3,'0'); // RAW
printPads(10,' ');
Serial.print("/");
printIntWithPadding(controls.ldaPositionRemapped,3,'0');
printPads(3,' ');
printIntWithPadding(settings.ldaMinDC,3,'0');
Serial.print(" G");
printPads(5,' ');
printIntWithPadding(settings.ldaMaxDC,3,'0');
Serial.print(" H");
printFromFlash(ANSIclearEolAndLf);
printStringWithPadding(statusVNTtableStyle,19,' ');
printPads(41,' ');
/*printIntWithPadding(settings.vntOpeningPressureThreshold,3,'0');
Serial.print(" B");
// printPads(15,' ');
Serial.print(" Id");
printPads(1,' ');
printIntWithPadding(settings.inDamp,3,'0');
Serial.print(" Od");
printPads(1,' ');
printIntWithPadding(settings.outDamp,3,'0');
*/
if (settings.mode & MODE_DUTYCYCLEMAP) {
printFromFlash(statusVNTtableStyleDC);
}
else {
printFromFlash(statusVNTtableStyleMAP);
}
Serial.print(" M");
printFromFlash(ANSIclearEolAndLf);
printStringWithPadding(statusBits,19,' ');
printPads(3,' ');
printIntWithPadding(controls.statusBits,1,'0');
printFromFlash(ANSIclearEolAndLf);
printFromFlash(ANSIclearEolAndLf);
printPads(20,' ');
if (settings.mode & MODE_VNTOUTPUTINVERTED) {
printFromFlash(statusSelected);
}
else {
printFromFlash(statusUnSelected);
}
printFromFlash(statusVNTOutputInverted);
if (settings.mode & MODE_LDAOUTPUTINVERTED) {
printFromFlash(statusSelected);
}
else {
printFromFlash(statusUnSelected);
}
printFromFlash(statusLDAOutputInverted);
printFromFlash(ANSIclearEolAndLf);
printPads(20,' ');
printFromFlash(statusTemp1);
printIntWithPadding(controls.temp1,4,' ');
printFromFlash(statusC);
if (controls.output1Enabled) {
printFromFlash(statusOn);
} else {
printFromFlash(statusOff);
}
printFromFlash(statusTemp2);
printIntWithPadding(controls.temp2,4,' ');
printFromFlash(statusC);
if (controls.output2Enabled) {
printFromFlash(statusOn);
} else {
printFromFlash(statusOff);
}
printFromFlash(ANSIclearEolAndLf);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(statusFooter);
printFromFlash(ANSIclearEolAndLf);
printFromFlash(statusFooter2);
printFromFlash(ANSIclearEos);
}
void pagePreferences(char key) {
}
void pageLdaMapVisual(char key) {
switch (key) {
case 'l':
case 'L':
isLive=!isLive;
break;
}
if (!key && !isLive)
return;
pageHeader();
printFromFlash(mapVisualitionHelp);
printFromFlash(ANSIclearEolAndLf);
unsigned char tableSizeX = *(vntActuatorPressureRequestMap+3);
unsigned char tableSizeY = *(vntActuatorPressureRequestMap+4);
Serial.print(tableSizeX,DEC);
Serial.print("x");
Serial.print(tableSizeY,DEC);
printFromFlash(ANSIclearEolAndLf);
int x,y;
for (y=0;y<256;y=y+16) {
for (x=0;x<256;x=x+4) {
if (controls.mapCorrected >= y && controls.mapCorrected < y+16 && controls.rpmCorrected >=x && controls.rpmCorrected <x+4) {
Serial.write('O');
}
else {
Serial.write(mapDebugCharValue(mapLookUp(ldaPositionMap,x,y)));
}
}
if (controls.mapCorrected >= y && controls.mapCorrected < y+16)
Serial.print("<< ");
printFromFlash(ANSIclearEolAndLf);
}
for (x=0;x<256;x=x+4) {
if (controls.rpmCorrected>=x && controls.rpmCorrected<x+4) {
Serial.print("^");
continue;
}
else {
Serial.print(" ");
}
}
printFromFlash(ANSIclearEolAndLf);
}
void pageVntMapVisual(char key) {