mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 09:52:00 -04:00
hardware: Allow string codec for DeviceType and SteamDeckVariant
This commit is contained in:
parent
8c52189d98
commit
7a04e45dca
1 changed files with 6 additions and 15 deletions
|
@ -5,7 +5,7 @@
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{bail, ensure, Error, Result};
|
use anyhow::{bail, ensure, Result};
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use strum::{Display, EnumString};
|
use strum::{Display, EnumString};
|
||||||
|
@ -21,7 +21,8 @@ const SYS_VENDOR_PATH: &str = "/sys/class/dmi/id/sys_vendor";
|
||||||
const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name";
|
const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name";
|
||||||
const PRODUCT_NAME_PATH: &str = "/sys/class/dmi/id/product_name";
|
const PRODUCT_NAME_PATH: &str = "/sys/class/dmi/id/product_name";
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Default, Copy, Clone)]
|
#[derive(Display, EnumString, PartialEq, Debug, Default, Copy, Clone)]
|
||||||
|
#[strum(serialize_all = "snake_case", ascii_case_insensitive)]
|
||||||
pub(crate) enum SteamDeckVariant {
|
pub(crate) enum SteamDeckVariant {
|
||||||
#[default]
|
#[default]
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -29,7 +30,8 @@ pub(crate) enum SteamDeckVariant {
|
||||||
Galileo,
|
Galileo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Default, Copy, Clone)]
|
#[derive(Display, EnumString, PartialEq, Debug, Default, Copy, Clone)]
|
||||||
|
#[strum(serialize_all = "snake_case", ascii_case_insensitive)]
|
||||||
pub(crate) enum DeviceType {
|
pub(crate) enum DeviceType {
|
||||||
#[default]
|
#[default]
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -47,17 +49,6 @@ pub enum FanControlState {
|
||||||
Os = 1,
|
Os = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for SteamDeckVariant {
|
|
||||||
type Err = Error;
|
|
||||||
fn from_str(input: &str) -> Result<SteamDeckVariant, Self::Err> {
|
|
||||||
Ok(match input {
|
|
||||||
"Jupiter" => SteamDeckVariant::Jupiter,
|
|
||||||
"Galileo" => SteamDeckVariant::Galileo,
|
|
||||||
_ => SteamDeckVariant::Unknown,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Display, EnumString, PartialEq, Debug, Copy, Clone, TryFromPrimitive)]
|
#[derive(Display, EnumString, PartialEq, Debug, Copy, Clone, TryFromPrimitive)]
|
||||||
#[strum(ascii_case_insensitive)]
|
#[strum(ascii_case_insensitive)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
|
@ -73,7 +64,7 @@ pub(crate) async fn steam_deck_variant() -> Result<SteamDeckVariant> {
|
||||||
return Ok(SteamDeckVariant::Unknown);
|
return Ok(SteamDeckVariant::Unknown);
|
||||||
}
|
}
|
||||||
let board_name = fs::read_to_string(path(BOARD_NAME_PATH)).await?;
|
let board_name = fs::read_to_string(path(BOARD_NAME_PATH)).await?;
|
||||||
SteamDeckVariant::from_str(board_name.trim_end())
|
Ok(SteamDeckVariant::from_str(board_name.trim_end()).unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn device_type() -> Result<DeviceType> {
|
pub(crate) async fn device_type() -> Result<DeviceType> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue