After a few hours of googling I’m still at a loss on how to make this work.
It’s a class, and the Scheduler is from the separate TaskScheduler library. This object is instantiated in the main sketch and then passed into my library.
I’m trying to call a member function from this Task object, and that’s where the compiler throws an error (see below). I’m completely at a loss how to make it work.
The .h file:
#ifndef HYDROMONITORMASTER_H
#define HYDROMONITORMASTER_H
#include <TaskScheduler.h>
class HydroMonitorMaster
{
public:
HydroMonitorMaster();
void begin(Scheduler);
private:
// The task scheduler.
Scheduler ts;
Task tReadSensors(int, int, void (HydroMonitorMaster::*)(), Scheduler*, bool);
void readSensors(void);
};
#endif
The .cpp file:
#include <HydroMonitorMaster.h>
HydroMonitorMaster::HydroMonitorMaster() {
}
void HydroMonitorMaster::begin(Scheduler t) {
// f is the task scheduler object, we use this to set up all the repeating tasks.
ts = t;
tReadSensors (10*1000, TASK_FOREVER, &HydroMonitorMaster::readSensors, &ts, false);
tReadSensors.enable();
}
void HydroMonitorMaster::readSensors() {
// Go and read the sensors.
}
The .ino sketch (yes, this is the complete sketch that I use to compile this library - the real thing is of course a lot longer but the error doesn’t change stripping it down to this):
#include <HydroMonitorMaster.h>
And finally the error when trying to compile this:
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp: In member function 'void HydroMonitorMaster::begin(Scheduler)':
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp:12:15: error: '((HydroMonitorMaster*)this)->HydroMonitorMaster::tReadSensors' does not have class type
tReadSensors.enable();
^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).