Skip to content

Commit

Permalink
Preparing Backgroundog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 18, 2023
1 parent 3e4a4f8 commit 441b8ba
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
26 changes: 25 additions & 1 deletion src/Project/Sucrose.Backgroundog/Extension/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ public static JObject GetCpuInfo()
{
{ "Min", SBMI.CpuData.Min },
{ "Now", SBMI.CpuData.Now },
{ "Max", SBMI.CpuData.Max }
{ "Max", SBMI.CpuData.Max },
{ "Name", SBMI.CpuData.Name }
};
}

public static JObject GetMemoryInfo()
{
return new JObject
{
{ "Name", SBMI.CpuData.Name },
{ "MemoryUsed", SBMI.MemoryData.MemoryUsed },
{ "MemoryLoad", SBMI.MemoryData.MemoryLoad },
{ "MemoryAvailable", SBMI.MemoryData.MemoryAvailable },
Expand All @@ -27,5 +29,27 @@ public static JObject GetMemoryInfo()
{ "VirtualMemoryAvailable", SBMI.MemoryData.VirtualMemoryAvailable }
};
}

public static JObject GetBatteryInfo()
{
return new JObject
{
{ "Name", SBMI.BatteryData.Name },
{ "Voltage", SBMI.BatteryData.Voltage },
{ "ChargeRate", SBMI.BatteryData.ChargeRate },
{ "ChargeLevel", SBMI.BatteryData.ChargeLevel },
{ "ChargeCurrent", SBMI.BatteryData.ChargeCurrent },
{ "DischargeRate", SBMI.BatteryData.DischargeRate },
{ "DischargeLevel", SBMI.BatteryData.DischargeLevel },
{ "DischargeCurrent", SBMI.BatteryData.DischargeCurrent },
{ "DegradationLevel", SBMI.BatteryData.DegradationLevel },
{ "DesignedCapacity", SBMI.BatteryData.DesignedCapacity },
{ "RemainingCapacity", SBMI.BatteryData.RemainingCapacity },
{ "FullChargedCapacity", SBMI.BatteryData.FullChargedCapacity },
{ "ChargeDischargeRate", SBMI.BatteryData.ChargeDischargeRate },
{ "ChargeDischargeCurrent", SBMI.BatteryData.ChargeDischargeCurrent },
{ "RemainingTimeEstimated", SBMI.BatteryData.RemainingTimeEstimated }
};
}
}
}
63 changes: 62 additions & 1 deletion src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static async Task Start()
{
Min = Sensor.Min,
Max = Sensor.Max,
Now = Sensor.Value
Now = Sensor.Value,
Name = Hardware.Name
};
}
}
Expand All @@ -38,6 +39,8 @@ public static async Task Start()
{
Hardware.Update();

SBMI.MemoryData.Name = Hardware.Name;

foreach (ISensor Sensor in Hardware.Sensors)
{
switch (Sensor.Name)
Expand Down Expand Up @@ -65,10 +68,68 @@ public static async Task Start()
}
}
}
else if (Hardware.HardwareType == HardwareType.Battery)
{
Hardware.Update();

SBMI.BatteryData.Name = Hardware.Name;

foreach (ISensor Sensor in Hardware.Sensors)
{
switch (Sensor.Name)
{
case "Charge Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.ChargeLevel = Sensor.Value;
break;
case "Discharge Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.DischargeLevel = Sensor.Value;
break;
case "Voltage" when Sensor.SensorType == SensorType.Voltage:
SBMI.BatteryData.Voltage = Sensor.Value;
break;
case "Charge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.ChargeCurrent = Sensor.Value;
break;
case "Discharge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.DischargeCurrent = Sensor.Value;
break;
case "Charge / Discharge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.ChargeDischargeCurrent = Sensor.Value;
break;
case "Designed Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.DesignedCapacity = Sensor.Value;
break;
case "Full Charged Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.FullChargedCapacity = Sensor.Value;
break;
case "Remaining Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.RemainingCapacity = Sensor.Value;
break;
case "Charge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.ChargeRate = Sensor.Value;
break;
case "Discharge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.DischargeRate = Sensor.Value;
break;
case "Charge / Discharge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.ChargeDischargeRate = Sensor.Value;
break;
case "Degradation Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.DegradationLevel = Sensor.Value;
break;
case "Remaining Time (Estimated)" when Sensor.SensorType == SensorType.TimeSpan:
SBMI.BatteryData.RemainingTimeEstimated = Sensor.Value;
break;
default:
break;
}
}
}
}

