diff --git a/RF24.cpp b/RF24.cpp index 902c2cf30..d41e2da58 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1372,6 +1372,20 @@ bool RF24::rxFifoFull() /****************************************************************************/ +uint8_t RF24::isFifo(bool about_tx) +{ + return static_cast((read_register(FIFO_STATUS) >> (4 * about_tx)) & 3); +} + +/****************************************************************************/ + +bool RF24::isFifo(bool about_tx, bool check_empty) +{ + return static_cast(isFifo(about_tx) & _BV(!check_empty)); +} + +/****************************************************************************/ + bool RF24::txStandBy() { diff --git a/RF24.h b/RF24.h index 987e1521b..4495c92d9 100644 --- a/RF24.h +++ b/RF24.h @@ -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 * diff --git a/docs/sphinx/classRF24.rst b/docs/sphinx/classRF24.rst index 2ecc1917f..ef57f74c1 100644 --- a/docs/sphinx/classRF24.rst +++ b/docs/sphinx/classRF24.rst @@ -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 ************************** diff --git a/pyRF24/pyRF24.cpp b/pyRF24/pyRF24.cpp index 857a2f0ce..3f2e04fe0 100644 --- a/pyRF24/pyRF24.cpp +++ b/pyRF24/pyRF24.cpp @@ -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) @@ -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")))