Skip to content

Commit

Permalink
Add fan curve preset
Browse files Browse the repository at this point in the history
  • Loading branch information
lich426 committed Dec 3, 2020
1 parent bf1cc3c commit 4f12543
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 11 deletions.
39 changes: 39 additions & 0 deletions ControlForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 139 additions & 2 deletions ControlForm.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -81,6 +84,9 @@ public ControlForm()
mGraph.Width = mGraph.Width + widthGap;
mGraph.Height = mGraph.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;
Expand Down Expand Up @@ -157,6 +163,9 @@ private void localizeComponent()
mAddButton.Text = StringLib.Add;
mRemoveButton.Text = StringLib.Remove;
mGraphGroupBox.Text = StringLib.Graph;
mPresetLabel.Text = StringLib.Preset;
mPresetLoadButton.Text = StringLib.Load;
mPresetSaveButton.Text = StringLib.Save;
mUnitLabel.Text = StringLib.Unit;
mHysLabel.Text = StringLib.Hysteresis;
mStepCheckBox.Text = StringLib.Step;
Expand Down Expand Up @@ -273,6 +282,9 @@ private void initGraph()
mLineItem.Symbol.Size = 10.0f;
mLineItem.Symbol.Fill = new Fill(Color.White);

mPresetLabel.Visible = false;
mPresetLoadButton.Visible = false;
mPresetSaveButton.Visible = false;
mUnitLabel.Visible = false;
mUnitComboBox.Visible = false;
mGraph.Visible = false;
Expand Down Expand Up @@ -337,6 +349,9 @@ private void onRadioButtonClick(object sender, EventArgs e)

private void onSensorComboBoxIndexChanged(object sender, EventArgs e)
{
mPresetLabel.Visible = false;
mPresetLoadButton.Visible = false;
mPresetSaveButton.Visible = false;
mUnitLabel.Visible = false;
mUnitComboBox.Visible = false;
mGraph.Visible = false;
Expand Down Expand Up @@ -540,6 +555,9 @@ private void onFanListViewIndexChanged(object sender, EventArgs e)
var items = mFanListView.SelectedItems;
if (items == null || items.Count == 0)
{
mPresetLabel.Visible = false;
mPresetLoadButton.Visible = false;
mPresetSaveButton.Visible = false;
mUnitLabel.Visible = false;
mUnitComboBox.Visible = false;
mGraph.Visible = false;
Expand All @@ -550,6 +568,9 @@ private void onFanListViewIndexChanged(object sender, EventArgs e)
return;
}

mPresetLabel.Visible = true;
mPresetLoadButton.Visible = true;
mPresetSaveButton.Visible = true;
mUnitLabel.Visible = true;
mUnitComboBox.Visible = true;
mGraph.Visible = true;
Expand Down Expand Up @@ -649,6 +670,122 @@ private void onRemoveButtonClick(object sender, EventArgs e)
mFanListView.EndUpdate();
}

