29 releases

0.12.0 Nov 15, 2024
0.11.0 Jul 2, 2024
0.10.0 Jul 2, 2024
0.7.0 Aug 18, 2022
0.1.1 Nov 24, 2019

#55 in Hardware support

Download history 403/week @ 2024-08-18 127/week @ 2024-08-25 528/week @ 2024-09-01 897/week @ 2024-09-08 823/week @ 2024-09-15 982/week @ 2024-09-22 629/week @ 2024-09-29 784/week @ 2024-10-06 615/week @ 2024-10-13 292/week @ 2024-10-20 467/week @ 2024-10-27 1027/week @ 2024-11-03 796/week @ 2024-11-10 648/week @ 2024-11-17 342/week @ 2024-11-24 339/week @ 2024-12-01

2,142 downloads per month
Used in 3 crates

MIT license

275KB
6K SLoC

unsafe forbidden License

libmedium

A safe rust library to communicate with the sysfs interface of lm-sensors.

Usage

Just add this to your Cargo.toml file:

[dependencies]
libmedium = "0.12"

Cargo-Features

Standard features

  • writeable: Standard feature that enables all functions that write to sysfs. This includes setting pwm values and disabling sensors.
  • sync: Build synchronous versions of all sensors.
  • virtual_sensors: Feature that lets you create virtual sensors. Virtual sensors don't belong to sysfs but can be any file provided by a driver or the user.

Non standard features

  • uom_units: Sensor values are returned as types from the uom crate.
  • unrestricted_parsing: This feature allows parsing of paths other than '/sys/class/hwmon'. This should only be useful for testing and debugging.
  • async: Build asynchronous versions of all sensors.

Examples

  • Print the temperature of all the temp sensors in your system:
use libmedium::{
    parse_hwmons,
    sensors::sync_sensors::{temp::TempSensor, SyncSensor},
};

let hwmons = parse_hwmons().unwrap();
for hwmon in &hwmons {
    println!("hwmon{} with name {}:", hwmon.index(), hwmon.name());
    for (_, temp_sensor) in hwmon.temps() {
        let temperature = temp_sensor.read_input().unwrap();
        println!("\t{}: {}", temp_sensor.name(), temperature);
    }
}
  • Set the pwm value of all your pwm capable fans to full speed (this requires the writeable feature to not be disabled):
use libmedium::{
    parse_hwmons,
    sensors::sync_sensors::pwm::WriteablePwmSensor,
    units::{Pwm, PwmEnable},
};

let hwmons = parse_hwmons().unwrap();
for hwmon in &hwmons {
    for (_, pwm) in hwmon.writeable_pwms() {
        pwm.write_enable(PwmEnable::ManualControl).unwrap();
        pwm.write_pwm(Pwm::FULLSPEED).unwrap();
    }
}

License

This project is licensed under the MIT License - see the LICENSE file for details

Dependencies

~0–6MB
~26K SLoC