Skip to content

Commit

Permalink
v0.0.1 The first version that works as is
Browse files Browse the repository at this point in the history
  • Loading branch information
fu-raz committed Jul 18, 2022
1 parent f0f09f5 commit a1fdf0a
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vs/
FanControlThermaltake/bin/
FanControlThermaltake/obj/
ThermaltakeRiingPlusTest/bin/
ThermaltakeRiingPlusTest/obj/
*.user
Binary file added FanControl.Plugins.dll
Binary file not shown.
31 changes: 31 additions & 0 deletions FanControlThermaltake.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32407.343
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FanControl.ThermaltakeRiingPlus", "FanControlThermaltake\FanControl.ThermaltakeRiingPlus.csproj", "{EEDDA466-17A6-47EC-9D14-FA204D29D0D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThermaltakeRiingPlusTest", "ThermaltakeRiingPlusTest\ThermaltakeRiingPlusTest.csproj", "{94979930-644E-4FE6-B644-21AA5ECCE591}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EEDDA466-17A6-47EC-9D14-FA204D29D0D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEDDA466-17A6-47EC-9D14-FA204D29D0D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEDDA466-17A6-47EC-9D14-FA204D29D0D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEDDA466-17A6-47EC-9D14-FA204D29D0D3}.Release|Any CPU.Build.0 = Release|Any CPU
{94979930-644E-4FE6-B644-21AA5ECCE591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94979930-644E-4FE6-B644-21AA5ECCE591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94979930-644E-4FE6-B644-21AA5ECCE591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94979930-644E-4FE6-B644-21AA5ECCE591}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F572AD1-0AB5-44F9-9E54-BD0422D1E334}
EndGlobalSection
EndGlobal
38 changes: 38 additions & 0 deletions FanControlThermaltake/ControlSensor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using FanControl.Plugins;

namespace FanControl.ThermaltakeRiingPlus
{
public class ControlSensor : IPluginControlSensor
{
public string Id { get; }
public string Name { get; }
public float? Value { get; set; }

protected int portNumber;
protected TTFanController ttFanController;

public ControlSensor(string id, string name, int portNumber, TTFanController ttFanController)
{
this.Id = id;
this.Name = name;
this.portNumber = portNumber;
this.ttFanController = ttFanController;
this.Update();
}

public void Reset()
{
this.ttFanController.SetFanPower(this.portNumber, 50);
}

public void Set(float val)
{
this.ttFanController.SetFanPower(this.portNumber, val);
}

public void Update()
{
this.Value = this.ttFanController.GetFanPower(this.portNumber);
}
}
}
61 changes: 61 additions & 0 deletions FanControlThermaltake/DevicesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;

namespace FanControl.ThermaltakeRiingPlus
{
public class DevicesController
{
protected int VendorId = 0x264a;
protected int ProductId = 0x2260;
protected int MaxConnectedDevices = 5;
protected bool isConnected = false;
protected List<TTFanController> Devices = new List<TTFanController>();
public void Connect()
{
if (!this.isConnected)
{
// Get devices from HID
IEnumerable<HidSharp.HidDevice> deviceList = HidSharp.DeviceList.Local.GetHidDevices();
//HidDeviceList = HidDevices.Enumerate(this.VendorId);
foreach (HidSharp.HidDevice hidDevice in deviceList)
{
if (hidDevice.VendorID == this.VendorId)
{
Log.WriteToLog($"Found Thermaltake device with Vendor ID {hidDevice.VendorID} and Product ID {hidDevice.ProductID}");

if (hidDevice.ProductID >= this.ProductId &&
hidDevice.ProductID <= this.ProductId + this.MaxConnectedDevices)
{
Log.WriteToLog("We found a TT device");

if (hidDevice.TryOpen(out HidSharp.HidStream hidStream))
{
Log.WriteToLog("We opened the HID Device");
int controllerIndex = this.Devices.Count;
TTFanController ttFanController = new TTFanController(hidStream, controllerIndex);

Log.WriteToLog("Adding HID Device to Devices");
this.Devices.Add(ttFanController);
Log.WriteToLog($"We have {this.Devices.Count} devices");
}

}
}

}
}

}

public void Disconnect()
{
// I dunno what to do
}

public List<TTFanController> GetFanControllers()
{
return this.Devices;
}

}
}
18 changes: 18 additions & 0 deletions FanControlThermaltake/FanControl.ThermaltakeRiingPlus.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>

