25 releases

new 0.8.0 Apr 22, 2024
0.7.0 Aug 18, 2022
0.6.3 Apr 14, 2022
0.6.0 Nov 7, 2021
0.1.1 Nov 24, 2019

#88 in Hardware support

Download history 234/week @ 2024-01-03 37/week @ 2024-01-10 145/week @ 2024-01-17 308/week @ 2024-01-24 262/week @ 2024-01-31 386/week @ 2024-02-07 369/week @ 2024-02-14 565/week @ 2024-02-21 409/week @ 2024-02-28 45/week @ 2024-03-06 288/week @ 2024-03-13 219/week @ 2024-03-20 81/week @ 2024-03-27 247/week @ 2024-04-03 62/week @ 2024-04-10 187/week @ 2024-04-17

610 downloads per month
Used in 2 crates

MIT license

255KB
5.5K 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.8"

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.

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, Sensor},
};

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–1.5MB
~27K SLoC