2021-08-02 16:00:07 +02:00
|
|
|
use gumdrop::Options;
|
|
|
|
|
2021-12-03 07:35:17 +01:00
|
|
|
use amdgpu::utils::hw_mons;
|
|
|
|
use amdgpu_config::fan::Config;
|
|
|
|
|
2021-11-17 17:28:09 +01:00
|
|
|
use crate::{AmdFanError, FanMode};
|
2021-12-03 07:35:17 +01:00
|
|
|
use crate::command::Fan;
|
2021-08-02 16:00:07 +02:00
|
|
|
|
|
|
|
/// Change card fan mode to either automatic or manual
|
2021-11-17 17:28:09 +01:00
|
|
|
pub fn run(switcher: Switcher, mode: FanMode, config: Config) -> crate::Result<()> {
|
|
|
|
let mut hw_mons = Fan::wrap_all(hw_mons(true)?, &config);
|
2021-08-02 16:00:07 +02:00
|
|
|
|
|
|
|
let cards = match switcher.card {
|
2021-08-21 19:12:17 +02:00
|
|
|
Some(card_id) => match hw_mons.iter().position(|hw_mon| **hw_mon.card() == card_id) {
|
|
|
|
Some(card) => vec![hw_mons.remove(card)],
|
2021-08-02 16:00:07 +02:00
|
|
|
None => {
|
|
|
|
eprintln!("Card does not exists. Available cards: ");
|
2021-08-21 19:12:17 +02:00
|
|
|
for hw_mon in hw_mons {
|
|
|
|
eprintln!(" * {}", *hw_mon.card());
|
2021-08-02 16:00:07 +02:00
|
|
|
}
|
2021-11-17 17:28:09 +01:00
|
|
|
return Err(AmdFanError::NoAmdCardFound);
|
2021-08-02 16:00:07 +02:00
|
|
|
}
|
|
|
|
},
|
2021-08-21 19:12:17 +02:00
|
|
|
None => hw_mons,
|
2021-08-02 16:00:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for hw_mon in cards {
|
|
|
|
match mode {
|
|
|
|
FanMode::Automatic => {
|
2021-11-17 17:28:09 +01:00
|
|
|
if let Err(e) = hw_mon.write_automatic() {
|
2021-08-02 16:00:07 +02:00
|
|
|
log::error!("{:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FanMode::Manual => {
|
2021-11-17 17:28:09 +01:00
|
|
|
if let Err(e) = hw_mon.write_manual() {
|
2021-08-02 16:00:07 +02:00
|
|
|
log::error!("{:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Options)]
|
|
|
|
pub struct Switcher {
|
|
|
|
#[options(help = "Print help message")]
|
|
|
|
help: bool,
|
|
|
|
#[options(help = "GPU Card number")]
|
|
|
|
card: Option<u32>,
|
|
|
|
}
|