@@ -159,6 +159,9 @@ bool VS1::write(const Datapoint& datapoint, const uint8_t* data, uint8_t length)
159
159
160
160
bool VS1::begin () {
161
161
if (_interface->begin ()) {
162
+ while (_interface->available ()) {
163
+ _interface->read (); // clear rx buffer
164
+ }
162
165
_setState (State::INIT);
163
166
return true ;
164
167
}
@@ -188,7 +191,8 @@ void VS1::loop() {
188
191
break ;
189
192
}
190
193
// double timeout to accomodate for connection initialization
191
- if (_currentDatapoint && _currentMillis - _requestTime > 4000UL ) {
194
+ if (_currentDatapoint && _currentMillis - _requestTime > 5000UL ) {
195
+ _bytesTransferred = 0 ;
192
196
_setState (State::INIT);
193
197
_tryOnError (OptolinkResult::TIMEOUT);
194
198
}
@@ -226,6 +230,7 @@ void VS1::_syncEnq() {
226
230
if (_currentMillis - _lastMillis < 50 ) {
227
231
if (_currentDatapoint && _interface->write (&VitoWiFiInternals::ProtocolBytes.ENQ_ACK , 1 ) == 1 ) {
228
232
_setState (State::SEND);
233
+ _send (); // speed up things
229
234
}
230
235
} else {
231
236
_setState (State::INIT);
@@ -262,7 +267,7 @@ void VS1::_receive() {
262
267
++_bytesTransferred;
263
268
_lastMillis = _currentMillis;
264
269
}
265
- if (_bytesTransferred == _currentRequest .length ()) {
270
+ if (_bytesTransferred == _currentDatapoint .length ()) {
266
271
_bytesTransferred = 0 ;
267
272
_setState (State::SYNC_RECV);
268
273
_tryOnResponse ();
@@ -271,7 +276,7 @@ void VS1::_receive() {
271
276
272
277
void VS1::_tryOnResponse () {
273
278
if (_onResponseCallback) {
274
- _onResponseCallback (_responseBuffer, _currentRequest .length (), _currentDatapoint);
279
+ _onResponseCallback (_responseBuffer, _currentDatapoint .length (), _currentDatapoint);
275
280
}
276
281
_currentDatapoint = Datapoint (nullptr , 0 , 0 , noconv);
277
282
}
0 commit comments