mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Writing an interrupt seems so slow...
This commit is contained in:
+90
-28
@@ -8,9 +8,9 @@ use dbus::{
|
||||
tree::{Factory, MethodErr},
|
||||
};
|
||||
use log::{error, info, warn};
|
||||
use std::cell::RefCell;
|
||||
use std::error::Error;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
@@ -39,40 +39,89 @@ pub fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
},
|
||||
);
|
||||
connection.request_name(DBUS_IFACE, false, true, false)?;
|
||||
let factory = Factory::new_sync::<()>();
|
||||
let factory = Factory::new_fn::<()>();
|
||||
|
||||
let input: Arc<Mutex<Option<Vec<u8>>>> = Arc::new(Mutex::new(None));
|
||||
let input: Rc<RefCell<Option<Vec<u8>>>> = Rc::new(RefCell::new(None));
|
||||
let effect: Rc<RefCell<Option<Vec<Vec<u8>>>>> = Rc::new(RefCell::new(None));
|
||||
|
||||
let tree = factory.tree(()).add(
|
||||
factory.object_path(DBUS_PATH, ()).add(
|
||||
factory.interface(DBUS_IFACE, ()).add_m(
|
||||
factory
|
||||
// method for ledmessage
|
||||
.method("ledmessage", (), {
|
||||
let input = input.clone();
|
||||
factory
|
||||
.interface(DBUS_IFACE, ())
|
||||
.add_m(
|
||||
factory
|
||||
// method for ledmessage
|
||||
.method("ledmessage", (), {
|
||||
let input = input.clone();
|
||||
|
||||
move |m| {
|
||||
let bytes: Vec<u8> = m.msg.read1()?;
|
||||
if let Ok(mut lock) = input.lock() {
|
||||
*lock = Some(bytes.to_vec());
|
||||
let mret = m
|
||||
.msg
|
||||
.method_return()
|
||||
.append1(&format!("Wrote {:x?}", bytes));
|
||||
return Ok(vec![mret]);
|
||||
} else {
|
||||
return Err(MethodErr::failed("Could not lock daemon for access"));
|
||||
move |m| {
|
||||
let bytes: Vec<u8> = m.msg.read1()?;
|
||||
if let Ok(mut lock) = input.try_borrow_mut() {
|
||||
*lock = Some(bytes.to_vec());
|
||||
let mret = m
|
||||
.msg
|
||||
.method_return()
|
||||
.append1(&format!("Wrote {:x?}", bytes));
|
||||
return Ok(vec![mret]);
|
||||
} else {
|
||||
return Err(MethodErr::failed(
|
||||
"Could not lock daemon for access",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.outarg::<&str, _>("reply")
|
||||
.inarg::<Vec<u8>, _>("bytearray"),
|
||||
),
|
||||
})
|
||||
.outarg::<&str, _>("reply")
|
||||
.inarg::<Vec<u8>, _>("bytearray"),
|
||||
)
|
||||
.add_m(
|
||||
factory
|
||||
// method for ledmessage
|
||||
.method("ledeffect", (), {
|
||||
let effect = effect.clone();
|
||||
move |m| {
|
||||
if let Ok(mut lock) = effect.try_borrow_mut() {
|
||||
let mut iter = m.msg.iter_init();
|
||||
let byte_array: Vec<Vec<u8>> = vec![
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
iter.read()?,
|
||||
];
|
||||
|
||||
*lock = Some(byte_array);
|
||||
let mret =
|
||||
m.msg.method_return().append1(&format!("Got effect part"));
|
||||
return Ok(vec![mret]);
|
||||
} else {
|
||||
return Err(MethodErr::failed(
|
||||
"Could not lock daemon for access",
|
||||
));
|
||||
}
|
||||
}
|
||||
})
|
||||
.outarg::<&str, _>("reply")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray"),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// We add the tree to the connection so that incoming method calls will be handled.
|
||||
tree.start_receive_send(&connection);
|
||||
tree.start_receive(&connection);
|
||||
|
||||
//thread::spawn(move || loop {});
|
||||
|
||||
@@ -80,18 +129,31 @@ pub fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
loop {
|
||||
//thread::sleep(Duration::from_millis(2));
|
||||
connection
|
||||
.process(Duration::from_millis(20))
|
||||
.process(Duration::from_millis(1))
|
||||
.unwrap_or_else(|err| {
|
||||
error!("{:?}", err);
|
||||
false
|
||||
});
|
||||
|
||||
if let Ok(mut lock) = input.try_lock() {
|
||||
if let Ok(mut lock) = input.try_borrow_mut() {
|
||||
if let Some(bytes) = &*lock {
|
||||
rogcore.aura_set_and_save(&supported, &bytes)?;
|
||||
*lock = None;
|
||||
}
|
||||
}
|
||||
if let Ok(mut lock) = effect.try_borrow_mut() {
|
||||
if let Some(bytes) = &*lock {
|
||||
// It takes up to 20 milliseconds to write a complete colour block...
|
||||
//let now = std::time::Instant::now();
|
||||
for row in bytes {
|
||||
rogcore.aura_write(&row)?;
|
||||
}
|
||||
*lock = None;
|
||||
//let after = std::time::Instant::now();
|
||||
//let diff = after.duration_since(now);
|
||||
//dbg!(diff.as_millis());
|
||||
}
|
||||
}
|
||||
|
||||
match laptop.run(&mut rogcore) {
|
||||
Ok(_) => {}
|
||||
|
||||
Reference in New Issue
Block a user