mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fluke/dbus refactor
This commit is contained in:
105
rog-dbus/src/zbus_aura.rs
Normal file
105
rog-dbus/src/zbus_aura.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
//! # `DBus` interface proxy for: `org.asuslinux.Daemon`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `1.0.0` from `DBus` introspection
|
||||
//! data. Source: `Interface '/org/asuslinux/Aura' from service
|
||||
//! 'org.asuslinux.Daemon' on system bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This `DBus` object implements
|
||||
//! [standard `DBus` interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use rog_aura::advanced::UsbPackets;
|
||||
use rog_aura::usb::{AuraDevice, AuraPowerDev};
|
||||
use rog_aura::{AuraEffect, AuraModeNum, LedBrightness};
|
||||
use zbus::blocking::Connection;
|
||||
use zbus::{dbus_proxy, Result};
|
||||
|
||||
const BLOCKING_TIME: u64 = 33; // 100ms = 10 FPS, max 50ms = 20 FPS, 40ms = 25 FPS
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_service = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Aura"
|
||||
)]
|
||||
trait Aura {
|
||||
/// AllModeData method
|
||||
fn all_mode_data(&self) -> zbus::Result<BTreeMap<AuraModeNum, AuraEffect>>;
|
||||
|
||||
/// DirectAddressingRaw method
|
||||
fn direct_addressing_raw(&self, data: UsbPackets) -> zbus::Result<()>;
|
||||
|
||||
/// Brightness property
|
||||
#[dbus_proxy(property)]
|
||||
fn brightness(&self) -> zbus::Result<LedBrightness>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_brightness(&self, value: LedBrightness) -> zbus::Result<()>;
|
||||
|
||||
/// DeviceType property
|
||||
#[dbus_proxy(property)]
|
||||
fn device_type(&self) -> zbus::Result<AuraDevice>;
|
||||
|
||||
/// LedMode property
|
||||
#[dbus_proxy(property)]
|
||||
fn led_mode(&self) -> zbus::Result<AuraModeNum>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_led_mode(&self, value: AuraModeNum) -> zbus::Result<()>;
|
||||
|
||||
/// LedModeData property
|
||||
#[dbus_proxy(property)]
|
||||
fn led_mode_data(&self) -> zbus::Result<AuraEffect>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_led_mode_data(&self, value: AuraEffect) -> zbus::Result<()>;
|
||||
|
||||
/// LedPower property
|
||||
#[dbus_proxy(property)]
|
||||
fn led_power(&self) -> zbus::Result<AuraPowerDev>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_led_power(&self, value: (AuraPowerDev, bool)) -> zbus::Result<()>;
|
||||
|
||||
/// SupportedBrightness property
|
||||
#[dbus_proxy(property)]
|
||||
fn supported_brightness(&self) -> zbus::Result<Vec<LedBrightness>>;
|
||||
|
||||
/// SupportedModes property
|
||||
#[dbus_proxy(property)]
|
||||
fn supported_modes(&self) -> zbus::Result<Vec<AuraModeNum>>;
|
||||
}
|
||||
|
||||
pub struct AuraProxyPerkey<'a>(AuraProxyBlocking<'a>);
|
||||
|
||||
impl<'a> AuraProxyPerkey<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(AuraProxyPerkey(AuraProxyBlocking::new(conn)?))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn proxy(&self) -> &AuraProxyBlocking<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Write a single colour block.
|
||||
///
|
||||
/// Intentionally blocks for 10ms after sending to allow the block to
|
||||
/// be written to the keyboard EC. This should not be async.
|
||||
#[inline]
|
||||
pub fn direct_addressing_raw(&self, direct_raw: UsbPackets) -> Result<()> {
|
||||
self.0.direct_addressing_raw(direct_raw)?;
|
||||
std::thread::sleep(std::time::Duration::from_millis(BLOCKING_TIME));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user