mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Compare commits
14 Commits
FixedCurve
...
AllyTDP
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d10702d2a2 | ||
|
|
cb165093ac | ||
|
|
fa125e3346 | ||
|
|
32c007ada7 | ||
|
|
b83fa41772 | ||
|
|
966dd01f1d | ||
|
|
4f571e276c | ||
|
|
54ece1f621 | ||
|
|
a3474d38a5 | ||
|
|
d952d8859c | ||
|
|
c43bab3a33 | ||
|
|
fa8bce17c6 | ||
|
|
6978689f3d | ||
|
|
ad8858b836 |
@@ -1,10 +1,13 @@
|
||||
using GHelper.Gpu.AMD;
|
||||
using GHelper.Helpers;
|
||||
using GHelper.Input;
|
||||
using GHelper.Mode;
|
||||
using GHelper.USB;
|
||||
using HidSharp;
|
||||
using System.Text;
|
||||
|
||||
|
||||
|
||||
namespace GHelper.Ally
|
||||
{
|
||||
|
||||
@@ -32,17 +35,28 @@ namespace GHelper.Ally
|
||||
|
||||
public class AllyControl
|
||||
{
|
||||
System.Timers.Timer timer = default!;
|
||||
static System.Timers.Timer timer = default!;
|
||||
static AmdGpuControl amdControl = new AmdGpuControl();
|
||||
|
||||
SettingsForm settings;
|
||||
|
||||
static ControllerMode _mode = ControllerMode.Auto;
|
||||
static ControllerMode _applyMode = ControllerMode.Mouse;
|
||||
|
||||
static int _autoCount = 0;
|
||||
|
||||
static int _upCount = 0;
|
||||
static int _downCount = 0;
|
||||
|
||||
static int tdpMin = 6;
|
||||
static int tdpStable = tdpMin;
|
||||
static int tdpCurrent = -1;
|
||||
|
||||
static bool autoTDP = false;
|
||||
|
||||
static int fpsLimit = -1;
|
||||
|
||||
|
||||
public const string BindA = "01-01";
|
||||
public const string BindB = "01-02";
|
||||
public const string BindX = "01-03";
|
||||
@@ -280,32 +294,116 @@ namespace GHelper.Ally
|
||||
public AllyControl(SettingsForm settingsForm)
|
||||
{
|
||||
if (!AppConfig.IsAlly()) return;
|
||||
|
||||
settings = settingsForm;
|
||||
|
||||
timer = new System.Timers.Timer(300);
|
||||
timer.Elapsed += Timer_Elapsed;
|
||||
if (timer is null)
|
||||
{
|
||||
timer = new System.Timers.Timer(300);
|
||||
timer.Elapsed += Timer_Elapsed;
|
||||
Logger.WriteLine("Ally timer");
|
||||
}
|
||||
}
|
||||
|
||||
private int GetMaxTDP()
|
||||
{
|
||||
int tdp = AppConfig.GetMode("limit_total");
|
||||
if (tdp > 0) return tdp;
|
||||
switch (Modes.GetCurrentBase())
|
||||
{
|
||||
case 1:
|
||||
return 25;
|
||||
case 2:
|
||||
return 10;
|
||||
default:
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetTDP()
|
||||
{
|
||||
if (tdpCurrent < 0) tdpCurrent = GetMaxTDP();
|
||||
return tdpCurrent;
|
||||
}
|
||||
|
||||
private void SetTDP(int tdp, string log)
|
||||
{
|
||||
if (tdp < tdpStable) tdp = tdpStable;
|
||||
|
||||
int max = GetMaxTDP();
|
||||
if (tdp > max) tdp = max;
|
||||
|
||||
if (tdp == tdpCurrent) return;
|
||||
if (!autoTDP) return;
|
||||
|
||||
Program.acpi.DeviceSet(AsusACPI.PPT_APUA0, tdp, log);
|
||||
Program.acpi.DeviceSet(AsusACPI.PPT_APUA3, tdp, null);
|
||||
Program.acpi.DeviceSet(AsusACPI.PPT_APUC1, tdp, null);
|
||||
|
||||
tdpCurrent = tdp;
|
||||
}
|
||||
|
||||
private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
if (!autoTDP && _mode != ControllerMode.Auto) return;
|
||||
|
||||
float fps = amdControl.GetFPS();
|
||||
|
||||
ControllerMode newMode = (fps > 0) ? ControllerMode.Gamepad : ControllerMode.Mouse;
|
||||
|
||||
if (_applyMode != newMode) _autoCount++;
|
||||
else _autoCount = 0;
|
||||
|
||||
if (_mode != ControllerMode.Auto) return;
|
||||
|
||||
if (_autoCount > 2)
|
||||
if (autoTDP && fpsLimit > 0 && fpsLimit <= 120)
|
||||
{
|
||||
_autoCount = 0;
|
||||
ApplyMode(newMode);
|
||||
Logger.WriteLine(fps.ToString());
|
||||
int power = (int)amdControl.GetGpuPower();
|
||||
//Debug.WriteLine($"{power}: {fps}");
|
||||
|
||||
if (fps <= fpsLimit * 0.8) _upCount++;
|
||||
else _upCount = 0;
|
||||
|
||||
if (fps >= fpsLimit * 0.90) _downCount++;
|
||||
else _downCount = 0;
|
||||
|
||||
var tdp = GetTDP();
|
||||
if (_upCount >= 1)
|
||||
{
|
||||
_downCount = 0;
|
||||
_upCount = 0;
|
||||
SetTDP(tdp + 1, $"AutoTDP+ [{power}]{fps}");
|
||||
}
|
||||
|
||||
if (_downCount >= 8 && power < tdp)
|
||||
{
|
||||
_upCount = 0;
|
||||
_downCount--;
|
||||
SetTDP(tdp - 1, $"AutoTDP- [{power}]{fps}");
|
||||
}
|
||||
}
|
||||
|
||||
if (_mode == ControllerMode.Auto)
|
||||
{
|
||||
ControllerMode newMode = (fps > 0) ? ControllerMode.Gamepad : ControllerMode.Mouse;
|
||||
|
||||
if (_applyMode != newMode) _autoCount++;
|
||||
else _autoCount = 0;
|
||||
|
||||
if (_autoCount == 3)
|
||||
{
|
||||
_autoCount = 0;
|
||||
ApplyMode(newMode);
|
||||
Logger.WriteLine($"Controller Mode {fps}: {newMode}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ToggleAutoTDP()
|
||||
{
|
||||
autoTDP = !autoTDP;
|
||||
tdpCurrent = -1;
|
||||
|
||||
if (!autoTDP)
|
||||
{
|
||||
Program.modeControl.SetPerformanceMode();
|
||||
}
|
||||
|
||||
settings.VisualiseAutoTDP(autoTDP);
|
||||
|
||||
}
|
||||
|
||||
public void Init()
|
||||
@@ -319,7 +417,6 @@ namespace GHelper.Ally
|
||||
|
||||
fpsLimit = amdControl.GetFPSLimit();
|
||||
settings.VisualiseFPSLimit(fpsLimit);
|
||||
|
||||
}
|
||||
|
||||
public void ToggleFPSLimit()
|
||||
@@ -479,7 +576,7 @@ namespace GHelper.Ally
|
||||
DecodeBinding(KeyR2).CopyTo(bindings, 38);
|
||||
|
||||
//AsusHid.WriteInput(CommandReady, null);
|
||||
AsusHid.WriteInput(bindings, $"B{zone}");
|
||||
AsusHid.WriteInput(bindings, null);
|
||||
|
||||
}
|
||||
|
||||
@@ -495,19 +592,19 @@ namespace GHelper.Ally
|
||||
(byte)AppConfig.Get("ls_max", 100),
|
||||
(byte)AppConfig.Get("rs_min", 0),
|
||||
(byte)AppConfig.Get("rs_max", 100)
|
||||
}, "StickDeadzone");
|
||||
}, null);
|
||||
|
||||
AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xd1, 5, 4,
|
||||
(byte)AppConfig.Get("lt_min", 0),
|
||||
(byte)AppConfig.Get("lt_max", 100),
|
||||
(byte)AppConfig.Get("rt_min", 0),
|
||||
(byte)AppConfig.Get("rt_max", 100)
|
||||
}, "TriggerDeadzone");
|
||||
}, null);
|
||||
|
||||
AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xd1, 6, 2,
|
||||
(byte)AppConfig.Get("vibra", 100),
|
||||
(byte)AppConfig.Get("vibra", 100)
|
||||
}, "Vibration");
|
||||
}, null);
|
||||
|
||||
}
|
||||
|
||||
@@ -572,18 +669,11 @@ namespace GHelper.Ally
|
||||
_mode = mode;
|
||||
AppConfig.Set("controller_mode", (int)mode);
|
||||
|
||||
amdControl.StopFPS();
|
||||
ApplyMode(mode, init);
|
||||
|
||||
if (mode == ControllerMode.Auto)
|
||||
{
|
||||
amdControl.StartFPS();
|
||||
timer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.Stop();
|
||||
amdControl.StopFPS();
|
||||
}
|
||||
amdControl.StartFPS();
|
||||
timer.Start();
|
||||
|
||||
settings.VisualiseController(mode);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,18 @@ public class AmdGpuControl : IGpuControl
|
||||
|
||||
}
|
||||
|
||||
public int? GetGpuPower()
|
||||
{
|
||||
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_ASIC_POWER];
|
||||
if (gpuUsage.Supported == 0) return null;
|
||||
|
||||
return gpuUsage.Value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool SetVariBright(int enabled)
|
||||
{
|
||||
|
||||
25
app/Settings.Designer.cs
generated
25
app/Settings.Designer.cs
generated
@@ -135,6 +135,7 @@ namespace GHelper
|
||||
labelGamma = new Label();
|
||||
pictureGamma = new PictureBox();
|
||||
labelGammaTitle = new Label();
|
||||
buttonAutoTDP = new RButton();
|
||||
panelMatrix.SuspendLayout();
|
||||
panelMatrixAuto.SuspendLayout();
|
||||
tableLayoutMatrix.SuspendLayout();
|
||||
@@ -766,6 +767,7 @@ namespace GHelper
|
||||
tableAMD.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
|
||||
tableAMD.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
|
||||
tableAMD.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
|
||||
tableAMD.Controls.Add(buttonAutoTDP, 0, 0);
|
||||
tableAMD.Controls.Add(buttonOverlay, 0, 0);
|
||||
tableAMD.Controls.Add(buttonFPS, 0, 0);
|
||||
tableAMD.Dock = DockStyle.Top;
|
||||
@@ -1893,6 +1895,28 @@ namespace GHelper
|
||||
labelGammaTitle.TabIndex = 37;
|
||||
labelGammaTitle.Text = "Flicker-free Dimming";
|
||||
//
|
||||
// buttonAutoTDP
|
||||
//
|
||||
buttonAutoTDP.Activated = false;
|
||||
buttonAutoTDP.BackColor = SystemColors.ControlLightLight;
|
||||
buttonAutoTDP.BorderColor = Color.Transparent;
|
||||
buttonAutoTDP.BorderRadius = 5;
|
||||
buttonAutoTDP.Dock = DockStyle.Fill;
|
||||
buttonAutoTDP.FlatAppearance.BorderSize = 0;
|
||||
buttonAutoTDP.FlatStyle = FlatStyle.Flat;
|
||||
buttonAutoTDP.ForeColor = SystemColors.ControlText;
|
||||
buttonAutoTDP.Image = Properties.Resources.icons8_gauge_32;
|
||||
buttonAutoTDP.ImageAlign = ContentAlignment.MiddleRight;
|
||||
buttonAutoTDP.Location = new Point(528, 4);
|
||||
buttonAutoTDP.Margin = new Padding(4);
|
||||
buttonAutoTDP.Name = "buttonAutoTDP";
|
||||
buttonAutoTDP.Secondary = false;
|
||||
buttonAutoTDP.Size = new Size(255, 72);
|
||||
buttonAutoTDP.TabIndex = 13;
|
||||
buttonAutoTDP.Text = "AutoTDP";
|
||||
buttonAutoTDP.TextImageRelation = TextImageRelation.ImageBeforeText;
|
||||
buttonAutoTDP.UseVisualStyleBackColor = false;
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(192F, 192F);
|
||||
@@ -2095,5 +2119,6 @@ namespace GHelper
|
||||
private RButton buttonInstallColor;
|
||||
private Label labelVisual;
|
||||
private RButton buttonFHD;
|
||||
private RButton buttonAutoTDP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,9 @@ namespace GHelper
|
||||
|
||||
buttonUpdates.Click += ButtonUpdates_Click;
|
||||
|
||||
sliderBattery.ValueChanged += SliderBattery_ValueChanged;
|
||||
sliderBattery.MouseUp += SliderBattery_MouseUp;
|
||||
sliderBattery.KeyUp += SliderBattery_KeyUp;
|
||||
|
||||
Program.trayIcon.MouseMove += TrayIcon_MouseMove;
|
||||
|
||||
sensorTimer = new System.Timers.Timer(AppConfig.Get("sensor_timer", 1000));
|
||||
@@ -249,6 +251,9 @@ namespace GHelper
|
||||
|
||||
buttonFPS.Click += ButtonFPS_Click;
|
||||
buttonOverlay.Click += ButtonOverlay_Click;
|
||||
|
||||
buttonAutoTDP.Click += ButtonAutoTDP_Click;
|
||||
buttonAutoTDP.BorderColor = colorTurbo;
|
||||
|
||||
Text = "G-Helper " + (ProcessHelper.IsUserAdministrator() ? "—" : "-") + " " + AppConfig.GetModelShort();
|
||||
TopMost = AppConfig.Is("topmost");
|
||||
@@ -272,6 +277,21 @@ namespace GHelper
|
||||
screenControl.ToogleFHD();
|
||||
}
|
||||
|
||||
private void SliderBattery_KeyUp(object? sender, KeyEventArgs e)
|
||||
{
|
||||
BatteryControl.SetBatteryChargeLimit(sliderBattery.Value);
|
||||
}
|
||||
|
||||
private void SliderBattery_MouseUp(object? sender, MouseEventArgs e)
|
||||
{
|
||||
BatteryControl.SetBatteryChargeLimit(sliderBattery.Value);
|
||||
}
|
||||
|
||||
private void ButtonAutoTDP_Click(object? sender, EventArgs e)
|
||||
{
|
||||
allyControl.ToggleAutoTDP();
|
||||
}
|
||||
|
||||
private void LabelCharge_Click(object? sender, EventArgs e)
|
||||
{
|
||||
BatteryControl.BatteryReport();
|
||||
@@ -496,6 +516,12 @@ namespace GHelper
|
||||
buttonFPS.Text = "FPS Limit " + ((limit > 0 && limit <= 120) ? limit : "OFF");
|
||||
}
|
||||
|
||||
public void VisualiseAutoTDP(bool status)
|
||||
{
|
||||
Logger.WriteLine($"Auto TDP: {status}");
|
||||
buttonAutoTDP.Activated = status;
|
||||
}
|
||||
|
||||
private void SettingsForm_LostFocus(object? sender, EventArgs e)
|
||||
{
|
||||
lastLostFocus = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
@@ -736,11 +762,6 @@ namespace GHelper
|
||||
gpuControl.ToggleXGM();
|
||||
}
|
||||
|
||||
private void SliderBattery_ValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
BatteryControl.SetBatteryChargeLimit(sliderBattery.Value);
|
||||
}
|
||||
|
||||
|
||||
public void SetVersionLabel(string label, bool update = false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user