}//end event Service_CheckedChanged // Main button has been clicked on ("async" required due to async method calls) private async void mainButton_Click(object sender, EventArgs e) { /*** Clear Chart ***/ foreach (var series in sensorChart.Series) { series.Points.Clear(); } /*** Initialize eTDS object ***/ eTdsHeadset = new eTdsDevice(selectedService, selectedCharacteristic, dataBuffer); await eTdsHeadset.InitializationAsync(); /*** Display session info to user ***/ displayTextBox.AppendText("\r\n\r\n-- Started Test Session --\r\n"); displayTextBox.AppendText(string.Format("Device Name: {0} \r\n", eTdsHeadset.TdsDevice.Name)); // Display the name of the device displayTextBox.AppendText(string.Format("Service UUID: {0} \r\n", eTdsHeadset.myService.Uuid.ToString())); // Display the service UUID Thread readDataWithNotifThread = new Thread(new ThreadStart(eTdsHeadset.GetDataFromNotification)); readDataWithNotifThread.Priority = ThreadPriority.Highest; readDataWithNotifThread.Start(); Thread displayDataThread = new Thread(new ThreadStart(DisplayData)); displayDataThread.Priority = ThreadPriority.Lowest; displayDataThread.Start(); }//end event mainButton_Click
}//end event Service_CheckedChanged /* Main button has been clicked on */ // ("async" required due to async method calls) private async void mainButton_Click(object sender, EventArgs e) { /* Cleanup procedure if an eTdsHeadset object already exist */ if (eTdsHeadset != null) { eTdsHeadset.myService.Dispose(); // Cleanup procedure for Gatt Services dataBuffer.Reset(); // Reset buffer state to default values // Abort all created threads readDataWithNotifThread.Abort(); displayDataThread.Abort(); }//end if /* Format Chart */ // Clear all points for all series (collection of datapoints) foreach (var series in sensorChart.Series) { series.Points.Clear(); } // Set the width and initial value of the X-axis foreach (var chart in sensorChart.ChartAreas) { chart.AxisX.ScaleView.Size = axisView; // Set width of X-axis to a constant value chart.AxisX.ScaleView.Position = 0; // Set initial position to 0 } /* Change Start Button text */ StartButton.Text = "Start New Test"; /* Initialize eTdsDevice object */ eTdsHeadset = new eTdsDevice(selectedService, selectedCharacteristic, dataBuffer); await eTdsHeadset.InitializationAsync(); /* Display session info to user */ displayTextBox.AppendText("\r\n\r\n-- Started Test Session --\r\n"); displayTextBox.AppendText(string.Format("Device Name: {0} \r\n", eTdsHeadset.TdsDevice.Name)); // Display the name of the device displayTextBox.AppendText(string.Format("Service UUID: {0} \r\n", eTdsHeadset.myService.Uuid.ToString())); // Display the service UUID displayTextBox.AppendText("Frequency: TBD"); /* Create and Start Threads */ readDataWithNotifThread = new Thread(new ThreadStart(eTdsHeadset.GetDataFromNotification)); readDataWithNotifThread.Priority = ThreadPriority.Highest; readDataWithNotifThread.Start(); displayDataThread = new Thread(new ThreadStart(DisplayData)); displayDataThread.Priority = ThreadPriority.Lowest; displayDataThread.Start(); }//end event mainButton_Click
}//end event Service_CheckedChanged // Main button has been clicked on // "async" is required due to asynchronous method calls private async void mainButton_Click(object sender, EventArgs e) { displayTextBox.AppendText("\r\n\r\n-- Started Test Session --\r\n"); /*** Clear Chart ***/ foreach (var series in sensorChart.Series) { series.Points.Clear(); } /*** Initialize eTDS object ***/ eTdsDevice eTdsHeadset = new eTdsDevice(selectedService, selectedCharacteristic); await eTdsHeadset.InitializationAsync(); displayTextBox.AppendText(string.Format("Device Name: {0} \r\n", eTdsHeadset.TdsDevice.Name)); // Display the name of the device displayTextBox.AppendText(string.Format("Service UUID: {0} \r\n", eTdsHeadset.myService.Uuid.ToString())); // Display the service UUID /*** Read Data ***/ GattReadResult dataRaw; byte[] dataArray = new byte[6]; for (int i = 0; i < 10000; i++) { /* Read data from buffer */ dataRaw = null; dataRaw = await eTdsHeadset.myCharacteristic.ReadValueAsync(BluetoothCacheMode.Cached); DataReader.FromBuffer(dataRaw.Value).ReadBytes(dataArray); /* Convert raw data into meaningful values (3-D axis) */ short[] sensorValue = convertSensorData(dataArray); /* Display and graph axis values */ count++; // this.SetText(string.Format("Sensor Data Readout\r\n\r\nX-Axis: {0}\r\nY-Axis: {1}\r\nZ-Axis: {2}\r\nCount: {3}", sensorValue[0], sensorValue[1], sensorValue[2], count)); this.SetGraph(sensorValue); /* Pause thread execution */ Thread.Sleep(10); } /*** Create an event handler when the characteristic value changes ***/ //eTdsHeadset.myCharacteristic.ValueChanged += myCharacteristic_ValueChanged; //await eTdsHeadset.myCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); }//end event mainButton_Click
}//end event Service_CheckedChanged /* Main button has been clicked on */ // ("async" required due to async method calls) private async void startButton_Click(object sender, RoutedEventArgs e) { /* Cleanup procedure if an eTdsHeadset object already exist */ if (eTdsHeadset != null) { eTdsHeadset.myService.Dispose(); // Cleanup procedure for Gatt Services dataBuffer.Reset(); // Reset buffer state to default values // Abort all created threads readDataWithNotifThread.Abort(); displayDataThread.Abort(); }//end if // Clear all points for all series (collection of datapoints) viewModel.ClearModel(0); /* Change Start Button text */ startButton.Content = "Start New Test"; /* Initialize eTdsDevice object */ eTdsHeadset = new eTdsDevice(selectedService, selectedCharacteristic, dataBuffer); await eTdsHeadset.InitializationAsync(); /* Display session info to user */ displayTextBox.AppendText("\n\n-- Started Test Session --\n"); displayTextBox.AppendText(string.Format("Device Name: {0}\n", eTdsHeadset.TdsDevice.Name)); // Display the name of the device displayTextBox.AppendText(string.Format("Service UUID: {0}\n", eTdsHeadset.myService.Uuid.ToString())); // Display the service UUID displayTextBox.AppendText("Frequency: TBD"); /* Create and Start Threads */ readDataWithNotifThread = new Thread(new ThreadStart(eTdsHeadset.GetDataFromNotification)); readDataWithNotifThread.Priority = ThreadPriority.Highest; readDataWithNotifThread.Start(); displayDataThread = new Thread(new ThreadStart(DisplayData)); displayDataThread.Priority = ThreadPriority.Lowest; displayDataThread.Start(); }//end event startButton_Click