Move EmbeddedController model selection out of Motherboard

This commit is contained in:
PhyxionNL
2021-06-22 10:22:06 +02:00
parent e5a852457f
commit 24331fb6dc
2 changed files with 45 additions and 46 deletions
@@ -35,13 +35,51 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC
public override HardwareType HardwareType => HardwareType.EmbeddedController;
public static EmbeddedController Create(List<EmbeddedControllerSource> sources, ISettings settings)
internal static EmbeddedController Create(Model model, ISettings settings)
{
return Environment.OSVersion.Platform switch
var sources = new List<EmbeddedControllerSource>();
switch (model)
{
PlatformID.Win32NT => new WindowsEmbeddedController(sources, settings),
_ => null
};
case Model.ROG_STRIX_X570_E_GAMING:
case Model.ROG_CROSSHAIR_VIII_HERO:
{
sources.AddRange(new EmbeddedControllerSource[]
{
new("Chipset", 0x3A, SensorType.Temperature, ReadByte),
new("CPU", 0x3B, SensorType.Temperature, ReadByte),
new("Motherboard", 0x3C, SensorType.Temperature, ReadByte),
new("T Sensor", 0x3D, SensorType.Temperature, ReadByte),
new("VRM", 0x3E, SensorType.Temperature, ReadByte),
new("CPU Opt", 0xB0, SensorType.Fan, ReadWordBE),
new("Chipset", 0xB4, SensorType.Fan, ReadWordBE),
new("CPU", 0xF4, SensorType.Current, ReadByte)
});
break;
}
}
switch (model)
{
case Model.ROG_CROSSHAIR_VIII_HERO:
{
// TODO: "why 42?" is a silly question, I know, but still, why? On the serious side, it might be 41.6(6)
sources.Add(new EmbeddedControllerSource("Flow Rate", 0xBC, SensorType.Flow, (ecIO, port) => ecIO.ReadWordBE(port) / 42f * 60f));
break;
}
}
if (sources.Count > 0)
{
return Environment.OSVersion.Platform switch
{
PlatformID.Win32NT => new WindowsEmbeddedController(sources, settings),
_ => null
};
}
return null;
}
public override void Update()
@@ -61,17 +61,15 @@ namespace LibreHardwareMonitor.Hardware.Motherboard
_lpcIO = new LpcIO();
superIO = _lpcIO.SuperIO;
}
EmbeddedController embeddedController = CreateEmbeddedController(model, settings);
EmbeddedController embeddedController = EmbeddedController.Create(model, settings);
SubHardware = new IHardware[superIO.Count + (embeddedController != null ? 1 : 0)];
for (int i = 0; i < superIO.Count; i++)
SubHardware[i] = new SuperIOHardware(this, superIO[i], manufacturer, model, settings);
if (embeddedController != null)
{
SubHardware[superIO.Count] = embeddedController;
}
}
public event SensorEventHandler SensorAdded;
@@ -159,42 +157,5 @@ namespace LibreHardwareMonitor.Hardware.Motherboard
hardware.Close();
}
}
private static EmbeddedController CreateEmbeddedController(Model model, ISettings settings)
{
var sources = new List<EmbeddedControllerSource>();
switch (model)
{
case Model.ROG_STRIX_X570_E_GAMING:
case Model.ROG_CROSSHAIR_VIII_HERO:
{
sources.AddRange(new EmbeddedControllerSource[]
{
new("Chipset", 0x3A, SensorType.Temperature, EmbeddedController.ReadByte),
new("CPU", 0x3B, SensorType.Temperature, EmbeddedController.ReadByte),
new("Motherboard", 0x3C, SensorType.Temperature, EmbeddedController.ReadByte),
new("T Sensor", 0x3D, SensorType.Temperature, EmbeddedController.ReadByte),
new("VRM", 0x3E, SensorType.Temperature, EmbeddedController.ReadByte),
new("CPU Opt", 0xB0, SensorType.Fan, EmbeddedController.ReadWordBE),
new("Chipset", 0xB4, SensorType.Fan, EmbeddedController.ReadWordBE),
new("CPU", 0xF4, SensorType.Current, EmbeddedController.ReadByte)
});
break;
}
}
switch (model)
{
case Model.ROG_CROSSHAIR_VIII_HERO:
{
// TODO: "why 42?" is a silly question, I know, but still, why? On the serious side, it might be 41.6(6)
sources.Add(new("Flow Rate", 0xBC, SensorType.Flow, (ecIO, port) => ecIO.ReadWordBE(port) / 42f * 60f));
break;
}
}
return sources.Count > 0 ? EmbeddedController.Create(sources, settings) : null;
}
}
}