-
Notifications
You must be signed in to change notification settings - Fork 16
/
LiquidctlCLIWrapper.cs
60 lines (51 loc) · 2.06 KB
/
LiquidctlCLIWrapper.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Newtonsoft.Json;
namespace FanControl.Liquidctl
{
internal static class LiquidctlCLIWrapper
{
public static string liquidctlexe = "Plugins\\liquidctl.exe"; //TODO extract path to executable to config
internal static void Initialize()
{
LiquidctlCall($"--json initialize all");
}
internal static List<LiquidctlStatusJSON> ReadStatus()
{
Process process = LiquidctlCall($"--json status");
return JsonConvert.DeserializeObject<List<LiquidctlStatusJSON>>(process.StandardOutput.ReadToEnd());
}
internal static List<LiquidctlStatusJSON> ReadStatus(string address)
{
Process process = LiquidctlCall($"--json --address {address} status");
return JsonConvert.DeserializeObject<List<LiquidctlStatusJSON>>(process.StandardOutput.ReadToEnd());
}
internal static void SetPump(string address, int value)
{
LiquidctlCall($"--address {address} set pump speed {(value)}");
}
internal static void SetFan(string address, int value)
{
LiquidctlCall($"--address {address} set fan speed {(value)}");
}
private static Process LiquidctlCall(string arguments)
{
Process process = new Process();
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = liquidctlexe;
process.StartInfo.Arguments = arguments;
process.Start();
process.WaitForExit();
if (process.ExitCode != 0)
{
throw new Exception($"liquidctl returned non-zero exit code {process.ExitCode}. Last stderr output:\n{process.StandardError.ReadToEnd()}");
}
return process;
}
}
}