I developed an Arduino library that have a method called "process". This method is a Void function and must be called inside the loop and most of the time the library handles everything by it self:
#include <HookNinja.h>
HookNinja hookninja;
void setup()
{}
void loop()
{
hookninja.process();
}
The idea is to keep the user program a simple as possible. Sometimes "process" have some data to give back to the user so he can use it as he likes. A simple approach is not to make process void and make the user check for the return value of process:
void loop()
{
someVariableType foo;
foo = hookninja.process();
if(foo) {
//user defined things
}
}
But the data returned by process could be anything, from an int to an array of Strings, only the user knows the return type, also this method seems not very elegant. Im not an expert of C++, for me the ideal solution will be an object oriented approach were the user pass a function to process that can be called from the library, but I have no idea how to do this in C++, something like:
void userFunction(type param) {
//do something with param
}
void loop() {
hookNinja.process(some how pass userFunction here)
}