mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Control the backlight
This commit is contained in:
1
.idea/dictionaries/luke.xml
generated
1
.idea/dictionaries/luke.xml
generated
@@ -1,6 +1,7 @@
|
|||||||
<component name="ProjectDictionaryState">
|
<component name="ProjectDictionaryState">
|
||||||
<dictionary name="luke">
|
<dictionary name="luke">
|
||||||
<words>
|
<words>
|
||||||
|
<w>backlight</w>
|
||||||
<w>hotkey</w>
|
<w>hotkey</w>
|
||||||
</words>
|
</words>
|
||||||
</dictionary>
|
</dictionary>
|
||||||
|
|||||||
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -125,6 +125,12 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "numtoa"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e521b6adefa0b2c1fa5d2abdf9a5216288686fe6146249215d884c0e5ab320b0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
@@ -180,6 +186,7 @@ dependencies = [
|
|||||||
"rusb",
|
"rusb",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
|
"sysfs-class",
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -222,6 +229,15 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sysfs-class"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "718e4a5d0e144ff01e05bb8618a4997d8901cdec74cf25826bca2535ef406f3e"
|
||||||
|
dependencies = [
|
||||||
|
"numtoa",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "take_mut"
|
name = "take_mut"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ 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"
|
toml = "0.5"
|
||||||
|
sysfs-class = "0.1.2"
|
||||||
@@ -4,6 +4,8 @@ use rusb::{DeviceHandle, Error};
|
|||||||
use std::cell::{Ref, RefCell};
|
use std::cell::{Ref, RefCell};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use sysfs_class::Brightness;
|
||||||
|
use sysfs_class::SysClass;
|
||||||
|
|
||||||
pub const LED_MSG_LEN: usize = 17;
|
pub const LED_MSG_LEN: usize = 17;
|
||||||
static LED_INIT1: [u8; 2] = [0x5d, 0xb9];
|
static LED_INIT1: [u8; 2] = [0x5d, 0xb9];
|
||||||
@@ -165,15 +167,6 @@ impl RogCore {
|
|||||||
Err(Error::NotSupported)
|
Err(Error::NotSupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn load_config(&mut self) -> Result<(), Error> {
|
|
||||||
// if let Some(current) = self.config.get_current() {
|
|
||||||
// self.aura_set_and_save(¤t)?;
|
|
||||||
// }
|
|
||||||
// let bright = RogCore::aura_brightness_bytes(self.config.brightness)?;
|
|
||||||
// self.aura_set_and_save(&bright)?;
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn poll_keyboard(&self, buf: &mut [u8; 32]) -> Result<Option<usize>, Error> {
|
pub fn poll_keyboard(&self, buf: &mut [u8; 32]) -> Result<Option<usize>, Error> {
|
||||||
match self
|
match self
|
||||||
.handle
|
.handle
|
||||||
@@ -192,3 +185,43 @@ impl RogCore {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Backlight {
|
||||||
|
backlight: sysfs_class::Backlight,
|
||||||
|
step: u64,
|
||||||
|
max: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Backlight {
|
||||||
|
pub fn new(id: &str) -> Result<Backlight, std::io::Error> {
|
||||||
|
for bl in sysfs_class::Backlight::iter() {
|
||||||
|
let bl = bl?;
|
||||||
|
if bl.id() == id {
|
||||||
|
let max = bl.max_brightness()?;
|
||||||
|
let step = max / 50;
|
||||||
|
return Ok(Backlight {
|
||||||
|
backlight: bl,
|
||||||
|
step,
|
||||||
|
max,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("Backlight not found")
|
||||||
|
}
|
||||||
|
pub fn step_up(&self) {
|
||||||
|
let brightness = self.backlight.brightness().unwrap();
|
||||||
|
if brightness + self.step <= self.max {
|
||||||
|
self.backlight
|
||||||
|
.set_brightness(brightness + self.step)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn step_down(&self) {
|
||||||
|
let brightness = self.backlight.brightness().unwrap();
|
||||||
|
if brightness > self.step {
|
||||||
|
self.backlight
|
||||||
|
.set_brightness(brightness - self.step)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
use crate::aura::BuiltInModeByte;
|
use crate::aura::BuiltInModeByte;
|
||||||
use crate::core::RogCore;
|
use crate::core::{Backlight, RogCore};
|
||||||
|
|
||||||
// ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="gdbus call
|
// ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="gdbus call
|
||||||
// --session --dest org.gnome.SettingsDaemon.Power
|
// --session --dest org.gnome.SettingsDaemon.Power
|
||||||
// --object-path /org/gnome/SettingsDaemon/Power
|
// --object-path /org/gnome/SettingsDaemon/Power
|
||||||
// --method org.freedesktop.DBus.Properties.Set org.gnome.SettingsDaemon.Power.Screen Brightness '<int32 65>'"
|
// --method org.freedesktop.DBus.Properties.Set org.gnome.SettingsDaemon.Power.Screen Brightness '<int32 65>'"
|
||||||
|
|
||||||
const POWER_BUS_NAME: &'static str = "org.gnome.SettingsDaemon.Power";
|
|
||||||
const POWER_IFACE_NAME: &'static str = "org.gnome.SettingsDaemon.Power.Screen";
|
|
||||||
const POWER_PATH: &'static str = "/org/gnome/SettingsDaemon/Power";
|
|
||||||
|
|
||||||
pub trait Laptop {
|
pub trait Laptop {
|
||||||
fn do_hotkey_action(&self, core: &mut RogCore, key_byte: u8);
|
fn do_hotkey_action(&self, core: &mut RogCore, key_byte: u8);
|
||||||
fn hotkey_group_byte(&self) -> u8;
|
fn hotkey_group_byte(&self) -> u8;
|
||||||
@@ -19,6 +15,7 @@ pub trait Laptop {
|
|||||||
fn board_name(&self) -> &str;
|
fn board_name(&self) -> &str;
|
||||||
fn prod_family(&self) -> &str;
|
fn prod_family(&self) -> &str;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LaptopGX502GW {
|
pub struct LaptopGX502GW {
|
||||||
usb_vendor: u16,
|
usb_vendor: u16,
|
||||||
usb_product: u16,
|
usb_product: u16,
|
||||||
@@ -28,9 +25,12 @@ pub struct LaptopGX502GW {
|
|||||||
min_bright: u8,
|
min_bright: u8,
|
||||||
max_bright: u8,
|
max_bright: u8,
|
||||||
supported_modes: Vec<BuiltInModeByte>,
|
supported_modes: Vec<BuiltInModeByte>,
|
||||||
|
backlight: Backlight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LaptopGX502GW {
|
impl LaptopGX502GW {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
// Find backlight
|
||||||
LaptopGX502GW {
|
LaptopGX502GW {
|
||||||
usb_vendor: 0x0B05,
|
usb_vendor: 0x0B05,
|
||||||
usb_product: 0x1866,
|
usb_product: 0x1866,
|
||||||
@@ -53,6 +53,7 @@ impl LaptopGX502GW {
|
|||||||
BuiltInModeByte::ThinZoomy,
|
BuiltInModeByte::ThinZoomy,
|
||||||
BuiltInModeByte::WideZoomy,
|
BuiltInModeByte::WideZoomy,
|
||||||
],
|
],
|
||||||
|
backlight: Backlight::new("intel_backlight").unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +108,12 @@ impl Laptop for LaptopGX502GW {
|
|||||||
rogcore.config().write();
|
rogcore.config().write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GX502GWKeys::ScreenBrightUp => {}
|
GX502GWKeys::ScreenBrightUp => {
|
||||||
|
self.backlight.step_up();
|
||||||
|
}
|
||||||
|
GX502GWKeys::ScreenBrightDown => {
|
||||||
|
self.backlight.step_down();
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if key_byte != 0 {
|
if key_byte != 0 {
|
||||||
dbg!(&key_byte);
|
dbg!(&key_byte);
|
||||||
|
|||||||
Reference in New Issue
Block a user