@@ -90,16 +90,31 @@ void EslovHandler::update()
90
90
uint8_t availableData = requestAvailableData ();
91
91
Serial.write (availableData);
92
92
93
- SensorLongDataPacket sensorData;
93
+ SensorDataPacket sensorData;
94
94
while (availableData) {
95
95
// delay(ESLOV_DELAY);
96
96
requestSensorData (sensorData);
97
97
delay (ESLOV_DELAY);
98
- if (sensorData.sensorId == 115 || sensorData.sensorId == 171 ) {
99
- Serial.write ((uint8_t *)&sensorData, sizeof (SensorLongDataPacket));
100
- } else {
101
- Serial.write ((uint8_t *)&sensorData, sizeof (SensorDataPacket));
102
- }
98
+ Serial.write ((uint8_t *)&sensorData, sizeof (SensorDataPacket));
99
+ availableData--;
100
+ }
101
+
102
+ _rxIndex = 0 ;
103
+
104
+ } else if (_rxBuffer[0 ] == HOST_READ_LONG_SENSOR_OPCODE) {
105
+
106
+ if (_debug) {
107
+ _debug->print (" received read sensor opcode\r\n " );
108
+ }
109
+ uint8_t availableData = requestAvailableLongData ();
110
+ Serial.write (availableData);
111
+
112
+ SensorLongDataPacket sensorData;
113
+ while (availableData) {
114
+ // delay(ESLOV_DELAY);
115
+ requestSensorLongData (sensorData);
116
+ delay (ESLOV_DELAY);
117
+ Serial.write ((uint8_t *)&sensorData, sizeof (SensorLongDataPacket));
103
118
availableData--;
104
119
}
105
120
@@ -218,23 +233,45 @@ uint8_t EslovHandler::requestAvailableData()
218
233
delay (ESLOV_DELAY);
219
234
}
220
235
221
- bool EslovHandler::requestSensorData (SensorLongDataPacket &sData )
236
+ uint8_t EslovHandler::requestAvailableLongData ()
237
+ {
238
+ writeStateChange (ESLOV_AVAILABLE_LONG_SENSOR_STATE);
239
+ while (!digitalRead (_eslovIntPin)) {}
240
+ uint8_t ret = Wire.requestFrom (ESLOV_DEFAULT_ADDRESS, 1 );
241
+ if (!ret) return 0 ;
242
+ return Wire.read ();
243
+ delay (ESLOV_DELAY);
244
+ }
245
+
246
+ bool EslovHandler::requestSensorData (SensorDataPacket &sData )
222
247
{
223
248
if (_eslovState != ESLOV_READ_SENSOR_STATE) {
224
249
writeStateChange (ESLOV_READ_SENSOR_STATE);
225
250
while (!digitalRead (_eslovIntPin)) {}
226
251
}
252
+ // uint8_t ret = Wire.requestFrom(ESLOV_DEFAULT_ADDRESS, sizeof(SensorDataPacket));
227
253
uint8_t ret = Wire.requestFrom (ESLOV_DEFAULT_ADDRESS, sizeof (SensorDataPacket));
228
254
if (!ret) return false ;
229
255
230
256
uint8_t *data = (uint8_t *)&sData ;
231
257
for (uint8_t i = 0 ; i < sizeof (SensorDataPacket); i++) {
232
258
data[i] = Wire.read ();
233
259
}
234
- if (data[0 ] == 115 || data[0 ] == 171 ) {
235
- for (uint8_t i = sizeof (SensorDataPacket); i < (sizeof (SensorLongDataPacket) - sizeof (SensorDataPacket)); i++) {
236
- data[i] = Wire.read ();
237
- }
260
+ return true ;
261
+ }
262
+
263
+ bool EslovHandler::requestSensorLongData (SensorLongDataPacket &sData )
264
+ {
265
+ if (_eslovState != ESLOV_READ_LONG_SENSOR_STATE) {
266
+ writeStateChange (ESLOV_READ_LONG_SENSOR_STATE);
267
+ while (!digitalRead (_eslovIntPin)) {}
268
+ }
269
+ uint8_t ret = Wire.requestFrom (ESLOV_DEFAULT_ADDRESS, sizeof (SensorLongDataPacket));
270
+ if (!ret) return false ;
271
+
272
+ uint8_t *data = (uint8_t *)&sData ;
273
+ for (uint8_t i = 0 ; i < sizeof (SensorLongDataPacket); i++) {
274
+ data[i] = Wire.read ();
238
275
}
239
276
return true ;
240
277
}
0 commit comments