Skip to content

Commit e1d280c

Browse files
committed
RadioLibWrappers.cpp: Improve readability of state macros
The STATE_* defines are meant to be used as enumerations, except for STATE_INT_READY which describes a single bit flag. Improve the name of the flag to make the difference clearer. While at it also make the enumeration use a continuous increment without gaps. Signed-off-by: Frieder Schrempf <frieder@fris.de>
1 parent f9250da commit e1d280c

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/helpers/radiolib/RadioLibWrappers.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
#define STATE_IDLE 0
66
#define STATE_RX 1
7-
#define STATE_TX_WAIT 3
8-
#define STATE_TX_DONE 4
9-
#define STATE_INT_READY 16
7+
#define STATE_TX_WAIT 2
8+
#define STATE_TX_DONE 3
9+
10+
#define FLAG_INT_READY (1 << 4)
1011

1112
#define NUM_NOISE_FLOOR_SAMPLES 64
1213
#define SAMPLING_THRESHOLD 14
@@ -21,7 +22,7 @@ static
2122
#endif
2223
void setFlag(void) {
2324
// we sent a packet, set the flag
24-
state |= STATE_INT_READY;
25+
state |= FLAG_INT_READY;
2526
}
2627

2728
void RadioLibWrapper::begin() {
@@ -59,7 +60,7 @@ void RadioLibWrapper::doResetAGC() {
5960

6061
void RadioLibWrapper::resetAGC() {
6162
// make sure we're not mid-receive of packet!
62-
if ((state & STATE_INT_READY) != 0 || isReceivingPacket()) return;
63+
if ((state & FLAG_INT_READY) != 0 || isReceivingPacket()) return;
6364

6465
doResetAGC();
6566
state = STATE_IDLE; // trigger a startReceive()
@@ -103,12 +104,12 @@ void RadioLibWrapper::startRecv() {
103104
}
104105

105106
bool RadioLibWrapper::isInRecvMode() const {
106-
return (state & ~STATE_INT_READY) == STATE_RX;
107+
return (state & ~FLAG_INT_READY) == STATE_RX;
107108
}
108109

109110
int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) {
110111
int len = 0;
111-
if (state & STATE_INT_READY) {
112+
if (state & FLAG_INT_READY) {
112113
len = _radio->getPacketLength();
113114
if (len > 0) {
114115
if (len > sz) { len = sz; }
@@ -154,7 +155,7 @@ bool RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) {
154155
}
155156

156157
bool RadioLibWrapper::isSendComplete() {
157-
if (state & STATE_INT_READY) {
158+
if (state & FLAG_INT_READY) {
158159
state = STATE_IDLE;
159160
n_sent++;
160161
return true;

0 commit comments

Comments
 (0)