[][src]Crate lm73

This is a platform agnostic Rust driver for the lm73 temperature sensor and thermal watchdog, based on the embedded-hal traits.

This driver allows you to:

  • Enable/disable the device.
  • Read the temperature.
  • Set the OS temperature.
  • Set the OS operation mode.

The device

The lm73 temperature sensor includes a delta-sigma analog-to-digital converter, and a digital overtemperature detector. The host can query the lm73 through its I2C interface to read temperature at any time.

Datasheet:

Usage examples (see also examples folder)

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Read temperature

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ Lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Lm73::new(dev, address);
let temp_celsius = sensor.read_temperature().unwrap();
println!("Temperature: {}ºC", temp_celsius);

Provide an alternative address

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ Lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let (a2, a1, a0) = (false, false, true);
let address = SlaveAddr::Alternative(a2, a1, a0);
let mut sensor = Lm73::new(dev, address);

Set the OneShot operation mode

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ Lm73, SlaveAddr, OsMode };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Lm73::new(dev, SlaveAddr::default());
sensor.set_os_mode(OsMode::Enabled).unwrap();

Set the HIGH_TEMP temperature

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ Lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Lm73::new(dev, SlaveAddr::default());
let temp_celsius = 50.0;
sensor.set_temperature_high(temp_celsius).unwrap();

Enable / disable the sensor

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ Lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Lm73::new(dev, SlaveAddr::default());
sensor.disable().unwrap(); // shutdown
sensor.enable().unwrap();

Structs

Lm73

Lm73 device driver.

Enums

AlertEnable

Alert Enable operation mode

Error

All possible errors in this crate

OsMode

OneShot operation mode

OsPolarity

OS polarity

Resolution

Resolution of temperature

SlaveAddr

Possible slave addresses