Replies: 4 comments 7 replies
-
I made some modifications (with the help of chatGPT). Decided to stick with the pointers in that wrapper struct, so it looks like this now: struct Dimmer {
HALight* ha_light;
dimmerLamp* dimmer;
ace_button::AceButton* button;
Dimmer(HALight& _hl , dimmerLamp& _dl, ace_button::AceButton& _ab) :
ha_light(&_hl), dimmer(&_dl), button(&_ab)
{ }
}; And I am initializing all the objects before I use them in the array of Dimmers: ace_button::AceButton b54(54);
ace_button::AceButton b55(55);
dimmerLamp d22(22);
dimmerLamp d23(23);
HALight room1("room1", HALight::BrightnessFeature);
HALight room2("room2", HALight::BrightnessFeature);
Dimmer dimmers_array[] = {
Dimmer(room1, d22, b54),
Dimmer(room2, d23, b55),
}; Might be a better way to do it as I guess I do not want to make any object copies at all. |
Beta Was this translation helpful? Give feedback.
-
The source of the error is that the C++ compiler automatically creates a copy constructor for your The reason I deleted the copy constructor for AceButton is because it does not make semantic sense to allow a button object to be copied. There is one physical button bound to one instance of The solution from ChatGPT is ok. But I think a simpler solution is to just disable the copy-constructor on your class Dimmer {
...
private:
Dimmer(const Dimmer&) = delete; If you have 16 buttons and 16 dimmers, and so on, this should allow your original code to work, and save you from typing 16 x 3 = 48 extra lines of code where you manually instantiate all those objects. |
Beta Was this translation helpful? Give feedback.
-
Side Note: I'm not sure when they added the ability to close Discussions, or maybe it was always there but I never noticed it, but I prefer to keep discussions open so that other people searching for similar problems can find the discussions easier. It's one of the advantages of Discussions over Issues, in my opinion for things like this, because the default search under Issues ignores closed Issues, and many people don't bother doing the extra search. |
Beta Was this translation helpful? Give feedback.
-
Perhaps something like this? MyClass.h #include <Arduino.h>
#include <AceButton.h>
class MyClass : public ace_button::IEventHandler {
protected:
ace_button::AceButton myButton;
void handleEvent(ace_button::AceButton* button, uint8_t eventType, uint8_t buttonState) override;
public:
MyClass(uint8_t button_pin);
}; MyClass.cpp #include "./MyClass.h"
using namespace ace_button;
MyClass::MyClass(uint8_t button_pin) : myButton(button_pin) {
myButton.getButtonConfig()->setIEventHandler(this);
};
void MyClass::handleEvent(AceButton* button, uint8_t eventType, uint8_t buttonState) {
// handle event here
}
|
Beta Was this translation helpful? Give feedback.
-
I am using an Arduino Mega to build a Dimmer module.
It has 16 buttons that I would like to group together with 16 dimmers. I thought about using a struct for a dimmer-button pair. I am also using a third item to glue this together - a home assistant class for managing the MQTT states and communicating with the MQTT server so that the dimmers can be easily controlled via the MQTT server.
I have created the following struct:
It worked well when I tested it without Buttons but when I added AceButton to the Dimmer class, I am getting this error:
My very limited knowledge of C++ tells me that it is likely because AceButton has a deleted copy constructor which prevented creating one automatically for Dimmer class. I did notice that AceButton has deleted copy constructor but I don't see any notes as to why in the code.
The reason I am creating this array of Dimmer structs is because it make it much easier to create logic in all the callbacks. I can simply find the right Dimmer with all the mapped modules and there is just a single array I keep the mappings defined.
Any suggestions on how to handle AceButton differently to make it work this way?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions