Fan mode toggling enabled

This commit is contained in:
Luke
2020-04-23 20:48:14 +12:00
parent 11548217b7
commit 588c71d9ae
7 changed files with 76 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rog-daemon" name = "rog-daemon"
version = "0.5.0" version = "0.6.0"
authors = ["Luke <luke@ljones.dev>"] authors = ["Luke <luke@ljones.dev>"]
edition = "2018" edition = "2018"

View File

@@ -65,7 +65,7 @@ Currently if no options are supplied for the CLI mode selection then a default i
+ [X] Screen off? Now mapped to a keycode but has no effect + [X] Screen off? Now mapped to a keycode but has no effect
+ [X] Screen brightness up/down + [X] Screen brightness up/down
+ [ ] ROG key custom mapping (Can be done in source) + [ ] ROG key custom mapping (Can be done in source)
+ [ ] Fan/Performance mode + [X] Fan/Performance mode
+ [ ] Screen off?? + [ ] Screen off??
+ [X] Touchpad toggle (using a virtual keyboard to emit F21...) + [X] Touchpad toggle (using a virtual keyboard to emit F21...)
- [X] Capture and use hotkeys **Partially completed: aura keys work** - [X] Capture and use hotkeys **Partially completed: aura keys work**
@@ -73,7 +73,7 @@ Currently if no options are supplied for the CLI mode selection then a default i
+ [X] Volume + media controls work + [X] Volume + media controls work
- [X] Logging - required for journalctl - [X] Logging - required for journalctl
As the daemon currently stands it should be enough for a functional system. Fan mode toggling requires a newer kernel. I'm unsure when the patches required for it got merged - I've tested with the 5.6.6 kernel only.
## Other Laptops ## Other Laptops

View File

