diff --git a/ControlForm.Designer.cs b/ControlForm.Designer.cs index 5d0fafa..7f07048 100644 --- a/ControlForm.Designer.cs +++ b/ControlForm.Designer.cs @@ -31,8 +31,8 @@ private void InitializeComponent() this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ControlForm)); this.mEnableCheckBox = new System.Windows.Forms.CheckBox(); - this.mSensorGroupBox = new System.Windows.Forms.GroupBox(); - this.mSensorComboBox = new System.Windows.Forms.ComboBox(); + this.mTempGroupBox = new System.Windows.Forms.GroupBox(); + this.mTempComboBox = new System.Windows.Forms.ComboBox(); this.mFanGroupBox = new System.Windows.Forms.GroupBox(); this.mRemoveButton = new System.Windows.Forms.Button(); this.mAddButton = new System.Windows.Forms.Button(); @@ -55,7 +55,7 @@ private void InitializeComponent() this.mUnitComboBox = new System.Windows.Forms.ComboBox(); this.mPresetLoadButton = new System.Windows.Forms.Button(); this.mPresetSaveButton = new System.Windows.Forms.Button(); - this.mSensorGroupBox.SuspendLayout(); + this.mTempGroupBox.SuspendLayout(); this.mFanGroupBox.SuspendLayout(); this.mGraphGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.mHysNumericUpDown)).BeginInit(); @@ -72,24 +72,24 @@ private void InitializeComponent() this.mEnableCheckBox.Text = "Enable automatic fan control"; this.mEnableCheckBox.UseVisualStyleBackColor = true; // - // mSensorGroupBox + // mTempGroupBox // - this.mSensorGroupBox.Controls.Add(this.mSensorComboBox); - this.mSensorGroupBox.Location = new System.Drawing.Point(12, 61); - this.mSensorGroupBox.Name = "mSensorGroupBox"; - this.mSensorGroupBox.Size = new System.Drawing.Size(208, 51); - this.mSensorGroupBox.TabIndex = 1; - this.mSensorGroupBox.TabStop = false; - this.mSensorGroupBox.Text = "Sensor"; + this.mTempGroupBox.Controls.Add(this.mTempComboBox); + this.mTempGroupBox.Location = new System.Drawing.Point(12, 61); + this.mTempGroupBox.Name = "mTempGroupBox"; + this.mTempGroupBox.Size = new System.Drawing.Size(208, 51); + this.mTempGroupBox.TabIndex = 1; + this.mTempGroupBox.TabStop = false; + this.mTempGroupBox.Text = "Temperature Sensor"; // - // mSensorComboBox + // mTempComboBox // - this.mSensorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.mSensorComboBox.FormattingEnabled = true; - this.mSensorComboBox.Location = new System.Drawing.Point(7, 21); - this.mSensorComboBox.Name = "mSensorComboBox"; - this.mSensorComboBox.Size = new System.Drawing.Size(195, 20); - this.mSensorComboBox.TabIndex = 1; + this.mTempComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.mTempComboBox.FormattingEnabled = true; + this.mTempComboBox.Location = new System.Drawing.Point(7, 21); + this.mTempComboBox.Name = "mTempComboBox"; + this.mTempComboBox.Size = new System.Drawing.Size(195, 20); + this.mTempComboBox.TabIndex = 1; // // mFanGroupBox // @@ -341,7 +341,7 @@ private void InitializeComponent() this.Controls.Add(this.mOKButton); this.Controls.Add(this.mGraphGroupBox); this.Controls.Add(this.mFanGroupBox); - this.Controls.Add(this.mSensorGroupBox); + this.Controls.Add(this.mTempGroupBox); this.Controls.Add(this.mEnableCheckBox); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MinimizeBox = false; @@ -349,7 +349,7 @@ private void InitializeComponent() this.Name = "ControlForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "FanControl"; - this.mSensorGroupBox.ResumeLayout(false); + this.mTempGroupBox.ResumeLayout(false); this.mFanGroupBox.ResumeLayout(false); this.mGraphGroupBox.ResumeLayout(false); this.mGraphGroupBox.PerformLayout(); @@ -364,8 +364,8 @@ private void InitializeComponent() #endregion private System.Windows.Forms.CheckBox mEnableCheckBox; - private System.Windows.Forms.GroupBox mSensorGroupBox; - private System.Windows.Forms.ComboBox mSensorComboBox; + private System.Windows.Forms.GroupBox mTempGroupBox; + private System.Windows.Forms.ComboBox mTempComboBox; private System.Windows.Forms.GroupBox mFanGroupBox; private System.Windows.Forms.ListView mFanListView; private System.Windows.Forms.ComboBox mFanComboBox; diff --git a/ControlForm.cs b/ControlForm.cs index 3971399..da10f07 100644 --- a/ControlForm.cs +++ b/ControlForm.cs @@ -23,7 +23,7 @@ public partial class ControlForm : Form private bool mIsUpdateGraph = true; private bool mIsResize = false; - private int mSelectedSensorIndex = -1; + private int mSelectedTempIndex = -1; private int mSelectedIndex = -1; private PointPairList mPointList = null; @@ -32,10 +32,12 @@ public partial class ControlForm : Form private PointPairList mNowPoint = null; private LineItem mNowPointLineItem = null; - private int mModeIndex = 0; - private List> mControlDataList = new List>(); + private MODE_TYPE mModeType = MODE_TYPE.NORMAL; + private List[] mControlDataList = new List[4]; private FanData mSelectedFanData = null; + private List mListViewBaseControlList = new List(); + public event EventHandler onApplyCallback; public ControlForm() @@ -43,102 +45,94 @@ public ControlForm() InitializeComponent(); this.localizeComponent(); - mControlDataList.Add(ControlManager.getInstance().getCloneControlDataList(0)); - mControlDataList.Add(ControlManager.getInstance().getCloneControlDataList(1)); - mControlDataList.Add(ControlManager.getInstance().getCloneControlDataList(2)); - mControlDataList.Add(ControlManager.getInstance().getCloneControlDataList(3)); - mModeIndex = ControlManager.getInstance().ModeIndex; + mControlDataList[0] = ControlManager.getInstance().getCloneControlDataList(MODE_TYPE.NORMAL); + mControlDataList[1] = ControlManager.getInstance().getCloneControlDataList(MODE_TYPE.SILENCE); + mControlDataList[2] = ControlManager.getInstance().getCloneControlDataList(MODE_TYPE.PERFORMANCE); + mControlDataList[3] = ControlManager.getInstance().getCloneControlDataList(MODE_TYPE.GAME); + + mModeType = ControlManager.getInstance().ModeType; this.initControl(); this.initGraph(); - // Can only resize windows with Windows 10 - if (System.Environment.OSVersion.Version.Major >= 10) - { - this.SetStyle(ControlStyles.UserPaint | + this.SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor, true); - this.Resize += (sender, e) => - { - if (mIsResize == true) - return; - mIsResize = true; - - //Console.WriteLine("Size : {0}, {1}", this.Width, this.Height); + this.Resize += (sender, e) => + { + if (mIsResize == true) + return; + mIsResize = true; - int widthGap = this.Width - mLastSize.Width; - int heightGap = this.Height - mLastSize.Height; + //Console.WriteLine("Size : {0}, {1}", this.Width, this.Height); - //Console.WriteLine("Gap : {0}, {1}", widthGap, heightGap); + int widthGap = this.Width - mLastSize.Width; + int heightGap = this.Height - mLastSize.Height; - mFanGroupBox.Height = mFanGroupBox.Height + heightGap; - mFanListView.Height = mFanListView.Height + heightGap; - mRemoveButton.Top = mRemoveButton.Top + heightGap; + //Console.WriteLine("Gap : {0}, {1}", widthGap, heightGap); - mModeGroupBox.Width = mModeGroupBox.Width + widthGap; + mFanGroupBox.Height = mFanGroupBox.Height + heightGap; + mFanListView.Height = mFanListView.Height + heightGap; + mRemoveButton.Top = mRemoveButton.Top + heightGap; - mGraphGroupBox.Width = mGraphGroupBox.Width + widthGap; - mGraphGroupBox.Height = mGraphGroupBox.Height + heightGap; + mModeGroupBox.Width = mModeGroupBox.Width + widthGap; - mGraph.Width = mGraph.Width + widthGap; - mGraph.Height = mGraph.Height + heightGap; + mGraphGroupBox.Width = mGraphGroupBox.Width + widthGap; + mGraphGroupBox.Height = mGraphGroupBox.Height + heightGap; - mPresetLabel.Left = mPresetLabel.Left + widthGap; - mPresetLoadButton.Left = mPresetLoadButton.Left + widthGap; - mPresetSaveButton.Left = mPresetSaveButton.Left + widthGap; - mUnitLabel.Left = mUnitLabel.Left + widthGap; - mUnitComboBox.Left = mUnitComboBox.Left + widthGap; - mHysLabel.Left = mHysLabel.Left + widthGap; - mHysNumericUpDown.Left = mHysNumericUpDown.Left + widthGap; - mStepCheckBox.Left = mStepCheckBox.Left + widthGap; + mGraph.Width = mGraph.Width + widthGap; + mGraph.Height = mGraph.Height + heightGap; - mApplyButton.Left = mApplyButton.Left + widthGap; - mApplyButton.Top = mApplyButton.Top + heightGap; + mPresetLabel.Left = mPresetLabel.Left + widthGap; + mPresetLoadButton.Left = mPresetLoadButton.Left + widthGap; + mPresetSaveButton.Left = mPresetSaveButton.Left + widthGap; + mUnitLabel.Left = mUnitLabel.Left + widthGap; + mUnitComboBox.Left = mUnitComboBox.Left + widthGap; + mHysLabel.Left = mHysLabel.Left + widthGap; + mHysNumericUpDown.Left = mHysNumericUpDown.Left + widthGap; + mStepCheckBox.Left = mStepCheckBox.Left + widthGap; - mOKButton.Left = mOKButton.Left + widthGap; - mOKButton.Top = mOKButton.Top + heightGap; + mApplyButton.Left = mApplyButton.Left + widthGap; + mApplyButton.Top = mApplyButton.Top + heightGap; - mLastSize.Width = this.Width; - mLastSize.Height = this.Height; + mOKButton.Left = mOKButton.Left + widthGap; + mOKButton.Top = mOKButton.Top + heightGap; - if (this.WindowState != FormWindowState.Maximized) - { - mNormalLastSize.Width = this.Width; - mNormalLastSize.Height = this.Height; - } - - mIsResize = false; - }; - - this.ResizeBegin += (s, e) => - { - mIsUpdateGraph = false; - this.SuspendLayout(); - }; - this.ResizeEnd += (s, e) => - { - this.ResumeLayout(); - mIsUpdateGraph = true; - }; + mLastSize.Width = this.Width; + mLastSize.Height = this.Height; - if (ControlManager.getInstance().IsMaximize == true) + if (this.WindowState != FormWindowState.Maximized) { - this.WindowState = FormWindowState.Maximized; + mNormalLastSize.Width = this.Width; + mNormalLastSize.Height = this.Height; } - this.Width = ControlManager.getInstance().Width; - this.Height = ControlManager.getInstance().Height; - mLastSize.Width = this.Width; - mLastSize.Height = this.Height; - mNormalLastSize.Width = this.Width; - mNormalLastSize.Height = this.Height; - } - else + mIsResize = false; + }; + + this.ResizeBegin += (s, e) => + { + mIsUpdateGraph = false; + this.SuspendLayout(); + }; + this.ResizeEnd += (s, e) => { - this.MaximizeBox = false; - this.FormBorderStyle = FormBorderStyle.FixedSingle; + this.ResumeLayout(); + mIsUpdateGraph = true; + }; + + if (ControlManager.getInstance().IsMaximize == true) + { + this.WindowState = FormWindowState.Maximized; } + + this.Width = ControlManager.getInstance().Width; + this.Height = ControlManager.getInstance().Height; + mLastSize.Width = this.Width; + mLastSize.Height = this.Height; + mNormalLastSize.Width = this.Width; + mNormalLastSize.Height = this.Height; } private void localizeComponent() @@ -150,7 +144,7 @@ private void localizeComponent() mSilenceRadioButton.Text = StringLib.Silence; mPerformanceRadioButton.Text = StringLib.Performance; mGameRadioButton.Text = StringLib.Game; - mSensorGroupBox.Text = StringLib.Sensor; + mTempGroupBox.Text = StringLib.Target_Temp; mFanGroupBox.Text = StringLib.Fan; mAddButton.Text = StringLib.Add; mRemoveButton.Text = StringLib.Remove; @@ -171,17 +165,17 @@ private void initControl() mEnableCheckBox.Checked = ControlManager.getInstance().IsEnable; - mNormalRadioButton.Checked = (mModeIndex == 0); - mSilenceRadioButton.Checked = (mModeIndex == 1); - mPerformanceRadioButton.Checked = (mModeIndex == 2); - mGameRadioButton.Checked = (mModeIndex == 3); + mNormalRadioButton.Checked = (mModeType == MODE_TYPE.NORMAL); + mSilenceRadioButton.Checked = (mModeType == MODE_TYPE.SILENCE); + mPerformanceRadioButton.Checked = (mModeType == MODE_TYPE.PERFORMANCE); + mGameRadioButton.Checked = (mModeType == MODE_TYPE.GAME); mNormalRadioButton.Click += onRadioButtonClick; mSilenceRadioButton.Click += onRadioButtonClick; mPerformanceRadioButton.Click += onRadioButtonClick; mGameRadioButton.Click += onRadioButtonClick; - mSensorComboBox.SelectedIndexChanged += onSensorComboBoxIndexChanged; + mTempComboBox.SelectedIndexChanged += onTempComboBoxIndexChanged; mFanListView.Columns.Add("MyColumn", -2, HorizontalAlignment.Center); mFanListView.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent); @@ -196,20 +190,23 @@ private void initControl() mHysNumericUpDown.ValueChanged += onHysNumericValueChanged; - for (int i = 0; i < controlManager.getNameCount(0); i++) + var tempBaseList = HardwareManager.getInstance().TempBaseList; + var controlBaseList = HardwareManager.getInstance().ControlBaseList; + + for (int i = 0; i < tempBaseList.Count; i++) { - mSensorComboBox.Items.Add(controlManager.getName(0, i, false)); + mTempComboBox.Items.Add(tempBaseList[i].Name); } - for (int i = 0; i < controlManager.getNameCount(2); i++) + for (int i = 0; i < controlBaseList.Count; i++) { - mFanComboBox.Items.Add(controlManager.getName(2, i, false)); + mFanComboBox.Items.Add(controlBaseList[i].Name); } - if (mSensorComboBox.Items.Count > 0) + if (mTempComboBox.Items.Count > 0) { - mSensorComboBox.SelectedIndex = 0; - mSelectedSensorIndex = 0; + mTempComboBox.SelectedIndex = 0; + mSelectedTempIndex = 0; } if (mFanComboBox.Items.Count > 0) @@ -321,25 +318,29 @@ private void setGraphFromSelectedFanData() private void onRadioButtonClick(object sender, EventArgs e) { - int index = -1; - if(sender == mNormalRadioButton) index = 0; - else if (sender == mSilenceRadioButton) index = 1; - else if (sender == mPerformanceRadioButton) index = 2; - else index = 3; - if (index == mModeIndex) + MODE_TYPE modeType = MODE_TYPE.NORMAL; + if(sender == mNormalRadioButton) + modeType = MODE_TYPE.NORMAL; + else if (sender == mSilenceRadioButton) + modeType = MODE_TYPE.SILENCE; + else if (sender == mPerformanceRadioButton) + modeType = MODE_TYPE.PERFORMANCE; + else + modeType = MODE_TYPE.GAME; + if (modeType == mModeType) return; - mModeIndex = index; + mModeType = modeType; - mNormalRadioButton.Checked = (mModeIndex == 0); - mSilenceRadioButton.Checked = (mModeIndex == 1); - mPerformanceRadioButton.Checked = (mModeIndex == 2); - mGameRadioButton.Checked = (mModeIndex == 3); + mNormalRadioButton.Checked = (mModeType == MODE_TYPE.NORMAL); + mSilenceRadioButton.Checked = (mModeType == MODE_TYPE.SILENCE); + mPerformanceRadioButton.Checked = (mModeType == MODE_TYPE.PERFORMANCE); + mGameRadioButton.Checked = (mModeType == MODE_TYPE.GAME); - this.onSensorComboBoxIndexChanged(null, EventArgs.Empty); + this.onTempComboBoxIndexChanged(null, EventArgs.Empty); } - private void onSensorComboBoxIndexChanged(object sender, EventArgs e) + private void onTempComboBoxIndexChanged(object sender, EventArgs e) { mPresetLabel.Visible = false; mPresetLoadButton.Visible = false; @@ -352,21 +353,32 @@ private void onSensorComboBoxIndexChanged(object sender, EventArgs e) mHysNumericUpDown.Visible = false; mSelectedFanData = null; + mListViewBaseControlList.Clear(); mFanListView.BeginUpdate(); mFanListView.Clear(); - mSelectedSensorIndex = mSensorComboBox.SelectedIndex; - var controlData = this.getControlData(mSelectedSensorIndex); + mSelectedTempIndex = mTempComboBox.SelectedIndex; + var controlData = this.getControlData(mSelectedTempIndex); if(controlData == null) { mFanListView.EndUpdate(); return; } + var controlBaseMap = HardwareManager.getInstance().ControlBaseMap; for (int i = 0; i < controlData.FanDataList.Count; i++) { var fanData = controlData.FanDataList[i]; - mFanListView.Items.Add(fanData.Name); + + string fanID = fanData.ID; + if (controlBaseMap.ContainsKey(fanID) == false) + { + continue; + } + + var device = controlBaseMap[fanID]; + mListViewBaseControlList.Add(device); + mFanListView.Items.Add(device.Name); } mFanListView.EndUpdate(); } @@ -439,7 +451,7 @@ private void setPoint(double y) if (mSelectedFanData != null) { mSelectedFanData.ValueList[mSelectedIndex] = (int)y; - } + } for (int i = 0; i < mSelectedIndex; i++) { @@ -468,8 +480,8 @@ private void setPoint(double y) public void onUpdateTimer() { - if (mSensorComboBox.Items.Count == 0 || - mSelectedSensorIndex == -1 || + if (mTempComboBox.Items.Count == 0 || + mSelectedTempIndex == -1 || mFanComboBox.Items.Count == 0 || mSelectedFanData == null || mNowPoint == null || @@ -478,24 +490,42 @@ public void onUpdateTimer() return; } + var items = mFanListView.SelectedItems; + if (items == null || items.Count == 0) + return; + + int itemIndex = items[0].Index; var hardwareManager = HardwareManager.getInstance(); - var sensor = hardwareManager.getSensor(mSelectedSensorIndex); - var control = hardwareManager.getControl(mSelectedFanData.Index); - if (sensor == null || control == null) + var tempBaseList = hardwareManager.TempBaseList; + var controlBaseList = hardwareManager.ControlBaseList; + + if (mSelectedTempIndex >= tempBaseList.Count || itemIndex >= mListViewBaseControlList.Count) + return; + + var tempDevice = tempBaseList[mSelectedTempIndex]; + var controlDevice = mListViewBaseControlList[itemIndex]; + if (tempDevice == null || controlDevice == null) return; - mNowPoint[0].X = (double)sensor.Value; - mNowPoint[0].Y = (double)control.LastValue; + mNowPoint[0].X = (double)tempDevice.Value; + mNowPoint[0].Y = (double)controlDevice.LastValue; mGraph.Refresh(); } - private ControlData getControlData(int sensorIndex) + private ControlData getControlData(int tempIndex) { + var tempBaseList = HardwareManager.getInstance().TempBaseList; + if (tempIndex >= tempBaseList.Count) + return null; + + string id = tempBaseList[tempIndex].ID; + ControlData controlData = null; - for (int i = 0; i < mControlDataList[mModeIndex].Count; i++) + int modeIndex = (int)mModeType; + for (int i = 0; i < mControlDataList[modeIndex].Count; i++) { - var tempControlData = mControlDataList[mModeIndex][i]; - if (tempControlData.Index == sensorIndex) + var tempControlData = mControlDataList[modeIndex][i]; + if (tempControlData.ID.Equals(id) == true) { controlData = tempControlData; break; @@ -504,17 +534,21 @@ private ControlData getControlData(int sensorIndex) return controlData; } - private FanData getFanData(int sensorIndex, int fanIndex) + private FanData getFanData(int tempIndex, int fanIndex) { - var controlData = this.getControlData(sensorIndex); + var controlData = this.getControlData(tempIndex); if (controlData == null) return null; + if (fanIndex >= mListViewBaseControlList.Count) + return null; + + var device = mListViewBaseControlList[fanIndex]; FanData fanData = null; for (int i = 0; i < controlData.FanDataList.Count; i++) { var tempFanData = controlData.FanDataList[i]; - if (tempFanData.Index == fanIndex) + if (tempFanData.ID.Equals(device.ID) == true) { fanData = tempFanData; break; @@ -523,9 +557,9 @@ private FanData getFanData(int sensorIndex, int fanIndex) return fanData; } - private FanData getFanData(int sensorIndex, string fanName) + private FanData getFanData(int tempIndex, string id) { - var controlData = this.getControlData(sensorIndex); + var controlData = this.getControlData(tempIndex); if (controlData == null) return null; @@ -533,7 +567,7 @@ private FanData getFanData(int sensorIndex, string fanName) for (int i = 0; i < controlData.FanDataList.Count; i++) { var tempFanData = controlData.FanDataList[i]; - if (tempFanData.Name.Equals(fanName) == true) + if (tempFanData.ID.Equals(id) == true) { fanData = tempFanData; break; @@ -571,7 +605,10 @@ private void onFanListViewIndexChanged(object sender, EventArgs e) mHysNumericUpDown.Visible = true; var item = items[0]; - mSelectedFanData = this.getFanData(mSelectedSensorIndex, item.Text); + int itemIndex = item.Index; + mSelectedFanData = this.getFanData(mSelectedTempIndex, itemIndex); + if (mSelectedFanData == null) + return; // setGraphFromSelectedFanData this.setGraphFromSelectedFanData(); @@ -607,32 +644,39 @@ private void onHysNumericValueChanged(object sender, EventArgs e) private void onAddButtonClick(object sender, EventArgs e) { - if (mSensorComboBox.Items.Count == 0 || mFanComboBox.Items.Count == 0) + if (mTempComboBox.Items.Count == 0 || mFanComboBox.Items.Count == 0) return; - int sensorIndex = mSelectedSensorIndex; + int modeIndex = (int)mModeType; + int tempIndex = mSelectedTempIndex; int fanIndex = mFanComboBox.SelectedIndex; - var controlManager = ControlManager.getInstance(); - var sensorName = controlManager.getName(0, sensorIndex, false); - var fanControlName = controlManager.getName(2, fanIndex, false); + var tempBaseList = HardwareManager.getInstance().TempBaseList; + var controlBaseList = HardwareManager.getInstance().ControlBaseList; + + if (tempIndex >= tempBaseList.Count || fanIndex >= controlBaseList.Count) + return; - var controlData = this.getControlData(sensorIndex); + var tempDevice = tempBaseList[tempIndex]; + var controlDevice = controlBaseList[fanIndex]; + + var controlData = this.getControlData(tempIndex); if(controlData == null) { - controlData = new ControlData(sensorIndex, sensorName); - mControlDataList[mModeIndex].Add(controlData); + controlData = new ControlData(tempDevice.ID); + mControlDataList[modeIndex].Add(controlData); } mFanListView.BeginUpdate(); - var fanData = this.getFanData(sensorIndex, fanIndex); + var fanData = this.getFanData(tempIndex, controlDevice.ID); if(fanData == null) { - fanData = new FanData(fanIndex, fanControlName, FanValueUnit.Size_5, true, 0); + fanData = new FanData(controlDevice.ID, FanValueUnit.Size_5, true, 0); controlData.FanDataList.Add(fanData); - mFanListView.Items.Add(fanData.Name); + mListViewBaseControlList.Add(controlDevice); + mFanListView.Items.Add(controlDevice.Name); } mFanListView.EndUpdate(); @@ -645,16 +689,13 @@ private void onRemoveButtonClick(object sender, EventArgs e) return; var item = items[0]; - var controlData = this.getControlData(mSelectedSensorIndex); - for(int i = 0; i < controlData.FanDataList.Count; i++) - { - var fanData = controlData.FanDataList[i]; - if(fanData.Name.Equals(item.Text) == true) - { - controlData.FanDataList.RemoveAt(i); - break; - } - } + int itemIndex = item.Index; + var controlData = this.getControlData(mSelectedTempIndex); + if (controlData == null) + return; + + mListViewBaseControlList.RemoveAt(itemIndex); + controlData.FanDataList.RemoveAt(itemIndex); mSelectedFanData = null; mFanListView.BeginUpdate(); @@ -779,7 +820,7 @@ private void onPresetSaveButtonClick(object sender, EventArgs e) private void onApplyButtonClick(object sender, EventArgs e) { - for (int i = 0; i < mControlDataList.Count; i++) + for (int i = 0; i < mControlDataList.Length; i++) { for (int j = 0; j < mControlDataList[i].Count; j++) { @@ -789,14 +830,14 @@ private void onApplyButtonClick(object sender, EventArgs e) mControlDataList[i][j].FanDataList[k].LastChangedValue = 0; } } - ControlManager.getInstance().setControlDataList(i, mControlDataList[i]); + ControlManager.getInstance().setControlDataList((MODE_TYPE)i, mControlDataList[i]); } ControlManager.getInstance().Width = mNormalLastSize.Width; ControlManager.getInstance().Height = mNormalLastSize.Height; ControlManager.getInstance().IsMaximize = (this.WindowState == FormWindowState.Maximized); - ControlManager.getInstance().ModeIndex = mModeIndex; + ControlManager.getInstance().ModeType = mModeType; ControlManager.getInstance().IsEnable = mEnableCheckBox.Checked; ControlManager.getInstance().write(); diff --git a/FanCtrl.csproj b/FanCtrl.csproj index 6292ae8..fcbb961 100644 --- a/FanCtrl.csproj +++ b/FanCtrl.csproj @@ -28,7 +28,7 @@ Lich FanCtrl 0 - 1.2.9.0 + 1.3.0.0 false true true @@ -44,7 +44,7 @@ prompt 4 false - false + true AnyCPU @@ -182,16 +182,27 @@ - + + + + + + + + + + + + @@ -205,20 +216,17 @@ - - - - + diff --git a/FanCtrl/Controller/HidUSBController.cs b/FanCtrl/Controller/HidUSBController.cs index b58de0f..0bdda8c 100644 --- a/FanCtrl/Controller/HidUSBController.cs +++ b/FanCtrl/Controller/HidUSBController.cs @@ -20,6 +20,7 @@ public class HidUSBController : USBController private delegate void RecvDelegate(); private delegate void SendDelegate(); + private uint mIndex = 0; private bool mIsSend = false; private List mSendArrayList = new List(); private object mSendArrayListLock = new object(); @@ -33,7 +34,7 @@ public static uint getDeviceCount(USBVendorID vendorID, USBProductID productID) { uint count = 0; try - { + { int venderID2 = (int)vendorID; int productID2 = (int)productID; foreach (HidDevice dev in DeviceList.Local.GetHidDevices(venderID2)) @@ -42,7 +43,7 @@ public static uint getDeviceCount(USBVendorID vendorID, USBProductID productID) { count++; } - } + } } catch { } return count; @@ -52,6 +53,7 @@ public override bool start(uint index) { try { + mIndex = index; uint i = 0; int venderID = (int)this.VendorID; int productID = (int)this.ProductID; @@ -112,7 +114,7 @@ public override void send(byte[] buffer) { this.writeAsync(); } - Monitor.Exit(mSendArrayListLock); + Monitor.Exit(mSendArrayListLock); } public override void send(List bufferList) @@ -169,10 +171,18 @@ private void write() } } } - catch { } + catch + { + mSendArrayList.Clear(); + mIsSend = false; + Monitor.Exit(mSendArrayListLock); + this.stop(); + this.start(mIndex); + return; + } mSendArrayList.Clear(); mIsSend = false; Monitor.Exit(mSendArrayListLock); } } -} +} \ No newline at end of file diff --git a/FanCtrl/Data/Control/ControlData.cs b/FanCtrl/Data/Control/ControlData.cs index 63b6bd8..b546c40 100644 --- a/FanCtrl/Data/Control/ControlData.cs +++ b/FanCtrl/Data/Control/ControlData.cs @@ -8,24 +8,21 @@ namespace FanCtrl { public class ControlData { - public int Index { get; set; } - - public string Name { get; set; } + public string ID { get; set; } private List mFanDataList = new List(); public List FanDataList { get { return mFanDataList; } } - public ControlData(int index, string name) + public ControlData(string id) { - Index = index; - Name = name; + ID = id; } public ControlData clone() { - var controlData = new ControlData(Index, Name); + var controlData = new ControlData(ID); for (int i = 0; i < mFanDataList.Count; i++) controlData.FanDataList.Add(mFanDataList[i].clone()); return controlData; diff --git a/FanCtrl/Data/Control/ControlManager.cs b/FanCtrl/Data/Control/ControlManager.cs index 14496f1..e2a2953 100644 --- a/FanCtrl/Data/Control/ControlManager.cs +++ b/FanCtrl/Data/Control/ControlManager.cs @@ -12,9 +12,24 @@ namespace FanCtrl { + public enum NAME_TYPE + { + TEMPERATURE, + FAN, + CONTOL, + } + + public enum MODE_TYPE + { + NORMAL, + SILENCE, + PERFORMANCE, + GAME, + } + public class ControlManager { - private string mControlFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "Control.json"; + public string mControlFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "Control.json"; private static ControlManager sManager = new ControlManager(); public static ControlManager getInstance() { return sManager; } @@ -93,257 +108,85 @@ public bool IsEnable } } - private int mModeIndex = 0; - public int ModeIndex + private MODE_TYPE mModeType = MODE_TYPE.NORMAL; + public MODE_TYPE ModeType { get { Monitor.Enter(mLock); - int index = mModeIndex; + MODE_TYPE type = mModeType; Monitor.Exit(mLock); - return index; + return type; } set { Monitor.Enter(mLock); - mModeIndex = value; + mModeType = value; Monitor.Exit(mLock); } } private List[] mControlDataList = new List[4]; - private List mSensorNameList = new List(); - private List mFanNameList = new List(); - private List mFanControlNameList = new List(); - - private List mOriginSensorNameList = new List(); - private List mOriginFanNameList = new List(); - private List mOriginFanControlNameList = new List(); - private ControlManager() { - mControlDataList[0] = new List(); - mControlDataList[1] = new List(); - mControlDataList[2] = new List(); - mControlDataList[3] = new List(); + mControlDataList[0] = (new List()); + mControlDataList[1] = (new List()); + mControlDataList[2] = (new List()); + mControlDataList[3] = (new List()); } private void clear() { mIsEnable = false; for (int i = 0; i < mControlDataList.Length; i++) + { mControlDataList[i].Clear(); - - mModeIndex = 0; - - for (int i = 0; i < mSensorNameList.Count; i++) - mSensorNameList[i] = mOriginSensorNameList[i]; - - for (int i = 0; i < mFanNameList.Count; i++) - mFanNameList[i] = mOriginFanNameList[i]; - - for (int i = 0; i < mFanControlNameList.Count; i++) - mFanControlNameList[i] = mOriginFanControlNameList[i]; + } + mModeType = MODE_TYPE.NORMAL; } public void reset() { Monitor.Enter(mLock); - mIsEnable = false; - for (int i = 0; i < mControlDataList.Length; i++) - mControlDataList[i].Clear(); - - mModeIndex = 0; - mSensorNameList.Clear(); - mFanNameList.Clear(); - mFanControlNameList.Clear(); - + this.clear(); Monitor.Exit(mLock); } - public void setNameCount(int type, int count) + public List getControlDataList(MODE_TYPE modeType) { Monitor.Enter(mLock); - List nameList = null; - List nameList2 = null; - if (type == 0) - { - nameList = mSensorNameList; - nameList2 = mOriginSensorNameList; - } - else if (type == 1) - { - nameList = mFanNameList; - nameList2 = mOriginFanNameList; - } - else - { - nameList = mFanControlNameList; - nameList2 = mOriginFanControlNameList; - } - - nameList.Clear(); - nameList2.Clear(); - for (int i = 0; i < count; i++) - { - nameList.Add(""); - nameList2.Add(""); - } - Monitor.Exit(mLock); - } - - public int getNameCount(int type) - { - Monitor.Enter(mLock); - List nameList = null; - if (type == 0) nameList = mSensorNameList; - else if (type == 1) nameList = mFanNameList; - else nameList = mFanControlNameList; - - int count = nameList.Count; - Monitor.Exit(mLock); - return count; - } - - public string getName(int type, int index, bool isOrigin) - { - Monitor.Enter(mLock); - List nameList = null; - if (type == 0) - { - nameList = (isOrigin == true) ? mOriginSensorNameList : mSensorNameList; - } - else if (type == 1) - { - nameList = (isOrigin == true) ? mOriginFanNameList : mFanNameList; - } - else - { - nameList = (isOrigin == true) ? mOriginFanControlNameList : mFanControlNameList; - } - - if (index >= nameList.Count) - { - Monitor.Exit(mLock); - return ""; - } - var valueString = nameList[index]; - Monitor.Exit(mLock); - return valueString; - } - - public void setName(int type, int index, bool isOrigin, string nameString) - { - Monitor.Enter(mLock); - List nameList = null; - if (type == 0) - { - nameList = (isOrigin == true) ? mOriginSensorNameList : mSensorNameList; - } - else if (type == 1) - { - nameList = (isOrigin == true) ? mOriginFanNameList : mFanNameList; - } - else - { - nameList = (isOrigin == true) ? mOriginFanControlNameList : mFanControlNameList; - } - - if (index >= nameList.Count) - { - Monitor.Exit(mLock); - return; - } - nameList[index] = nameString; - - if (isOrigin == false) - { - // sensor - if(type == 0) - { - for (int i = 0; i < mControlDataList.Length; i++) - { - for (int j = 0; j < mControlDataList[i].Count; j++) - { - var controlData = mControlDataList[i][j]; - if (controlData.Index == index) - { - controlData.Name = nameString; - break; - } - } - } - } - - // control - else if(type == 2) - { - for (int i = 0; i < mControlDataList.Length; i++) - { - for (int j = 0; j < mControlDataList[i].Count; j++) - { - var controlData = mControlDataList[i][j]; - for(int k = 0; k < controlData.FanDataList.Count; k++) - { - var fanData = controlData.FanDataList[k]; - if(fanData.Index == index) - { - fanData.Name = nameString; - break; - } - } - } - } - } - } - + int modeIndex = (int)modeType; + var controlDataList = mControlDataList[modeIndex]; Monitor.Exit(mLock); + return controlDataList; } - public void setControlDataList(int modeIndex, List controlData) + public void setControlDataList(MODE_TYPE modeType, List controlDataList) { Monitor.Enter(mLock); + int modeIndex = (int)modeType; var selectedControlDataList = mControlDataList[modeIndex]; selectedControlDataList.Clear(); - for (int i = 0; i < controlData.Count; i++) - selectedControlDataList.Add(controlData[i].clone()); + for (int i = 0; i < controlDataList.Count; i++) + { + selectedControlDataList.Add(controlDataList[i].clone()); + } Monitor.Exit(mLock); } - public List getCloneControlDataList(int modeIndex) + public List getCloneControlDataList(MODE_TYPE modeType) { Monitor.Enter(mLock); + int modeIndex = (int)modeType; var selectedControlDataList = mControlDataList[modeIndex]; var controlDataList = new List(); for (int i = 0; i < selectedControlDataList.Count; i++) - controlDataList.Add(selectedControlDataList[i].clone()); - Monitor.Exit(mLock); - return controlDataList; - } - - public int getControlDataCount(int modeIndex) - { - Monitor.Enter(mLock); - var selectedControlDataList = mControlDataList[modeIndex]; - int count = selectedControlDataList.Count; - Monitor.Exit(mLock); - return count; - } - - public ControlData getControlData(int modeIndex, int index) - { - Monitor.Enter(mLock); - var selectedControlDataList = mControlDataList[modeIndex]; - if (index >= selectedControlDataList.Count) { - Monitor.Exit(mLock); - return null; + controlDataList.Add(selectedControlDataList[i].clone()); } - - var controlData = selectedControlDataList[index]; Monitor.Exit(mLock); - return controlData; + return controlDataList; } public bool read() @@ -351,9 +194,11 @@ public bool read() Monitor.Enter(mLock); for (int i = 0; i < mControlDataList.Length; i++) + { mControlDataList[i].Clear(); + } - String jsonString; + string jsonString; try { jsonString = File.ReadAllText(mControlFileName); @@ -377,58 +222,20 @@ public bool read() if (rootObject.ContainsKey("modeIndex") == false) { - mModeIndex = 0; + mModeType = MODE_TYPE.NORMAL; } else { - mModeIndex = rootObject.Value("modeIndex"); - if (mModeIndex < 0 || mModeIndex > 3) - mModeIndex = 0; + int modeIndex = rootObject.Value("modeIndex"); + if (modeIndex < 0 || modeIndex > 3) + modeIndex = 0; + mModeType = (MODE_TYPE)modeIndex; } - // name - if (rootObject.ContainsKey("name") == true) - { - var nameObject = rootObject.Value("name"); - - // sensor name - if (nameObject.ContainsKey("sensor") == true) - { - var sensorList = nameObject.Value("sensor"); - for(int i = 0; i (); - mSensorNameList[i] = nameString; - } - } - - // fan name - if (nameObject.ContainsKey("fan") == true) - { - var fanList = nameObject.Value("fan"); - for (int i = 0; i < fanList.Count; i++) - { - var nameString = fanList[i].Value(); - mFanNameList[i] = nameString; - } - } - - // fan control name - if (nameObject.ContainsKey("control") == true) - { - var controlList = nameObject.Value("control"); - for (int i = 0; i < controlList.Count; i++) - { - var nameString = controlList[i].Value(); - mFanControlNameList[i] = nameString; - } - } - } - - this.readData(rootObject, "control", ref mControlDataList[0]); - this.readData(rootObject, "silence", ref mControlDataList[1]); - this.readData(rootObject, "performance", ref mControlDataList[2]); - this.readData(rootObject, "game", ref mControlDataList[3]); + this.readData(rootObject, "control", mControlDataList[0]); + this.readData(rootObject, "silence", mControlDataList[1]); + this.readData(rootObject, "performance", mControlDataList[2]); + this.readData(rootObject, "game", mControlDataList[3]); } catch { @@ -440,46 +247,56 @@ public bool read() return true; } - private void readData(JObject rootObject, string keyString, ref List controlDataList) + private void readData(JObject rootObject, string keyString, List controlDataList) { if (rootObject.ContainsKey(keyString) == false) return; + var tempBaseMap = HardwareManager.getInstance().TempBaseMap; + var controlBaseMap = HardwareManager.getInstance().ControlBaseMap; + var controlList = rootObject.Value(keyString); for (int i = 0; i < controlList.Count; i++) { var controlObject = (JObject)controlList[i]; - - if (controlObject.ContainsKey("index") == false || - controlObject.ContainsKey("name") == false) + if (controlObject.ContainsKey("id") == false) { continue; } - int sensorIndex = controlObject.Value("index"); - string sensorName = controlObject.Value("name"); + string id = controlObject.Value("id"); + + // check temperature sensor + if (tempBaseMap.ContainsKey(id) == false) + { + continue; + } - var controlData = new ControlData(sensorIndex, sensorName); + var controlData = new ControlData(id); // FanData var fanList = controlObject.Value("fan"); for (int j = 0; j < fanList.Count; j++) { var fanObject = (JObject)fanList[j]; + if (fanObject.ContainsKey("id") == false) + { + continue; + } - if (fanObject.ContainsKey("index") == false || - fanObject.ContainsKey("name") == false) + string fanID = fanObject.Value("id"); + + // check control sensor + if (controlBaseMap.ContainsKey(fanID) == false) { continue; } - int fanIndex = fanObject.Value("index"); - string fanName = fanObject.Value("name"); bool isStep = (fanObject.ContainsKey("step") == true) ? fanObject.Value("step") : true; int hysteresis = (fanObject.ContainsKey("hysteresis") == true) ? fanObject.Value("hysteresis") : 0; int unit = (fanObject.ContainsKey("unit") == true) ? fanObject.Value("unit") : 1; - var fanData = new FanData(fanIndex, fanName, (FanValueUnit)unit, isStep, hysteresis); + var fanData = new FanData(fanID, (FanValueUnit)unit, isStep, hysteresis); // Percent value var valueList = fanObject.Value("value"); @@ -514,41 +331,12 @@ public void write() rootObject["height"] = mHeight; rootObject["maximize"] = mIsMaximize; rootObject["enable"] = mIsEnable; - rootObject["modeIndex"] = mModeIndex; + rootObject["modeIndex"] = (int)mModeType; - // name - var nameObject = new JObject(); - - // sensor name - var sensorList = new JArray(); - for(int i = 0; i < mSensorNameList.Count; i++) - { - sensorList.Add(mSensorNameList[i]); - } - nameObject["sensor"] = sensorList; - - // fan name - var fanList = new JArray(); - for (int i = 0; i < mFanNameList.Count; i++) - { - fanList.Add(mFanNameList[i]); - } - nameObject["fan"] = fanList; - - // fan control name - var fanControlList = new JArray(); - for (int i = 0; i < mFanControlNameList.Count; i++) - { - fanControlList.Add(mFanControlNameList[i]); - } - nameObject["control"] = fanControlList; - - rootObject["name"] = nameObject; - - this.writeData(rootObject, "control", ref mControlDataList[0]); - this.writeData(rootObject, "silence", ref mControlDataList[1]); - this.writeData(rootObject, "performance", ref mControlDataList[2]); - this.writeData(rootObject, "game", ref mControlDataList[3]); + this.writeData(rootObject, "control", mControlDataList[0]); + this.writeData(rootObject, "silence", mControlDataList[1]); + this.writeData(rootObject, "performance", mControlDataList[2]); + this.writeData(rootObject, "game", mControlDataList[3]); File.WriteAllText(mControlFileName, rootObject.ToString()); } @@ -559,7 +347,7 @@ public void write() Monitor.Exit(mLock); } - private void writeData(JObject rootObject, string keyString, ref List controlDataList) + private void writeData(JObject rootObject, string keyString, List controlDataList) { var controlList = new JArray(); for (int i = 0; i < controlDataList.Count; i++) @@ -569,17 +357,15 @@ private void writeData(JObject rootObject, string keyString, ref List controlDataList) - { - for (int i = 0; i < controlDataList.Count; i++) - { - var controlData = controlDataList[i]; - string sensorName = mSensorNameList[controlData.Index]; - if (controlData.Name.Equals(sensorName) == false) - { - return false; - } - - var fanDataList = controlData.FanDataList; - for (int j = 0; j < fanDataList.Count; j++) - { - var fanData = fanDataList[j]; - string fanControlName = mFanControlNameList[fanData.Index]; - if (fanData.Name.Equals(fanControlName) == false) - { - return false; - } - } - } - return true; - } } } diff --git a/FanCtrl/Data/Control/FanData.cs b/FanCtrl/Data/Control/FanData.cs index 2ead97e..27854cc 100644 --- a/FanCtrl/Data/Control/FanData.cs +++ b/FanCtrl/Data/Control/FanData.cs @@ -20,9 +20,7 @@ public class FanData public const int MAX_FAN_VALUE_SIZE_5 = 21; public const int MAX_FAN_VALUE_SIZE_10 = 11; - public int Index { get; set; } - - public string Name { get; set; } + public string ID { get; set; } public FanValueUnit Unit { get; set; } @@ -39,10 +37,9 @@ public int[] ValueList public int LastChangedValue { get; set; } public int LastChangedTemp { get; set; } - public FanData(int index, string name, FanValueUnit unit, bool isStep, int hysteresis) + public FanData(string id, FanValueUnit unit, bool isStep, int hysteresis) { - Index = index; - Name = name; + ID = id; IsStep = isStep; Hysteresis = hysteresis; Unit = unit; @@ -55,7 +52,7 @@ public FanData(int index, string name, FanValueUnit unit, bool isStep, int hyste public FanData clone() { - var fanData = new FanData(Index, Name, Unit, IsStep, Hysteresis); + var fanData = new FanData(ID, Unit, IsStep, Hysteresis); for (int i = 0; i < this.getMaxFanValue(); i++) { fanData.ValueList[i] = mValueList[i]; diff --git a/FanCtrl/Data/OSD/OSDItem.cs b/FanCtrl/Data/OSD/OSDItem.cs index e50b0f9..52ab5d6 100644 --- a/FanCtrl/Data/OSD/OSDItem.cs +++ b/FanCtrl/Data/OSD/OSDItem.cs @@ -7,40 +7,11 @@ namespace FanCtrl { - public enum OSDItemType : int - { - Sensor = 0, - Fan, - Control, - Predefined, - Unknown, - } - - public enum OSDUnitType : int - { - Temperature = 0, - RPM, - Percent, - MHz, - kHz, - KB, - MB, - GB, - MBPerSec, - Voltage, - Power, - FPS, - Blank, - Unknown, - } - public class OSDItem { - public OSDItemType ItemType { get; set; } - public OSDUnitType UnitType { get; set; } - public int Index { get; set; } = 0; + public string ID { get; set; } public bool IsColor { get; set; } = false; @@ -71,52 +42,54 @@ public string getOSDString(int digit) // Value var hardwareManager = HardwareManager.getInstance(); - if (ItemType == OSDItemType.Sensor) + + if (UnitType == OSDUnitType.FPS) { - var sensor = hardwareManager.getSensor(Index); - if (sensor == null) - return ""; - int value = sensor.Value; - value = (OptionManager.getInstance().IsFahrenheit == true) ? Util.getFahrenheit(value) : value; - osdString.Append(value.ToString()); + osdString.Append(""); } - else if (ItemType == OSDItemType.Fan) + else if (UnitType == OSDUnitType.Blank) { - var fan = hardwareManager.getFan(Index); - if (fan == null) - return ""; - int value = fan.Value; - osdString.Append(value.ToString()); + osdString.Append(" "); } - else if (ItemType == OSDItemType.Control) - { - var control = hardwareManager.getControl(Index); - if (control == null) - return ""; - int value = control.Value; - osdString.Append(value.ToString()); - } - else if (ItemType == OSDItemType.Predefined) + else { - if(UnitType == OSDUnitType.FPS) + var tempBaseMap = hardwareManager.TempBaseMap; + var fanBaseMap = hardwareManager.FanBaseMap; + var controlBaseMap = hardwareManager.ControlBaseMap; + var osdMap = hardwareManager.OSDSensorMap; + + if (tempBaseMap.ContainsKey(ID) == true) { - osdString.Append(""); + var device = tempBaseMap[ID]; + int value = device.Value; + value = (OptionManager.getInstance().IsFahrenheit == true) ? Util.getFahrenheit(value) : value; + osdString.Append(value.ToString()); } - else if(UnitType == OSDUnitType.Blank) + + else if (fanBaseMap.ContainsKey(ID) == true) { - osdString.Append(" "); + var device = fanBaseMap[ID]; + int value = device.Value; + osdString.Append(value.ToString()); } - else + + else if (controlBaseMap.ContainsKey(ID) == true) { - var sensor = hardwareManager.getOSDSensor(Index); - if (sensor == null) - return ""; + var device = controlBaseMap[ID]; + int value = device.Value; + osdString.Append(value.ToString()); + } + + else if (osdMap.ContainsKey(ID) == true) + { + var sensor = osdMap[ID]; osdString.Append(sensor.getString()); } - } - else - { - return ""; + + else + { + return ""; + } } // Value postfix @@ -146,9 +119,8 @@ public string getOSDString(int digit) public OSDItem clone() { var item = new OSDItem(); - item.ItemType = this.ItemType; item.UnitType = this.UnitType; - item.Index = this.Index; + item.ID = this.ID; item.IsColor = this.IsColor; item.Color = Color.FromArgb(this.Color.R, this.Color.G, this.Color.B); return item; diff --git a/FanCtrl/Data/OSD/OSDManager.cs b/FanCtrl/Data/OSD/OSDManager.cs index 74571fb..c1513fd 100644 --- a/FanCtrl/Data/OSD/OSDManager.cs +++ b/FanCtrl/Data/OSD/OSDManager.cs @@ -15,7 +15,7 @@ namespace FanCtrl { public class OSDManager { - private string mOSDFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "OSD.json"; + public string mOSDFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "OSD.json"; private static OSDManager sManager = new OSDManager(); public static OSDManager getInstance() { return sManager; } @@ -86,6 +86,7 @@ private OSDManager() private void clear() { mIsEnable = false; + mIsTime = false; mGroupList.Clear(); } @@ -114,14 +115,16 @@ public void read() try { + var osdMap = HardwareManager.getInstance().OSDSensorMap; + var rootObject = JObject.Parse(jsonString); - mIsEnable = (rootObject.ContainsKey("enable") == true) ? rootObject.Value("enable") : false; - mIsTime = (rootObject.ContainsKey("time") == true) ? rootObject.Value("time") : false; + mIsEnable = (rootObject.ContainsKey("IsEnable") == true) ? rootObject.Value("IsEnable") : false; + mIsTime = (rootObject.ContainsKey("IsTime") == true) ? rootObject.Value("IsTime") : false; - if (rootObject.ContainsKey("group") == true) + if (rootObject.ContainsKey("Group") == true) { - var groupList = rootObject.Value("group"); + var groupList = rootObject.Value("Group"); for(int i = 0; i < groupList.Count; i++) { var groupObject = (JObject)groupList[i]; @@ -146,21 +149,22 @@ public void read() { var itemObject = (JObject)itemList[j]; - var itemType = (itemObject.ContainsKey("itemType") == false) ? (int)OSDItemType.Unknown : itemObject.Value("itemType"); var unitType = (itemObject.ContainsKey("unitType") == false) ? (int)OSDUnitType.Unknown : itemObject.Value("unitType"); - int index = (itemObject.ContainsKey("index") == false) ? 0 : itemObject.Value("index"); + string id = (itemObject.ContainsKey("id") == false) ? "" : itemObject.Value("id"); isColor = (itemObject.ContainsKey("isColor") == false) ? false : itemObject.Value("isColor"); r = (itemObject.ContainsKey("r") == false) ? (byte)0xFF : itemObject.Value("r"); g = (itemObject.ContainsKey("g") == false) ? (byte)0xFF : itemObject.Value("g"); b = (itemObject.ContainsKey("b") == false) ? (byte)0xFF : itemObject.Value("b"); - if (itemType >= (int)OSDItemType.Unknown || unitType >= (int)OSDUnitType.Unknown) + if (unitType >= (int)OSDUnitType.Unknown || id.Length == 0) + continue; + + if (osdMap.ContainsKey(id) == false) continue; var item = new OSDItem(); - item.ItemType = (OSDItemType)itemType; item.UnitType = (OSDUnitType)unitType; - item.Index = index; + item.ID = id; item.IsColor = isColor; item.Color = Color.FromArgb(r, g, b); group.ItemList.Add(item); @@ -187,8 +191,8 @@ public void write() try { var rootObject = new JObject(); - rootObject["enable"] = mIsEnable; - rootObject["time"] = mIsTime; + rootObject["IsEnable"] = mIsEnable; + rootObject["IsTime"] = mIsTime; var groupList = new JArray(); for(int i = 0; i < mGroupList.Count; i++) @@ -209,9 +213,8 @@ public void write() var item = group.ItemList[j]; var itemObject = new JObject(); - itemObject["itemType"] = (int)item.ItemType; itemObject["unitType"] = (int)item.UnitType; - itemObject["index"] = item.Index; + itemObject["id"] = item.ID; itemObject["isColor"] = item.IsColor; itemObject["r"] = item.Color.R; itemObject["g"] = item.Color.G; @@ -223,7 +226,7 @@ public void write() groupList.Add(groupObject); } - rootObject["group"] = groupList; + rootObject["Group"] = groupList; File.WriteAllText(mOSDFileName, rootObject.ToString()); } diff --git a/FanCtrl/Data/Option/OptionManager.cs b/FanCtrl/Data/Option/OptionManager.cs index d5c4fb0..e2448fb 100644 --- a/FanCtrl/Data/Option/OptionManager.cs +++ b/FanCtrl/Data/Option/OptionManager.cs @@ -10,12 +10,6 @@ namespace FanCtrl { - public enum LibraryType - { - LibreHardwareMonitor = 0, - OpenHardwareMonitor, - }; - public class OptionManager { private string mOptionFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "Option.json"; @@ -27,36 +21,48 @@ public class OptionManager private OptionManager() { - Interval = 1000; - IsGigabyte = false; - LibraryType = LibraryType.LibreHardwareMonitor; - IsNvAPIWrapper = false; - IsDimm = true; - IsKraken = true; - IsCLC = true; - IsRGBnFC = true; - IsAnimation = true; - IsFahrenheit = false; - IsMinimized = false; - IsStartUp = false; + this.reset(); } public int Interval { get; set; } + // Gigabyte public bool IsGigabyte { get; set; } - - public LibraryType LibraryType { get; set; } - + public bool IsGigabyteMotherboard { get; set; } + public bool IsGigabyteGpu { get; set; } + + // LibreHardwareMonitor + public bool IsLHM { get; set; } + public bool IsLHMCpu { get; set; } + public bool IsLHMMotherboard { get; set; } + public bool IsLHMGpu { get; set; } + public bool IsLHMContolled { get; set; } + public bool IsLHMStorage { get; set; } + + // OpenHardwareMonitor + public bool IsOHM { get; set; } + public bool IsOHMCpu { get; set; } + public bool IsOHMMotherboard { get; set; } + public bool IsOHMGpu { get; set; } + public bool IsOHMContolled { get; set; } + public bool IsOHMStorage { get; set; } + + // NvApiWrapper public bool IsNvAPIWrapper { get; set; } + // Dimm public bool IsDimm { get; set; } + // NZXT Kraken X2, X3 public bool IsKraken { get; set; } + // EVGA CLC public bool IsCLC { get; set; } + // NZXT Fan&Contoller public bool IsRGBnFC { get; set; } + // Other options public bool IsAnimation { get; set; } public bool IsFahrenheit { get; set; } @@ -89,6 +95,39 @@ public bool IsStartUp } } + public void reset() + { + Interval = 1000; + + IsGigabyte = false; + IsGigabyteMotherboard = true; + IsGigabyteGpu = true; + + IsLHM = true; + IsLHMCpu = true; + IsLHMMotherboard = true; + IsLHMGpu = false; + IsLHMContolled = true; + IsLHMStorage = false; + + IsOHM = false; + IsOHMCpu = true; + IsOHMMotherboard = true; + IsOHMGpu = true; + IsOHMContolled = true; + IsOHMStorage = true; + + IsNvAPIWrapper = true; + IsDimm = true; + IsKraken = true; + IsCLC = true; + IsRGBnFC = true; + + IsAnimation = true; + IsFahrenheit = false; + IsMinimized = false; + } + public bool read() { try @@ -96,25 +135,37 @@ public bool read() var jsonString = File.ReadAllText(mOptionFileName); var rootObject = JObject.Parse(jsonString); - Interval = (rootObject.ContainsKey("interval") == true) ? rootObject.Value("interval") : 1000; - - IsGigabyte = (rootObject.ContainsKey("gigabyte") == true) ? rootObject.Value("gigabyte") : false; - - if (rootObject.ContainsKey("library") == false) - LibraryType = LibraryType.LibreHardwareMonitor; - else - LibraryType = (rootObject.Value("library") == 0) ? LibraryType.LibreHardwareMonitor : LibraryType.OpenHardwareMonitor; - - IsNvAPIWrapper = (rootObject.ContainsKey("nvapi") == true) ? rootObject.Value("nvapi") : false; - IsDimm = (rootObject.ContainsKey("dimm") == true) ? rootObject.Value("dimm") : true; - IsKraken = (rootObject.ContainsKey("kraken") == true) ? rootObject.Value("kraken") : true; - IsCLC = (rootObject.ContainsKey("clc") == true) ? rootObject.Value("clc") : true; - IsRGBnFC = (rootObject.ContainsKey("rgbnfc") == true) ? rootObject.Value("rgbnfc") : true; - IsAnimation = (rootObject.ContainsKey("animation") == true) ? rootObject.Value("animation") : true; - IsFahrenheit = (rootObject.ContainsKey("fahrenheit") == true) ? rootObject.Value("fahrenheit") : false; - IsMinimized = (rootObject.ContainsKey("minimized") == true) ? rootObject.Value("minimized") : false; - IsStartUp = (rootObject.ContainsKey("startup") == true) ? rootObject.Value("startup") : false; - DelayTime = (rootObject.ContainsKey("delay") == true) ? rootObject.Value("delay") : 0; + Interval = (rootObject.ContainsKey("Interval") == true) ? rootObject.Value("Interval") : 1000; + + IsGigabyte = (rootObject.ContainsKey("IsGigabyte") == true) ? rootObject.Value("IsGigabyte") : false; + IsGigabyteMotherboard = (rootObject.ContainsKey("IsGigabyteMotherboard") == true) ? rootObject.Value("IsGigabyteMotherboard") : true; + IsGigabyteGpu = (rootObject.ContainsKey("IsGigabyteGpu") == true) ? rootObject.Value("IsGigabyteGpu") : true; + + IsLHM = (rootObject.ContainsKey("IsLHM") == true) ? rootObject.Value("IsLHM") : true; + IsLHMCpu = (rootObject.ContainsKey("IsLHMCpu") == true) ? rootObject.Value("IsLHMCpu") : true; + IsLHMMotherboard = (rootObject.ContainsKey("IsLHMMotherboard") == true) ? rootObject.Value("IsLHMMotherboard") : true; + IsLHMGpu = (rootObject.ContainsKey("IsLHMGpu") == true) ? rootObject.Value("IsLHMGpu") : true; + IsLHMContolled = (rootObject.ContainsKey("IsLHMContolled") == true) ? rootObject.Value("IsLHMContolled") : true; + IsLHMStorage = (rootObject.ContainsKey("IsLHMStorage") == true) ? rootObject.Value("IsLHMStorage") : true; + + IsOHM = (rootObject.ContainsKey("IsOHM") == true) ? rootObject.Value("IsOHM") : false; + IsOHMCpu = (rootObject.ContainsKey("IsOHMCpu") == true) ? rootObject.Value("IsOHMCpu") : true; + IsOHMMotherboard = (rootObject.ContainsKey("IsOHMMotherboard") == true) ? rootObject.Value("IsOHMMotherboard") : true; + IsOHMGpu = (rootObject.ContainsKey("IsOHMGpu") == true) ? rootObject.Value("IsOHMGpu") : true; + IsOHMContolled = (rootObject.ContainsKey("IsOHMContolled") == true) ? rootObject.Value("IsOHMContolled") : true; + IsOHMStorage = (rootObject.ContainsKey("IsOHMStorage") == true) ? rootObject.Value("IsOHMStorage") : true; + + IsNvAPIWrapper = (rootObject.ContainsKey("IsNvAPIWrapper") == true) ? rootObject.Value("IsNvAPIWrapper") : true; + IsDimm = (rootObject.ContainsKey("IsDimm") == true) ? rootObject.Value("IsDimm") : true; + IsKraken = (rootObject.ContainsKey("IsKraken") == true) ? rootObject.Value("IsKraken") : true; + IsCLC = (rootObject.ContainsKey("IsCLC") == true) ? rootObject.Value("IsCLC") : true; + IsRGBnFC = (rootObject.ContainsKey("IsRGBnFC") == true) ? rootObject.Value("IsRGBnFC") : true; + + IsAnimation = (rootObject.ContainsKey("IsAnimation") == true) ? rootObject.Value("IsAnimation") : true; + IsFahrenheit = (rootObject.ContainsKey("IsFahrenheit") == true) ? rootObject.Value("IsFahrenheit") : false; + IsMinimized = (rootObject.ContainsKey("IsMinimized") == true) ? rootObject.Value("IsMinimized") : false; + + DelayTime = (rootObject.ContainsKey("DelayTime") == true) ? rootObject.Value("DelayTime") : 0; } catch { @@ -128,19 +179,38 @@ public void write() try { var rootObject = new JObject(); - rootObject["interval"] = Interval; - rootObject["gigabyte"] = IsGigabyte; - rootObject["library"] = (LibraryType == LibraryType.LibreHardwareMonitor) ? 0 : 1; - rootObject["dimm"] = IsDimm; - rootObject["nvapi"] = IsNvAPIWrapper; - rootObject["kraken"] = IsKraken; - rootObject["clc"] = IsCLC; - rootObject["rgbnfc"] = IsRGBnFC; - rootObject["animation"] = IsAnimation; - rootObject["fahrenheit"] = IsFahrenheit; - rootObject["minimized"] = IsMinimized; - rootObject["startup"] = IsStartUp; - rootObject["delay"] = DelayTime; + rootObject["Interval"] = Interval; + + rootObject["IsGigabyte"] = IsGigabyte; + rootObject["IsGigabyteMotherboard"] = IsGigabyteMotherboard; + rootObject["IsGigabyteGpu"] = IsGigabyteGpu; + + rootObject["IsLHM"] = IsLHM; + rootObject["IsLHMCpu"] = IsLHMCpu; + rootObject["IsLHMMotherboard"] = IsLHMMotherboard; + rootObject["IsLHMGpu"] = IsLHMGpu; + rootObject["IsLHMContolled"] = IsLHMContolled; + rootObject["IsLHMStorage"] = IsLHMStorage; + + rootObject["IsOHM"] = IsOHM; + rootObject["IsOHMCpu"] = IsOHMCpu; + rootObject["IsOHMMotherboard"] = IsOHMMotherboard; + rootObject["IsOHMGpu"] = IsOHMGpu; + rootObject["IsOHMContolled"] = IsOHMContolled; + rootObject["IsOHMStorage"] = IsOHMStorage; + + rootObject["IsNvAPIWrapper"] = IsNvAPIWrapper; + rootObject["IsDimm"] = IsDimm; + rootObject["IsKraken"] = IsKraken; + rootObject["IsCLC"] = IsCLC; + rootObject["IsRGBnFC"] = IsRGBnFC; + + rootObject["IsAnimation"] = IsAnimation; + rootObject["IsFahrenheit"] = IsFahrenheit; + rootObject["IsMinimized"] = IsMinimized; + + rootObject["DelayTime"] = DelayTime; + File.WriteAllText(mOptionFileName, rootObject.ToString()); } catch {} diff --git a/FanCtrl/Hardware/BaseDevice.cs b/FanCtrl/Hardware/BaseDevice.cs new file mode 100644 index 0000000..f60bc56 --- /dev/null +++ b/FanCtrl/Hardware/BaseDevice.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Linq; +using System.Threading; + +namespace FanCtrl +{ + public class BaseDevice + { + public LIBRARY_TYPE Type { get; set; } + + public string Name { get; set; } + + public string ID { get; set; } + + public BaseDevice() + { + + } + + public virtual void update() + { + + } + } +} diff --git a/FanCtrl/Hardware/Control/BaseControl.cs b/FanCtrl/Hardware/Control/BaseControl.cs index fe42f3f..b820074 100644 --- a/FanCtrl/Hardware/Control/BaseControl.cs +++ b/FanCtrl/Hardware/Control/BaseControl.cs @@ -7,7 +7,7 @@ namespace FanCtrl { - public class BaseControl + public class BaseControl : BaseDevice { // Value public int Value { get; set; } @@ -16,20 +16,14 @@ public class BaseControl public int LastValue { get; set; } - public string Name { get; set; } - - public BaseControl() + public BaseControl(LIBRARY_TYPE type) { + Type = type; Value = 0; NextValue = 0; LastValue = 0; } - public virtual void update() - { - - } - public virtual int getMinSpeed() { return 0; diff --git a/FanCtrl/Hardware/Control/CLCFanControl.cs b/FanCtrl/Hardware/Control/CLCFanControl.cs index b5656fa..1d33b56 100644 --- a/FanCtrl/Hardware/Control/CLCFanControl.cs +++ b/FanCtrl/Hardware/Control/CLCFanControl.cs @@ -10,8 +10,9 @@ public class CLCFanControl : BaseControl { private CLC mCLC = null; - public CLCFanControl(CLC clc, uint num) : base() + public CLCFanControl(string id, CLC clc, uint num) : base(LIBRARY_TYPE.EVGA_CLC) { + ID = id; mCLC = clc; Name = "EVGA CLC Fan"; if (num > 1) diff --git a/FanCtrl/Hardware/Control/CLCPumpControl.cs b/FanCtrl/Hardware/Control/CLCPumpControl.cs index c5c504d..0f6594a 100644 --- a/FanCtrl/Hardware/Control/CLCPumpControl.cs +++ b/FanCtrl/Hardware/Control/CLCPumpControl.cs @@ -10,8 +10,9 @@ public class CLCPumpControl : BaseControl { private CLC mCLC = null; - public CLCPumpControl(CLC clc, uint num) : base() + public CLCPumpControl(string id, CLC clc, uint num) : base(LIBRARY_TYPE.EVGA_CLC) { + ID = id; mCLC = clc; Name = "EVGA CLC Pump"; if (num > 1) diff --git a/FanCtrl/Hardware/Control/GigabyteAmdGpuFanControl.cs b/FanCtrl/Hardware/Control/GigabyteAmdGpuFanControl.cs index 50e798b..7aa7893 100644 --- a/FanCtrl/Hardware/Control/GigabyteAmdGpuFanControl.cs +++ b/FanCtrl/Hardware/Control/GigabyteAmdGpuFanControl.cs @@ -15,8 +15,9 @@ public class GigabyteAmdGpuFanControl : BaseControl private int mMinSpeed = 0; private int mMaxSpeed = 100; - public GigabyteAmdGpuFanControl(string name, int index, int minSpeed, int maxSpeed) : base() + public GigabyteAmdGpuFanControl(string id, string name, int index, int minSpeed, int maxSpeed) : base(LIBRARY_TYPE.Gigabyte) { + ID = id; Name = name; mIndex = index; mMinSpeed = minSpeed; diff --git a/FanCtrl/Hardware/Control/GigabyteFanControl.cs b/FanCtrl/Hardware/Control/GigabyteFanControl.cs index 0d1eedf..f1e9667 100644 --- a/FanCtrl/Hardware/Control/GigabyteFanControl.cs +++ b/FanCtrl/Hardware/Control/GigabyteFanControl.cs @@ -15,8 +15,9 @@ public class GigabyteFanControl : BaseControl private int mMinSpeed = 0; private int mMaxSpeed = 100; - public GigabyteFanControl(string name, int index, int value) : base() + public GigabyteFanControl(string id, string name, int index, int value) : base(LIBRARY_TYPE.Gigabyte) { + ID = id; Name = name; mIndex = index; Value = value; diff --git a/FanCtrl/Hardware/Control/GigabyteNvidiaGpuFanControl.cs b/FanCtrl/Hardware/Control/GigabyteNvidiaGpuFanControl.cs index 545cad2..49a4bcb 100644 --- a/FanCtrl/Hardware/Control/GigabyteNvidiaGpuFanControl.cs +++ b/FanCtrl/Hardware/Control/GigabyteNvidiaGpuFanControl.cs @@ -15,8 +15,9 @@ public class GigabyteNvidiaGpuFanControl : BaseControl private int mMinSpeed = 0; private int mMaxSpeed = 100; - public GigabyteNvidiaGpuFanControl(string name, int index, int minSpeed, int maxSpeed) : base() + public GigabyteNvidiaGpuFanControl(string id, string name, int index, int minSpeed, int maxSpeed) : base(LIBRARY_TYPE.Gigabyte) { + ID = id; Name = name; mIndex = index; mMinSpeed = minSpeed; diff --git a/FanCtrl/Hardware/Control/HardwareControl.cs b/FanCtrl/Hardware/Control/HardwareControl.cs deleted file mode 100644 index 5c3c8bd..0000000 --- a/FanCtrl/Hardware/Control/HardwareControl.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using LibreHardwareMonitor.Hardware; -using OpenHardwareMonitor.Hardware; - -namespace FanCtrl -{ - public class HardwareControl : BaseControl - { - // ISensor - private LibreHardwareMonitor.Hardware.ISensor mLHMSensor = null; - private OpenHardwareMonitor.Hardware.ISensor mOHMSensor = null; - - public HardwareControl(LibreHardwareMonitor.Hardware.ISensor sensor, string name) : base() - { - mLHMSensor = sensor; - Name = name; - Value = 0; - LastValue = 0; - } - - public HardwareControl(OpenHardwareMonitor.Hardware.ISensor sensor, string name) : base() - { - mOHMSensor = sensor; - Name = name; - Value = 0; - LastValue = 0; - } - - public override void update() - { - double temp = 0.0f; - if(mLHMSensor != null && mLHMSensor.Value.HasValue == true) - { - temp = (double)mLHMSensor.Value; - } - else if (mOHMSensor != null && mOHMSensor.Value.HasValue == true) - { - temp = (double)mOHMSensor.Value; - } - temp = Math.Round(temp); - Value = (int)temp; - LastValue = (int)temp; - } - - public override int getMinSpeed() - { - if (mLHMSensor != null && mLHMSensor.Control != null) - { - return (int)mLHMSensor.Control.MinSoftwareValue; - } - else if (mOHMSensor != null && mOHMSensor.Control != null) - { - return (int)mOHMSensor.Control.MinSoftwareValue; - } - return 0; - } - - public override int getMaxSpeed() - { - if (mLHMSensor != null && mLHMSensor.Control != null) - { - return (int)mLHMSensor.Control.MaxSoftwareValue; - } - else if (mOHMSensor != null && mOHMSensor.Control != null) - { - return (int)mOHMSensor.Control.MaxSoftwareValue; - } - return 100; - } - - public override int setSpeed(int value) - { - if (mLHMSensor != null && mLHMSensor.Control != null) - { - mLHMSensor.Control.SetSoftware(value); - } - else if (mOHMSensor != null && mOHMSensor.Control != null) - { - mOHMSensor.Control.SetSoftware(value); - } - Value = value; - LastValue = value; - return value; - } - } -} diff --git a/FanCtrl/Hardware/Control/HardwareGpuControl.cs b/FanCtrl/Hardware/Control/HardwareGpuControl.cs index f618314..a80ef7c 100644 --- a/FanCtrl/Hardware/Control/HardwareGpuControl.cs +++ b/FanCtrl/Hardware/Control/HardwareGpuControl.cs @@ -14,7 +14,7 @@ public class HardwareGpuControl : BaseControl private LibreHardwareMonitor.Hardware.ISensor mLHMSensor = null; private OpenHardwareMonitor.Hardware.ISensor mOHMSensor = null; - public HardwareGpuControl(LibreHardwareMonitor.Hardware.ISensor sensor, string name) : base() + public HardwareGpuControl(LibreHardwareMonitor.Hardware.ISensor sensor, string name) : base(LIBRARY_TYPE.LHM) { mLHMSensor = sensor; Name = name; @@ -22,7 +22,7 @@ public HardwareGpuControl(LibreHardwareMonitor.Hardware.ISensor sensor, string n LastValue = 0; } - public HardwareGpuControl(OpenHardwareMonitor.Hardware.ISensor sensor, string name) : base() + public HardwareGpuControl(OpenHardwareMonitor.Hardware.ISensor sensor, string name) : base(LIBRARY_TYPE.OHM) { mOHMSensor = sensor; Name = name; diff --git a/FanCtrl/Hardware/Control/KrakenFanControl.cs b/FanCtrl/Hardware/Control/KrakenFanControl.cs index 9a04051..5859a00 100644 --- a/FanCtrl/Hardware/Control/KrakenFanControl.cs +++ b/FanCtrl/Hardware/Control/KrakenFanControl.cs @@ -10,8 +10,9 @@ public class KrakenFanControl : BaseControl { private Kraken mKraken = null; - public KrakenFanControl(Kraken kraken, uint num) : base() + public KrakenFanControl(string id, Kraken kraken, uint num) : base(LIBRARY_TYPE.NZXT_Kraken) { + ID = id; mKraken = kraken; Name = "NZXT Kraken Fan"; if (num > 1) diff --git a/FanCtrl/Hardware/Control/KrakenPumpControl.cs b/FanCtrl/Hardware/Control/KrakenPumpControl.cs index d4e4e7f..0ba773d 100644 --- a/FanCtrl/Hardware/Control/KrakenPumpControl.cs +++ b/FanCtrl/Hardware/Control/KrakenPumpControl.cs @@ -10,8 +10,9 @@ public class KrakenPumpControl : BaseControl { private Kraken mKraken = null; - public KrakenPumpControl(Kraken kraken, uint num) : base() + public KrakenPumpControl(string id, Kraken kraken, uint num) : base(LIBRARY_TYPE.NZXT_Kraken) { + ID = id; mKraken = kraken; Name = "NZXT Kraken Pump"; if (num > 1) diff --git a/FanCtrl/Hardware/Control/LHMControl.cs b/FanCtrl/Hardware/Control/LHMControl.cs new file mode 100644 index 0000000..6eb9885 --- /dev/null +++ b/FanCtrl/Hardware/Control/LHMControl.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using LibreHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class LHMControl : BaseControl + { + // ISensor + private ISensor mSensor = null; + + public LHMControl(string id, ISensor sensor, string name) : base(LIBRARY_TYPE.LHM) + { + ID = id; + mSensor = sensor; + Name = name; + Value = 0; + LastValue = 0; + } + + public override void update() + { + double temp = 0.0f; + if (mSensor != null && mSensor.Value.HasValue == true) + { + temp = (double)mSensor.Value; + } + temp = Math.Round(temp); + Value = (int)temp; + LastValue = (int)temp; + } + + public override int getMinSpeed() + { + if (mSensor != null && mSensor.Control != null) + { + return (int)mSensor.Control.MinSoftwareValue; + } + return 0; + } + + public override int getMaxSpeed() + { + if (mSensor != null && mSensor.Control != null) + { + return (int)mSensor.Control.MaxSoftwareValue; + } + return 100; + } + + public override int setSpeed(int value) + { + if (mSensor != null && mSensor.Control != null) + { + mSensor.Control.SetSoftware(value); + } + Value = value; + LastValue = value; + return value; + } + } +} diff --git a/FanCtrl/Hardware/Control/NvAPIFanControl.cs b/FanCtrl/Hardware/Control/NvAPIFanControl.cs index 2d99a61..5e91914 100644 --- a/FanCtrl/Hardware/Control/NvAPIFanControl.cs +++ b/FanCtrl/Hardware/Control/NvAPIFanControl.cs @@ -16,8 +16,9 @@ public class NvAPIFanControl : BaseControl private int mMinSpeed = 0; private int mMaxSpeed = 100; - public NvAPIFanControl(string name, int index, int coolerID, int value, int minSpeed, int maxSpeed) : base() + public NvAPIFanControl(string id, string name, int index, int coolerID, int value, int minSpeed, int maxSpeed) : base(LIBRARY_TYPE.NvAPIWrapper) { + ID = id; Name = name; mIndex = index; mCoolerID = coolerID; diff --git a/FanCtrl/Hardware/Control/OHMControl.cs b/FanCtrl/Hardware/Control/OHMControl.cs new file mode 100644 index 0000000..a082a7b --- /dev/null +++ b/FanCtrl/Hardware/Control/OHMControl.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class OHMControl : BaseControl + { + // ISensor + private ISensor mSensor = null; + + public OHMControl(string id, ISensor sensor, string name) : base(LIBRARY_TYPE.OHM) + { + ID = id; + mSensor = sensor; + Name = name; + Value = 0; + LastValue = 0; + } + + public override void update() + { + double temp = 0.0f; + if (mSensor != null && mSensor.Value.HasValue == true) + { + temp = (double)mSensor.Value; + } + temp = Math.Round(temp); + Value = (int)temp; + LastValue = (int)temp; + } + + public override int getMinSpeed() + { + if (mSensor != null && mSensor.Control != null) + { + return (int)mSensor.Control.MinSoftwareValue; + } + return 0; + } + + public override int getMaxSpeed() + { + if (mSensor != null && mSensor.Control != null) + { + return (int)mSensor.Control.MaxSoftwareValue; + } + return 100; + } + + public override int setSpeed(int value) + { + if (mSensor != null && mSensor.Control != null) + { + mSensor.Control.SetSoftware(value); + } + Value = value; + LastValue = value; + return value; + } + } +} diff --git a/FanCtrl/Hardware/Control/RGBnFCControl.cs b/FanCtrl/Hardware/Control/RGBnFCControl.cs index 9ad8014..74801c9 100644 --- a/FanCtrl/Hardware/Control/RGBnFCControl.cs +++ b/FanCtrl/Hardware/Control/RGBnFCControl.cs @@ -11,8 +11,9 @@ public class RGBnFCControl : BaseControl private RGBnFC mRGBnFC = null; private int mIndex = 0; - public RGBnFCControl(RGBnFC fc, int index, uint num) : base() + public RGBnFCControl(string id, RGBnFC fc, int index, uint num) : base(LIBRARY_TYPE.RGBnFC) { + ID = id; mRGBnFC = fc; mIndex = index; Name = "NZXT RGB&Fan #" + num; diff --git a/FanCtrl/Hardware/Define.cs b/FanCtrl/Hardware/Define.cs new file mode 100644 index 0000000..bce1be5 --- /dev/null +++ b/FanCtrl/Hardware/Define.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Linq; +using System.Threading; + +namespace FanCtrl +{ + public enum LIBRARY_TYPE + { + Gigabyte, + LHM, + OHM, + NvAPIWrapper, + DIMM, + NZXT_Kraken, + EVGA_CLC, + RGBnFC, + OSD, + + MAX, + }; + + public class Define + { + public static string[] cLibraryTypeString = { + "Gigabyte", + "LibreHardwareMonitor", + "OpenHardwareMonitor", + "NvAPIWrapper", + "DIMM", + "NZXT Kraken", + "EVGA CLC", + "NZXT RGB&FanController", + "On screen display", + }; + } +} diff --git a/FanCtrl/Hardware/Gigabyte.cs b/FanCtrl/Hardware/Gigabyte.cs index 31a0bbf..6bf047c 100644 --- a/FanCtrl/Hardware/Gigabyte.cs +++ b/FanCtrl/Hardware/Gigabyte.cs @@ -16,6 +16,10 @@ namespace FanCtrl { public class Gigabyte { + private const string mIDPrefixTemperature = "Gigabyte/Temp"; + private const string mIDPrefixFan = "Gigabyte/Fan"; + private const string mIDPrefixControl = "Gigabyte/Control"; + public delegate void LockBusHandler(); public delegate int AddChangeValueHandler(int value, BaseControl control); @@ -31,17 +35,15 @@ public class Gigabyte public event LockBusHandler LockBus; public event LockBusHandler UnlockBus; - public event AddChangeValueHandler AddChangeValue; public Gigabyte() { } public bool start() { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; try { var controller = new EngineServiceController("EasyTuneEngineService"); - if(controller.IsInstall() == false) + if (controller.IsInstall() == false) { controller.Dispose(); this.stop(); @@ -53,9 +55,12 @@ public bool start() controller.Start(); } controller.Dispose(); + } + catch { } - this.lockBus(); - + this.lockBus(); + try + { mGigabyteHardwareMonitorControlModule = new HardwareMonitorControlModule(); mGigabyteHardwareMonitorControlModule.Initialize(HardwareMonitorSourceTypes.HwRegister); @@ -63,17 +68,17 @@ public bool start() var temperatureList = new List(); mGigabyteSmartGuardianFanControlModule.GetHardwareMonitorDatas(ref temperatureList, ref mGigabyteFanSpeedList); - var management = new GraphicsCardServiceManagement(); - if (management.IsProcessExist() == true) + if (OptionManager.getInstance().IsGigabyteGpu == true) { - mGigabyteGraphicsCardControlModule = new GraphicsCardControlModule(); - if (mGigabyteGraphicsCardControlModule.AmdGpuCount > 0) + var management = new GraphicsCardServiceManagement(); + if (management.IsProcessExist() == true) { - mGigabyteGraphicsCardControlModule.GetObjects(ref mGigabyteAmdRadeonGraphicsModuleList); - } + mGigabyteGraphicsCardControlModule = new GraphicsCardControlModule(); + if (mGigabyteGraphicsCardControlModule.AmdGpuCount > 0) + { + mGigabyteGraphicsCardControlModule.GetObjects(ref mGigabyteAmdRadeonGraphicsModuleList); + } - if (isNvAPIWrapper == false) - { if (mGigabyteGraphicsCardControlModule.NvidiaGpuCount > 0) { mGigabyteGraphicsCardControlModule.GetObjects(ref mGigabyteNvidiaGeforceGraphicsModuleList); @@ -86,6 +91,7 @@ public bool start() } catch { + this.unlockBus(); this.stop(); } return false; @@ -110,33 +116,58 @@ public static void stopService() public void stop() { - for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) + if (OptionManager.getInstance().IsGigabyteGpu == true) { - mGigabyteAmdRadeonGraphicsModuleList[i].Dispose(); - } - mGigabyteAmdRadeonGraphicsModuleList.Clear(); + for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) + { + try + { + mGigabyteAmdRadeonGraphicsModuleList[i].Dispose(); + } + catch { } + } + mGigabyteAmdRadeonGraphicsModuleList.Clear(); - for (int i = 0; i < mGigabyteNvidiaGeforceGraphicsModuleList.Count; i++) - { - mGigabyteNvidiaGeforceGraphicsModuleList[i].Dispose(); + for (int i = 0; i < mGigabyteNvidiaGeforceGraphicsModuleList.Count; i++) + { + try + { + mGigabyteNvidiaGeforceGraphicsModuleList[i].Dispose(); + } + catch { } + } + mGigabyteNvidiaGeforceGraphicsModuleList.Clear(); } - mGigabyteNvidiaGeforceGraphicsModuleList.Clear(); - if (mGigabyteSmartGuardianFanControlModule != null) + try { - mGigabyteSmartGuardianFanControlModule.Dispose(); - mGigabyteSmartGuardianFanControlModule = null; + if (mGigabyteSmartGuardianFanControlModule != null) + { + mGigabyteSmartGuardianFanControlModule.Dispose(); + mGigabyteSmartGuardianFanControlModule = null; + } } - if (mGigabyteHardwareMonitorControlModule != null) + catch { } + + try { - mGigabyteHardwareMonitorControlModule.Dispose(); - mGigabyteHardwareMonitorControlModule = null; + if (mGigabyteHardwareMonitorControlModule != null) + { + mGigabyteHardwareMonitorControlModule.Dispose(); + mGigabyteHardwareMonitorControlModule = null; + } } - if(mGigabyteGraphicsCardControlModule != null) + catch { } + + try { - mGigabyteGraphicsCardControlModule.Dispose(); - mGigabyteGraphicsCardControlModule = null; + if (mGigabyteGraphicsCardControlModule != null) + { + mGigabyteGraphicsCardControlModule.Dispose(); + mGigabyteGraphicsCardControlModule = null; + } } + catch { } mGigabyteTemperatureList.Clear(); mGigabyteFanSpeedList.Clear(); @@ -152,235 +183,219 @@ private void unlockBus() UnlockBus(); } - public void createTemp(ref List sensorList) + public void createTemp(ref List deviceList) { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; + var device = new HardwareDevice("Gigabyte"); - this.lockBus(); - var pHwMonitoredDataList = new HardwareMonitoredDataCollection(); - mGigabyteHardwareMonitorControlModule.GetCurrentMonitoredData(SensorTypes.Temperature, ref pHwMonitoredDataList); - this.unlockBus(); - - int num = 2; - for (int i = 0; i < pHwMonitoredDataList.Count; i++) + if (OptionManager.getInstance().IsGigabyteMotherboard == true) { - string name = pHwMonitoredDataList[i].Title; - mGigabyteTemperatureList.Add(pHwMonitoredDataList[i].Value); - - while (this.isExistTemp(ref sensorList, name) == true) + this.lockBus(); + try { - name = pHwMonitoredDataList[i].Title + " #" + num++; - } + var pHwMonitoredDataList = new HardwareMonitoredDataCollection(); + mGigabyteHardwareMonitorControlModule.GetCurrentMonitoredData(SensorTypes.Temperature, ref pHwMonitoredDataList); + for (int i = 0; i < pHwMonitoredDataList.Count; i++) + { + string name = pHwMonitoredDataList[i].Title; + string id = string.Format("{0}/{1}/{2}", mIDPrefixTemperature, name, pHwMonitoredDataList[i].DeviceUUID); + + mGigabyteTemperatureList.Add(pHwMonitoredDataList[i].Value); - var sensor = new GigabyteTemp(name, i); - sensor.onGetGigabyteTemperatureHandler += onGetGigabyteTemperature; - sensorList.Add(sensor); + var sensor = new GigabyteTemp(id, name, i); + sensor.onGetGigabyteTemperatureHandler += onGetGigabyteTemperature; + device.addDevice(sensor); + } + } + catch { } + this.unlockBus(); } - num = 2; - for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) + if (OptionManager.getInstance().IsGigabyteGpu == true) { - string name = mGigabyteAmdRadeonGraphicsModuleList[i].ProductName; - while (this.isExistTemp(ref sensorList, name) == true) + for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) { - name = mGigabyteAmdRadeonGraphicsModuleList[i].ProductName + " #" + num++; + string name = mGigabyteAmdRadeonGraphicsModuleList[i].ProductName; + string id = string.Format("{0}/{1}/{2}", mIDPrefixTemperature, name, i); + var sensor = new GigabyteAmdGpuTemp(id, name, i); + sensor.onGetGigabyteAmdTemperatureHandler += onGetGigabyteAmdTemperature; + device.addDevice(sensor); } - var sensor = new GigabyteAmdGpuTemp(name, i); - sensor.onGetGigabyteAmdTemperatureHandler += onGetGigabyteAmdTemperature; - sensorList.Add(sensor); - } - - if (isNvAPIWrapper == false) - { - num = 2; for (int i = 0; i < mGigabyteNvidiaGeforceGraphicsModuleList.Count; i++) { string name = mGigabyteNvidiaGeforceGraphicsModuleList[i].ProductName; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = mGigabyteNvidiaGeforceGraphicsModuleList[i].ProductName + " #" + num++; - } - - var sensor = new GigabyteNvidiaGpuTemp(name, i); + string id = string.Format("{0}/{1}/{2}", mIDPrefixTemperature, name, i); + var sensor = new GigabyteNvidiaGpuTemp(id, name, i); sensor.onGetGigabyteNvidiaTemperatureHandler += onGetGigabyteNvidiaTemperature; - sensorList.Add(sensor); + device.addDevice(sensor); } } + + if (device.DeviceList.Count > 0) + { + deviceList.Add(device); + } } - public void createFan(ref List fanList) + public void createFan(ref List deviceList) { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; + var device = new HardwareDevice("Gigabyte"); - int num = 2; - for (int i = 0; i < mGigabyteSmartGuardianFanControlModule.FanControlCount; i++) + if (OptionManager.getInstance().IsGigabyteMotherboard == true) { - string originName; - mGigabyteSmartGuardianFanControlModule.GetFanControlTitle(i, out originName); - if (originName.Equals("PCH") == true) - continue; - - var name = originName; - while (this.isExistFan(ref fanList, name) == true) + int num = 1; + this.lockBus(); + try { - name = originName + " #" + num++; - } + for (int i = 0; i < mGigabyteSmartGuardianFanControlModule.FanControlCount; i++) + { + string name; + mGigabyteSmartGuardianFanControlModule.GetFanControlTitle(i, out name); + if (name.Length == 0) + { + name = "Fan #" + num++; + } - var fan = new GigabyteFanSpeed(name, i); - fan.onGetGigabyteFanSpeedHandler += onGetGigabyteFanSpeed; - fanList.Add(fan); + string id = string.Format("{0}/{1}/{2}", mIDPrefixFan, name, i); + var fan = new GigabyteFanSpeed(id, name, i); + fan.onGetGigabyteFanSpeedHandler += onGetGigabyteFanSpeed; + device.addDevice(fan); + } + } + catch { } + this.unlockBus(); } - int gpuNum = 1; - for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) + if (OptionManager.getInstance().IsGigabyteGpu == true) { - var name = "GPU Fan #" + gpuNum++; - while (this.isExistFan(ref fanList, name) == true) + int num = 1; + for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) { - name = "GPU Fan #" + gpuNum++; - } + string name = mGigabyteAmdRadeonGraphicsModuleList[i].DisplayName; + if (name.Length == 0) + { + name = "GPU Fan #" + num++; + } - var fan = new GigabyteAmdGpuFanSpeed(name, i); - fan.onGetGigabyteAmdFanSpeedHandler += onGetGigabyteAmdFanSpeed; - fanList.Add(fan); - } + string id = string.Format("{0}/{1}/{2}", mIDPrefixFan, name, i); + var fan = new GigabyteAmdGpuFanSpeed(name, i); + fan.onGetGigabyteAmdFanSpeedHandler += onGetGigabyteAmdFanSpeed; + device.addDevice(fan); + } - if (isNvAPIWrapper == false) - { for (int i = 0; i < mGigabyteNvidiaGeforceGraphicsModuleList.Count; i++) { - var name = "GPU Fan #" + gpuNum++; - while (this.isExistFan(ref fanList, name) == true) + string name = mGigabyteNvidiaGeforceGraphicsModuleList[i].DisplayName; + if (name.Length == 0) { - name = "GPU Fan #" + gpuNum++; + name = "GPU Fan #" + num++; } - var fan = new GigabyteNvidiaFanSpeed(name, i); + string id = string.Format("{0}/{1}/{2}", mIDPrefixFan, name, i); + var fan = new GigabyteNvidiaFanSpeed(id, name, i); fan.onGetGigabyteNvidiaFanSpeedHandler += onGetGigabyteNvidiaFanSpeed; - fanList.Add(fan); + device.addDevice(fan); } + } + + if (device.DeviceList.Count > 0) + { + deviceList.Add(device); } } - public void createControl(ref List controlList) + public void createControl(ref List deviceList) { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; + var device = new HardwareDevice("Gigabyte"); - int num = 2; - for (int i = 0; i < mGigabyteSmartGuardianFanControlModule.FanControlCount; i++) + if (OptionManager.getInstance().IsGigabyteMotherboard == true) { - string originName; - mGigabyteSmartGuardianFanControlModule.GetFanControlTitle(i, out originName); - if (originName.Equals("PCH") == true) - continue; - - var name = originName; - while (this.isExistControl(ref controlList, name) == true) + int num = 1; + this.lockBus(); + try { - name = originName + " #" + num++; - } + for (int i = 0; i < mGigabyteSmartGuardianFanControlModule.FanControlCount; i++) + { + string name; + mGigabyteSmartGuardianFanControlModule.GetFanControlTitle(i, out name); + if (name.Length == 0) + { + name = "Fan Control #" + num++; + } - var config = new SmartFanControlConfig(); - mGigabyteSmartGuardianFanControlModule.Get(i, ref config); + var config = new SmartFanControlConfig(); + mGigabyteSmartGuardianFanControlModule.Get(i, ref config); - double pwm = (double)config.FanConfig.StartPWM; - int value = (int)Math.Round(pwm / 255.0f * 100.0f); - - var control = new GigabyteFanControl(name, i, value); - control.onSetGigabyteControlHandler += onSetGigabyteControl; - controlList.Add(control); - } + double pwm = (double)config.FanConfig.StartPWM; + int value = (int)Math.Round(pwm / 255.0f * 100.0f); - int gpuNum = 1; - for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) - { - this.lockBus(); - var info = new GraphicsFanSpeedInfo(); - mGigabyteAmdRadeonGraphicsModuleList[i].GetFanSpeedInfo(ref info); + string id = string.Format("{0}/{1}/{2}", mIDPrefixControl, name, i); + var control = new GigabyteFanControl(id, name, i, value); + control.onSetGigabyteControlHandler += onSetGigabyteControl; + device.addDevice(control); + } + } + catch { } this.unlockBus(); + } - var name = "GPU Fan #" + gpuNum++; - while (this.isExistControl(ref controlList, name) == true) + if (OptionManager.getInstance().IsGigabyteGpu == true) + { + int num = 1; + for (int i = 0; i < mGigabyteAmdRadeonGraphicsModuleList.Count; i++) { - name = "GPU Fan #" + gpuNum++; - } + var info = new GraphicsFanSpeedInfo(); + mGigabyteAmdRadeonGraphicsModuleList[i].GetFanSpeedInfo(ref info); - var control = new GigabyteAmdGpuFanControl(name, i, info.MinPercent, info.MaxPercent); - control.onSetGigabyteAmdControlHandler += onSetGigabyteAmdControl; - controlList.Add(control); + string name = mGigabyteAmdRadeonGraphicsModuleList[i].DisplayName; + if (name.Length == 0) + { + name = "GPU Fan Control #" + num++; + } - this.addChangeValue(control.getMinSpeed(), control); - } + string id = string.Format("{0}/{1}/{2}", mIDPrefixControl, name, i); + var control = new GigabyteAmdGpuFanControl(id, name, i, info.MinPercent, info.MaxPercent); + control.onSetGigabyteAmdControlHandler += onSetGigabyteAmdControl; + device.addDevice(control); + } - if (isNvAPIWrapper == false) - { for (int i = 0; i < mGigabyteNvidiaGeforceGraphicsModuleList.Count; i++) { - this.lockBus(); var info = new GraphicsCoolerSetting(); mGigabyteNvidiaGeforceGraphicsModuleList[i].GetFanSpeedInfo(ref info); info.Support = true; info.Manual = true; - this.unlockBus(); int minPercent = (int)Math.Ceiling(info.Config.Minimum); int maxPercent = (int)Math.Ceiling(info.Config.Maximum); - var name = "GPU Fan #" + gpuNum++; - while (this.isExistControl(ref controlList, name) == true) + string name = mGigabyteNvidiaGeforceGraphicsModuleList[i].DisplayName; + if (name.Length == 0) { - name = "GPU Fan #" + gpuNum++; + name = "GPU Fan Control #" + num++; } - var control = new GigabyteNvidiaGpuFanControl(name, i, minPercent, maxPercent); + string id = string.Format("{0}/{1}/{2}", mIDPrefixControl, name, i); + var control = new GigabyteNvidiaGpuFanControl(id, name, i, minPercent, maxPercent); control.onSetGigabyteNvidiaControlHandler += onSetGigabyteNvidiaControl; - controlList.Add(control); - - this.addChangeValue(control.getMinSpeed(), control); - } - } - } - - private bool isExistTemp(ref List sensorList, string name) - { - for (int i = 0; i < sensorList.Count; i++) - { - if (sensorList[i].Name.Equals(name) == true) - { - return true; + device.addDevice(control); } - } - return false; - } + } - private bool isExistFan(ref List fanList, string name) - { - for (int i = 0; i < fanList.Count; i++) + if (device.DeviceList.Count > 0) { - if (fanList[i].Name.Equals(name) == true) - { - return true; - } + deviceList.Add(device); } - return false; } - private bool isExistControl(ref List controlList, string name) + private float onGetGigabyteFanSpeed(int index) { - for (int i = 0; i < controlList.Count; i++) + try { - if (controlList[i].Name.Equals(name) == true) - { - return true; - } + return mGigabyteFanSpeedList[index]; } - return false; - } - - private float onGetGigabyteFanSpeed(int index) - { - return mGigabyteFanSpeedList[index]; + catch { } + return 0.0f; } private float onGetGigabyteAmdFanSpeed(int index) @@ -412,7 +427,12 @@ private float onGetGigabyteNvidiaFanSpeed(int index) private float onGetGigabyteTemperature(int index) { - return mGigabyteTemperatureList[index]; + try + { + return mGigabyteTemperatureList[index]; + } + catch { } + return 0.0f; } private float onGetGigabyteAmdTemperature(int index) @@ -476,32 +496,30 @@ private void onSetGigabyteNvidiaControl(int index, int value) public void update() { - var tempDataList = new HardwareMonitoredDataCollection(); - var fanDataList = new HardwareMonitoredDataCollection(); - - this.lockBus(); - try + if (OptionManager.getInstance().IsGigabyteMotherboard == true) { - mGigabyteHardwareMonitorControlModule.GetCurrentMonitoredData(SensorTypes.Temperature, ref tempDataList); - mGigabyteHardwareMonitorControlModule.GetCurrentMonitoredData(SensorTypes.Fan, ref fanDataList); - } - catch { } - this.unlockBus(); + var tempDataList = new HardwareMonitoredDataCollection(); + var fanDataList = new HardwareMonitoredDataCollection(); - for (int i = 0; i < tempDataList.Count; i++) - { - mGigabyteTemperatureList[i] = tempDataList[i].Value; - } + this.lockBus(); + try + { + mGigabyteHardwareMonitorControlModule.GetCurrentMonitoredData(SensorTypes.Temperature, ref tempDataList); + mGigabyteHardwareMonitorControlModule.GetCurrentMonitoredData(SensorTypes.Fan, ref fanDataList); + } + catch { } + this.unlockBus(); - for (int i = 0; i < fanDataList.Count; i++) - { - mGigabyteFanSpeedList[i] = fanDataList[i].Value; - } - } + for (int i = 0; i < tempDataList.Count; i++) + { + mGigabyteTemperatureList[i] = tempDataList[i].Value; + } - private int addChangeValue(int value, BaseControl control) - { - return AddChangeValue(value, control); + for (int i = 0; i < fanDataList.Count; i++) + { + mGigabyteFanSpeedList[i] = fanDataList[i].Value; + } + } } } } diff --git a/FanCtrl/Hardware/HardwareDevice.cs b/FanCtrl/Hardware/HardwareDevice.cs new file mode 100644 index 0000000..4845897 --- /dev/null +++ b/FanCtrl/Hardware/HardwareDevice.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Linq; +using System.Threading; + +namespace FanCtrl +{ + public class HardwareDevice + { + // device name + public string Name { get; set; } + + // device list + public List DeviceList { get; } = new List(); + + public HardwareDevice(string name) + { + Name = name; + } + + public void addDevice(BaseDevice device) + { + DeviceList.Add(device); + } + } +} diff --git a/FanCtrl/Hardware/HardwareManager.cs b/FanCtrl/Hardware/HardwareManager.cs index 2b789e6..b82733b 100644 --- a/FanCtrl/Hardware/HardwareManager.cs +++ b/FanCtrl/Hardware/HardwareManager.cs @@ -6,13 +6,18 @@ using NvAPIWrapper; using NvAPIWrapper.GPU; using System.Text; +using System.IO; +using System.Reflection; +using Newtonsoft.Json.Linq; namespace FanCtrl { public class HardwareManager { + public string mHardwareFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "Hardware.json"; + // Singletone - private HardwareManager(){} + private HardwareManager() { } private static HardwareManager sManager = new HardwareManager(); public static HardwareManager getInstance() { return sManager; } @@ -28,7 +33,6 @@ private HardwareManager(){} private Mutex mPCIMutex = null; // Gigabyte - private bool mIsGigabyte = false; private Gigabyte mGigabyte = null; // LibreHardwareMonitor @@ -38,35 +42,39 @@ private HardwareManager(){} private OHM mOHM = null; // NZXT Kraken - private List mKrakenList = new List(); - public List getKrakenList() { return mKrakenList; } + public List KrakenList { get; } = new List(); // EVGA CLC - private List mCLCList = new List(); - public List getCLCList() { return mCLCList; } + public List CLCList { get; } = new List(); // NZXT RGB & Fan Controller - private List mRGBnFCList = new List(); - public List getRGBnFCList() { return mRGBnFCList; } + public List RGBnFCList { get; } = new List(); - // Temperature sensor List - private List mSensorList = new List(); + // Temperature sensor + public List> TempList { get; } = new List>(); + public List TempBaseList { get; } = new List(); + public Dictionary TempBaseMap { get; } = new Dictionary(); - // Fan List - private List mFanList = new List(); + // Fan + public List> FanList { get; } = new List>(); + public List FanBaseList { get; } = new List(); + public Dictionary FanBaseMap { get; } = new Dictionary(); - // Control List - private List mControlList = new List(); + // Control + public List> ControlList { get; } = new List>(); + public List ControlBaseList { get; } = new List(); + public Dictionary ControlBaseMap { get; } = new Dictionary(); // OSD sensor List - private List mOSDSensorList = new List(); + public List OSDSensorList { get; } = new List(); + public Dictionary OSDSensorMap { get; } = new Dictionary(); // next tick change value private List mChangeValueList = new List(); private List mChangeControlList = new List(); // update timer - private System.Timers.Timer mUpdateTimer = new System.Timers.Timer(); + private System.Timers.Timer mUpdateTimer = null; public event UpdateTimerEventHandler onUpdateCallback; public delegate void UpdateTimerEventHandler(); @@ -94,39 +102,68 @@ public void start() mutexName = "Global\\Access_PCI"; this.createBusMutex(mutexName, ref mPCIMutex); + // create list + for (int i = 0; i < (int)LIBRARY_TYPE.MAX; i++) + { + TempList.Add(new List()); + FanList.Add(new List()); + ControlList.Add(new List()); + } + // Gigabyte - if(OptionManager.getInstance().IsGigabyte == true) + if (OptionManager.getInstance().IsGigabyte == true) { mGigabyte = new Gigabyte(); - mGigabyte.AddChangeValue += addChangeValue; mGigabyte.LockBus += lockBus; mGigabyte.UnlockBus += unlockBus; - mIsGigabyte = mGigabyte.start(); + if (mGigabyte.start() == false) + { + mGigabyte = null; + } + else + { + var tempList = TempList[(int)LIBRARY_TYPE.Gigabyte]; + mGigabyte.createTemp(ref tempList); + + var fanList = FanList[(int)LIBRARY_TYPE.Gigabyte]; + mGigabyte.createFan(ref fanList); + + var controlList = ControlList[(int)LIBRARY_TYPE.Gigabyte]; + mGigabyte.createControl(ref controlList); + } } - else + + // LHM + if (OptionManager.getInstance().IsLHM == true) { - mIsGigabyte = false; - Gigabyte.stopService(); + mLHM = new LHM(); + mLHM.start(); + + var tempList = TempList[(int)LIBRARY_TYPE.LHM]; + mLHM.createTemp(ref tempList); + + var fanList = FanList[(int)LIBRARY_TYPE.LHM]; + mLHM.createFan(ref fanList); + + var controlList = ControlList[(int)LIBRARY_TYPE.LHM]; + mLHM.createControl(ref controlList); } - - if (mIsGigabyte == false) + + // OHM + if (OptionManager.getInstance().IsOHM == true) { - mGigabyte = null; + mOHM = new OHM(); + mOHM.start(); - // LibreHardwareMonitor - if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) - { - mLHM = new LHM(); - mLHM.start(); - } + var tempList = TempList[(int)LIBRARY_TYPE.OHM]; + mOHM.createTemp(ref tempList); - // OpenHardwareMonitor - else - { - mOHM = new OHM(); - mOHM.start(); - } + var fanList = FanList[(int)LIBRARY_TYPE.OHM]; + mOHM.createFan(ref fanList); + + var controlList = ControlList[(int)LIBRARY_TYPE.OHM]; + mOHM.createControl(ref controlList); } // NvAPIWrapper @@ -136,12 +173,118 @@ public void start() { NVIDIA.Initialize(); } - catch { } + catch { } + + try + { + var gpuArray = PhysicalGPU.GetPhysicalGPUs(); + for (int i = 0; i < gpuArray.Length; i++) + { + var gpu = gpuArray[i]; + var hardwareName = gpu.FullName; + + // temperature + var id = string.Format("NvAPIWrapper/{0}/{1}/Temp", hardwareName, i); + var name = "GPU Core"; + var temp = new NvAPITemp(id, name, i); + temp.onGetNvAPITemperatureHandler += onGetNvAPITemperature; + + var tempDevice = new HardwareDevice(hardwareName); + tempDevice.addDevice(temp); + + var tempList = TempList[(int)LIBRARY_TYPE.NvAPIWrapper]; + tempList.Add(tempDevice); + + var fanDevice = new HardwareDevice(hardwareName); + var controlDevice = new HardwareDevice(hardwareName); + + int num = 1; + var e = gpuArray[i].CoolerInformation.Coolers.GetEnumerator(); + while (e.MoveNext()) + { + var value = e.Current; + int coolerID = value.CoolerId; + int speed = value.CurrentLevel; + int minSpeed = 0;// value.DefaultMinimumLevel; + int maxSpeed = 100;// value.DefaultMaximumLevel; + + // fan + id = string.Format("NvAPIWrapper/{0}/{1}/Fan/{2}", hardwareName, i, coolerID); + name = "GPU Fan #" + num; + var fan = new NvAPIFanSpeed(id, name, i, coolerID); + fan.onGetNvAPIFanSpeedHandler += onGetNvAPIFanSpeed; + fanDevice.addDevice(fan); + + // control + id = string.Format("NvAPIWrapper/{0}/{1}/Control/{2}", hardwareName, i, coolerID); + name = "GPU Fan #" + num; + var control = new NvAPIFanControl(id, name, i, coolerID, speed, minSpeed, maxSpeed); + control.onSetNvAPIControlHandler += onSetNvApiControl; + controlDevice.addDevice(control); + num++; + } + + if (fanDevice.DeviceList.Count > 0) + { + var fanList = FanList[(int)LIBRARY_TYPE.NvAPIWrapper]; + fanList.Add(fanDevice); + } + + if (controlDevice.DeviceList.Count > 0) + { + var controlList = ControlList[(int)LIBRARY_TYPE.NvAPIWrapper]; + controlList.Add(controlDevice); + } + } + } + catch { } } - this.createTemp(); - this.createFan(); - this.createControl(); + // DIMM thermal sensor + if (OptionManager.getInstance().IsDimm == true) + { + this.lockBus(); + this.lockSMBus(0); + if (SMBusController.open(false) == true) + { + var device = new HardwareDevice("DIMM"); + + int num = 1; + int busCount = SMBusController.getCount(); + + for (int i = 0; i < busCount; i++) + { + var detectBytes = SMBusController.i2cDetect(i); + if (detectBytes != null) + { + // 0x18 ~ 0x20 + for (int j = 0; j < detectBytes.Length; j++) + { + if (j < 24) + continue; + else if (j > 32) + break; + + if (detectBytes[j] == (byte)j) + { + var id = string.Format("DIMM/{0}/{1}", i, j); + var temp = new DimmTemp(id, "DIMM #" + num++, i, detectBytes[j]); + temp.onSetDimmTemperature += onSetDimmTemperature; + device.addDevice(temp); + } + } + } + } + + if (device.DeviceList.Count > 0) + { + var tempList = TempList[(int)LIBRARY_TYPE.DIMM]; + tempList.Add(device); + } + } + this.unlockSMBus(); + this.unlockBus(); + } // NZXT Kraken if (OptionManager.getInstance().IsKraken == true) @@ -151,57 +294,107 @@ public void start() uint num = 1; // X2 + var tempDevice = new HardwareDevice("NZXT Kraken X2"); + var fanDevice = new HardwareDevice("NZXT Kraken X2"); + var controlDevice = new HardwareDevice("NZXT Kraken X2"); uint devCount = HidUSBController.getDeviceCount(USBVendorID.NZXT, USBProductID.KrakenX2); for (uint i = 0; i < devCount; i++) { var kraken = new Kraken(); if (kraken.start(i, USBProductID.KrakenX2) == true) { - mKrakenList.Add(kraken); + KrakenList.Add(kraken); - var sensor = new KrakenLiquidTemp(kraken, num); - mSensorList.Add(sensor); + var id = string.Format("NZXT/KrakenX2/{0}/Temp", i); + var temp = new KrakenLiquidTemp(id, kraken, num); + tempDevice.addDevice(temp); - var fan = new KrakenFanSpeed(kraken, num); - mFanList.Add(fan); + id = string.Format("NZXT/KrakenX2/{0}/Fan", i); + var fan = new KrakenFanSpeed(id, kraken, num); + fanDevice.addDevice(fan); - var pump = new KrakenPumpSpeed(kraken, num); - mFanList.Add(pump); + id = string.Format("NZXT/KrakenX2/{0}/Pump", i); + var pump = new KrakenPumpSpeed(id, kraken, num); + fanDevice.addDevice(pump); - var fanControl = new KrakenFanControl(kraken, num); - mControlList.Add(fanControl); - this.addChangeValue(30, fanControl); + id = string.Format("NZXT/KrakenX2/{0}/Control/Fan", i); + var fanControl = new KrakenFanControl(id, kraken, num); + controlDevice.addDevice(fanControl); + this.addChangeValue(30, fanControl, false); - var pumpControl = new KrakenPumpControl(kraken, num); - mControlList.Add(pumpControl); - this.addChangeValue(50, pumpControl); + id = string.Format("NZXT/KrakenX2/{0}/Control/Pump", i); + var pumpControl = new KrakenPumpControl(id, kraken, num); + controlDevice.addDevice(pumpControl); + this.addChangeValue(50, pumpControl, false); num++; } } + if (tempDevice.DeviceList.Count > 0) + { + var tempList = TempList[(int)LIBRARY_TYPE.NZXT_Kraken]; + tempList.Add(tempDevice); + } + + if (fanDevice.DeviceList.Count > 0) + { + var fanList = FanList[(int)LIBRARY_TYPE.NZXT_Kraken]; + fanList.Add(fanDevice); + } + + if (controlDevice.DeviceList.Count > 0) + { + var controlList = ControlList[(int)LIBRARY_TYPE.NZXT_Kraken]; + controlList.Add(controlDevice); + } + // X3 + tempDevice = new HardwareDevice("NZXT Kraken X3"); + fanDevice = new HardwareDevice("NZXT Kraken X3"); + controlDevice = new HardwareDevice("NZXT Kraken X3"); devCount = HidUSBController.getDeviceCount(USBVendorID.NZXT, USBProductID.KrakenX3); for (uint i = 0; i < devCount; i++) { var kraken = new Kraken(); if (kraken.start(i, USBProductID.KrakenX3) == true) { - mKrakenList.Add(kraken); + KrakenList.Add(kraken); - var sensor = new KrakenLiquidTemp(kraken, num); - mSensorList.Add(sensor); + var id = string.Format("NZXT/KrakenX3/{0}/Temp", i); + var temp = new KrakenLiquidTemp(id, kraken, num); + tempDevice.addDevice(temp); - var pump = new KrakenPumpSpeed(kraken, num); - mFanList.Add(pump); + id = string.Format("NZXT/KrakenX3/{0}/Pump", i); + var pump = new KrakenPumpSpeed(id, kraken, num); + fanDevice.addDevice(pump); - var pumpControl = new KrakenPumpControl(kraken, num); - mControlList.Add(pumpControl); - this.addChangeValue(50, pumpControl); + id = string.Format("NZXT/KrakenX3/{0}/Control/Pump", i); + var pumpControl = new KrakenPumpControl(id, kraken, num); + controlDevice.addDevice(pumpControl); + this.addChangeValue(50, pumpControl, false); num++; } } + + if (tempDevice.DeviceList.Count > 0) + { + var tempList = TempList[(int)LIBRARY_TYPE.NZXT_Kraken]; + tempList.Add(tempDevice); + } + + if (fanDevice.DeviceList.Count > 0) + { + var fanList = FanList[(int)LIBRARY_TYPE.NZXT_Kraken]; + fanList.Add(fanDevice); + } + + if (controlDevice.DeviceList.Count > 0) + { + var controlList = ControlList[(int)LIBRARY_TYPE.NZXT_Kraken]; + controlList.Add(controlDevice); + } } catch { } } @@ -215,38 +408,68 @@ public void start() uint clcIndex = 0; // SiUSBController + var tempDevice = new HardwareDevice("EVGA CLC"); + var fanDevice = new HardwareDevice("EVGA CLC"); + var controlDevice = new HardwareDevice("EVGA CLC"); uint devCount = SiUSBController.getDeviceCount(USBVendorID.ASETEK, USBProductID.CLC); for (uint i = 0; i < devCount; i++) { var clc = new CLC(); if (clc.start(true, clcIndex, i) == true) { - mCLCList.Add(clc); + CLCList.Add(clc); - var sensor = new CLCLiquidTemp(clc, num); - mSensorList.Add(sensor); + var id = string.Format("EVGA/CLC/{0}/Temp", i); + var temp = new CLCLiquidTemp(id, clc, num); + tempDevice.addDevice(temp); - var fan = new CLCFanSpeed(clc, num); - mFanList.Add(fan); + id = string.Format("EVGA/CLC/{0}/Fan", i); + var fan = new CLCFanSpeed(id, clc, num); + fanDevice.addDevice(fan); - var pump = new CLCPumpSpeed(clc, num); - mFanList.Add(pump); + id = string.Format("EVGA/CLC/{0}/Pump", i); + var pump = new CLCPumpSpeed(id, clc, num); + fanDevice.addDevice(pump); - var fanControl = new CLCFanControl(clc, num); - mControlList.Add(fanControl); - this.addChangeValue(25, fanControl); + id = string.Format("EVGA/CLC/{0}/Control/Fan", i); + var fanControl = new CLCFanControl(id, clc, num); + controlDevice.addDevice(fanControl); + this.addChangeValue(25, fanControl, false); - var pumpControl = new CLCPumpControl(clc, num); - mControlList.Add(pumpControl); - this.addChangeValue(50, pumpControl); + id = string.Format("EVGA/CLC/{0}/Control/Pump", i); + var pumpControl = new CLCPumpControl(id, clc, num); + controlDevice.addDevice(pumpControl); + this.addChangeValue(50, pumpControl, false); clcIndex++; num++; } } + if (tempDevice.DeviceList.Count > 0) + { + var tempList = TempList[(int)LIBRARY_TYPE.EVGA_CLC]; + tempList.Add(tempDevice); + } + + if (fanDevice.DeviceList.Count > 0) + { + var fanList = FanList[(int)LIBRARY_TYPE.EVGA_CLC]; + fanList.Add(fanDevice); + } + + if (controlDevice.DeviceList.Count > 0) + { + var controlList = ControlList[(int)LIBRARY_TYPE.EVGA_CLC]; + controlList.Add(controlDevice); + } + if (WinUSBController.init() == true) { + tempDevice = new HardwareDevice("EVGA CLC"); + fanDevice = new HardwareDevice("EVGA CLC"); + controlDevice = new HardwareDevice("EVGA CLC"); + // WinUSBController devCount = WinUSBController.getDeviceCount(USBVendorID.ASETEK, USBProductID.CLC); for (uint i = 0; i < devCount; i++) @@ -254,29 +477,52 @@ public void start() var clc = new CLC(); if (clc.start(false, clcIndex, i) == true) { - mCLCList.Add(clc); + CLCList.Add(clc); - var sensor = new CLCLiquidTemp(clc, num); - mSensorList.Add(sensor); + var id = string.Format("EVGA/CLC/{0}/Temp", i); + var temp = new CLCLiquidTemp(id, clc, num); + tempDevice.addDevice(temp); - var fan = new CLCFanSpeed(clc, num); - mFanList.Add(fan); + id = string.Format("EVGA/CLC/{0}/Fan", i); + var fan = new CLCFanSpeed(id, clc, num); + fanDevice.addDevice(fan); - var pump = new CLCPumpSpeed(clc, num); - mFanList.Add(pump); + id = string.Format("EVGA/CLC/{0}/Pump", i); + var pump = new CLCPumpSpeed(id, clc, num); + fanDevice.addDevice(pump); - var fanControl = new CLCFanControl(clc, num); - mControlList.Add(fanControl); - this.addChangeValue(25, fanControl); + id = string.Format("EVGA/CLC/{0}/Control/Fan", i); + var fanControl = new CLCFanControl(id, clc, num); + controlDevice.addDevice(fanControl); + this.addChangeValue(25, fanControl, false); - var pumpControl = new CLCPumpControl(clc, num); - mControlList.Add(pumpControl); - this.addChangeValue(50, pumpControl); + id = string.Format("EVGA/CLC/{0}/Control/Pump", i); + var pumpControl = new CLCPumpControl(id, clc, num); + controlDevice.addDevice(pumpControl); + this.addChangeValue(50, pumpControl, false); clcIndex++; num++; } } + + if (tempDevice.DeviceList.Count > 0) + { + var tempList = TempList[(int)LIBRARY_TYPE.EVGA_CLC]; + tempList.Add(tempDevice); + } + + if (fanDevice.DeviceList.Count > 0) + { + var fanList = FanList[(int)LIBRARY_TYPE.EVGA_CLC]; + fanList.Add(fanDevice); + } + + if (controlDevice.DeviceList.Count > 0) + { + var controlList = ControlList[(int)LIBRARY_TYPE.EVGA_CLC]; + controlList.Add(controlDevice); + } } } catch { } @@ -286,6 +532,8 @@ public void start() { try { + var fanDevice = new HardwareDevice("NZXT RGB & Fan Controller"); + var controlDevice = new HardwareDevice("NZXT RGB & Fan Controller"); uint num = 1; uint devCount = HidUSBController.getDeviceCount(USBVendorID.NZXT, USBProductID.RGBAndFanController); for (uint i = 0; i < devCount; i++) @@ -293,73 +541,87 @@ public void start() var rgb = new RGBnFC(); if (rgb.start(i) == true) { - mRGBnFCList.Add(rgb); + RGBnFCList.Add(rgb); for (int j = 0; j < RGBnFC.MAX_FAN_COUNT; j++) { - var fan = new RGBnFCFanSpeed(rgb, j, num); - mFanList.Add(fan); + var id = string.Format("NZXT/RGBnFC/{0}/Fan/{1}", i, j); + var fan = new RGBnFCFanSpeed(id, rgb, j, num); + fanDevice.addDevice(fan); - var control = new RGBnFCControl(rgb, j, num); - mControlList.Add(control); - this.addChangeValue(control.getMinSpeed(), control); + id = string.Format("NZXT/RGBnFC/{0}/Control/{1}", i, j); + var control = new RGBnFCControl(id, rgb, j, num); + controlDevice.addDevice(control); + this.addChangeValue(control.getMinSpeed(), control, false); num++; } } } + + if (fanDevice.DeviceList.Count > 0) + { + var fanList = FanList[(int)LIBRARY_TYPE.RGBnFC]; + fanList.Add(fanDevice); + } + + if (controlDevice.DeviceList.Count > 0) + { + var controlList = ControlList[(int)LIBRARY_TYPE.RGBnFC]; + controlList.Add(controlDevice); + } } catch { } } - // DIMM thermal sensor - if (OptionManager.getInstance().IsDimm == true) + for (int i = 0; i < TempList.Count; i++) { - this.lockSMBus(0); - if (SMBusController.open(false) == true) + var deviceList = TempList[i]; + for (int j = 0; j < deviceList.Count; j++) { - int num = 1; - int busCount = SMBusController.getCount(); - - for (int i = 0; i < busCount; i++) + var device = deviceList[j]; + for (int k = 0; k < device.DeviceList.Count; k++) { - var detectBytes = SMBusController.i2cDetect(i); - if (detectBytes != null) - { - // 0x18 ~ 0x20 - for (int j = 0; j < detectBytes.Length; j++) - { - if (j < 24) - continue; - else if (j > 32) - break; - - if (detectBytes[j] == (byte)j) - { - var sensor = new DimmTemp("DIMM #" + num++, i, detectBytes[j]); - sensor.onSetDimmTemperature += onSetDimmTemperature; - mSensorList.Add(sensor); - } - } - } + var temp = device.DeviceList[k]; + TempBaseList.Add((BaseSensor)temp); + TempBaseMap.Add(temp.ID, (BaseSensor)temp); } } - this.unlockSMBus(); - } - - // Motherboard temperature - this.createMotherBoardTemp(); - - // GPU - this.createGPUTemp(); - this.createGPUFan(); - this.createGPUControl(); + } + for (int i = 0; i < FanList.Count; i++) + { + var deviceList = FanList[i]; + for (int j = 0; j < deviceList.Count; j++) + { + var device = deviceList[j]; + for (int k = 0; k < device.DeviceList.Count; k++) + { + var fan = device.DeviceList[k]; + FanBaseList.Add((BaseSensor)fan); + FanBaseMap.Add(fan.ID, (BaseSensor)fan); + } + } + } + for (int i = 0; i < ControlList.Count; i++) + { + var deviceList = ControlList[i]; + for (int j = 0; j < deviceList.Count; j++) + { + var device = deviceList[j]; + for (int k = 0; k < device.DeviceList.Count; k++) + { + var control = device.DeviceList[k]; + ControlBaseList.Add((BaseControl)control); + ControlBaseMap.Add(control.ID, (BaseControl)control); + } + } + } // osd sensor this.createOSDSensor(); Monitor.Exit(mLock); - } + } public void stop() { @@ -371,10 +633,18 @@ public void stop() } mIsStart = false; - mChangeControlList.Clear(); - mChangeValueList.Clear(); + if (mUpdateTimer != null) + { + mUpdateTimer.Stop(); + mUpdateTimer.Dispose(); + mUpdateTimer = null; + } - mUpdateTimer.Stop(); + if (mGigabyte != null) + { + mGigabyte.stop(); + mGigabyte = null; + } if (mLHM != null) { @@ -388,46 +658,53 @@ public void stop() mOHM = null; } - for (int i = 0; i < mKrakenList.Count; i++) + for (int i = 0; i < KrakenList.Count; i++) { try { - mKrakenList[i].stop(); + KrakenList[i].stop(); } catch { } } - mKrakenList.Clear(); + KrakenList.Clear(); - for (int i = 0; i < mCLCList.Count; i++) + for (int i = 0; i < CLCList.Count; i++) { try { - mCLCList[i].stop(); + CLCList[i].stop(); } catch { } } - mCLCList.Clear(); + CLCList.Clear(); - for (int i = 0; i < mRGBnFCList.Count; i++) + for (int i = 0; i < RGBnFCList.Count; i++) { try { - mRGBnFCList[i].stop(); + RGBnFCList[i].stop(); } catch { } } - mRGBnFCList.Clear(); + RGBnFCList.Clear(); - if (mIsGigabyte == true && mGigabyte != null) - { - mIsGigabyte = false; - mGigabyte.stop(); - mGigabyte = null; - } + mChangeControlList.Clear(); + mChangeValueList.Clear(); + + TempList.Clear(); + FanList.Clear(); + ControlList.Clear(); + + TempBaseList.Clear(); + FanBaseList.Clear(); + ControlBaseList.Clear(); - mSensorList.Clear(); - mFanList.Clear(); - mControlList.Clear(); + TempBaseMap.Clear(); + FanBaseMap.Clear(); + ControlBaseMap.Clear(); + + OSDSensorList.Clear(); + OSDSensorMap.Clear(); SMBusController.close(); @@ -464,6 +741,7 @@ public void startUpdate() return; } + mUpdateTimer = new System.Timers.Timer(); mUpdateTimer.Interval = OptionManager.getInstance().Interval; mUpdateTimer.Elapsed += onUpdateTimer; mUpdateTimer.Start(); @@ -471,7 +749,7 @@ public void startUpdate() Monitor.Exit(mLock); } - public void restartTimer(int interval) + public void restartTimer() { Monitor.Enter(mLock); if (mIsStart == false) @@ -479,7 +757,18 @@ public void restartTimer(int interval) Monitor.Exit(mLock); return; } - mUpdateTimer.Interval = interval; + + if (mUpdateTimer != null) + { + mUpdateTimer.Stop(); + mUpdateTimer.Dispose(); + mUpdateTimer = null; + } + + mUpdateTimer = new System.Timers.Timer(); + mUpdateTimer.Interval = OptionManager.getInstance().Interval; + mUpdateTimer.Elapsed += onUpdateTimer; + mUpdateTimer.Start(); Monitor.Exit(mLock); } @@ -539,7 +828,7 @@ private bool lockSMBus(int ms) { try { - return mSMBusMutex.WaitOne(ms); + return mSMBusMutex.WaitOne(ms, false); } catch { } return false; @@ -561,334 +850,188 @@ private void unlockSMBus() } catch { } } - - private void createTemp() - { - // Gigabyte - if (mIsGigabyte == true) - { - mGigabyte.createTemp(ref mSensorList); - } - - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) - { - mLHM.createTemp(ref mSensorList); - } - - // OpenHardwareMonitor - else - { - mOHM.createTemp(ref mSensorList); - } - } - - private void createMotherBoardTemp() + + private void createOSDSensor() { - if (mIsGigabyte == true) - return; - - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) - { - mLHM.createMotherBoardTemp(ref mSensorList); - } - - // OpenHardwareMonitor - else + // Temp + for (int i = 0; i < TempBaseList.Count; i++) { - mOHM.createMotherBoardTemp(ref mSensorList); + var device = TempBaseList[i]; + string id = device.ID; + string prefix = "[" + StringLib.Temperature + "] "; + string name = device.Name; + var osdSensor = new OSDSensor(id, prefix, name, OSDUnitType.Temperature); + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); } - } - private void createFan() - { - // Gigabyte - if (mIsGigabyte == true) + // Fan + for (int i = 0; i < FanBaseList.Count; i++) { - mGigabyte.createFan(ref mFanList); + var device = FanBaseList[i]; + string id = device.ID; + string prefix = "[" + StringLib.Fan_speed + "] "; + string name = device.Name; + var osdSensor = new OSDSensor(id, prefix, name, OSDUnitType.RPM); + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); } - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) + // Control + for (int i = 0; i < ControlBaseList.Count; i++) { - mLHM.createFan(ref mFanList); + var device = ControlBaseList[i]; + string id = device.ID; + string prefix = "[" + StringLib.Fan_control + "] "; + string name = device.Name; + var osdSensor = new OSDSensor(id, prefix, name, OSDUnitType.Percent); + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); } - // OpenHardwareMonitor - else - { - mOHM.createFan(ref mFanList); - } - } + // Framerate + string id2 = "OSD/Framerate"; + string prefix2 = "[" + StringLib.ETC + "] "; + string name2 = "Framerate"; + var osdSensor2 = new OSDSensor(id2, prefix2, name2, OSDUnitType.FPS); + OSDSensorList.Add(osdSensor2); + OSDSensorMap.Add(id2, osdSensor2); - private void createControl() - { - // Gigabyte - if (mIsGigabyte == true) - { - mGigabyte.createControl(ref mControlList); - } + // Blank + id2 = "OSD/Blank"; + name2 = "Blank"; + osdSensor2 = new OSDSensor(id2, prefix2, name2, OSDUnitType.Blank); + OSDSensorList.Add(osdSensor2); + OSDSensorMap.Add(id2, osdSensor2); - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) + //////////////// other sensor //////////////// + // LHM + if (OptionManager.getInstance().IsLHM == true && mLHM != null) { - mLHM.createControl(ref mControlList); + mLHM.createOSDSensor(OSDSensorList, OSDSensorMap); } - // OpenHardwareMonitor - else + // OHM + if (OptionManager.getInstance().IsOHM == true && mOHM != null) { - mOHM.createControl(ref mControlList); + mOHM.createOSDSensor(OSDSensorList, OSDSensorMap); } - } - private void createGPUTemp() - { + // NvAPIWrapper if (OptionManager.getInstance().IsNvAPIWrapper == true) { - this.lockBus(); try { - int gpuNum = 2; + string idPrefix = "NvAPIWrapper/OSD"; var gpuArray = PhysicalGPU.GetPhysicalGPUs(); for (int i = 0; i < gpuArray.Length; i++) { - var gpu = gpuArray[i]; - var name = gpu.FullName; - while (this.isExistTemp(name) == true) - { - name = gpu.FullName + " #" + gpuNum++; - } + int subIndex = 0; - var temp = new NvAPITemp(name, i); - temp.onGetNvAPITemperatureHandler += onGetNvAPITemperature; - mSensorList.Add(temp); + string id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + string prefix = "[Clock] "; + string name = "GPU Graphics"; + var osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.kHz, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Clock] "; + name = "GPU Memory"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.kHz, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Clock] "; + name = "GPU Processor"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.kHz, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Clock] "; + name = "GPU Video Decoding"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.kHz, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Load] "; + name = "GPU Core"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.Percent, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Load] "; + name = "GPU Frame Buffer"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.Percent, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Load] "; + name = "GPU Video Engine"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.Percent, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Load] "; + name = "GPU Bus Interface"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.Percent, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Load] "; + name = "GPU Memory"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.Percent, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Data] "; + name = "GPU Memory Free"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.KB, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Data] "; + name = "GPU Memory Used"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.KB, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); + + id = string.Format("{0}/{1}/{2}", idPrefix, i, subIndex); + prefix = "[Data] "; + name = "GPU Memory Total"; + osdSensor = new NvAPIOSDSensor(id, prefix, name, OSDUnitType.KB, i, subIndex++); + osdSensor.onNvAPIOSDSensorUpdate += onNvAPIOSDSensorUpdate; + OSDSensorList.Add(osdSensor); + OSDSensorMap.Add(id, osdSensor); } } - catch { } - this.unlockBus(); + catch { } } } - private void createGPUFan() + private void onSetDimmTemperature(object sender, int busIndex, byte address) { - // Gigabyte - if (mIsGigabyte == true) { } - - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) - { - mLHM.createGPUFan(ref mFanList); - } - - // OpenHardwareMonitor - else - { - mOHM.createGPUFan(ref mFanList); - } - - if (OptionManager.getInstance().IsNvAPIWrapper == true) - { - this.lockBus(); - try - { - int gpuFanNum = 1; - var gpuArray = PhysicalGPU.GetPhysicalGPUs(); - for (int i = 0; i < gpuArray.Length; i++) - { - var e = gpuArray[i].CoolerInformation.Coolers.GetEnumerator(); - while (e.MoveNext()) - { - var value = e.Current; - var name = "GPU Fan #" + gpuFanNum++; - while (this.isExistFan(name) == true) - { - name = "GPU Fan #" + gpuFanNum++; - } - - var fan = new NvAPIFanSpeed(name, i, value.CoolerId); - fan.onGetNvAPIFanSpeedHandler += onGetNvAPIFanSpeed; - mFanList.Add(fan); - } - } - } - catch { } - this.unlockBus(); - } - } - - private void createGPUControl() - { - // Gigabyte - if (mIsGigabyte == true) { } - - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) - { - mLHM.createGPUFanControl(ref mControlList); - } - - // OpenHardwareMonitor - else - { - mOHM.createGPUFanControl(ref mControlList); - } - - if (OptionManager.getInstance().IsNvAPIWrapper == true) - { - this.lockBus(); - try - { - int gpuFanNum = 1; - var gpuArray = PhysicalGPU.GetPhysicalGPUs(); - for (int i = 0; i < gpuArray.Length; i++) - { - var e = gpuArray[i].CoolerInformation.Coolers.GetEnumerator(); - while (e.MoveNext()) - { - var value = e.Current; - int coolerID = value.CoolerId; - int speed = value.CurrentLevel; - int minSpeed = 0;// value.DefaultMinimumLevel; - int maxSpeed = 100;// value.DefaultMaximumLevel; - - var name = "GPU Fan Control #" + gpuFanNum++; - while (this.isExistControl(name) == true) - { - name = "GPU Fan Control #" + gpuFanNum++; - } - - var control = new NvAPIFanControl(name, i, coolerID, speed, minSpeed, maxSpeed); - control.onSetNvAPIControlHandler += onSetNvApiControl; - mControlList.Add(control); - } - } - } - catch { } - this.unlockBus(); - } - } - - private void createOSDSensor() - { - if (mIsGigabyte == true) {} - - // LibreHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.LibreHardwareMonitor) - { - mLHM.createOSDSensor(ref mOSDSensorList); - } - - // OpenHardwareMonitor - else if (OptionManager.getInstance().LibraryType == LibraryType.OpenHardwareMonitor) - { - mOHM.createOSDSensor(ref mOSDSensorList); - } - - if (OptionManager.getInstance().IsNvAPIWrapper == true) - { - this.lockBus(); - try - { - var gpuArray = PhysicalGPU.GetPhysicalGPUs(); - for (int i = 0; i < gpuArray.Length; i++) - { - int subIndex = 0; - - var osdSensor = new OSDSensor(OSDUnitType.kHz, "[Clock] GPU Graphics", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.kHz, "[Clock] GPU Memory", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.kHz, "[Clock] GPU Processor", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.kHz, "[Clock] GPU Video Decoding", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.Percent, "[Load] GPU Core", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.Percent, "[Load] GPU Frame Buffer", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.Percent, "[Load] GPU Video Engine", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.Percent, "[Load] GPU Bus Interface", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.Percent, "[Load] GPU Memory", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.KB, "[Data] GPU Memory Free", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.KB, "[Data] GPU Memory Used", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - - osdSensor = new OSDSensor(OSDUnitType.KB, "[Data] GPU Memory Total", i, subIndex++); - osdSensor.onOSDSensorUpdate += onOSDSensorUpdate; - mOSDSensorList.Add(osdSensor); - } - } - catch { } - this.unlockBus(); - } - } - - private bool isExistTemp(string name) - { - for (int i = 0; i < mSensorList.Count; i++) - { - if (mSensorList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private bool isExistFan(string name) - { - for (int i = 0; i < mFanList.Count; i++) - { - if (mFanList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private bool isExistControl(string name) - { - for (int i = 0; i < mControlList.Count; i++) - { - if (mControlList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private void onSetDimmTemperature(object sender, int busIndex, byte address) - { - var sensor = (DimmTemp)sender; + var sensor = (DimmTemp)sender; if (this.lockSMBus(10) == false) return; @@ -918,7 +1061,6 @@ private void onSetDimmTemperature(object sender, int busIndex, byte address) private int onGetNvAPITemperature(int index) { - this.lockBus(); int temp = 0; try { @@ -937,14 +1079,12 @@ private int onGetNvAPITemperature(int index) break; } } - catch { } - this.unlockBus(); + catch { } return temp; } private int onGetNvAPIFanSpeed(int index, int coolerID) { - this.lockBus(); int speed = 0; try { @@ -967,13 +1107,11 @@ private int onGetNvAPIFanSpeed(int index, int coolerID) } } catch { } - this.unlockBus(); return speed; } private void onSetNvApiControl(int index, int coolerID, int value) { - this.lockBus(); try { var gpuArray = PhysicalGPU.GetPhysicalGPUs(); @@ -985,67 +1123,61 @@ private void onSetNvApiControl(int index, int coolerID, int value) var info = gpuArray[index].CoolerInformation; info.SetCoolerSettings(coolerID, value); } - catch { } - this.unlockBus(); + catch { } } - private double onOSDSensorUpdate(OSDLibraryType libraryType, int index, int subIndex) + private double onNvAPIOSDSensorUpdate(int index, int subIndex) { double value = 0; - if (libraryType == OSDLibraryType.NvApiWrapper) - { - this.lockBus(); - try + try + { + var gpuArray = PhysicalGPU.GetPhysicalGPUs(); + var gpu = gpuArray[index]; + + switch (subIndex) { - var gpuArray = PhysicalGPU.GetPhysicalGPUs(); - var gpu = gpuArray[index]; - - switch (subIndex) - { - case 0: - value = (double)gpu.CurrentClockFrequencies.GraphicsClock.Frequency; - break; - case 1: - value = (double)gpu.CurrentClockFrequencies.MemoryClock.Frequency; - break; - case 2: - value = (double)gpu.CurrentClockFrequencies.ProcessorClock.Frequency; - break; - case 3: - value = (double)gpu.CurrentClockFrequencies.VideoDecodingClock.Frequency; - break; - case 4: - value = (double)gpu.UsageInformation.GPU.Percentage; - break; - case 5: - value = (double)gpu.UsageInformation.FrameBuffer.Percentage; - break; - case 6: - value = (double)gpu.UsageInformation.VideoEngine.Percentage; - break; - case 7: - value = (double)gpu.UsageInformation.BusInterface.Percentage; - break; - case 8: - value = (double)(((double)gpu.MemoryInformation.PhysicalFrameBufferSizeInkB - (double)gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB) / (double)gpu.MemoryInformation.PhysicalFrameBufferSizeInkB * 100.0); - break; - case 9: - value = (double)gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB; - break; - case 10: - value = (double)(gpu.MemoryInformation.PhysicalFrameBufferSizeInkB - gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB); - break; - case 11: - value = (double)gpu.MemoryInformation.PhysicalFrameBufferSizeInkB; - break; - default: - value = 0; - break; - } + case 0: + value = (double)gpu.CurrentClockFrequencies.GraphicsClock.Frequency; + break; + case 1: + value = (double)gpu.CurrentClockFrequencies.MemoryClock.Frequency; + break; + case 2: + value = (double)gpu.CurrentClockFrequencies.ProcessorClock.Frequency; + break; + case 3: + value = (double)gpu.CurrentClockFrequencies.VideoDecodingClock.Frequency; + break; + case 4: + value = (double)gpu.UsageInformation.GPU.Percentage; + break; + case 5: + value = (double)gpu.UsageInformation.FrameBuffer.Percentage; + break; + case 6: + value = (double)gpu.UsageInformation.VideoEngine.Percentage; + break; + case 7: + value = (double)gpu.UsageInformation.BusInterface.Percentage; + break; + case 8: + value = (double)(((double)gpu.MemoryInformation.PhysicalFrameBufferSizeInkB - (double)gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB) / (double)gpu.MemoryInformation.PhysicalFrameBufferSizeInkB * 100.0); + break; + case 9: + value = (double)gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB; + break; + case 10: + value = (double)(gpu.MemoryInformation.PhysicalFrameBufferSizeInkB - gpu.MemoryInformation.CurrentAvailableDedicatedVideoMemoryInkB); + break; + case 11: + value = (double)gpu.MemoryInformation.PhysicalFrameBufferSizeInkB; + break; + default: + value = 0; + break; } - catch { } - this.unlockBus(); } + catch { } return value; } @@ -1055,7 +1187,7 @@ private void onUpdateTimer(object sender, EventArgs e) return; #if MY_DEBUG - if (ControlManager.getInstance().ModeIndex == 2) + if (ControlManager.getInstance().ModeType == MODE_TYPE.PERFORMANCE) { if (mDebugUpdateCount <= 0) { @@ -1070,93 +1202,143 @@ private void onUpdateTimer(object sender, EventArgs e) } #endif - if (mIsGigabyte == true && mGigabyte != null) + try { - mGigabyte.update(); + if (mGigabyte != null) + { + mGigabyte.update(); + } } + catch { } - if (mLHM != null) + try { - mLHM.update(); + if (mLHM != null) + { + mLHM.update(); + } } + catch { } - if (mOHM != null) + try { - mOHM.update(); + if (mOHM != null) + { + mOHM.update(); + } } + catch { } - for (int i = 0; i < mSensorList.Count; i++) + try { - mSensorList[i].update(); - } + for (int i = 0; i < (int)LIBRARY_TYPE.MAX; i++) + { + var tempList = TempList[i]; + for (int j = 0; j < tempList.Count; j++) + { + var deviceList = tempList[j].DeviceList; + for (int k = 0; k < deviceList.Count; k++) + { + var temp = deviceList[k]; + temp.update(); + } + } - for (int i = 0; i < mFanList.Count; i++) - { - mFanList[i].update(); - } + var fanList = FanList[i]; + for (int j = 0; j < fanList.Count; j++) + { + var deviceList = fanList[j].DeviceList; + for (int k = 0; k < deviceList.Count; k++) + { + var fan = deviceList[k]; + fan.update(); + } + } - for (int i = 0; i < mControlList.Count; i++) - { - mControlList[i].update(); + var controlList = ControlList[i]; + for (int j = 0; j < controlList.Count; j++) + { + var deviceList = controlList[j].DeviceList; + for (int k = 0; k < deviceList.Count; k++) + { + var control = deviceList[k]; + control.update(); + } + } + } } + catch { } - // change value - bool isExistChange = false; - if (mChangeValueList.Count > 0) + try { - for (int i = 0; i < mChangeControlList.Count; i++) + // change value + bool isExistChange = false; + if (mChangeValueList.Count > 0) { - isExistChange = true; - mChangeControlList[i].setSpeed(mChangeValueList[i]); + for (int i = 0; i < mChangeControlList.Count; i++) + { + isExistChange = true; + mChangeControlList[i].setSpeed(mChangeValueList[i]); + } + mChangeControlList.Clear(); + mChangeValueList.Clear(); } - mChangeControlList.Clear(); - mChangeValueList.Clear(); - } - - // Control - var controlManager = ControlManager.getInstance(); - if (controlManager.IsEnable == true && isExistChange == false) - { - var controlDictionary = new Dictionary(); - int modeIndex = controlManager.ModeIndex; - for (int i = 0; i < controlManager.getControlDataCount(modeIndex); i++) + // Control + var controlDictionary = new Dictionary(); + var controlManager = ControlManager.getInstance(); + if (controlManager.IsEnable == true && isExistChange == false) { - var controlData = controlManager.getControlData(modeIndex, i); - if (controlData == null) - break; - - int sensorIndex = controlData.Index; - int temperature = mSensorList[sensorIndex].Value; + var tempBaseMap = HardwareManager.getInstance().TempBaseMap; + var controlBaseMap = HardwareManager.getInstance().ControlBaseMap; - for (int j = 0; j < controlData.FanDataList.Count; j++) + var controlDataList = controlManager.getControlDataList(controlManager.ModeType); + for (int i = 0; i < controlDataList.Count; i++) { - var fanData = controlData.FanDataList[j]; - int controlIndex = fanData.Index; - int percent = fanData.getValue(temperature); + var controlData = controlDataList[i]; + if (controlData == null) + break; - var control = mControlList[controlIndex]; + string tempID = controlData.ID; + if (tempBaseMap.ContainsKey(tempID) == false) + continue; - if (controlDictionary.ContainsKey(controlIndex) == false) - { - controlDictionary[controlIndex] = control; - control.NextValue = percent; - } - else + var tempDevice = tempBaseMap[tempID]; + int temperature = tempDevice.Value; + + for (int j = 0; j < controlData.FanDataList.Count; j++) { - control.NextValue = (control.NextValue >= percent) ? control.NextValue : percent; + var fanData = controlData.FanDataList[j]; + + string fanID = fanData.ID; + if (controlBaseMap.ContainsKey(fanID) == false) + continue; + + var controlDevice = controlBaseMap[fanID]; + int percent = fanData.getValue(temperature); + + if (controlDictionary.ContainsKey(fanID) == false) + { + controlDictionary.Add(fanID, controlDevice); + controlDevice.NextValue = percent; + } + else + { + controlDevice.NextValue = (controlDevice.NextValue >= percent) ? controlDevice.NextValue : percent; + } } } - } - foreach (var keyPair in controlDictionary) - { - var control = keyPair.Value; - if (control.Value == control.NextValue) - continue; - control.setSpeed(control.NextValue); + foreach (var keyPair in controlDictionary) + { + var control = keyPair.Value; + if (control.Value == control.NextValue) + continue; + control.setSpeed(control.NextValue); + } } } + catch { } // onUpdateCallback onUpdateCallback(); @@ -1205,13 +1387,15 @@ private void onUpdateTimer(object sender, EventArgs e) osdManager.IsUpdate = false; } } - Monitor.Exit(mLock); } - public int addChangeValue(int value, BaseControl control) + public int addChangeValue(int value, BaseControl control, bool isLock = true) { - Monitor.Enter(mLock); + if (isLock == true) + { + Monitor.Enter(mLock); + } if (value < control.getMinSpeed()) { value = control.getMinSpeed(); @@ -1222,92 +1406,181 @@ public int addChangeValue(int value, BaseControl control) } mChangeValueList.Add(value); mChangeControlList.Add(control); - Monitor.Exit(mLock); - return value; - } - - public int getSensorCount() - { - Monitor.Enter(mLock); - int count = mSensorList.Count; - Monitor.Exit(mLock); - return count; - } - public BaseSensor getSensor(int index) - { - Monitor.Enter(mLock); - if (index >= mSensorList.Count) + if (isLock == true) { Monitor.Exit(mLock); - return null; } - var sensor = mSensorList[index]; - Monitor.Exit(mLock); - return sensor; - } - - public int getFanCount() - { - Monitor.Enter(mLock); - int count = mFanList.Count; - Monitor.Exit(mLock); - return count; + return value; } - public BaseSensor getFan(int index) + public bool read(ref bool isDifferent) { Monitor.Enter(mLock); - if (index >= mFanList.Count) + String jsonString; + try + { + jsonString = File.ReadAllText(mHardwareFileName); + } + catch { Monitor.Exit(mLock); - return null; + this.write(); + return false; } - var fan = mFanList[index]; - Monitor.Exit(mLock); - return fan; - } - public int getControlCount() - { - Monitor.Enter(mLock); - int count = mControlList.Count; - Monitor.Exit(mLock); - return count; - } + try + { + var rootObject = JObject.Parse(jsonString); - public BaseControl getControl(int index) - { - Monitor.Enter(mLock); - if (index >= mControlList.Count) + // name + if (rootObject.ContainsKey("name") == true) + { + var nameObject = rootObject.Value("name"); + + // temperature name + if (nameObject.ContainsKey("temp") == true) + { + var list = nameObject.Value("temp"); + for (int i = 0; i < list.Count; i++) + { + var jobject = list[i]; + string id = jobject.Value("id"); + string name = jobject.Value("name"); + + if (TempBaseMap.ContainsKey(id) == false) + { + isDifferent = true; + continue; + } + + var device = TempBaseMap[id]; + device.Name = name; + + if (OSDSensorMap.ContainsKey(id) == true) + { + var sensor = OSDSensorMap[id]; + sensor.Name = name; + } + } + } + + // fan name + if (nameObject.ContainsKey("fan") == true) + { + var list = nameObject.Value("fan"); + for (int i = 0; i < list.Count; i++) + { + var jobject = list[i]; + string id = jobject.Value("id"); + string name = jobject.Value("name"); + + if (FanBaseMap.ContainsKey(id) == false) + { + isDifferent = true; + continue; + } + + var device = FanBaseMap[id]; + device.Name = name; + + if (OSDSensorMap.ContainsKey(id) == true) + { + var sensor = OSDSensorMap[id]; + sensor.Name = name; + } + } + } + + // control name + if (nameObject.ContainsKey("control") == true) + { + var list = nameObject.Value("control"); + for (int i = 0; i < list.Count; i++) + { + var jobject = list[i]; + string id = jobject.Value("id"); + string name = jobject.Value("name"); + + if (ControlBaseMap.ContainsKey(id) == false) + { + isDifferent = true; + continue; + } + + var device = ControlBaseMap[id]; + device.Name = name; + + if (OSDSensorMap.ContainsKey(id) == true) + { + var sensor = OSDSensorMap[id]; + sensor.Name = name; + } + } + } + } + } + catch { Monitor.Exit(mLock); - return null; + return false; } - var control = mControlList[index]; Monitor.Exit(mLock); - return control; + return true; } - public int getOSDSensorCount() + public void write() { Monitor.Enter(mLock); - int count = mOSDSensorList.Count; - Monitor.Exit(mLock); - return count; - } - - public OSDSensor getOSDSensor(int index) - { - Monitor.Enter(mLock); - if (index >= mOSDSensorList.Count) + try { - Monitor.Exit(mLock); - return null; + var rootObject = new JObject(); + + // name + var nameObject = new JObject(); + + // temp name + var tempList = new JArray(); + for (int i = 0; i < TempBaseList.Count; i++) + { + var device = TempBaseList[i]; + var jobject = new JObject(); + jobject["id"] = device.ID; + jobject["name"] = device.Name; + tempList.Add(jobject); + } + nameObject["temp"] = tempList; + + // fan name + var fanList = new JArray(); + for (int i = 0; i < FanBaseList.Count; i++) + { + var device = FanBaseList[i]; + var jobject = new JObject(); + jobject["id"] = device.ID; + jobject["name"] = device.Name; + fanList.Add(jobject); + } + nameObject["fan"] = fanList; + + // control name + var controlList = new JArray(); + for (int i = 0; i < ControlBaseList.Count; i++) + { + var device = ControlBaseList[i]; + var jobject = new JObject(); + jobject["id"] = device.ID; + jobject["name"] = device.Name; + controlList.Add(jobject); + } + nameObject["control"] = controlList; + + rootObject["name"] = nameObject; + + File.WriteAllText(mHardwareFileName, rootObject.ToString()); } - var other = mOSDSensorList[index]; + catch { } Monitor.Exit(mLock); - return other; } } } diff --git a/FanCtrl/Hardware/LHM.cs b/FanCtrl/Hardware/LHM.cs index 1d27767..e054da4 100644 --- a/FanCtrl/Hardware/LHM.cs +++ b/FanCtrl/Hardware/LHM.cs @@ -7,6 +7,11 @@ namespace FanCtrl { public class LHM : IVisitor { + private const string mIDPrefixTemperature = "LHM/Temp"; + private const string mIDPrefixFan = "LHM/Fan"; + private const string mIDPrefixControl = "LHM/Control"; + private const string mIDPrefixOSD = "LHM/OSD"; + private bool mIsStart = false; private Computer mComputer = null; @@ -20,11 +25,12 @@ public void start() mIsStart = true; mComputer = new Computer(); - mComputer.IsCpuEnabled = true; + mComputer.IsCpuEnabled = OptionManager.getInstance().IsLHMCpu; + mComputer.IsMotherboardEnabled = OptionManager.getInstance().IsLHMMotherboard; + mComputer.IsControllerEnabled = OptionManager.getInstance().IsLHMContolled; + mComputer.IsGpuEnabled = OptionManager.getInstance().IsLHMGpu; + mComputer.IsStorageEnabled = OptionManager.getInstance().IsLHMStorage; mComputer.IsMemoryEnabled = true; - mComputer.IsMotherboardEnabled = true; - mComputer.IsControllerEnabled = true; - mComputer.IsGpuEnabled = true; mComputer.Open(); mComputer.Accept(this); @@ -43,78 +49,24 @@ public void stop() } } - public void createTemp(ref List sensorList) - { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; - - // CPU, GPU - int cpuNum = 2; - int gpuAmdNum = 2; - int gpuNvidiaNum = 2; - var hardwareArray = mComputer.Hardware; - for (int i = 0; i < hardwareArray.Count; i++) - { - if (hardwareArray[i].HardwareType == HardwareType.Cpu) - { - string name = hardwareArray[i].Name; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = hardwareArray[i].Name + " #" + cpuNum++; - } - var sensor = new HardwareTemp(hardwareArray[i], name); - sensorList.Add(sensor); - } - - if (hardwareArray[i].HardwareType == HardwareType.GpuAmd) - { - string name = hardwareArray[i].Name; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = hardwareArray[i].Name + " #" + gpuAmdNum++; - } - var sensor = new HardwareTemp(hardwareArray[i], name); - sensorList.Add(sensor); - } - - else if (hardwareArray[i].HardwareType == HardwareType.GpuNvidia && isNvAPIWrapper == false) - { - string name = hardwareArray[i].Name; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = hardwareArray[i].Name + " #" + gpuNvidiaNum++; - } - var sensor = new HardwareTemp(hardwareArray[i], name); - sensorList.Add(sensor); - } - } - } - - public void createMotherBoardTemp(ref List sensorList) + public void createTemp(ref List deviceList) { - // Motherboard - int num = 1; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Count; i++) { - if (hardwareArray[i].HardwareType == HardwareType.Cpu || - hardwareArray[i].HardwareType == HardwareType.GpuAmd || - hardwareArray[i].HardwareType == HardwareType.GpuNvidia) - { - continue; - } + string hardwareName = (hardwareArray[i].Name.Length > 0) ? hardwareArray[i].Name : "Unknown"; + var device = new HardwareDevice(hardwareName); var sensorArray = hardwareArray[i].Sensors; for (int j = 0; j < sensorArray.Length; j++) { - if (sensorArray[j].SensorType != LibreHardwareMonitor.Hardware.SensorType.Temperature) + if (sensorArray[j].SensorType != SensorType.Temperature) continue; - string originName = sensorArray[j].Name.ToUpper(); - if (originName.Contains("CPU") == true) - continue; - - var sensor = new HardwareMotherBoardTemp(sensorArray[j], "Motherboard #" + num++); - sensorList.Add(sensor); + string id = string.Format("{0}{1}", mIDPrefixTemperature, sensorArray[j].Identifier.ToString()); + string name = (sensorArray[j].Name.Length > 0) ? sensorArray[j].Name : "Temperature"; + var sensor = new LHMTemp(id, sensorArray[j], name); + device.addDevice(sensor); } var subHardwareArray = hardwareArray[i].SubHardware; @@ -123,78 +75,84 @@ public void createMotherBoardTemp(ref List sensorList) var subSensorList = subHardwareArray[j].Sensors; for (int k = 0; k < subSensorList.Length; k++) { - if (subSensorList[k].SensorType != LibreHardwareMonitor.Hardware.SensorType.Temperature) - continue; - - string originName = subSensorList[k].Name.ToUpper(); - if (originName.Contains("CPU") == true) + if (subSensorList[k].SensorType != SensorType.Temperature) continue; - var sensor = new HardwareMotherBoardTemp(subSensorList[k], "Motherboard #" + num++); - sensorList.Add(sensor); + string id = string.Format("{0}{1}", mIDPrefixTemperature, subSensorList[k].Identifier.ToString()); + string name = (subSensorList[k].Name.Length > 0) ? subSensorList[k].Name : "Temperature"; + var sensor = new LHMTemp(id, subSensorList[k], name); + device.addDevice(sensor); } } + + if (device.DeviceList.Count > 0) + { + deviceList.Add(device); + } } } - public void createFan(ref List fanList) + public void createFan(ref List deviceList) { - int fanNum = 1; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Count; i++) { - if (hardwareArray[i].HardwareType == HardwareType.GpuNvidia || - hardwareArray[i].HardwareType == HardwareType.GpuAmd) - { - continue; - } + string hardwareName = (hardwareArray[i].Name.Length > 0) ? hardwareArray[i].Name : "Unknown"; + var device = new HardwareDevice(hardwareName); var sensorArray = hardwareArray[i].Sensors; for (int j = 0; j < sensorArray.Length; j++) { - if (sensorArray[j].SensorType != LibreHardwareMonitor.Hardware.SensorType.Fan) + if (sensorArray[j].SensorType != SensorType.Fan) continue; - var fan = new HardwareFanSpeed(sensorArray[j], "Fan #" + fanNum++); - fanList.Add(fan); + string id = string.Format("{0}{1}", mIDPrefixFan, sensorArray[j].Identifier.ToString()); + string name = (sensorArray[j].Name.Length > 0) ? sensorArray[j].Name : "Fan"; + var sensor = new LHMFanSpeed(id, sensorArray[j], name); + device.addDevice(sensor); } var subHardwareArray = hardwareArray[i].SubHardware; for (int j = 0; j < subHardwareArray.Length; j++) { - var subSensorArray = subHardwareArray[j].Sensors; - for (int k = 0; k < subSensorArray.Length; k++) + var subSensorList = subHardwareArray[j].Sensors; + for (int k = 0; k < subSensorList.Length; k++) { - if (subSensorArray[k].SensorType != LibreHardwareMonitor.Hardware.SensorType.Fan) + if (subSensorList[k].SensorType != SensorType.Fan) continue; - var fan = new HardwareFanSpeed(subSensorArray[k], "Fan #" + fanNum++); - fanList.Add(fan); + string id = string.Format("{0}{1}", mIDPrefixFan, subSensorList[k].Identifier.ToString()); + string name = (subSensorList[k].Name.Length > 0) ? subSensorList[k].Name : "Fan"; + var sensor = new LHMFanSpeed(id, subSensorList[k], name); + device.addDevice(sensor); } } + + if (device.DeviceList.Count > 0) + { + deviceList.Add(device); + } } } - public void createControl(ref List controlList) + public void createControl(ref List deviceList) { - int fanNum = 1; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Count; i++) { - if (hardwareArray[i].HardwareType == HardwareType.GpuNvidia || - hardwareArray[i].HardwareType == HardwareType.GpuAmd) - { - continue; - } + string hardwareName = (hardwareArray[i].Name.Length > 0) ? hardwareArray[i].Name : "Unknown"; + var device = new HardwareDevice(hardwareName); var sensorArray = hardwareArray[i].Sensors; for (int j = 0; j < sensorArray.Length; j++) { - if (sensorArray[j].SensorType != LibreHardwareMonitor.Hardware.SensorType.Control) + if (sensorArray[j].SensorType != SensorType.Control) continue; - var control = new HardwareControl(sensorArray[j], "Fan Control #" + fanNum++); - controlList.Add(control); + string id = string.Format("{0}{1}", mIDPrefixControl, sensorArray[j].Identifier.ToString()); + string name = (sensorArray[j].Name.Length > 0) ? sensorArray[j].Name : "Control"; + var sensor = new LHMControl(id, sensorArray[j], name); + device.addDevice(sensor); } var subHardwareArray = hardwareArray[i].SubHardware; @@ -203,207 +161,103 @@ public void createControl(ref List controlList) var subSensorList = subHardwareArray[j].Sensors; for (int k = 0; k < subSensorList.Length; k++) { - if (subSensorList[k].SensorType != LibreHardwareMonitor.Hardware.SensorType.Control) + if (subSensorList[k].SensorType != SensorType.Control) continue; - var control = new HardwareControl(subSensorList[k], "Fan Control #" + fanNum++); - controlList.Add(control); + string id = string.Format("{0}{1}", mIDPrefixControl, subSensorList[k].Identifier.ToString()); + string name = (subSensorList[k].Name.Length > 0) ? subSensorList[k].Name : "Control"; + var sensor = new LHMControl(id, subSensorList[k], name); + device.addDevice(sensor); } } - } - } - public void createGPUFan(ref List fanList) - { - bool isNvAPIWrapper =OptionManager.getInstance().IsNvAPIWrapper; - - int gpuFanNum = 1; - var hardwareArray = mComputer.Hardware; - for (int i = 0; i < hardwareArray.Count; i++) - { - if ((hardwareArray[i].HardwareType == HardwareType.GpuNvidia && isNvAPIWrapper == false) || - (hardwareArray[i].HardwareType == HardwareType.GpuAmd)) + if (device.DeviceList.Count > 0) { - var sensorArray = hardwareArray[i].Sensors; - for (int j = 0; j < sensorArray.Length; j++) - { - if (sensorArray[j].SensorType == LibreHardwareMonitor.Hardware.SensorType.Fan) - { - var name = "GPU Fan #" + gpuFanNum++; - while (this.isExistFan(ref fanList, name) == true) - { - name = "GPU Fan #" + gpuFanNum++; - } - - var fan = new HardwareFanSpeed(sensorArray[j], name); - fanList.Add(fan); - } - } - - var subHardwareArray = hardwareArray[i].SubHardware; - for (int j = 0; j < subHardwareArray.Length; j++) - { - var subSensorList = subHardwareArray[j].Sensors; - for (int k = 0; k < subSensorList.Length; k++) - { - if (subSensorList[k].SensorType == LibreHardwareMonitor.Hardware.SensorType.Fan) - { - var name = "GPU Fan #" + gpuFanNum++; - while (this.isExistFan(ref fanList, name) == true) - { - name = "GPU Fan #" + gpuFanNum++; - } - - var fan = new HardwareFanSpeed(subSensorList[k], name); - fanList.Add(fan); - } - } - } - } - } - } - - public void createGPUFanControl(ref List controlList) - { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; - - int gpuFanNum = 1; - var hardwareArray = mComputer.Hardware; - for (int i = 0; i < hardwareArray.Count; i++) - { - if ((hardwareArray[i].HardwareType == HardwareType.GpuNvidia && isNvAPIWrapper == false) || - (hardwareArray[i].HardwareType == HardwareType.GpuAmd)) - { - var sensorArray = hardwareArray[i].Sensors; - for (int j = 0; j < sensorArray.Length; j++) - { - if (sensorArray[j].SensorType == LibreHardwareMonitor.Hardware.SensorType.Control) - { - var name = "GPU Fan Control #" + gpuFanNum++; - while (this.isExistControl(ref controlList, name) == true) - { - name = "GPU Fan Control #" + gpuFanNum++; - } - - var control = new HardwareControl(sensorArray[j], name); - controlList.Add(control); - } - } - - var subHardwareArray = hardwareArray[i].SubHardware; - for (int j = 0; j < subHardwareArray.Length; j++) - { - var subSensorList = subHardwareArray[j].Sensors; - for (int k = 0; k < subSensorList.Length; k++) - { - if (subSensorList[k].SensorType == LibreHardwareMonitor.Hardware.SensorType.Control) - { - var name = "GPU Fan Control #" + gpuFanNum++; - while (this.isExistControl(ref controlList, name) == true) - { - name = "GPU Fan Control #" + gpuFanNum++; - } - - var control = new HardwareControl(subSensorList[k], name); - controlList.Add(control); - } - } - } + deviceList.Add(device); } } } - public void createOSDSensor(ref List osdList) + public void createOSDSensor(List osdList, Dictionary osdMap) { try { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Count; i++) { - if (isNvAPIWrapper == true && hardwareArray[i].HardwareType == HardwareType.GpuNvidia) - continue; - var sensorArray = hardwareArray[i].Sensors; - this.setOSDSensor(sensorArray, SensorType.Load, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Clock, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Voltage, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Data, ref osdList); - this.setOSDSensor(sensorArray, SensorType.SmallData, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Power, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Throughput, ref osdList); + this.setOSDSensor(sensorArray, SensorType.Load, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Clock, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Voltage, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Data, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.SmallData, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Power, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Throughput, osdList, osdMap); var subHardwareArray = hardwareArray[i].SubHardware; for (int j = 0; j < subHardwareArray.Length; j++) { var subSensorArray = subHardwareArray[j].Sensors; - this.setOSDSensor(subSensorArray, SensorType.Load, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Clock, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Voltage, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Data, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.SmallData, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Power, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Throughput, ref osdList); + this.setOSDSensor(subSensorArray, SensorType.Load, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Clock, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Voltage, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Data, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.SmallData, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Power, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Throughput, osdList, osdMap); } } } catch { } } - private void setOSDSensor(ISensor[] sensorArray, SensorType sensorType, ref List osdList) + private void setOSDSensor(ISensor[] sensorArray, SensorType sensorType, List osdList, Dictionary osdMap) { - var sensorList = new List(); for (int i = 0; i < sensorArray.Length; i++) { + var sensor = sensorArray[i]; if (sensorArray[i].SensorType != sensorType) { continue; - } - sensorList.Add(sensorArray[i]); - } - - for (int i = 0; i < sensorList.Count; i++) - { - var sensor = sensorList[i]; + } - int index = osdList.Count; OSDUnitType unitType = OSDUnitType.Unknown; - string sensorName = ""; - switch (sensorList[i].SensorType) + string prefix = ""; + switch (sensorArray[i].SensorType) { case SensorType.Voltage: unitType = OSDUnitType.Voltage; - sensorName = "[Voltage] "; + prefix = "[Voltage] "; break; case SensorType.Power: unitType = OSDUnitType.Power; - sensorName = "[Power] "; + prefix = "[Power] "; break; case SensorType.Load: unitType = OSDUnitType.Percent; - sensorName = "[Load] "; + prefix = "[Load] "; break; case SensorType.Clock: unitType = OSDUnitType.MHz; - sensorName = "[Clock] "; + prefix = "[Clock] "; break; case SensorType.Data: unitType = OSDUnitType.GB; - sensorName = "[Data] "; + prefix = "[Data] "; break; case SensorType.SmallData: unitType = OSDUnitType.MB; - sensorName = "[Data] "; + prefix = "[Data] "; break; case SensorType.Throughput: unitType = OSDUnitType.MBPerSec; - sensorName = "[Throughput] "; + prefix = "[Throughput] "; break; default: @@ -414,8 +268,10 @@ private void setOSDSensor(ISensor[] sensorArray, SensorType sensorType, ref List if (unitType == OSDUnitType.Unknown) continue; - var osdSensor = new OSDSensor(sensorList[i], unitType, sensorName + sensorList[i].Name, index); + string id = string.Format("{0}{1}", mIDPrefixOSD, sensor.Identifier.ToString()); + var osdSensor = new LHMOSDSensor(id, prefix, sensorArray[i].Name, unitType, sensor); osdList.Add(osdSensor); + osdMap.Add(id, osdSensor); } } @@ -423,43 +279,7 @@ public void update() { mComputer.Accept(this); } - - private bool isExistTemp(ref List sensorList, string name) - { - for (int i = 0; i < sensorList.Count; i++) - { - if (sensorList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private bool isExistFan(ref List fanList, string name) - { - for (int i = 0; i < fanList.Count; i++) - { - if (fanList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private bool isExistControl(ref List controlList, string name) - { - for (int i = 0; i < controlList.Count; i++) - { - if (controlList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - + /////////////////////////// Visitor /////////////////////////// public void VisitComputer(IComputer computer) { diff --git a/FanCtrl/Hardware/OHM.cs b/FanCtrl/Hardware/OHM.cs index 6016c02..e429718 100644 --- a/FanCtrl/Hardware/OHM.cs +++ b/FanCtrl/Hardware/OHM.cs @@ -7,6 +7,11 @@ namespace FanCtrl { public class OHM : IVisitor { + private const string mIDPrefixTemperature = "OHM/Temp"; + private const string mIDPrefixFan = "OHM/Fan"; + private const string mIDPrefixControl = "OHM/Control"; + private const string mIDPrefixOSD = "OHM/OSD"; + private bool mIsStart = false; private Computer mComputer = null; @@ -20,11 +25,12 @@ public void start() mIsStart = true; mComputer = new Computer(); - mComputer.CPUEnabled = true; + mComputer.CPUEnabled = OptionManager.getInstance().IsOHMCpu; + mComputer.MainboardEnabled = OptionManager.getInstance().IsOHMMotherboard; + mComputer.FanControllerEnabled = OptionManager.getInstance().IsOHMContolled; + mComputer.GPUEnabled = OptionManager.getInstance().IsOHMGpu; + mComputer.HDDEnabled = OptionManager.getInstance().IsOHMStorage; mComputer.RAMEnabled = true; - mComputer.MainboardEnabled = true; - mComputer.FanControllerEnabled = true; - mComputer.GPUEnabled = true; mComputer.Open(); mComputer.Accept(this); @@ -43,78 +49,24 @@ public void stop() } } - public void createTemp(ref List sensorList) - { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; - - // CPU, GPU - int cpuNum = 2; - int GpuAtiNum = 2; - int gpuNvidiaNum = 2; - var hardwareArray = mComputer.Hardware; - for (int i = 0; i < hardwareArray.Length; i++) - { - if (hardwareArray[i].HardwareType == HardwareType.CPU) - { - string name = hardwareArray[i].Name; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = hardwareArray[i].Name + " #" + cpuNum++; - } - var sensor = new HardwareTemp(hardwareArray[i], name); - sensorList.Add(sensor); - } - - if (hardwareArray[i].HardwareType == HardwareType.GpuAti) - { - string name = hardwareArray[i].Name; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = hardwareArray[i].Name + " #" + GpuAtiNum++; - } - var sensor = new HardwareTemp(hardwareArray[i], name); - sensorList.Add(sensor); - } - - else if (hardwareArray[i].HardwareType == HardwareType.GpuNvidia && isNvAPIWrapper == false) - { - string name = hardwareArray[i].Name; - while (this.isExistTemp(ref sensorList, name) == true) - { - name = hardwareArray[i].Name + " #" + gpuNvidiaNum++; - } - var sensor = new HardwareTemp(hardwareArray[i], name); - sensorList.Add(sensor); - } - } - } - - public void createMotherBoardTemp(ref List sensorList) + public void createTemp(ref List deviceList) { - // Motherboard - int num = 1; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Length; i++) { - if (hardwareArray[i].HardwareType == HardwareType.CPU || - hardwareArray[i].HardwareType == HardwareType.GpuAti || - hardwareArray[i].HardwareType == HardwareType.GpuNvidia) - { - continue; - } + string hardwareName = (hardwareArray[i].Name.Length > 0) ? hardwareArray[i].Name : "Unknown"; + var device = new HardwareDevice(hardwareName); var sensorArray = hardwareArray[i].Sensors; for (int j = 0; j < sensorArray.Length; j++) { - if (sensorArray[j].SensorType != OpenHardwareMonitor.Hardware.SensorType.Temperature) + if (sensorArray[j].SensorType != SensorType.Temperature) continue; - string originName = sensorArray[j].Name.ToUpper(); - if (originName.Contains("CPU") == true) - continue; - - var sensor = new HardwareMotherBoardTemp(sensorArray[j], "Motherboard #" + num++); - sensorList.Add(sensor); + string id = string.Format("{0}{1}", mIDPrefixTemperature, sensorArray[j].Identifier.ToString()); + string name = (sensorArray[j].Name.Length > 0) ? sensorArray[j].Name : "Temperature"; + var sensor = new OHMTemp(id, sensorArray[j], name); + device.addDevice(sensor); } var subHardwareArray = hardwareArray[i].SubHardware; @@ -123,78 +75,84 @@ public void createMotherBoardTemp(ref List sensorList) var subSensorList = subHardwareArray[j].Sensors; for (int k = 0; k < subSensorList.Length; k++) { - if (subSensorList[k].SensorType != OpenHardwareMonitor.Hardware.SensorType.Temperature) - continue; - - string originName = subSensorList[k].Name.ToUpper(); - if (originName.Contains("CPU") == true) + if (subSensorList[k].SensorType != SensorType.Temperature) continue; - var sensor = new HardwareMotherBoardTemp(subSensorList[k], "Motherboard #" + num++); - sensorList.Add(sensor); + string id = string.Format("{0}{1}", mIDPrefixTemperature, subSensorList[k].Identifier.ToString()); + string name = (subSensorList[k].Name.Length > 0) ? subSensorList[k].Name : "Temperature"; + var sensor = new OHMTemp(id, subSensorList[k], name); + device.addDevice(sensor); } } + + if (device.DeviceList.Count > 0) + { + deviceList.Add(device); + } } } - public void createFan(ref List fanList) + public void createFan(ref List deviceList) { - int fanNum = 1; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Length; i++) { - if (hardwareArray[i].HardwareType == HardwareType.GpuNvidia || - hardwareArray[i].HardwareType == HardwareType.GpuAti) - { - continue; - } + string hardwareName = (hardwareArray[i].Name.Length > 0) ? hardwareArray[i].Name : "Unknown"; + var device = new HardwareDevice(hardwareName); var sensorArray = hardwareArray[i].Sensors; for (int j = 0; j < sensorArray.Length; j++) { - if (sensorArray[j].SensorType != OpenHardwareMonitor.Hardware.SensorType.Fan) + if (sensorArray[j].SensorType != SensorType.Fan) continue; - var fan = new HardwareFanSpeed(sensorArray[j], "Fan #" + fanNum++); - fanList.Add(fan); + string id = string.Format("{0}{1}", mIDPrefixFan, sensorArray[j].Identifier.ToString()); + string name = (sensorArray[j].Name.Length > 0) ? sensorArray[j].Name : "Fan"; + var sensor = new OHMFanSpeed(id, sensorArray[j], name); + device.addDevice(sensor); } var subHardwareArray = hardwareArray[i].SubHardware; for (int j = 0; j < subHardwareArray.Length; j++) { - var subSensorArray = subHardwareArray[j].Sensors; - for (int k = 0; k < subSensorArray.Length; k++) + var subSensorList = subHardwareArray[j].Sensors; + for (int k = 0; k < subSensorList.Length; k++) { - if (subSensorArray[k].SensorType != OpenHardwareMonitor.Hardware.SensorType.Fan) + if (subSensorList[k].SensorType != SensorType.Fan) continue; - var fan = new HardwareFanSpeed(subSensorArray[k], "Fan #" + fanNum++); - fanList.Add(fan); + string id = string.Format("{0}{1}", mIDPrefixFan, subSensorList[k].Identifier.ToString()); + string name = (subSensorList[k].Name.Length > 0) ? subSensorList[k].Name : "Fan"; + var sensor = new OHMFanSpeed(id, subSensorList[k], name); + device.addDevice(sensor); } } + + if (device.DeviceList.Count > 0) + { + deviceList.Add(device); + } } } - public void createControl(ref List controlList) + public void createControl(ref List deviceList) { - int fanNum = 1; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Length; i++) { - if (hardwareArray[i].HardwareType == HardwareType.GpuNvidia || - hardwareArray[i].HardwareType == HardwareType.GpuAti) - { - continue; - } + string hardwareName = (hardwareArray[i].Name.Length > 0) ? hardwareArray[i].Name : "Unknown"; + var device = new HardwareDevice(hardwareName); var sensorArray = hardwareArray[i].Sensors; for (int j = 0; j < sensorArray.Length; j++) { - if (sensorArray[j].SensorType != OpenHardwareMonitor.Hardware.SensorType.Control) + if (sensorArray[j].SensorType != SensorType.Control) continue; - var control = new HardwareControl(sensorArray[j], "Fan Control #" + fanNum++); - controlList.Add(control); + string id = string.Format("{0}{1}", mIDPrefixControl, sensorArray[j].Identifier.ToString()); + string name = (sensorArray[j].Name.Length > 0) ? sensorArray[j].Name : "Control"; + var sensor = new OHMControl(id, sensorArray[j], name); + device.addDevice(sensor); } var subHardwareArray = hardwareArray[i].SubHardware; @@ -203,207 +161,103 @@ public void createControl(ref List controlList) var subSensorList = subHardwareArray[j].Sensors; for (int k = 0; k < subSensorList.Length; k++) { - if (subSensorList[k].SensorType != OpenHardwareMonitor.Hardware.SensorType.Control) + if (subSensorList[k].SensorType != SensorType.Control) continue; - var control = new HardwareControl(subSensorList[k], "Fan Control #" + fanNum++); - controlList.Add(control); + string id = string.Format("{0}{1}", mIDPrefixControl, subSensorList[k].Identifier.ToString()); + string name = (subSensorList[k].Name.Length > 0) ? subSensorList[k].Name : "Control"; + var sensor = new OHMControl(id, subSensorList[k], name); + device.addDevice(sensor); } } - } - } - public void createGPUFan(ref List fanList) - { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; - - int gpuFanNum = 1; - var hardwareArray = mComputer.Hardware; - for (int i = 0; i < hardwareArray.Length; i++) - { - if ((hardwareArray[i].HardwareType == HardwareType.GpuNvidia && isNvAPIWrapper == false) || - (hardwareArray[i].HardwareType == HardwareType.GpuAti)) + if (device.DeviceList.Count > 0) { - var sensorArray = hardwareArray[i].Sensors; - for (int j = 0; j < sensorArray.Length; j++) - { - if (sensorArray[j].SensorType == OpenHardwareMonitor.Hardware.SensorType.Fan) - { - var name = "GPU Fan #" + gpuFanNum++; - while (this.isExistFan(ref fanList, name) == true) - { - name = "GPU Fan #" + gpuFanNum++; - } - - var fan = new HardwareFanSpeed(sensorArray[j], name); - fanList.Add(fan); - } - } - - var subHardwareArray = hardwareArray[i].SubHardware; - for (int j = 0; j < subHardwareArray.Length; j++) - { - var subSensorList = subHardwareArray[j].Sensors; - for (int k = 0; k < subSensorList.Length; k++) - { - if (subSensorList[k].SensorType == OpenHardwareMonitor.Hardware.SensorType.Fan) - { - var name = "GPU Fan #" + gpuFanNum++; - while (this.isExistFan(ref fanList, name) == true) - { - name = "GPU Fan #" + gpuFanNum++; - } - - var fan = new HardwareFanSpeed(subSensorList[k], name); - fanList.Add(fan); - } - } - } - } - } - } - - public void createGPUFanControl(ref List controlList) - { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; - - int gpuFanNum = 1; - var hardwareArray = mComputer.Hardware; - for (int i = 0; i < hardwareArray.Length; i++) - { - if ((hardwareArray[i].HardwareType == HardwareType.GpuNvidia && isNvAPIWrapper == false) || - (hardwareArray[i].HardwareType == HardwareType.GpuAti)) - { - var sensorArray = hardwareArray[i].Sensors; - for (int j = 0; j < sensorArray.Length; j++) - { - if (sensorArray[j].SensorType == OpenHardwareMonitor.Hardware.SensorType.Control) - { - var name = "GPU Fan Control #" + gpuFanNum++; - while (this.isExistControl(ref controlList, name) == true) - { - name = "GPU Fan Control #" + gpuFanNum++; - } - - var control = new HardwareControl(sensorArray[j], name); - controlList.Add(control); - } - } - - var subHardwareArray = hardwareArray[i].SubHardware; - for (int j = 0; j < subHardwareArray.Length; j++) - { - var subSensorList = subHardwareArray[j].Sensors; - for (int k = 0; k < subSensorList.Length; k++) - { - if (subSensorList[k].SensorType == OpenHardwareMonitor.Hardware.SensorType.Control) - { - var name = "GPU Fan Control #" + gpuFanNum++; - while (this.isExistControl(ref controlList, name) == true) - { - name = "GPU Fan Control #" + gpuFanNum++; - } - - var control = new HardwareControl(subSensorList[k], name); - controlList.Add(control); - } - } - } + deviceList.Add(device); } } } - public void createOSDSensor(ref List osdList) + public void createOSDSensor(List osdList, Dictionary osdMap) { try { - bool isNvAPIWrapper = OptionManager.getInstance().IsNvAPIWrapper; var hardwareArray = mComputer.Hardware; for (int i = 0; i < hardwareArray.Length; i++) { - if (isNvAPIWrapper == true && hardwareArray[i].HardwareType == HardwareType.GpuNvidia) - continue; - var sensorArray = hardwareArray[i].Sensors; - this.setOSDSensor(sensorArray, SensorType.Load, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Clock, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Voltage, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Data, ref osdList); - this.setOSDSensor(sensorArray, SensorType.SmallData, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Power, ref osdList); - this.setOSDSensor(sensorArray, SensorType.Throughput, ref osdList); + this.setOSDSensor(sensorArray, SensorType.Load, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Clock, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Voltage, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Data, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.SmallData, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Power, osdList, osdMap); + this.setOSDSensor(sensorArray, SensorType.Throughput, osdList, osdMap); var subHardwareArray = hardwareArray[i].SubHardware; for (int j = 0; j < subHardwareArray.Length; j++) { var subSensorArray = subHardwareArray[j].Sensors; - this.setOSDSensor(subSensorArray, SensorType.Load, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Clock, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Voltage, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Data, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.SmallData, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Power, ref osdList); - this.setOSDSensor(subSensorArray, SensorType.Throughput, ref osdList); + this.setOSDSensor(subSensorArray, SensorType.Load, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Clock, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Voltage, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Data, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.SmallData, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Power, osdList, osdMap); + this.setOSDSensor(subSensorArray, SensorType.Throughput, osdList, osdMap); } } } catch { } } - private void setOSDSensor(ISensor[] sensorArray, SensorType sensorType, ref List osdList) + private void setOSDSensor(ISensor[] sensorArray, SensorType sensorType, List osdList, Dictionary osdMap) { - var sensorList = new List(); for (int i = 0; i < sensorArray.Length; i++) { + var sensor = sensorArray[i]; if (sensorArray[i].SensorType != sensorType) { continue; } - sensorList.Add(sensorArray[i]); - } - - for (int i = 0; i < sensorList.Count; i++) - { - var sensor = sensorList[i]; - int index = osdList.Count; OSDUnitType unitType = OSDUnitType.Unknown; - string sensorName = ""; - switch (sensorList[i].SensorType) + string prefix = ""; + switch (sensorArray[i].SensorType) { case SensorType.Voltage: unitType = OSDUnitType.Voltage; - sensorName = "[Voltage] "; + prefix = "[Voltage] "; break; case SensorType.Power: unitType = OSDUnitType.Power; - sensorName = "[Power] "; + prefix = "[Power] "; break; case SensorType.Load: unitType = OSDUnitType.Percent; - sensorName = "[Load] "; + prefix = "[Load] "; break; case SensorType.Clock: unitType = OSDUnitType.MHz; - sensorName = "[Clock] "; + prefix = "[Clock] "; break; case SensorType.Data: unitType = OSDUnitType.GB; - sensorName = "[Data] "; + prefix = "[Data] "; break; case SensorType.SmallData: unitType = OSDUnitType.MB; - sensorName = "[Data] "; + prefix = "[Data] "; break; case SensorType.Throughput: unitType = OSDUnitType.MBPerSec; - sensorName = "[Throughput] "; + prefix = "[Throughput] "; break; default: @@ -414,8 +268,10 @@ private void setOSDSensor(ISensor[] sensorArray, SensorType sensorType, ref List if (unitType == OSDUnitType.Unknown) continue; - var osdSensor = new OSDSensor(sensorList[i], unitType, sensorName + sensorList[i].Name, index); + string id = string.Format("{0}{1}", mIDPrefixOSD, sensor.Identifier.ToString()); + var osdSensor = new OHMOSDSensor(id, prefix, sensorArray[i].Name, unitType, sensor); osdList.Add(osdSensor); + osdMap.Add(id, osdSensor); } } @@ -424,42 +280,6 @@ public void update() mComputer.Accept(this); } - private bool isExistTemp(ref List sensorList, string name) - { - for (int i = 0; i < sensorList.Count; i++) - { - if (sensorList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private bool isExistFan(ref List fanList, string name) - { - for (int i = 0; i < fanList.Count; i++) - { - if (fanList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - - private bool isExistControl(ref List controlList, string name) - { - for (int i = 0; i < controlList.Count; i++) - { - if (controlList[i].Name.Equals(name) == true) - { - return true; - } - } - return false; - } - /////////////////////////// Visitor /////////////////////////// public void VisitComputer(IComputer computer) { diff --git a/FanCtrl/Hardware/OSD/LHMOSDSensor.cs b/FanCtrl/Hardware/OSD/LHMOSDSensor.cs new file mode 100644 index 0000000..1266740 --- /dev/null +++ b/FanCtrl/Hardware/OSD/LHMOSDSensor.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using LibreHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class LHMOSDSensor : OSDSensor + { + private ISensor mSensor = null; + + public LHMOSDSensor(string id, string prefix, string name, OSDUnitType unitType, ISensor sensor) : base(id, prefix, name, unitType) + { + mSensor = sensor; + } + + public override void update() + { + if (mSensor != null) + { + DoubleValue = (mSensor.Value.HasValue == true) ? (double)mSensor.Value : (double)Value; + } + } + } +} diff --git a/FanCtrl/Hardware/OSD/NvAPIOSDSensor.cs b/FanCtrl/Hardware/OSD/NvAPIOSDSensor.cs new file mode 100644 index 0000000..2d6965a --- /dev/null +++ b/FanCtrl/Hardware/OSD/NvAPIOSDSensor.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using LibreHardwareMonitor.Hardware; +using OpenHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class NvAPIOSDSensor : OSDSensor + { + public delegate double OnNvAPIOSDSensorUpdate(int index, int subIndex); + public event OnNvAPIOSDSensorUpdate onNvAPIOSDSensorUpdate; + + private int mIndex = 0; + private int mSubIndex = 0; + + public NvAPIOSDSensor(string id, string prefix, string name, OSDUnitType unitType, int index, int subIndex) : base(id, prefix, name, unitType) + { + mIndex = index; + mSubIndex = subIndex; + } + + public override void update() + { + if (onNvAPIOSDSensorUpdate != null) + { + DoubleValue = onNvAPIOSDSensorUpdate(mIndex, mSubIndex); + } + } + } +} diff --git a/FanCtrl/Hardware/OSD/OHMOSDSensor.cs b/FanCtrl/Hardware/OSD/OHMOSDSensor.cs new file mode 100644 index 0000000..204a59b --- /dev/null +++ b/FanCtrl/Hardware/OSD/OHMOSDSensor.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class OHMOSDSensor : OSDSensor + { + private ISensor mSensor = null; + + public OHMOSDSensor(string id, string prefix, string name, OSDUnitType unitType, ISensor sensor) : base(id, prefix, name, unitType) + { + mSensor = sensor; + } + + public override void update() + { + if (mSensor != null) + { + DoubleValue = (mSensor.Value.HasValue == true) ? (double)mSensor.Value : (double)Value; + } + } + } +} diff --git a/FanCtrl/Hardware/OSD/OSDSensor.cs b/FanCtrl/Hardware/OSD/OSDSensor.cs new file mode 100644 index 0000000..3a01c04 --- /dev/null +++ b/FanCtrl/Hardware/OSD/OSDSensor.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using LibreHardwareMonitor.Hardware; +using OpenHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public enum OSDUnitType : int + { + Temperature = 0, + RPM, + Percent, + MHz, + kHz, + KB, + MB, + GB, + MBPerSec, + Voltage, + Power, + FPS, + Blank, + Unknown, + } + + public class OSDSensor + { + public string Prefix { get; set; } + + public string Name { get; set; } + + public string ID { get; set; } + + public OSDUnitType UnitType { get; set; } + + public double DoubleValue { get; set; } + + public int Value { get; set; } + + public OSDSensor(string id, string prefix, string name, OSDUnitType unitType) + { + ID = id; + Prefix = prefix; + Name = name; + UnitType = unitType; + } + + public virtual string getString() + { + this.update(); + + if (UnitType == OSDUnitType.Voltage) + { + return string.Format("{0:0.00}", DoubleValue); + } + else if (UnitType == OSDUnitType.kHz) + { + Value = (int)Math.Round(DoubleValue / 1000); + return Value.ToString(); + } + else if (UnitType == OSDUnitType.KB) + { + Value = (int)Math.Round(DoubleValue / 1024); + return Value.ToString(); + } + else if (UnitType == OSDUnitType.GB) + { + Value = (int)Math.Round(DoubleValue * 1024); + return Value.ToString(); + } + else if (UnitType == OSDUnitType.MBPerSec) + { + double value = Math.Round(DoubleValue / 1024 / 1024); + return string.Format("{0}", value); + } + else + { + Value = (int)Math.Round(DoubleValue); + return Value.ToString(); + } + } + + public virtual void update() + { + + } + } +} diff --git a/FanCtrl/Hardware/Sensor/BaseSensor.cs b/FanCtrl/Hardware/Sensor/BaseSensor.cs index a7038a9..7308c6c 100644 --- a/FanCtrl/Hardware/Sensor/BaseSensor.cs +++ b/FanCtrl/Hardware/Sensor/BaseSensor.cs @@ -6,31 +6,12 @@ namespace FanCtrl { - public enum SENSOR_TYPE + public class BaseSensor : BaseDevice { - // temperature - TEMPERATURE, - - // fan speed - FAN, - - // OSD sensor - OSD, - - UNKNOWN, - }; - - public class BaseSensor - { - // Sensor type - public SENSOR_TYPE Type { get; } - // Value public int Value { get; set; } - public string Name { get; set; } - - public BaseSensor(SENSOR_TYPE type) + public BaseSensor(LIBRARY_TYPE type) { Type = type; Value = 0; @@ -39,12 +20,6 @@ public BaseSensor(SENSOR_TYPE type) public virtual string getString() { return ""; - } - - public virtual void update() - { - - } - + } } } diff --git a/FanCtrl/Hardware/Sensor/CLCFanSpeed.cs b/FanCtrl/Hardware/Sensor/CLCFanSpeed.cs index a97e655..851a62c 100644 --- a/FanCtrl/Hardware/Sensor/CLCFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/CLCFanSpeed.cs @@ -10,8 +10,9 @@ public class CLCFanSpeed : BaseSensor { private CLC mCLC = null; - public CLCFanSpeed(CLC clc, uint num) : base(SENSOR_TYPE.FAN) + public CLCFanSpeed(string id, CLC clc, uint num) : base(LIBRARY_TYPE.EVGA_CLC) { + ID = id; mCLC = clc; Name = "EVGA CLC Fan"; if (num > 1) diff --git a/FanCtrl/Hardware/Sensor/CLCLiquidTemp.cs b/FanCtrl/Hardware/Sensor/CLCLiquidTemp.cs index c7f9baf..0d22f9c 100644 --- a/FanCtrl/Hardware/Sensor/CLCLiquidTemp.cs +++ b/FanCtrl/Hardware/Sensor/CLCLiquidTemp.cs @@ -10,8 +10,9 @@ public class CLCLiquidTemp : BaseSensor { private CLC mCLC = null; - public CLCLiquidTemp(CLC clc, uint num) : base(SENSOR_TYPE.TEMPERATURE) + public CLCLiquidTemp(string id, CLC clc, uint num) : base(LIBRARY_TYPE.EVGA_CLC) { + ID = id; mCLC = clc; Name = "EVGA CLC Liquid"; if (num > 1) diff --git a/FanCtrl/Hardware/Sensor/CLCPumpSpeed.cs b/FanCtrl/Hardware/Sensor/CLCPumpSpeed.cs index d035c7d..d05d624 100644 --- a/FanCtrl/Hardware/Sensor/CLCPumpSpeed.cs +++ b/FanCtrl/Hardware/Sensor/CLCPumpSpeed.cs @@ -10,8 +10,9 @@ public class CLCPumpSpeed : BaseSensor { private CLC mCLC = null; - public CLCPumpSpeed(CLC clc, uint num) : base(SENSOR_TYPE.FAN) + public CLCPumpSpeed(string id, CLC clc, uint num) : base(LIBRARY_TYPE.EVGA_CLC) { + ID = id; mCLC = clc; Name = "EVGA CLC Pump"; if (num > 1) diff --git a/FanCtrl/Hardware/Sensor/DimmTemp.cs b/FanCtrl/Hardware/Sensor/DimmTemp.cs index b741024..db9e259 100644 --- a/FanCtrl/Hardware/Sensor/DimmTemp.cs +++ b/FanCtrl/Hardware/Sensor/DimmTemp.cs @@ -15,8 +15,9 @@ public class DimmTemp : BaseSensor private int mBusIndex = 0; private byte mAddress = 0; - public DimmTemp(string name, int busIndex, byte address) : base(SENSOR_TYPE.TEMPERATURE) + public DimmTemp(string id, string name, int busIndex, byte address) : base(LIBRARY_TYPE.DIMM) { + ID = id; Name = name; mBusIndex = busIndex; mAddress = address; diff --git a/FanCtrl/Hardware/Sensor/GigabyteAmdGpuFanSpeed.cs b/FanCtrl/Hardware/Sensor/GigabyteAmdGpuFanSpeed.cs index a32b21c..2b78a97 100644 --- a/FanCtrl/Hardware/Sensor/GigabyteAmdGpuFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/GigabyteAmdGpuFanSpeed.cs @@ -14,7 +14,7 @@ public class GigabyteAmdGpuFanSpeed : BaseSensor private int mIndex = -1; - public GigabyteAmdGpuFanSpeed(string name, int index) : base(SENSOR_TYPE.FAN) + public GigabyteAmdGpuFanSpeed(string name, int index) : base(LIBRARY_TYPE.Gigabyte) { Name = name; mIndex = index; diff --git a/FanCtrl/Hardware/Sensor/GigabyteAmdGpuTemp.cs b/FanCtrl/Hardware/Sensor/GigabyteAmdGpuTemp.cs index b31072b..f7e5e21 100644 --- a/FanCtrl/Hardware/Sensor/GigabyteAmdGpuTemp.cs +++ b/FanCtrl/Hardware/Sensor/GigabyteAmdGpuTemp.cs @@ -14,9 +14,10 @@ public class GigabyteAmdGpuTemp : BaseSensor private int mIndex = -1; - public GigabyteAmdGpuTemp(string name, int index) : base(SENSOR_TYPE.TEMPERATURE) + public GigabyteAmdGpuTemp(string id, string name, int index) : base(LIBRARY_TYPE.Gigabyte) { - Name = name;// module.ProductName; + ID = id; + Name = name; mIndex = index; } diff --git a/FanCtrl/Hardware/Sensor/GigabyteFanSpeed.cs b/FanCtrl/Hardware/Sensor/GigabyteFanSpeed.cs index a1316cb..5636630 100644 --- a/FanCtrl/Hardware/Sensor/GigabyteFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/GigabyteFanSpeed.cs @@ -15,8 +15,9 @@ public class GigabyteFanSpeed : BaseSensor private int mIndex = -1; - public GigabyteFanSpeed(string name, int index) : base(SENSOR_TYPE.FAN) + public GigabyteFanSpeed(string id, string name, int index) : base(LIBRARY_TYPE.Gigabyte) { + ID = id; Name = name; mIndex = index; } diff --git a/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuFanSpeed.cs b/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuFanSpeed.cs index cd89ce3..1685e3d 100644 --- a/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuFanSpeed.cs @@ -14,8 +14,9 @@ public class GigabyteNvidiaFanSpeed : BaseSensor private int mIndex = -1; - public GigabyteNvidiaFanSpeed(string name, int index) : base(SENSOR_TYPE.FAN) + public GigabyteNvidiaFanSpeed(string id, string name, int index) : base(LIBRARY_TYPE.Gigabyte) { + ID = id; Name = name; mIndex = index; } diff --git a/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuTemp.cs b/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuTemp.cs index a9a15a1..bf1494c 100644 --- a/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuTemp.cs +++ b/FanCtrl/Hardware/Sensor/GigabyteNvidiaGpuTemp.cs @@ -14,9 +14,10 @@ public class GigabyteNvidiaGpuTemp : BaseSensor private int mIndex = -1; - public GigabyteNvidiaGpuTemp(string name, int index) : base(SENSOR_TYPE.TEMPERATURE) + public GigabyteNvidiaGpuTemp(string id, string name, int index) : base(LIBRARY_TYPE.Gigabyte) { - Name = name;// module.ProductName; + ID = id; + Name = name; mIndex = index; } diff --git a/FanCtrl/Hardware/Sensor/GigabyteTemp.cs b/FanCtrl/Hardware/Sensor/GigabyteTemp.cs index 39edd20..94a7e03 100644 --- a/FanCtrl/Hardware/Sensor/GigabyteTemp.cs +++ b/FanCtrl/Hardware/Sensor/GigabyteTemp.cs @@ -15,8 +15,9 @@ public class GigabyteTemp : BaseSensor private int mIndex = -1; - public GigabyteTemp(string name, int index) : base(SENSOR_TYPE.TEMPERATURE) + public GigabyteTemp(string id, string name, int index) : base(LIBRARY_TYPE.Gigabyte) { + ID = id; Name = name; mIndex = index; } diff --git a/FanCtrl/Hardware/Sensor/HardwareFanSpeed.cs b/FanCtrl/Hardware/Sensor/HardwareFanSpeed.cs deleted file mode 100644 index 9fea35d..0000000 --- a/FanCtrl/Hardware/Sensor/HardwareFanSpeed.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using LibreHardwareMonitor.Hardware; -using OpenHardwareMonitor.Hardware; - -namespace FanCtrl -{ - public class HardwareFanSpeed : BaseSensor - { - // ISensor - private LibreHardwareMonitor.Hardware.ISensor mLHMSensor = null; - private OpenHardwareMonitor.Hardware.ISensor mOHMSensor = null; - - public HardwareFanSpeed(LibreHardwareMonitor.Hardware.ISensor sensor, string name) : base(SENSOR_TYPE.FAN) - { - mLHMSensor = sensor; - Name = name; - } - - public HardwareFanSpeed(OpenHardwareMonitor.Hardware.ISensor sensor, string name) : base(SENSOR_TYPE.FAN) - { - mOHMSensor = sensor; - Name = name; - } - - public override string getString() - { - return Value.ToString() + " RPM"; - } - - public override void update() - { - if (mLHMSensor != null) - { - Value = (mLHMSensor.Value.HasValue == true) ? (int)mLHMSensor.Value : Value; - } - else if (mOHMSensor != null) - { - Value = (mOHMSensor.Value.HasValue == true) ? (int)mOHMSensor.Value : Value; - } - } - - } -} diff --git a/FanCtrl/Hardware/Sensor/HardwareMotherBoardTemp.cs b/FanCtrl/Hardware/Sensor/HardwareMotherBoardTemp.cs deleted file mode 100644 index aca0b60..0000000 --- a/FanCtrl/Hardware/Sensor/HardwareMotherBoardTemp.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using LibreHardwareMonitor.Hardware; -using OpenHardwareMonitor.Hardware; - -namespace FanCtrl -{ - public class HardwareMotherBoardTemp : BaseSensor - { - // ISensor - private LibreHardwareMonitor.Hardware.ISensor mLHMSensor = null; - private OpenHardwareMonitor.Hardware.ISensor mOHMSensor = null; - - public HardwareMotherBoardTemp(LibreHardwareMonitor.Hardware.ISensor sensor, string name) : base(SENSOR_TYPE.TEMPERATURE) - { - mLHMSensor = sensor; - Name = name; - } - - public HardwareMotherBoardTemp(OpenHardwareMonitor.Hardware.ISensor sensor, string name) : base(SENSOR_TYPE.TEMPERATURE) - { - mOHMSensor = sensor; - Name = name; - } - - public override string getString() - { - if (OptionManager.getInstance().IsFahrenheit == true) - return Util.getFahrenheit(Value) + " °F"; - else - return Value + " °C"; - } - public override void update() - { - if (mLHMSensor != null) - { - double temp = ((mLHMSensor.Value.HasValue == true) ? Math.Round((double)mLHMSensor.Value) : 0); - if (temp > 0.0f) - { - Value = (int)temp; - } - } - else if (mOHMSensor != null) - { - double temp = ((mOHMSensor.Value.HasValue == true) ? Math.Round((double)mOHMSensor.Value) : 0); - if (temp > 0.0f) - { - Value = (int)temp; - } - } - } - - } -} diff --git a/FanCtrl/Hardware/Sensor/HardwareTemp.cs b/FanCtrl/Hardware/Sensor/HardwareTemp.cs deleted file mode 100644 index 06d98c4..0000000 --- a/FanCtrl/Hardware/Sensor/HardwareTemp.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using LibreHardwareMonitor.Hardware; -using OpenHardwareMonitor.Hardware; - -namespace FanCtrl -{ - public class HardwareTemp : BaseSensor - { - // IHardware - private LibreHardwareMonitor.Hardware.IHardware mLHMHardware = null; - private OpenHardwareMonitor.Hardware.IHardware mOHMHardware = null; - - // SensorList - private List mLHMList = new List(); - private List mOHMList = new List(); - - public HardwareTemp(LibreHardwareMonitor.Hardware.IHardware hardware, string name) : base(SENSOR_TYPE.TEMPERATURE) - { - mLHMHardware = hardware; - Name = name; - } - - public HardwareTemp(OpenHardwareMonitor.Hardware.IHardware hardware, string name) : base(SENSOR_TYPE.TEMPERATURE) - { - mOHMHardware = hardware; - Name = name; - } - - public void setTemperatureSensor() - { - if (mLHMList.Count > 0 || mOHMList.Count > 0) - return; - - if(mLHMHardware != null) - { - LibreHardwareMonitor.Hardware.ISensor packageSensor = null; - var sensor = mLHMHardware.Sensors; - for (int i = 0; i < sensor.Length; i++) - { - if (sensor[i].SensorType == LibreHardwareMonitor.Hardware.SensorType.Temperature) - { - if (mLHMHardware.HardwareType == LibreHardwareMonitor.Hardware.HardwareType.Cpu || - mLHMHardware.HardwareType == LibreHardwareMonitor.Hardware.HardwareType.GpuAmd || - mLHMHardware.HardwareType == LibreHardwareMonitor.Hardware.HardwareType.GpuNvidia) - { - if (sensor[i].Name.IndexOf("Core") >= 0) - { - mLHMList.Add(sensor[i]); - } - - if (sensor[i].Name.IndexOf("Package") >= 0) - { - packageSensor = sensor[i]; - break; - } - } - } - } - - if (packageSensor != null) - { - mLHMList.Clear(); - mLHMList.Add(packageSensor); - } - } - - else if (mOHMHardware != null) - { - OpenHardwareMonitor.Hardware.ISensor packageSensor = null; - var sensor = mOHMHardware.Sensors; - for (int i = 0; i < sensor.Length; i++) - { - if (sensor[i].SensorType == OpenHardwareMonitor.Hardware.SensorType.Temperature) - { - if (mOHMHardware.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.CPU || - mOHMHardware.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.GpuAti || - mOHMHardware.HardwareType == OpenHardwareMonitor.Hardware.HardwareType.GpuNvidia) - { - if (sensor[i].Name.IndexOf("Core") >= 0) - { - mOHMList.Add(sensor[i]); - } - - if (sensor[i].Name.IndexOf("Package") >= 0) - { - packageSensor = sensor[i]; - break; - } - } - } - } - - if (packageSensor != null) - { - mOHMList.Clear(); - mOHMList.Add(packageSensor); - } - } - } - - public override string getString() - { - if (OptionManager.getInstance().IsFahrenheit == true) - return Util.getFahrenheit(Value) + " °F"; - else - return Value + " °C"; - } - public override void update() - { - // setTemperatureSensor - this.setTemperatureSensor(); - - double temp = 0.0f; - - if (mLHMHardware != null) - { - for (int i = 0; i < mLHMList.Count; i++) - { - temp = temp + ((mLHMList[i].Value.HasValue == true) ? Math.Round((double)mLHMList[i].Value) : 0); - } - - if (temp > 0.0f) - { - temp = temp / mLHMList.Count; - Value = (int)temp; - } - } - - else if (mOHMHardware != null) - { - for (int i = 0; i < mOHMList.Count; i++) - { - temp = temp + ((mOHMList[i].Value.HasValue == true) ? Math.Round((double)mOHMList[i].Value) : 0); - } - - if (temp > 0.0f) - { - temp = temp / mOHMList.Count; - Value = (int)temp; - } - } - - } - } -} diff --git a/FanCtrl/Hardware/Sensor/KrakenFanSpeed.cs b/FanCtrl/Hardware/Sensor/KrakenFanSpeed.cs index 04099af..6257b60 100644 --- a/FanCtrl/Hardware/Sensor/KrakenFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/KrakenFanSpeed.cs @@ -10,8 +10,9 @@ public class KrakenFanSpeed : BaseSensor { private Kraken mKraken = null; - public KrakenFanSpeed(Kraken kraken, uint num) : base(SENSOR_TYPE.FAN) + public KrakenFanSpeed(string id, Kraken kraken, uint num) : base(LIBRARY_TYPE.NZXT_Kraken) { + ID = id; mKraken = kraken; Name = "NZXT Kraken Fan"; if (num > 1) diff --git a/FanCtrl/Hardware/Sensor/KrakenLiquidTemp.cs b/FanCtrl/Hardware/Sensor/KrakenLiquidTemp.cs index 8d01345..bbc151e 100644 --- a/FanCtrl/Hardware/Sensor/KrakenLiquidTemp.cs +++ b/FanCtrl/Hardware/Sensor/KrakenLiquidTemp.cs @@ -10,8 +10,9 @@ public class KrakenLiquidTemp : BaseSensor { private Kraken mKraken = null; - public KrakenLiquidTemp(Kraken kraken, uint num) : base(SENSOR_TYPE.TEMPERATURE) + public KrakenLiquidTemp(string id, Kraken kraken, uint num) : base(LIBRARY_TYPE.NZXT_Kraken) { + ID = id; mKraken = kraken; Name = "NZXT Kraken Liquid"; if (num > 1) diff --git a/FanCtrl/Hardware/Sensor/KrakenPumpSpeed.cs b/FanCtrl/Hardware/Sensor/KrakenPumpSpeed.cs index 691a439..e1f31d0 100644 --- a/FanCtrl/Hardware/Sensor/KrakenPumpSpeed.cs +++ b/FanCtrl/Hardware/Sensor/KrakenPumpSpeed.cs @@ -10,8 +10,9 @@ public class KrakenPumpSpeed : BaseSensor { private Kraken mKraken = null; - public KrakenPumpSpeed(Kraken kraken, uint num) : base(SENSOR_TYPE.FAN) + public KrakenPumpSpeed(string id, Kraken kraken, uint num) : base(LIBRARY_TYPE.NZXT_Kraken) { + ID = id; mKraken = kraken; Name = "NZXT Kraken Pump"; if (num > 1) diff --git a/FanCtrl/Hardware/Sensor/LHMFanSpeed.cs b/FanCtrl/Hardware/Sensor/LHMFanSpeed.cs new file mode 100644 index 0000000..c6d607f --- /dev/null +++ b/FanCtrl/Hardware/Sensor/LHMFanSpeed.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using LibreHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class LHMFanSpeed : BaseSensor + { + // ISensor + private ISensor mSensor = null; + + public LHMFanSpeed(string id, ISensor sensor, string name) : base(LIBRARY_TYPE.LHM) + { + ID = id; + mSensor = sensor; + Name = name; + } + + public override string getString() + { + return Value.ToString() + " RPM"; + } + + public override void update() + { + if (mSensor != null) + { + Value = (mSensor.Value.HasValue == true) ? (int)mSensor.Value : Value; + } + } + + } +} diff --git a/FanCtrl/Hardware/Sensor/LHMTemp.cs b/FanCtrl/Hardware/Sensor/LHMTemp.cs new file mode 100644 index 0000000..bc1d423 --- /dev/null +++ b/FanCtrl/Hardware/Sensor/LHMTemp.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using LibreHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class LHMTemp : BaseSensor + { + // ISensor + private ISensor mSensor = null; + + public LHMTemp(string id, ISensor sensor, string name) : base(LIBRARY_TYPE.LHM) + { + ID = id; + mSensor = sensor; + Name = name; + } + + public override string getString() + { + if (OptionManager.getInstance().IsFahrenheit == true) + return Util.getFahrenheit(Value) + " °F"; + else + return Value + " °C"; + } + public override void update() + { + double temp = ((mSensor.Value.HasValue == true) ? Math.Round((double)mSensor.Value) : 0); + if (temp > 0.0f) + { + Value = (int)temp; + } + } + } +} diff --git a/FanCtrl/Hardware/Sensor/NvAPIFanSpeed.cs b/FanCtrl/Hardware/Sensor/NvAPIFanSpeed.cs index 62f121b..5ad3ae9 100644 --- a/FanCtrl/Hardware/Sensor/NvAPIFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/NvAPIFanSpeed.cs @@ -16,8 +16,9 @@ public class NvAPIFanSpeed : BaseSensor private int mIndex = 0; private int mCooerID = 0; - public NvAPIFanSpeed(string name, int index, int coolerID) : base(SENSOR_TYPE.FAN) + public NvAPIFanSpeed(string id, string name, int index, int coolerID) : base(LIBRARY_TYPE.NvAPIWrapper) { + ID = id; Name = name; mIndex = index; mCooerID = coolerID; diff --git a/FanCtrl/Hardware/Sensor/NvAPITemp.cs b/FanCtrl/Hardware/Sensor/NvAPITemp.cs index 90c3adf..88e7153 100644 --- a/FanCtrl/Hardware/Sensor/NvAPITemp.cs +++ b/FanCtrl/Hardware/Sensor/NvAPITemp.cs @@ -16,8 +16,9 @@ public class NvAPITemp : BaseSensor private int mIndex = -1; - public NvAPITemp(string name, int index) : base(SENSOR_TYPE.TEMPERATURE) + public NvAPITemp(string id, string name, int index) : base(LIBRARY_TYPE.NvAPIWrapper) { + ID = id; Name = name; mIndex = index; } diff --git a/FanCtrl/Hardware/Sensor/OHMFanSpeed.cs b/FanCtrl/Hardware/Sensor/OHMFanSpeed.cs new file mode 100644 index 0000000..f2385e2 --- /dev/null +++ b/FanCtrl/Hardware/Sensor/OHMFanSpeed.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class OHMFanSpeed : BaseSensor + { + // ISensor + private ISensor mSensor = null; + + public OHMFanSpeed(string id, ISensor sensor, string name) : base(LIBRARY_TYPE.OHM) + { + ID = id; + mSensor = sensor; + Name = name; + } + + public override string getString() + { + return Value.ToString() + " RPM"; + } + + public override void update() + { + if (mSensor != null) + { + Value = (mSensor.Value.HasValue == true) ? (int)mSensor.Value : Value; + } + } + + } +} diff --git a/FanCtrl/Hardware/Sensor/OHMTemp.cs b/FanCtrl/Hardware/Sensor/OHMTemp.cs new file mode 100644 index 0000000..f0725a5 --- /dev/null +++ b/FanCtrl/Hardware/Sensor/OHMTemp.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenHardwareMonitor.Hardware; + +namespace FanCtrl +{ + public class OHMTemp : BaseSensor + { + // ISensor + private ISensor mSensor = null; + + public OHMTemp(string id, ISensor sensor, string name) : base(LIBRARY_TYPE.OHM) + { + ID = id; + mSensor = sensor; + Name = name; + } + + public override string getString() + { + if (OptionManager.getInstance().IsFahrenheit == true) + return Util.getFahrenheit(Value) + " °F"; + else + return Value + " °C"; + } + public override void update() + { + double temp = ((mSensor.Value.HasValue == true) ? Math.Round((double)mSensor.Value) : 0); + if (temp > 0.0f) + { + Value = (int)temp; + } + } + } +} diff --git a/FanCtrl/Hardware/Sensor/OSDSensor.cs b/FanCtrl/Hardware/Sensor/OSDSensor.cs deleted file mode 100644 index ff8595c..0000000 --- a/FanCtrl/Hardware/Sensor/OSDSensor.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using LibreHardwareMonitor.Hardware; -using OpenHardwareMonitor.Hardware; - -namespace FanCtrl -{ - public enum OSDLibraryType - { - LibreHardwareMonitor = 0, - OpenHardwareMonitor = 1, - NvApiWrapper = 2, - } - - public class OSDSensor : BaseSensor - { - public delegate double OnOSDSensorUpdate(OSDLibraryType libraryType, int index, int subIndex); - public event OnOSDSensorUpdate onOSDSensorUpdate; - - private LibreHardwareMonitor.Hardware.ISensor mLHMSensor = null; - private OpenHardwareMonitor.Hardware.ISensor mOHMSensor = null; - - private int mIndex = 0; - private int mSubIndex = 0; - - public OSDLibraryType LibraryType { get; set; } - - public OSDUnitType UnitType { get; set; } - - public double DoubleValue { get; set; } - - public OSDSensor(LibreHardwareMonitor.Hardware.ISensor sensor, OSDUnitType unitType, string name, int index) : base(SENSOR_TYPE.OSD) - { - mLHMSensor = sensor; - LibraryType = OSDLibraryType.LibreHardwareMonitor; - UnitType = unitType; - Name = name; - mIndex = index; - } - - public OSDSensor(OpenHardwareMonitor.Hardware.ISensor sensor, OSDUnitType unitType, string name, int index) : base(SENSOR_TYPE.OSD) - { - mOHMSensor = sensor; - LibraryType = OSDLibraryType.OpenHardwareMonitor; - UnitType = unitType; - Name = name; - mIndex = index; - } - - public OSDSensor(OSDUnitType unitType, string name, int index, int subIndex) : base(SENSOR_TYPE.OSD) - { - LibraryType = OSDLibraryType.NvApiWrapper; - UnitType = unitType; - Name = name; - mIndex = index; - mSubIndex = subIndex; - } - - public override string getString() - { - this.update(); - - if (UnitType == OSDUnitType.Voltage) - { - return string.Format("{0:0.00}", DoubleValue); - } - else if (UnitType == OSDUnitType.kHz) - { - Value = (int)Math.Round(DoubleValue / 1000); - return Value.ToString(); - } - else if (UnitType == OSDUnitType.KB) - { - Value = (int)Math.Round(DoubleValue / 1024); - return Value.ToString(); - } - else if (UnitType == OSDUnitType.GB) - { - Value = (int)Math.Round(DoubleValue * 1024); - return Value.ToString(); - } - else if (UnitType == OSDUnitType.MBPerSec) - { - double value = Math.Round(DoubleValue / 1024 / 1024); - return string.Format("{0}", value); - } - else - { - Value = (int)Math.Round(DoubleValue); - return Value.ToString(); - } - } - public override void update() - { - if (mLHMSensor != null) - { - DoubleValue = (mLHMSensor.Value.HasValue == true) ? (double)mLHMSensor.Value : (double)Value; - } - - else if (mOHMSensor != null) - { - DoubleValue = (mOHMSensor.Value.HasValue == true) ? (double)mOHMSensor.Value : (double)Value; - } - else - { - DoubleValue = onOSDSensorUpdate(LibraryType, mIndex, mSubIndex); - } - } - } -} diff --git a/FanCtrl/Hardware/Sensor/RGBnFCFanSpeed.cs b/FanCtrl/Hardware/Sensor/RGBnFCFanSpeed.cs index d8a4b6e..3725eac 100644 --- a/FanCtrl/Hardware/Sensor/RGBnFCFanSpeed.cs +++ b/FanCtrl/Hardware/Sensor/RGBnFCFanSpeed.cs @@ -11,8 +11,9 @@ public class RGBnFCFanSpeed : BaseSensor private RGBnFC mRGBnFC = null; private int mIndex = 0; - public RGBnFCFanSpeed(RGBnFC fc, int index, uint num) : base(SENSOR_TYPE.FAN) + public RGBnFCFanSpeed(string id, RGBnFC fc, int index, uint num) : base(LIBRARY_TYPE.RGBnFC) { + ID = id; mRGBnFC = fc; mIndex = index; Name = "NZXT RGB&Fan #" + num; diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 2ae4f95..1d481f3 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -31,8 +31,11 @@ private void InitializeComponent() this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.mTempGroupBox = new System.Windows.Forms.GroupBox(); + this.mTempPanel = new System.Windows.Forms.Panel(); this.mFanGroupBox = new System.Windows.Forms.GroupBox(); + this.mFanPanel = new System.Windows.Forms.Panel(); this.mControlGroupBox = new System.Windows.Forms.GroupBox(); + this.mControlPanel = new System.Windows.Forms.Panel(); this.mFanControlButton = new System.Windows.Forms.Button(); this.mToolTip = new System.Windows.Forms.ToolTip(this.components); this.mOptionButton = new System.Windows.Forms.Button(); @@ -55,6 +58,9 @@ private void InitializeComponent() this.mOSDButton = new System.Windows.Forms.Button(); this.mLoadingPanel = new System.Windows.Forms.Panel(); this.label1 = new System.Windows.Forms.Label(); + this.mTempGroupBox.SuspendLayout(); + this.mFanGroupBox.SuspendLayout(); + this.mControlGroupBox.SuspendLayout(); this.mTrayMenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.mDonatePictureBox)).BeginInit(); this.mLoadingPanel.SuspendLayout(); @@ -62,34 +68,61 @@ private void InitializeComponent() // // mTempGroupBox // + this.mTempGroupBox.Controls.Add(this.mTempPanel); this.mTempGroupBox.Location = new System.Drawing.Point(12, 12); this.mTempGroupBox.Name = "mTempGroupBox"; - this.mTempGroupBox.Size = new System.Drawing.Size(252, 53); + this.mTempGroupBox.Size = new System.Drawing.Size(272, 53); this.mTempGroupBox.TabIndex = 0; this.mTempGroupBox.TabStop = false; this.mTempGroupBox.Text = "Temperature"; // + // mTempPanel + // + this.mTempPanel.AutoScroll = true; + this.mTempPanel.Location = new System.Drawing.Point(5, 12); + this.mTempPanel.Name = "mTempPanel"; + this.mTempPanel.Size = new System.Drawing.Size(261, 35); + this.mTempPanel.TabIndex = 0; + // // mFanGroupBox // - this.mFanGroupBox.Location = new System.Drawing.Point(270, 12); + this.mFanGroupBox.Controls.Add(this.mFanPanel); + this.mFanGroupBox.Location = new System.Drawing.Point(290, 12); this.mFanGroupBox.Name = "mFanGroupBox"; - this.mFanGroupBox.Size = new System.Drawing.Size(217, 53); + this.mFanGroupBox.Size = new System.Drawing.Size(272, 53); this.mFanGroupBox.TabIndex = 1; this.mFanGroupBox.TabStop = false; this.mFanGroupBox.Text = "Fan speed"; // + // mFanPanel + // + this.mFanPanel.AutoScroll = true; + this.mFanPanel.Location = new System.Drawing.Point(6, 12); + this.mFanPanel.Name = "mFanPanel"; + this.mFanPanel.Size = new System.Drawing.Size(260, 35); + this.mFanPanel.TabIndex = 1; + // // mControlGroupBox // - this.mControlGroupBox.Location = new System.Drawing.Point(493, 12); + this.mControlGroupBox.Controls.Add(this.mControlPanel); + this.mControlGroupBox.Location = new System.Drawing.Point(568, 12); this.mControlGroupBox.Name = "mControlGroupBox"; - this.mControlGroupBox.Size = new System.Drawing.Size(217, 53); + this.mControlGroupBox.Size = new System.Drawing.Size(306, 53); this.mControlGroupBox.TabIndex = 2; this.mControlGroupBox.TabStop = false; this.mControlGroupBox.Text = "Fan control"; // + // mControlPanel + // + this.mControlPanel.AutoScroll = true; + this.mControlPanel.Location = new System.Drawing.Point(6, 12); + this.mControlPanel.Name = "mControlPanel"; + this.mControlPanel.Size = new System.Drawing.Size(294, 35); + this.mControlPanel.TabIndex = 2; + // // mFanControlButton // - this.mFanControlButton.Location = new System.Drawing.Point(588, 75); + this.mFanControlButton.Location = new System.Drawing.Point(752, 71); this.mFanControlButton.Name = "mFanControlButton"; this.mFanControlButton.Size = new System.Drawing.Size(122, 38); this.mFanControlButton.TabIndex = 5; @@ -103,7 +136,7 @@ private void InitializeComponent() // // mOptionButton // - this.mOptionButton.Location = new System.Drawing.Point(460, 75); + this.mOptionButton.Location = new System.Drawing.Point(624, 71); this.mOptionButton.Name = "mOptionButton"; this.mOptionButton.Size = new System.Drawing.Size(122, 38); this.mOptionButton.TabIndex = 6; @@ -236,7 +269,7 @@ private void InitializeComponent() // // mOSDButton // - this.mOSDButton.Location = new System.Drawing.Point(332, 75); + this.mOSDButton.Location = new System.Drawing.Point(496, 71); this.mOSDButton.Name = "mOSDButton"; this.mOSDButton.Size = new System.Drawing.Size(122, 38); this.mOSDButton.TabIndex = 13; @@ -247,15 +280,15 @@ private void InitializeComponent() // mLoadingPanel // this.mLoadingPanel.Controls.Add(this.label1); - this.mLoadingPanel.Location = new System.Drawing.Point(9, 7); + this.mLoadingPanel.Location = new System.Drawing.Point(5, 3); this.mLoadingPanel.Name = "mLoadingPanel"; - this.mLoadingPanel.Size = new System.Drawing.Size(701, 106); + this.mLoadingPanel.Size = new System.Drawing.Size(874, 111); this.mLoadingPanel.TabIndex = 0; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(321, 46); + this.label1.Location = new System.Drawing.Point(403, 50); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(62, 12); this.label1.TabIndex = 0; @@ -264,8 +297,7 @@ private void InitializeComponent() // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.ClientSize = new System.Drawing.Size(719, 122); + this.ClientSize = new System.Drawing.Size(883, 116); this.Controls.Add(this.mLoadingPanel); this.Controls.Add(this.mOSDButton); this.Controls.Add(this.mOptionButton); @@ -276,12 +308,14 @@ private void InitializeComponent() this.Controls.Add(this.mControlGroupBox); this.Controls.Add(this.mFanGroupBox); this.Controls.Add(this.mTempGroupBox); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "FanControl"; + this.Text = "FanCtrl"; + this.mTempGroupBox.ResumeLayout(false); + this.mFanGroupBox.ResumeLayout(false); + this.mControlGroupBox.ResumeLayout(false); this.mTrayMenuStrip.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.mDonatePictureBox)).EndInit(); this.mLoadingPanel.ResumeLayout(false); @@ -318,6 +352,9 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.Panel mLoadingPanel; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel mTempPanel; + private System.Windows.Forms.Panel mFanPanel; + private System.Windows.Forms.Panel mControlPanel; } } diff --git a/MainForm.cs b/MainForm.cs index 3d1c089..a5295be 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -4,6 +4,7 @@ using System.Data; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; @@ -18,30 +19,40 @@ namespace FanCtrl public partial class MainForm : Form { private bool mIsExit = false; + private bool mIsFirstLoad = true; - private List