Skip to content

Instantly share code, notes, and snippets.

@peazz
Created August 15, 2021 18:20
Show Gist options
  • Save peazz/af550d98189bd5971cbb35a320656b5b to your computer and use it in GitHub Desktop.
Save peazz/af550d98189bd5971cbb35a320656b5b to your computer and use it in GitHub Desktop.
OHM Step 5
if (hardware.HardwareType == HardwareType.CPU)
{
// only fire the update when found
hardware.Update();
// loop through the data
foreach (var sensor in hardware.Sensors)
if (sensor.SensorType == SensorType.Temperature && sensor.Name.Contains("CPU Package"))
{
// store
cpuTemp = sensor.Value.GetValueOrDefault();
// print to console
System.Diagnostics.Debug.WriteLine("cpuTemp: " + sensor.Value.GetValueOrDefault());
}
else if (sensor.SensorType == SensorType.Load && sensor.Name.Contains("CPU Total"))
{
// store
cpuUsage = sensor.Value.GetValueOrDefault();
// print to console
System.Diagnostics.Debug.WriteLine("cpuUsage: " + sensor.Value.GetValueOrDefault());
}
else if (sensor.SensorType == SensorType.Power && sensor.Name.Contains("CPU Package"))
{
// store
cpuPowerDrawPackage = sensor.Value.GetValueOrDefault();
// print to console
System.Diagnostics.Debug.WriteLine("CPU Power Draw - Package: " + sensor.Value.GetValueOrDefault());
}
else if (sensor.SensorType == SensorType.Clock && sensor.Name.Contains("CPU Core #1"))
{
// store
cpuFrequency = sensor.Value.GetValueOrDefault();
// print to console
System.Diagnostics.Debug.WriteLine("cpuFrequency: " + sensor.Value.GetValueOrDefault());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment