nRF24 / CircuitPython_nRF24L01

CircuitPython driver library for the nRF24L01 transceiver.
http://circuitpython-nrf24l01.rtfd.io/
MIT License
45 stars 11 forks source link

RF24Network, RF24Mesh, and RXing BLE #33

Closed 2bndy5 closed 2 years ago

2bndy5 commented 3 years ago

yeah, I've been busy adding/improving this lib (yet again)... As always docs are hosted at rtfd.io.

You may notice that the docs' theme has changed slightly. This is due to the use of the new sphinx-immaterial theme. This theme allows for both light and dark themed color palettes (which can be sought from the system settings by the internet browser).

BLE can now receive

the fake_ble module now has a new class called QueueElement which is used to decode incoming BLE data as it goes from the FakeBLE class' new rx_cache buffer and is saved in the new rx_queue attribute. The existing example has been updated to demonstrate this additional API (which includes a new overridden available() & read()).

RF24Network & RF24Mesh

The C++ libraries that were ported to pure python are a freaking beast. Many of the compile time macros used in C++ could not be used in python (same goes for ALL the overloaded C++ functions). Instead, I had to utilize inheritance to limit consumed memory resources, but some C++ features that were hard-coded at compile-time are straight-up dynamic attributes in this lib. Instead of listing all the features, I will list the differences between C++ libs and this pure python lib's modules.

Instead of writing numerous examples that are almost identical, there is only 1 new example for networking. It demonstrates both fragmented and un-fragmented payloads as well as RF24Network, RF24Mesh, and RF24MeshNoMaster classes. Note, I had to diverge from using the typical master() and slave() named functions as to not confuse with network node operations; this example uses emit() and idle() functions instead.

context manager

As always I've kept compatibility with python's context management system (the with statements). Thus you can use the same radio to take a break from networking and quickly do BLE or basic RF24 operations. This will prove even more useful when using the radio to participate in separate networks on different channels and/or using different physical address "seeds".

RF24Network

RF24Mesh

All RF24Network functionality is inherited into RF24Mesh.

Examples revisited

All examples have been slightly modified to use constant-type names for the SPI_BUS, CE_PIN, & CSN_PIN.

New Wrappers

2bndy5 commented 2 years ago

@wohali I added the ability to set address_length to 2 bytes when configuring with input value outside [3, 5] domain.

Other more advanced stuff can be done with RF24._reg_write_byte(register_offset, register_value)