Skip to content

Commit

Permalink
update plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
irusanov committed Jun 3, 2022
1 parent 56828ed commit 9002c3c
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 52 deletions.
2 changes: 1 addition & 1 deletion WPF/Common/Sensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public float? Value

public Sensor(string name, int index)
{
Name = name;
Name = name ?? "";
Index = index;
}

Expand Down
65 changes: 34 additions & 31 deletions WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public partial class MainWindow
private bool compatMode;
//private Computer computer;

private readonly string AssemblyProduct = ((AssemblyProductAttribute)Attribute.GetCustomAttribute(
Assembly.GetExecutingAssembly(),
typeof(AssemblyProductAttribute), false)).Product;

private readonly string AssemblyVersion = ((AssemblyFileVersionAttribute)Attribute.GetCustomAttribute(
Assembly.GetExecutingAssembly(),
typeof(AssemblyFileVersionAttribute), false)).Version;

public MainWindow()
{
try
Expand Down Expand Up @@ -99,6 +107,9 @@ public MainWindow()
SplashWindow.Loading("Plugins");
SplashWindow.Loading("SVI2 Plugin");
plugins.Add(new SVI2Plugin(cpu));
//plugins.Add(new OHWMPlugin());
//plugins[1].Open();

ReadSVI();
/*computer = new Computer()
{
Expand Down Expand Up @@ -131,7 +142,8 @@ public MainWindow()
timings = MEMCFG,
cpu.powerTable,
WMIPresent = !compatMode,
settings
settings,
plugins
};
}
catch (Exception ex)
Expand Down Expand Up @@ -182,6 +194,9 @@ private void NotifyIcon_MouseClick(object sender, Forms.MouseEventArgs e)

private void ExitApplication()
{
foreach (var plugin in plugins)
plugin?.Close();

_notifyIcon?.Dispose();
AsusWmi?.Dispose();
cpu?.Dispose();
Expand Down Expand Up @@ -301,7 +316,6 @@ private void ReadMemoryModulesInfo()

foreach (var module in modules)
{
var rank = module.DualRank ? "DR" : "SR";
totalCapacity += module.Capacity;
comboBoxPartNumber.Items.Add(
$"{module.Slot}: {module.PartNumber} ({module.Capacity / 1024 / (1024 * 1024)}GB, {module.Rank})");
Expand All @@ -321,29 +335,16 @@ private void ReadMemoryModulesInfo()
}
}

/* private void RefreshSensors()
private void RefreshSensors()
{
foreach (var hardware in computer.Hardware)
plugins[1].Update();
foreach (var sensor in plugins[1].Sensors)
{
if (hardware.HardwareType == HardwareType.Mainboard)
{
foreach (var subHardware in hardware.SubHardware)
{
subHardware.Update();
foreach (var subsensor in subHardware.Sensors)
{
//if (subsensor.SensorType == SensorType.Voltage)
Console.WriteLine($"----{subsensor.SensorType}, Name: {subsensor.Name}, Value: {subsensor.Value}");
}
}
}
Console.WriteLine($"----Name: {sensor.Name}, Value: {sensor.Value}");
}
}*/

private bool RefreshPowerTable()
{
return cpu.RefreshPowerTable() == SMU.Status.OK;
//Console.WriteLine("CCD temp: " + cpu.GetSingleCcdTemperature(0));
//Console.WriteLine("Core temp: " + cpu.GetCpuTemperature());
}

private void ReadSVI()
Expand All @@ -369,17 +370,16 @@ private void ReadMemoryConfig()
$"{className}.InstanceName='{instanceName}'",
null);

// Get possible values (index) of a memory option in BIOS
/*pack = WMI.InvokeMethod(classInstance, "Getdvalues", "pack", "ID", 0x20007);
if (pack != null)
/* // Get possible values (index) of a memory option in BIOS
var dvaluesPack = WMI.InvokeMethod(classInstance, "Getdvalues", "pack", "ID", 0x20035);
if (dvaluesPack != null)
{
uint[] DValuesBuffer = (uint[])pack.GetPropertyValue("DValuesBuffer");
uint[] DValuesBuffer = (uint[])dvaluesPack.GetPropertyValue("DValuesBuffer");
for (var i = 0; i < DValuesBuffer.Length; i++)
{
Debug.WriteLine("{0}", DValuesBuffer[i]);
}
}
*/
}*/


