Skip to content

Commit

Permalink
feat(tuxedo_sysfs): write part of charging profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
liketechnik committed Jun 22, 2024
1 parent 56c6734 commit 9d41b95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
21 changes: 20 additions & 1 deletion tuxedo_sysfs/src/charging/charge_control.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::io;

use crate::sysfs_util::{
r_file, read_int_list, read_path_to_int_list, read_path_to_string, read_to_string,
r_file, read_int_list, read_path_to_int_list, read_path_to_string, read_to_string, write_int,
write_string,
};

use super::BatteryChargeControl;
Expand Down Expand Up @@ -125,4 +126,22 @@ impl BatteryChargeControl {
.trim()
.to_owned())
}

/// <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power>
/// (section charge_type)
pub async fn set_charge_type(&mut self, charge_type: String) -> Result<(), io::Error> {
write_string(&mut self.charge_type_file, charge_type).await
}

/// generally: 0-100,
/// but may be further restricted to [`Self::available_start_thresholds`]
pub async fn set_start_threshold(&mut self, threshold: u32) -> Result<(), io::Error> {
write_int(&mut self.start_threshold_file, threshold).await
}

/// generally: 0-100,
/// but may be further restricted to [`Self::available_end_thresholds`]
pub async fn set_end_threshold(&mut self, threshold: u32) -> Result<(), io::Error> {
write_int(&mut self.end_threshold_file, threshold).await
}
}
10 changes: 9 additions & 1 deletion tuxedo_sysfs/src/charging/charging_priority.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use crate::sysfs_util::{r_file, read_to_string, read_to_string_list, rw_file};
use crate::sysfs_util::{r_file, read_to_string, read_to_string_list, rw_file, write_string};

use super::ChargingPriority;

Expand Down Expand Up @@ -32,4 +32,12 @@ impl ChargingPriority {
.trim()
.to_owned())
}

/// charge_battery, performance
/// src/ng-app/app/charging-settings/charging-settings.component.ts
/// in TCC
/// / src/uniwill_keyboard.h in tuxedo-keyboard
pub async fn set_charging_priority(&mut self, priority: String) -> Result<(), io::Error> {
write_string(&mut self.charging_priority_file, priority).await
}
}
10 changes: 9 additions & 1 deletion tuxedo_sysfs/src/charging/charging_profile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use crate::sysfs_util::{r_file, read_to_string, read_to_string_list, rw_file};
use crate::sysfs_util::{r_file, read_to_string, read_to_string_list, rw_file, write_string};

use super::ChargingProfile;

Expand Down Expand Up @@ -32,4 +32,12 @@ impl ChargingProfile {
.trim()
.to_owned())
}

/// high_capacity, balanced, stationary according to
/// src/ng-app/app/charging-settings/charging-settings.component.ts
/// in TCC
/// / src/uniwill_keyboard.h in tuxedo-keyboard
pub async fn set_charging_profile(&mut self, profile: String) -> Result<(), io::Error> {
write_string(&mut self.charging_profile_file, profile).await
}
}
4 changes: 4 additions & 0 deletions tuxedo_sysfs/src/sysfs_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ where
pub(crate) async fn write_string(file: &mut fs::File, string: String) -> Result<(), io::Error> {
write_buffer(file, string.into_bytes()).await
}

pub(crate) async fn write_int(file: &mut fs::File, int: u32) -> Result<(), io::Error> {
write_string(file, format!("{}", int)).await
}

0 comments on commit 9d41b95

Please sign in to comment.