giova014:
You want a function to create new instances of Task?
Or do you want just one Task (named _task, for example) inside the TestClass, so you can use the functions using this _task?
One instance of the task that I can use within TestClass.
PaulS:
I copied the zip files into the appropriate places. When I try to compile your sketch, I get:
Now, the messages may not be very clear, but they stem from the fact that taskCallBack() is not a static method.
When I make taskCallback() a static method
static void taskCallBack();
I get:which stems from the fact that new returns a pointer, and you are not storing the pointer in a pointer variable.
When I fix that:
Task *_task;
I get:And that stems from the fact that the .ino file can not have the same name as the source file, since the .ino file will be converted to a cpp file for compiling.
Thank you Paul for such walkthrough .. But strangely our error messages do not match. First one I got same as what you pasted. But the second I made my callback static I got old error plus "error: cannot declare member function 'static void TestClass::taskCallBack()' to have static linkage [-fpermissive]".
Here is full error:
Compiling 'SuperCool' for 'Arduino Uno'
TestClass.cpp:In constructor 'TestClass::TestClass()'
TestClass.cpp:14:8: error: invalid user-defined conversion from 'Task*' to 'const Task&' [-fpermissive]
_task = new Task(1,-1, &TestClass*:taskCallBack);
TaskScheduler.h:Task(long unsigned int, long int, void (*)()) <near match>
TaskScheduler.h:no known conversion for argument 1 from 'Task*' to 'long unsigned int'
TestClass.cpp:14:8: error: invalid conversion from 'Task*' to 'long unsigned int' [-fpermissive]
_task = new Task(1,-1, &TestClass*:taskCallBack);
TaskScheduler.h:77:2: error: initializing argument 1 of 'Task::Task(long unsigned int, long int, void (*)())' [-fpermissive]
TestClass.cpp:At global scope
TestClass.cpp:17:37: error: cannot declare member function 'static void TestClass::taskCallBack()' to have static linkage [-fpermissive]
static void TestClass*:taskCallBack()
Error compiling
Then when I add pointer as you mentioned... I left just with following error:
TestClass.cpp:17:37: error: cannot declare member function 'static void TestClass::taskCallBack()' to have static linkage [-fpermissive]
If I then remove the static, but leave pointer, I get following error:
Compiling 'SmartEtch' for 'Arduino Uno'
Binary sketch size: 13 360 bytes (used 41% of a 32 256 byte maximum) (2,15 secs)
Minimum Memory Usage: 1125 bytes (55% of a 2048 byte maximum)
Compiling 'SuperCool' for 'Arduino Uno'
TestClass.cpp:In constructor 'TestClass::TestClass()'
TestClass.cpp:14:49: error: no matching function for call to 'Task::Task(int, int, void (TestClass::*)())'
_task = new Task(1,-1, &TestClass*:taskCallBack);
TestClass.cpp:candidates are
TaskScheduler.h:Task(long unsigned int, long int, void (*)())
TaskScheduler.h:*)()' to 'void (*)()'
TaskScheduler.h:Task(const Task&)
TaskScheduler.h:candidate expects 1 argument, 3 provided
Error compiling
Sorry for taking so much of your time. I have now put static back on and renamed ino file... So just stuck with that error "error: cannot declare member function 'static void TestClass::taskCallBack()' to have static linkage [-fpermissive]"
Any more ideas?
Test Class After Changes.zip (10.3 KB)