Console.WriteLine(JsonConvert.SerializeObject(SBMI.CpuData, Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(SBMI.MemoryData, Formatting.Indented));
Console.WriteLine(JsonConvert.SerializeObject(SBMI.BatteryData, Formatting.Indented));

//foreach (IHardware Hardware in SBMI.Computer.Hardware)
//{
Expand Down
24 changes: 23 additions & 1 deletion src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibreHardwareMonitor.Hardware;
using SBSDBS = Sucrose.Backgroundog.Struct.Data.BatteryStruct;
using SBSDCS = Sucrose.Backgroundog.Struct.Data.CpuStruct;
using SBSDMS = Sucrose.Backgroundog.Struct.Data.MemoryStruct;
using Timer = System.Threading.Timer;
Expand All @@ -21,13 +22,15 @@ internal static class Internal
{
Min = 0f,
Now = 0f,
Max = 0f
Max = 0f,
Name = string.Empty
};

public static SBSDMS MemoryData = new()
{
MemoryUsed = 0f,
MemoryLoad = 0f,
Name = string.Empty,
MemoryAvailable = 0f,
VirtualMemoryUsed = 0f,
VirtualMemoryLoad = 0f,
Expand All @@ -46,5 +49,24 @@ internal static class Internal
IsControllerEnabled = false,
IsMotherboardEnabled = false,
};

public static SBSDBS BatteryData = new()
{
Voltage = 0f,
ChargeRate = 0f,
ChargeLevel = 0f,
ChargeCurrent = 0f,
DischargeRate = 0f,
DischargeLevel = 0f,
Name = string.Empty,
DischargeCurrent = 0f,
DegradationLevel = 0f,
DesignedCapacity = 0f,
RemainingCapacity = 0f,
FullChargedCapacity = 0f,
ChargeDischargeRate = 0f,
ChargeDischargeCurrent = 0f,
RemainingTimeEstimated = 0f
};
}
}
76 changes: 76 additions & 0 deletions src/Project/Sucrose.Backgroundog/Struct/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public struct CpuStruct
///
/// </summary>
public float? Max;
/// <summary>
///
/// </summary>
public string? Name;
}

/// <summary>
Expand All @@ -28,6 +32,10 @@ public struct CpuStruct
[StructLayout(LayoutKind.Sequential)]
public struct MemoryStruct
{
/// <summary>
///
/// </summary>
public string? Name;
/// <summary>
///
/// </summary>
Expand All @@ -53,4 +61,72 @@ public struct MemoryStruct
/// </summary>
public float? VirtualMemoryAvailable;
}

/// <summary>
///
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct BatteryStruct
{
/// <summary>
///
/// </summary>
public string? Name;
/// <summary>
///
/// </summary>
public float? Voltage;
/// <summary>
///
/// </summary>
public float? ChargeRate;
/// <summary>
///
/// </summary>
public float? ChargeLevel;
/// <summary>
///
/// </summary>
public float? ChargeCurrent;
/// <summary>
///
/// </summary>
public float? DischargeRate;
/// <summary>
///
/// </summary>
public float? DischargeLevel;
/// <summary>
///
/// </summary>
public float? DischargeCurrent;
/// <summary>
///
/// </summary>
public float? DegradationLevel;
/// <summary>
///
/// </summary>
public float? DesignedCapacity;
/// <summary>
///
/// </summary>
public float? RemainingCapacity;
/// <summary>
///
/// </summary>
public float? FullChargedCapacity;
/// <summary>
///
/// </summary>
public float? ChargeDischargeRate;
/// <summary>
///
/// </summary>
public float? ChargeDischargeCurrent;
/// <summary>
///
/// </summary>
public float? RemainingTimeEstimated;
}
}

0 comments on commit 441b8ba

Please sign in to comment.