Skip to content

Commit 0412a40

Browse files
committed
no more deadcode
1 parent 2659fc0 commit 0412a40

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

libs/cramium-hal/src/bmp180.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
use cramium_api::{I2cApi, I2cResult};
22

33
pub const BMP180_ADDR: u8 = 0x77;
4+
#[cfg(feature = "std")]
45
const REG_CALIB_START: u8 = 0xAA;
56
const REG_CTRL: u8 = 0xF4;
67
const REG_DATA_START: u8 = 0xF6;
78
const CMD_READ_TEMP: u8 = 0x2E;
89

910
#[derive(Debug, Clone, Copy)]
1011

12+
#[allow(dead_code)]
1113
struct Bmp180Calibration {
12-
ac1: i16, ac2: i16, ac3: i16,
13-
ac4: u16, ac5: u16, ac6: u16,
14-
b1: i16, b2: i16,
15-
mb: i16, mc: i16, md: i16,
14+
ac1: i16,
15+
ac2: i16,
16+
ac3: i16,
17+
ac4: u16,
18+
ac5: u16,
19+
ac6: u16,
20+
b1: i16,
21+
b2: i16,
22+
mb: i16,
23+
mc: i16,
24+
md: i16,
1625
}
1726

1827
pub struct Bmp180 {
@@ -32,26 +41,34 @@ impl Bmp180 {
3241
Err(_) => return Err(I2cResult::InternalError),
3342
}
3443

44+
// note: calibration data is Big Endian, hence the from_be_bytes
3545
let calibration = Bmp180Calibration {
3646
ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]),
3747
ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]),
3848
ac3: i16::from_be_bytes([cal_buf[4], cal_buf[5]]),
3949
ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]),
4050
ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]),
4151
ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]),
42-
b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]),
43-
b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]),
44-
mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]),
45-
mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]),
46-
md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]),
52+
b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]),
53+
b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]),
54+
mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]),
55+
mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]),
56+
md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]),
4757
};
4858

49-
if calibration.ac1 == 0 || calibration.ac2 == 0 || calibration.ac3 == 0 ||
50-
calibration.ac4 == 0 || calibration.ac5 == 0 || calibration.ac6 == 0 ||
51-
calibration.b1 == 0 || calibration.b2 == 0 ||
52-
calibration.mb == 0 || calibration.mc == 0 || calibration.md == 0 ||
53-
calibration.ac1 == -1 {
54-
// Return an error indicating the data from the sensor is invalid.
59+
if calibration.ac1 == 0
60+
|| calibration.ac2 == 0
61+
|| calibration.ac3 == 0
62+
|| calibration.ac4 == 0
63+
|| calibration.ac5 == 0
64+
|| calibration.ac6 == 0
65+
|| calibration.b1 == 0
66+
|| calibration.b2 == 0
67+
|| calibration.mb == 0
68+
|| calibration.mc == 0
69+
|| calibration.md == 0
70+
|| calibration.ac1 == -1
71+
{
5572
return Err(I2cResult::InternalError);
5673
}
5774

services/bao-console/src/cmds/test.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use String;
2-
32
use cram_hal_service::I2c;
4-
use cramium_hal::bmp180::Bmp180; // Correctly import from the library
3+
use cramium_hal::bmp180::Bmp180;
54

65
use crate::{CommonEnv, ShellCmdApi};
76

@@ -23,27 +22,23 @@ impl<'a> ShellCmdApi<'a> for Test {
2322
if let Some(sub_cmd) = tokens.next() {
2423
match sub_cmd {
2524
"temp" => {
26-
// Initialize I2C connection
2725
let mut i2c = I2c::new();
2826

29-
// Attempt to initialize the BMP180 sensor
3027
match Bmp180::new(&mut i2c) {
31-
Ok(sensor) => {
32-
// If successful, attempt to read the temperature
33-
match sensor.read_temperature(&mut i2c) {
34-
Ok(temp) => {
35-
write!(ret, "BMP180 Temperature: {:.1}°C", temp).unwrap();
36-
}
37-
Err(e) => {
38-
write!(ret, "Failed to read temperature: {:?}", e).unwrap();
39-
}
28+
Ok(sensor) => match sensor.read_temperature(&mut i2c) {
29+
Ok(temp) => {
30+
write!(ret, "BMP180 Temperature: {:.1}°C", temp).unwrap();
4031
}
41-
}
32+
Err(e) => {
33+
write!(ret, "Failed to read temperature: {:?}", e).unwrap();
34+
}
35+
},
4236
Err(e) => {
4337
write!(ret, "Failed to initialize BMP180 sensor: {:?}", e).unwrap();
4438
}
4539
}
4640
}
41+
4742
_ => {
4843
write!(ret, "{}", helpstring).unwrap();
4944
}

0 commit comments

Comments
 (0)