-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
113 lines (103 loc) · 3.35 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using Microsoft.Extensions.Logging;
using NDesk.Options;
using NvAPIWrapper.GPU;
using System;
namespace nvidia_settings_cli
{
class Program
{
static void REPL()
{
while (true)
{
Console.WriteLine("What speed do you want your fan to go between 0 and 100 ? ");
var input = Console.ReadLine();
Console.WriteLine(""); // We want a blank line for future prints
var parsed = int.TryParse(input, out int speed);
if (!parsed)
{
Console.WriteLine("Please enter a proper number.");
continue;
}
GpuFunctions.SetFanSpeed(speed);
var gpus = PhysicalGPU.GetPhysicalGPUs();
System.Threading.Thread.Sleep(1000);
foreach (var gpu in gpus)
{
GpuFunctions.ReportSpeeds(gpu);
}
}
}
static void ShowHelp(OptionSet optionSet)
{
Console.WriteLine("Usage: nv-settings-cli [OPTIONS]");
Console.WriteLine("Interact with Nvidia GPUs via the windows command line.");
Console.WriteLine("If there are no options the GPU fan speed will be set to 50%");
Console.WriteLine();
Console.WriteLine("Options:");
optionSet.WriteOptionDescriptions(Console.Out);
}
static void Main(string[] args)
{
bool repl = false;
bool show_help = false;
bool show_temp = false;
bool debug = false;
int speed = 50;
var optionSet = new OptionSet() {
{
"r|repl",
"enter a read-evaluate-print-loop which will keep prompting\n" +
"for new speeds.",
v => repl = v != null
},
{
"d|debug",
"show debug logging",
v => debug = v != null
},
{
"s|speed=",
"set the fan to this speed.\n" +
"this must be an integer between 1 and 100.",
(int v) => speed = v
},
{
"t|temp",
"get the current GPU temperature.",
v => show_temp = v != null
},
{
"h|help",
"show this message and exit.",
v => show_help = v != null
},
};
var e = optionSet.Parse(args);
if (debug)
{
Logger.DEBUG = true;
}
if (show_help)
{
ShowHelp(optionSet);
return;
}
if (repl)
{
REPL();
return;
}
if (show_temp)
{
var gpus = PhysicalGPU.GetPhysicalGPUs();
foreach (var gpu in gpus) {
var temp = GpuFunctions.GetTemperature(gpu);
Console.WriteLine(temp);
}
return;
}
GpuFunctions.SetFanSpeed(speed);
}
}
}