public ArduinoEMGPlotter(ref Chart chart, ref Label _lblBufferStatus) { chartHandler = new EMGChart(ref chart, 5000); BufferMediaMovel = new CircularBuffer <double>(100);//Media movel de 100 pontos = 10HZ +- for (int i = 0; i < BufferMediaMovel.Capacity; i++) { BufferMediaMovel.SecureEnqueue(0); } chartHandler.ConfigureChart("Leituras", "EMG Plotter"); arduinoHandler = new ArduinoHandler(); dataconsumer = new ThreadHandler(() => { if (arduinoHandler.dataWaiting) { double valormedia; double valor2add = arduinoHandler.bufferAquisition. SecureDequeue() * 5 / 1024.0 - 2.5; chartHandler.AddYToBuffer(valor2add); if (BufferMediaMovel.Full) { BufferMediaMovel.SecureDequeue(); valormedia = BufferMediaMovel.ToArray().Average(); BufferMediaMovel.SecureEnqueue(Math.Abs(valor2add) * 3.23); var temp = (EMGChart)chartHandler; temp.AddEnvoloriaToBuffer(valormedia); } } }); bufferLabelUpdater = new Timer(); lblBufferStatus = _lblBufferStatus; bufferLabelUpdater.Interval = 50; bufferLabelUpdater.Tick += bufferLabelUpdater_Tick; }
public ArduinoEMGPlotter(ref Chart chart, ref Label _lblBufferStatus, ref Bunifu.Framework.UI.BunifuProgressBar _calib_progress_bar) { iniciarVariaveisProcessamento(); _k = 2; is_in_calibration = false; calib_progress_bar = _calib_progress_bar; chartHandler = new EMGChart(ref chart, qnt_pontos); //chart com 5000 pontos emgChart = (EMGChart)chartHandler; BufferCalibracao = new CircularBuffer <double>(4096); valorhbt = new double[2048]; chartHandler.ConfigureChart("Leituras", "EMG Plotter"); bufferLabelUpdater = new Timer(); lblBufferStatus = _lblBufferStatus; bufferLabelUpdater.Interval = 50; bufferLabelUpdater.Tick += bufferLabelUpdater_Tick; arduinoHandler = new ArduinoHandler(); dataconsumer = new ThreadHandler(processingRoutine); #region Lambda from hell //() => //{ // if (arduinoHandler.dataWaiting) // { // double valor2add = arduinoHandler.bufferAquisition. // SecureDequeue() * 5 / 1024.0 - 2.5; // chartHandler.AddYToBuffer(valor2add); // #region Janelamento da calibração // if (is_in_calibration) // { // BufferCalibracao.Enqueue(valor2add); // if (BufferCalibracao.Count % 50 == 0) // { // calib_progress_bar.BeginInvoke(new Action(() => // { // calib_progress_bar.Value = (int)(100.0f * BufferCalibracao.Count / (double)BufferCalibracao.Capacity); // })); // } // if (BufferCalibracao.Full) // { // calibrar = BufferCalibracao.ToArray(); // Accord.Math.HilbertTransform.FHT(calibrar, Accord.Math.FourierTransform.Direction.Forward); //aplicar a transformada de Hilbert // calibrar = calibrar.Abs(); // calibrar_filtrado = Butter.Butterworth(calibrar, emgChart.period_aquire, 7); // media = calibrar.Average(); // std = Accord.Statistics.Measures.StandardDeviation(calibrar); // emgChart.limiar = media + k * std; // is_in_calibration = false; // } // } // #endregion // //Esta rotina deve ser Otimizada para que os dados nao sejam processados num Timer // //Os dados devem ir para um buffer de processamento e não para o mesmo buffer de plotagem // } //}); #endregion }