An Arduino library to call functions via Serial
Download the the tow files, DynamicDriver.h and DynamicDriver.cpp Include the DynamicDriver.h in your project.
First you need to create your custom functions for example:
classSetPinModeFunction : publicFunction//Function class need to be the base class
{
public:
FunctionType getReturnType() //override getReturnType() and return your returnType,
{ //the types supported are in from FunctionTypereturnVOIDT;
}
intgetArgumentsCount() //override getArgumentsCount() and return the quantity arguments of your function
{
return2;
}
FunctionType* getArgumentTypes() //override getArgumentTypes() an array with the types of your arguments
{
return argumentTypes;
}
voidexecute(void** arguments, void *returnValue) //override exectute(), execute is called when the function is called via Serial
{
byte pin = *(byte*)arguments[0]; //get the first argument
byte mode = *(byte*)arguments[1]; //get the second argumentpinMode(pin, mode); //do the work
}
private:
FunctionType argumentTypes[2]{ FunctionType::BYTET, FunctionType::BYTET };
};After you have created your customs functions create your listener
classMyDynamicDriver : publicDynamicDriver//Dynamic Driver need to be the base class
{
public:MyDynamicDriver()
{
}
Function* getFunction(byte commandByte) //only you need to override getFunction and return the function that correspond by id
{
// dont use 0switch (commandByte)
{
case1:
return &pinModeFunc;
break;
case2:
return &digitalWriteFunc;
break;
default:
break;
}
}
private:
SetPinModeFunction pinModeFunc;
DigitalWriteFunction digitalWriteFunc;
};After you have your listener you need to to call driver.setup() and driver.loop():
MyDynamicDriver driver;
voidsetup()
{
driver.setup();
}
voidloop()
{
driver.loop();
}
You need to use a client for now the only one that you can use is the C# client that is: https://github.com/aleGuardiola/ArduinoDynamicDriver but you are welcome to provide a new one :).