forked from Churrosoft/OpenEFI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.cpp
More file actions
91 lines (84 loc) · 2.08 KB
/
Memory.cpp
File metadata and controls
91 lines (84 loc) · 2.08 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
#include "Memory.h"
#include "AT24CX.h"
//Libreria de memoria i2c : https://github.com/cyberp/AT24Cx
AT24C32 mem;
#define col 11
#define fil 18
#define DTCAddress 2500
Memory::Memory(int p){
}
void Memory::Actualizar(int val, int x, int y){
pos = x * 2 + y * 2; //teoricamente aca tendria que estar el lugar donde voy a guardar
mem.writeInt(pos,val);
}
int Memory::GetVal(byte tabla, byte x, byte y){
switch (tabla) {
case 0: //Avance
pos = 0;
break;
case 1: //Tiempo de inyeccion base
pos = col * 2 + fil * 2;
break;
case 2://Eficiencia Volumetrica (VE)
pos = (col * 2 + fil * 2) * 2;
break;
case 3: //Correccion por temperatura(inyeccion)
pos = (col * 2 + fil * 2) * 3;
break;
case 4: //Correccion por temperatura (encendido) o Correccion por voltaje inyecccion
pos = (col * 2 + fil * 2) * 4;
break;
}
pos += 11 * y;
pos += x;
return mem.readInt(pos);
}
void Memory::Leer(int **tabla, int tipo){
//voy a guardar todos los datos de la tabla de corrido, asi que, primero grabo datos desde [0][0],
//hasta [0][11] y luego repito con las demas filas
switch (tipo){
case 0: //Avance
pos = 0;
break;
case 1: //Tiempo de inyeccion base
pos = col * 2 + fil * 2;
break;
case 2://Eficiencia Volumetrica (VE)
pos = (col * 2 + fil * 2) * 2;
break;
case 3: //Correccion por temperatura(inyeccion)
pos = (col * 2 + fil * 2) * 3;
break;
case 4: //Correccion por temperatura (encendido) o Correccion por voltaje inyecccion
pos = (col * 2 + fil * 2) * 4;
break;
}
for (i = 0; i <= fil; i++ ) {
for (i2 = 0; i2 <= col; i++) {
tabla[i][i2] = mem.readInt(pos);
pos += 2;
}
}
pos = 0;
}
int * Memory::GetDTC(){
pos = DTCAddress;
int *DTC = malloc(12);
for (i = 0; i <= 12; i++) {
DTC[i] = mem.readInt(pos);
pos += 2;
}
return DTC;
}
void Memory::SetDTC(int code){
//este void guarda un DTC nuevo en la memoria
bool grabado = false;
byte posAUX = 0;
do{
if( mem.readInt( DTCAddress + posAUX) == 0 ) {
mem.writeInt( DTCAddress + posAUX, code );
grabado = true;
}
else { posAUX += 2; }
}while( grabado != true || posAUX <= DTCAddress + 24 );
}