Skip to content

Commit

Permalink
more review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Mar 6, 2024
1 parent 3fa016d commit 0f4c0ce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions examples/scanner/scanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void loop(void) {
if (Serial.peek() == '\r' || Serial.peek() == '\n') {
Serial.read();
} else { // got a charater that isn't a line feed
break; // handle it on nect loop() iteration
break; // handle it on next loop() iteration
}
}
}
Expand All @@ -185,10 +185,11 @@ void loop(void) {
// Listen for a little
radio.startListening();
delayMicroseconds(128);
bool foundSignal = radio.testRPD();
radio.stopListening();

// Did we get a signal?
if (radio.testRPD() || radio.available()) {
if (foundSignal || radio.testRPD() || radio.available()) {
++values[i];
radio.flush_rx(); // discard packets of noise
}
Expand Down
4 changes: 3 additions & 1 deletion examples_linux/ncurses/scanner_curses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const uint8_t CACHE_MAX = 5; // maximum depth of history for calculating pe
struct ChannelHistory
{
unsigned int total = 0; // the summary of signal counts for the channel
bool history[CACHE_MAX]; // a cache of history for the channel

/**
* Push new scan result for a channel into the history.
Expand All @@ -63,6 +62,9 @@ struct ChannelHistory
history[CACHE_MAX - 1] = value;
return sum;
}

private:
bool history[CACHE_MAX]; // a cache of history for the channel
};
ChannelHistory stored[MAX_CHANNELS];

Expand Down
1 change: 0 additions & 1 deletion examples_linux/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ int main(int argc, char** argv)
// Listen for a little
radio.startListening();
delayMicroseconds(130);
// for some reason, this flag is more accurate on Linux when still in RX mode.
bool foundSignal = radio.testRPD();
radio.stopListening();

Expand Down
14 changes: 7 additions & 7 deletions examples_linux/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
class ChannelHistory:
def __init__(self) -> None:
#: FIFO for tracking peak decays
self.history: List[bool] = [False] * CACHE_MAX
self._history: List[bool] = [False] * CACHE_MAX
#: for the total signal counts
self.total: int = 0

def push(self, value: bool) -> int:
"""Push a scan result's value into history while returning the sum of cached
signals found. This function also increments the total signal count accordingly.
"""
self.history = self.history[1:] + [value]
self._history = self._history[1:] + [value]
self.total += value
return self.history.count(True)
return self._history.count(True)


#: An array of histories for each channel
Expand Down Expand Up @@ -173,12 +173,12 @@ def scan_channel(channel: int) -> bool:
radio.channel = channel
radio.startListening()
time.sleep(0.00013)
result = radio.testRPD()
found_signal = radio.testRPD()
radio.stopListening()
result = result or radio.testRPD() or radio.available()
if result:
if found_signal or radio.testRPD() or radio.available():
radio.flush_rx()
return result
return True
return False


def main():
Expand Down

0 comments on commit 0f4c0ce

Please sign in to comment.