Replies: 4 comments 7 replies
-
The short answer is that you can't do this directly, but it's pretty easy to do indirectly. Background: Take a look at the definition of /*!
\brief Set interrupt service routine function to call when DIO0 activates.
\param func Pointer to interrupt service routine.
*/
void setDio0Action(void (*func)(void)); You can see that the method expects the argument to be a pointer to void-type function in the global scope taking no arguments, such as
Your class method wil have a different signature however, it will be:
That's the reason why your compilation fails in the first and fourth example. Moreover, there's a fundamental issue with examples 2 and 3: assuming Solution: You'd have to create your own However, there's a simpler solution - does MyClass mine;
void callMyClass(void) {
mine.onReceive();
}
(...)
radio.setDio0Action(callMyClass); |
Beta Was this translation helpful? Give feedback.
-
I am currently working with the @sergimn implementation, continuing a LoRaMesh Library LoRaMesher. I am stuck with this problem and how to remove the fork that Sergi did in the past. I do not really like to use a global variable because, in some point, other users could break the library. I have found some library that works in AVR, for example functional-avr Could there be a possibility to implement the previous pull request with these fixes for the AVR devices? Thanks for your time! |
Beta Was this translation helpful? Give feedback.
-
This might be an interesting read, even thought this is already an old question and it does not really satisfy the question asked as the article basically says to not do it |
Beta Was this translation helpful? Give feedback.
-
Hi guys,
class Executable
{
public:
virtual void exec(void) = 0;
virtual ~Executable() = default;
};
class MyClass : public Executable
{
public:
void exec(void) override {
... code to handle ....
}
}; ... and finally we can use it like this MyClass mine;
...
radio.setDio0Action(mine); |
Beta Was this translation helpful? Give feedback.
-
I'm trying to develop a C++ class that uses RadioLib. Once I try to specify what function should be called when new data is received with
radio->setDio0Action(&this->onReceive);
, the compilation errorerror: invalid use of non-static member function
appears. I've tried the following lines without success, each with a slightly different error message:Is there a way to, when a packet is received, access the private variables of an instance? The instance has data such as nº of packets received or the node ID, something that is not compatible with making the method
static
as some people may suggest.I found this example and this stackoverflow answer and both indicate that the underlying code has to has support for an extra parameter (the instance we want to get the data from).
In case what I'm asking needs a rework of the code, do you think it should be easy to do? I'm currently using a ESP32 with a SX127x module. Do you know if the underlying hardware supports passing a parameter to the interruption handler?
Beta Was this translation helpful? Give feedback.
All reactions