@@ -231,29 +231,32 @@ void ICACHE_RAM_ATTR ESPiLight::interruptHandler() {
231
231
232
232
if (pulseTrain.length == 0 ) {
233
233
const unsigned long now = micros ();
234
- const unsigned int duration = now - _lastChange;
235
-
236
- /* We first do some filtering (same as pilight BPF) */
237
- if (duration > minpulselen) {
238
- if (duration < maxpulselen) {
239
- /* All codes are buffered */
240
- codes[_nrpulses] = (uint16_t )duration;
241
- _nrpulses = (uint8_t )((_nrpulses + 1 ) % MAXPULSESTREAMLENGTH);
242
- /* Let's match footers */
243
- if (duration > mingaplen) {
244
- // Debug('g');
245
- /* Only match minimal length pulse streams */
246
- if (_nrpulses >= minrawlen && _nrpulses <= maxrawlen) {
247
- // Debug(_nrpulses);
248
- // Debug('l');
249
- pulseTrain.length = _nrpulses;
250
- _actualPulseTrain = (_actualPulseTrain + 1 ) % RECEIVER_BUFFER_SIZE;
234
+ if (now > _lastChange) { // prevent overflow after 70 minutes
235
+ const unsigned long duration = now - _lastChange;
236
+
237
+ /* We first do some filtering (same as pilight BPF) */
238
+ if (duration > minpulselen) {
239
+ if (duration < maxpulselen) {
240
+ /* All codes are buffered */
241
+ codes[_nrpulses] = (uint16_t )duration;
242
+ _nrpulses = (uint8_t )((_nrpulses + 1 ) % MAXPULSESTREAMLENGTH);
243
+ /* Let's match footers */
244
+ if (duration > mingaplen) {
245
+ // Debug('g');
246
+ /* Only match minimal length pulse streams */
247
+ if (_nrpulses >= minrawlen && _nrpulses <= maxrawlen) {
248
+ // Debug(_nrpulses);
249
+ // Debug('l');
250
+ pulseTrain.length = _nrpulses;
251
+ _actualPulseTrain =
252
+ (_actualPulseTrain + 1 ) % RECEIVER_BUFFER_SIZE;
253
+ }
254
+ _nrpulses = 0 ;
251
255
}
252
- _nrpulses = 0 ;
253
256
}
254
257
}
255
- _lastChange = now;
256
258
}
259
+ _lastChange = now;
257
260
} else {
258
261
Debug (" _!_" );
259
262
}
@@ -399,7 +402,8 @@ size_t ESPiLight::parsePulseTrain(uint16_t *pulses, uint8_t length) {
399
402
}
400
403
401
404
/* Reset # of repeats after a certain delay */
402
- if ((protocol->second - protocol->first ) > 500000 ) {
405
+ if (protocol->second < protocol->first ||
406
+ (protocol->second - protocol->first ) > 500000 ) {
403
407
protocol->repeats = 0 ;
404
408
}
405
409
@@ -417,6 +421,7 @@ size_t ESPiLight::parsePulseTrain(uint16_t *pulses, uint8_t length) {
417
421
}
418
422
}
419
423
pnode = pnode->next ;
424
+ yield ();
420
425
}
421
426
if (_rawCallback != nullptr ) {
422
427
(_rawCallback)(pulses, length);
0 commit comments