Sensirion / sensirion-i2c-rs

Rust library with common functionality for our I2C sensors
BSD 3-Clause "New" or "Revised" License
12 stars 8 forks source link

Add support for writing u8 commands #20

Closed sirhcel closed 2 years ago

sirhcel commented 2 years ago

The Sensirion SHT4x series uses 8 bit commands and the new function write_command_u8 has been added to support these devices as well.

For the sake of a clean naming scheme, write_command_u16 is provided as a replacement for write_command. The latter is still available but deprecated.

Using suffixes to distinguish between u8 and u16 commands has been chosen because there is no trait for to_be_bytes which would allow to use a generic function. The crate num_traits provides the trait PrimInt which covers to_be but not to_be_bytes. See https://github.com/rust-num/num-traits/issues/189 for details.

dbrgn commented 2 years ago

I haven't tested any of this, but the diff looks reasonable to me.

It would probably be possible to hack together something generic with a trait and const generics, but that's just unnecessary complexity 🙂