Skip to content

Commit

Permalink
Merge branch 'seerge:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
IceStormNG authored Sep 21, 2024
2 parents fac4772 + 59b5888 commit fe377e5
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 116 deletions.
6 changes: 4 additions & 2 deletions app/Ally/AllyControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
if (!autoTDP && _mode != ControllerMode.Auto) return;

float fps = amdControl.GetFPS();
int? usage = 0;

if (autoTDP && fpsLimit > 0 && fpsLimit <= 120)
{
Expand Down Expand Up @@ -377,7 +378,8 @@ private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)

if (_mode == ControllerMode.Auto)
{
ControllerMode newMode = (fps > 0) ? ControllerMode.Gamepad : ControllerMode.Mouse;
if (fps > 0) usage = amdControl.GetiGpuUse();
ControllerMode newMode = (fps > 0 && usage > 15) ? ControllerMode.Gamepad : ControllerMode.Mouse;

if (_applyMode != newMode) _autoCount++;
else _autoCount = 0;
Expand All @@ -386,7 +388,7 @@ private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
_autoCount = 0;
ApplyMode(newMode);
Logger.WriteLine($"Controller Mode {fps}: {newMode}");
Logger.WriteLine($"Controller Mode (FPS={fps}, USAGE={usage}%): {newMode}");
}
}

