I'm using the ArduinoLowPower library with the SAMD21 M0 to handle deep sleep and interrupts, which works fine with small programs. The library automatically instantiates itself (in ArduinoLowPower.cpp) as
ArduinoLowPowerClass LowPower;
ArduinoLowPower.h includes this line:
extern ArduinoLowPowerClass LowPower;
However, when attempting to integrate the library into a much larger program using the RadioHead library, during compilation of RadioHead source code, the compiler or linker does not recognize the library instance.
For example (main source code)
#define SEROUT Serial1
#include <SPI.h>
#include "ArduinoLowPower.h" //same error with #include <ArduinoLowPower.h>
#include <RH_RF95.h>
and adding this to RH_RF95.h
void RH_RF95::setModeRx()
{
if (_mode != RHModeRx)
{
modeWillChange(RHModeRx);
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_RXCONTINUOUS);
spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x00); // Interrupt on RxDone
_mode = RHModeRx;
// set deep sleep mode (from ArduinoLowPower library)
LowPower.deepSleep();
}
}
results in a scope error message:
C:\Users\Jim\Desktop\FeatherM0LoRa\libraries\RadioHead\RH_RF95.cpp: In member function 'void RH_RF95::setModeRx()':
C:\Users\Jim\Desktop\FeatherM0LoRa\libraries\RadioHead\RH_RF95.cpp:439:5: error: 'LowPower' was not declared in this scope
439 | LowPower.deepSleep();
| ^~~~~~~~
Hopefully, someone can explain what I'm doing wrong!
Just to verify spelling, etc., when putting that call in the main code, no error message is generated:
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t len = sizeof(buf);
if (rf95.recv((uint8_t *)buf, &len))
{
buf[len] = 0; //zero terminate
SEROUT.println(buf);
}
}
LowPower.deepSleep(); //dummy call to check whether the library is instantiated
}