Skip to content

Commit

Permalink
re-add dynamic sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Settimi committed Jun 17, 2024
1 parent c9b0739 commit 7c0c6ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LaserGRBL/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// utilizzando l'asterisco (*) come descritto di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("7.6.1")]
[assembly: AssemblyVersion ("7.6.2")]
[assembly: NeutralResourcesLanguage("en")]
10 changes: 8 additions & 2 deletions LaserGRBL/UserControls/GrblPanel3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public partial class GrblPanel3D : UserControl, IGrblPanel
private bool mFSTrig;

private Base.Mathematics.MobileDAverageCalculator FrameTime;
private Base.Mathematics.MobileDAverageCalculator SleepTime;
private Base.Mathematics.MobileDAverageCalculator RefreshRate;

private static Exception FatalException;
Expand Down Expand Up @@ -114,6 +115,7 @@ public GrblPanel3D()
InitializeComponent();
OpCounter = 0;
FrameTime = new Base.Mathematics.MobileDAverageCalculator(30);
SleepTime = new Base.Mathematics.MobileDAverageCalculator(30);
RefreshRate = new Base.Mathematics.MobileDAverageCalculator(30);
mLastWPos = GPoint.Zero;
mLastMPos = GPoint.Zero;
Expand Down Expand Up @@ -321,9 +323,13 @@ private void DrawScene()
g.ReleaseHdc(handleDeviceContext);
}
mBmp.Bitmap = newBmp;

FrameTime.EnqueueNewSample(crono.ElapsedTime.TotalMilliseconds);

//TH.SleepTime = BestSleep(FrameTime.Avg, 10, 100, 10, 50);
int best_sleep = BestSleep(FrameTime.CurrentValue, 10, 100, 10, 50);
SleepTime.EnqueueNewSample(best_sleep);
Thread.Sleep(best_sleep);

// call control invalidate
Invalidate();

Expand Down Expand Up @@ -649,7 +655,7 @@ private void DoGDIDraw(PaintEventArgs e)
else
VertexString = string.Format("{0,6:###0.0} B", VertexCounter / 1000000000.0);

text = $"VER {VertexString}\nAFT {string.Format("{0,6:##0} ms", FrameTime.Avg)}\nFPS {string.Format("{0,6:##0}", 1000.0 / RefreshRate.Avg)}";
text = $"VER {VertexString}\nAFT {string.Format("{0,6:##0} ms", FrameTime.Avg)}\nAST {string.Format("{0,6:##0} ms", SleepTime.Avg)}\nRPS {string.Format("{0,6:##0}", 1000.0 / RefreshRate.Avg)}";
size = MeasureText(text, font);
point = new Point(Width - size.Width - mPadding.Right, pos);
DrawOverlay(e, point, size, ColorScheme.PreviewRuler, 100);
Expand Down

0 comments on commit 7c0c6ce

Please sign in to comment.