Skip to main content

Thermometer

Struct Thermometer 

Source
pub struct Thermometer { /* private fields */ }
Expand description

A DS18B20 the kernel exposes as a w1_slave file.

§Examples

use pamoja_core::Sensor;
use pamoja_sensors::ds18b20::linux::Thermometer;

let mut probe = Thermometer::new("000005e2fdc3");
let scratchpad = probe.read().await?;
println!("{:.4} C", scratchpad.temperature_celsius());

Implementations§

Source§

impl Thermometer

Source

pub fn new(serial: &str) -> Thermometer

Names a thermometer by the serial in its directory name.

§Arguments
  • serial - the twelve hex digits after 28- in the device directory.
§Returns

The thermometer, reading /sys/bus/w1/devices/28-<serial>/w1_slave.

Source

pub fn at(path: impl Into<PathBuf>) -> Thermometer

Names a thermometer by the path of its w1_slave file.

§Arguments
  • path - the file to read.
§Returns

The thermometer.

Source

pub fn path(&self) -> &Path

Returns the path of the file the thermometer reads.

Source

pub fn serial(&self) -> Option<&str>

Returns the serial the kernel named the thermometer’s directory after.

§Returns

The twelve hex digits after 28-, as in 000005e2fdc3, which tell one probe from another and stay with the part for life. None when the file does not sit in a DS18B20’s directory, as a thermometer named by at may not.

§Examples
use pamoja_sensors::ds18b20::linux::Thermometer;

assert_eq!(Thermometer::new("000005e2fdc3").serial(), Some("000005e2fdc3"));
assert_eq!(Thermometer::at("/tmp/w1_slave").serial(), None);
Source

pub fn discover() -> Result<Vec<Thermometer>>

Lists every DS18B20 the kernel has found.

§Returns

One thermometer per 28-* directory under DEVICES.

§Errors

Returns the I/O error if the directory cannot be listed, which usually means the 1-Wire overlay is not enabled.

Source

pub fn discover_in(devices: &Path) -> Result<Vec<Thermometer>>

Lists every DS18B20 directory under devices.

§Arguments
  • devices - the directory the kernel lists its 1-Wire devices in.
§Returns

One thermometer per directory whose name starts with the DS18B20 family code, sorted by name.

§Errors

Returns the I/O error if the directory cannot be listed.

Source

pub fn read_scratchpad(&self) -> Result<Scratchpad, ThermometerError>

Reads the file, which makes the kernel run a conversion, and decodes it.

§Returns

The CRC-checked scratchpad.

§Errors

Returns ThermometerError::Io if the file cannot be read and ThermometerError::Sensor if it does not decode.

Trait Implementations§

Source§

impl Clone for Thermometer

Source§

fn clone(&self) -> Thermometer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Thermometer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Thermometer

Source§

impl PartialEq for Thermometer

Source§

fn eq(&self, other: &Thermometer) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Sensor for Thermometer

Source§

type Reading = Scratchpad

The value produced by a single read, for example a temperature or a fix.
Source§

async fn read(&mut self) -> Result<Scratchpad>

Takes a single reading from the sensor. Read more
§

fn map<F, T>(self, select: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Reading) -> T,

Wraps this sensor so every reading passes through select first. Read more
Source§

impl StructuralPartialEq for Thermometer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.