Skip to content

Commit

Permalink
Fixed Ayaneo RGB reset on connect and disconnect of power (#929)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
indiesaudi authored Jan 5, 2024
1 parent a93ddab commit c93e725
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 12 additions & 5 deletions HandheldCompanion/Devices/AYANEO/AYANEODevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion HandheldCompanion/Managers/DynamicLightingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ private static void InitializeDirect3DDevice()
else
{
// Handle other exceptions here
throw;
}
}
}
Expand Down

0 comments on commit c93e725

Please sign in to comment.