mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
@@ -13,7 +13,7 @@ use rog_anime::{
|
|||||||
};
|
};
|
||||||
use rog_supported::AnimeSupportedFunctions;
|
use rog_supported::AnimeSupportedFunctions;
|
||||||
use rusb::{Device, DeviceHandle};
|
use rusb::{Device, DeviceHandle};
|
||||||
use std::{cell::{RefCell}, error::Error, sync::{Arc, Mutex}, thread::sleep};
|
use std::{cell::RefCell, error::Error, sync::{Arc, Mutex}, thread::sleep};
|
||||||
use std::{
|
use std::{
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
@@ -32,6 +32,7 @@ impl GetSupported for CtrlAnime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct CtrlAnime {
|
pub struct CtrlAnime {
|
||||||
|
_node: String,
|
||||||
handle: RefCell<DeviceHandle<rusb::GlobalContext>>,
|
handle: RefCell<DeviceHandle<rusb::GlobalContext>>,
|
||||||
cache: AnimeConfigCached,
|
cache: AnimeConfigCached,
|
||||||
config: AnimeConfig,
|
config: AnimeConfig,
|
||||||
@@ -44,6 +45,7 @@ pub struct CtrlAnime {
|
|||||||
impl CtrlAnime {
|
impl CtrlAnime {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(config: AnimeConfig) -> Result<CtrlAnime, Box<dyn Error>> {
|
pub fn new(config: AnimeConfig) -> Result<CtrlAnime, Box<dyn Error>> {
|
||||||
|
let node = Self::find_node("193b")?;
|
||||||
let device = Self::get_dev_handle()?;
|
let device = Self::get_dev_handle()?;
|
||||||
|
|
||||||
info!("Device has an AniMe Matrix display");
|
info!("Device has an AniMe Matrix display");
|
||||||
@@ -51,6 +53,7 @@ impl CtrlAnime {
|
|||||||
cache.init_from_config(&config)?;
|
cache.init_from_config(&config)?;
|
||||||
|
|
||||||
let ctrl = CtrlAnime {
|
let ctrl = CtrlAnime {
|
||||||
|
_node: node,
|
||||||
handle: RefCell::new(device),
|
handle: RefCell::new(device),
|
||||||
cache,
|
cache,
|
||||||
config,
|
config,
|
||||||
@@ -62,6 +65,34 @@ impl CtrlAnime {
|
|||||||
Ok(ctrl)
|
Ok(ctrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn find_node(id_product: &str) -> Result<String, RogError> {
|
||||||
|
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
RogError::Udev("enumerator failed".into(), err)
|
||||||
|
})?;
|
||||||
|
enumerator.match_subsystem("usb").map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
RogError::Udev("match_subsystem failed".into(), err)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
for device in enumerator.scan_devices().map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
RogError::Udev("scan_devices failed".into(), err)
|
||||||
|
})? {
|
||||||
|
if let Some(attr) = device.attribute_value("idProduct") {
|
||||||
|
if attr == id_product {
|
||||||
|
if let Some(dev_node) = device.devnode() {
|
||||||
|
info!("Using device at: {:?} for AniMe control", dev_node);
|
||||||
|
return Ok(dev_node.to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(RogError::MissingFunction(
|
||||||
|
"ASUS AniMe device node not found".into(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
fn get_dev_handle() -> Result<DeviceHandle<rusb::GlobalContext>, Box<dyn Error>> {
|
fn get_dev_handle() -> Result<DeviceHandle<rusb::GlobalContext>, Box<dyn Error>> {
|
||||||
// We don't expect this ID to ever change
|
// We don't expect this ID to ever change
|
||||||
let device = CtrlAnime::get_device(0x0b05, 0x193b)?;
|
let device = CtrlAnime::get_device(0x0b05, 0x193b)?;
|
||||||
@@ -188,6 +219,11 @@ impl CtrlAnime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_bytes(&self, message: &[u8]) {
|
fn write_bytes(&self, message: &[u8]) {
|
||||||
|
// if let Ok(mut file) = OpenOptions::new().write(true).open(&self.node) {
|
||||||
|
// println!("write: {:02x?}", &message);
|
||||||
|
// return file
|
||||||
|
// .write_all(message).unwrap();
|
||||||
|
// }
|
||||||
let mut error = false;
|
let mut error = false;
|
||||||
|
|
||||||
match self.handle.borrow().write_control(
|
match self.handle.borrow().write_control(
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use rog_profiles::error::ProfileError;
|
|
||||||
use rog_profiles::{FanCurves, Profile};
|
use rog_profiles::{FanCurves, Profile};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
@@ -16,27 +15,22 @@ pub struct ProfileConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ProfileConfig {
|
impl ProfileConfig {
|
||||||
fn new(config_path: String) -> Result<Self, ProfileError> {
|
fn new(config_path: String) -> Self {
|
||||||
let mut platform = ProfileConfig {
|
let mut platform = ProfileConfig {
|
||||||
config_path,
|
config_path,
|
||||||
active: Profile::Balanced,
|
active: Profile::Balanced,
|
||||||
fan_curves: None,
|
fan_curves: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !Profile::is_platform_profile_supported() {
|
|
||||||
return Err(ProfileError::NotSupported);
|
|
||||||
}
|
|
||||||
|
|
||||||
if FanCurves::is_fan_curves_supported() {
|
if FanCurves::is_fan_curves_supported() {
|
||||||
let mut curves = FanCurves::default();
|
let mut curves = FanCurves::default();
|
||||||
curves.update_from_platform();
|
curves.update_from_platform();
|
||||||
platform.fan_curves = Some(curves);
|
platform.fan_curves = Some(curves);
|
||||||
}
|
}
|
||||||
Ok(platform)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ProfileConfig {
|
platform
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load(config_path: String) -> Self {
|
pub fn load(config_path: String) -> Self {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
@@ -48,7 +42,7 @@ impl ProfileConfig {
|
|||||||
let mut config;
|
let mut config;
|
||||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||||
if read_len == 0 {
|
if read_len == 0 {
|
||||||
config = Self::new(config_path).unwrap();
|
config = Self::new(config_path);
|
||||||
} else if let Ok(data) = serde_json::from_str(&buf) {
|
} else if let Ok(data) = serde_json::from_str(&buf) {
|
||||||
config = data;
|
config = data;
|
||||||
config.config_path = config_path;
|
config.config_path = config_path;
|
||||||
@@ -57,7 +51,7 @@ impl ProfileConfig {
|
|||||||
panic!("Please remove {} then restart service", config_path);
|
panic!("Please remove {} then restart service", config_path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config = Self::new(config_path).unwrap()
|
config = Self::new(config_path)
|
||||||
}
|
}
|
||||||
config.write();
|
config.write();
|
||||||
config
|
config
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ impl GetSupported for CtrlPlatformProfile {
|
|||||||
if !Profile::is_platform_profile_supported() {
|
if !Profile::is_platform_profile_supported() {
|
||||||
warn!(
|
warn!(
|
||||||
r#"
|
r#"
|
||||||
platform_profile kernel interface not found, your laptop does not support this, or the iterface is missing.
|
platform_profile kernel interface not found, your laptop does not support this, or the interface is missing.
|
||||||
To enable profile support you require a kernel with the following patch applied:
|
To enable profile support you require a kernel with the following patch applied:
|
||||||
https://lkml.org/lkml/2021/8/18/1022
|
https://lkml.org/lkml/2021/8/18/1022
|
||||||
"#
|
"#
|
||||||
@@ -51,7 +51,7 @@ https://lkml.org/lkml/2021/8/18/1022
|
|||||||
if !FanCurves::is_fan_curves_supported() {
|
if !FanCurves::is_fan_curves_supported() {
|
||||||
info!(
|
info!(
|
||||||
r#"
|
r#"
|
||||||
fan curves kernel interface not found, your laptop does not support this, or the iterface is missing.
|
fan curves kernel interface not found, your laptop does not support this, or the interface is missing.
|
||||||
To enable fan-curve support you require a kernel with the following patch applied:
|
To enable fan-curve support you require a kernel with the following patch applied:
|
||||||
https://lkml.org/lkml/2021/8/20/232
|
https://lkml.org/lkml/2021/8/20/232
|
||||||
Please note that as of 24/08/2021 this is not final.
|
Please note that as of 24/08/2021 this is not final.
|
||||||
|
|||||||
Reference in New Issue
Block a user