// Get function names with their IDs
Expand Down Expand Up @@ -702,11 +702,11 @@ private void PowerCfgTimer_Tick(object sender, EventArgs e)

Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, new Action(() =>
{
//ReadTimings();
//ReadMemoryConfig();
// ReadTimings();
// ReadMemoryConfig();
cpu.RefreshPowerTable();
ReadSVI();
//RefreshSensors();
// RefreshSensors();
}));
}).Start();
}
Expand Down Expand Up @@ -979,7 +979,10 @@ private void AdonisWindow_Closing(object sender, System.ComponentModel.CancelEve
settings.Save();
}

_notifyIcon.Dispose();
foreach (var plugin in plugins)
plugin?.Close();

_notifyIcon.Dispose();
AsusWmi?.Dispose();
cpu?.Dispose();
}
Expand Down
3 changes: 2 additions & 1 deletion WPF/Plugin/IPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public interface IPlugin
string Author { get; }
string Version { get; }
List<Sensor> Sensors { get; }
//void Init();
void Open();
void Close();
bool Update();
}
}
127 changes: 127 additions & 0 deletions WPF/Plugin/OHWMPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ZenStates.Core;
using ZenTimings.Common;

namespace ZenTimings.Plugin
{
public class OHWMPlugin : IPlugin
{
internal dynamic computer;
internal Assembly assembly;
internal Type Mainboard;
public string Name => "OpenHardwareMonitor Plugin";

public string Description => "A wrapper around OpenHardwareMonitor's DLL";

public string Author => "Ivan Rusanov";

public string Version => "1.0";

public List<Sensor> Sensors { get; internal set; }

public OHWMPlugin()
{
try
{
assembly = Assembly.LoadFrom("OpenHardwareMonitorLib.dll");
Type type = assembly.GetType("OpenHardwareMonitor.Hardware.Computer");
computer = Activator.CreateInstance(type);
Mainboard = assembly.GetType("OpenHardwareMonitor.Hardware.Mainboard.Mainboard");
}
catch (Exception ex)
{
Close();
}
}

public void Close()
{
computer?.Close();
assembly = null;
}

public void Open()
{
Sensors = new List<Sensor>();
computer.MainboardEnabled = true;
computer.Open();

foreach (var hardware in computer.Hardware)
{
if (GetPropValue(hardware, "HardwareType").ToString() == "Mainboard")
{
foreach (var subHardware in GetPropValue(hardware, "SubHardware"))
{
Type type = subHardware.GetType();
// subHardware.Update();

type.InvokeMember("Update",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
subHardware,
null);

foreach (var subsensor in GetPropValue(subHardware, "Sensors"))
{
if (GetPropValue(subsensor, "SensorType").ToString() == "Voltage")
{
// Console.WriteLine($"----Index: {GetPropValue(subsensor, "Index")}, {GetPropValue(subsensor, "SensorType")}, Name: {GetPropValue(subsensor, "Name")}, Value: {GetPropValue(subsensor, "Value")}");
try
{
Sensors.Add(
new Sensor((string)GetPropValue(subsensor, "Name"), (int)GetPropValue(subsensor, "Index"))
{
Value = GetPropValue(subsensor, "Value") ?? 0,
}
);
}
catch { }
}
}
}
}
}
}

public bool Update()
{
foreach (var hardware in computer.Hardware)
{
if (GetPropValue(hardware, "HardwareType").ToString() == "Mainboard")
{
foreach (var subHardware in GetPropValue(hardware, "SubHardware"))
{
Type type = subHardware.GetType();
// subHardware.Update();

type.InvokeMember("Update",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
subHardware,
null);

foreach (var subsensor in GetPropValue(subHardware, "Sensors"))
{
if (GetPropValue(subsensor, "SensorType").ToString() == "Voltage")
{
Sensors[(int)GetPropValue(subsensor, "Index")].Value = GetPropValue(subsensor, "Value") ?? 0;
}
}
}
}
}

return true;
}

private static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName)?.GetValue(src, null);
}
}
}
43 changes: 26 additions & 17 deletions WPF/Plugin/SVI2Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ZenTimings.Plugin
{
public class SVI2Plugin : IPlugin
{
internal readonly Cpu _cpu;
internal Cpu _cpu;
internal int timeout = 20;
internal const string VERSION = "1.0";

Expand All @@ -19,7 +19,7 @@ public class SVI2Plugin : IPlugin

public string Version => VERSION;

public List<Sensor> Sensors { get; }
public List<Sensor> Sensors { get; private set; }

public SVI2Plugin(Cpu cpu)
{
Expand All @@ -37,29 +37,38 @@ public SVI2Plugin(Cpu cpu)
}
}

/*public void Init()
{
throw new NotImplementedException();
}*/

public bool Update()
{
uint soc_plane_value;
do
if (Sensors.Count > 0)
{
soc_plane_value = _cpu.ReadDword(_cpu.info.svi2.socAddress);
} while ((soc_plane_value & 0xFF00) != 0 && --timeout > 0);
uint soc_plane_value;
do
{
soc_plane_value = _cpu.ReadDword(_cpu.info.svi2.socAddress);
} while ((soc_plane_value & 0xFF00) != 0 && --timeout > 0);

if (timeout > 0)
{
uint socVid = (soc_plane_value >> 16) & 0xFF;
Sensors[0].Value = Convert.ToSingle(Utils.VidToVoltage(socVid));
if (timeout > 0)
{
uint socVid = (soc_plane_value >> 16) & 0xFF;
Sensors[0].Value = Convert.ToSingle(Utils.VidToVoltage(socVid));

Console.WriteLine(Sensors[0].Min + " " + Sensors[0].Max);
return true;
Console.WriteLine(Sensors[0].Min + " " + Sensors[0].Max);
return true;
}
}

return false;
}

public void Open()
{
throw new NotImplementedException();
}

public void Close()
{
_cpu = null;
Sensors = null;
}
}
}
4 changes: 2 additions & 2 deletions WPF/ZenTimings.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -121,6 +121,7 @@
<Compile Include="Converters\FloatToNAConverter.cs" />
<Compile Include="Converters\FloatToVoltageConverter.cs" />
<Compile Include="Plugin\IPlugin.cs" />
<Compile Include="Plugin\OHWMPlugin.cs" />
<Compile Include="Plugin\SVI2Plugin.cs" />
<Compile Include="Properties\BuildNumberTemplate.cs">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -229,7 +230,6 @@
<ItemGroup>
<Resource Include="Resources\new-icon\64.png" />
<Resource Include="Resources\new-icon\16.png" />
<Resource Include="ZenTimings2022.ico" />
<Resource Include="Resources\ZenTimings2022.ico" />
<Content Include="Properties\BuildNumberTemplate.tt">
<Generator>TextTemplatingFileGenerator</Generator>
Expand Down
6 changes: 6 additions & 0 deletions WPF/ZenTimings.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZenTimings", "ZenTimings.cs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZenTimings-legacy", "..\WPF-no-themes\ZenTimings-legacy.csproj", "{C745505A-2C8B-44DF-9240-76D51738D9EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OHWMPlugin", "..\OHWMPlugin\OHWMPlugin.csproj", "{29941469-27AD-4C9B-8DE2-7E971105A99C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{C745505A-2C8B-44DF-9240-76D51738D9EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C745505A-2C8B-44DF-9240-76D51738D9EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C745505A-2C8B-44DF-9240-76D51738D9EF}.Release|Any CPU.Build.0 = Release|Any CPU
{29941469-27AD-4C9B-8DE2-7E971105A99C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29941469-27AD-4C9B-8DE2-7E971105A99C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29941469-27AD-4C9B-8DE2-7E971105A99C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29941469-27AD-4C9B-8DE2-7E971105A99C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 9002c3c

Please sign in to comment.