Attempt to get multi-static working

This commit is contained in:
Luke
2020-05-22 20:53:05 +12:00
parent 5e781cbd3d
commit bd67afb104
42 changed files with 579 additions and 42 deletions

View File

@@ -37,7 +37,7 @@ serde_derive = "1.0"
toml = "0.5"
# Device control
# sysfs-class = "^0.1.2" # used for backlight control mostly
sysfs-class = "^0.1.2" # used for backlight control and baord ID
# cpu power management
intel-pstate = "^0.2.1"
# virtualisation of HID, mainly for outputting consumer key codes

View File

@@ -114,6 +114,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
loop {
connection.process_all();
// Check if a key press issued a command
let res = aura_command_recv.recv_timeout(Duration::from_micros(50));
if let Ok(command) = res {
let mut config = config.lock().await;
@@ -134,6 +135,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
*effect = None;
time_mark = Instant::now();
} else {
// Check if single mode
if let Ok(mut lock) = input.try_lock() {
if let Some(bytes) = lock.take() {
if bytes.len() > 0 {
@@ -157,10 +159,17 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
if let Some(effect) = effect_lock.take() {
if effect.len() == 11 {
let mut config = config.lock().await;
led_writer
.do_command(AuraCommand::WriteEffect(effect), &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err));
if effect.len() > 4 {
led_writer
.do_command(AuraCommand::WriteEffect(effect), &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err));
} else {
led_writer
.do_command(AuraCommand::WriteMultizone(effect), &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err));
}
time_mark = Instant::now();
}
}
@@ -207,6 +216,31 @@ fn dbus_create_ledmsg_method(msg: LedMsgType) -> Method<MTSync, ()> {
.inarg::<Vec<u8>, _>("bytearray")
}
fn dbus_create_ledmultizone_method(effect: EffectType) -> Method<MTSync, ()> {
let factory = Factory::new_sync::<()>();
factory
// method for ledmessage
.method("LedWriteMultizone", (), {
move |m| {
if let Ok(mut lock) = effect.try_lock() {
let mut iter = m.msg.iter_init();
let byte_array: Vec<Vec<u8>> =
vec![iter.read()?, iter.read()?, iter.read()?, iter.read()?];
*lock = Some(byte_array);
let mret = m.msg.method_return().append1(&format!("Got effect part"));
Ok(vec![mret])
} else {
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")
}
fn dbus_create_ledeffect_method(effect: EffectType) -> Method<MTSync, ()> {
let factory = Factory::new_sync::<()>();
factory
@@ -261,6 +295,7 @@ fn dbus_create_tree() -> (Tree<MTSync, ()>, LedMsgType, EffectType, Arc<Signal<(
factory
.interface(DBUS_IFACE, ())
.add_m(dbus_create_ledmsg_method(input_bytes.clone()))
.add_m(dbus_create_ledmultizone_method(input_effect.clone()))
.add_m(dbus_create_ledeffect_method(input_effect.clone()))
.add_s(effect_cancel_sig.clone()),
),

View File

@@ -9,35 +9,7 @@ pub(crate) fn match_laptop() -> LaptopBase {
let device_desc = device.device_descriptor().unwrap();
if device_desc.vendor_id() == 0x0b05 {
match device_desc.product_id() {
0x1869 | 0x1866 => {
info!("Found GX502 or similar");
return LaptopBase {
usb_vendor: 0x0B05,
usb_product: 0x1866,
report_filter_bytes: vec![0x5a, 0x02],
min_led_bright: 0x00,
max_led_bright: 0x03,
//from `lsusb -vd 0b05:1866`
led_endpoint: 0x04,
//from `lsusb -vd 0b05:1866`
key_endpoint: 0x83,
supported_modes: vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Cycle,
BuiltInModeByte::Rainbow,
BuiltInModeByte::Rain,
BuiltInModeByte::Random,
BuiltInModeByte::Highlight,
BuiltInModeByte::Laser,
BuiltInModeByte::Ripple,
BuiltInModeByte::Pulse,
BuiltInModeByte::ThinZoomy,
BuiltInModeByte::WideZoomy,
],
//backlight: Backlight::new("intel_backlight").unwrap(),
};
}
0x1869 | 0x1866 => return choose_1866_device(),
0x1854 => {
info!("Found GL753 or similar");
return LaptopBase {
@@ -65,6 +37,54 @@ pub(crate) fn match_laptop() -> LaptopBase {
panic!("could not match laptop");
}
fn choose_1866_device() -> LaptopBase {
let dmi = sysfs_class::DmiId::default();
let board_name = dmi.board_name().expect("Could not get board_name");
let mut laptop = LaptopBase {
usb_vendor: 0x0B05,
usb_product: 0x1866,
report_filter_bytes: vec![0x5a, 0x02],
min_led_bright: 0x00,
max_led_bright: 0x03,
//from `lsusb -vd 0b05:1866`
led_endpoint: 0x04,
//from `lsusb -vd 0b05:1866`
key_endpoint: 0x83,
supported_modes: vec![],
//backlight: Backlight::new("intel_backlight").unwrap(),
};
match &board_name.as_str()[..5] {
"GX502" | "GA502" => {
info!("Found GX502 or GA502 series");
laptop.supported_modes = vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Cycle,
BuiltInModeByte::Rainbow,
BuiltInModeByte::Rain,
BuiltInModeByte::Random,
BuiltInModeByte::Highlight,
BuiltInModeByte::Laser,
BuiltInModeByte::Ripple,
BuiltInModeByte::Pulse,
BuiltInModeByte::ThinZoomy,
BuiltInModeByte::WideZoomy,
];
}
"GM501" => {
info!("Found GM501 series");
laptop.supported_modes = vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Cycle,
BuiltInModeByte::Rainbow,
];
}
_ => panic!("Unsupported laptop: {}, please request support at https://github.com/flukejones/rog-core", board_name),
}
laptop
}
pub(super) struct LaptopBase {
usb_vendor: u16,
usb_product: u16,

View File

@@ -24,6 +24,7 @@ pub enum AuraCommand {
WriteBytes(Vec<u8>),
WriteEffect(Vec<Vec<u8>>),
ReloadLast,
WriteMultizone(Vec<Vec<u8>>),
}
/// UNSAFE: Must live as long as RogCore
@@ -136,6 +137,7 @@ where
}
}
AuraCommand::WriteBytes(bytes) => self.set_and_save(&bytes, config).await?,
AuraCommand::WriteMultizone(effect) => self.write_multizone(effect).await?,
AuraCommand::WriteEffect(effect) => self.write_effect(effect).await?,
AuraCommand::ReloadLast => self.reload_last_builtin(&config).await?,
}
@@ -188,6 +190,16 @@ where
Ok(())
}
#[inline]
async fn write_multizone(&mut self, effect: Vec<Vec<u8>>) -> Result<(), AuraError> {
for row in effect.iter() {
self.write_bytes(row).await?;
}
self.write_bytes(&LED_SET).await?;
self.write_bytes(&LED_APPLY).await?;
Ok(())
}
/// Used to set a builtin mode and save the settings for it
#[inline]
async fn set_and_save(&self, bytes: &[u8], config: &mut Config) -> Result<(), AuraError> {

View File

@@ -55,7 +55,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Version: {}", VERSION);
}
let writer = AuraDbusWriter::new()?;
let mut writer = AuraDbusWriter::new()?;
if let Some(Command::LedMode(mode)) = parsed.command {
if let Some(command) = mode.command {
@@ -63,12 +63,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
match command {
SetAuraBuiltin::MultiStatic(_) => {
let byte_arr = <[[u8; LED_MSG_LEN]; 4]>::from(command);
for arr in byte_arr.iter() {
match writer.write_bytes(arr) {
Ok(msg) => println!("Response: {}", msg),
Err(err) => println!("Error: {}", err),
}
}
writer.write_multizone(&byte_arr)?;
}
_ => match writer.write_builtin_mode(&command) {
Ok(msg) => println!("Response: {}", msg),