diff --git a/src/rf95/RadioInterface.h b/src/rf95/RadioInterface.h index 09fd960b8..c4323f545 100644 --- a/src/rf95/RadioInterface.h +++ b/src/rf95/RadioInterface.h @@ -67,7 +67,7 @@ class RadioInterface * * This method must be used before putting the CPU into deep or light sleep. */ - bool canSleep() { return true; } + virtual bool canSleep() { return true; } /// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep. virtual bool sleep() { return true; } diff --git a/src/rf95/RadioLibInterface.cpp b/src/rf95/RadioLibInterface.cpp index 9ae539bd1..65561adeb 100644 --- a/src/rf95/RadioLibInterface.cpp +++ b/src/rf95/RadioLibInterface.cpp @@ -89,6 +89,15 @@ ErrorCode RadioLibInterface::send(MeshPacket *p) } } +bool RadioLibInterface::canSleep() +{ + bool res = txQueue.isEmpty(); + if (!res) // only print debug messages if we are vetoing sleep + DEBUG_MSG("radio wait to sleep, txEmpty=%d\n", txQueue.isEmpty()); + + return res; +} + void RadioLibInterface::loop() { PendingISR wasPending = pending; // atomic read diff --git a/src/rf95/RadioLibInterface.h b/src/rf95/RadioLibInterface.h index 161b3c30d..a990bf8c0 100644 --- a/src/rf95/RadioLibInterface.h +++ b/src/rf95/RadioLibInterface.h @@ -88,6 +88,13 @@ class RadioLibInterface : public RadioInterface virtual void loop(); // Idle processing + /** + * Return true if we think the board can go to sleep (i.e. our tx queue is empty, we are not sending or receiving) + * + * This method must be used before putting the CPU into deep or light sleep. + */ + virtual bool canSleep(); + private: /** start an immediate transmit */ void startSend(MeshPacket *txp); diff --git a/src/rf95/SX1262Interface.cpp b/src/rf95/SX1262Interface.cpp index d8c5e28da..6a1bf851f 100644 --- a/src/rf95/SX1262Interface.cpp +++ b/src/rf95/SX1262Interface.cpp @@ -107,4 +107,15 @@ bool SX1262Interface::canSendImmediately() DEBUG_MSG("Can not set now, busyTx=%d, busyRx=%d\n", busyTx, busyRx); return !busyTx && !busyRx; +} + + + +bool SX1262Interface::sleep() +{ + // we no longer care about interrupts from this device + // prepareDeepSleep(); + + // FIXME - put chipset into sleep mode + return false; } \ No newline at end of file diff --git a/src/rf95/SX1262Interface.h b/src/rf95/SX1262Interface.h index bacfb69eb..8f1ed514b 100644 --- a/src/rf95/SX1262Interface.h +++ b/src/rf95/SX1262Interface.h @@ -19,6 +19,9 @@ class SX1262Interface : public RadioLibInterface /// \return true if initialisation succeeded. virtual bool reconfigure(); + /// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep. + virtual bool sleep(); + protected: /** * Glue functions called from ISR land