Skip to content

Commit

Permalink
hwcaps: Add new crate for checking hardware capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronErhardt committed Nov 14, 2023
1 parent bcbe216 commit dcdab5e
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"tailor_api": "0.2.3",
"tailor_client": "0.2.3",
"tailor_cli": "0.2.3",
"tailor_gui": "0.2.3"
"tailor_gui": "0.2.3",
"tailor_hwcaps": "0.2.0"
}
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[workspace]
resolver = "2"
members = [
"tuxedo_ioctl",
"tuxedo_sysfs",
"tailord",
"tailor_api",
"tailor_client",
"tailor_cli",
"tailor_hwcaps",
]

exclude = [
Expand Down
3 changes: 3 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
"tailor_gui": {
"release-type": "rust"
},
"tailor_hwcaps": {
"release-type": "rust"
}
}
}
13 changes: 13 additions & 0 deletions tailor_hwcaps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "tailor_hwcaps"
version = "0.2.0"
edition = "2021"

description = "A crate for checking the hardware capabilities on different devices"

[dependencies]
sudo = "0.6.0"
tokio-uring = "0.4.0"

tuxedo_ioctl = { path = "../tuxedo_ioctl" }
tuxedo_sysfs = { path = "../tuxedo_sysfs" }
110 changes: 110 additions & 0 deletions tailor_hwcaps/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use std::fmt::Debug;

fn print_value<T: Debug>(property: &str, value: &T) {
println!("[OK] {property}: {value:?}");
}

fn print_info(property: &str) {
println!("[INFO] {property}");
}

fn print_err<T: Debug>(property: &str, value: &T) {
println!("[ERR] {property}: {value:?}");
}

fn print_fatal<T: Debug>(property: &str, value: &T) {
println!("[FATAL] {property}: {value:?}");
}

fn print_result<T: Debug, E: Debug>(property: &str, value: &Result<T, E>) {
match value {
Ok(ok) => print_value(property, ok),
Err(err) => print_err(property, err),
}
}

fn main() {
sudo::escalate_if_needed().unwrap();

ioctl();

tokio_uring::start(sysfs());
}

fn ioctl() {
let io = tuxedo_ioctl::hal::IoInterface::new();
let io = match io {
Ok(io) => io,
Err(err) => {
print_fatal("Connecting to ioctl interface failed", &err);
return;
}
};

print_value("Module version", &io.module_version);

print_result("Device interface ID", &io.device.device_interface_id_str());
print_result("Model ID", &io.device.device_model_id_str());

print_result(
"Available ODM performance profiles",
&io.device.get_available_odm_performance_profiles(),
);
print_result(
"Default ODM performance profile",
&io.device.get_default_odm_performance_profile(),
);

print_value("Number of fans", &io.device.get_number_fans());
let fan_temperatures = (0..io.device.get_number_fans())
.map(|fan| io.device.get_fan_temperature(fan))
.collect::<Result<Vec<_>, _>>();
let fan_speeds = (0..io.device.get_number_fans())
.map(|fan| io.device.get_fan_speed_percent(fan))
.collect::<Result<Vec<_>, _>>();
print_result("Fan temperatures [°C]", &fan_temperatures);
print_result("Fan speeds [%]", &fan_speeds);
print_result("Fan min speed [%]", &io.device.get_fans_min_speed());

if let Some(webcam) = &io.webcam {
print_result("Webcam enabled", &webcam.get_webcam());
} else {
print_info("Webcam control is not available");
}

if let Some(tdp) = &io.tdp {
let number_of_tdp_devices = tdp.get_number_tdps();
print_result("number_of_tdp_devices", &number_of_tdp_devices);
print_result("tdp_descriptors", &tdp.get_tdp_descriptors());

let number_of_tdp_devices = number_of_tdp_devices.unwrap_or_default();
let tdps = (0..number_of_tdp_devices)
.map(|tdp_index| tdp.get_tdp(tdp_index))
.collect::<Result<Vec<_>, _>>();
let max_tdps = (0..number_of_tdp_devices)
.map(|tdp_index| tdp.get_tdp_max(tdp_index))
.collect::<Result<Vec<_>, _>>();
let min_tdps = (0..number_of_tdp_devices)
.map(|tdp_index| tdp.get_tdp_min(tdp_index))
.collect::<Result<Vec<_>, _>>();

print_result("tdps", &tdps);
print_result("max_tdps", &max_tdps);
print_result("min_tdps", &min_tdps);
} else {
print_info("TDP control is not available");
}
}

async fn sysfs() {
let led_collection = tuxedo_sysfs::led::Collection::new().await.unwrap();
print_value("Number of LED devices", &led_collection.len());

for (idx, mut controller) in led_collection.into_inner().into_iter().enumerate() {
print_value("LED device number", &idx);
print_value("LED device name", &controller.device_name());
print_value("LED device function", &controller.function());
print_value("LED mode", &controller.mode());
print_value("LED device color", &controller.get_color().await);
}
}
3 changes: 3 additions & 0 deletions tuxedo_sysfs/src/led/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
mod collection;
mod controller;

/// A collection of controllers for LED devices.
/// Stores a [`Vec`] of [`Controller`] and initializes by
/// detecting all available LED devices via sysfs.
#[derive(Debug)]
pub struct Collection {
controllers: Vec<Controller>,
Expand Down

0 comments on commit dcdab5e

Please sign in to comment.