copterust / bmp280

embedded-hal compatible driver for bmp280 pressure sensor
7 stars 12 forks source link

Incorrect status calculation #2

Closed regexident closed 3 years ago

regexident commented 4 years ago

The expression 1 == status & 0b00001000 will always evaluate to false.

Wrong:

/// Returns device status
pub fn status(&mut self) -> Status {
    let status = self.read_byte(Register::status);
    Status {
        measuring: (1 == status & 0b00001000),
        im_update: (1 == status & 0b00000001),
    }
}

Correct:

/// Returns device status
pub fn status(&mut self) -> Status {
    let status = self.read_byte(Register::status);
    Status {
        measuring: (status & 0b00001000) != 0b0,
        im_update: (status & 0b00000001) != 0b0,
    }
}
little-arhat commented 3 years ago

Thanks, indeed.