From c93e72507c79e7e77226db5bf77fdaa09d4d78a7 Mon Sep 17 00:00:00 2001 From: Abdullah Hamed Date: Fri, 5 Jan 2024 12:24:15 -0800 Subject: [PATCH] Fixed Ayaneo RGB reset on connect and disconnect of power (#929) * Fixed Ayaneo RGB reset on connect and disconnect of power * Added support for both disconnect and reconnect of power to ayaneo RGB controls * changed string operations to assigning PowerLineStatus only --- .../Devices/AYANEO/AYANEODevice.cs | 17 ++++++++++++----- .../Managers/DynamicLightingManager.cs | 1 - 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/HandheldCompanion/Devices/AYANEO/AYANEODevice.cs b/HandheldCompanion/Devices/AYANEO/AYANEODevice.cs index 3c17e3da4..63c6b2032 100644 --- a/HandheldCompanion/Devices/AYANEO/AYANEODevice.cs +++ b/HandheldCompanion/Devices/AYANEO/AYANEODevice.cs @@ -19,12 +19,12 @@ private enum JoystickSelection private byte maxIntensity = 100; // Use the max brightness for color brightness combination value private int prevBatteryLevelPercentage; - private PowerStatus prevPowerStatus; + private PowerLineStatus prevPowerStatus; public AYANEODevice() { - prevPowerStatus = SystemInformation.PowerStatus; - prevBatteryLevelPercentage = (int)(prevPowerStatus.BatteryLifePercent * 100); + prevPowerStatus = SystemInformation.PowerStatus.PowerLineStatus; + prevBatteryLevelPercentage = (int)(SystemInformation.PowerStatus.BatteryLifePercent * 100); PowerManager.PowerStatusChanged += PowerManager_PowerStatusChanged; } @@ -40,12 +40,19 @@ private void PowerManager_PowerStatusChanged(PowerStatus powerStatus) int currentBatteryLevelPercentage = (int)(powerStatus.BatteryLifePercent * 100); // Check if the device went from battery to charging - if (powerStatus.PowerLineStatus == PowerLineStatus.Online && prevPowerStatus.PowerLineStatus == PowerLineStatus.Offline) + if (powerStatus.PowerLineStatus == PowerLineStatus.Online && prevPowerStatus == PowerLineStatus.Offline) { LogManager.LogDebug("Ayaneo LED, device went from battery to charging, apply color"); base.PowerStatusChange(this); } + // Check if the device went from charging to battery + if (powerStatus.PowerLineStatus == PowerLineStatus.Offline && prevPowerStatus == PowerLineStatus.Online) + { + LogManager.LogDebug("Ayaneo LED, device went from charging to battery, apply color"); + base.PowerStatusChange(this); + } + // Check for the battery level change scenarios // Check if the battery went from 99 or lower to 100 @@ -64,7 +71,7 @@ private void PowerManager_PowerStatusChanged(PowerStatus powerStatus) // Track battery level % and power status for next round prevBatteryLevelPercentage = currentBatteryLevelPercentage; - prevPowerStatus = powerStatus; + prevPowerStatus = powerStatus.PowerLineStatus; } private void SetJoystick(JoystickSelection joyStick) diff --git a/HandheldCompanion/Managers/DynamicLightingManager.cs b/HandheldCompanion/Managers/DynamicLightingManager.cs index d63f176fb..22b124485 100644 --- a/HandheldCompanion/Managers/DynamicLightingManager.cs +++ b/HandheldCompanion/Managers/DynamicLightingManager.cs @@ -131,7 +131,6 @@ private static void InitializeDirect3DDevice() else { // Handle other exceptions here - throw; } } }