Skip to content

Commit

Permalink
Add support for Hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
lich426 committed Jul 2, 2021
1 parent 04c46b2 commit acaeec1
Show file tree
Hide file tree
Showing 13 changed files with 6,317 additions and 60 deletions.
2 changes: 1 addition & 1 deletion ControlForm.Designer.cs

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

13 changes: 12 additions & 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.3.9.0</ApplicationVersion>
<ApplicationVersion>1.4.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down Expand Up @@ -178,6 +178,8 @@
<Compile Include="FanCtrl\Data\Control\ControlManager.cs" />
<Compile Include="FanCtrl\Data\Control\FanData.cs" />
<Compile Include="FanCtrl\Data\Control\ControlData.cs" />
<Compile Include="FanCtrl\Data\Hotkey\HotkeyData.cs" />
<Compile Include="FanCtrl\Data\Hotkey\HotkeyManager.cs" />
<Compile Include="FanCtrl\Data\OSD\OSDGroup.cs" />
<Compile Include="FanCtrl\Data\OSD\OSDItem.cs" />
<Compile Include="FanCtrl\Data\OSD\OSDManager.cs" />
Expand Down Expand Up @@ -242,6 +244,12 @@
<Compile Include="FanCtrl\Util\MessageBoxEx.cs" />
<Compile Include="FanCtrl\Util\PointObj.cs" />
<Compile Include="FanCtrl\Util\Util.cs" />
<Compile Include="HotkeyForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="HotkeyForm.Designer.cs">
<DependentUpon>HotkeyForm.cs</DependentUpon>
</Compile>
<Compile Include="LightingForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -281,6 +289,9 @@
<EmbeddedResource Include="ControlForm.resx">
<DependentUpon>ControlForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="HotkeyForm.resx">
<DependentUpon>HotkeyForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LightingForm.resx">
<DependentUpon>LightingForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down
15 changes: 4 additions & 11 deletions FanCtrl/Controller/SMBUsIntel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@ public static byte smbDetect(byte addr)

