(Update: it seems this currently doesn’t work by design: Look into the scheduling of lamba function with captures as another option · Issue #24 · davetcc/TaskManagerIO · GitHub)
So, allow me an additional question please, also if it doesn’t quite fit into the scope of “PlatformIO”, but basic C++ I guess.
I couldn’t help but going down the refactoring rabbit hole because I didn’t like the lacking cohesion of the code base and I wanted the struct REMOTE
be less anemic like I know as a Domain-Driven Design aficionado.
So besides many other things my REMOTE got methods like moveUp
, down
etc. so it’s in the control and responsibility of the REMOTE to handly anything related to the particular intention: i.e. as well publishing the MQTT state[^1].
Eventually I stumbled upon a code line (L122 in particular) that doesn’t compile:
(github) /afoeder/Somfy_Remote/blob/2d0a154fd3dbc646dfd8dcc6693c7388357a66cf/src/main.cpp#L113-L123
(this discourse apparently doesn’t allow me to post a link to GH)
It tells me src/main.cpp:123:22: error: no matching function for call to 'TaskManager::scheduleOnce(uint32_t&, REMOTE::moveDown(PubSubClient&, const char*, const char*)::__lambda0)'
.
I’ve trial&error’d a bit with an empty function body and the above error occurs exactly as soon as I introduce this
in the lambda capture group [this]
. Using [&]
with an empty func body compiles; but as soon as I reintroduce an invokation on this
like so [&] { this->dummy(); }
the error occurs again.
Won’t that maybe work by design? Can’t I schedule a task with a reference to this
because the environment could lose/garbage-collect the instance?
Sorry for the long text but I wanted to go sure there’s all information and intent.
Thanks again and have a happy easter!
[^1]: granted, I wouldn’t see MQTT being the native task of the remote but that’s some other step for further refactoring. I might have some domain helper that ties together MQTT listening, remote sending, and MQTT republishing.