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

C++ Expert wanted ... #94

Open
1 task
mitra42 opened this issue Dec 16, 2024 · 5 comments
Open
1 task

C++ Expert wanted ... #94

mitra42 opened this issue Dec 16, 2024 · 5 comments

Comments

@mitra42
Copy link
Owner

mitra42 commented Dec 16, 2024

There are a few challenges that an expert C++ coder could help with .

  • In actuator_digital.cpp - and actuator_ledbuiltin.cpp - I'd like to pass a callback that is a method of an instance of a class, but I'm completely failing to get something that will compile.
  • [ ]
@jksemple
Copy link
Contributor

If you subclass all your different actuators from a common super Actuator which has a virtual inputReceived() method you can then pass across a reference to the actuator object instead of passing the callback. That can then be held in your subscriptions collection and then the MQTT object can call actuator.inputReceived() on each such subscribed actuator object. The appropriate concrete inputReceived() method will then get executed. I think that might work.

@mitra42
Copy link
Owner Author

mitra42 commented Dec 28, 2024

Yes - it might, the challenge is that about half of the sensors/actuators/control are not done as Classes - they are using the "setup/loop" paradigm of Arduino IDE. Its a gradual rewrite to turn them into classes.

@jksemple
Copy link
Contributor

jksemple commented Dec 28, 2024

If you don't want to rewrite all your actuators as classes you'll just have to stick to the callback approach and where you have a class you'll need to define a callback free function outside the class that calls this->inputReceived(). Not pretty, but you can't pass an object method as a function pointer parameter AFAIK. But then, I'm not an expert.

@mitra42
Copy link
Owner Author

mitra42 commented Dec 30, 2024

Ok - its quite possibly the time to bite the bullet and rewrite as classes, not just for this reason. I've got a issue for this somewhere and will stick a proposed class hierarchy there after the break. #25

@jksemple
Copy link
Contributor

In sensor.cpp you wanted to declare sensors as a static member of Sensor. You can do this but you do need to initialise the static member before 'main' runs. Somewhere in sensor.cpp add the line std::vector<Sensor*> Sensor::sensors = std::vector<Sensor*>();

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

No branches or pull requests

2 participants