steamosctl: Use more enums instead of u32 where applicable

This commit is contained in:
Vicki Pfau 2024-05-13 16:45:46 -07:00
parent 936bdb220c
commit d027445d9d
2 changed files with 18 additions and 16 deletions

View file

@ -9,9 +9,11 @@ use anyhow::Result;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use itertools::Itertools; use itertools::Itertools;
use std::ops::Deref; use std::ops::Deref;
use steamos_manager::cec::HdmiCecState;
use steamos_manager::hardware::FanControlState;
use steamos_manager::power::GPUPerformanceLevel; use steamos_manager::power::GPUPerformanceLevel;
use steamos_manager::proxy::ManagerProxy; use steamos_manager::proxy::ManagerProxy;
use steamos_manager::wifi::WifiBackend; use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement};
use zbus::fdo::PropertiesProxy; use zbus::fdo::PropertiesProxy;
use zbus::names::InterfaceName; use zbus::names::InterfaceName;
use zbus::{zvariant, Connection}; use zbus::{zvariant, Connection};
@ -36,8 +38,8 @@ enum Commands {
/// Set the fan control state /// Set the fan control state
SetFanControlState { SetFanControlState {
/// 0 - BIOS, 1 - OS /// Valid options are bios, os
state: u32, state: FanControlState,
}, },
/// Get the fan control state /// Get the fan control state
@ -45,7 +47,7 @@ enum Commands {
/// Set the GPU performance level /// Set the GPU performance level
SetGPUPerformanceLevel { SetGPUPerformanceLevel {
/// Allowed levels are auto, low, high, manual, peak_performance /// Valid levels are auto, low, high, manual, peak_performance
level: GPUPerformanceLevel, level: GPUPerformanceLevel,
}, },
@ -96,8 +98,8 @@ enum Commands {
/// Set wifi debug mode /// Set wifi debug mode
SetWifiDebugMode { SetWifiDebugMode {
/// 1 for on, 0 for off /// Valid modes are on, off
mode: u32, mode: WifiDebugMode,
/// The size of the debug buffer, in bytes /// The size of the debug buffer, in bytes
#[arg(default_value_t = 20000)] #[arg(default_value_t = 20000)]
buffer: u32, buffer: u32,
@ -108,8 +110,8 @@ enum Commands {
/// Set the wifi power management state /// Set the wifi power management state
SetWifiPowerManagementState { SetWifiPowerManagementState {
/// 0 - disabled, 1 - enabled /// Valid modes are enabled, disabled
state: u32, state: WifiPowerManagement,
}, },
/// Get the wifi power management state /// Get the wifi power management state
@ -120,8 +122,8 @@ enum Commands {
/// Set the state of HDMI-CEC support /// Set the state of HDMI-CEC support
SetHdmiCecState { SetHdmiCecState {
/// 0 - disabled, 1 - only controls, 2 - Controls and TV waking /// Valid modes are disabled, control-only, control-and-wake
state: u32, state: HdmiCecState,
}, },
/// Update the BIOS, if possible /// Update the BIOS, if possible
@ -180,7 +182,7 @@ async fn main() -> Result<()> {
println!("Version: {version}"); println!("Version: {version}");
} }
Commands::SetFanControlState { state } => { Commands::SetFanControlState { state } => {
proxy.set_fan_control_state(*state).await?; proxy.set_fan_control_state(*state as u32).await?;
} }
Commands::SetGPUPerformanceLevel { level } => { Commands::SetGPUPerformanceLevel { level } => {
proxy.set_gpu_performance_level(*level as u32).await?; proxy.set_gpu_performance_level(*level as u32).await?;
@ -235,21 +237,21 @@ async fn main() -> Result<()> {
println!("Wifi backend: {backend_string}"); println!("Wifi backend: {backend_string}");
} }
Commands::SetWifiDebugMode { mode, buffer } => { Commands::SetWifiDebugMode { mode, buffer } => {
proxy.set_wifi_debug_mode(*mode, *buffer).await?; proxy.set_wifi_debug_mode(*mode as u32, *buffer).await?;
} }
Commands::GetWifiDebugMode => { Commands::GetWifiDebugMode => {
let mode = proxy.wifi_debug_mode_state().await?; let mode = proxy.wifi_debug_mode_state().await?;
println!("Wifi debug mode: {mode}"); println!("Wifi debug mode: {mode}");
} }
Commands::SetWifiPowerManagementState { state } => { Commands::SetWifiPowerManagementState { state } => {
proxy.set_wifi_power_management_state(*state).await?; proxy.set_wifi_power_management_state(*state as u32).await?;
} }
Commands::GetWifiPowerManagementState => { Commands::GetWifiPowerManagementState => {
let state = proxy.wifi_power_management_state().await?; let state = proxy.wifi_power_management_state().await?;
println!("Wifi power management state: {state}"); println!("Wifi power management state: {state}");
} }
Commands::SetHdmiCecState { state } => { Commands::SetHdmiCecState { state } => {
proxy.set_hdmi_cec_state(*state).await?; proxy.set_hdmi_cec_state(*state as u32).await?;
} }
Commands::GetHdmiCecState => { Commands::GetHdmiCecState => {
let state = proxy.hdmi_cec_state().await?; let state = proxy.hdmi_cec_state().await?;

View file

@ -14,16 +14,16 @@ use tokio::signal::unix::{signal, SignalKind};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
use tracing::{info, warn}; use tracing::{info, warn};
mod cec;
mod ds_inhibit; mod ds_inhibit;
mod error; mod error;
mod hardware;
mod manager; mod manager;
mod process; mod process;
mod sls; mod sls;
mod systemd; mod systemd;
pub mod cec;
pub mod daemon; pub mod daemon;
pub mod hardware;
pub mod power; pub mod power;
pub mod proxy; pub mod proxy;
pub mod wifi; pub mod wifi;