if (res >= 0)
{
ushort data = getWord(addr, 0x06);
var temp = BitConverter.GetBytes(data);
Array.Reverse(temp);

ushort manufacturerID = BitConverter.ToUInt16(temp, 0);

for (int i = 0; i < SMBusController.sManufacturerID.Length; i++)
{
if (manufacturerID == SMBusController.sManufacturerID[i])
return addr;
}
ushort manufacturerID = getWord(addr, 0x06);
ushort deviceID = getWord(addr, 0x07);
if (manufacturerID > 0 && deviceID > 0)
return addr;
}
return 0x00;
}
Expand Down
10 changes: 0 additions & 10 deletions FanCtrl/Controller/SMBusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ namespace FanCtrl
{
class SMBusController
{
public static ushort[] sManufacturerID = {
0x1B09, // On Semiconductor
0x0054, // MicroChip
0x104A, // ST
0x00B3, // RENESAS
0x1131, // NXP
0x1C85, // ABLIC

};

enum CPU_TYPE
{
AMD,
Expand Down
15 changes: 4 additions & 11 deletions FanCtrl/Controller/SMbusAmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ public static byte smbDetect(byte addr)
Ring0.WriteSmbus(SMB_HSTCNT, 0);
if (transaction() == true)
{
ushort data = getWord(addr, 0x06);
var temp = BitConverter.GetBytes(data);
Array.Reverse(temp);

ushort manufacturerID = BitConverter.ToUInt16(temp, 0);

for (int i = 0; i < SMBusController.sManufacturerID.Length; i++)
{
if (manufacturerID == SMBusController.sManufacturerID[i])
return addr;
}
ushort manufacturerID = getWord(addr, 0x06);
ushort deviceID = getWord(addr, 0x07);
if (manufacturerID > 0 && deviceID > 0)
return addr;
}
return 0x00;
}
Expand Down
34 changes: 34 additions & 0 deletions FanCtrl/Data/Hotkey/HotkeyData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FanCtrl
{
public class HotkeyData
{
public bool mIsCtrl { get; set; } = false;
public bool mIsAlt { get; set; } = false;
public bool mIsLShift { get; set; } = false;
public bool mIsRShift { get; set; } = false;

public int mKey { get; set; } = (int)Keys.None;

public HotkeyData()
{
this.reset();
}

public void reset()
{
mIsCtrl = false;
mIsAlt = false;
mIsLShift = false;
mIsRShift = false;
mKey = (int)Keys.None;
}
}
}
112 changes: 112 additions & 0 deletions FanCtrl/Data/Hotkey/HotkeyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection;

namespace FanCtrl
{
public class HotkeyManager
{
private string mHotkeyFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "Hotkey.json";

private static HotkeyManager sManager = new HotkeyManager();
public static HotkeyManager getInstance() { return sManager; }

public HotkeyData mEnableFanControlData { get; set; } = new HotkeyData();
public HotkeyData mModeNormalData { get; set; } = new HotkeyData();
public HotkeyData mModeSilenceData { get; set; } = new HotkeyData();
public HotkeyData mModePerformanceData { get; set; } = new HotkeyData();
public HotkeyData mModeGameData { get; set; } = new HotkeyData();
public HotkeyData mEnableOSDData { get; set; } = new HotkeyData();

private HotkeyManager()
{
this.reset();
}

public void reset()
{
mEnableFanControlData.reset();
mModeNormalData.reset();
mModeSilenceData.reset();
mModePerformanceData.reset();
mModeGameData.reset();
mEnableOSDData.reset();
}

public bool read()
{
try
{
var jsonString = File.ReadAllText(mHotkeyFileName);
var rootObject = JObject.Parse(jsonString);

this.readData(rootObject, "mEnableFanControlData", mEnableFanControlData);
this.readData(rootObject, "mModeNormalData", mModeNormalData);
this.readData(rootObject, "mModeSilenceData", mModeSilenceData);
this.readData(rootObject, "mModePerformanceData", mModePerformanceData);
this.readData(rootObject, "mModeGameData", mModeGameData);
this.readData(rootObject, "mEnableOSDData", mEnableOSDData);
}
catch
{
return false;
}
return true;
}

private void readData(JObject rootObject, string keyString, HotkeyData HotkeyData)
{
if (rootObject.ContainsKey(keyString) == false)
return;

var hotKeyObject = rootObject.Value<JObject>(keyString);
bool isCtrl = (hotKeyObject.ContainsKey("mIsCtrl") == true) ? hotKeyObject.Value<bool>("mIsCtrl") : false;
bool isAlt = (hotKeyObject.ContainsKey("mIsAlt") == true) ? hotKeyObject.Value<bool>("mIsAlt") : false;
bool isLShift = (hotKeyObject.ContainsKey("mIsLShift") == true) ? hotKeyObject.Value<bool>("mIsLShift") : false;
bool isRShift = (hotKeyObject.ContainsKey("mIsRShift") == true) ? hotKeyObject.Value<bool>("mIsRShift") : false;
int key = (hotKeyObject.ContainsKey("mKey") == true) ? hotKeyObject.Value<int>("mKey") : 0;

HotkeyData.mIsCtrl = isCtrl;
HotkeyData.mIsAlt = isAlt;
HotkeyData.mIsLShift = isLShift;
HotkeyData.mIsRShift = isRShift;
HotkeyData.mKey = key;
}

public void write()
{
try
{
var rootObject = new JObject();

this.writeData(rootObject, "mEnableFanControlData", mEnableFanControlData);
this.writeData(rootObject, "mModeNormalData", mModeNormalData);
this.writeData(rootObject, "mModeSilenceData", mModeSilenceData);
this.writeData(rootObject, "mModePerformanceData", mModePerformanceData);
this.writeData(rootObject, "mModeGameData", mModeGameData);
this.writeData(rootObject, "mEnableOSDData", mEnableOSDData);

File.WriteAllText(mHotkeyFileName, rootObject.ToString());
}
catch {}
}

private void writeData(JObject rootObject, string keyString, HotkeyData HotkeyData)
{
var tempObject = new JObject();
tempObject["mIsCtrl"] = HotkeyData.mIsCtrl;
tempObject["mIsAlt"] = HotkeyData.mIsAlt;
tempObject["mIsLShift"] = HotkeyData.mIsLShift;
tempObject["mIsRShift"] = HotkeyData.mIsRShift;
tempObject["mKey"] = HotkeyData.mKey;

rootObject[keyString] = tempObject;
}
}
}
Loading

0 comments on commit acaeec1

Please sign in to comment.