Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I call a class member function using Tasker #10

Open
tichaonax opened this issue Jul 27, 2020 · 2 comments
Open

How do I call a class member function using Tasker #10

tichaonax opened this issue Jul 27, 2020 · 2 comments

Comments

@tichaonax
Copy link

I am trying to use Tasker in an instance class. The method has to be a member so that it can access class variables for that instance. Norml functions work but I need to bind to the call to an instance. I have dine it with other callbacks using the same syntax. I have tried to add int as parameter and changed member from private to public but no change.

`
void ChannelStateService::begin() {
_deviceTime.setInterval(std::bind(&ChannelStateService::updateStateTime, this), 10000);
}

void ChannelStateService::updateStateTime(){
update([&](ChannelState& channelState) {
return StateUpdateResult::CHANGED;
}, _state.channel.name);
}
`
I get the following error:

src/automation/ChannelStateService.cpp: In member function 'void ChannelStateService::begin()':
src/automation/ChannelStateService.cpp:187:90: error: no matching function for call to 'Tasker::setInterval(std::_Bind_helper<false, void (ChannelStateService::)(), ChannelStateService const>::type, int)'
_deviceTime.setInterval(std::bind(&ChannelStateService::updateStateTime, this), 10000);
^
src/automation/ChannelStateService.cpp:187:90: note: candidates are:
In file included from src/automation/ChannelStateService.h:18:0,
from src/automation/ChannelStateService.cpp:2:
.pio/libdeps/esp12e/Tasker/Tasker.h:92:6: note: bool Tasker::setInterval(TaskCallback0, long unsigned int, byte)
bool Tasker::setInterval(TaskCallback0 func, unsigned long interval, byte prio)
^
.pio/libdeps/esp12e/Tasker/Tasker.h:92:6: note: no known conversion for argument 1 from 'std::_Bind_helper<false, void (ChannelStateService::)(), ChannelStateService const>::type {aka std::_Bind<std::_Mem_fn<void (ChannelStateService::)()>(ChannelStateService)>}' to 'TaskCallback0 {aka void (*)()}'
.pio/libdeps/esp12e/Tasker/Tasker.h:87:6: note: bool Tasker::setInterval(TaskCallback1, long unsigned int, int, byte)
bool Tasker::setInterval(TaskCallback1 func, unsigned long interval, int param, byte prio)

@blazerunner44
Copy link

@tichaonax I know it's been awhile, but did you ever find a solution to this?

@tichaonax
Copy link
Author

tichaonax commented Nov 11, 2022

Yes, you can take look at the new implementation in my repo
https://github.com/tichaonax/esp8266-react-scheduler/blob/master/src/automation/TaskScheduler.cpp,
ChannelStateService.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants