mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Bright go up. Bright go down.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -170,7 +170,6 @@ dependencies = [
|
|||||||
"rog-lib",
|
"rog-lib",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"toml",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -181,6 +180,7 @@ dependencies = [
|
|||||||
"rusb",
|
"rusb",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ gumdrop = "0.8"
|
|||||||
dbus = "0.7.1"
|
dbus = "0.7.1"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
toml = "0.5"
|
|
||||||
rog-lib = { path = "../rog-lib" }
|
rog-lib = { path = "../rog-lib" }
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
use crate::{config::Config, DBUS_IFACE, DBUS_PATH};
|
use crate::{DBUS_IFACE, DBUS_PATH};
|
||||||
use dbus::{
|
use dbus::{
|
||||||
blocking::Connection,
|
blocking::Connection,
|
||||||
tree::{Factory, MethodErr},
|
tree::{Factory, MethodErr},
|
||||||
};
|
};
|
||||||
use rog_lib::core::RogCore;
|
use rog_lib::hotkeys::*;
|
||||||
|
use rog_lib::{config::Config, core::RogCore};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
pub struct Daemon {
|
pub struct Daemon {
|
||||||
rogcore: RogCore,
|
rogcore: RogCore,
|
||||||
|
hotkeys: Box<dyn Laptop>,
|
||||||
config: Config,
|
config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,6 +19,7 @@ impl Daemon {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Daemon {
|
Daemon {
|
||||||
rogcore: RogCore::new().expect("Could not start RogCore"),
|
rogcore: RogCore::new().expect("Could not start RogCore"),
|
||||||
|
hotkeys: Box::new(LaptopGX502GW::new()),
|
||||||
config: Config::default().read(),
|
config: Config::default().read(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,17 +86,14 @@ impl Daemon {
|
|||||||
// We add the tree to the connection so that incoming method calls will be handled.
|
// We add the tree to the connection so that incoming method calls will be handled.
|
||||||
tree.start_receive(&connection);
|
tree.start_receive(&connection);
|
||||||
|
|
||||||
|
let mut key_buf = [0u8; 32];
|
||||||
loop {
|
loop {
|
||||||
connection.process(Duration::from_millis(5))?;
|
connection.process(Duration::from_millis(1))?;
|
||||||
// READ KEYBOARD
|
// READ KEYBOARD
|
||||||
// TODO: this needs to move to a thread
|
// TODO: this needs to move to a thread, but there is unsafety
|
||||||
match daemon.borrow_mut().rogcore.poll_keyboard() {
|
|
||||||
Ok(buf) => {
|
|
||||||
// [5d, 1, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] up
|
|
||||||
// [5d, 1, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] down
|
|
||||||
// [5d, 1, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] left
|
|
||||||
// [5d, 1, 0, 0, 4f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] right
|
|
||||||
|
|
||||||
|
match daemon.borrow_mut().rogcore.poll_keyboard(&mut key_buf) {
|
||||||
|
Ok(read) => {
|
||||||
// [5a, c4, ; 32 bytes long] fn+up
|
// [5a, c4, ; 32 bytes long] fn+up
|
||||||
// [5a, c5, ; 32 bytes long] fn+down
|
// [5a, c5, ; 32 bytes long] fn+down
|
||||||
// [5a, b2, ; 32 bytes long] fn+left
|
// [5a, b2, ; 32 bytes long] fn+left
|
||||||
@@ -103,7 +103,15 @@ impl Daemon {
|
|||||||
// read config + inc/dec brightness byte
|
// read config + inc/dec brightness byte
|
||||||
// write to aura
|
// write to aura
|
||||||
// write config
|
// write config
|
||||||
println!("{:x?}", buf);
|
let hotkeys = unsafe { &mut (*daemon.as_ptr()).hotkeys };
|
||||||
|
let mut rogcore = unsafe { &mut (*daemon.as_ptr()).rogcore };
|
||||||
|
let mut config = unsafe { &mut (*daemon.as_ptr()).config };
|
||||||
|
|
||||||
|
if let Some(_count) = read {
|
||||||
|
if key_buf[0] == hotkeys.hotkey_group_byte() {
|
||||||
|
hotkeys.do_hotkey_action(&mut rogcore, &mut config, key_buf[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => println!("{:?}", err),
|
Err(err) => println!("{:?}", err),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// TODO: use /sys/class/dmi/id/board_name to detect model
|
// TODO: use /sys/class/dmi/id/board_name to detect model
|
||||||
mod config;
|
|
||||||
mod daemon;
|
mod daemon;
|
||||||
|
|
||||||
use crate::daemon::*;
|
use crate::daemon::*;
|
||||||
@@ -12,7 +11,6 @@ use rog_lib::core::{LedBrightness, RogCore, LED_MSG_LEN};
|
|||||||
pub static DBUS_NAME: &'static str = "org.rogcore.Daemon";
|
pub static DBUS_NAME: &'static str = "org.rogcore.Daemon";
|
||||||
pub static DBUS_PATH: &'static str = "/org/rogcore/Daemon";
|
pub static DBUS_PATH: &'static str = "/org/rogcore/Daemon";
|
||||||
pub static DBUS_IFACE: &'static str = "org.rogcore.Daemon";
|
pub static DBUS_IFACE: &'static str = "org.rogcore.Daemon";
|
||||||
pub static CONFIG_PATH: &'static str = "/etc/rogcore.conf";
|
|
||||||
|
|
||||||
#[derive(Debug, Options)]
|
#[derive(Debug, Options)]
|
||||||
struct CLIStart {
|
struct CLIStart {
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ rusb = "0.5"
|
|||||||
gumdrop = "0.8"
|
gumdrop = "0.8"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
toml = "0.5"
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
use crate::CONFIG_PATH;
|
use crate::{aura::SetAuraBuiltin, core::LED_MSG_LEN};
|
||||||
use rog_lib::{aura::SetAuraBuiltin, core::LED_MSG_LEN};
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
pub static CONFIG_PATH: &'static str = "/etc/rogcore.conf";
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
pub(crate) struct Config {
|
pub struct Config {
|
||||||
pub brightness: u8,
|
pub brightness: u8,
|
||||||
pub builtin: Vec<u8>,
|
pub builtin: Vec<u8>,
|
||||||
}
|
}
|
||||||
@@ -55,38 +55,34 @@ pub struct RogCore {
|
|||||||
handle: DeviceHandle<rusb::GlobalContext>,
|
handle: DeviceHandle<rusb::GlobalContext>,
|
||||||
initialised: bool,
|
initialised: bool,
|
||||||
led_interface_num: u8,
|
led_interface_num: u8,
|
||||||
keys_interface_num: u8,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RogCore {
|
impl RogCore {
|
||||||
pub fn new() -> Result<RogCore, Error> {
|
pub fn new() -> Result<RogCore, Error> {
|
||||||
|
// TODO: make this more configurable
|
||||||
let mut handle = RogCore::get_device(0x0B05, 0x1866)?;
|
let mut handle = RogCore::get_device(0x0B05, 0x1866)?;
|
||||||
handle.set_active_configuration(0).unwrap_or(());
|
handle.set_active_configuration(0).unwrap_or(());
|
||||||
|
|
||||||
let config = handle.device().config_descriptor(0).unwrap();
|
let config = handle.device().config_descriptor(0).unwrap();
|
||||||
// Interface with outputs
|
// Interface with outputs
|
||||||
let mut keys_interface_num = 0;
|
|
||||||
let mut led_interface_num = 0;
|
let mut led_interface_num = 0;
|
||||||
for iface in config.interfaces() {
|
for iface in config.interfaces() {
|
||||||
for desc in iface.descriptors() {
|
for desc in iface.descriptors() {
|
||||||
for endpoint in desc.endpoint_descriptors() {
|
for endpoint in desc.endpoint_descriptors() {
|
||||||
if endpoint.address() == 0x83 {
|
if endpoint.address() == 0x81 {
|
||||||
keys_interface_num = desc.interface_number();
|
|
||||||
} else if endpoint.address() == 0x81 {
|
|
||||||
led_interface_num = desc.interface_number();
|
led_interface_num = desc.interface_number();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.set_auto_detach_kernel_driver(true).unwrap();
|
|
||||||
handle.set_auto_detach_kernel_driver(true).unwrap();
|
handle.set_auto_detach_kernel_driver(true).unwrap();
|
||||||
|
|
||||||
Ok(RogCore {
|
Ok(RogCore {
|
||||||
handle,
|
handle,
|
||||||
initialised: false,
|
initialised: false,
|
||||||
led_interface_num,
|
led_interface_num,
|
||||||
keys_interface_num,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,22 +140,21 @@ impl RogCore {
|
|||||||
self.aura_write_messages(&messages)
|
self.aura_write_messages(&messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poll_keyboard(&mut self) -> Result<[u8; 32], Error> {
|
pub fn poll_keyboard(&mut self, buf: &mut [u8; 32]) -> Result<Option<usize>, Error> {
|
||||||
self.handle.claim_interface(self.keys_interface_num)?;
|
|
||||||
|
|
||||||
let mut buf = [0; 32];
|
|
||||||
match self
|
match self
|
||||||
.handle
|
.handle
|
||||||
.read_interrupt(0x83, &mut buf, Duration::from_micros(10))
|
.read_interrupt(0x83, buf, Duration::from_micros(10))
|
||||||
{
|
{
|
||||||
Ok(_) => {
|
Ok(o) => {
|
||||||
self.handle.release_interface(self.keys_interface_num)?;
|
if buf[0] == 0x5a {
|
||||||
Ok(buf)
|
return Ok(Some(o));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => match err {
|
Err(err) => match err {
|
||||||
//Error::Timeout => {}
|
//Error::Timeout => {}
|
||||||
_ => return Err(err),
|
_ => return Err(err),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
92
rog-lib/src/hotkeys.rs
Normal file
92
rog-lib/src/hotkeys.rs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
use crate::config::Config;
|
||||||
|
use crate::core::RogCore;
|
||||||
|
|
||||||
|
pub trait Laptop {
|
||||||
|
fn do_hotkey_action(&self, core: &mut RogCore, config: &mut Config, key_byte: u8);
|
||||||
|
fn hotkey_group_byte(&self) -> u8;
|
||||||
|
}
|
||||||
|
pub struct LaptopGX502GW {
|
||||||
|
hotkey_group_byte: u8,
|
||||||
|
min_bright: u8,
|
||||||
|
max_bright: u8,
|
||||||
|
}
|
||||||
|
impl LaptopGX502GW {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
LaptopGX502GW {
|
||||||
|
hotkey_group_byte: 0x5a,
|
||||||
|
min_bright: 0x00,
|
||||||
|
max_bright: 0x03,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Laptop for LaptopGX502GW {
|
||||||
|
fn do_hotkey_action(&self, core: &mut RogCore, config: &mut Config, key_byte: u8) {
|
||||||
|
match GX502GWKeys::from(key_byte) {
|
||||||
|
GX502GWKeys::Rog => {
|
||||||
|
println!("ROG!");
|
||||||
|
}
|
||||||
|
GX502GWKeys::LedBrightUp => {
|
||||||
|
let mut bright = config.brightness;
|
||||||
|
if bright < self.max_bright {
|
||||||
|
bright += 1;
|
||||||
|
config.brightness = bright;
|
||||||
|
}
|
||||||
|
let bytes = RogCore::aura_brightness_bytes(bright).unwrap();
|
||||||
|
core.aura_set_mode(&bytes).unwrap();
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
GX502GWKeys::LedBrightDown => {
|
||||||
|
let mut bright = config.brightness;
|
||||||
|
if bright > self.min_bright {
|
||||||
|
bright -= 1;
|
||||||
|
config.brightness = bright;
|
||||||
|
}
|
||||||
|
let bytes = RogCore::aura_brightness_bytes(bright).unwrap();
|
||||||
|
core.aura_set_mode(&bytes).unwrap();
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
_ => println!("{:X?}", key_byte),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn hotkey_group_byte(&self) -> u8 {
|
||||||
|
self.hotkey_group_byte
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum GX502GWKeys {
|
||||||
|
Rog = 0x38,
|
||||||
|
MicToggle = 0x7C,
|
||||||
|
Fan = 0xAE,
|
||||||
|
ScreenToggle = 0x35,
|
||||||
|
ScreenBrightDown = 0x10,
|
||||||
|
ScreenBrightUp = 0x20,
|
||||||
|
TouchPadToggle = 0x6b,
|
||||||
|
Sleep = 0x6C,
|
||||||
|
AirplaneMode = 0x88,
|
||||||
|
LedBrightUp = 0xC4,
|
||||||
|
LedBrightDown = 0xC5,
|
||||||
|
AuraPrevious = 0xB2,
|
||||||
|
AuraNext = 0xB3,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for GX502GWKeys {
|
||||||
|
fn from(byte: u8) -> Self {
|
||||||
|
match byte {
|
||||||
|
0x38 => GX502GWKeys::Rog,
|
||||||
|
0x7C => GX502GWKeys::MicToggle,
|
||||||
|
0xAE => GX502GWKeys::Fan,
|
||||||
|
0x35 => GX502GWKeys::ScreenToggle,
|
||||||
|
0x10 => GX502GWKeys::ScreenBrightDown,
|
||||||
|
0x20 => GX502GWKeys::ScreenBrightUp,
|
||||||
|
0x6b => GX502GWKeys::TouchPadToggle,
|
||||||
|
0x6C => GX502GWKeys::Sleep,
|
||||||
|
0x88 => GX502GWKeys::AirplaneMode,
|
||||||
|
0xC4 => GX502GWKeys::LedBrightUp,
|
||||||
|
0xC5 => GX502GWKeys::LedBrightDown,
|
||||||
|
0xB2 => GX502GWKeys::AuraPrevious,
|
||||||
|
0xB3 => GX502GWKeys::AuraNext,
|
||||||
|
_ => GX502GWKeys::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
pub mod aura;
|
pub mod aura;
|
||||||
|
pub mod config;
|
||||||
pub mod core;
|
pub mod core;
|
||||||
mod error;
|
mod error;
|
||||||
|
pub mod hotkeys;
|
||||||
|
|||||||
Reference in New Issue
Block a user