The sweep functionality which was available as a helper function in the library will now be part of the Device struct as a method named sweep_write. This is a breaking change, but I think it's worth it as it greatly simplifies the user-facing API and adds to the overall uniformity of the crate as sweep_write is similar to write_value.
Checks have also been added to both avoid panics caused by integer overflow ( fixes #1 ) and to avoid writing beyond the max brightness value of the backlight device.
Update:
Using this opportunity, the sleep duration or delay between each iteration of the loop (delay between each incremental write to the brightness file) has been exposed through the new Delay parameter in the sweep_write function, letting the users have more control.
This can be used as device.sweep_write(10, Delay::default()) (default delay of 25ms) or device.sweep_write(10, Delay::from_millis(25)). Since Delay is a wrapper type for std::time::duration, Duration type can easily be converted into Delay type by calling into() like so: device.sweep_write(10, Duration::from_millis(25).into())
Another notable change includes the use of a single file handle inside sweep_write for all writes. (Before, Device::write_value was called on each write inside the loop, which in-turn used std::fs::write). Users may notice a slight improvement in the smoothness of the brightness transition.
todo
[x] Add missing unit tests
[x] Review code to look for improvement opportunities
The sweep functionality which was available as a helper function in the library will now be part of the Device struct as a method named
sweep_write
. This is a breaking change, but I think it's worth it as it greatly simplifies the user-facing API and adds to the overall uniformity of the crate assweep_write
is similar towrite_value
.Checks have also been added to both avoid panics caused by integer overflow ( fixes #1 ) and to avoid writing beyond the max brightness value of the backlight device.
Update: Using this opportunity, the sleep duration or delay between each iteration of the loop (delay between each incremental write to the brightness file) has been exposed through the new Delay parameter in the sweep_write function, letting the users have more control.
This can be used as
device.sweep_write(10, Delay::default())
(default delay of 25ms) ordevice.sweep_write(10, Delay::from_millis(25))
. Since Delay is a wrapper type forstd::time::duration
, Duration type can easily be converted into Delay type by callinginto()
like so:device.sweep_write(10, Duration::from_millis(25).into())
Another notable change includes the use of a single file handle inside sweep_write for all writes. (Before,
Device::write_value
was called on each write inside the loop, which in-turn usedstd::fs::write
). Users may notice a slight improvement in the smoothness of the brightness transition.todo