Skip to content

Commit

Permalink
Minor test of platform attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
flukejones committed Dec 27, 2024
1 parent a1a9c70 commit fd3384d
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 333 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Added
- asus-armoury driver support. WIP, will be adjusted/changed further

## [v6.1.0-rc1]

### Added
Expand Down
10 changes: 10 additions & 0 deletions asusctl/src/cli_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum CliCommand {
Scsi(ScsiCommand),
#[options(help = "Change bios settings")]
Platform(PlatformCommand),
#[options(help = "Change platform settings")]
PlatformNew(PlatformNewCommand),
}

#[derive(Debug, Clone, Options)]
Expand Down Expand Up @@ -121,3 +123,11 @@ pub struct PlatformCommand {
#[options(no_long, short = "o", help = "get panel overdrive")]
pub panel_overdrive_get: bool,
}

#[derive(Options, Debug)]
pub struct PlatformNewCommand {
#[options(help = "print help message")]
pub help: bool,
#[options(free)]
pub free: Vec<String>,
}
56 changes: 54 additions & 2 deletions asusctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rog_anime::usb::get_anime_type;
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, Vec2};
use rog_aura::keyboard::{AuraPowerState, LaptopAuraPower};
use rog_aura::{self, AuraDeviceType, AuraEffect, PowerZones};
use rog_dbus::asus_armoury::AsusArmouryProxyBlocking;
use rog_dbus::list_iface_blocking;
use rog_dbus::scsi_aura::ScsiAuraProxyBlocking;
use rog_dbus::zbus_anime::AnimeProxyBlocking;
Expand Down Expand Up @@ -140,13 +141,13 @@ where
// e.to_owned()).collect(); println!("{}, {:?}", v.0, o);
for k in v.1.keys() {
if k.as_str() == iface_name {
println!("Found {iface_name} device at {}, {}", v.0, k);
// println!("Found {iface_name} device at {}, {}", v.0, k);
paths.push(v.0.clone());
}
}
}
if paths.len() > 1 {
println!("Multiple aura devices found: {paths:?}");
println!("Multiple asusd interfaces devices found");
}
if !paths.is_empty() {
let mut ctrl = Vec::new();
Expand Down Expand Up @@ -187,6 +188,7 @@ fn do_parsed(
Some(CliCommand::Platform(cmd)) => {
handle_platform_properties(&conn, supported_properties, cmd)?
}
Some(CliCommand::PlatformNew(cmd)) => handle_platform_new_properties(&conn, cmd)?,
None => {
if (!parsed.show_supported
&& parsed.kbd_bright.is_none()
Expand Down Expand Up @@ -1066,3 +1068,53 @@ fn check_systemd_unit_enabled(name: &str) -> bool {
}
false
}

fn handle_platform_new_properties(
conn: &Connection,
cmd: &PlatformNewCommand,
) -> Result<(), Box<dyn std::error::Error>> {
{
if cmd.free.is_empty() || cmd.help {
println!("Missing arg or command\n");

let usage: Vec<String> = PlatformCommand::usage()
.lines()
.map(|s| s.to_owned())
.collect();
}

if let Ok(attr) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
for attr in attr.iter() {
let name = attr.name()?;
let attrs = attr.available_attrs()?;
// dbg!(&name, &attrs);
println!("{name}::");
if attrs.contains(&"defalt_value".to_string()) {
let v = attr.default_value()?;
println!(" default_value: {v:?}");
}
if attrs.contains(&"min_value".to_string()) {
let v = attr.min_value()?;
println!(" min_value: {v:?}");
}
if attrs.contains(&"max_value".to_string()) {
let v = attr.max_value()?;
println!(" max_value: {v}");
}
if attrs.contains(&"scalar_increment".to_string()) {
let v = attr.scalar_increment()?;
println!(" scalar_increment: {v}");
}
if attrs.contains(&"possible_values".to_string()) {
let v = attr.possible_values()?;
println!(" possible_values: {v:?}");
}
if attrs.contains(&"current_value".to_string()) {
let v = attr.current_value()?;
println!(" current_value: {v}");
}
}
}
}
Ok(())
}
59 changes: 56 additions & 3 deletions asusd/src/asus_armoury/attr_int.rs → asusd/src/asus_armoury.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use rog_platform::firmware_attributes::FirmwareAttributes;
use zbus::Connection;

use log::error;
use rog_platform::firmware_attributes::{AttrValue, Attribute};
use serde::{Deserialize, Serialize};
use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Type, Value};
use zbus::{fdo, interface, Connection};
use zbus::{fdo, interface};

use crate::error::RogError;
use crate::ASUS_ZBUS_PATH;
Expand Down Expand Up @@ -43,13 +46,43 @@ impl AsusArmouryAttribute {

/// If return is `-1` on a property then there is avilable value for that
/// property
#[interface(name = "org.asuslinux.AsusArmoury")]
#[interface(name = "xyz.ljones.AsusArmoury")]
impl AsusArmouryAttribute {
#[zbus(property)]
async fn name(&self) -> String {
self.0.name().to_string()
}

#[zbus(property)]
async fn available_attrs(&self) -> Vec<String> {
let mut attrs = Vec::new();
if !matches!(self.0.default_value(), AttrValue::None) {
attrs.push("default_value".to_string());
}
if !matches!(self.0.min_value(), AttrValue::None) {
attrs.push("min_value".to_string());
}
if !matches!(self.0.max_value(), AttrValue::None) {
attrs.push("max_value".to_string());
}
if !matches!(self.0.scalar_increment(), AttrValue::None) {
attrs.push("scalar_increment".to_string());
}
if !matches!(self.0.possible_values(), AttrValue::None) {
attrs.push("possible_values".to_string());
}
// TODO: Don't unwrap, use error
if let Ok(value) = self.0.current_value().map_err(|e| {
error!("Failed to read: {e:?}");
e
}) {
if !matches!(value, AttrValue::None) {
attrs.push("current_value".to_string());
}
}
attrs
}

/// If return is `-1` then there is no default value
#[zbus(property)]
async fn default_value(&self) -> i32 {
Expand Down Expand Up @@ -77,7 +110,18 @@ impl AsusArmouryAttribute {

#[zbus(property)]
async fn scalar_increment(&self) -> i32 {
self.0.scalar_increment().unwrap_or(1)
match self.0.scalar_increment() {
AttrValue::Integer(i) => *i,
_ => -1,
}
}

#[zbus(property)]
async fn possible_values(&self) -> Vec<i32> {
match self.0.possible_values() {
AttrValue::EnumInt(i) => i.clone(),
_ => Vec::default(),
}
}

#[zbus(property)]
Expand All @@ -103,3 +147,12 @@ impl AsusArmouryAttribute {
})?)
}
}

pub async fn start_attributes_zbus(server: &Connection) -> Result<(), RogError> {
for attr in FirmwareAttributes::new().attributes() {
AsusArmouryAttribute::new(attr.clone())
.start_tasks(server)
.await?;
}
Ok(())
}
89 changes: 0 additions & 89 deletions asusd/src/asus_armoury/attr_enum_int.rs

This file was deleted.

89 changes: 0 additions & 89 deletions asusd/src/asus_armoury/attr_enum_str.rs

This file was deleted.

Loading

0 comments on commit fd3384d

Please sign in to comment.