Skip to content

Commit

Permalink
Add support for liquidctl plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
lich426 committed Oct 28, 2022
1 parent f56a9b6 commit 0448a63
Show file tree
Hide file tree
Showing 30 changed files with 17,443 additions and 59 deletions.
41 changes: 39 additions & 2 deletions FanCtrl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PublisherName>Lich</PublisherName>
<SuiteName>FanCtrl</SuiteName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.5.0.0</ApplicationVersion>
<ApplicationVersion>1.5.1.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down Expand Up @@ -210,12 +210,18 @@
<Compile Include="FanCtrl\Hardware\HWInfo\HWInfoManager.cs" />
<Compile Include="FanCtrl\Hardware\HWInfo\HWInfoCategory.cs" />
<Compile Include="FanCtrl\Hardware\HWInfo\HWInfoDevice.cs" />
<Compile Include="FanCtrl\Hardware\liquidctl\LiquidctlData.cs" />
<Compile Include="FanCtrl\Hardware\liquidctl\LiquidctlStatusData.cs" />
<Compile Include="FanCtrl\Hardware\liquidctl\LiquidctlManager.cs" />
<Compile Include="FanCtrl\Hardware\Kraken.cs" />
<Compile Include="FanCtrl\Hardware\LHM.cs" />
<Compile Include="FanCtrl\Hardware\OSD\HWInfoOSDSensor.cs" />
<Compile Include="FanCtrl\Hardware\OSD\OHMOSDSensor.cs" />
<Compile Include="FanCtrl\Hardware\OSD\LHMOSDSensor.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\HWInfoFanSpeed.cs" />
<Compile Include="FanCtrl\Hardware\Control\LiquidctlControl.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\LiquidctlSpeed.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\LiquidctlTemp.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\HWInfoTemp.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\OHMFanSpeed.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\LHMFanSpeed.cs" />
Expand Down Expand Up @@ -263,6 +269,24 @@
<Compile Include="LightingForm.Designer.cs">
<DependentUpon>LightingForm.cs</DependentUpon>
</Compile>
<Compile Include="LiquidctlCommandForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="LiquidctlCommandForm.Designer.cs">
<DependentUpon>LiquidctlCommandForm.cs</DependentUpon>
</Compile>
<Compile Include="LiquidctlFanControlForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="LiquidctlFanControlForm.Designer.cs">
<DependentUpon>LiquidctlFanControlForm.cs</DependentUpon>
</Compile>
<Compile Include="LiquidctlForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="LiquidctlForm.Designer.cs">
<DependentUpon>LiquidctlForm.cs</DependentUpon>
</Compile>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -305,6 +329,15 @@
<EmbeddedResource Include="LightingForm.resx">
<DependentUpon>LightingForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LiquidctlCommandForm.resx">
<DependentUpon>LiquidctlCommandForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LiquidctlFanControlForm.resx">
<DependentUpon>LiquidctlFanControlForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LiquidctlForm.resx">
<DependentUpon>LiquidctlForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -375,7 +408,11 @@
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(SolutionDir)dll\*.dll" "$(TargetDir)"</PostBuildEvent>
<PostBuildEvent>copy /Y "$(SolutionDir)dll\*.dll" "$(TargetDir)"
mkdir "$(TargetDir)\plugin"
copy /Y "$(SolutionDir)plugin\*.exe" "$(TargetDir)plugin"
mkdir "$(TargetDir)\preset"
copy /Y "$(SolutionDir)preset\*.preset" "$(TargetDir)preset"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>del "$(TargetDir)*.dll"</PreBuildEvent>
Expand Down
6 changes: 6 additions & 0 deletions FanCtrl/Data/Option/OptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private OptionManager()
// HWiNFO
public bool IsHWInfo { get; set; }

// liquidctl
public bool IsLiquidctl { get; set; }

// Other options
public bool IsAnimation { get; set; }

Expand Down Expand Up @@ -130,6 +133,7 @@ public void reset()
IsCLC = true;
IsRGBnFC = true;
IsHWInfo = false;
IsLiquidctl = false;

IsAnimation = true;
IsFahrenheit = false;
Expand Down Expand Up @@ -171,6 +175,7 @@ public bool read()
IsCLC = (rootObject.ContainsKey("IsCLC") == true) ? rootObject.Value<bool>("IsCLC") : true;
IsRGBnFC = (rootObject.ContainsKey("IsRGBnFC") == true) ? rootObject.Value<bool>("IsRGBnFC") : true;
IsHWInfo = (rootObject.ContainsKey("IsHWInfo") == true) ? rootObject.Value<bool>("IsHWInfo") : false;
IsLiquidctl = (rootObject.ContainsKey("IsLiquidctl") == true) ? rootObject.Value<bool>("IsLiquidctl") : false;

IsAnimation = (rootObject.ContainsKey("IsAnimation") == true) ? rootObject.Value<bool>("IsAnimation") : true;
IsFahrenheit = (rootObject.ContainsKey("IsFahrenheit") == true) ? rootObject.Value<bool>("IsFahrenheit") : false;
Expand Down Expand Up @@ -218,6 +223,7 @@ public void write()
rootObject["IsCLC"] = IsCLC;
rootObject["IsRGBnFC"] = IsRGBnFC;
rootObject["IsHWInfo"] = IsHWInfo;
rootObject["IsLiquidctl"] = IsLiquidctl;

