Skip to content

Commit

Permalink
Add isFifo() methods (#849)
Browse files Browse the repository at this point in the history
* add new isFifo() methods

* fix call to overloaded `isFifo()`

* fix copy-n-paste error

* add to py wrapper; remove const-ness from params

* fix casting in py wrapper

* ran clang-format on pyRF24.cpp

* update return type for writeAckPL() in py wrapper

* add new methods to sphinx docs
  • Loading branch information
2bndy5 authored Jul 9, 2022
1 parent 86599a0 commit c3aa6ef
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
14 changes: 14 additions & 0 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,20 @@ bool RF24::rxFifoFull()

/****************************************************************************/

uint8_t RF24::isFifo(bool about_tx)
{
return static_cast<uint8_t>((read_register(FIFO_STATUS) >> (4 * about_tx)) & 3);
}

/****************************************************************************/

bool RF24::isFifo(bool about_tx, bool check_empty)
{
return static_cast<bool>(isFifo(about_tx) & _BV(!check_empty));
}

/****************************************************************************/

bool RF24::txStandBy()
{

Expand Down
18 changes: 18 additions & 0 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,24 @@ class RF24
*/
bool rxFifoFull();

/**
* @param about_tx `true` focuses on the TX FIFO, `false` focuses on the RX FIFO
* @return
* - `0` if the specified FIFO is neither full nor empty.
* - `1` if the specified FIFO is empty.
* - `2` if the specified FIFO is full.
*/
uint8_t isFifo(bool about_tx);

/**
* @param about_tx `true` focuses on the TX FIFO, `false` focuses on the RX FIFO
* @param check_empty
* - `true` checks if the specified FIFO is empty
* - `false` checks is the specified FIFO is full.
* @return A boolean answer to the question "is the [TX/RX] FIFO [empty/full]?"
*/
bool isFifo(bool about_tx, bool check_empty);

/**
* Enter low-power mode
*
Expand Down
2 changes: 2 additions & 0 deletions docs/sphinx/classRF24.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ FIFO Management
.. doxygenfunction:: RF24::rxFifoFull
.. doxygenfunction:: RF24::flush_tx
.. doxygenfunction:: RF24::flush_rx
.. doxygenfunction:: RF24::isFifo (bool about_tx)
.. doxygenfunction:: RF24::isFifo (bool about_tx, bool check_empty)

Ambiguous Signal Detection
**************************
Expand Down
6 changes: 4 additions & 2 deletions pyRF24/pyRF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ bool write_wrap2(RF24& ref, bp::object buf, const bool multicast)
return ref.write(get_bytes_or_bytearray_str(buf), get_bytes_or_bytearray_ln(buf), multicast);
}

void writeAckPayload_wrap(RF24& ref, uint8_t pipe, bp::object buf)
bool writeAckPayload_wrap(RF24& ref, uint8_t pipe, bp::object buf)
{
ref.writeAckPayload(pipe, get_bytes_or_bytearray_str(buf), get_bytes_or_bytearray_ln(buf));
return ref.writeAckPayload(pipe, get_bytes_or_bytearray_str(buf), get_bytes_or_bytearray_ln(buf));
}

bool writeFast_wrap1(RF24& ref, bp::object buf)
Expand Down Expand Up @@ -309,6 +309,8 @@ BOOST_PYTHON_MODULE(RF24)
.def("reUseTX", &RF24::reUseTX)
.def("read", &read_wrap, (bp::arg("maxlen")))
.def("rxFifoFull", &RF24::rxFifoFull)
.def("isFifo", (uint8_t(::RF24::*)(bool))(&::RF24::isFifo), (bp::arg("about_tx")))
.def("isFifo", (bool (::RF24::*)(bool, bool))(&::RF24::isFifo), (bp::arg("about_tx"), bp::arg("check_empty")))
.def("setAddressWidth", &RF24::setAddressWidth)
.def("setAutoAck", (void (::RF24::*)(bool))(&::RF24::setAutoAck), (bp::arg("enable")))
.def("setAutoAck", (void (::RF24::*)(::uint8_t, bool))(&::RF24::setAutoAck), (bp::arg("pipe"), bp::arg("enable")))
Expand Down

0 comments on commit c3aa6ef

Please sign in to comment.