Skip to content

Commit 31bb560

Browse files
Merge pull request #24 from FrameworkComputer/info-granularity
chromium_ec: Add ReducedPowerInfo
2 parents 14ca5ad + 8319a2d commit 31bb560

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

framework_lib/src/chromium_ec/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub const BOARD_VERSION_15: u8 = 15;
313313
pub struct EcRequestExpansionBayStatus {}
314314

315315
#[repr(C, packed)]
316-
#[derive(Clone, Copy, PartialEq, Eq)]
316+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
317317
pub struct EcResponseExpansionBayStatus {
318318
pub state: u8,
319319
pub board_id_0: u8,

framework_lib/src/chromium_ec/input_deck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl From<u8> for InputDeckState {
130130
}
131131
}
132132

133-
#[derive(Clone, PartialEq, Eq)]
133+
#[derive(Clone, PartialEq, Eq, Debug)]
134134
pub struct InputDeckStatus {
135135
pub state: InputDeckState,
136136
pub hubboard_present: bool,
@@ -197,7 +197,7 @@ impl From<EcResponseDeckState> for InputDeckStatus {
197197
}
198198
}
199199

200-
#[derive(Clone, PartialEq, Eq)]
200+
#[derive(Clone, PartialEq, Eq, Debug)]
201201
pub struct TopRowPositions {
202202
/// C1 all the way left
203203
/// B1 all the way left

framework_lib/src/power.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,40 @@ pub struct PowerInfo {
9797
pub battery: Option<BatteryInformation>,
9898
}
9999

100+
#[derive(Debug, Clone, PartialEq, Eq)]
101+
pub struct ReducedBatteryInformation {
102+
pub cycle_count: u32,
103+
pub charge_percentage: u32, // Calculated based on Remaining Capacity / LFCC
104+
pub charging: bool,
105+
}
106+
107+
/// Reduced version of PowerInfo
108+
///
109+
/// Usually you won't need all of the fields.
110+
/// Some of them (e.g. present_voltage) will vary with a high frequency, so it's not good to
111+
/// compare two PowerInfo structs to see whether the battery status has changed.
112+
#[derive(Debug, Clone, PartialEq, Eq)]
113+
pub struct ReducedPowerInfo {
114+
pub ac_present: bool,
115+
pub battery: Option<ReducedBatteryInformation>,
116+
}
117+
impl From<PowerInfo> for ReducedPowerInfo {
118+
fn from(val: PowerInfo) -> Self {
119+
ReducedPowerInfo {
120+
ac_present: val.ac_present,
121+
battery: if let Some(b) = val.battery {
122+
Some(ReducedBatteryInformation {
123+
cycle_count: b.cycle_count,
124+
charge_percentage: b.charge_percentage,
125+
charging: b.charging,
126+
})
127+
} else {
128+
None
129+
},
130+
}
131+
}
132+
}
133+
100134
fn read_string(ec: &CrosEc, address: u16) -> String {
101135
let bytes = ec.read_memory(address, EC_MEMMAP_TEXT_MAX).unwrap();
102136
String::from_utf8_lossy(bytes.as_slice()).replace(|c: char| c == '\0', "")

0 commit comments

Comments
 (0)