Skip to content

Commit 5864442

Browse files
committed
Only wait before sending if in first verification state (fixes pimatic/homeduino#16)
1 parent e92aa59 commit 5864442

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

RFControl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,30 +493,30 @@ void listenBeforeTalk()
493493
// listen before talk
494494
unsigned long waited = 0;
495495
if(interruptPin != -1) {
496-
while(state != STATUS_WAITING && state != STATUS_RECORDING_END && state != STATUS_RECORDING_0) {
496+
while(state > STATUS_RECORDING_0 && state != STATUS_RECORDING_END) {
497497
//wait till no rf message is in the air
498-
waited += 10;
499-
delayMicroseconds(10000);
498+
waited += 5;
499+
delayMicroseconds(3); // 5 - some micros for other stuff
500500
// don't wait longer than 5sec
501-
if(waited > 5000) {
501+
if(waited > 5000000) {
502502
break;
503503
}
504504
// some delay between the message in air and the new message send
505-
if(state == STATUS_WAITING || state == STATUS_RECORDING_END) {
506-
waited += 100;
507-
// INT_MAX < 100000 => do two calls
508-
delayMicroseconds(50000);
509-
delayMicroseconds(50000);
505+
// there could be additional repeats following so wait some more time
506+
if(state <= STATUS_RECORDING_0 || state == STATUS_RECORDING_END) {
507+
waited += 1000000;
508+
delay(1000);
510509
}
511510
}
512-
513511
// stop receiving while sending, this method preserves the recording state
514512
detachInterrupt(interruptPin);
515513
}
516514
// this prevents loosing the data in the receiving buffer, after sending
517515
if(data1_ready || data2_ready) {
518516
state = STATUS_RECORDING_END;
519517
}
518+
// Serial.print(waited);
519+
// Serial.print(" ");
520520
}
521521

522522
void afterTalk()

0 commit comments

Comments
 (0)