Skip to content

Commit 3da148e

Browse files
Bump the rf24-submodules group with 2 updates (#100)
* Bump the rf24-submodules group with 2 updates Bumps the rf24-submodules group with 2 updates: [RF24](https://github.com/nRF24/RF24) and [RF24Network](https://github.com/nRF24/RF24Network). Updates `RF24` from `ce9bbb8` to `6f3da43` - [Release notes](https://github.com/nRF24/RF24/releases) - [Commits](nRF24/RF24@ce9bbb8...6f3da43) Updates `RF24Network` from `551461f` to `731a368` - [Release notes](https://github.com/nRF24/RF24Network/releases) - [Commits](nRF24/RF24Network@551461f...731a368) --- updated-dependencies: - dependency-name: RF24 dependency-type: direct:production dependency-group: rf24-submodules - dependency-name: RF24Network dependency-type: direct:production dependency-group: rf24-submodules ... Signed-off-by: dependabot[bot] <[email protected]> * add new enum about FIFO state Includes various typing fixes and spelling corrections in examples. Updated docs with deprecation admonitions about deprecated parameters. Renamed requirements-build.txt as these dependencies are only needed to build the package and are already specified in pyproject.toml. * use `ruff format --check` in CI --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Brendan <[email protected]>
1 parent 5d946da commit 3da148e

17 files changed

+106
-48
lines changed

.github/workflows/build.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
# cmake ships with the ubuntu-latest runner
2727
run: |
2828
sudo apt-get install python3-dev
29-
python3 -m pip install -r docs/requirements.txt -r requirements.txt -r requirements-dev.txt
29+
python3 -m pip install -r docs/requirements.txt -r requirements-build.txt -r requirements-dev.txt
3030
3131
- name: Run cpp-linter as a py pkg
3232
env:
@@ -51,7 +51,7 @@ jobs:
5151
- name: Build package for docs extraction and linting examples
5252
run: |
5353
python -m pip install build
54-
python -m build
54+
python -m build
5555
python -m pip install dist/pyrf24-*.whl
5656
5757
- name: check python typing
@@ -61,7 +61,7 @@ jobs:
6161
run: ruff check examples/*.py src/pyrf24/*.py* setup.py docs/conf.py
6262

6363
- name: format python sources
64-
run: ruff format examples/*.py src/pyrf24/*.py* setup.py docs/conf.py
64+
run: ruff format --check examples/*.py src/pyrf24/*.py* setup.py docs/conf.py
6565

6666
- name: Get doc dependencies
6767
run: |-

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
sudo apt install python3-dev
3333
python3 -m pip install --upgrade pip
34-
python3 -m pip install -r requirements.txt
34+
python3 -m pip install -r requirements-build.txt
3535
3636
- name: Set up QEMU
3737
if: matrix.platform != 'native'

.readthedocs.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ python:
2727
- method: pip
2828
path: .
2929
- requirements: docs/requirements.txt
30-
- requirements: requirements.txt

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ Building a somewhat portable binary distribution for python packages involves bu
129129
.whl file known as a wheel. This wheel can be used to install the pyrf24 package on systems using the
130130
same version of CPython, CPU architecture, and C standard lib.
131131

132-
1. Because building wheels is not done in an isolated build environment, it is advised that
132+
1. If building wheels is not done in an isolated build environment, it is advised that
133133
some build-time dependencies be installed manually to ensure up-to-date stable releases are used.
134134
Execute the following from the root directory of this repo:
135135

136136
.. code-block:: bash
137137
138-
python -m pip install -r requirements.txt
138+
python -m pip install -r requirements-build.txt
139139
140140
.. note::
141141
This step only needs to be done once.

docs/rf24_api.rst

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Enum classes
3030
.. autoclass:: pyrf24.rf24_pa_dbm_e
3131
:members: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
3232

33+
.. autoclass:: pyrf24.rf24_fifo_state_e
34+
:members: RF24_FIFO_OCCUPIED, RF24_FIFO_EMPTY, RF24_FIFO_FULL, RF24_FIFO_INVALID
35+
3336
RF24 class
3437
----------
3538

examples/acknowledgement_payloads.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def master(count: int = 5): # count = 5 will only transmit 5 packets
8888
)
8989
if radio.available():
9090
# print the received ACK that was automatically sent
91-
result = radio.read(radio.get_dynamic_payload_size())
92-
print(f" Received: {result[:6].decode('utf-8')}{result[7:8][0]}")
91+
payload = radio.read(radio.get_dynamic_payload_size())
92+
print(f" Received: {payload[:6].decode('utf-8')}{payload[7:8][0]}")
9393
counter[0] += 1 # increment payload counter
9494
else:
9595
print(" Received an empty ACK packet")

examples/fake_ble_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def master(count=50):
9393

9494
# create an object for manipulating temperature measurements
9595
temperature_service = TemperatureServiceData()
96-
# temperature's float data has up to 2 decimal places of percision
96+
# temperature's float data has up to 2 decimal places of precision
9797
temperature_service.data = 42.0
9898

9999

examples/interrupt_configure.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"""
77

88
import time
9-
from pyrf24 import RF24, RF24_PA_LOW, RF24_DRIVER
9+
from pyrf24 import RF24, RF24_PA_LOW, RF24_DRIVER, RF24_FIFO_FULL
1010

1111
try:
12-
import gpiod
13-
from gpiod.line import Edge
12+
import gpiod # type: ignore[import-untyped]
13+
from gpiod.line import Edge # type: ignore[import-untyped]
1414
except ImportError as exc:
1515
raise ImportError(
1616
"This script requires gpiod installed for observing the IRQ pin. Please run\n"
@@ -192,8 +192,8 @@ def slave(timeout=6): # will listen for 6 seconds before timing out
192192
radio.write_ack_payload(1, ack_payloads[1])
193193
radio.write_ack_payload(1, ack_payloads[2])
194194
radio.listen = True # start listening & clear irq_dr flag
195-
start_timer = time.monotonic() # start timer now
196-
while not radio.is_fifo(False, False) and time.monotonic() - start_timer < timeout:
195+
end_time = time.monotonic() + timeout # start timer now
196+
while radio.is_fifo(False) != RF24_FIFO_FULL and time.monotonic() < end_time:
197197
# if RX FIFO is not full and timeout is not reached, then keep waiting
198198
pass
199199
time.sleep(0.5) # wait for last ACK payload to transmit

examples/multiceiver_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def master(node_number: int = 0, count: int = 6):
8585
if report:
8686
print(
8787
f"Transmission of payloadID {counter} as node {node_number}",
88-
f"successfull! Transmission time: {(end_timer - start_timer) / 1000}",
88+
f"successful! Transmission time: {(end_timer - start_timer) / 1000}",
8989
"us",
9090
)
9191
else:

examples/scanner.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"""
88

99
import time
10-
from pyrf24 import RF24, RF24_CRC_DISABLED, address_repr, RF24_DRIVER
10+
from typing import Optional
11+
from pyrf24 import RF24, RF24_CRC_DISABLED, address_repr, RF24_DRIVER, RF24_FIFO_EMPTY
1112

1213
print(__file__) # print example name
1314

@@ -70,13 +71,13 @@ def scan(timeout: int = 30):
7071
signals = [0] * 126 # store the signal count for each channel
7172
sweeps = 0 # keep track of the number of sweeps made through all channels
7273
curr_channel = 0
73-
start_timer = time.monotonic() # start the timer
74-
while time.monotonic() - start_timer < timeout:
74+
end_time = time.monotonic() + timeout # start the timer
75+
while time.monotonic() < end_time:
7576
radio.channel = curr_channel
76-
radio.listen = 1 # start a RX session
77+
radio.listen = True # start a RX session
7778
time.sleep(0.00013) # wait 130 microseconds
7879
found_signal = radio.rpd
79-
radio.listen = 0 # end the RX session
80+
radio.listen = False # end the RX session
8081
found_signal = found_signal or radio.rpd or radio.available()
8182

8283
# count signal as interference
@@ -110,7 +111,7 @@ def scan(timeout: int = 30):
110111
print("")
111112

112113

113-
def noise(timeout: int = 1, channel: int = None):
114+
def noise(timeout: int = 1, channel: Optional[int] = None):
114115
"""print a stream of detected noise for duration of time.
115116
116117
:param int timeout: The number of seconds to scan for ambient noise.
@@ -120,15 +121,15 @@ def noise(timeout: int = 1, channel: int = None):
120121
if channel is not None:
121122
radio.channel = channel
122123
radio.listen = True
123-
timeout += time.monotonic()
124-
while time.monotonic() < timeout:
124+
end_time = timeout + time.monotonic()
125+
while time.monotonic() < end_time:
125126
signal = radio.read(radio.payload_size)
126127
if signal:
127128
print(address_repr(signal, False, " "))
128129
radio.listen = False
129-
while not radio.is_fifo(False, True):
130+
while radio.is_fifo(False) != RF24_FIFO_EMPTY:
130131
# dump the left overs in the RX FIFO
131-
print(address_repr(radio.read(), False, " "))
132+
print(address_repr(radio.read(32), False, " "))
132133

133134

134135
def set_role():

examples/scanner_curses.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import curses
1010
import time
11-
from typing import List, Tuple, Any
11+
from typing import List, Tuple, Any, cast, Optional
1212
from pyrf24 import RF24, RF24_1MBPS, RF24_2MBPS, RF24_250KBPS, RF24_DRIVER
1313

1414
print(__file__) # print example name
@@ -75,7 +75,7 @@ def __init__( # pylint: disable=too-many-arguments,invalid-name
7575
x: int,
7676
y: int,
7777
cols: int,
78-
std_scr: Any, # type: curses.window,
78+
std_scr: Any, # type is actually curses.window,
7979
label: str,
8080
color: int,
8181
):
@@ -109,7 +109,7 @@ def update(self, completed: int, signal_count: int):
109109

110110
def init_display(window) -> List[ProgressBar]:
111111
"""Creates a table of progress bars (1 for each channel)."""
112-
progress_bars: List[ProgressBar] = [None] * TOTAL_CHANNELS
112+
progress_bars: List[Optional[ProgressBar]] = [None] * TOTAL_CHANNELS
113113
bar_w = int(curses.COLS / 6)
114114
for i in range(21): # 21 rows
115115
for j in range(i, i + (21 * 6), 21): # 6 columns
@@ -122,7 +122,7 @@ def init_display(window) -> List[ProgressBar]:
122122
label=f"{2400 + (j)} ",
123123
color=color,
124124
)
125-
return progress_bars
125+
return cast(List[ProgressBar], progress_bars)
126126

127127

128128
def init_radio():
File renamed without changes.

src/pyRF24.cpp

+42-10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ void init_rf24(py::module& m)
6565
)docstr")
6666
.export_values();
6767

68+
py::enum_<rf24_fifo_state_e>(m, "rf24_fifo_state_e")
69+
.value("RF24_FIFO_OCCUPIED", RF24_FIFO_OCCUPIED, R"docstr(
70+
The FIFO is not full nor empty, but it is occupied with 1 or 2 payloads.
71+
)docstr")
72+
.value("RF24_FIFO_EMPTY", RF24_FIFO_EMPTY, R"docstr(
73+
The FIFO is empty.
74+
)docstr")
75+
.value("RF24_FIFO_FULL", RF24_FIFO_FULL, R"docstr(
76+
The FIFO is full.
77+
)docstr")
78+
.value("RF24_FIFO_INVALID", RF24_FIFO_INVALID, R"docstr(
79+
Represents corruption of data over SPI (when observed).
80+
)docstr")
81+
.export_values();
82+
6883
py::enum_<rf24_pa_dbm_e>(m, "rf24_pa_dbm_e")
6984
.value("RF24_PA_MIN", RF24_PA_MIN, R"docstr(
7085
+----------------------+--------------------+--------------------+
@@ -711,6 +726,12 @@ void init_rf24(py::module& m)
711726
712727
:param int pipe_number: The pipe number to use for receiving transmissions. This value should be in range [0, 5].
713728
:param bytes,bytearray,int address: The address assigned to the specified data pipe for receiving transmissions.
729+
730+
.. deprecated:: 0.2.1
731+
Use `bytes` or `bytearray` to specify address.
732+
733+
Using an `int` to specify the address has been deprecated because of
734+
inconsistent endianess and needless memory consumption.
714735
)docstr",
715736
py::arg("pipe_number"), py::arg("address"))
716737

@@ -739,6 +760,12 @@ void init_rf24(py::module& m)
739760
Open data pipe 0 for transmitting to a specified address.
740761
741762
:param bytes,bytearray,int address: The address assigned to data pipe 0 for outgoing transmissions.
763+
764+
.. deprecated:: 0.2.1
765+
Use `bytes` or `bytearray` to specify address.
766+
767+
Using an `int` to specify the address has been deprecated because of
768+
inconsistent endianess and needless memory consumption.
742769
)docstr",
743770
py::arg("address"))
744771

@@ -834,7 +861,7 @@ void init_rf24(py::module& m)
834861

835862
.def("is_fifo", static_cast<bool (RF24Wrapper::*)(bool, bool)>(&RF24Wrapper::isFifo), R"docstr(
836863
is_fifo(about_tx: bool, check_empty: bool) -> bool \
837-
is_fifo(about_tx: bool) -> int
864+
is_fifo(about_tx: bool) -> rf24_fifo_state_e
838865
839866
840867
Get information about a specified FIFO buffers.
@@ -843,6 +870,13 @@ void init_rf24(py::module& m)
843870
to make returned data describe the RX FIFO.
844871
:param bool check_empty: Check if the specified FIFO is empty. Set this to `False` to
845872
check if the specified FIFO is full.
873+
874+
.. deprecated:: 0.4.4
875+
Use ``is_fifo(about_tx: bool)`` for better precision.
876+
877+
The ``is_fifo(about_tx: bool, check_empty: bool)`` signature may yield
878+
inaccurate information when data suffers corruption over the SPI bus'
879+
MISO line.
846880
)docstr",
847881
py::arg("about_tx"), py::arg("check_empty"))
848882

@@ -853,19 +887,17 @@ void init_rf24(py::module& m)
853887

854888
// *****************************************************************************
855889

856-
.def("is_fifo", static_cast<uint8_t (RF24Wrapper::*)(bool)>(&RF24Wrapper::isFifo), R"docstr(
890+
.def("is_fifo", static_cast<rf24_fifo_state_e (RF24Wrapper::*)(bool)>(&RF24Wrapper::isFifo), R"docstr(
857891
:Returns:
858-
- A `bool` describing if the specified FIFO is empty or full.
859-
- An `int` if the ``check_empty`` parameter was unspecified. In which case, the return integer is
860-
861-
- ``0`` if the specified FIFO is neither full nor empty.
862-
- ``1`` if the specified FIFO is empty.
863-
- ``2`` if the specified FIFO is full.
892+
- A `bool` describing if the specified FIFO is empty or full
893+
if the ``check_empty`` parameter was specified.
894+
- An enumeration of `rf24_fifo_state_e` describing the specifed FIFO's state
895+
if the ``check_empty`` parameter was unspecified.
864896
)docstr",
865897
py::arg("about_tx"))
866898

867-
.def("isFifo", static_cast<uint8_t (RF24Wrapper::*)(bool)>(&RF24Wrapper::isFifo), R"docstr(
868-
isFifo(about_tx: bool) -> int
899+
.def("isFifo", static_cast<rf24_fifo_state_e (RF24Wrapper::*)(bool)>(&RF24Wrapper::isFifo), R"docstr(
900+
isFifo(about_tx: bool) -> rf24_fifo_state_e
869901
)docstr",
870902
py::arg("about_tx"))
871903

src/pyrf24/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
RF24_PA_HIGH,
1515
RF24_PA_MAX,
1616
RF24_DRIVER,
17+
rf24_fifo_state_e,
18+
RF24_FIFO_OCCUPIED,
19+
RF24_FIFO_EMPTY,
20+
RF24_FIFO_FULL,
21+
RF24_FIFO_INVALID,
1722
RF24Network,
1823
RF24NetworkHeader,
1924
# RF24NetworkFrame,
@@ -72,6 +77,11 @@
7277
"RF24_PA_HIGH",
7378
"RF24_PA_MAX",
7479
"RF24_DRIVER",
80+
"rf24_fifo_state_e",
81+
"RF24_FIFO_OCCUPIED",
82+
"RF24_FIFO_EMPTY",
83+
"RF24_FIFO_FULL",
84+
"RF24_FIFO_INVALID",
7585
"RF24Network",
7686
"RF24NetworkHeader",
7787
"MAX_USER_DEFINED_HEADER_TYPE",

src/pyrf24/pyrf24.pyi

+19-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ RF24_PA_LOW: rf24_pa_dbm_e = rf24_pa_dbm_e.RF24_PA_LOW
3333
RF24_PA_HIGH: rf24_pa_dbm_e = rf24_pa_dbm_e.RF24_PA_HIGH
3434
RF24_PA_MAX: rf24_pa_dbm_e = rf24_pa_dbm_e.RF24_PA_MAX
3535

36+
class rf24_fifo_state_e:
37+
RF24_FIFO_OCCUPIED: rf24_fifo_state_e
38+
RF24_FIFO_EMPTY: rf24_fifo_state_e
39+
RF24_FIFO_FULL: rf24_fifo_state_e
40+
RF24_FIFO_INVALID: rf24_fifo_state_e
41+
42+
RF24_FIFO_OCCUPIED: rf24_fifo_state_e = rf24_fifo_state_e.RF24_FIFO_OCCUPIED
43+
RF24_FIFO_EMPTY: rf24_fifo_state_e = rf24_fifo_state_e.RF24_FIFO_EMPTY
44+
RF24_FIFO_FULL: rf24_fifo_state_e = rf24_fifo_state_e.RF24_FIFO_FULL
45+
RF24_FIFO_INVALID: rf24_fifo_state_e = rf24_fifo_state_e.RF24_FIFO_INVALID
46+
3647
class RF24:
3748
@overload
3849
def __init__(
@@ -69,12 +80,14 @@ class RF24:
6980
def isChipConnected(self) -> bool: ...
7081
def isPVariant(self) -> bool: ...
7182
def isValid(self) -> bool: ...
72-
def is_fifo(
73-
self, about_tx: bool, check_empty: Optional[bool] = None
74-
) -> Union[bool, int]: ...
75-
def isFifo(
76-
self, about_tx: bool, check_empty: Optional[bool] = None
77-
) -> Union[bool, int]: ...
83+
@overload
84+
def is_fifo(self, about_tx: bool) -> rf24_fifo_state_e: ...
85+
@overload
86+
def is_fifo(self, about_tx: bool, check_empty: bool) -> bool: ...
87+
@overload
88+
def isFifo(self, about_tx: bool) -> rf24_fifo_state_e: ...
89+
@overload
90+
def isFifo(self, about_tx: bool, check_empty: bool) -> bool: ...
7891
def mask_irq(self, tx_ok: bool, tx_fail: bool, rx_ready: bool) -> None: ...
7992
def maskIRQ(self, tx_ok: bool, tx_fail: bool, rx_ready: bool) -> None: ...
8093
def open_tx_pipe(self, address: Union[bytes, bytearray, int]) -> None: ...

0 commit comments

Comments
 (0)