generated from SteamDeckHomebrew/decky-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
398e05d
commit 4886699
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import glob | ||
import decky_plugin | ||
import subprocess | ||
from enum import Enum | ||
|
||
# ENERGY_PERFORMANCE_PREFERENCE_PATH | ||
EPP_DEVICES = glob.glob('/sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference') | ||
EPP_OPTION_PATHS = glob.glob('/sys/devices/system/cpu/cpu*/cpufreq/energy_performance_available_preferences') | ||
EPP_PATH ='/sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference' | ||
|
||
POWER_GOVERNOR_PATH = '/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor' | ||
POWER_GOVERNOR_DEVICES = glob.glob(POWER_GOVERNOR_PATH) | ||
|
||
class PowerGovernorOptions(Enum): | ||
PERFORMANCE = 'performance' | ||
POWER_SAVE = 'powersave' | ||
BALANCED = 'schedutil' | ||
|
||
def set_power_governor(governor_option): | ||
try: | ||
option = PowerGovernorOptions(governor_option).value | ||
|
||
if len(POWER_GOVERNOR_DEVICES) > 0: | ||
return execute_bash_command(option, POWER_GOVERNOR_PATH) | ||
except Exception as e: | ||
decky_plugin.logger.error(f'{__name__} error setting power governor {e}') | ||
|
||
def get_available_epp_options(): | ||
try: | ||
if len(EPP_OPTION_PATHS) > 0: | ||
path = EPP_OPTION_PATHS[0] | ||
with open(path, 'r') as file: | ||
available_options = file.read().strip().split(' ') | ||
file.close() | ||
return available_options | ||
except Exception as e: | ||
decky_plugin.logger.error(f'{__name__} error getting epp options {e}') | ||
|
||
return [] | ||
|
||
def set_epp(epp_option): | ||
try: | ||
if epp_option not in get_available_epp_options(): | ||
return | ||
if len(EPP_DEVICES) > 0: | ||
return execute_bash_command(epp_option, EPP_PATH) | ||
|
||
except Exception as e: | ||
decky_plugin.logger.error(f'{__name__} error setting epp {e}') | ||
|
||
def execute_bash_command(command, path): | ||
cmd = f"echo '{command}' | tee {path}" | ||
result = subprocess.run(cmd, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
return result |