#pwm #fan #sensor #hwmon

libmedium

Library to interface with lm_sensors

19 unstable releases (4 breaking)

0.5.5 Mar 23, 2021
0.5.3 Jan 20, 2021
0.5.0 Nov 26, 2020
0.2.2 Jun 30, 2020
0.1.1 Nov 24, 2019

#53 in Hardware support

Download history 43/week @ 2021-04-03 39/week @ 2021-04-10 17/week @ 2021-04-17 8/week @ 2021-04-24 22/week @ 2021-05-01 4/week @ 2021-05-08 21/week @ 2021-05-15 1/week @ 2021-05-22 3/week @ 2021-05-29 21/week @ 2021-06-05 8/week @ 2021-06-12 2/week @ 2021-06-19 9/week @ 2021-06-26 6/week @ 2021-07-03 8/week @ 2021-07-10 28/week @ 2021-07-17

157 downloads per month
Used in rasp_mgr

MIT license

120KB
3K 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.5"

Cargo-Features

Standard features

  • writeable: Standard feature that enables all functions that write to sysfs. This includes setting pwm values and disabling 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.

Examples

  • Print the temperature of all the temp sensors in your system:
use libmedium::{
    parse_hwmons,
    sensors::{Input, Sensor},
};

let hwmons = parse_hwmons().unwrap();
for (hwmon_index, hwmon_name, 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::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::from_percent(100.0)).unwrap();
    }
}

License

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

Dependencies

~210KB