This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hyrules
committed
Sep 18, 2016
1 parent
5b28de7
commit 143ab18
Showing
36 changed files
with
2,483 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Management; | ||
using OpenHardwareMonitor; | ||
using OpenHardwareMonitor.Hardware; | ||
using OpenHardwareMonitor.Collections; | ||
using System.Windows.Threading; | ||
using System.ComponentModel; | ||
|
||
namespace WinHue3 | ||
{ | ||
public class CpuTemp | ||
{ | ||
public float? temperature | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public string pollSensorName; | ||
|
||
public List<ISensor> cpuSensors | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
private readonly DispatcherTimer timer; | ||
private readonly Computer comp; | ||
private readonly BackgroundWorker bgwOpen; | ||
private bool _notWorking = false; | ||
|
||
public bool Working | ||
{ | ||
get{ return _notWorking;} | ||
private set{ _notWorking = value;} | ||
} | ||
|
||
public CpuTemp(int pollingInterval) | ||
{ | ||
|
||
comp = new Computer(); | ||
timer = new DispatcherTimer(); | ||
timer.Tick += timer_Tick; | ||
timer.Interval = new TimeSpan(0, 0, pollingInterval); | ||
comp.CPUEnabled = true; | ||
|
||
bgwOpen = new BackgroundWorker(); | ||
bgwOpen.DoWork += bgwOpen_DoWork; | ||
try | ||
{ | ||
comp.Open(); | ||
UpdateSensors(); | ||
comp.Close(); | ||
Working = true; | ||
} | ||
catch (Exception) | ||
{ | ||
Working = false; | ||
} | ||
|
||
pollSensorName = "CPU Package"; | ||
} | ||
|
||
void bgwOpen_DoWork(object sender, DoWorkEventArgs e) | ||
{ | ||
try | ||
{ | ||
comp.Open(); | ||
timer.Start(); | ||
Working = true; | ||
} | ||
catch(Exception) | ||
{ | ||
Working = false; | ||
} | ||
|
||
|
||
} | ||
|
||
public void Start() | ||
{ | ||
if (!timer.IsEnabled && Working) | ||
{ | ||
bgwOpen.RunWorkerAsync(); | ||
} | ||
} | ||
|
||
public void Stop() | ||
{ | ||
if (!timer.IsEnabled || !Working) return; | ||
timer.Stop(); | ||
comp.Close(); | ||
} | ||
|
||
private void timer_Tick(object sender, EventArgs e) | ||
{ | ||
UpdateSensors(); | ||
int cpuPackage = cpuSensors.FindIndex(sensor => sensor.Name == pollSensorName); | ||
if (cpuPackage == -1) | ||
cpuPackage = 0; | ||
|
||
temperature = cpuSensors[cpuPackage].Value; | ||
OnTempUpdated?.Invoke(this, new CpuTempEventArgs() { currentTemp= temperature}); | ||
} | ||
|
||
public event CpuTempEvent OnTempUpdated; | ||
public delegate void CpuTempEvent(object sender, CpuTempEventArgs e); | ||
public event CpuSensorEvent OnSensorUpdated; | ||
public delegate void CpuSensorEvent(object sender, EventArgs e); | ||
|
||
private void UpdateSensors() | ||
{ | ||
foreach (IHardware hardware in comp.Hardware) | ||
{ | ||
if (hardware.HardwareType != HardwareType.CPU) continue; | ||
|
||
hardware.Update(); | ||
|
||
cpuSensors = hardware.Sensors.ToList<ISensor>(); | ||
cpuSensors.RemoveAll(sens => sens.SensorType != SensorType.Temperature); | ||
} | ||
OnSensorUpdated?.Invoke(this, new EventArgs()); | ||
} | ||
} | ||
|
||
public class CpuTempEventArgs : EventArgs | ||
{ | ||
public float? currentTemp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using HueLib2; | ||
|
||
namespace WinHue3 | ||
{ | ||
|
||
public class CpuTempMonitor : View | ||
{ | ||
/// <summary> | ||
/// Name of the plugin. | ||
/// </summary> | ||
private const string PluginName = "Cpu Temp Monitor"; | ||
|
||
/// <summary> | ||
/// Description of the plugin. | ||
/// </summary> | ||
private const string PluginDesc = "Adjust a light or group of light depending on the temperature of your cpu."; | ||
|
||
/// <summary> | ||
/// Author of the plugin. | ||
/// </summary> | ||
private const string PluginAuth = "Pascal Pharand"; | ||
|
||
CpuTemp _temp; | ||
|
||
double _gradientStartColor; | ||
double _gradientStopColor; | ||
double _gradientStopTemp; | ||
double _gradientStartTemp; | ||
string _objectId; | ||
bool _objectType; | ||
byte _userBri; | ||
byte _userSat; | ||
private bool _isrunning; | ||
|
||
public CpuTempMonitor() | ||
{ | ||
_temp = new CpuTemp(1); | ||
_temp.OnTempUpdated += temp_OnTempUpdated; | ||
LoadSettings(); | ||
} | ||
|
||
private void LoadSettings() | ||
{ | ||
_gradientStartColor = Properties.Settings.Default.CPUTemp_gradientStartColor; | ||
_gradientStartTemp = Properties.Settings.Default.CPUTemp_gradientStartTemp; | ||
_gradientStopColor = Properties.Settings.Default.CPUTemp_gradientStopColor; | ||
_gradientStopTemp = Properties.Settings.Default.CPUTemp_gradientStopTemp; | ||
_objectId = Properties.Settings.Default.CPUTemp_ObjectID; | ||
_objectType = Properties.Settings.Default.CPUTemp_ObjectType; | ||
_userBri = Properties.Settings.Default.CpuTemp_Brightness; | ||
_userSat = Properties.Settings.Default.CPUTemp_Saturation; | ||
|
||
} | ||
|
||
public bool IsRunning | ||
{ | ||
get { return _isrunning;} | ||
private set { _isrunning = value; OnPropertyChanged(); } | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Required for the interface to know what the plugin name is. | ||
/// </summary> | ||
public string pluginName => PluginName; | ||
|
||
/// <summary> | ||
/// Required for the interface to know what the plugin description is. | ||
/// </summary> | ||
public string pluginDesc => PluginDesc; | ||
|
||
/// <summary> | ||
/// Required for the interface to know what the plugin author is. | ||
/// </summary> | ||
public string pluginAuth => PluginAuth; | ||
|
||
/// <summary> | ||
/// Required by the interface get the icon image. | ||
/// </summary> | ||
public Bitmap pluginIcon => Properties.Resources.cputemp; | ||
|
||
/// <summary> | ||
/// Do the plugin work. | ||
/// </summary> | ||
public void Start() | ||
{ | ||
_temp.Start(); | ||
IsRunning = true; | ||
} | ||
|
||
/// <summary> | ||
/// Stop the plugin. | ||
/// </summary> | ||
public void Stop() | ||
{ | ||
_temp.Stop(); | ||
IsRunning = false; | ||
} | ||
|
||
/// <summary> | ||
/// Show the settings form for the plugin. | ||
/// </summary> | ||
/// <returns>True or false or null depending on what you want to return.</returns> | ||
public bool? ShowSettingsForm() | ||
{ | ||
_temp.Stop(); | ||
Form_CpuTempMonitorSettings settings = new Form_CpuTempMonitorSettings(_temp) {Owner = Application.Current.MainWindow}; | ||
_temp.OnTempUpdated -= temp_OnTempUpdated; | ||
var result = settings.ShowDialog(); | ||
_temp.OnTempUpdated += temp_OnTempUpdated; | ||
if (result == true) | ||
LoadSettings(); | ||
return result; | ||
} | ||
|
||
void temp_OnTempUpdated(object sender, CpuTempEventArgs e) | ||
{ | ||
float? actualtemp = e.currentTemp; | ||
ushort hueTemp = 0; | ||
|
||
if (actualtemp == null) | ||
{ | ||
hueTemp = (ushort)_gradientStartColor; | ||
} | ||
else | ||
{ | ||
|
||
double gradientRange = _gradientStartColor - _gradientStopColor; | ||
double tempRange = _gradientStopTemp - _gradientStartTemp; | ||
|
||
// Check for the order of the sliders. Is the first slider before the 2nd or the other way around. | ||
if (gradientRange > 0) | ||
{ | ||
double multiplier = _gradientStartColor / tempRange; | ||
hueTemp = (ushort)(_gradientStartColor - (multiplier * (actualtemp - _gradientStartTemp))); | ||
} | ||
else | ||
{ | ||
hueTemp = (ushort)((_gradientStopColor * actualtemp) / _gradientStopTemp); | ||
} | ||
|
||
} | ||
|
||
if (_objectType == true) | ||
{ | ||
BridgeStore.SelectedBridge.SetState<Light>(new State() { hue = hueTemp, bri = _userBri, sat = _userSat, @on = true, transitiontime = 9 },_objectId); | ||
} | ||
else | ||
{ | ||
BridgeStore.SelectedBridge.SetState<Group>(new HueLib2.Action() { hue = hueTemp, bri = _userBri, sat = _userSat, @on = true, transitiontime = 9 },_objectId); | ||
} | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.