Skip to content

Commit

Permalink
Merge remote-tracking branch 'tronru/lid-switch-state-change' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Nov 30, 2023
2 parents 0569e26 + 3f03e9b commit 436da87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Add support for user-defined control codes in services.
(See: `Service::notify` and `notify_service.rs` example)
- Add support for `LidSwitchStateChange` in `PowerBroadcastSetting`.
(See: `LidSwitchStateChange`)


## [0.6.0] - 2023-03-07
Expand Down
30 changes: 30 additions & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,29 @@ impl AwayModeState {
}
}

/// Enum indicates the current lid switch state as
/// the Data member of GUID_LIDSWITCH_STATE_CHANGE notification
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum LidSwitchStateChange {
Closed = 0,
Open = 1,
}

impl LidSwitchStateChange {
pub fn to_raw(&self) -> u32 {
*self as u32
}

pub fn from_raw(raw: u32) -> Result<LidSwitchStateChange, ParseRawError> {
match raw {
x if x == LidSwitchStateChange::Closed.to_raw() => Ok(LidSwitchStateChange::Closed),
x if x == LidSwitchStateChange::Open.to_raw() => Ok(LidSwitchStateChange::Open),
_ => Err(ParseRawError::InvalidInteger(raw)),
}
}
}

/// Struct converted from Power::POWERBROADCAST_SETTING
///
/// Please refer to MSDN for more info about the data members:
Expand All @@ -785,6 +808,7 @@ pub enum PowerBroadcastSetting {
PowerSavingStatus(BatterySaverState),
PowerSchemePersonality(PowerSchemePersonality),
SystemAwayMode(AwayModeState),
LidSwitchStateChange(LidSwitchStateChange),
}

impl PowerBroadcastSetting {
Expand Down Expand Up @@ -850,6 +874,12 @@ impl PowerBroadcastSetting {
AwayModeState::from_raw(away_mode_state)?,
))
}
x if is_equal_guid(x, &SystemServices::GUID_LIDSWITCH_STATE_CHANGE) => {
let lid_switch_state = *(data as *const u32);
Ok(PowerBroadcastSetting::LidSwitchStateChange(
LidSwitchStateChange::from_raw(lid_switch_state)?,
))
}
x => Err(ParseRawError::InvalidGuid(string_from_guid(x))),
}
}
Expand Down

0 comments on commit 436da87

Please sign in to comment.