-
Notifications
You must be signed in to change notification settings - Fork 5
/
SDCARD.ino
51 lines (48 loc) · 2.71 KB
/
SDCARD.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
#if defined(SDCARD)
void writeHeader() {
#ifdef LOGGING_FULL
file.print(F("INJ_OBD;INJ_HW;IGN;IAC;RPM;MAP;ECT;TPS;SPD;OXSENS;ASE;COLD;DET;OXf;Re-ENRICHMENT;STARTER;IDLE;A/C;NEUTRAL;Ex1;Ex2;AVG SPD;LPK_OBD;LPH_OBD;LPH_INJ;TOTAL_OBD;TOTAL_INJ;AVG_OBD;AVG_INJ"));
#else
file.print(F("INJ_OBD;INJ_HW;IGN;IAC;RPM;MAP;ECT;TPS;SPD;O2SENS;EXHAUST;AVG SPD;LPH_INJ;TOTAL_INJ;AVG_INJ;CURR_INJ;CURR_RUN;TOTAL_RUN;"));
#endif
file.println();
if (!file.sync() || file.getWriteError()) error("write error");
}
void logData() {
file.print(getOBDdata(OBD_INJ)); file.write(';'); file.print(float(INJ_TIME) / 1000); file.write(';'); file.print(getOBDdata(OBD_IGN)); file.write(';'); file.print(getOBDdata(OBD_IAC)); file.write(';');
file.print(getOBDdata(OBD_RPM)); file.write(';'); file.print(getOBDdata(OBD_MAP)); file.write(';'); file.print(getOBDdata(OBD_ECT)); file.write(';');
file.print(getOBDdata(OBD_TPS)); file.write(';'); file.print(getOBDdata(OBD_SPD)); file.write(';'); file.print(getOBDdata(OBD_OXSENS)); file.write(';'); file.print(getOBDdata(20)); file.write(';');
#ifdef LOGGING_FULL
file.print(getOBDdata(11)); file.write(';'); file.print(getOBDdata(12)); file.write(';'); file.print(getOBDdata(13)); file.write(';'); file.print(getOBDdata(14)); file.write(';');
file.print(getOBDdata(15)); file.write(';'); file.print(getOBDdata(16)); file.write(';'); file.print(getOBDdata(17)); file.write(';'); file.print(getOBDdata(18)); file.write(';');
file.print(getOBDdata(19)); file.write(';'); file.print(getOBDdata(20)); file.write(';'); file.print(getOBDdata(21)); file.write(';');
#endif
file.print(total_avg_speed); file.write(';'); //AVG_SPD ok
file.print(float(INJ_TIME) / 1000 * getOBDdata(OBD_RPM)*Ls * 0.18); file.write(';'); //LPH_INJ ok
file.print(total_consumption_inj); file.write(';'); //TOTAL_INJ ok
file.print(avg_consumption_inj); file.write(';'); //!AVG_INJ
file.print(current_consumption_inj); file.write(';'); //!CURR_INJ
file.print(current_run); file.write(';'); //CURR_RUN ok
file.print(total_run); file.write(';');//RUN_TOTAL ok
file.println();
if (!file.sync() || file.getWriteError()) error("write error");
}
void SDinit(){
if (!sd.begin(SS, SD_SCK_MHZ(50))) {
sd.initErrorHalt();
}
while (sd.exists(fileName)) {
if (fileName[BASE_NAME_SIZE + 1] != '9') {
fileName[BASE_NAME_SIZE + 1]++;
} else if (fileName[BASE_NAME_SIZE] != '9') {
fileName[BASE_NAME_SIZE + 1] = '0';
fileName[BASE_NAME_SIZE]++;
} else {
error("Can't create file name");
}
}
if (!file.open(fileName, O_CREAT | O_WRITE )) {
error("file.open");
}
}
#endif