</PropertyGroup>

<ItemGroup>
<PackageReference Include="HidSharp" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="FanControl.Plugins">
<HintPath>..\FanControl.Plugins.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions FanControlThermaltake/FanSensor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FanControl.Plugins;

namespace FanControl.ThermaltakeRiingPlus
{
public class FanSensor : IPluginSensor
{
public string Id { get; }
public string Name { get; }
public float? Value { get; set; }

protected int portNumber;
protected TTFanController ttFanController;

public FanSensor(string id, string name, int portNumber, TTFanController ttFanController)
{
this.Id = id;
this.Name = name;
this.portNumber = portNumber;
this.ttFanController = ttFanController;
this.Update();
}

public void Update()
{
this.Value = this.ttFanController.GetFanRPM(this.portNumber);
}
}
}
49 changes: 49 additions & 0 deletions FanControlThermaltake/Log.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.Tasks;

namespace FanControl.ThermaltakeRiingPlus
{
public class Log
{
// Yea I know this is lame
protected static bool Debug = false;
public static void WriteToLog(String data)
{
if (Log.Debug)
{
string fileName = "Thermaltake.log";

if (!String.IsNullOrWhiteSpace(fileName) && !String.IsNullOrWhiteSpace(data))
{
try
{
System.IO.File.AppendAllText(fileName, $"{DateTime.UtcNow:R} {data}{Environment.NewLine}");
}
catch (System.Security.SecurityException)
{

}
catch (System.IO.IOException)
{

}
catch (NotSupportedException)
{

}
catch (UnauthorizedAccessException)
{

}
catch (ArgumentException)
{

}
}
}
}
}
}
59 changes: 59 additions & 0 deletions FanControlThermaltake/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using FanControl.Plugins;
using System.Collections.Generic;

namespace FanControl.ThermaltakeRiingPlus
{
public class Plugin : IPlugin2
{
private DevicesController DevicesController = new DevicesController();
public string Name => "Thermaltake Riing Plus";

public void Close()
{
this.DevicesController.Disconnect();
}

public void Initialize()
{
Log.WriteToLog("Initializing Plugin");
this.DevicesController.Connect();
}

public void Load(IPluginSensorsContainer container)
{
Log.WriteToLog("Loading Sensors");

List<ControlSensor> controlSensors = new List<ControlSensor>();
List<FanSensor> fanSensors = new List<FanSensor>();

List<TTFanController> fanControllers = this.DevicesController.GetFanControllers();

foreach (TTFanController fanController in fanControllers)
{
List<ControlSensor> cs = fanController.GetControlSensors();
foreach (ControlSensor sensor in cs)
{
Log.WriteToLog($"We found {sensor.Name} at {sensor.Value}% power");
controlSensors.Add(sensor);
}

List<FanSensor> fs = fanController.GetFanSensors();
foreach (FanSensor sensor in fs)
{
Log.WriteToLog($"We found {sensor.Name} at {sensor.Value} RPM");
fanSensors.Add(sensor);
}
}

Log.WriteToLog($"We found {controlSensors.Count} Control sensors and {fanSensors.Count} Fan sensors");

if (controlSensors.Count > 0) container.ControlSensors.AddRange(controlSensors);
if (fanSensors.Count > 0) container.FanSensors.AddRange(fanSensors);
}

public void Update()
{

}
}
}
Loading

0 comments on commit a1fdf0a

Please sign in to comment.