-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Rem0o/feature/refactor_and_optimize
Refactor + cleanup
- Loading branch information
Showing
4 changed files
with
113 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,44 @@ | ||
using FanControl.OpenFanPlugin; | ||
using FanControl.Plugins; | ||
using System; | ||
using System.Net; | ||
using FanControl.Plugins; | ||
|
||
namespace FanControl.OpenFanPlugin | ||
{ | ||
public class OpenFanManagementControlSensor: IPluginControlSensor | ||
{ | ||
private readonly int _fanIndex; | ||
private float? _val; | ||
private float? _lastSetValue; | ||
|
||
|
||
public OpenFanManagementControlSensor(int fanIndex) => _fanIndex = fanIndex; | ||
|
||
public float? Value { get; private set; } | ||
|
||
public string Name => $"OpenFAN Fan #{(int)_fanIndex + 1}"; | ||
public string Name => $"OpenFAN Fan #{_fanIndex + 1}"; | ||
|
||
public string Origin => $"OpenFAN"; | ||
|
||
public string Id => "Control_" + _fanIndex.ToString(); | ||
public string Id => "OpenFan/Control/" + _fanIndex.ToString(); | ||
|
||
public void Reset() | ||
{ | ||
//DellSmbiosBzh.EnableAutomaticFanControl(_fanIndex == BzhFanIndex.Fan1 ? false : true); | ||
// set back the original control value, is there a command to get the current value we could use | ||
// to get the original value at the start? | ||
} | ||
|
||
public void Set(float val) | ||
{ | ||
if (val != _val) | ||
{ | ||
SetFanSpeed(val); | ||
_val = val; | ||
} | ||
_lastSetValue = val; | ||
} | ||
|
||
public void Update() => Value = _val; | ||
public void Update(){ } | ||
|
||
|
||
private void SetFanSpeed(float speed) | ||
public void SetFanSpeed(OpenFan_Serial serial) | ||
{ | ||
OpenFan_Serial OpenFan = new OpenFan_Serial(); | ||
OpenFan.SetPercent(_fanIndex, (int)speed); | ||
OpenFan.Close(); | ||
if (Value != _lastSetValue) | ||
{ | ||
serial.SetPercent(_fanIndex, (int)_lastSetValue); | ||
Value = _lastSetValue; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
using FanControl.Plugins; | ||
using System; | ||
using System.Net; | ||
using FanControl.OpenFanPlugin; | ||
using System.Collections.Generic; | ||
|
||
namespace FanControl.OpenFanPlugin | ||
{ | ||
public class OpenFanManagementFanSensor : IPluginSensor | ||
{ | ||
private readonly int _fanIndex; | ||
|
||
public OpenFanManagementFanSensor(int fanIndex) => _fanIndex = fanIndex; | ||
public OpenFanManagementFanSensor(int fanIndex) | ||
{ | ||
_fanIndex = fanIndex; | ||
} | ||
|
||
public string Identifier => $"OpenFan/Fan{(int)_fanIndex}"; | ||
public string Identifier => $"OpenFan/Fan/{_fanIndex}"; | ||
|
||
public float? Value { get; private set; } | ||
|
||
public string Name => $"OpenFan FAN #{(int)_fanIndex + 1}"; | ||
public string Name => $"OpenFan FAN #{_fanIndex + 1}"; | ||
|
||
public string Origin => $"OpenFan"; | ||
|
||
public string Id => "Fan_" + _fanIndex.ToString(); | ||
|
||
public void Update() => Value = GetFanRPM(); | ||
public void Update() { } | ||
|
||
private int GetFanRPM() | ||
public void UpdateFanRPM(SerialResponse response) | ||
{ | ||
int rpm = 0; | ||
OpenFan_Serial OpenFan = new OpenFan_Serial(); | ||
rpm = OpenFan.ReadRPM(_fanIndex); | ||
OpenFan.Close(); | ||
|
||
return rpm; | ||
int rpm = response.Data[_fanIndex]; | ||
Value = rpm; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.