Skip to content

Commit

Permalink
Added OSD items
Browse files Browse the repository at this point in the history
  • Loading branch information
lich426 committed Jun 16, 2020
1 parent 1104931 commit 9824bb1
Show file tree
Hide file tree
Showing 18 changed files with 900 additions and 218 deletions.
3 changes: 2 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.1.6.0</ApplicationVersion>
<ApplicationVersion>1.1.7.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down Expand Up @@ -215,6 +215,7 @@
<Compile Include="FanCtrl\Data\Option\StartupControl.cs" />
<Compile Include="FanCtrl\Controller\SMBusController.cs" />
<Compile Include="FanCtrl\Controller\USBController.cs" />
<Compile Include="FanCtrl\Hardware\Sensor\OSDSensor.cs" />
<Compile Include="FanCtrl\Util\MessageBoxEx.cs" />
<Compile Include="FanCtrl\Util\Util.cs" />
<Compile Include="LightingForm.cs">
Expand Down
5 changes: 4 additions & 1 deletion FanCtrl/Data/OSD/OSDGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class OSDGroup

public Color Color { get; set; } = Color.White;

public int Digit { get; set; } = 5;

private List<OSDItem> mItemList = new List<OSDItem>();
public List<OSDItem> ItemList
{
Expand Down Expand Up @@ -63,7 +65,7 @@ public string getOSDString(int maxNameLength)
for (int i = 0; i < mItemList.Count; i++)
{
var item = mItemList[i];
osdString.Append(item.getOSDString());
osdString.Append(item.getOSDString(Digit));
}

osdString.Append("\n");
Expand All @@ -76,6 +78,7 @@ public OSDGroup clone()
group.Name = this.Name;
group.IsColor = this.IsColor;
group.Color = Color.FromArgb(this.Color.R, this.Color.G, this.Color.B);
group.Digit = this.Digit;

for (int i = 0; i < mItemList.Count; i++)
group.ItemList.Add(mItemList[i].clone());
Expand Down
62 changes: 47 additions & 15 deletions FanCtrl/Data/OSD/OSDItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@ namespace FanCtrl
public enum OSDItemType : int
{
Sensor = 0,
Fan = 1,
Control = 2,
Predefined = 3,
Fan,
Control,
Predefined,
Unknown,
}

public enum OSDUnitType : int
{
Temperature = 0,
RPM = 1,
Percent = 2,
//MHz = 3,
//MB = 4,
//FPS = 5,
RPM,
Percent,
MHz,
kHz,
KB,
MB,
GB,
MBPerSec,
Voltage,
Power,
FPS,
Blank,
Unknown,
}

public class OSDItem
Expand All @@ -37,7 +46,7 @@ public class OSDItem

public Color Color { get; set; } = Color.White;

public string getOSDString()
public string getOSDString(int digit)
{
try
{
Expand All @@ -58,7 +67,7 @@ public string getOSDString()
}

// Value prefix
osdString.Append("<A0>");
osdString.Append(string.Format("<A=-{0}>", digit));

// Value
var hardwareManager = HardwareManager.getInstance();
Expand Down Expand Up @@ -87,12 +96,24 @@ public string getOSDString()
int value = control.Value;
osdString.Append(value.ToString());
}
/*
else if (ItemType == OSDItemType.Predefined)
{
if(UnitType == OSDUnitType.FPS)
{
osdString.Append("<FR>");
}
else if(UnitType == OSDUnitType.Blank)
{
osdString.Append(" ");
}
else
{
var sensor = hardwareManager.getOSDSensor(Index);
if (sensor == null)
return "";
osdString.Append(sensor.getString());
}
}
*/
else
{
return "";
Expand Down Expand Up @@ -146,16 +167,27 @@ public string getUnitString()
case OSDUnitType.Percent:
return " %";

/*
case OSDUnitType.MHz:
case OSDUnitType.kHz:
return " MHz";

case OSDUnitType.KB:
case OSDUnitType.GB:
case OSDUnitType.MB:
return " MB";

case OSDUnitType.MBPerSec:
return " MB/s";

case OSDUnitType.Voltage:
return " V";

case OSDUnitType.Power:
return " W";

case OSDUnitType.FPS:
return " FPS";
*/

default:
return " ";
}
Expand Down
54 changes: 40 additions & 14 deletions FanCtrl/Data/OSD/OSDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Windows.Forms.DataVisualization.Charting;
using System.Timers;

namespace FanCtrl
{
Expand Down Expand Up @@ -57,11 +57,29 @@ public bool IsEnable
}
}

