jcw/jeelib — pull request #13 by CapnBry (2012-03-13 14:08:46+00:00)
Title: Transmit-only clients no longer have to enable receiver before enabling transmitter

Transmit-only clients, which wake sleep/rf12sleep mode to transmit data usually do something like this:

~~~
rf12_sleep(RF12_WAKEUP);
while (!rf12_canSend())
rf12_recvDone();
rf12_sendStart(...);
rf12_sendWait(...);
rf12_sleep(RF12_SLEEP);
~~~

When the RF12M wakes up, the first call to canSend returns false, because rxstate == TXIDLE, so recvDone is executed once. This first call enables the receiver. Because the receiver takes several ms to start up after a sleep, the second call to canSend will always return true. There just isn't long enough between the calls for any data to be received or the receiver to even become operational.

This patch looks completely unrelated but really what it does is removes the reliance on canSend completing successfully. When the RF returns from sleep, it is already in "RF_IDLE_MODE" and rxstate is already TXIDLE. The only thing canSend is doing is forcing rf12_grp to group, this can be eliminated by using group directly during CRC calculation and transmit. The RF12.cpp code size is the same, and transmit-only clients now may transmit directly without checking a receive. If you try this without this patch, it transmits a packet for group 0.

~~~
rf12_sleep(RF12_WAKEUP);
rf12_sendStart(...);
rf12_sendWait(...);
rf12_sleep(RF12_SLEEP);
~~~