mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
no more deadcode
This commit is contained in:
parent
2659fc0894
commit
0412a401d8
2 changed files with 41 additions and 29 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
use cramium_api::{I2cApi, I2cResult};
|
use cramium_api::{I2cApi, I2cResult};
|
||||||
|
|
||||||
pub const BMP180_ADDR: u8 = 0x77;
|
pub const BMP180_ADDR: u8 = 0x77;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
const REG_CALIB_START: u8 = 0xAA;
|
const REG_CALIB_START: u8 = 0xAA;
|
||||||
const REG_CTRL: u8 = 0xF4;
|
const REG_CTRL: u8 = 0xF4;
|
||||||
const REG_DATA_START: u8 = 0xF6;
|
const REG_DATA_START: u8 = 0xF6;
|
||||||
|
|
@ -8,11 +9,19 @@ const CMD_READ_TEMP: u8 = 0x2E;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
struct Bmp180Calibration {
|
struct Bmp180Calibration {
|
||||||
ac1: i16, ac2: i16, ac3: i16,
|
ac1: i16,
|
||||||
ac4: u16, ac5: u16, ac6: u16,
|
ac2: i16,
|
||||||
b1: i16, b2: i16,
|
ac3: i16,
|
||||||
mb: i16, mc: i16, md: i16,
|
ac4: u16,
|
||||||
|
ac5: u16,
|
||||||
|
ac6: u16,
|
||||||
|
b1: i16,
|
||||||
|
b2: i16,
|
||||||
|
mb: i16,
|
||||||
|
mc: i16,
|
||||||
|
md: i16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Bmp180 {
|
pub struct Bmp180 {
|
||||||
|
|
@ -32,6 +41,7 @@ impl Bmp180 {
|
||||||
Err(_) => return Err(I2cResult::InternalError),
|
Err(_) => return Err(I2cResult::InternalError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// note: calibration data is Big Endian, hence the from_be_bytes
|
||||||
let calibration = Bmp180Calibration {
|
let calibration = Bmp180Calibration {
|
||||||
ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]),
|
ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]),
|
||||||
ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]),
|
ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]),
|
||||||
|
|
@ -39,19 +49,26 @@ impl Bmp180 {
|
||||||
ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]),
|
ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]),
|
||||||
ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]),
|
ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]),
|
||||||
ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]),
|
ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]),
|
||||||
b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]),
|
b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]),
|
||||||
b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]),
|
b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]),
|
||||||
mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]),
|
mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]),
|
||||||
mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]),
|
mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]),
|
||||||
md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]),
|
md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]),
|
||||||
};
|
};
|
||||||
|
|
||||||
if calibration.ac1 == 0 || calibration.ac2 == 0 || calibration.ac3 == 0 ||
|
if calibration.ac1 == 0
|
||||||
calibration.ac4 == 0 || calibration.ac5 == 0 || calibration.ac6 == 0 ||
|
|| calibration.ac2 == 0
|
||||||
calibration.b1 == 0 || calibration.b2 == 0 ||
|
|| calibration.ac3 == 0
|
||||||
calibration.mb == 0 || calibration.mc == 0 || calibration.md == 0 ||
|
|| calibration.ac4 == 0
|
||||||
calibration.ac1 == -1 {
|
|| calibration.ac5 == 0
|
||||||
// Return an error indicating the data from the sensor is invalid.
|
|| calibration.ac6 == 0
|
||||||
|
|| calibration.b1 == 0
|
||||||
|
|| calibration.b2 == 0
|
||||||
|
|| calibration.mb == 0
|
||||||
|
|| calibration.mc == 0
|
||||||
|
|| calibration.md == 0
|
||||||
|
|| calibration.ac1 == -1
|
||||||
|
{
|
||||||
return Err(I2cResult::InternalError);
|
return Err(I2cResult::InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use String;
|
use String;
|
||||||
|
|
||||||
use cram_hal_service::I2c;
|
use cram_hal_service::I2c;
|
||||||
use cramium_hal::bmp180::Bmp180; // Correctly import from the library
|
use cramium_hal::bmp180::Bmp180;
|
||||||
|
|
||||||
use crate::{CommonEnv, ShellCmdApi};
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
|
|
@ -23,27 +22,23 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
"temp" => {
|
"temp" => {
|
||||||
// Initialize I2C connection
|
|
||||||
let mut i2c = I2c::new();
|
let mut i2c = I2c::new();
|
||||||
|
|
||||||
// Attempt to initialize the BMP180 sensor
|
|
||||||
match Bmp180::new(&mut i2c) {
|
match Bmp180::new(&mut i2c) {
|
||||||
Ok(sensor) => {
|
Ok(sensor) => match sensor.read_temperature(&mut i2c) {
|
||||||
// If successful, attempt to read the temperature
|
Ok(temp) => {
|
||||||
match sensor.read_temperature(&mut i2c) {
|
write!(ret, "BMP180 Temperature: {:.1}°C", temp).unwrap();
|
||||||
Ok(temp) => {
|
|
||||||
write!(ret, "BMP180 Temperature: {:.1}°C", temp).unwrap();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
write!(ret, "Failed to read temperature: {:?}", e).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
|
write!(ret, "Failed to read temperature: {:?}", e).unwrap();
|
||||||
|
}
|
||||||
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
write!(ret, "Failed to initialize BMP180 sensor: {:?}", e).unwrap();
|
write!(ret, "Failed to initialize BMP180 sensor: {:?}", e).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue