void dataSourceUpdating(int racerIndex, DataSourcePacket data) { RacerDetails racer = racerDetails[racerIndex]; //Handle targets if this is a distance race if (target_type == targetType.Meters) { if (data.distance >= racer.targetValue) { double finishTime = raceTimer.Elapsed.TotalMilliseconds / 1000; //Since the finish distance is usually a little past the target when we get it, we need to interpolate to get an accurate value for the actual finish //TODO qc Another issue with accuracy is that depending on the timing of the first update packets between racers, one racer can have up to one packet period advantage. racer.finish(++finishOrder, targetType.Seconds, finishTime - ((data.distance - racer.targetValue) / data.speed_ms)); //If everyone is done, stop the timer, don't wait for simulator results if (racer.dataSource.isHuman) { if (--notFinishedHumanRacers == 0) { //Make sure all non-humans are closed too foreach (RacerDetails i in racerDetails) { i.dataSource.stop(); i.dataSource.isInUse = false; } startAsync(finishRaceAsync); } } } else { if (data.speed_ms != 0) { racer.racePanel.updateProgressDisplay(data.distance, (int)(1000 * (racer.targetValue - data.distance) / data.speed_ms)); } else { racer.racePanel.updateProgressDisplay(data.distance, 0); } } } racer.racePanel.updateStats(data); }
void ReceberMensagem(DataSourcePacket lastSeenData, DataSourcePacket lastSeenData2) { if (InvokeRequired) { ReceberMensagemCallback callback = ReceberMensagem; Invoke(callback, lastSeenData, lastSeenData2); } else { if (lastSeenData != null) { lblDist.Text = Math.Round(lastSeenData.distance).ToString() + " m"; lblVel.Text = Math.Round(lastSeenData.speed_ms * 3.6).ToString() + " km/h"; } if (lastSeenData2 != null) { lblCad.Text = Math.Round(lastSeenData2.cadence, 2).ToString() + " rpm"; } } }
public void refreshView() { Dispatcher.Invoke(new Action(() => { DataSourcePacket lastSeenData = antPlusConnection.dataSource.getLastDataRcvd(); Label_Description2.Content = antPlusConnection.dataSource.getSportType(); Label_DevID.Content = antPlusConnection.dataSource.searchProfile.deviceNumber; Label_Status.Content = antPlusConnection.getConnStatus().ToString(); if (lastSeenData == null) { Label_Dist.Content = "---"; Label_Speed.Content = "---"; Label_Cadence.Content = "---"; } else { Label_Dist.Content = Math.Round(lastSeenData.distance).ToString(); Label_Speed.Content = Math.Round(lastSeenData.speed_ms, 2).ToString(); Label_Cadence.Content = Math.Round(lastSeenData.cadence).ToString(); } })); }