private bool mIsTime = false;
public bool IsTime
{
get
{
Monitor.Enter(mLock);
bool isTime = mIsTime;
Monitor.Exit(mLock);
return isTime;
}
set
{
Monitor.Enter(mLock);
mIsTime = value;
Monitor.Exit(mLock);
}
}

private List<OSDGroup> mGroupList = new List<OSDGroup>();

private OSDManager()
{

}

private void clear()
Expand Down Expand Up @@ -98,6 +116,7 @@ public void read()
var rootObject = JObject.Parse(jsonString);

mIsEnable = (rootObject.ContainsKey("enable") == true) ? rootObject.Value<bool>("enable") : false;
mIsTime = (rootObject.ContainsKey("time") == true) ? rootObject.Value<bool>("time") : false;

if (rootObject.ContainsKey("group") == true)
{
Expand All @@ -106,16 +125,18 @@ public void read()
{
var groupObject = (JObject)groupList[i];

string name = groupObject.Value<string>("name");
bool isColor = groupObject.Value<bool>("isColor");
byte r = groupObject.Value<byte>("r");
byte g = groupObject.Value<byte>("g");
byte b = groupObject.Value<byte>("b");
string name = (groupObject.ContainsKey("name") == false) ? "" : groupObject.Value<string>("name");
bool isColor = (groupObject.ContainsKey("isColor") == false) ? false : groupObject.Value<bool>("isColor");
byte r = (groupObject.ContainsKey("r") == false) ? (byte)0xFF : groupObject.Value<byte>("r");
byte g = (groupObject.ContainsKey("g") == false) ? (byte)0xFF : groupObject.Value<byte>("g");
byte b = (groupObject.ContainsKey("b") == false) ? (byte)0xFF : groupObject.Value<byte>("b");
int digit = (groupObject.ContainsKey("digit") == false) ? 5 : groupObject.Value<int>("digit");

var group = new OSDGroup();
group.Name = name;
group.IsColor = isColor;
group.Color = Color.FromArgb(r, g, b);
group.Digit = digit;

if (groupObject.ContainsKey("item") == true)
{
Expand All @@ -124,13 +145,16 @@ public void read()
{
var itemObject = (JObject)itemList[j];

var itemType = itemObject.Value<int>("itemType");
var unitType = itemObject.Value<int>("unitType");
int index = itemObject.Value<int>("index");
isColor = itemObject.Value<bool>("isColor");
r = itemObject.Value<byte>("r");
g = itemObject.Value<byte>("g");
b = itemObject.Value<byte>("b");
var itemType = (itemObject.ContainsKey("itemType") == false) ? (int)OSDItemType.Unknown : itemObject.Value<int>("itemType");
var unitType = (itemObject.ContainsKey("unitType") == false) ? (int)OSDUnitType.Unknown : itemObject.Value<int>("unitType");
int index = (itemObject.ContainsKey("index") == false) ? 0 : itemObject.Value<int>("index");
isColor = (itemObject.ContainsKey("isColor") == false) ? false : itemObject.Value<bool>("isColor");
r = (itemObject.ContainsKey("r") == false) ? (byte)0xFF : itemObject.Value<byte>("r");
g = (itemObject.ContainsKey("g") == false) ? (byte)0xFF : itemObject.Value<byte>("g");
b = (itemObject.ContainsKey("b") == false) ? (byte)0xFF : itemObject.Value<byte>("b");

if (itemType >= (int)OSDItemType.Unknown || unitType >= (int)OSDUnitType.Unknown)
continue;

var item = new OSDItem();
item.ItemType = (OSDItemType)itemType;
Expand Down Expand Up @@ -163,6 +187,7 @@ public void write()
{
var rootObject = new JObject();
rootObject["enable"] = mIsEnable;
rootObject["time"] = mIsTime;

var groupList = new JArray();
for(int i = 0; i < mGroupList.Count; i++)
Expand All @@ -175,6 +200,7 @@ public void write()
groupObject["r"] = group.Color.R;
groupObject["g"] = group.Color.G;
groupObject["b"] = group.Color.B;
groupObject["digit"] = group.Digit;

var itemList = new JArray();
for (int j = 0; j < group.ItemList.Count; j++)
Expand Down
Loading

0 comments on commit 9824bb1

Please sign in to comment.