Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerMateVolume: receive reliable notifications when the computer resumes from standby, so device settings can be reset #2

Closed
Aldaviva opened this issue Jul 15, 2023 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Aldaviva
Copy link
Owner

Aldaviva commented Jul 15, 2023

Problem

PowerMate devices do not persist their settings (like LED brightness) when the computer resumes from standby. On its own, the device will revert its brightness to the default value when the computer resumes, as if you had replugged it.

Broken workaround

#1: To work around this, PowerMateVolume listens for the SystemEvents.PowerModeChanged event, and uses that to reset the device settings when resuming from standby by setting all the HID features again based on the in-memory values. It also resets all the features on any device input (like rotation) if the expected and actual settings differ, but this relies on the user manually using the PowerMate to fix the settings.

Unfortunately, SystemEvents only fires the PowerModeChanged event on resume roughly 95% of the time. In the remaining occurrences, the event is not fired and PowerMateVolume does not reset the settings, so the LED brightness and other settings will be wrong.

Better workaround

To fix this, maybe we should detect resumes using ETW instead of whatever message pump bullshit SystemEvents uses.

Fail2Ban4Win has an example of programmatically listening for ETW records, although that's written for .NET Framework instead of .NET Core, so the dependencies may be different.

Standby and resume records are found in the System log, from the Kernel-Power source, with event IDs 42 (standby) and 107 (resume).

@Aldaviva Aldaviva added the bug Something isn't working label Jul 15, 2023
@Aldaviva Aldaviva self-assigned this Jul 15, 2023
Aldaviva added a commit that referenced this issue Jul 15, 2023
… resumes from standby, so device settings can be reset
@Aldaviva
Copy link
Owner Author

The Event Log listener solution seems to be working well so far.

Aldaviva added a commit that referenced this issue Aug 1, 2023
… resumes from standby, so device settings can be reset [add documentation and unit tests, remove log message dialogs]
@Aldaviva Aldaviva added this to the 1.1.0 milestone Aug 1, 2023
@Aldaviva Aldaviva closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant