diff --git a/main.py b/main.py index 0192ed2..c005088 100644 --- a/main.py +++ b/main.py @@ -77,6 +77,15 @@ class Plugin: freq = int(freq_maybe) return self.SCALING_FREQUENCIES.index(freq) + # GPU stuff + + async def set_gpu_power(self, value: int, power_number: int) -> bool: + write_to_sys(gpu_power_path(power_number), value) + return True + + async def get_gpu_power(self, power_number: int) -> int: + return int(read_from_sys(gpu_power_path(power_number), amount=-1).strip()) + # Fan stuff async def set_fan_tick(self, tick: int): @@ -138,6 +147,9 @@ def cpu_freq_scaling_path(cpu_number: int) -> str: def cpu_governor_scaling_path(cpu_number: int) -> str: return f"/sys/devices/system/cpu/cpu{cpu_number}/cpufreq/scaling_governor" + +def gpu_power_path(power_number: int) -> str: + return f"/sys/class/hwmon/hwmon4/power{power_number}_cap" def write_to_sys(path, value: int): with open(path, mode="w") as f: diff --git a/main_view.html b/main_view.html index 93f0f58..da2bbd6 100644 --- a/main_view.html +++ b/main_view.html @@ -38,6 +38,14 @@ return call_plugin_method("get_max_boost", {}); } + function setGPUPower(value, index) { + return call_plugin_method("set_gpu_power", {"value": value, "power_number": index}); + } + + function getGPUPower(index) { + return call_plugin_method("get_gpu_power", {"power_number": index}); + } + function setFanTick(tick) { return call_plugin_method("set_fan_tick", {"tick": tick}); } @@ -66,6 +74,7 @@ setToggleState(document.getElementById("smtToggle"), await getSMT()); selectNotch("cpuThreadsNotch", await getCPUs() - 1, 8); selectNotch("frequencyNotch", await getMaxBoost(), 3); + await onReadyGPU(); selectNotch("fanNotch", await getFanTick(), 8); await updateBatteryStats(); // this is unimportant; always do it last @@ -128,6 +137,56 @@ selectNotch(ROOT_ID, index, 8); } + async function onReadyGPU() { + let power1_cap = await getGPUPower(1); + let power2_cap = await getGPUPower(2); + if (power1_cap <= 0) { + selectNotch("slowPPTNotch", 0, 3); + document.getElementById("slowPPTAutoDefault").innerText = "Default"; + } else if (power1_cap > 15000000) { + selectNotch("slowPPTNotch", 2, 3); + document.getElementById("slowPPTAutoDefault").innerText = "Default"; + } else { + selectNotch("slowPPTNotch", 1, 3); + } + + if (power2_cap <= 0) { + selectNotch("fastPPTNotch", 0, 3); + document.getElementById("fastPPTAutoDefault").innerText = "Default"; + } else if (power2_cap > 15000000) { + selectNotch("fastPPTNotch", 2, 3); + document.getElementById("fastPPTAutoDefault").innerText = "Default"; + } else { + selectNotch("fastPPTNotch", 1, 3); + } + } + + async function onSetSlowPPTNotch(index) { + const ROOT_ID = "slowPPTNotch"; + document.getElementById("slowPPTAutoDefault").innerText = "Default"; + if (index == 0) { + await setGPUPower(0, 1); + } else if (index == 1) { + await setGPUPower(15000000, 1); + } else { + await setGPUPower(29000000, 1); + } + selectNotch(ROOT_ID, index, 3); + } + + async function onSetFastPPTNotch(index) { + const ROOT_ID = "fastPPTNotch"; + document.getElementById("fastPPTAutoDefault").innerText = "Default"; + if (index == 0) { + await setGPUPower(0, 2); + } else if (index == 1) { + await setGPUPower(15000000, 2); + } else { + await setGPUPower(30000000, 2); + } + selectNotch(ROOT_ID, index, 3); + } + function selectNotch(rootId, index, elements) { // WARNING: this yeets any style in div of slider const ENABLED_CLASS = "gamepadslider_TickActive_j418S"; @@ -159,6 +218,8 @@
+ + + + + +