### Reading Hardware Sensors Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Example of how to parse available hardware monitors and read input values from temperature sensors. ```APIDOC ## Reading Temperature Sensors ### Description Parses the system's hardware monitors and iterates through temperature sensors to read their current input values. ### Request Example ```rust use libmedium::{ Hwmon, Hwmons, sensors::{Sensor, SensorBase}, }; let hwmons = Hwmons::parse_read_only().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); } } ``` ``` -------------------------------- ### Reading Temperature Sensors Source: https://docs.rs/libmedium/0.2.2/libmedium/index.html This example demonstrates how to iterate through all hardware monitoring devices (hwmons) and print the names and temperatures of all temperature sensors found. ```APIDOC ## Example: Reading Temperature Sensors ### Description This code snippet shows how to read the temperature of all temperature sensors available in the system using the `libmedium` crate. ### Usage ```rust use libmedium::{ Hwmon, Hwmons, sensors::{Sensor, SensorBase}, }; let hwmons = Hwmons::parse_read_only().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); } } ``` ``` -------------------------------- ### Error Handling Example Source: https://docs.rs/libmedium/0.2.2/libmedium/enum.ParsingError.html Demonstrates how to handle parsing errors by matching on the error type and printing the error message. This example shows a common pattern for dealing with potential parsing failures. ```rust if let Err(e) = "xc".parse::() { // Print `e` itself, no need for description(). eprintln!("Error: {}", e); } ``` -------------------------------- ### Setting Fan PWM to Full Speed Source: https://docs.rs/libmedium/0.2.2/libmedium/index.html This example shows how to set the Pulse Width Modulation (PWM) value for all controllable fans to 100% (full speed) using manual control. ```APIDOC ## Example: Setting Fan PWM to Full Speed ### Description This code snippet demonstrates how to set all PWM-capable fans to manual control and run them at 100% speed using the `libmedium` crate. ### Usage ```rust use libmedium::{ Hwmon, Hwmons, sensors::PwmSensor, units::{Pwm, PwmEnable}, }; let hwmons = Hwmons::parse_read_write().unwrap(); for (_, _, hwmon) in &hwmons { for (_, pwm) in hwmon.pwms() { pwm.write_enable(PwmEnable::ManualControl).unwrap(); pwm.write_pwm(Pwm::from_percent(100.0)).unwrap(); } } ``` ``` -------------------------------- ### Hwmons API Usage Source: https://docs.rs/libmedium/0.2.2/libmedium Examples of how to interact with the Hwmons struct to read sensor data or control hardware components like fans. ```APIDOC ## Reading Sensor Data ### Description Iterate through hardware monitoring devices to read temperature sensor inputs. ### Request Example ```rust use libmedium::{Hwmon, Hwmons, sensors::{Sensor, SensorBase}}; let hwmons = Hwmons::parse_read_only().unwrap(); for (hwmon_index, hwmon_name, hwmon) in &hwmons { for (_, temp_sensor) in hwmon.temps() { let temperature = temp_sensor.read_input().unwrap(); } } ``` ## Controlling PWM Fans ### Description Set PWM-capable fans to manual control and adjust their speed. ### Request Example ```rust use libmedium::{Hwmon, Hwmons, sensors::PwmSensor, units::{Pwm, PwmEnable}}; let hwmons = Hwmons::parse_read_write().unwrap(); for (_, _, hwmon) in &hwmons { for (_, pwm) in hwmon.pwms() { pwm.write_enable(PwmEnable::ManualControl).unwrap(); pwm.write_pwm(Pwm::from_percent(100.0)).unwrap(); } } ``` -------------------------------- ### Writing PWM Fan Control Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Example of how to set PWM sensors to manual control and update their speed percentage. ```APIDOC ## Setting PWM Fan Speed ### Description Configures PWM-capable fans to manual control mode and sets them to full speed (100%). ### Request Example ```rust use libmedium::{ Hwmon, Hwmons, sensors::PwmSensor, units::{Pwm, PwmEnable}, }; let hwmons = Hwmons::parse_read_write().unwrap(); for (_, _, hwmon) in &hwmons { for (_, pwm) in hwmon.pwms() { pwm.write_enable(PwmEnable::ManualControl).unwrap(); pwm.write_pwm(Pwm::from_percent(100.0)).unwrap(); } } ``` ``` -------------------------------- ### Get Hardware Monitor Path Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Returns the `PathBuf` for the current hardware monitor instance, joining the root path with the hwmon index. ```rust pub fn path(&self) -> PathBuf { self.root.join(format!("hwmon{}", self.index)) } ``` -------------------------------- ### Create and Open File for PWM Enable Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Conditionally creates and opens a file for PWM enable settings if `create_enable_file` is true. Writes '2\n' to the file. ```rust OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(&format!("pwm{}_enable", index))) .unwrap() .write(b"2\n") .unwrap(); ``` -------------------------------- ### Get Sensor State Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.WritableSensorBase.html Retrieves the current state of all writable subfunctions for the sensor. ```rust fn state(&self) -> Result ``` -------------------------------- ### Get Pwm as Percent Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Returns the PWM value of the Pwm struct as a floating-point percentage. ```rust pub fn as_percent(self) -> f64 ``` -------------------------------- ### Create and Open File for PWM Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Opens or creates a file for PWM settings, ensuring it's readable, writable, and truncated. Writes '0\n' to the file. ```rust OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(&format!("pwm{}", index))) .unwrap() .write(b"0\n") .unwrap(); ``` -------------------------------- ### Create Fan Enable File Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Creates a file to enable a fan, opening it with read/write/create/truncate options and writing '1\n'. ```rust .write(true) .create(true) .truncate(true) .open(self.path().join(format!("fan{}_enable", index))) .unwrap() .write(b"1\n") .unwrap(); ``` -------------------------------- ### Get Supported Write Subfunctions Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadWritePower.html Retrieves a list of all subfunction types that can be written to by this sensor. ```APIDOC ## GET /sensors/{id}/writable_subfunctions ### Description Returns a list of all writable subfunction types supported by this sensor. ### Method GET ### Endpoint `/sensors/{id}/writable_subfunctions` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the sensor. ### Response #### Success Response (200) - **subFunctions** (array) - A list of supported writable SensorSubFunctionType. #### Response Example ```json { "subFunctions": [ "Temperature", "Humidity" ] } ``` ``` -------------------------------- ### Sensor Path Operations Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadOnlyPower.html Provides a method to get the path of a sensor's subfunction. ```APIDOC ## GET /sensors/path ### Description Returns the path this sensor's subfunction of the given type would have. ### Method GET ### Endpoint /sensors/path ### Parameters #### Query Parameters - **sub_type** (SensorSubFunctionType) - Required - The type of subfunction to get the path for. ### Response #### Success Response (200) - **path** (PathBuf) - The file path of the sensor subfunction. #### Response Example ```json { "path": "/sys/bus/iio/devices/iio:device0/in_voltage0_raw" } ``` ``` -------------------------------- ### Virtual Hwmon Builder for Testing Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Utility for creating mock hardware monitor structures in the filesystem for unit testing. ```rust pub struct VirtualHwmonBuilder { root: PathBuf, index: u16, } impl VirtualHwmonBuilder { pub fn create( root: impl AsRef, index: u16, name: impl AsRef<[u8]>, ) -> VirtualHwmonBuilder { let path = root.as_ref().join(format!("hwmon{}", index)); fs::create_dir_all(&path).unwrap(); File::create(path.join("name")) .unwrap() .write(name.as_ref()) .unwrap(); VirtualHwmonBuilder { root: root.as_ref().to_path_buf(), index, } } pub fn add_temp( self, index: u16, value: i32, label: impl AsRef, ) -> VirtualHwmonBuilder { OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(format!("temp{}_input", index))) .unwrap() .write(value.to_string().as_bytes()) .unwrap(); OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(format!("temp{}_enable", index))) .unwrap() .write(b"1\n") .unwrap(); OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(format!("temp{}_label", index))) .unwrap() .write(label.as_ref().as_bytes()) .unwrap(); self } pub fn add_fan(self, index: u16, value: u32) -> VirtualHwmonBuilder { OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(format!("fan{}_input", index))) .unwrap() .write(value.to_string().as_bytes()) .unwrap(); OpenOptions::new() .read(true) ``` -------------------------------- ### Get Min Pwm Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Returns the minimum of two Pwm values. This is a nightly-only experimental API. ```rust #[must_use]fn min(self, other: Self) -> Self ``` -------------------------------- ### Get Max Pwm Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Returns the maximum of two Pwm values. This is a nightly-only experimental API. ```rust #[must_use]fn max(self, other: Self) -> Self ``` -------------------------------- ### Create and Open File for PWM Mode Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Conditionally creates and opens a file for PWM mode settings if `create_mode_file` is true. Writes '1\n' to the file. ```rust OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open(self.path().join(&format!("pwm{}_mode", index))) .unwrap() .write(b"1\n") .unwrap(); ``` -------------------------------- ### Hwmons Initialization Source: https://docs.rs/libmedium/0.2.2/libmedium/struct.Hwmons.html Methods to initialize the Hwmons struct by parsing system hardware monitoring paths. ```APIDOC ## parse_read_only ### Description Parses /sys/class/hwmon and returns the found hwmons as a read-only Hwmons object. ### Response - **Result, Error>** - Returns the Hwmons object or an error if parsing fails. ## parse_read_write ### Description Parses /sys/class/hwmon and returns the found hwmons as a read-write Hwmons object. Requires sufficient system privileges (usually root). ### Response - **Result, Error>** - Returns the Hwmons object or an error if parsing fails. ``` -------------------------------- ### Get Supported Write Sub-functions Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.WritableSensorBase.html Returns a list of all writable subfunction types that this sensor supports. ```rust fn supported_write_sub_functions(&self) -> Vec ``` -------------------------------- ### Get Pwm as u8 Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Returns the PWM value of the Pwm struct as a u8, in the range of 0 to 255. ```rust pub fn as_u8(self) -> u8 ``` -------------------------------- ### Keyboard Shortcut: Show Help Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadOnlyEnergy.html Pressing the '?' key displays the help dialog, providing information on available keyboard shortcuts. ```text ? ``` -------------------------------- ### Test Parsing of Virtual Hwmon Configurations Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html This test function demonstrates the creation of virtual hardware monitor configurations using `VirtualHwmonBuilder` and then parses them using `Hwmons::parse`. It includes assertions to verify the number of PWM, temperature, and fan entries, as well as the correct retrieval of specific entries by index and name. ```rust let test_path = Path::new("test_parse"); VirtualHwmonBuilder::create(test_path, 0, "system") .add_pwm(1, true, true) .add_pwm(2, true, true) .add_temp(1, 40000, "temp1") .add_temp(2, 60000, "temp2"); VirtualHwmonBuilder::create(test_path, 1, "other") .add_pwm(1, true, true) .add_temp(1, 40000, "temp1") .add_fan(2, 1000); let hwmons: Hwmons = Hwmons::parse(test_path).unwrap(); let hwmon0 = hwmons.hwmons_by_name("system").next().unwrap(); let hwmon1 = hwmons.hwmons_by_name("other").next().unwrap(); assert_eq!(hwmon0.name(), hwmons.hwmon_by_index(0).unwrap().name()); assert_eq!(hwmon1.name(), hwmons.hwmon_by_index(1).unwrap().name()); assert_eq!(hwmons.hwmon_by_index(2).is_none(), true); assert_eq!(hwmons.hwmons_by_name("alias").next().is_none(), true); assert_eq!(hwmon0.temps().len(), 2); assert_eq!(hwmon1.temps().len(), 1); assert_eq!(hwmon0.pwms().len(), 2); assert_eq!(hwmon1.pwms().len(), 1); hwmon0.pwms().get(&1u16).unwrap(); hwmon0.pwms().get(&2u16).unwrap(); hwmon1.pwms().get(&1u16).unwrap(); hwmon0.temps().get(&1u16).unwrap(); hwmon0.temps().get(&2u16).unwrap(); hwmon1.temps().get(&1u16).unwrap(); remove_dir_all(test_path).unwrap(); ``` -------------------------------- ### Initialize Hwmon Sensors Source: https://docs.rs/libmedium/0.2.2/src/libmedium/hwmon.rs.html Initializes various hardware monitoring sensors for a given hwmon structure. Ensure the correct count is provided for each sensor type. ```rust hwmon.humidities = init_sensors(&hwmon, 1)?; hwmon.powers = init_sensors(&hwmon, 1)?; hwmon.pwms = init_sensors(&hwmon, 1)?; hwmon.temps = init_sensors(&hwmon, 1)?; hwmon.voltages = init_sensors(&hwmon, 0)?; Ok(hwmon) } } ``` -------------------------------- ### Print error using Display Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Error.html Example of printing an error using the Display implementation instead of the deprecated description method. ```rust if let Err(e) = "xc".parse::() { // Print `e` itself, no need for description(). eprintln!("Error: {}", e); } ``` -------------------------------- ### Get Accuracy as Percent Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Accuracy.html Returns the Accuracy struct's value as a u8 percentage. This method consumes the Accuracy instance. ```rust pub fn as_percent(self) -> u8 ``` -------------------------------- ### Keyboard Shortcuts for Documentation Navigation Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadOnlyHumidity.html Common keyboard shortcuts for interacting with the documentation interface, including showing help, focusing search, navigating results, switching tabs, and expanding/collapsing sections. ```text ? ``` ```text S ``` ```text ↑ ``` ```text ↓ ``` ```text ↹ ``` ```text ⏎ ``` ```text + ``` ```text - ``` -------------------------------- ### Test sensor reading and label parsing Source: https://docs.rs/libmedium/0.2.2/src/libmedium/sensors/mod.rs.html Unit tests demonstrating how to use VirtualHwmonBuilder to mock hardware paths and verify sensor input readings and label parsing. ```rust #[test] fn test_sensor_read_value() { let test_path = Path::new("test_sensor_read_value"); VirtualHwmonBuilder::create(test_path, 0, "system") .add_temp(1, 40000, "temp1") .add_fan(1, 60); let hwmons: Hwmons = Hwmons::parse(test_path).unwrap(); let hwmon = hwmons.hwmon_by_index(0).unwrap(); let temp = ReadOnlyTemp::parse(hwmon, 1).unwrap(); let fan = ReadOnlyFan::parse(hwmon, 1).unwrap(); #[cfg(not(feature = "measurements_units"))] assert_eq!( Temperature::from_degrees_celsius(40.0), temp.read_input().unwrap() ); #[cfg(feature = "measurements_units")] assert_eq!(Temperature::from_celsius(40.0), temp.read_input().unwrap()); #[cfg(not(feature = "measurements_units"))] assert_eq!(60, fan.read_input().unwrap().as_rpm()); #[cfg(feature = "measurements_units")] assert_eq!(60.0, fan.read_input().unwrap().as_hertz() * 60.0); remove_dir_all(test_path).unwrap(); } ``` ```rust #[test] fn test_label() { let test_path = Path::new("test_label"); VirtualHwmonBuilder::create(test_path, 0, "system").add_temp(1, 40000, "test_temp1\n"); let hwmons: Hwmons = Hwmons::parse(test_path).unwrap(); let hwmon = hwmons.hwmon_by_index(0).unwrap(); let temp = ReadOnlyTemp::parse(hwmon, 1).unwrap(); assert_eq!(temp.name(), String::from("test_temp1")); remove_dir_all(test_path).unwrap(); } ``` -------------------------------- ### Keyboard Shortcut: Expand All Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadOnlyEnergy.html The '+' key expands all collapsible sections in the documentation. ```text + ``` -------------------------------- ### Keyboard Shortcuts Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Temperature.html A list of keyboard shortcuts for navigating the documentation and interacting with search features. ```APIDOC ## Keyboard Shortcuts `?` Show this help dialog `S` Focus the search field `↑` Move up in search results `↓` Move down in search results `↹` Switch tab `⏎` Go to active search result `+` Expand all sections `-` Collapse all sections ``` -------------------------------- ### Parse Hwmon sensors Source: https://docs.rs/libmedium/0.2.2/src/libmedium/hwmon.rs.html Initializes a Hwmon instance by parsing sensor data from a filesystem path. Requires a valid parent path and index. ```rust type Parent = Hwmons; fn parse(parent: &Self::Parent, index: u16) -> ParsingResult { let path = parent.path().join(format!("hwmon{}", index)); check_path(&path)?; let mut hwmon = Self { name: get_name(&path)?, path, currs: BTreeMap::new(), energies: BTreeMap::new(), fans: BTreeMap::new(), humidities: BTreeMap::new(), powers: BTreeMap::new(), pwms: BTreeMap::new(), temps: BTreeMap::new(), voltages: BTreeMap::new(), }; hwmon.currs = init_sensors(&hwmon, 1)?; hwmon.energies = init_sensors(&hwmon, 1)?; hwmon.fans = init_sensors(&hwmon, 1)?; hwmon.humidities = init_sensors(&hwmon, 1)?; hwmon.powers = init_sensors(&hwmon, 1)?; hwmon.pwms = init_sensors(&hwmon, 1)?; hwmon.temps = init_sensors(&hwmon, 1)?; hwmon.voltages = init_sensors(&hwmon, 0)?; Ok(hwmon) } } ``` ```rust fn parse(parent: &Self::Parent, index: u16) -> ParsingResult { let path = parent.path().join(format!("hwmon{}", index)); check_path(&path)?; let mut hwmon = Self { name: get_name(&path)?, path, currs: BTreeMap::new(), energies: BTreeMap::new(), fans: BTreeMap::new(), humidities: BTreeMap::new(), powers: BTreeMap::new(), pwms: BTreeMap::new(), temps: BTreeMap::new(), voltages: BTreeMap::new(), }; hwmon.currs = init_sensors(&hwmon, 1)?; hwmon.energies = init_sensors(&hwmon, 1)?; hwmon.fans = init_sensors(&hwmon, 1)?; ``` -------------------------------- ### Clone Pwm from Source Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Implements the clone_from method for Pwm, enabling copy-assignment. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Keyboard Shortcuts Source: https://docs.rs/libmedium/0.2.2/src/libmedium/units/native/temperature.rs.html Common keyboard shortcuts for navigating the documentation website. ```APIDOC ## Keyboard Shortcuts * `?` - Show this help dialog * `S` - Focus the search field * `↑` - Move up in search results * `↓` - Move down in search results * `↹` - Switch tab * `⏎` - Go to active search result * `+` - Expand all sections * `-` - Collapse all sections ``` -------------------------------- ### Keyboard Shortcuts Source: https://docs.rs/libmedium/0.2.2/libmedium/all.html Common keyboard shortcuts for navigating the documentation. ```APIDOC ## Keyboard Shortcuts - `?`: Show this help dialog - `S`: Focus the search field - `↑`: Move up in search results - `↓`: Move down in search results - `↹`: Switch tab - `⏎`: Go to active search result - `+`: Expand all sections - `-`: Collapse all sections ``` -------------------------------- ### Documentation Navigation and Search Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.EnergySensor.html Provides information on keyboard shortcuts and search tricks for navigating and searching within the documentation. ```APIDOC ## Keyboard Shortcuts - `?`: Show this help dialog - `S`: Focus the search field - `↑`: Move up in search results - `↓`: Move down in search results - `↹`: Switch tab - `⏎`: Go to active search result - `+`: Expand all sections - `-`: Collapse all sections ## Search Tricks - Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type. Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. - Search functions by type signature (e.g., `vec -> usize` or `* -> vec`). - Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`). - Look for items with an exact name by putting double quotes around your request: `"string"`. - Look for items inside another one by searching for a path: `vec::Vec`. ``` -------------------------------- ### Power Struct Methods Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Power.html Methods for creating and converting Power instances. ```APIDOC ## Power::from_watts ### Description Create a Power struct from a value measuring watts. ### Parameters - **degrees** (impl Into) - Required - The power value in watts. ## Power::from_microwatts ### Description Create a Power struct from a value measuring microwatts. ### Parameters - **microwatts** (impl Into) - Required - The power value in microwatts. ## Power::as_watts ### Description Returns this struct's value as watts. ### Response - **f64** - The power value in watts. ## Power::as_microwatts ### Description Returns this struct's value as microwatts. ### Response - **u32** - The power value in microwatts. ``` -------------------------------- ### Parse Hwmon Directories Source: https://docs.rs/libmedium/0.2.2/src/libmedium/lib.rs.html Methods for parsing hardware monitor paths, including read-only and read-write variants. ```rust impl Hwmons { /// Parses /sys/class/hwmon and returns the found hwmons as a Hwmons object. pub fn parse_read_only() -> ParsingResult { Self::parse(HWMON_PATH) } } ``` ```rust #[cfg(feature = "writable")] impl Hwmons { /// Parses /sys/class/hwmon and returns the found hwmons as a Hwmons object. /// Be sure you have sufficient rights to write to your sensors. Usually only root has those rights. pub fn parse_read_write() -> ParsingResult { Self::parse(HWMON_PATH) } /// Parses the given path and returns the found hwmons as a `Hwmons` object. /// This function should only be used for debug and test purposes. Usually you should use /// parse_read_write() or parse_read_only(). #[cfg(feature = "unrestricted_parsing")] pub fn parse_path(path: impl AsRef) -> ParsingResult { Self::parse(path) } } ``` -------------------------------- ### Voltage Struct Methods Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Voltage.html Methods for creating and converting Voltage instances. ```APIDOC ## Voltage Struct Methods ### Description Methods to instantiate a Voltage object from different units and convert them back. ### Methods - **from_milli_volts(millis: i32) -> Voltage**: Create a Voltage struct from millivolts. - **as_milli_volts(self) -> i32**: Return the value in millivolts. - **from_volts(volts: impl Into) -> Voltage**: Create a Voltage struct from volts. - **as_volts(self) -> f64**: Return the value in volts. ``` -------------------------------- ### Trait Implementations and Conversions Source: https://docs.rs/libmedium/0.2.2/libmedium/hwmon/struct.ReadOnlyHwmon.html Overview of standard trait implementations for data borrowing, ownership, and type conversion. ```APIDOC ## Trait Implementations ### BorrowMut - **fn borrow_mut(&mut self) -> &mut T**: Mutably borrows from an owned value. ### From - **fn from(t: T) -> T**: Performs the conversion from T to T. ### Into - **fn into(self) -> U**: Performs the conversion from T to U. ### ToOwned - **type Owned = T**: The resulting type after obtaining ownership. - **fn to_owned(&self) -> T**: Creates owned data from borrowed data, usually by cloning. - **fn clone_into(&self, target: &mut T)**: Uses borrowed data to replace owned data (Nightly-only). ### TryFrom - **type Error = Infallible**: The type returned in the event of a conversion error. - **fn try_from(value: U) -> Result>::Error>**: Performs the conversion. ### TryInto - **type Error = >::Error**: The type returned in the event of a conversion error. - **fn try_into(self) -> Result>::Error>**: Performs the conversion. ``` -------------------------------- ### libmedium::units Module Overview Source: https://docs.rs/libmedium/0.2.2/libmedium/units/index.html Overview of the structs, enums, and traits available in the libmedium::units module for sensor data representation. ```APIDOC ## libmedium::units Module ### Description This module defines the units and data structures used for sensor readings within the libmedium library. ### Structs - **Accuracy**: Represents the accuracy of a power sensor. - **AngularVelocity**: Represents a frequency. - **Current**: Represents an electrical current. - **Energy**: Represents used energy. - **Error**: Error returned from reading raw sensor values. - **FanDivisor**: Represents a fan divisor (must be powers of two). - **Frequency**: Represents a frequency. - **Humidity**: Represents humidity. - **Power**: Represents electrical power. - **Pwm**: Represents a PWM value between 0 and 255. - **Temperature**: Represents a temperature. - **Voltage**: Represents an electrical voltage. ### Enums - **PwmEnable**: Represents the control states a PWM can be in. - **PwmMode**: Represents the modes by which a fan's speed can be regulated. - **TempType**: Represents the different temperature sensor types. ### Traits - **Raw**: Trait to be implemented by types that raw sensor strings should be converted into. ``` -------------------------------- ### Temperature Struct Methods Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Temperature.html Methods for creating and converting Temperature instances. ```APIDOC ## Temperature Struct Methods ### Description Methods to instantiate a Temperature struct from various units and retrieve values in specific units. ### Methods - **from_degrees_celsius(degrees: impl Into) -> Self**: Create a Temperature struct from degrees Celsius. - **from_millidegrees_celsius(millidegrees: impl Into) -> Self**: Create a Temperature struct from millidegrees Celsius. - **from_degrees_fahrenheit(degrees: impl Into) -> Self**: Create a Temperature struct from degrees Fahrenheit. - **as_degrees_celsius(self) -> f64**: Returns the value as degrees Celsius. - **as_millidegrees_celsius(self) -> i32**: Returns the value as millidegrees Celsius. - **as_degrees_fahrenheit(self) -> f64**: Returns the value as degrees Fahrenheit. ``` -------------------------------- ### Search Tricks Source: https://docs.rs/libmedium/0.2.2/libmedium/all.html Tips for using the search functionality effectively. ```APIDOC ## Search Tricks - Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type. Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. - Search functions by type signature (e.g., `vec -> usize` or `* -> vec`). - Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`). - Look for items with an exact name by putting double quotes around your request: `"string"`. - Look for items inside another one by searching for a path: `vec::Vec`. ``` -------------------------------- ### Current Trait Implementations Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Current.html Demonstrates various trait implementations for the Current struct, enabling operations like addition, averaging, debugging, and more. ```APIDOC ## Trait Implementations for Current ### `impl Add for Current` #### `type Output = Self` #### `fn add(self, other: Self) -> Self` Performs the `+` operation. ### `impl Average for S` #### `fn read_average(&self) -> Result` Reads this sensor's average value. ### `impl Clone for Current` #### `fn clone(&self) -> Current` Returns a copy of the value. #### `fn clone_from(&mut self, source: &Self)` Performs copy-assignment from `source`. ### `impl Copy for Current` ### `impl Crit for S` #### `fn read_crit(&self) -> Result` Reads this sensor's crit value. #### `fn write_crit(&self, crit: P) -> Result<(), Error>` Writes this sensor's crit value. ### `impl Debug for Current` #### `fn fmt(&self, f: &mut Formatter) -> Result` Formats the value using the given formatter. ### `impl Display for Current` #### `fn fmt(&self, f: &mut Formatter) -> Result` Formats the value using the given formatter. ### `impl> Div for Current` #### `type Output = Self` #### `fn div(self, other: T) -> Current` Performs the `/` operation. ### `impl Eq for Current` ### `impl Hash for Current` #### `fn hash<__H: Hasher>(&self, state: &mut __H)` Feeds this value into the given `Hasher`. #### `fn hash_slice(data: &[Self], state: &mut H) where H: Hasher` Feeds a slice of this type into the given `Hasher`. ### `impl Highest for S` #### `fn read_highest(&self) -> Result` Reads this sensor's historically highest input. ### `impl LowCrit for S` #### `fn read_lcrit(&self) -> Result` Reads this sensor's lcrit value. #### `fn write_lcrit(&self, lcrit: P) -> Result<(), Error>` Writes this sensor's lcrit value. ### `impl Lowest for S` #### `fn read_lowest(&self) -> Result` Reads this sensor's historically lowest input. ### `impl Max for S` #### `fn read_max(&self) -> Result` Reads this sensor's max value. #### `fn write_max(&self, max: P) -> Result<(), Error>` Writes this sensor's max value. ### `impl Min for S` #### `fn read_min(&self) -> Result` Reads this sensor's min value. #### `fn write_min(&self, min: P) -> Result<(), Error>` Writes this sensor's min value. ``` -------------------------------- ### Expand All Sections Keyboard Shortcut Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.Faulty.html Press the '+' key to expand all sections. ```text '+' ``` -------------------------------- ### Keyboard Shortcuts for Docs.rs Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.Highest.html Provides a list of keyboard shortcuts for navigating and interacting with the Docs.rs documentation interface. These shortcuts can improve efficiency when browsing documentation. ```text ? Show this help dialog S Focus the search field ↑ Move up in search results ↓ Move down in search results ↹ Switch tab ⏎ Go to active search result + Expand all sections - Collapse all sections ``` -------------------------------- ### Search Tricks Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Temperature.html Tips and tricks for using the search functionality effectively, including type prefixes, signature searches, and exact matching. ```APIDOC ## Search Tricks Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type. Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. Search functions by type signature (e.g., `vec -> usize` or `* -> vec`) Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`) You can look for items with an exact name by putting double quotes around your request: `"string"` Look for items inside another one by searching for a path: `vec::Vec` ``` -------------------------------- ### libmedium-0.2.2 API Documentation Source: https://docs.rs/libmedium/0.2.2/libmedium/all.html This section details the available structs, enums, and traits within the libmedium-0.2.2 crate. ```APIDOC ## libmedium-0.2.2 API Documentation ### Structs - Hwmons - Iter - hwmon::ReadOnlyHwmon - hwmon::ReadWriteHwmon - sensors::ReadOnlyCurr - sensors::ReadOnlyEnergy - sensors::ReadOnlyFan - sensors::ReadOnlyHumidity - sensors::ReadOnlyPower - sensors::ReadOnlyPwm - sensors::ReadOnlyTemp - sensors::ReadOnlyVolt - sensors::ReadWriteCurr - sensors::ReadWriteEnergy - sensors::ReadWriteFan - sensors::ReadWriteHumidity - sensors::ReadWritePower - sensors::ReadWritePwm - sensors::ReadWriteTemp - sensors::ReadWriteVolt - sensors::SensorState - units::Accuracy - units::AngularVelocity - units::Current - units::Energy - units::Error - units::FanDivisor - units::Frequency - units::Humidity - units::Power - units::Pwm - units::Temperature - units::Voltage ### Enums - ParsingError - sensors::Error - sensors::SensorSubFunctionType - units::PwmEnable - units::PwmMode - units::TempType ### Traits - hwmon::Hwmon - sensors::Average - sensors::Crit - sensors::CurrSensor - sensors::EnergySensor - sensors::FanSensor - sensors::Faulty - sensors::Highest - sensors::HumiditySensor - sensors::LowCrit - sensors::Lowest - sensors::Max - sensors::Min - sensors::PowerSensor - sensors::PwmSensor - sensors::Sensor - sensors::SensorBase - sensors::TempSensor - sensors::VoltSensor - sensors::WritableSensorBase - units::Raw ``` -------------------------------- ### Construct Pwm from Percent Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Creates a Pwm struct from a floating-point percentage value. ```rust pub fn from_percent(percent: f64) -> Self ``` -------------------------------- ### Implement SensorBase for ReadWriteFan Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadWriteFan.html Implements basic sensor functionalities for ReadWriteFan, such as retrieving the base type, index, hardware monitoring path, supported read sub-functions, name, and raw reading capabilities. ```rust fn base(&self) -> &'static str ``` ```rust fn index(&self) -> u16 ``` ```rust fn hwmon_path(&self) -> &Path ``` ```rust fn supported_read_sub_functions(&self) -> Vec ``` ```rust fn name(&self) -> String ``` ```rust fn read_raw(&self, sub_type: SensorSubFunctionType) -> Result ``` ```rust fn subfunction_path(&self, sub_type: SensorSubFunctionType) -> PathBuf ``` -------------------------------- ### Raw Trait Implementation Source: https://docs.rs/libmedium/0.2.2/src/libmedium/units/mod.rs.html Demonstrates the implementation of the `Raw` trait for common types like bool, String, and Duration, enabling conversion from raw sensor strings. ```APIDOC ## Trait: Raw ### Description Trait that needs to be implemented by all types that raw sensor strings should be converted into. ### Methods - `from_raw(raw: &str) -> Result`: Converts a raw sensor string into a usable type. - `to_raw(&self) -> Cow`: Converts self into a writable raw sensor string. ### Implementations #### `impl Raw for bool` - `from_raw(raw: &str) -> Result`: Converts "1" to `true` and "0" to `false`. Returns an error for other inputs. - `to_raw(&self) -> Cow`: Returns `"1"` for `true` and `"0"` for `false`. #### `impl Raw for String` - `from_raw(raw: &str) -> Result`: Trims whitespace and returns the string. - `to_raw(&self) -> Cow`: Returns the string as a borrowed `Cow`. #### `impl Raw for Duration` - `from_raw(raw: &str) -> Result`: Parses the string as milliseconds and converts it to a `Duration`. Returns an error if parsing fails. - `to_raw(&self) -> Cow`: Returns the duration in milliseconds as a string. ``` -------------------------------- ### Hwmon Trait Methods Source: https://docs.rs/libmedium/0.2.2/libmedium/hwmon/trait.Hwmon.html Methods for retrieving hardware monitoring data maps from an Hwmon implementation. ```APIDOC ## Hwmon Trait Methods ### Description Provides access to various hardware monitoring metrics stored in BTreeMaps indexed by a u16 identifier. ### Methods - **currents()**: Returns a reference to a BTreeMap of Current values. - **energies()**: Returns a reference to a BTreeMap of Energy values. - **fans()**: Returns a reference to a BTreeMap of Fan values. - **humidities()**: Returns a reference to a BTreeMap of Humidity values. - **powers()**: Returns a reference to a BTreeMap of Power values. - **pwms()**: Returns a reference to a BTreeMap of Pwm values. - **temps()**: Returns a reference to a BTreeMap of Temp values. - **voltages()**: Returns a reference to a BTreeMap of Voltage values. ``` -------------------------------- ### Hwmon Trait Methods Source: https://docs.rs/libmedium/0.2.2/src/libmedium/hwmon.rs.html Methods available for interacting with hardware monitoring interfaces. ```APIDOC ## GET /hwmon/info ### Description Retrieves metadata and sensor collections for a hardware monitoring instance. ### Method GET ### Parameters #### Path Parameters - **index** (u16) - Optional - The specific index of the sensor to retrieve. ### Response #### Success Response (200) - **name** (str) - The name of the hwmon instance. - **path** (Path) - The filesystem path of the hwmon instance. - **sensors** (BTreeMap) - A collection of sensors mapped by their index. ``` -------------------------------- ### Initialize sensors from hwmon Source: https://docs.rs/libmedium/0.2.2/src/libmedium/hwmon.rs.html Initializes a collection of sensors of a specific type from a given hwmon parent. It iterates through possible sensor indices, attempting to parse each one until an error occurs or parsing is no longer possible. ```Rust fn init_sensors(hwmon: &H, start_index: u16) -> ParsingResult> where S: SensorBase + Parseable, H: Hwmon, { let mut sensors = BTreeMap::new(); for index in start_index.. { match S::parse(hwmon, index) { Ok(sensor) => { sensors.insert(index, sensor); } Err(sensor_error) => match sensor_error { ParsingError::InsufficientRights { path } => { return Err(ParsingError::InsufficientRights { path }) } _ => break, }, } } Ok(sensors) } ``` -------------------------------- ### Check Pwm Inequality Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Pwm.html Implements the inequality comparison for Pwm using the ne method. ```rust fn ne(&self, other: &Pwm) -> bool ``` -------------------------------- ### Temperature Equality and Ordering Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Temperature.html Defines how Temperature values are compared for equality and their ordering relationships. ```APIDOC ## Temperature Equality and Ordering ### Description Defines how Temperature values are compared for equality and their ordering relationships. ### Methods #### `eq(&self, other: &Temperature) -> bool` Tests for equality between two Temperature values (`==`). #### `ne(&self, other: &Temperature) -> bool` Tests for inequality between two Temperature values (`!=`). #### `partial_cmp(&self, other: &Temperature) -> Option` Returns an ordering between two Temperature values if one exists. #### `lt(&self, other: &Temperature) -> bool` Tests if `self` is less than `other` (`<`). #### `le(&self, other: &Temperature) -> bool` Tests if `self` is less than or equal to `other` (`<=`). #### `gt(&self, other: &Temperature) -> bool` Tests if `self` is greater than `other` (`>`). #### `ge(&self, other: &Temperature) -> bool` Tests if `self` is greater than or equal to `other` (`>=`). ``` -------------------------------- ### SensorBase Required Method: hwmon_path() Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.SensorBase.html Returns the hardware monitoring path for the sensor. This method must be implemented by all types that implement the SensorBase trait. ```rust fn hwmon_path(&self) -> &Path; ``` -------------------------------- ### Compare Temperatures Source: https://docs.rs/libmedium/0.2.2/libmedium/units/struct.Temperature.html Compares two Temperature instances and returns an Ordering. ```rust fn cmp(&self, other: &Temperature) -> Ordering ``` -------------------------------- ### Keyboard Shortcut: Collapse All Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadOnlyEnergy.html The '-' key collapses all collapsible sections in the documentation. ```text - ``` -------------------------------- ### Search Trick: Multiple Queries Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/struct.ReadOnlyEnergy.html Search for multiple items simultaneously by separating your queries with a comma (e.g., `str,u8`). ```text str,u8 ``` -------------------------------- ### Search Tricks for Docs.rs Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.Highest.html Explains advanced search techniques for Docs.rs, including prefix searches, type filtering, searching by function signature, and combining multiple search queries. Exact name and path searches are also supported. ```text Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type. Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. Search functions by type signature (e.g., `vec -> usize` or `* -> vec`) Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`) You can look for items with an exact name by putting double quotes around your request: `"string"` Look for items inside another one by searching for a path: `vec::Vec` ``` -------------------------------- ### Collapse All Sections Keyboard Shortcut Source: https://docs.rs/libmedium/0.2.2/libmedium/sensors/trait.Faulty.html Press the '-' key to collapse all sections. ```text '-' ```