Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions embedded-batteries/src/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ impl From<PowerUnit> for u32 {
}
}

impl TryFrom<u32> for PowerUnit {
type Error = ();
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::MilliWatts),
1 => Ok(Self::MilliAmps),
_ => Err(()),
}
}
}

/// Battery Technology.
#[repr(u32)]
#[derive(Default, Copy, Clone, PartialEq, Eq, IntoBytes, Immutable)]
Expand All @@ -210,6 +221,17 @@ impl From<BatteryTechnology> for u32 {
}
}

impl TryFrom<u32> for BatteryTechnology {
type Error = ();
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::Primary),
1 => Ok(Self::Secondary),
_ => Err(()),
}
}
}

/// Battery Swapping Capability.
#[derive(Default, Copy, Clone, PartialEq, Eq, IntoBytes, Immutable)]
#[repr(u32)]
Expand All @@ -234,6 +256,18 @@ impl From<BatterySwapCapability> for u32 {
}
}

impl TryFrom<u32> for BatterySwapCapability {
type Error = ();
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::NonSwappable),
1 => Ok(Self::ColdSwappable),
2 => Ok(Self::HotSwappable),
_ => Err(()),
}
}
}

/// PSR: Power Source Status.
///
/// Represents whether a power source (e.g., AC adapter) is currently online or offline.
Expand Down Expand Up @@ -272,6 +306,17 @@ impl From<PowerSource> for u32 {
}
}

impl TryFrom<u32> for PowerSource {
type Error = ();
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::Offline),
1 => Ok(Self::Online),
_ => Err(()),
}
}
}

/// PIF: Power Source Information.
///
/// Represents static information about a power source device. This information
Expand Down Expand Up @@ -451,6 +496,18 @@ pub enum ThresholdId {
SustainablePeakPower = 2,
}

impl TryFrom<u32> for ThresholdId {
type Error = ();
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::ClearAll),
1 => Ok(Self::InstantaneousPeakPower),
2 => Ok(Self::SustainablePeakPower),
_ => Err(()),
}
}
}

/// Return codes for BPT operations.
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq)]
Expand Down