@@ -10,6 +10,17 @@ static char rxIdx; //Indice del buffer de recepcion
10
10
static bool autosend ;
11
11
static uint16_t pm25 ;
12
12
static uint16_t pm10 ;
13
+ static comandoEnviar_t ultimoComandoEnviado ;
14
+
15
+ typedef enum {
16
+ ReadMeasure ,
17
+ StartMeasure ,
18
+ StopMeasure ,
19
+ EnableAutosend ,
20
+ DisableAutosend
21
+
22
+ }comandoEnviar_t ;
23
+
13
24
14
25
static void enviaOrden (char * const orden , char largo );
15
26
@@ -31,26 +42,32 @@ void hpmChangeAutosend (bool enable) {
31
42
}
32
43
33
44
void hpmSendReadMeasure (void ) {
45
+ ultimoComandoEnviado = ReadMeasure ;
34
46
const char orden [] = {0x68 ,0x01 ,0x04 ,0x93 };
35
47
enviaOrden (orden ,4 );
36
48
}
37
49
38
50
void hpmSendStartMeasure (void ) {
51
+ ultimoComandoEnviado = StartMeasure ;
39
52
const char orden [] = {0x68 ,0x01 ,0x01 ,0x96 };
40
53
enviaOrden (orden ,4 );
54
+
41
55
}
42
56
43
57
void hpmSendStopMeasure (void ) {
58
+ ultimoComandoEnviado = StopMeasure ;
44
59
const char orden [] = {0x68 ,0x01 ,0x02 ,0x95 };
45
60
enviaOrden (orden ,4 );
46
61
}
47
62
48
63
void hpmSendEnableAutoSend (void ) {
64
+ ultimoComandoEnviado = EnableAutosend ;
49
65
const char orden [] = {0x68 ,0x01 ,0x40 ,0x57 };
50
66
enviaOrden (orden ,4 );
51
67
}
52
68
53
69
void hpmSendDisableAutoSend (void ) {
70
+ ultimoComandoEnviado = DisableAutosend ;
54
71
const char orden [] = {0x68 ,0x01 ,0x20 ,0x77 };
55
72
enviaOrden (orden ,4 );
56
73
}
@@ -68,11 +85,11 @@ uint16_t getLastPM25 (void)
68
85
/*
69
86
//Quizas no sea necesario este bloque de codigo, teniendo en cuenta la descripcion
70
87
//de la funcion HPMinput() - TODO: Eliminar este comentario, de ser necesario
71
- if (modo == true){
88
+ if (autosend == true){
72
89
pm25=(carga[6]<<8)+carga[7];
73
90
}
74
91
else{
75
- ReadMeasure ();
92
+ hpmSendReadMeasure ();
76
93
pm25=(carga[3]<<8)+carga[4];
77
94
}
78
95
// */
@@ -84,17 +101,17 @@ uint16_t getLastPM10(void)
84
101
/*
85
102
//Quizas no sea necesario este bloque de codigo, teniendo en cuenta la descripcion
86
103
//de la funcion HPMinput() - TODO: Eliminar este comentario, de ser necesario
87
- if (modo == true){
104
+ if (autosend == true){
88
105
pm10=(carga[8]<<8)+carga[9];
89
106
}
90
107
else{
91
- ReadMeasure ();
108
+ hpmSendReadMeasure ();
92
109
pm10=(carga[5]<<8)+carga[6];
93
110
}
94
111
// */
95
112
return pm10 ;
96
113
}
97
-
114
+ /*
98
115
void HPMinput(char octeto) {
99
116
if (rxIdx < RXBUFLEN) {
100
117
rxBuffer[rxIdx++] = octeto;
@@ -106,15 +123,52 @@ void HPMinput(char octeto) {
106
123
* al comienzo del codigo. Y es en este bloque de codigo que ese "updated"
107
124
* se ha de actualizar. Idealmente, se habria de poner a true, cuando
108
125
* ya se tengan los octetos suficientes segun el modo y/u orden enviada.
109
- */
126
+
110
127
if (autosend) {
111
- //TODO: Procesamiento segun Tabla 5 del Datasheet
128
+ /*TODO: Procesamiento segun Tabla 5 del Datasheet
129
+
130
+
112
131
} else {
113
- //TODO: Procesamiento segun Tabla 4 del Datasheet
132
+ /*TODO: Procesamiento segun Tabla 4 del Datasheet
133
+
134
+
114
135
}
115
136
}
116
137
}
138
+ */
117
139
140
+ void HPMinput (char octeto ) {
141
+ if (rxIdx < RXBUFLEN ) {
142
+ rxBuffer [rxIdx ++ ] = octeto ;
143
+ if (autosend ) {
144
+ if (rxIdx == RXBUFLEN ){
145
+ rxBuffer [rxIdx ++ ]= octeto ;
146
+ pm10 = (rxBuffer [8 ]<<8 )+ rxBuffer [9 ];
147
+ pm25 = (rxBuffer [6 ]<<8 )+ rxBuffer [7 ];
148
+ rxIdx = 0 ;
149
+
150
+ }else {
151
+ switch (ultimoComandoEnviado ){
152
+ case ReadMeasure :
153
+ if (rxIdx == RXBUFLEN ){
154
+ rxBuffer [rxIdx ++ ]= octeto ;
155
+ pm10 = (rxBuffer [5 ]<<8 )+ rxBuffer [6 ];
156
+ pm25 = (rxBuffer [3 ]<<8 )+ rxBuffer [4 ];
157
+ rxIdx = 0 ;
158
+ break ;
159
+
160
+ }
161
+
162
+ }
163
+
164
+ }
165
+ /*TODO: Procesamiento segun Tabla 5 del Datasheet*/
166
+
167
+
168
+ }
169
+ }
170
+ }
171
+
118
172
void enviaOrden (char * const orden , char largo ) {
119
173
handlerEnvio (orden ,largo );
120
174
rxIdx = 0 ;
0 commit comments