Skip to content

Commit 89b24da

Browse files
committed
#140 show crank position and speed on Crank tab
1 parent 779e1e5 commit 89b24da

4 files changed

Lines changed: 155 additions & 51 deletions

File tree

Trixter.XDream.Diagnostics/Controls/CrankDetails.Designer.cs

Lines changed: 101 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Trixter.XDream.Diagnostics/Controls/CrankDetails.cs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public partial class CrankDetails : UserControl
2525
bool paused = false;
2626
DateTimeOffset lastUpdate;
2727

28+
public DataAccess DataAccess { get; set; }
29+
2830
public CrankDetails()
2931
{
3032
InitializeComponent();
@@ -61,8 +63,8 @@ public CrankDetails()
6163
this.pnlLabels.Controls.AddRange(labels);
6264

6365
this.pnlLabels.Resize += (s, e) => { this.UpdatePositions(); };
64-
65-
66+
67+
this.Enabled = false;
6668
}
6769

6870
private void UpdatePositions()
@@ -80,7 +82,6 @@ private void UpdatePositions()
8082

8183
int y = origin.Y + (int)(Math.Sin(angle) * C);
8284
int x = origin.X + (int)(Math.Cos(angle) * C);
83-
int position = i + 1;
8485

8586
Label label = this.labels[i];
8687

@@ -109,18 +110,16 @@ private void btnPauseResume_Click(object sender, EventArgs e)
109110
}
110111
}
111112

112-
public void UpdateSeries(bool force =false)
113+
private void UpdateSeries(bool force = false)
113114
{
114115
lock (this.sync)
115116
{
116117

117118
if (!force && paused)
118119
return;
119120

120-
if (DateTimeOffset.UtcNow - this.lastUpdate < TimeSpan.FromMilliseconds(updateIntervalMilliseconds))
121-
return;
122-
123-
long then = DateTimeOffset.UtcNow.Ticks - TimeSpan.FromMilliseconds(currentPositionIntervalMilliseconds).Ticks;
121+
long then = DateTimeOffset.UtcNow.Ticks -
122+
TimeSpan.FromMilliseconds(currentPositionIntervalMilliseconds).Ticks;
124123
Color defaultColor = gbCrankDetails.BackColor;
125124

126125
for (int i = 0; i < labels.Length; i++)
@@ -134,8 +133,6 @@ public void UpdateSeries(bool force =false)
134133
color = current;
135134
this.labels[i].BackColor = color;
136135
}
137-
138-
this.lastUpdate = DateTimeOffset.UtcNow;
139136
}
140137
}
141138

@@ -146,5 +143,35 @@ public void VisitCrankPosition(int crankPosition)
146143
this.crankPositionVisits[crankPosition - 1] = DateTimeOffset.UtcNow.Ticks;
147144
}
148145
}
146+
147+
public void UpdateDetails(bool forceSeries=false)
148+
{
149+
lock (this.sync)
150+
{
151+
if (DateTimeOffset.UtcNow.Subtract(this.lastUpdate).TotalMilliseconds < updateIntervalMilliseconds)
152+
return;
153+
154+
this.lastUpdate = DateTimeOffset.UtcNow;
155+
156+
this.UpdateSeries(forceSeries);
157+
158+
XDreamMachine xdm = this.DataAccess?.XDreamMachine;
159+
XDreamState message = this.DataAccess?.LastMessage;
160+
161+
if (xdm == null || message == null)
162+
{
163+
this.Enabled = false;
164+
165+
this.lbCrankPositionValue.Text = "";
166+
this.lbCrankSpeedValue.Text = "";
167+
return;
168+
}
169+
170+
this.Enabled = true;
171+
172+
this.lbCrankPositionValue.Text = message.CrankPosition.ToString();
173+
this.lbCrankSpeedValue.Text = xdm.CrankMeter.RPM.ToString();
174+
}
175+
}
149176
}
150177
}

Trixter.XDream.Diagnostics/MainForm.Designer.cs

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)