-
Notifications
You must be signed in to change notification settings - Fork 14
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
Allow setting full-on and full-off bits via set_all_on_off() #17
Conversation
Thanks for the PR. I understand the need for something like this. (&mut self, on: &[u16; 16], off: &[u16; 16], full_on: &[bool; 16], full_off: &[bool; 16]) Inside the method would just zip all lists together and |
This method signature with four slice arguments, which you propose, was exactly my first idea. I started implementing it and then changed my mind, because of the amount of boilerplate code for creating and handling the four arrays. But I see why you prefer it and I'd be okay with implementing and using it. (And I like As an alternative: What do you think about combining the four arrays like this: pub struct ChannelOnOff {
pub on: u16,
pub off: u16,
pub full_on: bool,
pub full_off: bool,
}
impl<...> Pca9685<...> {
// ...
set_all_channels(&mut self, values: &[ChannelOnOff; 16]) -> ... { ... }
} |
That looks like a nice alternative. |
In my use case, that would be quite nice, because I already have a function that encapsulates the calculation of all channels' on and off counter values, based on all target duty cycles. Currently it returns the two |
One disadvantage of the struct-based solution: Due to alignment, it will probably have an overhead of 32 padding bytes for the whole array (assuming 4-byte alignment: 16*2byte). This may be an issue, when keeping the data for controlling multiple Pca9685 chips in memory on a microcontroller. |
I defined a type like this:
Without mention of any additional padding, so I think we are ok. |
Ah, okay, forget what I said. We only have one or two bytes long fields in this struct, so there is no need for the compiler to 4-byte-align the struct (independent from the CPU architecture). I already fully implemented this new approach in PR #18. |
Closing in favor of #18 |
Problem
I use the PCA9685 for driving multichannel LED strips with animations. In every animation step, I update all on/off values with
set_all_on_off()
and afterwards useset_channel_full_on()
resp.set_channel_full_off()
for all channels that shall be full on/off. This got me issues with visible flickering of the full on/off channels.Thus, I want to be able to update all channels' on/off counter values and the full-on and full-off bits in a single I2C transaction.
Solution
I extended the allowed range of values in the slice arguments of
set_all_on_off()
, so it's possible to set the 13th bit (the full-on/full-off bit) for each individual channel. This is a backwards-compatible change.Alternatives
If you don't like the relaxed range check of the on/off values in the existing
set_all_on_off()
method, because of its mixed-up value semantics (I understand that setting a channel to full-off is semantically different from setting the off counter value), I can refactor the PR to add another method for this combined functionality. (Any ideas for the name?)This separate method could also take two additional
&[bool; 16]
slices for the full-on/full-off values, but I considered this is a bit inefficient and rather unergonomically to use.Alternatively, I thought about adding public constants
FULL_ON_BIT: u16
andFULL_OFF_VALUE: u16
to make the new combined functionality ofset_all_on_off()
easier to use.