rootObject["IsAnimation"] = IsAnimation;
rootObject["IsFahrenheit"] = IsFahrenheit;
Expand Down
49 changes: 49 additions & 0 deletions FanCtrl/Hardware/Control/LiquidctlControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FanCtrl
{
public class LiquidctlControl : BaseControl
{
public string DeviceName { get; set; }

public string Address { get; set; }

public string ChannelName { get; set; }

public LiquidctlControl(int index, string deviceName, string name, string address, string channelName) : base(LIBRARY_TYPE.Liquidctl)
{
ID = string.Format("liquidctl/{0}/{1}/Control/{2}", deviceName, address, index);
DeviceName = deviceName;
Name = name;
Address = address;
ChannelName = channelName;
Value = LastValue = NextValue = 50;
}

public override int setSpeed(int value)
{
if (Address.Length == 0 || ChannelName.Length == 0)
return Value;

Task.Run(() => {
var p = new Process();
p.StartInfo.FileName = LiquidctlManager.getInstance().LiquidctlPath;
p.StartInfo.Arguments = string.Format("--address \"{0}\" set {1} speed {2}", Address, ChannelName, NextValue);
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
if (p.Start() == true)
{
p.Close();
}
});

Value = LastValue = NextValue = value;
return value;
}
}
}
2 changes: 2 additions & 0 deletions FanCtrl/Hardware/Define.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum LIBRARY_TYPE
EVGA_CLC,
RGBnFC,
HWiNFO,
Liquidctl,
OSD,

MAX,
Expand All @@ -35,6 +36,7 @@ public class Define
"EVGA CLC",
"NZXT RGB&FanController",
"HWiNFO",
"liquidctl",
"On screen display",
};
}
Expand Down
22 changes: 22 additions & 0 deletions FanCtrl/Hardware/HardwareManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,27 @@ public void start()
catch { }
}

if (OptionManager.getInstance().IsLiquidctl == true)
{
LiquidctlManager.getInstance().start();

var tempList = TempList[(int)LIBRARY_TYPE.Liquidctl];
LiquidctlManager.getInstance().createTemp(ref tempList);

var fanList = FanList[(int)LIBRARY_TYPE.Liquidctl];
LiquidctlManager.getInstance().createFan(ref fanList);

var controlList = ControlList[(int)LIBRARY_TYPE.Liquidctl];
LiquidctlManager.getInstance().createControl(ref controlList);

int count = LiquidctlManager.getInstance().getLiquidctlControlCount();
for (int i = 0; i < count; i++)
{
var control = LiquidctlManager.getInstance().getLiquidctlControl(i);
this.addChangeValue(control.Value, control, false);
}
}

for (int i = 0; i < TempList.Count; i++)
{
var deviceList = TempList[i];
Expand Down Expand Up @@ -742,6 +763,7 @@ public void stop()
}

HWInfoManager.getInstance().stop();
LiquidctlManager.getInstance().stop();

mChangeControlList.Clear();
mChangeValueList.Clear();
Expand Down
34 changes: 34 additions & 0 deletions FanCtrl/Hardware/Sensor/LiquidctlSpeed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FanCtrl
{
public class LiquidctlSpeed : BaseSensor
{
private LiquidctlStatusData mLiquidctlStatusData;

public LiquidctlSpeed(LiquidctlStatusData statusData) : base(LIBRARY_TYPE.Liquidctl)
{
ID = string.Format("liquidctl/{0}/{1}/{2}/Fan", statusData.LiquidctlData.Description, statusData.LiquidctlData.Address, statusData.Key);
Name = statusData.Key;
mLiquidctlStatusData = statusData;
}

public override string getString()
{
return Value + " RPM";
}
public override void update()
{
try
{
double value = double.Parse(mLiquidctlStatusData.Value);
Value = (int)Math.Round(value);
}
catch { }
}
}
}
37 changes: 37 additions & 0 deletions FanCtrl/Hardware/Sensor/LiquidctlTemp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FanCtrl
{
public class LiquidctlTemp : BaseSensor
{
private LiquidctlStatusData mLiquidctlStatusData;

public LiquidctlTemp(LiquidctlStatusData statusData) : base(LIBRARY_TYPE.Liquidctl)
{
ID = string.Format("liquidctl/{0}/{1}/{2}/Temp", statusData.LiquidctlData.Description, statusData.LiquidctlData.Address, statusData.Key);
Name = statusData.Key;
mLiquidctlStatusData = statusData;
}

public override string getString()
{
if (OptionManager.getInstance().IsFahrenheit == true)
return Util.getFahrenheit(Value) + " °F";
else
return Value + " °C";
}
public override void update()
{
try
{
double value = double.Parse(mLiquidctlStatusData.Value);
Value = (int)Math.Round(value);
}
catch { }
}
}
}
49 changes: 49 additions & 0 deletions FanCtrl/Hardware/liquidctl/LiquidctlData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FanCtrl
{
public class LiquidctlData
{
public string Bus { get; set; }

public string Address { get; set; }

public string Description { get; set; }

private List<LiquidctlStatusData> mStatusDataList = new List<LiquidctlStatusData>();
private object mLock = new object();

public int getStatusCount()
{
Monitor.Enter(mLock);
int count = mStatusDataList.Count;
Monitor.Exit(mLock);
return count;
}

public LiquidctlStatusData getStatusData(int index)
{
Monitor.Enter(mLock);
if (index >= mStatusDataList.Count)
{
Monitor.Exit(mLock);
return null;
}
var data = mStatusDataList[index];
Monitor.Exit(mLock);
return data;
}

public void addStatusData(LiquidctlStatusData data)
{
Monitor.Enter(mLock);
mStatusDataList.Add(data);
Monitor.Exit(mLock);
}
}
}
Loading

0 comments on commit 0448a63

Please sign in to comment.