Skip to content

Commit

Permalink
Updated msg_type to be more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
ohunter committed May 7, 2024
1 parent 4f02678 commit 65feddc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ impl<'a> I2CTransfer<'a> for LinuxI2CDevice {
/// Issue the provided sequence of I2C transactions
fn transfer(&mut self, messages: &'a mut [Self::Message]) -> Result<u32, LinuxI2CError> {
let msg_type = |flag: u16| flag & I2CMessageFlags::READ.bits();
let mut prev_msg_type = !msg_type(messages[0].flags);
let mut prev_msg_type = messages.first().map(|m| msg_type(m.flags));
for msg in messages.iter_mut() {
msg.addr = self.slave_address;

let cur_msg_type = msg_type(msg.flags);
if prev_msg_type == cur_msg_type {
if prev_msg_type.is_some_and(|prev| prev == cur_msg_type) {
msg.flags |= I2CMessageFlags::NO_START.bits();
} else {
prev_msg_type = cur_msg_type;
prev_msg_type = Some(cur_msg_type);
}
}
ffi::i2c_rdwr(self.as_raw_fd(), messages).map_err(From::from)
Expand Down

0 comments on commit 65feddc

Please sign in to comment.