-
Notifications
You must be signed in to change notification settings - Fork 52
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
Make breathe function more flexible #78
Make breathe function more flexible #78
Conversation
Any comments on this? I will adapt the tests & docs too if accepted. |
@boraozgen: Let's make it a non breaking change. For example we could use default parameters for Example: static constexpr uint16_t kUndef16 = 0xffff;
// Set effect to Breathe, with the given period time in ms.
B& Breathe(uint16_t a, unti16_t b=kUndef16, unti16_t c=kUndef16) {
if (b==kUndef16) {
// old behaviour, just use a
} else {
// new behaviour - configure all durations with a,b,c
}
}
... The other option (cleaner) option would be to just introduce a second B& Breathe(uint16_t duration) {
return Breathe(duration>>1, 0, duration>>1);
}
B& Breathe(uint16_t duration_fade_on, unti16_t duration_on, unti16_t duration_fade_off) {
// new code
} I think this is the better and cleaner approach. What Do you think? |
edacad9
to
10cef3e
Compare
I like the shim idea with two APIs. I find division more expressive than shifting, I believe it would be optimized by the compiler anyway. Pushed the new version with fixed tests. I also added the new API to readme, but didn't touch the original examples with the old Breathe API for simplicity. |
src/jled_base.h
Outdated
: fadeon_func(period_ - t, periodh); | ||
auto ret = kZeroBrightness; | ||
if (t < duration_fade_on_) | ||
ret = fadeon_func(t, duration_fade_on_); |
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.
please remove variable ret
and just return
the calculated value, instead of overwriting it (all occurences)
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.
Done
src/jled_base.h
Outdated
ret = kFullBrightness; | ||
else if (t < Period()) | ||
ret = fadeon_func(Period() - t, duration_fade_off_); | ||
return ret; |
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.
else return kZeroBirghtness
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.
Done
In addition to just a period argument, the Breathe method now accepts fade-on, on and fade-off durations for a more flexible breathe animation. The old API is preserved with a shim layer.
10cef3e
to
9096933
Compare
Thank you very much the PR! |
Thanks for the great library! Here is a change I find useful:
Instead of just a period argument, breathe function now accepts fade-on, on and fade-off durations for more a more flexible breathe animation.
As this causes a breaking change, we could add this as a separate function instead. Open for suggestions.