Check and pass error if charge limit not in 20-100 range

Closes #144
This commit is contained in:
Luke D. Jones
2021-10-27 22:59:04 +13:00
parent 3f0df82f2d
commit 7bc6c83a04
7 changed files with 16 additions and 11 deletions

View File

@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Convert fan curve percentage to 0-255 expected by kernel driver only if '%' char is used, otherwise the expected range for fan power is 0-255
- Use correct error in daemon for invalid charging limit
- Enforce charging limit values in range 20-100
### Added
- LED modes for G513QR

6
Cargo.lock generated
View File

@@ -44,7 +44,7 @@ dependencies = [
[[package]]
name = "asusctl"
version = "4.0.4"
version = "4.0.5"
dependencies = [
"daemon",
"gif",
@@ -208,7 +208,7 @@ dependencies = [
[[package]]
name = "daemon"
version = "4.0.4"
version = "4.0.5"
dependencies = [
"env_logger",
"log",
@@ -932,7 +932,7 @@ dependencies = [
[[package]]
name = "rog_profiles"
version = "1.1.2"
version = "1.1.3"
dependencies = [
"serde",
"serde_derive",

View File

@@ -1,6 +1,6 @@
[package]
name = "asusctl"
version = "4.0.4"
version = "4.0.5"
authors = ["Luke D Jones <luke@ljones.dev>"]
edition = "2018"

View File

@@ -1,6 +1,6 @@
[package]
name = "daemon"
version = "4.0.4"
version = "4.0.5"
license = "MPL-2.0"
readme = "README.md"
authors = ["Luke <luke@ljones.dev>"]

View File

@@ -30,7 +30,10 @@ pub struct CtrlCharge {
#[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlCharge {
pub fn set_limit(&mut self, limit: u8) {
pub fn set_limit(&mut self, limit: u8) -> Result<(), RogError> {
if !(20..=100).contains(&limit) {
return Err(RogError::ChargeLimit(limit));
}
if let Ok(mut config) = self.config.try_lock() {
self.set(limit, &mut config)
.map_err(|err| {
@@ -45,6 +48,7 @@ impl CtrlCharge {
})
.ok();
}
Ok(())
}
pub fn limit(&self) -> i8 {
@@ -106,10 +110,7 @@ impl CtrlCharge {
pub(super) fn set(&self, limit: u8, config: &mut Config) -> Result<(), RogError> {
if !(20..=100).contains(&limit) {
warn!(
"Unable to set battery charge limit, must be between 20-100: requested {}",
limit
);
return Err(RogError::ChargeLimit(limit));
}
let path = Self::get_battery_path()?;

View File

@@ -22,6 +22,7 @@ pub enum RogError {
Modprobe(String),
Io(std::io::Error),
Zbus(zbus::Error),
ChargeLimit(u8),
}
impl fmt::Display for RogError {
@@ -46,6 +47,7 @@ impl fmt::Display for RogError {
RogError::Modprobe(detail) => write!(f, "Modprobe error: {}", detail),
RogError::Io(detail) => write!(f, "std::io error: {}", detail),
RogError::Zbus(detail) => write!(f, "Zbus error: {}", detail),
RogError::ChargeLimit(value) => write!(f, "Invalid charging limit, not in range 20-100%: {}", value),
}
}
}

View File

@@ -1,6 +1,6 @@
[package]
name = "rog_profiles"
version = "1.1.2"
version = "1.1.3"
authors = ["Luke D. Jones <luke@ljones.dev>"]
edition = "2018"