Expand Down
7 changes: 5 additions & 2 deletions app/AnimeMatrix/AniMatrixControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ public void SetSlash(bool wakeUp = false)
deviceSlash.SetEnabled(true);
deviceSlash.Init();
deviceSlash.SetLidMode(false);
switch ((SlashMode)running)
{
case SlashMode.Static:
Expand Down Expand Up @@ -150,6 +148,11 @@ public void SetLidMode(bool force = false)
{
bool matrixLid = AppConfig.Is("matrix_lid");

if (deviceSlash is not null)
{
deviceSlash.SetLidMode(!matrixLid);
}

if (matrixLid || force)
{
Logger.WriteLine($"Matrix LidClosed: {lidClose}");
Expand Down
2 changes: 1 addition & 1 deletion app/AnimeMatrix/SlashDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void SetBatterySaver(bool status)

public void SetLidMode(bool status)
{
Set(CreatePacket([0xD8, 0x00, 0x00, 0x02, 0xA5, status ? (byte)0x80 : (byte)0x00]), $"DisableLidClose {status}");
Set(CreatePacket([0xD8, 0x00, 0x00, 0x02, 0xA5, status ? (byte)0x80 : (byte)0x00]), $"SlashLidCloseAnimation {status}");
}

public void SetSleepActive(bool status)
Expand Down
9 changes: 7 additions & 2 deletions app/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static bool IsDUO()
// G14 2020 has no aura, but media keys instead
public static bool NoAura()
{
return (ContainsModel("GA401I") && !ContainsModel("GA401IHR")) || ContainsModel("HN7306");
return (ContainsModel("GA401I") && !ContainsModel("GA401IHR")) || ContainsModel("GA502IU") || ContainsModel("HN7306");
}

public static bool MediaKeys()
Expand All @@ -421,7 +421,7 @@ public static bool MediaKeys()

public static bool IsSingleColor()
{
return ContainsModel("GA401") || ContainsModel("FX517Z") || ContainsModel("FX516P") || ContainsModel("X13") || IsARCNM() || ContainsModel("GA502IU") || ContainsModel("FA617N") || ContainsModel("FA617X") || NoAura();
return ContainsModel("GA401") || ContainsModel("FX517Z") || ContainsModel("FX516P") || ContainsModel("X13") || IsARCNM() || ContainsModel("FA617N") || ContainsModel("FA617X") || NoAura();
}

public static bool IsSlash()
Expand Down Expand Up @@ -691,4 +691,9 @@ public static bool IsForceMiniled()
return ContainsModel("G834JYR") || Is("force_miniled");
}

public static bool SaveDimming()
{
return Is("save_dimming");
}

}
3 changes: 2 additions & 1 deletion app/Battery/BatteryControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static void SetBatteryChargeLimit(int limit = -1)

if (AppConfig.IsChargeLimit6080())
{
if (limit > 80) limit = 100;
if (limit > 85) limit = 100;
else if (limit >= 80) limit = 80;
else if (limit < 60) limit = 60;
}

Expand Down
87 changes: 58 additions & 29 deletions app/Display/ColorProfileHelper.cs

Large diffs are not rendered by default.

68 changes: 54 additions & 14 deletions app/Display/VisualControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static class VisualControl

private static int _brightness = 100;
private static bool _init = true;
private static bool _download = true;
private static string? _splendidPath = null;

private static System.Timers.Timer brightnessTimer = new System.Timers.Timer(200);
Expand Down Expand Up @@ -211,9 +212,19 @@ public static void SetGamut(int mode = -1)

AppConfig.Set("gamut", mode);

if (RunSplendid(SplendidCommand.GamutMode, 0, mode)) return;

if (_init)
var result = RunSplendid(SplendidCommand.GamutMode, 0, mode);
if (result == 0) return;
if (result == -1)
{
Logger.WriteLine("Gamut setting refused, reverting.");
RunSplendid(SplendidCommand.GamutMode, 0, (int)GetDefaultGamut());
if (ProcessHelper.IsUserAdministrator() && _download)
{
_download = false;
ColorProfileHelper.InstallProfile();
}
}
if (result == 1 && _init)
{
_init = false;
RunSplendid(SplendidCommand.Init);
Expand Down Expand Up @@ -253,9 +264,19 @@ public static void SetVisual(SplendidCommand mode = SplendidCommand.Default, int
break;
}

if (RunSplendid(mode, 0, balance)) return;

if (_init)
var result = RunSplendid(mode, 0, balance);
if (result == 0) return;
if (result == -1)
{
Logger.WriteLine("Visual mode setting refused, reverting.");
RunSplendid(SplendidCommand.Default, 0, DefaultColorTemp);
if (ProcessHelper.IsUserAdministrator() && _download)
{
_download = false;
ColorProfileHelper.InstallProfile();
}
}
if (result == 1 && _init)
{
_init = false;
RunSplendid(SplendidCommand.Init);
Expand Down Expand Up @@ -288,7 +309,7 @@ private static string GetSplendidPath()
return _splendidPath;
}

private static bool RunSplendid(SplendidCommand command, int? param1 = null, int? param2 = null)
private static int RunSplendid(SplendidCommand command, int? param1 = null, int? param2 = null)
{
var splendid = GetSplendidPath();
bool isVivo = AppConfig.IsVivoZenPro();
Expand All @@ -298,39 +319,58 @@ private static bool RunSplendid(SplendidCommand command, int? param1 = null, int
{
if (command == SplendidCommand.DimmingVisual && isVivo) command = SplendidCommand.DimmingVivo;
var result = ProcessHelper.RunCMD(splendid, (int)command + " " + param1 + " " + param2);
if (result.Contains("file not exist") || (result.Length == 0 && !isVivo)) return false;
if (result.Contains("file not exist") || (result.Length == 0 && !isVivo)) return 1;
if (result.Contains("return code: -1")) return -1;
}

return true;
return 0;
}

private static void BrightnessTimerTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
brightnessTimer.Stop();


if (RunSplendid(SplendidCommand.DimmingVisual, 0, (int)(40 + _brightness * 0.6))) return;
if (RunSplendid(SplendidCommand.DimmingVisual, 0, (int)(40 + _brightness * 0.6)) == 0) return;

if (_init)
{
_init = false;
RunSplendid(SplendidCommand.Init);
RunSplendid(SplendidCommand.Init, 4);
if (RunSplendid(SplendidCommand.DimmingVisual, 0, (int)(40 + _brightness * 0.6))) return;
if (RunSplendid(SplendidCommand.DimmingVisual, 0, (int)(40 + _brightness * 0.6)) == 0) return;
}

// GammaRamp Fallback
SetGamma(_brightness);
}

public static void InitBrightness()
{
if (!AppConfig.IsOLED()) return;
if (!AppConfig.SaveDimming()) return;

int brightness = GetBrightness();
if (brightness >= 0) SetBrightness(brightness);
}

private static bool IsOnBattery()
{
return AppConfig.SaveDimming() && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;
}

public static int GetBrightness()
{
return AppConfig.Get(IsOnBattery() ? "brightness_battery" : "brightness", 100);
}

public static int SetBrightness(int brightness = -1, int delta = 0)
{
if (!AppConfig.IsOLED()) return -1;

if (brightness < 0) brightness = AppConfig.Get("brightness", 100);
if (brightness < 0) GetBrightness();

_brightness = Math.Max(0, Math.Min(100, brightness + delta));
AppConfig.Set("brightness", _brightness);
AppConfig.Set(IsOnBattery() ? "brightness_battery" : "brightness", _brightness);

brightnessTimer.Start();

Expand Down
3 changes: 2 additions & 1 deletion app/Extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
customActions.Remove("fnlock");
break;
case "fnv":
customActions[""] = EMPTY;
customActions[""] = Properties.Strings.VisualMode;
customActions.Remove("visual");
break;
case "fne":
customActions[""] = "Calculator";
Expand Down
2 changes: 1 addition & 1 deletion app/GHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.187</AssemblyVersion>
<AssemblyVersion>0.191</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
12 changes: 12 additions & 0 deletions app/Gpu/AMD/AmdGpuControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ public AmdGpuControl()

}

public int? GetiGpuUse()
{
if (_adlContextHandle == nint.Zero || _iGPU == null) return null;
if (ADL2_New_QueryPMLogData_Get(_adlContextHandle, ((ADLAdapterInfo)_iGPU).AdapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput) != Adl2.ADL_SUCCESS) return null;

ADLSingleSensorData gpuUsage = adlpmLogDataOutput.Sensors[(int)ADLSensorType.PMLOG_INFO_ACTIVITY_GFX];
if (gpuUsage.Supported == 0) return null;

return gpuUsage.Value;

}

public int? GetGpuPower()
{
if (_adlContextHandle == nint.Zero || _iGPU == null) return null;
Expand Down
2 changes: 1 addition & 1 deletion app/Gpu/NVidia/NvidiaSmi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static int GetDefaultMaxGPUPower()
public static int GetMaxGPUPower()
{
string output = RunNvidiaSmiCommand("--query-gpu=power.max_limit --format csv,noheader,nounits");
output = output.Trim().Trim('\n', '\r');
output = output.Trim().Trim('\n', '\r').Replace(".00","").Replace(",00", "");

if (float.TryParse(output, out float floatValue))
{
Expand Down
Loading

0 comments on commit fe377e5

Please sign in to comment.