mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
split out types, dbus
This commit is contained in:
168
rog-dbus/src/lib.rs
Normal file
168
rog-dbus/src/lib.rs
Normal file
@@ -0,0 +1,168 @@
|
||||
pub static DBUS_NAME: &str = "org.asuslinux.Daemon";
|
||||
pub static DBUS_PATH: &str = "/org/asuslinux/Daemon";
|
||||
pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
|
||||
pub const LED_MSG_LEN: usize = 17;
|
||||
|
||||
pub mod zbus_anime;
|
||||
pub mod zbus_charge;
|
||||
pub mod zbus_gfx;
|
||||
pub mod zbus_led;
|
||||
pub mod zbus_profile;
|
||||
pub mod zbus_rogbios;
|
||||
pub mod zbus_supported;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
use rog_types::aura_modes::AuraModes;
|
||||
use zbus::{Connection, Result, SignalReceiver};
|
||||
|
||||
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub struct DbusProxies<'a> {
|
||||
anime: zbus_anime::AnimeProxy<'a>,
|
||||
charge: zbus_charge::ChargeProxy<'a>,
|
||||
gfx: zbus_gfx::GfxProxy<'a>,
|
||||
led: zbus_led::LedProxy<'a>,
|
||||
profile: zbus_profile::ProfileProxy<'a>,
|
||||
rog_bios: zbus_rogbios::RogBiosProxy<'a>,
|
||||
supported: zbus_supported::SupportProxy<'a>,
|
||||
}
|
||||
|
||||
impl<'a> DbusProxies<'a> {
|
||||
#[inline]
|
||||
pub fn new() -> Result<(Self, Connection)> {
|
||||
let conn = Connection::new_system()?;
|
||||
|
||||
Ok((
|
||||
DbusProxies {
|
||||
anime: zbus_anime::AnimeProxy::new(&conn)?,
|
||||
led: zbus_led::LedProxy::new(&conn)?,
|
||||
charge: zbus_charge::ChargeProxy::new(&conn)?,
|
||||
gfx: zbus_gfx::GfxProxy::new(&conn)?,
|
||||
profile: zbus_profile::ProfileProxy::new(&conn)?,
|
||||
rog_bios: zbus_rogbios::RogBiosProxy::new(&conn)?,
|
||||
supported: zbus_supported::SupportProxy::new(&conn)?,
|
||||
},
|
||||
conn,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn setup_recv(&'a self, conn: Connection) -> SignalReceiver {
|
||||
let mut recv = SignalReceiver::new(conn);
|
||||
//recv.receive_for(&self.proxy_anime);
|
||||
recv.receive_for(self.led.proxy());
|
||||
recv.receive_for(self.charge.proxy());
|
||||
recv.receive_for(self.gfx.proxy());
|
||||
recv.receive_for(self.profile.proxy());
|
||||
recv
|
||||
}
|
||||
|
||||
pub fn anime(&self) -> &zbus_anime::AnimeProxy<'a> {
|
||||
&self.anime
|
||||
}
|
||||
|
||||
pub fn charge(&self) -> &zbus_charge::ChargeProxy<'a> {
|
||||
&self.charge
|
||||
}
|
||||
|
||||
pub fn gfx(&self) -> &zbus_gfx::GfxProxy<'a> {
|
||||
&self.gfx
|
||||
}
|
||||
|
||||
pub fn led(&self) -> &zbus_led::LedProxy<'a> {
|
||||
&self.led
|
||||
}
|
||||
|
||||
pub fn profile(&self) -> &zbus_profile::ProfileProxy<'a> {
|
||||
&self.profile
|
||||
}
|
||||
|
||||
pub fn rog_bios(&self) -> &zbus_rogbios::RogBiosProxy<'a> {
|
||||
&self.rog_bios
|
||||
}
|
||||
|
||||
pub fn supported(&self) -> &zbus_supported::SupportProxy<'a> {
|
||||
&self.supported
|
||||
}
|
||||
}
|
||||
|
||||
// Signals separated out
|
||||
pub struct Signals {
|
||||
pub gfx_vendor: Arc<Mutex<Option<String>>>,
|
||||
pub gfx_action: Arc<Mutex<Option<String>>>,
|
||||
pub profile: Arc<Mutex<Option<String>>>,
|
||||
pub led_mode: Arc<Mutex<Option<AuraModes>>>,
|
||||
pub charge: Arc<Mutex<Option<u8>>>,
|
||||
}
|
||||
|
||||
impl Signals {
|
||||
#[inline]
|
||||
pub fn new(proxies: &DbusProxies) -> Result<Self> {
|
||||
//
|
||||
let charge_signal = Arc::new(Mutex::new(None));
|
||||
proxies
|
||||
.charge
|
||||
.connect_notify_charge(charge_signal.clone())?;
|
||||
|
||||
//
|
||||
let ledmode_signal = Arc::new(Mutex::new(None));
|
||||
proxies.led.connect_notify_led(ledmode_signal.clone())?;
|
||||
|
||||
let gfx_action_signal = Arc::new(Mutex::new(None));
|
||||
proxies
|
||||
.gfx
|
||||
.connect_notify_action(gfx_action_signal.clone())?;
|
||||
|
||||
let gfx_vendor_signal = Arc::new(Mutex::new(None));
|
||||
proxies.gfx.connect_notify_gfx(gfx_vendor_signal.clone())?;
|
||||
|
||||
let profile_signal = Arc::new(Mutex::new(None));
|
||||
proxies
|
||||
.profile
|
||||
.connect_notify_profile(profile_signal.clone())?;
|
||||
|
||||
Ok(Signals {
|
||||
gfx_vendor: gfx_vendor_signal,
|
||||
gfx_action: gfx_action_signal,
|
||||
profile: profile_signal,
|
||||
led_mode: ledmode_signal,
|
||||
charge: charge_signal,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// This is the main way to communicate with the DBUS interface
|
||||
pub struct AuraDbusClient<'a> {
|
||||
proxies: DbusProxies<'a>,
|
||||
signals: Signals,
|
||||
}
|
||||
|
||||
impl<'a> AuraDbusClient<'a> {
|
||||
#[inline]
|
||||
pub fn new() -> Result<(Self, Connection)> {
|
||||
let (proxies, conn) = DbusProxies::new()?;
|
||||
let signals = Signals::new(&proxies)?;
|
||||
|
||||
Ok((AuraDbusClient { proxies, signals }, conn))
|
||||
}
|
||||
|
||||
pub fn proxies(&self) -> &DbusProxies {
|
||||
&self.proxies
|
||||
}
|
||||
|
||||
/*
|
||||
* GFX
|
||||
*/
|
||||
pub fn gfx_wait_changed(&self) -> Result<String> {
|
||||
loop {
|
||||
if let Ok(res) = self.proxies.gfx.proxy().next_signal() {
|
||||
if res.is_none() {
|
||||
if let Ok(lock) = self.signals.gfx_action.lock() {
|
||||
if let Some(stuff) = lock.as_ref() {
|
||||
return Ok(stuff.to_string());
|
||||
}
|
||||
}
|
||||
// return Ok("Failed for unknown reason".to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
rog-dbus/src/zbus_anime.rs
Normal file
75
rog-dbus/src/zbus_anime.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
//! # 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/Anime' 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::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
use rog_types::anime_matrix::{AniMeMatrix, AniMePacketType, ANIME_PANE1_PREFIX, ANIME_PANE2_PREFIX};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Anime"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// SetAnime method
|
||||
fn set_anime(&self, input: &[&[u8]]) -> zbus::Result<()>;
|
||||
|
||||
/// SetBootOnOff method
|
||||
fn set_boot_on_off(&self, status: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetOnOff method
|
||||
fn set_on_off(&self, status: bool) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub struct AnimeProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> AnimeProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(AnimeProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_brightness(&self, led_brightness: u8) -> Result<()> {
|
||||
let mut anime_matrix = AniMeMatrix::new();
|
||||
|
||||
anime_matrix.fill_with(led_brightness);
|
||||
|
||||
let mut image = AniMePacketType::from(anime_matrix);
|
||||
image[0][..7].copy_from_slice(&ANIME_PANE1_PREFIX);
|
||||
image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX);
|
||||
|
||||
self.0.set_anime(&[&image[0], &image[1]])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn toggle_boot_on(&self, on: bool) -> Result<()> {
|
||||
self.0.set_boot_on_off(on)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn toggle_on(&self, on: bool) -> Result<()> {
|
||||
self.0.set_on_off(on)
|
||||
}
|
||||
}
|
||||
73
rog-dbus/src/zbus_charge.rs
Normal file
73
rog-dbus/src/zbus_charge.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
//! # 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/Charge' 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::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Charge"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// Limit method
|
||||
fn limit(&self) -> zbus::Result<i16>;
|
||||
|
||||
/// SetLimit method
|
||||
fn set_limit(&self, limit: u8) -> zbus::Result<()>;
|
||||
|
||||
/// NotifyCharge signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_charge(&self, limit: u8) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub struct ChargeProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> ChargeProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(ChargeProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_limit(&self, level: u8) -> Result<()> {
|
||||
self.0.set_limit(level)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_limit(&self) -> Result<i16> {
|
||||
self.0.limit()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_charge(&self, charge: Arc<Mutex<Option<u8>>>) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_charge(move |data| {
|
||||
if let Ok(mut lock) = charge.lock() {
|
||||
*lock = Some(data);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
98
rog-dbus/src/zbus_gfx.rs
Normal file
98
rog-dbus/src/zbus_gfx.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
//! # DBus interface proxy for: `org.asuslinux.Gfx`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data.
|
||||
//! Source: `Interface '/org/asuslinux/Gfx' 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::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Gfx"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// Power method
|
||||
fn power(&self) -> zbus::Result<String>;
|
||||
|
||||
/// SetVendor method
|
||||
fn set_vendor(&self, vendor: &str) -> zbus::Result<()>;
|
||||
|
||||
/// Vendor method
|
||||
fn vendor(&self) -> zbus::Result<String>;
|
||||
|
||||
/// NotifyAction signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_action(&self, action: &str) -> zbus::Result<()>;
|
||||
|
||||
/// NotifyGfx signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_gfx(&self, vendor: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub struct GfxProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> GfxProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(GfxProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gfx_get_pwr(&self) -> Result<String> {
|
||||
self.0.power()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gfx_get_mode(&self) -> Result<String> {
|
||||
self.0.vendor()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn gfx_write_mode(&self, vendor: &str) -> Result<()> {
|
||||
self.0.set_vendor(vendor)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_action(
|
||||
&self,
|
||||
action: Arc<Mutex<Option<String>>>,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_action(move |data| {
|
||||
if let Ok(mut lock) = action.lock() {
|
||||
*lock = Some(data.to_owned());
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_gfx(&self, vendor: Arc<Mutex<Option<String>>>) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_gfx(move |data| {
|
||||
if let Ok(mut lock) = vendor.lock() {
|
||||
*lock = Some(data.to_owned());
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
142
rog-dbus/src/zbus_led.rs
Normal file
142
rog-dbus/src/zbus_led.rs
Normal file
@@ -0,0 +1,142 @@
|
||||
//! # 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/Led' 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::sync::{Arc, Mutex};
|
||||
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
use rog_types::{aura_modes::AuraModes, cli_options::LedBrightness, fancy::KeyColourArray};
|
||||
|
||||
const BLOCKING_TIME: u64 = 40; // 100ms = 10 FPS, max 50ms = 20 FPS, 40ms = 25 FPS
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Led"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// LedBrightness method
|
||||
fn led_brightness(&self) -> zbus::Result<i16>;
|
||||
|
||||
/// LedMode method
|
||||
fn led_mode(&self) -> zbus::Result<String>;
|
||||
|
||||
/// LedModes method
|
||||
fn led_modes(&self) -> zbus::Result<String>;
|
||||
|
||||
/// NextLedMode method
|
||||
fn next_led_mode(&self) -> zbus::Result<()>;
|
||||
|
||||
/// PrevLedMode method
|
||||
fn prev_led_mode(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SetLedMode method
|
||||
fn set_led_mode(&self, data: &str) -> zbus::Result<()>;
|
||||
|
||||
/// NotifyLed signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_led(&self, data: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub struct LedProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> LedProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(LedProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_led_brightness(&self) -> Result<LedBrightness> {
|
||||
match self.0.led_brightness()? {
|
||||
-1 => Ok(LedBrightness::new(None)),
|
||||
level => Ok(LedBrightness::new(Some(level as u8))),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_brightness(&self, level: u8) -> Result<()> {
|
||||
self.set_led_mode(&AuraModes::LedBrightness(level))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn next_led_mode(&self) -> Result<()> {
|
||||
self.0.next_led_mode()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn prev_led_mode(&self) -> Result<()> {
|
||||
self.0.prev_led_mode()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_led_mode(&self, mode: &AuraModes) -> Result<()> {
|
||||
self.0.set_led_mode(&serde_json::to_string(mode).unwrap())
|
||||
}
|
||||
|
||||
/// 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 set_per_key(&self, key_colour_array: &KeyColourArray) -> Result<()> {
|
||||
let group = key_colour_array.get();
|
||||
let mut vecs = Vec::with_capacity(group.len());
|
||||
for v in group {
|
||||
vecs.push(v.to_vec());
|
||||
}
|
||||
let mode = AuraModes::PerKey(vecs);
|
||||
|
||||
self.set_led_mode(&mode)?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(BLOCKING_TIME));
|
||||
|
||||
// if self.stop.load(Ordering::Relaxed) {
|
||||
// println!("Keyboard backlight was changed, exiting");
|
||||
// std::process::exit(1)
|
||||
// }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This method must always be called before the very first write to initialise
|
||||
/// the keyboard LED EC in the correct mode
|
||||
#[inline]
|
||||
pub fn init_effect(&self) -> Result<()> {
|
||||
let mode = AuraModes::PerKey(vec![vec![]]);
|
||||
self.0.set_led_mode(&serde_json::to_string(&mode).unwrap())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_led(&self, led: Arc<Mutex<Option<AuraModes>>>) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_led(move |data| {
|
||||
if let Ok(mut lock) = led.lock() {
|
||||
if let Ok(dat) = serde_json::from_str(&data) {
|
||||
*lock = Some(dat);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
97
rog-dbus/src/zbus_profile.rs
Normal file
97
rog-dbus/src/zbus_profile.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
//! # 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/Profile' 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::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use rog_types::profile::ProfileEvent;
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Profile"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// ActiveProfileName method
|
||||
fn active_profile_name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// NextProfile method
|
||||
fn next_profile(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Profile method
|
||||
fn profile(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Profiles method
|
||||
fn profiles(&self) -> zbus::Result<String>;
|
||||
|
||||
/// SetProfile method
|
||||
fn set_profile(&self, profile: &str) -> zbus::Result<()>;
|
||||
|
||||
/// NotifyProfile signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_profile(&self, profile: &str) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub struct ProfileProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> ProfileProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(ProfileProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn active_profile_name(&self) -> Result<String> {
|
||||
self.0.active_profile_name()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn next_fan(&self) -> Result<()> {
|
||||
self.0.next_profile()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_fan_mode(&self, level: u8) -> Result<()> {
|
||||
self.0
|
||||
.set_profile(&serde_json::to_string(&ProfileEvent::ChangeMode(level)).unwrap())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_command(&self, cmd: &ProfileEvent) -> Result<()> {
|
||||
self.0.set_profile(&serde_json::to_string(cmd).unwrap())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_profile(
|
||||
&self,
|
||||
charge: Arc<Mutex<Option<String>>>,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_profile(move |data| {
|
||||
if let Ok(mut lock) = charge.lock() {
|
||||
*lock = Some(data.to_owned());
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
109
rog-dbus/src/zbus_rogbios.rs
Normal file
109
rog-dbus/src/zbus_rogbios.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
//! # 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/RogBios' 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::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/RogBios"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// DedicatedGraphicMode method
|
||||
fn dedicated_graphic_mode(&self) -> zbus::Result<i16>;
|
||||
|
||||
/// PostBootSound method
|
||||
fn post_boot_sound(&self) -> zbus::Result<i16>;
|
||||
|
||||
/// SetDedicatedGraphicMode method
|
||||
fn set_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetPostBootSound method
|
||||
fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>;
|
||||
|
||||
/// NotifyDedicatedGraphicMode signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
|
||||
|
||||
/// NotifyPostBootSound signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn notify_post_boot_sound(&self, dedicated: bool) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub struct RogBiosProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> RogBiosProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(RogBiosProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_dedicated_gfx(&self) -> Result<i16> {
|
||||
self.0.dedicated_graphic_mode()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_dedicated_gfx(&self, on: bool) -> Result<()> {
|
||||
self.0.set_dedicated_graphic_mode(on)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_post_sound(&self) -> Result<i16> {
|
||||
self.0.post_boot_sound()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_post_sound(&self, on: bool) -> Result<()> {
|
||||
self.0.set_post_boot_sound(on)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_dedicated_graphic_mode(
|
||||
&self,
|
||||
dedicated: Arc<Mutex<Option<bool>>>,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_dedicated_graphic_mode(move |data| {
|
||||
if let Ok(mut lock) = dedicated.lock() {
|
||||
*lock = Some(data);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_post_boot_sound(
|
||||
&self,
|
||||
sound: Arc<Mutex<Option<bool>>>,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
self.0.connect_notify_post_boot_sound(move |data| {
|
||||
if let Ok(mut lock) = sound.lock() {
|
||||
*lock = Some(data);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
49
rog-dbus/src/zbus_supported.rs
Normal file
49
rog-dbus/src/zbus_supported.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
//! # 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/Supported' 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::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::{dbus_proxy, Connection, Result};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "org.asuslinux.Daemon",
|
||||
default_path = "/org/asuslinux/Supported"
|
||||
)]
|
||||
trait Daemon {
|
||||
/// SupportedFunctions method
|
||||
fn supported_functions(&self) -> zbus::Result<String>;
|
||||
}
|
||||
|
||||
pub struct SupportProxy<'a>(DaemonProxy<'a>);
|
||||
|
||||
impl<'a> SupportProxy<'a> {
|
||||
#[inline]
|
||||
pub fn new(conn: &Connection) -> Result<Self> {
|
||||
Ok(SupportProxy(DaemonProxy::new(&conn)?))
|
||||
}
|
||||
|
||||
pub fn proxy(&self) -> &DaemonProxy<'a> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_supported_functions(&self) -> Result<String> {
|
||||
self.0.supported_functions()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user