|
| 1 | +using System.Collections.Generic; |
| 2 | +using HidSharp; |
| 3 | + |
| 4 | +namespace OpenHardwareMonitor.Hardware.Psu.Msi; |
| 5 | + |
| 6 | +internal sealed class MsiPsu : Hardware |
| 7 | +{ |
| 8 | + private readonly HidDevice _device; |
| 9 | + private readonly List<PsuSensor> _sensors = []; |
| 10 | + |
| 11 | + public MsiPsu(HidDevice device, ISettings settings, int index) |
| 12 | + : base("MSI PSU", new Identifier("psu", "msi", index.ToString()), settings) |
| 13 | + { |
| 14 | + _device = device; |
| 15 | + using HidStream stream = device.Open(); |
| 16 | + UsbApi.FirmwareInfo fwInfo = UsbApi.FwInfo(stream); |
| 17 | + Name = $"{fwInfo.Vendor} {fwInfo.Product}"; |
| 18 | + |
| 19 | + AddSensors(settings); |
| 20 | + } |
| 21 | + |
| 22 | + public override HardwareType HardwareType => HardwareType.Psu; |
| 23 | + |
| 24 | + public override void Update() |
| 25 | + { |
| 26 | + using HidStream stream = _device.Open(); |
| 27 | + float[] info = UsbApi.InfoList(stream); |
| 28 | + _sensors.ForEach(s => s.Update(info)); |
| 29 | + } |
| 30 | + |
| 31 | + private void AddSensors(ISettings settings) |
| 32 | + { |
| 33 | + int sensorIndex = 0; |
| 34 | + |
| 35 | + _sensors.Add(new PsuSensor("Case", sensorIndex++, SensorType.Fan, this, settings, UsbApi.IndexInfo.FAN_RPM)); |
| 36 | + _sensors.Add(new PsuSensor("Case", sensorIndex++, SensorType.Temperature, this, settings, UsbApi.IndexInfo.TEMP)); |
| 37 | + |
| 38 | + _sensors.Add(new PsuSensor("+12V", sensorIndex++, SensorType.Voltage, this, settings, UsbApi.IndexInfo.VOLTS_12)); |
| 39 | + _sensors.Add(new PsuSensor("+12V", sensorIndex++, SensorType.Current, this, settings, UsbApi.IndexInfo.AMPS_12)); |
| 40 | + |
| 41 | + _sensors.Add(new PsuSensor("+5V", sensorIndex++, SensorType.Voltage, this, settings, UsbApi.IndexInfo.VOLTS_5)); |
| 42 | + _sensors.Add(new PsuSensor("+5V", sensorIndex++, SensorType.Current, this, settings, UsbApi.IndexInfo.AMPS_5)); |
| 43 | + |
| 44 | + _sensors.Add(new PsuSensor("+3.3V", sensorIndex++, SensorType.Voltage, this, settings, UsbApi.IndexInfo.VOLTS_3V3)); |
| 45 | + _sensors.Add(new PsuSensor("+3.3V", sensorIndex++, SensorType.Current, this, settings, UsbApi.IndexInfo.AMPS_3V3)); |
| 46 | + |
| 47 | + _sensors.Add(new PsuSensor("PSU Efficiency", sensorIndex++, SensorType.Level, this, settings, UsbApi.IndexInfo.EFFICIENCY)); |
| 48 | + _sensors.Add(new PsuSensor("PSU Out", sensorIndex++, SensorType.Power, this, settings, UsbApi.IndexInfo.PSU_OUT)); |
| 49 | + _sensors.Add(new PsuSensor("Total Runtime", sensorIndex++, SensorType.TimeSpan, this, settings, UsbApi.IndexInfo.RUNTIME, true)); |
| 50 | + } |
| 51 | + |
| 52 | + private class PsuSensor : Sensor |
| 53 | + { |
| 54 | + private readonly UsbApi.IndexInfo _indexInfo; |
| 55 | + |
| 56 | + public PsuSensor(string name, int index, SensorType type, MsiPsu hardware, ISettings settings, UsbApi.IndexInfo indexInfo, bool noHistory = false) |
| 57 | + : base(name, index, false, type, hardware, null, settings, noHistory) |
| 58 | + { |
| 59 | + _indexInfo = indexInfo; |
| 60 | + hardware.ActivateSensor(this); |
| 61 | + } |
| 62 | + |
| 63 | + public void Update(float[] info) |
| 64 | + { |
| 65 | + Value = info[(int)_indexInfo]; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments