-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Preparing color.h for IDF >= 5 #5051
Conversation
Are you sure this is the right way to go? When the "=" operator is used now, won't this convert the color first to a 32 bit int, do some bit-magic and create a new |
No, I'm not sure. The message I got was:
I'll try adding an explicit copy constructor instead, could that work? |
017b8a9
to
c628dea
Compare
db0c17c
to
bc7cf3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
To bad it failed CI... Reworking it now |
14581d4
to
3cecefd
Compare
a4afe3f
to
053a3f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, what a rabbit hole you got yourself into :-D
The changes look good to me; just a small suggestion regarding name, but feel free to ignore it.
This might have conflicts with #5001 though; IMHO it would be better to wait until that one is merged (hopefully soon), and rebase on top of that. Now that it has been merged, you should probably rebase.
esphome/core/color.h
Outdated
@@ -43,7 +43,9 @@ struct Color { | |||
b((colorcode >> 0) & 0xFF), | |||
w((colorcode >> 24) & 0xFF) {} | |||
|
|||
inline bool is_on() ALWAYS_INLINE { return this->raw_32 != 0; } | |||
inline Color(const Color &other_color) : raw_32(other_color.raw_32) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK the C++ convention for copy constructors is to call the original "other", but I might be mistaken here.
inline Color(const Color &other_color) : raw_32(other_color.raw_32) {} | |
inline Color(const Color &other) : raw_32(other.raw_32) {} |
Also this should probably be marked as a breaking change; if you had to change the const'ness of all the displays, external components will also break and need to change that. (Don't get me wrong; I still think these changes you are making are meaningful and good) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
As mentioned above this might be a breaking change for external display components. IMHO it should be put in the same release as #5002 (which is also a breaking change for external display components), so that those components do not need to react to breaking changes twice.
@HeMan I wonder, can we just remove the offended Adding Also the description says "Compiler started to give warnings about operator= in color.h when preparing other components for IDF >= 5.". It would help to have those warning listed in the description. IMHO. Just remove |
Hmm, @guillempages had the suspicion that that it would cast to uint32_t to let the other operator= do it's magic, but I tried to remove both operators and everything seem to work fine. I think that is the best solution, but I'll create another PR to let you decide which to use. |
What does this implement/fix?
Compiler started to give warnings about operator= in color.h when preparing other components for IDF >= 5. Adding copy constructor and changing is_on to const gave a suggestion from compiler to change argument to const reference on display-classes. It's a breaking change for external modules based on the display class.
Types of changes
Related issue or feature (if applicable): fixes
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#
Test Environment
Example entry for
config.yaml
:# Example config.yaml
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: