Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added help menu and additional commands #9

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions amdgpu_fan/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,63 @@ def main():

config = load_config(CONFIG_LOCATIONS[-1])

FanController(config).main()

CMD_HELP = """usage: amdgpu-fan [COMMAND] [ARGS] [CARD]

CARD should be what shows up in /sys/class/drm. If there's only one card (ex: card0), it will be automatically detected.

commands:
--start start fan control
--get get information about the card
--set-speed set gpu fan speed

args:
with --get:
fan_speed get the current speed of the fan
gpu_temp get the current temp of the gpu

with --set-speed:
input the speed you'd like from 0-100 or auto
100 = max, 0 = off, 'auto' = system controlled
"""

args = sys.argv[1:]
if '--help' in args or '-h' in args or len(args) == 0\
or args[0] not in ('--start', '--get', '--set-speed')\
or (args[0] == '--get' and (args[1] not in ('fan_speed', 'gpu_temp'))):
print(CMD_HELP)
sys.exit(1)

scanner = Scanner()

command = args[0]
if len(args) > 1:
arg = args[1]
if len(args) < 3:
cards = Scanner(config.get('cards')).cards
if len(cards) > 1:
print("There are two or more cards. Please specify the card you wish to examine.")
print(list(card.keys()))
sys.exit(1)
else:
card = list(cards.keys())[0]
else:
card = args[2]

if command == '--get':
if arg == 'fan_speed':
print(f"{scanner.cards.get(card).fan_speed} rpm")
elif arg == 'gpu_temp':
print(f"{scanner.cards.get(card).gpu_temp} °C")

elif command == '--set-speed':
if arg == 'auto':
scanner.cards.get(card).set_system_controlled_fan(True)
else:
print(scanner.cards.get(card).set_fan_speed(arg))
elif command == '--start':
FanController(config).main()

sys.exit(1)

if __name__ == '__main__':
main()