mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add initial dbus draft of asus_armoury attrs
This commit is contained in:
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
use zbus::zvariant::Type;
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
use crate::error::PlatformError;
|
||||
|
||||
@@ -31,7 +31,15 @@ fn read_string(path: &Path) -> Result<String, PlatformError> {
|
||||
Ok(buf.trim().to_string())
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Type, Value, OwnedValue)]
|
||||
pub enum AttrType {
|
||||
MinMax = 0,
|
||||
EnumInt = 1,
|
||||
EnumStr = 2,
|
||||
Unbounded = 3,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
|
||||
pub enum AttrValue {
|
||||
Integer(i32),
|
||||
String(String),
|
||||
@@ -41,7 +49,7 @@ pub enum AttrValue {
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Attribute {
|
||||
name: String,
|
||||
help: String,
|
||||
@@ -62,6 +70,20 @@ impl Attribute {
|
||||
&self.help
|
||||
}
|
||||
|
||||
pub fn attribute_type(&self) -> AttrType {
|
||||
let mut attr_type = AttrType::Unbounded;
|
||||
match self.max_value {
|
||||
AttrValue::Integer(_) => attr_type = AttrType::MinMax,
|
||||
_ => {}
|
||||
}
|
||||
match self.possible_values {
|
||||
AttrValue::EnumInt(_) => attr_type = AttrType::EnumInt,
|
||||
AttrValue::EnumStr(_) => attr_type = AttrType::EnumStr,
|
||||
_ => {}
|
||||
}
|
||||
attr_type
|
||||
}
|
||||
|
||||
/// Read the `current_value` directly from the attribute path
|
||||
pub fn current_value(&self) -> Result<AttrValue, PlatformError> {
|
||||
match read_string(&self.base_path.join("current_value")) {
|
||||
|
||||
Reference in New Issue
Block a user