diff --git a/RFM69.py b/RFM69.py index 5e52ee0..b839dee 100755 --- a/RFM69.py +++ b/RFM69.py @@ -206,6 +206,7 @@ def sendWithRetry(self, toAddress, buff = "", retries = 3, retryWaitTime = 10): sentTime = time.time() while (time.time() - sentTime) * 1000 < retryWaitTime: if self.ACKReceived(toAddress): + self.receiveBegin() return True return False @@ -295,6 +296,8 @@ def receiveBegin(self): self.setMode(RF69_MODE_RX) def receiveDone(self): + while self.intLock: + pass # wait for lock to be removed if (self.mode == RF69_MODE_RX or self.mode == RF69_MODE_STANDBY) and self.PAYLOADLEN > 0: self.setMode(RF69_MODE_STANDBY) return True @@ -303,10 +306,6 @@ def receiveDone(self): # Russss figured out that if you leave alone long enough it times out # tell it to stop being silly and listen for more packets self.writeReg(REG_PACKETCONFIG2, (self.readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART) - elif self.mode == RF69_MODE_RX: - # already in RX no payload yet - return False - self.receiveBegin() return False def readRSSI(self, forceTrigger = False): diff --git a/example.py b/example.py index c6e281c..4757e1f 100755 --- a/example.py +++ b/example.py @@ -23,12 +23,13 @@ if test.sendWithRetry(2, "blah", 3, 20): print "ack recieved" print "reading" +test.receiveBegin() while True: - test.receiveBegin() - while not test.receiveDone(): - time.sleep(.1) - print "%s from %s RSSI:%s" % ("".join([chr(letter) for letter in test.DATA]), test.SENDERID, test.RSSI) - if test.ACKRequested(): - test.sendACK() + if test.receiveDone(): + print "%s from %s RSSI:%s" % ("".join([chr(letter) for letter in test.DATA]), test.SENDERID, test.RSSI) + if test.ACKRequested(): + test.sendACK() + else: + test.receiveBegin() print "shutting down" test.shutdown()