private void onPresetLoadButtonClick(object sender, EventArgs e)
{
if (mSelectedFanData == null)
return;

string nowDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string presetDirectory = nowDirectory + "\\preset";
if (Directory.Exists(presetDirectory) == false)
{
presetDirectory = nowDirectory;
}

var ofd = new OpenFileDialog();
ofd.Title = StringLib.Load;
ofd.InitialDirectory = presetDirectory;
ofd.Filter = "Preset file (*.preset) | *.preset;";
var dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
try
{
string fileName = ofd.FileName;
string jsonString = File.ReadAllText(fileName);

// check data
var rootObject = JObject.Parse(jsonString);
bool isStep = rootObject.Value<bool>("step");
int hysteresis = rootObject.Value<int>("hysteresis");
var unit = (FanValueUnit)rootObject.Value<int>("unit");

var valueList = rootObject.Value<JArray>("value");
if (unit == FanValueUnit.Size_1)
{
if (valueList.Count != FanData.MAX_FAN_VALUE_SIZE_1)
throw new Exception();
}
else if (unit == FanValueUnit.Size_5)
{
if (valueList.Count != FanData.MAX_FAN_VALUE_SIZE_5)
throw new Exception();
}
else if (unit == FanValueUnit.Size_10)
{
if (valueList.Count != FanData.MAX_FAN_VALUE_SIZE_10)
throw new Exception();
}
else
{
throw new Exception();
}

mSelectedFanData.IsStep = isStep;
mSelectedFanData.Hysteresis = hysteresis;
mSelectedFanData.Unit = unit;
mSelectedFanData.setChangeUnitAndFanValue(unit);
for (int i = 0; i < valueList.Count; i++)
{
int value = valueList[i].Value<int>();
mSelectedFanData.ValueList[i] = value;
}

// setGraphFromSelectedFanData
this.setGraphFromSelectedFanData();

mUnitComboBox.SelectedIndex = (int)mSelectedFanData.Unit;
mStepCheckBox.Checked = mSelectedFanData.IsStep;
mLineItem.Line.StepType = (mStepCheckBox.Checked == true) ? StepType.ForwardStep : StepType.NonStep;
mHysNumericUpDown.Enabled = mStepCheckBox.Checked;
mHysNumericUpDown.Value = mSelectedFanData.Hysteresis;

this.onUpdateTimer();
}
catch
{
MessageBox.Show(StringLib.Failed_to_read_preset_file);
}
}
}

private void onPresetSaveButtonClick(object sender, EventArgs e)
{
if (mSelectedFanData == null)
return;

string nowDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string presetDirectory = nowDirectory + "\\preset";
if (Directory.Exists(presetDirectory) == false)
{
presetDirectory = nowDirectory;
}

var sfd = new SaveFileDialog();
sfd.Title = StringLib.Save;
sfd.InitialDirectory = presetDirectory;
sfd.Filter = "Preset file (*.preset) | *.preset;";
var dr = sfd.ShowDialog();
if (dr == DialogResult.OK)
{
var rootObject = new JObject();
rootObject["step"] = mSelectedFanData.IsStep;
rootObject["hysteresis"] = mSelectedFanData.Hysteresis;
rootObject["unit"] = (int)mSelectedFanData.Unit;

var valueList = new JArray();
for (int i = 0; i < mSelectedFanData.getMaxFanValue(); i++)
{
int value = mSelectedFanData.ValueList[i];
valueList.Add(value);
}
rootObject["value"] = valueList;

string fileName = sfd.FileName;
File.WriteAllText(fileName, rootObject.ToString());
}
}

private void onApplyButtonClick(object sender, EventArgs e)
{
for (int i = 0; i < mControlDataList.Count; i++)
Expand Down Expand Up @@ -679,6 +816,6 @@ private void onOKButtonClick(object sender, EventArgs e)
{
this.onApplyButtonClick(sender, e);
this.Close();
}
}
}
}
2 changes: 1 addition & 1 deletion FanCtrl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PublisherName>Lich</PublisherName>
<SuiteName>FanCtrl</SuiteName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.2.7.0</ApplicationVersion>
<ApplicationVersion>1.2.8.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
8 changes: 3 additions & 5 deletions FanCtrl/Hardware/HardwareManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//#define MY_DEBUG

using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Security.AccessControl;
Expand Down Expand Up @@ -752,8 +750,8 @@ private void createGPUControl()
var value = e.Current;
int coolerID = value.CoolerId;
int speed = value.CurrentLevel;
int minSpeed = value.DefaultMinimumLevel;
int maxSpeed = value.DefaultMaximumLevel;
int minSpeed = 0;// value.DefaultMinimumLevel;
int maxSpeed = 100;// value.DefaultMaximumLevel;

var name = "GPU Fan Control #" + gpuFanNum++;
while (this.isExistControl(name) == true)
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
[assembly: AssemblyVersion("1.2.7")]
[assembly: AssemblyFileVersion("1.2.7")]
[assembly: AssemblyInformationalVersion("1.2.7")]
[assembly: AssemblyVersion("1.2.8")]
[assembly: AssemblyFileVersion("1.2.8")]
[assembly: AssemblyInformationalVersion("1.2.8")]
36 changes: 36 additions & 0 deletions StringLib.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f12543

Please sign in to comment.