Skip to content

Commit

Permalink
Add sensorpanel import support
Browse files Browse the repository at this point in the history
- Change text rendering mode slightly to be more consistent (may cause some offset to existing panels)
  • Loading branch information
habibrehmansg committed Dec 15, 2024
1 parent 4ed3f6f commit 2cf24bf
Show file tree
Hide file tree
Showing 11 changed files with 858 additions and 50 deletions.
5 changes: 3 additions & 2 deletions InfoPanel/Drawing/CompatGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public override (float width, float height) MeasureString(string text, string fo
(strikeout ? FontStyle.Strikeout : FontStyle.Regular);

using var font = new Font(fontName, fontSize, fontStyle);
var size = this.Graphics.MeasureString(text, font);

var size = this.Graphics.MeasureString(text, font, 0, StringFormat.GenericTypographic);
return (size.Width, size.Height);
}

Expand All @@ -50,7 +51,7 @@ public override void DrawString(string text, string fontName, int fontSize, stri
using var font = new Font(fontName, fontSize, fontStyle);
using var brush = new SolidBrush(ColorTranslator.FromHtml(color));

using var format = new StringFormat();
using StringFormat format = (StringFormat)StringFormat.GenericTypographic.Clone();
if (rightAlign)
{
format.Alignment = StringAlignment.Far;
Expand Down
30 changes: 13 additions & 17 deletions InfoPanel/Drawing/GraphDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ public static void Run(ChartDisplayItem chartDisplayItem, MyGraphics g)
GraphDataCache.TryGetValue(key, out Queue<double>? queue);
if (queue != null)
{
if (HWHash.SENSORHASH.TryGetValue(key, out HWHash.HWINFO_HASH value))
HWHash.SENSORHASH.TryGetValue(key, out HWHash.HWINFO_HASH value);

lock (queue)
{
lock (queue)
{
queue.Enqueue(value.ValueNow);
queue.Enqueue(value.ValueNow);

if (queue.Count > 1000)
{
queue.Dequeue();
}
if (queue.Count > 4096)
{
queue.Dequeue();
}
}
}
Expand All @@ -87,17 +86,14 @@ public static void Run(ChartDisplayItem chartDisplayItem, MyGraphics g)
GraphDataCache2.TryGetValue(key, out Queue<double>? queue);
if (queue != null)
{
if (LibreMonitor.SENSORHASH.TryGetValue(key, out ISensor? value))
LibreMonitor.SENSORHASH.TryGetValue(key, out ISensor? value);
lock (queue)
{
queue.Enqueue(value?.Value ?? 0);

lock (queue)
if (queue.Count > 4096)
{
queue.Enqueue(value?.Value ?? 0);

if (queue.Count > 1000)
{
queue.Dequeue();
}
queue.Dequeue();
}
}
}
Expand Down Expand Up @@ -132,7 +128,7 @@ public static void Run(ChartDisplayItem chartDisplayItem, MyGraphics g)
{
tempValues = [.. queue];
}

double minValue = chartDisplayItem.MinValue;
double maxValue = chartDisplayItem.MaxValue;

Expand Down
21 changes: 21 additions & 0 deletions InfoPanel/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InfoPanel.Extensions
{
public static class DictionaryExtensions
{
public static string GetStringValue(this Dictionary<string, string> dict, string key, string fallback)
{
return dict.TryGetValue(key, out var value) ? value : fallback;
}

public static int GetIntValue(this Dictionary<string, string> dict, string key, int fallback)
{
return dict.TryGetValue(key, out var value) && int.TryParse(value, out var result) ? result : fallback;
}
}
}
3 changes: 3 additions & 0 deletions InfoPanel/Models/GaugeDisplayItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public GaugeDisplayItem(string name, UInt32 id, UInt32 instance, UInt32 entryId)
currentImageIndex = intermediateIndex;

result = Images[(int)Math.Round(intermediateIndex)];
} else
{
result = Images[0];
}
}

Expand Down
3 changes: 3 additions & 0 deletions InfoPanel/Models/SensorDisplayItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ private string EvaluateText(SensorReading sensorReading)
{
switch (sensorReading.Unit.ToLower())
{
case "gb":
value = string.Format("{0:0.0}", sensorReadingValue);
break;
case "kb/s":
case "mb/s":
case "mbar/min":
Expand Down
Loading

0 comments on commit 2cf24bf

Please sign in to comment.