diff options
| author | Ulf Lilleengen <[email protected]> | 2025-11-03 08:18:21 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-03 08:18:21 +0000 |
| commit | 3e7fdef2dc510a3e2b4c9d92c33c8c28fd44b25d (patch) | |
| tree | 11b2836ee9d2fc8023ecc0702683505c62911264 | |
| parent | 836b46f8df59ed22d13d11833b66397a26d89eed (diff) | |
| parent | 719c2bbbb89c0121bbd2b62f9aeb98327e583d2b (diff) | |
Merge pull request #4826 from mikeytdisco/temp_fix
Correct the temperature reading to preserve the sign bits
| -rw-r--r-- | examples/rp/src/bin/pio_onewire.rs | 2 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_onewire_parasite.rs | 2 | ||||
| -rw-r--r-- | examples/rp235x/src/bin/pio_onewire.rs | 2 | ||||
| -rw-r--r-- | examples/rp235x/src/bin/pio_onewire_parasite.rs | 2 | ||||
| -rw-r--r-- | examples/stm32g0/src/bin/onewire_ds18b20.rs | 2 |
5 files changed, 5 insertions, 5 deletions
diff --git a/examples/rp/src/bin/pio_onewire.rs b/examples/rp/src/bin/pio_onewire.rs index 102f13c45..6432edb8a 100644 --- a/examples/rp/src/bin/pio_onewire.rs +++ b/examples/rp/src/bin/pio_onewire.rs | |||
| @@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) { | |||
| 61 | let mut data = [0; 9]; | 61 | let mut data = [0; 9]; |
| 62 | onewire.read_bytes(&mut data).await; | 62 | onewire.read_bytes(&mut data).await; |
| 63 | if crc8(&data) == 0 { | 63 | if crc8(&data) == 0 { |
| 64 | let temp = ((data[1] as u32) << 8 | data[0] as u32) as f32 / 16.; | 64 | let temp = ((data[1] as i16) << 8 | data[0] as i16) as f32 / 16.; |
| 65 | info!("Read device {:x}: {} deg C", device, temp); | 65 | info!("Read device {:x}: {} deg C", device, temp); |
| 66 | } else { | 66 | } else { |
| 67 | warn!("Reading device {:x} failed", device); | 67 | warn!("Reading device {:x} failed", device); |
diff --git a/examples/rp/src/bin/pio_onewire_parasite.rs b/examples/rp/src/bin/pio_onewire_parasite.rs index fd076dee0..78fb94b18 100644 --- a/examples/rp/src/bin/pio_onewire_parasite.rs +++ b/examples/rp/src/bin/pio_onewire_parasite.rs | |||
| @@ -63,7 +63,7 @@ async fn main(_spawner: Spawner) { | |||
| 63 | let mut data = [0; 9]; | 63 | let mut data = [0; 9]; |
| 64 | onewire.read_bytes(&mut data).await; | 64 | onewire.read_bytes(&mut data).await; |
| 65 | if crc8(&data) == 0 { | 65 | if crc8(&data) == 0 { |
| 66 | let temp = ((data[1] as u32) << 8 | data[0] as u32) as f32 / 16.; | 66 | let temp = ((data[1] as i16) << 8 | data[0] as i16) as f32 / 16.; |
| 67 | info!("Read device {:x}: {} deg C", device, temp); | 67 | info!("Read device {:x}: {} deg C", device, temp); |
| 68 | } else { | 68 | } else { |
| 69 | warn!("Reading device {:x} failed. {:02x}", device, data); | 69 | warn!("Reading device {:x} failed. {:02x}", device, data); |
diff --git a/examples/rp235x/src/bin/pio_onewire.rs b/examples/rp235x/src/bin/pio_onewire.rs index 102f13c45..6432edb8a 100644 --- a/examples/rp235x/src/bin/pio_onewire.rs +++ b/examples/rp235x/src/bin/pio_onewire.rs | |||
| @@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) { | |||
| 61 | let mut data = [0; 9]; | 61 | let mut data = [0; 9]; |
| 62 | onewire.read_bytes(&mut data).await; | 62 | onewire.read_bytes(&mut data).await; |
| 63 | if crc8(&data) == 0 { | 63 | if crc8(&data) == 0 { |
| 64 | let temp = ((data[1] as u32) << 8 | data[0] as u32) as f32 / 16.; | 64 | let temp = ((data[1] as i16) << 8 | data[0] as i16) as f32 / 16.; |
| 65 | info!("Read device {:x}: {} deg C", device, temp); | 65 | info!("Read device {:x}: {} deg C", device, temp); |
| 66 | } else { | 66 | } else { |
| 67 | warn!("Reading device {:x} failed", device); | 67 | warn!("Reading device {:x} failed", device); |
diff --git a/examples/rp235x/src/bin/pio_onewire_parasite.rs b/examples/rp235x/src/bin/pio_onewire_parasite.rs index fd076dee0..78fb94b18 100644 --- a/examples/rp235x/src/bin/pio_onewire_parasite.rs +++ b/examples/rp235x/src/bin/pio_onewire_parasite.rs | |||
| @@ -63,7 +63,7 @@ async fn main(_spawner: Spawner) { | |||
| 63 | let mut data = [0; 9]; | 63 | let mut data = [0; 9]; |
| 64 | onewire.read_bytes(&mut data).await; | 64 | onewire.read_bytes(&mut data).await; |
| 65 | if crc8(&data) == 0 { | 65 | if crc8(&data) == 0 { |
| 66 | let temp = ((data[1] as u32) << 8 | data[0] as u32) as f32 / 16.; | 66 | let temp = ((data[1] as i16) << 8 | data[0] as i16) as f32 / 16.; |
| 67 | info!("Read device {:x}: {} deg C", device, temp); | 67 | info!("Read device {:x}: {} deg C", device, temp); |
| 68 | } else { | 68 | } else { |
| 69 | warn!("Reading device {:x} failed. {:02x}", device, data); | 69 | warn!("Reading device {:x} failed. {:02x}", device, data); |
diff --git a/examples/stm32g0/src/bin/onewire_ds18b20.rs b/examples/stm32g0/src/bin/onewire_ds18b20.rs index 62f8711a6..43ecca8c4 100644 --- a/examples/stm32g0/src/bin/onewire_ds18b20.rs +++ b/examples/stm32g0/src/bin/onewire_ds18b20.rs | |||
| @@ -267,7 +267,7 @@ where | |||
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | match Self::crc8(&data) == 0 { | 269 | match Self::crc8(&data) == 0 { |
| 270 | true => Ok(((data[1] as u16) << 8 | data[0] as u16) as f32 / 16.), | 270 | true => Ok(((data[1] as i16) << 8 | data[0] as i16) as f32 / 16.), |
| 271 | false => Err(()), | 271 | false => Err(()), |
| 272 | } | 272 | } |
| 273 | } | 273 | } |
