//public Action<Brush> BarDelegate; //public Action CountdownDelegate; //public Action<int> MashDelegate; public SerialComms(string port, int rate, int newperiod, Action <int, String> mydelegate, Action <MashSet, MashSet> myUpdate) { _datPort = new SerialPort(port, rate); period = newperiod; StatusDelegate = mydelegate; UpdateDelegate = myUpdate; //main = parent; mashes = new MashSet(); mashes2 = new MashSet(); if (!_datPort.IsOpen)//Open, if not already { _datPort.Open(); } if (_datPort == null || !_datPort.IsOpen) { StatusDelegate(STATUS, "Something went wrong."); return; } _datPort.DtrEnable = false; _datPort.RtsEnable = false; _datPort.ReceivedBytesThreshold = 3; _datPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); StatusDelegate(STATUS, String.Format("Connected to {0}", port)); return; }
public void StatsInvoke(MashSet mymashes, MashSet mymashes2) { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { UpdateStats(mymashes, mymashes2); })); }
private bool ParseResponse(byte[] response) { switch (response[0]) { case SPINUP: StatusDelegate(ACTIVE, "Device Ready.\n"); //StatusDelegate(String.Format("Seconds: {0} Config: {1:x}", response[1], response[2])); //countdown = 9; //BarDelegate(Brushes.Yellow); mashes = new MashSet(); mashes2 = new MashSet(); //isDown = true; return(true); case INITIATED: StatusDelegate(STARTED, "First mash started."); //CountdownDelegate(); return(true); case DOWNTIME: //Status("Down Received."); downval = (long)(response[1] + (response[2] * 256)); return(true); case UPTIME: //Status("Up Received."); CaptureMash(response[1], response[2]); return(true); case DOWNTIME2: //Status("Down2 Received."); downval2 = (long)(response[1] + (response[2] * 256)); return(true); case UPTIME2: //Status("Up2 Received."); CaptureMash2(response[1], response[2]); return(true); case FINISHED: StatusDelegate(COMPLETE, "Session finished.\n"); UpdateDelegate(mashes, mashes2); //main.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, // new Action(delegate () // { // main.UpdateStats(mashes, mashes2); // })); return(true); default: StatusDelegate(STATUS, "Device Comms Error. \n"); return(false); } }
public void UpdateStats(MashSet newmashes, MashSet newmashes2) { mashes = newmashes; mashes2 = newmashes2; long mymed = 0; long mymed2 = 0; Countdown(0); double score = CalculateScore(); statusBar.Fill = Brushes.Red; if (onebutton) { mymed = mashes.GetMedian(); newStats = new Stats(Math.Round(mashes.count / (mashes.totalTime / 1000.0), 3), mashes.upTotal / mashes.count, mashes.downTotal / mashes.count, score, Math.Round(1000.00 / mymed, 3)); } else { double totalmashes = mashes.count + mashes2.count; double totaltime = Math.Max(mashes.totalTime, mashes2.totalTime); double totalup = mashes.upTotal + mashes2.upTotal; double totaldown = mashes.downTotal + mashes2.downTotal; mymed = mashes.GetMedian(); mymed2 = mashes2.GetMedian(); newStats = new Stats(Math.Round(totalmashes / (totaltime / 1000.0), 3), Math.Round(totalup / totalmashes), Math.Round(totaldown / totalmashes), score, Math.Round(1000.00 / ((mymed + mymed2) / 4), 3)); } sheets.SaveSession(newStats, usersBox.SelectedValue.ToString(), input, mode); playerStats = sheets.GetPlayer(); globalStats = sheets.GetGlobal(); CheckWinner(); if (relative) { UpdateStatsRelative(); } else { UpdateStatLabels(); } timerLabel.Visibility = Visibility.Hidden; PlotResults(mymed, mymed2); }
private void startButton_Click(object sender, RoutedEventArgs e) { //myTimer.Enabled = true; //mystop.Start(); //myTimer.Start(); mashes = new MashSet(); chart.Visibility = Visibility.Hidden; timerLabel.Visibility = Visibility.Visible; mashLabel.Visibility = Visibility.Visible; mashLabel.Content = "Mashes: 0"; //scoreLabel.Visibility = Visibility.Hidden; //winnerLabel.Content = " "; ClearStats(); StartComms(); }
//private delegate void UpdateStatsDel(); public AttackWindow() { InitializeComponent(); //OxyPlot.Model _localBuffer = new List <byte>(); sheets = new MashAttack.SheetsAgent(); myTimer = new DispatcherTimer(DispatcherPriority.Normal); myTimer.Interval = new TimeSpan(0, 0, 0, 10, 0); myTimer.Tick += new EventHandler(TimeOver); updateTimer = new DispatcherTimer(DispatcherPriority.Normal); updateTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); updateTimer.Tick += new EventHandler(SecondElapsed); //myTimer.AutoReset = false; //myTimer.SynchronizingObject = (System.ComponentModel.ISynchronizeInvoke)this.avgHz; mashEnabled = false; mashes = new MashSet(); mashes2 = new MashSet(); first = true; mystop = new System.Diagnostics.Stopwatch(); prior = 0; updatePortList(); //myModel = new PlotModel { Title = "Mashing Rate" }; //configBox.Items.Insert(0, "10s1B"); //configBox.Items.Insert(1, "5s1B"); //configBox.Items.Insert(2, "30s1B"); //configBox.Items.Insert(3, "10s2B"); //configBox.Items.Insert(4, "5s2B"); //configBox.Items.Insert(5, "30s2B"); //inputBox.Items.Insert(0, "SNES"); //inputBox.Items.Insert(1, "NES"); //inputBox.Items.Insert(2, "GEN"); //inputBox.Items.Insert(3, "ARC"); //configBox.SelectedIndex = 0; //inputBox.SelectedIndex = 0; int i = 0; int j = 0; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { statLabels[i, j] = new Label(); statLabels[i, j].FontSize = 16; statLabels[i, j].HorizontalAlignment = System.Windows.HorizontalAlignment.Center; statLabels[i, j].VerticalAlignment = System.Windows.VerticalAlignment.Center; statsGrid.Children.Add(statLabels[i, j]); System.Windows.Controls.Grid.SetRow(statLabels[i, j], j); System.Windows.Controls.Grid.SetColumn(statLabels[i, j], i); } } statLabels[0, 1].Content = "Rate (Hz)"; statLabels[0, 3].Content = "Uptime (ms)"; statLabels[0, 4].Content = "Downtime (ms)"; statLabels[0, 5].Content = "Score"; statLabels[0, 2].Content = "Median (Hz)"; statLabels[2, 0].Content = "Player"; statLabels[1, 0].Content = "Session"; statLabels[3, 0].Content = "Global"; statLabels[0, 1].FontWeight = System.Windows.FontWeights.Bold; statLabels[0, 3].FontWeight = System.Windows.FontWeights.Bold; statLabels[0, 4].FontWeight = System.Windows.FontWeights.Bold; statLabels[0, 5].FontWeight = System.Windows.FontWeights.Bold; statLabels[0, 2].FontWeight = System.Windows.FontWeights.Bold; statLabels[1, 0].FontWeight = System.Windows.FontWeights.Bold; statLabels[2, 0].FontWeight = System.Windows.FontWeights.Bold; statLabels[3, 0].FontWeight = System.Windows.FontWeights.Bold; PlayerUpdate(); UpdateButtonList(); }