diff --git a/FanControl.AquacomputerDevices/AquacomputerPlugin.cs b/FanControl.AquacomputerDevices/AquacomputerPlugin.cs index 0892506..cdbd369 100644 --- a/FanControl.AquacomputerDevices/AquacomputerPlugin.cs +++ b/FanControl.AquacomputerDevices/AquacomputerPlugin.cs @@ -2,7 +2,9 @@ using FanControl.Plugins; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -11,8 +13,9 @@ namespace FanControl.AquacomputerDevices public class AquacomputerPlugin : IPlugin2 { public string Name => "Aquacomputer Devices"; - List devices; - + //List devices; + Dictionary devices; + private readonly IPluginLogger _logger; public AquacomputerPlugin(IPluginLogger logger) @@ -23,7 +26,7 @@ public AquacomputerPlugin(IPluginLogger logger) public void Close() { _logger.Log("AquacomputerPlugin: Closing."); - devices.ForEach(x => x.Unload()); + devices.Keys.ToList().ForEach(x => x.Unload()); devices.Clear(); } @@ -31,21 +34,28 @@ public void Initialize() { _logger.Log("AquacomputerPlugin: Initializing."); devices = HidLibrary.HidDevices.Enumerate(0x0C70, AllDevices.GetSupportedProductIds().ToArray()) - .Select(x => AllDevices.GetDevice(x, _logger)).ToList(); + .Select(x => AllDevices.GetDevice(x, _logger)) + .GroupBy(x => x.GetType()) + .SelectMany(x => x + .OrderBy(t => t.GetDevicePath().ToLowerInvariant()) + .Select((y, i) => new { Key = y, Index = i }) + ) + .ToDictionary(k => k.Key, e => e.Index); } public void Load(IPluginSensorsContainer _container) { _logger.Log("AquacomputerPlugin: Loading"); - devices.ForEach(x => { - _logger.Log("AquacomputerPlugin: Loading device "+x.ToString()); - x.Load(_container); - }); + foreach (var item in devices) + { + _logger.Log("AquacomputerPlugin: Loading device " + item.Key.ToString() + " with index: " + item.Value); + item.Key.Load(_container, item.Value); + } } public void Update() { - devices.ForEach(x => x.Update()); + devices.Keys.ToList().ForEach(x => x.Update()); } } } diff --git a/FanControl.AquacomputerDevices/Devices/HighFlowNextDevice.cs b/FanControl.AquacomputerDevices/Devices/HighFlowNextDevice.cs index 693a4a0..b77b2da 100644 --- a/FanControl.AquacomputerDevices/Devices/HighFlowNextDevice.cs +++ b/FanControl.AquacomputerDevices/Devices/HighFlowNextDevice.cs @@ -13,6 +13,8 @@ internal class HighFlowNextDevice : IAquacomputerDevice public int GetProductId() => 0xF012; + public string GetDevicePath() => hidDevice?.DevicePath; + public IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger) { _logger = logger; @@ -24,17 +26,17 @@ public IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger) return this; } - public void Load(IPluginSensorsContainer _container) + public void Load(IPluginSensorsContainer _container, int index = 0) { - _logger.Log($"HighFlowNextDevice.Load(_container: {_container})"); + _logger.Log($"HighFlowNextDevice.Load(_container: {_container}, index = {index})"); if (hidDevice == null) return; - _container.TempSensors.Add(new DeviceBaseSensor("HighFlowNextDevice.TemperatureWater", "Water Temperature", () => this.Data_GetTemperature(() => sensor_data.temperature_water))); - _container.TempSensors.Add(new DeviceBaseSensor("HighFlowNextDevice.TemperatureExt", "External Water Temperature", () => this.Data_GetTemperature(() => sensor_data.temperature_ext))); - _container.FanSensors.Add(new DeviceBaseSensor("HighFlowNextDevice.Flow", "Flow", () => this.Data_GetTemperature(() => sensor_data.flow, 10.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("HighFlowNextDevice.WaterQuality", "Water Quality", () => this.Data_GetTemperature(() => sensor_data.water_quality))); - _container.FanSensors.Add(new DeviceBaseSensor("HighFlowNextDevice.Conductivity", "Conductivity", () => this.Data_GetTemperature(() => sensor_data.conductivity, 10.0f))); + _container.TempSensors.Add(new DeviceBaseSensor("HighFlowNextDevice"+index+".TemperatureWater", "HighFlowNext "+index+" Water Temperature", () => this.Data_GetTemperature(() => sensor_data.temperature_water))); + _container.TempSensors.Add(new DeviceBaseSensor("HighFlowNextDevice"+index+".TemperatureExt" , "HighFlowNext "+index+" External Water Temperature", () => this.Data_GetTemperature(() => sensor_data.temperature_ext))); + _container.FanSensors.Add( new DeviceBaseSensor("HighFlowNextDevice"+index+".Flow" , "HighFlowNext "+index+" Flow", () => this.Data_GetTemperature(() => sensor_data.flow, 10.0f))); + _container.FanSensors.Add( new DeviceBaseSensor("HighFlowNextDevice"+index+".WaterQuality" , "HighFlowNext "+index+" Water Quality", () => this.Data_GetTemperature(() => sensor_data.water_quality))); + _container.FanSensors.Add( new DeviceBaseSensor("HighFlowNextDevice"+index+".Conductivity" , "HighFlowNext "+index+" Conductivity", () => this.Data_GetTemperature(() => sensor_data.conductivity, 10.0f))); } diff --git a/FanControl.AquacomputerDevices/Devices/IAquacomputerDevice.cs b/FanControl.AquacomputerDevices/Devices/IAquacomputerDevice.cs index 3e68569..ee1df18 100644 --- a/FanControl.AquacomputerDevices/Devices/IAquacomputerDevice.cs +++ b/FanControl.AquacomputerDevices/Devices/IAquacomputerDevice.cs @@ -13,9 +13,11 @@ internal interface IAquacomputerDevice { int GetProductId(); + String GetDevicePath(); + IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger); - void Load(IPluginSensorsContainer _container); + void Load(IPluginSensorsContainer _container, int index = 0); void Unload(); diff --git a/FanControl.AquacomputerDevices/Devices/OctoDevice.cs b/FanControl.AquacomputerDevices/Devices/OctoDevice.cs index 2b65c77..7a1fddf 100644 --- a/FanControl.AquacomputerDevices/Devices/OctoDevice.cs +++ b/FanControl.AquacomputerDevices/Devices/OctoDevice.cs @@ -21,6 +21,7 @@ internal class OctoDevice : IAquacomputerDevice private readonly TimeSpan settings_timeout = new TimeSpan(0, 5, 0); // every 5 minutes public int GetProductId() => 0xF011; + public string GetDevicePath() => hidDevice?.DevicePath; public IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger) { @@ -36,58 +37,58 @@ public IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger) return this; } - public void Load(IPluginSensorsContainer _container) + public void Load(IPluginSensorsContainer _container, int index = 0) { - _logger.Log($"OctoDevice.Load(_container: {_container})"); + _logger.Log($"OctoDevice.Load(_container: {_container}, index = {index})"); if (hidDevice == null) return; - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans0", "Octo Fan 1", () => this.Data_GetTemperature(() => this.sensor_data.fans[0].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans1", "Octo Fan 2", () => this.Data_GetTemperature(() => this.sensor_data.fans[1].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans2", "Octo Fan 3", () => this.Data_GetTemperature(() => this.sensor_data.fans[2].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans3", "Octo Fan 4", () => this.Data_GetTemperature(() => this.sensor_data.fans[3].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans4", "Octo Fan 5", () => this.Data_GetTemperature(() => this.sensor_data.fans[4].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans5", "Octo Fan 6", () => this.Data_GetTemperature(() => this.sensor_data.fans[5].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans6", "Octo Fan 7", () => this.Data_GetTemperature(() => this.sensor_data.fans[6].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Fans7", "Octo Fan 8", () => this.Data_GetTemperature(() => this.sensor_data.fans[7].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans0", "Octo "+index+" Fan 1", () => this.Data_GetTemperature(() => this.sensor_data.fans[0].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans1", "Octo "+index+" Fan 2", () => this.Data_GetTemperature(() => this.sensor_data.fans[1].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans2", "Octo "+index+" Fan 3", () => this.Data_GetTemperature(() => this.sensor_data.fans[2].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans3", "Octo "+index+" Fan 4", () => this.Data_GetTemperature(() => this.sensor_data.fans[3].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans4", "Octo "+index+" Fan 5", () => this.Data_GetTemperature(() => this.sensor_data.fans[4].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans5", "Octo "+index+" Fan 6", () => this.Data_GetTemperature(() => this.sensor_data.fans[5].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans6", "Octo "+index+" Fan 7", () => this.Data_GetTemperature(() => this.sensor_data.fans[6].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Fans7", "Octo "+index+" Fan 8", () => this.Data_GetTemperature(() => this.sensor_data.fans[7].speed, 1.0f))); // Value for this sensor should be checked! - _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice.Flow", "Octo Flow Sensor", () => this.Data_GetTemperature(() => this.sensor_data.flow))); + _container.FanSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Flow", "Octo "+index+" Flow Sensor", () => this.Data_GetTemperature(() => this.sensor_data.flow))); - _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice.Temp0", "Octo Temperature 1", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[0]))); - _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice.Temp1", "Octo Temperature 2", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[1]))); - _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice.Temp2", "Octo Temperature 3", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[2]))); - _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice.Temp3", "Octo Temperature 4", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[3]))); + _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Temp0", "Octo "+index+" Temperature 1", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[0]))); + _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Temp1", "Octo "+index+" Temperature 2", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[1]))); + _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Temp2", "Octo "+index+" Temperature 3", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[2]))); + _container.TempSensors.Add(new DeviceBaseSensor("OctoDevice"+index+".Temp3", "Octo "+index+" Temperature 4", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[3]))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power0", "Octo Controller Power 1", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power0", "Octo Controller Power 1", () => this.Settings_GetControllerPower(0), null, (x) => this.Settings_SetControllerPower(0, x), () => this.Settings_ResetControllerPower(0))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power1", "Octo Controller Power 2", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power1", "Octo "+index+" Controller Power 2", () => this.Settings_GetControllerPower(1), null, (x) => this.Settings_SetControllerPower(1, x), () => this.Settings_ResetControllerPower(1))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power2", "Octo Controller Power 3", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power2", "Octo "+index+" Controller Power 3", () => this.Settings_GetControllerPower(2), null, (x) => this.Settings_SetControllerPower(2, x), () => this.Settings_ResetControllerPower(2))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power3", "Octo Controller Power 4", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power3", "Octo "+index+" Controller Power 4", () => this.Settings_GetControllerPower(3), null, (x) => this.Settings_SetControllerPower(3, x), () => this.Settings_ResetControllerPower(3))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power4", "Octo Controller Power 5", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power4", "Octo "+index+" Controller Power 5", () => this.Settings_GetControllerPower(4), null, (x) => this.Settings_SetControllerPower(4, x), () => this.Settings_ResetControllerPower(4))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power5", "Octo Controller Power 6", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power5", "Octo "+index+" Controller Power 6", () => this.Settings_GetControllerPower(5), null, (x) => this.Settings_SetControllerPower(5, x), () => this.Settings_ResetControllerPower(5))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power6", "Octo Controller Power 7", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice"+index+".Power6", "Octo "+index+" Controller Power 7", () => this.Settings_GetControllerPower(6), null, (x) => this.Settings_SetControllerPower(6, x), () => this.Settings_ResetControllerPower(6))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice.Power7", "Octo Controller Power 8", + _container.ControlSensors.Add(new DeviceBaseControlSensor("OctoDevice."+index+"Power7", "Octo "+index+" Controller Power 8", () => this.Settings_GetControllerPower(7), null, (x) => this.Settings_SetControllerPower(7, x), () => this.Settings_ResetControllerPower(7))); diff --git a/FanControl.AquacomputerDevices/Devices/QuadroDevice.cs b/FanControl.AquacomputerDevices/Devices/QuadroDevice.cs index f9909e0..df19e0f 100644 --- a/FanControl.AquacomputerDevices/Devices/QuadroDevice.cs +++ b/FanControl.AquacomputerDevices/Devices/QuadroDevice.cs @@ -18,6 +18,7 @@ internal class QuadroDevice : IAquacomputerDevice private readonly TimeSpan settings_timeout = new TimeSpan(0, 5, 0); // every 5 minutes public int GetProductId() => 0xF00D; + public string GetDevicePath() => hidDevice?.DevicePath; public IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger) { @@ -33,38 +34,38 @@ public IAquacomputerDevice AssignDevice(HidDevice device, IPluginLogger logger) return this; } - public void Load(IPluginSensorsContainer _container) + public void Load(IPluginSensorsContainer _container, int index = 0) { - _logger.Log($"QuadroDevice.Load(_container: {_container})"); + _logger.Log($"QuadroDevice.Load(_container: {_container}, index = {index})"); if (hidDevice == null) return; - _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice.Fans0", "Quadro Fan 1", () => this.Data_GetTemperature(() => this.sensor_data.fans[0].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice.Fans1", "Quadro Fan 2", () => this.Data_GetTemperature(() => this.sensor_data.fans[1].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice.Fans2", "Quadro Fan 3", () => this.Data_GetTemperature(() => this.sensor_data.fans[2].speed, 1.0f))); - _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice.Fans3", "Quadro Fan 4", () => this.Data_GetTemperature(() => this.sensor_data.fans[3].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Fans0", "Quadro "+index+" Fan 1", () => this.Data_GetTemperature(() => this.sensor_data.fans[0].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Fans1", "Quadro "+index+" Fan 2", () => this.Data_GetTemperature(() => this.sensor_data.fans[1].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Fans2", "Quadro "+index+" Fan 3", () => this.Data_GetTemperature(() => this.sensor_data.fans[2].speed, 1.0f))); + _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Fans3", "Quadro "+index+" Fan 4", () => this.Data_GetTemperature(() => this.sensor_data.fans[3].speed, 1.0f))); // Value for this sensor should be checked! - _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice.Flow", "Quadro Flow Sensor", () => this.Data_GetTemperature(() => this.sensor_data.flow))); + _container.FanSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Flow", "Quadro "+index+" Flow Sensor", () => this.Data_GetTemperature(() => this.sensor_data.flow))); - _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice.Temp0", "Quadro Temperature 1", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[0]))); - _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice.Temp1", "Quadro Temperature 2", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[1]))); - _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice.Temp2", "Quadro Temperature 3", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[2]))); - _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice.Temp3", "Quadro Temperature 4", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[3]))); + _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Temp0", "Quadro "+index+" Temperature 1", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[0]))); + _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Temp1", "Quadro "+index+" Temperature 2", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[1]))); + _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Temp2", "Quadro "+index+" Temperature 3", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[2]))); + _container.TempSensors.Add(new DeviceBaseSensor("QuadroDevice"+index+".Temp3", "Quadro "+index+" Temperature 4", () => this.Data_GetTemperature(() => this.sensor_data.temperatures[3]))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice.Power0", "Quadro Controller Power 1", + _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice"+index+".Power0", "Quadro "+index+" Controller Power 1", () => this.Settings_GetControllerPower(0), null, (x) => this.Settings_SetControllerPower(0, x), () => this.Settings_ResetControllerPower(0))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice.Power1", "Quadro Controller Power 2", + _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice"+index+".Power1", "Quadro "+index+" Controller Power 2", () => this.Settings_GetControllerPower(1), null, (x) => this.Settings_SetControllerPower(1, x), () => this.Settings_ResetControllerPower(1))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice.Power2", "Quadro Controller Power 3", + _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice"+index+".Power2", "Quadro "+index+" Controller Power 3", () => this.Settings_GetControllerPower(2), null, (x) => this.Settings_SetControllerPower(2, x), () => this.Settings_ResetControllerPower(2))); - _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice.Power3", "Quadro Controller Power 4", + _container.ControlSensors.Add(new DeviceBaseControlSensor("QuadroDevice"+index+".Power3", "Quadro "+index+" Controller Power 4", () => this.Settings_GetControllerPower(3), null, (x) => this.Settings_SetControllerPower(3, x), () => this.Settings_ResetControllerPower(3))); diff --git a/FanControl.AquacomputerDevices/Properties/AssemblyInfo.cs b/FanControl.AquacomputerDevices/Properties/AssemblyInfo.cs index df11b0a..17a426e 100644 --- a/FanControl.AquacomputerDevices/Properties/AssemblyInfo.cs +++ b/FanControl.AquacomputerDevices/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.4")] -[assembly: AssemblyFileVersion("1.0.0.4")] +[assembly: AssemblyVersion("1.0.0.5")] +[assembly: AssemblyFileVersion("1.0.0.5")]