@@ -7,6 +7,7 @@ pub static CONFIG_PATH: &'static str = "/etc/rogcore.conf";
#[derive(Default, Deserialize, Serialize)] #[derive(Default, Deserialize, Serialize)]
pub struct Config { pub struct Config {
pub fan_mode: u8,
pub brightness: u8, pub brightness: u8,
pub current_mode: [u8; 4], pub current_mode: [u8; 4],
pub builtin_modes: BuiltInModeBytes, pub builtin_modes: BuiltInModeBytes,

View File

@@ -9,8 +9,12 @@ use crate::{
}; };
use aho_corasick::AhoCorasick; use aho_corasick::AhoCorasick;
use gumdrop::Options; use gumdrop::Options;
use log::{error, warn}; use log::{error, info, warn};
use rusb::DeviceHandle; use rusb::DeviceHandle;
use std::error::Error;
use std::fs::OpenOptions;
use std::io::{Read, Write};
use std::path::Path;
use std::process::Command; use std::process::Command;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
@@ -27,6 +31,9 @@ static LED_INIT5: [u8; 6] = [0x5e, 0x05, 0x20, 0x31, 0, 0x08];
static LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; static LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
static FAN_TYPE_1_PATH: &'static str = "/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy";
static FAN_TYPE_2_PATH: &'static str = "/sys/devices/platform/asus-nb-wmi/fan_boost_mode";
/// ROG device controller /// ROG device controller
/// ///
/// For the GX502GW the LED setup sequence looks like: /// For the GX502GW the LED setup sequence looks like:
@@ -79,6 +86,30 @@ impl RogCore {
}) })
} }
pub(crate) fn reload(&mut self) -> Result<(), Box<dyn Error>> {
let mode_curr = self.config.current_mode[3];
let mode = self
.config
.builtin_modes
.get_field_from(BuiltInModeByte::from(mode_curr).into())
.unwrap()
.to_owned();
self.aura_write_messages(&[&mode])?;
let path = if Path::new(FAN_TYPE_1_PATH).exists() {
FAN_TYPE_1_PATH
} else if Path::new(FAN_TYPE_2_PATH).exists() {
FAN_TYPE_2_PATH
} else {
return Ok(());
};
let mut file = OpenOptions::new().write(true).open(path)?;
file.write(format!("{:?}\n", self.config.fan_mode).as_bytes())?;
Ok(())
}
pub(crate) fn virt_keys(&mut self) -> &mut VirtKeys { pub(crate) fn virt_keys(&mut self) -> &mut VirtKeys {
&mut self.virt_keys &mut self.virt_keys
} }
@@ -312,6 +343,36 @@ impl RogCore {
.to_owned(); .to_owned();
self.aura_set_and_save(supported_modes, &mode_next) self.aura_set_and_save(supported_modes, &mode_next)
} }
pub(crate) fn fan_mode_step(&mut self) -> Result<(), Box<dyn Error>> {
let path = if Path::new(FAN_TYPE_1_PATH).exists() {
FAN_TYPE_1_PATH
} else if Path::new(FAN_TYPE_2_PATH).exists() {
FAN_TYPE_2_PATH
} else {
return Ok(());
};
let mut file = OpenOptions::new().read(true).write(true).open(path)?;
let mut buf = String::new();
if let Ok(_) = file.read_to_string(&mut buf) {
let mut n = u8::from_str_radix(&buf.trim_end(), 10)?;
info!("Current fan mode: {:?}", &n);
if n < 2 {
n += 1;
} else {
n = 0;
}
info!("Fan mode stepped to: {:?}", &n);
file.write(format!("{:?}\n", n).as_bytes())?;
self.config.fan_mode = n;
self.config.write();
}
Ok(())
}
} }
pub(crate) struct Backlight { pub(crate) struct Backlight {

View File

@@ -14,7 +14,7 @@ use std::time::Duration;
pub fn start_daemon() -> Result<(), Box<dyn Error>> { pub fn start_daemon() -> Result<(), Box<dyn Error>> {
let laptop = match_laptop(); let laptop = match_laptop();
let rogcore = RogCore::new(&*laptop).map_or_else( let mut rogcore = RogCore::new(&*laptop).map_or_else(
|err| { |err| {
error!("{}", err); error!("{}", err);
panic!("{}", err); panic!("{}", err);
@@ -24,6 +24,8 @@ pub fn start_daemon() -> Result<(), Box<dyn Error>> {
daemon daemon
}, },
); );
// Reload settings
rogcore.reload()?;
let mut connection = Connection::new_system().map_or_else( let mut connection = Connection::new_system().map_or_else(
|err| { |err| {

View File

@@ -4,7 +4,7 @@ use crate::error::AuraError;
use crate::virt_device::ConsumerKeys; use crate::virt_device::ConsumerKeys;
//use keycode::{KeyMap, KeyMappingId, KeyState, KeyboardState}; //use keycode::{KeyMap, KeyMappingId, KeyState, KeyboardState};
use super::Laptop; use super::Laptop;
use log::info; use log::{info, warn};
pub(super) struct LaptopGX502 { pub(super) struct LaptopGX502 {
usb_vendor: u16, usb_vendor: u16,
@@ -107,7 +107,11 @@ impl LaptopGX502 {
GX502Keys::Sleep => rogcore.suspend_with_systemd(), GX502Keys::Sleep => rogcore.suspend_with_systemd(),
GX502Keys::AirplaneMode => rogcore.toggle_airplane_mode(), GX502Keys::AirplaneMode => rogcore.toggle_airplane_mode(),
GX502Keys::MicToggle => {} GX502Keys::MicToggle => {}
GX502Keys::Fan => {} GX502Keys::Fan => {
rogcore.fan_mode_step().unwrap_or_else(|err| {
warn!("Couldn't toggle fan mode: {:?}", err);
});
}
GX502Keys::ScreenToggle => { GX502Keys::ScreenToggle => {
rogcore.virt_keys().press(ConsumerKeys::BacklightTog.into()); rogcore.virt_keys().press(ConsumerKeys::BacklightTog.into());
} }

View File

@@ -10,7 +10,7 @@ use env_logger::{Builder, Target};
use gumdrop::Options; use gumdrop::Options;
use log::LevelFilter; use log::LevelFilter;
static VERSION: &'static str = "0.5.0"; static VERSION: &'static str = "0.6.0";
#[derive(Debug, Options)] #[derive(Debug, Options)]
struct CLIStart { struct CLIStart {