Skip to content

Commit

Permalink
Merge pull request #319 from X9VoiD/reportrate
Browse files Browse the repository at this point in the history
Add ReportRate in TabletDebugger Window
  • Loading branch information
InfinityGhost committed Sep 29, 2020
2 parents 84d3f90 + 2ffa2ca commit 13d0177
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions OpenTabletDriver.UX/Windows/TabletDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ public TabletDebugger()
Text = "Aux Report",
Padding = App.GroupBoxPadding
};


reportRateCtrl = new GroupBox
{
Text = "Report Rate",
Padding = App.GroupBoxPadding
};

var mainLayout = new TableLayout
{
Width = 640,
Height = 480,
Spacing = new Size(5, 5),
Padding = new Padding(5),
Rows =
Rows =
{
new TableRow
{
Expand All @@ -65,7 +70,16 @@ public TabletDebugger()
}
};

this.Content = mainLayout;
this.Content = new StackLayout
{
Padding = 5,
Spacing = 5,
Items =
{
new StackLayoutItem(mainLayout, HorizontalAlignment.Stretch, true),
new StackLayoutItem(reportRateCtrl, HorizontalAlignment.Stretch)
}
};

InitializeAsync();
}
Expand All @@ -83,16 +97,22 @@ private void InitializeAsync()
};
}

private GroupBox rawTabCtrl, tabReportCtrl, rawAuxCtrl, auxReportCtrl;
private GroupBox rawTabCtrl, tabReportCtrl, rawAuxCtrl, auxReportCtrl, reportRateCtrl;
private float reportRate;
private DateTime lastTime = DateTime.UtcNow;

private void HandleReport(object sender, IDeviceReport report)
{
if (report is ITabletReport tabletReport)
{
Application.Instance.AsyncInvoke(() =>
{
var now = DateTime.UtcNow;
reportRate += (float)(((now - lastTime).TotalMilliseconds - reportRate) / 50);
lastTime = now;
rawTabCtrl.Content = tabletReport?.StringFormat(true);
tabReportCtrl.Content = tabletReport?.StringFormat(false).Replace(", ", Environment.NewLine);
reportRateCtrl.Content = $"{(uint)(1000 / reportRate)}hz";
});
}
if (report is IAuxReport auxReport)
Expand Down

0 comments on commit 13d0177

Please sign in to comment.