From 404476990aaf0df6039db75d434303fc2ff9f8e2 Mon Sep 17 00:00:00 2001 From: Lich Date: Sat, 3 Dec 2022 13:39:12 +0900 Subject: [PATCH] v1.5.5 --- FanCtrl.csproj | 3 +- Properties/AssemblyInfo.cs | 6 +-- src/UI/ControlForm.cs | 12 +++-- src/libs/Hardware/Control/BaseControl.cs | 46 ++++++++++++++----- src/libs/Hardware/HardwareManager.cs | 13 ++---- .../Hardware/liquidctl/LiquidctlManager.cs | 25 ++++++++++ 6 files changed, 77 insertions(+), 28 deletions(-) diff --git a/FanCtrl.csproj b/FanCtrl.csproj index b5c3e83..7e057e1 100644 --- a/FanCtrl.csproj +++ b/FanCtrl.csproj @@ -28,7 +28,7 @@ Lich FanCtrl 0 - 1.5.4.0 + 1.5.5.0 false true true @@ -423,6 +423,7 @@ mkdir "$(TargetDir)locale\ko" copy /Y "$(TargetDir)fr\*.*" "$(TargetDir)locale\fr" copy /Y "$(TargetDir)ja\*.*" "$(TargetDir)locale\ja" copy /Y "$(TargetDir)ko\*.*" "$(TargetDir)locale\ko" +timeout 1 > NUL rmdir /S /Q "$(TargetDir)fr" rmdir /S /Q "$(TargetDir)ja" rmdir /S /Q "$(TargetDir)ko" diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 7b43ce9..aab1a0f 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 // 기본값으로 할 수 있습니다. -[assembly: AssemblyVersion("1.5.4")] -[assembly: AssemblyFileVersion("1.5.4")] -[assembly: AssemblyInformationalVersion("1.5.4")] +[assembly: AssemblyVersion("1.5.5")] +[assembly: AssemblyFileVersion("1.5.5")] +[assembly: AssemblyInformationalVersion("1.5.5")] diff --git a/src/UI/ControlForm.cs b/src/UI/ControlForm.cs index 22b0f4b..39c3427 100644 --- a/src/UI/ControlForm.cs +++ b/src/UI/ControlForm.cs @@ -873,11 +873,12 @@ private void onPresetLoadButtonClick(object sender, EventArgs e) // check data var rootObject = JObject.Parse(jsonString); - bool isStep = rootObject.Value("step"); - int hysteresis = rootObject.Value("hysteresis"); - int auto = rootObject.Value("auto"); + bool isStep = (rootObject.ContainsKey("step") == true) ? rootObject.Value("step") : true; + int hysteresis = (rootObject.ContainsKey("hysteresis") == true) ? rootObject.Value("hysteresis") : 0; + int auto = (rootObject.ContainsKey("auto") == true) ? rootObject.Value("auto") : 0; + int delay = (rootObject.ContainsKey("delay") == true) ? rootObject.Value("delay") : 0; - var unit = (FanValueUnit)rootObject.Value("unit"); + var unit = (rootObject.ContainsKey("unit") == true) ? (FanValueUnit)rootObject.Value("unit") : FanValueUnit.Size_5; var valueList = rootObject.Value("value"); if (unit == FanValueUnit.Size_1) { @@ -902,6 +903,7 @@ private void onPresetLoadButtonClick(object sender, EventArgs e) mSelectedFanData.IsStep = isStep; mSelectedFanData.Hysteresis = hysteresis; mSelectedFanData.Auto = auto; + mSelectedFanData.DelayTime = delay; mSelectedFanData.setChangeUnitAndFanValue(unit); for (int i = 0; i < valueList.Count; i++) { @@ -917,6 +919,7 @@ private void onPresetLoadButtonClick(object sender, EventArgs e) mLineItem.Line.StepType = (mStepCheckBox.Checked == true) ? StepType.ForwardStep : StepType.NonStep; mHysNumericUpDown.Enabled = mStepCheckBox.Checked; mHysNumericUpDown.Value = mSelectedFanData.Hysteresis; + mDelayNumericUpDown.Value = mSelectedFanData.DelayTime; this.onUpdateTimer(); } @@ -951,6 +954,7 @@ private void onPresetSaveButtonClick(object sender, EventArgs e) rootObject["hysteresis"] = mSelectedFanData.Hysteresis; rootObject["unit"] = (int)mSelectedFanData.Unit; rootObject["auto"] = mSelectedFanData.Auto; + rootObject["delay"] = mSelectedFanData.DelayTime; var valueList = new JArray(); for (int i = 0; i < mSelectedFanData.getMaxFanValue(); i++) diff --git a/src/libs/Hardware/Control/BaseControl.cs b/src/libs/Hardware/Control/BaseControl.cs index cde7ce5..f8a5aeb 100644 --- a/src/libs/Hardware/Control/BaseControl.cs +++ b/src/libs/Hardware/Control/BaseControl.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using LibreHardwareMonitor.Hardware; +using Newtonsoft.Json.Linq; namespace FanCtrl { @@ -20,8 +21,8 @@ public class BaseControl : BaseDevice // timer timeout (ms) public int Timeout { get; set; } - private System.Timers.Timer mTimer; private object mTimerLock = new object(); + private System.Timers.Timer mTimer; private int mTimerValue; public BaseControl(LIBRARY_TYPE type) @@ -58,45 +59,66 @@ public virtual void setAuto() } - public void setSpeedWithTimer(int value, int time) + public void setSpeedWithTimer(int value) { + Monitor.Enter(mTimerLock); + int time = Timeout; + Timeout = 0; + if (time <= 0) { mTimerValue = value; + mTimer?.Stop(); this.setSpeed(value); + Monitor.Exit(mTimerLock); return; } if (Value == value) { - Monitor.Enter(mTimerLock); - mTimerValue = value; - Timeout = 0; mTimer?.Stop(); - Monitor.Exit(mTimerLock); + mTimerValue = value; + Console.WriteLine("BaseControl.setSpeedWithTimer() : equal value({0})", value); } else if (mTimerValue != value) { Console.WriteLine("BaseControl.setSpeedWithTimer() : value({0}), mTimerValue({1})", value, mTimerValue); + + mTimer?.Stop(); mTimerValue = value; - Timeout = 0; - Monitor.Enter(mTimerLock); - mTimer?.Stop(); - Monitor.Exit(mTimerLock); - mTimer = new System.Timers.Timer(); mTimer.Interval = time; + var timer = mTimer; mTimer.Elapsed += (sender, e) => { Monitor.Enter(mTimerLock); + if (timer.Enabled == false) + { + Monitor.Exit(mTimerLock); + return; + } + Console.WriteLine("BaseControl.setSpeedWithTimer() : setSpeed()"); this.setSpeed(value); - mTimer?.Stop(); + timer.Stop(); Monitor.Exit(mTimerLock); }; mTimer.Start(); } + Monitor.Exit(mTimerLock); + } + + public void checkTimer() + { + Monitor.Enter(mTimerLock); + if (Value == NextValue && Value != mTimerValue) + { + mTimerValue = Value; + mTimer?.Stop(); + Console.WriteLine("BaseControl.checkTimer() : stop timer"); + } + Monitor.Exit(mTimerLock); } public void stopTimer() diff --git a/src/libs/Hardware/HardwareManager.cs b/src/libs/Hardware/HardwareManager.cs index b4f2b50..a9c0fc1 100644 --- a/src/libs/Hardware/HardwareManager.cs +++ b/src/libs/Hardware/HardwareManager.cs @@ -1227,22 +1227,19 @@ private void onUpdateTimer(object sender, EventArgs e) Console.WriteLine("manual mode : name({0}), value({1}), nextvalue({2})", control.Name, control.Value, control.NextValue); if (control.Value == control.NextValue) - continue; - - if (control.Timeout > 0) - { - control.setSpeedWithTimer(control.NextValue, control.Timeout); - } - else { - control.setSpeed(control.NextValue); + control.checkTimer(); + continue; } + + control.setSpeedWithTimer(control.NextValue); } foreach (var keyPair in mAutoControlDictionary) { var control = keyPair.Value; Console.WriteLine("auto mode : name({0})", control.Name); + control.stopTimer(); control.setAuto(); } } diff --git a/src/libs/Hardware/liquidctl/LiquidctlManager.cs b/src/libs/Hardware/liquidctl/LiquidctlManager.cs index f6b9cdc..a413401 100644 --- a/src/libs/Hardware/liquidctl/LiquidctlManager.cs +++ b/src/libs/Hardware/liquidctl/LiquidctlManager.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Diagnostics; using System.Threading.Tasks; +using System.Net; namespace FanCtrl { @@ -57,6 +58,8 @@ public void start() try { + this.initialize(); + var jsonString = getStatus(); var rootArray = JArray.Parse(jsonString); for (int i = 0; i < rootArray.Count; i++) @@ -200,6 +203,28 @@ private void onUpdateTimer(object sender, EventArgs e) Monitor.Exit(mLock); } + private void initialize() + { + try + { + var p = new Process(); + p.StartInfo.FileName = LiquidctlPath; + p.StartInfo.Arguments = "initialize all"; + p.StartInfo.CreateNoWindow = true; + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardOutput = true; + if (p.Start() == true) + { + var jsonString = p.StandardOutput.ReadToEnd(); + p.Close(); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + private string getStatus() { try