diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index f63b937..7d28afb 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,7 +1,11 @@ -using System.Threading; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; using System.Windows; +using Correlator.Model; using Correlator.SensorHubTag; using Correlator.Util; +using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using MessageBox = System.Windows.MessageBox; using Window = System.Windows.Window; @@ -14,55 +18,109 @@ { InitializeComponent(); + //去掉四周坐标轴 + RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + + BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + GoBackButton.Click += delegate { Close(); }; - SensorACheckBox.Click += delegate + Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { - if (!SerialPortManager.Get.Sp.IsOpen) + Application.Current.Dispatcher.Invoke(delegate { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - } - else - { - if (SensorBCheckBox.IsChecked == true) + if (model.IsRedSensor) { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - SensorBCheckBox.IsChecked = false; + RedSensorScottPlotChart.Plot.Clear(); + RedSensorScottPlotChart.Refresh(); + + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + RedSensorScottPlotChart.Refresh(); } - - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - } - }; - - SensorBCheckBox.Click += delegate - { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - } - else - { - if (SensorACheckBox.IsChecked == true) + else { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - SensorACheckBox.IsChecked = false; - } + BlueSensorScottPlotChart.Plot.Clear(); + BlueSensorScottPlotChart.Refresh(); - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - } - }; + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + BlueSensorScottPlotChart.Refresh(); + } + }); + }); + + // SensorACheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // } + // else + // { + // if (SensorBCheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // SensorBCheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); + // } + // }; + // + // SensorBCheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // } + // else + // { + // if (SensorACheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // SensorACheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); + // } + // }; } private void SendSoundCollectCmd(object devCode) diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index f63b937..7d28afb 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,7 +1,11 @@ -using System.Threading; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; using System.Windows; +using Correlator.Model; using Correlator.SensorHubTag; using Correlator.Util; +using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using MessageBox = System.Windows.MessageBox; using Window = System.Windows.Window; @@ -14,55 +18,109 @@ { InitializeComponent(); + //去掉四周坐标轴 + RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + + BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + GoBackButton.Click += delegate { Close(); }; - SensorACheckBox.Click += delegate + Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { - if (!SerialPortManager.Get.Sp.IsOpen) + Application.Current.Dispatcher.Invoke(delegate { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - } - else - { - if (SensorBCheckBox.IsChecked == true) + if (model.IsRedSensor) { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - SensorBCheckBox.IsChecked = false; + RedSensorScottPlotChart.Plot.Clear(); + RedSensorScottPlotChart.Refresh(); + + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + RedSensorScottPlotChart.Refresh(); } - - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - } - }; - - SensorBCheckBox.Click += delegate - { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - } - else - { - if (SensorACheckBox.IsChecked == true) + else { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - SensorACheckBox.IsChecked = false; - } + BlueSensorScottPlotChart.Plot.Clear(); + BlueSensorScottPlotChart.Refresh(); - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - } - }; + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + BlueSensorScottPlotChart.Refresh(); + } + }); + }); + + // SensorACheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // } + // else + // { + // if (SensorBCheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // SensorBCheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); + // } + // }; + // + // SensorBCheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // } + // else + // { + // if (SensorACheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // SensorACheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); + // } + // }; } private void SendSoundCollectCmd(object devCode) diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index aacb1d0..7c1bc95 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -396,20 +396,23 @@ Grid.Column="0" Width="38" Height="82" - Margin="20,0,0,40" + Margin="20,0,0,20" VerticalAlignment="Bottom" Source="{Binding RedTransmitterSignalIntensity, ConverterParameter=0, Converter={StaticResource SignalImageConverter}}" /> - + Margin="0,20" + BorderBrush="LightGray" + BorderThickness="1"> + + diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index f63b937..7d28afb 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,7 +1,11 @@ -using System.Threading; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; using System.Windows; +using Correlator.Model; using Correlator.SensorHubTag; using Correlator.Util; +using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using MessageBox = System.Windows.MessageBox; using Window = System.Windows.Window; @@ -14,55 +18,109 @@ { InitializeComponent(); + //去掉四周坐标轴 + RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + + BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + GoBackButton.Click += delegate { Close(); }; - SensorACheckBox.Click += delegate + Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { - if (!SerialPortManager.Get.Sp.IsOpen) + Application.Current.Dispatcher.Invoke(delegate { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - } - else - { - if (SensorBCheckBox.IsChecked == true) + if (model.IsRedSensor) { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - SensorBCheckBox.IsChecked = false; + RedSensorScottPlotChart.Plot.Clear(); + RedSensorScottPlotChart.Refresh(); + + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + RedSensorScottPlotChart.Refresh(); } - - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - } - }; - - SensorBCheckBox.Click += delegate - { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - } - else - { - if (SensorACheckBox.IsChecked == true) + else { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - SensorACheckBox.IsChecked = false; - } + BlueSensorScottPlotChart.Plot.Clear(); + BlueSensorScottPlotChart.Refresh(); - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - } - }; + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + BlueSensorScottPlotChart.Refresh(); + } + }); + }); + + // SensorACheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // } + // else + // { + // if (SensorBCheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // SensorBCheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); + // } + // }; + // + // SensorBCheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // } + // else + // { + // if (SensorACheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // SensorACheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); + // } + // }; } private void SendSoundCollectCmd(object devCode) diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index aacb1d0..7c1bc95 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -396,20 +396,23 @@ Grid.Column="0" Width="38" Height="82" - Margin="20,0,0,40" + Margin="20,0,0,20" VerticalAlignment="Bottom" Source="{Binding RedTransmitterSignalIntensity, ConverterParameter=0, Converter={StaticResource SignalImageConverter}}" /> - + Margin="0,20" + BorderBrush="LightGray" + BorderThickness="1"> + + diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index 6593596..ae60c81 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -20,10 +20,12 @@ InitializeComponent(); var scottPlot = ScottplotView.Plot; - scottPlot.XLabel("频率(Hz)"); - scottPlot.YLabel("相关系数"); - ScottplotView.Refresh(); - + //去掉四周坐标轴 + scottPlot.XAxis.IsVisible = false; + scottPlot.XAxis2.IsVisible = false; + scottPlot.YAxis.IsVisible = false; + scottPlot.YAxis2.IsVisible = false; + #region 渲染、清空数据波形图 Messenger.Default.Register(this, MessengerToken.RenderOscillogram, array => @@ -100,11 +102,11 @@ ListenAudioButton.Click += delegate { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } var auditionWindow = new AuditionWindow { diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index f63b937..7d28afb 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,7 +1,11 @@ -using System.Threading; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; using System.Windows; +using Correlator.Model; using Correlator.SensorHubTag; using Correlator.Util; +using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using MessageBox = System.Windows.MessageBox; using Window = System.Windows.Window; @@ -14,55 +18,109 @@ { InitializeComponent(); + //去掉四周坐标轴 + RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + + BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + GoBackButton.Click += delegate { Close(); }; - SensorACheckBox.Click += delegate + Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { - if (!SerialPortManager.Get.Sp.IsOpen) + Application.Current.Dispatcher.Invoke(delegate { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - } - else - { - if (SensorBCheckBox.IsChecked == true) + if (model.IsRedSensor) { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - SensorBCheckBox.IsChecked = false; + RedSensorScottPlotChart.Plot.Clear(); + RedSensorScottPlotChart.Refresh(); + + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + RedSensorScottPlotChart.Refresh(); } - - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - } - }; - - SensorBCheckBox.Click += delegate - { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - } - else - { - if (SensorACheckBox.IsChecked == true) + else { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - SensorACheckBox.IsChecked = false; - } + BlueSensorScottPlotChart.Plot.Clear(); + BlueSensorScottPlotChart.Refresh(); - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - } - }; + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + BlueSensorScottPlotChart.Refresh(); + } + }); + }); + + // SensorACheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // } + // else + // { + // if (SensorBCheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // SensorBCheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); + // } + // }; + // + // SensorBCheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // } + // else + // { + // if (SensorACheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // SensorACheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); + // } + // }; } private void SendSoundCollectCmd(object devCode) diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index aacb1d0..7c1bc95 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -396,20 +396,23 @@ Grid.Column="0" Width="38" Height="82" - Margin="20,0,0,40" + Margin="20,0,0,20" VerticalAlignment="Bottom" Source="{Binding RedTransmitterSignalIntensity, ConverterParameter=0, Converter={StaticResource SignalImageConverter}}" /> - + Margin="0,20" + BorderBrush="LightGray" + BorderThickness="1"> + + diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index 6593596..ae60c81 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -20,10 +20,12 @@ InitializeComponent(); var scottPlot = ScottplotView.Plot; - scottPlot.XLabel("频率(Hz)"); - scottPlot.YLabel("相关系数"); - ScottplotView.Refresh(); - + //去掉四周坐标轴 + scottPlot.XAxis.IsVisible = false; + scottPlot.XAxis2.IsVisible = false; + scottPlot.YAxis.IsVisible = false; + scottPlot.YAxis2.IsVisible = false; + #region 渲染、清空数据波形图 Messenger.Default.Register(this, MessengerToken.RenderOscillogram, array => @@ -100,11 +102,11 @@ ListenAudioButton.Click += delegate { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } var auditionWindow = new AuditionWindow { diff --git a/Correlator/View/MainWindow.xaml.cs b/Correlator/View/MainWindow.xaml.cs index 99ff383..8a8bfff 100644 --- a/Correlator/View/MainWindow.xaml.cs +++ b/Correlator/View/MainWindow.xaml.cs @@ -33,7 +33,7 @@ { InitializeComponent(); - _checkSerialPortTimer.Start(); + // _checkSerialPortTimer.Start(); _checkSerialPortTimer.Tick += CheckSerialPortState; //倒计时显示大屏Logo diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index f63b937..7d28afb 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,7 +1,11 @@ -using System.Threading; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; using System.Windows; +using Correlator.Model; using Correlator.SensorHubTag; using Correlator.Util; +using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using MessageBox = System.Windows.MessageBox; using Window = System.Windows.Window; @@ -14,55 +18,109 @@ { InitializeComponent(); + //去掉四周坐标轴 + RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + + BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + GoBackButton.Click += delegate { Close(); }; - SensorACheckBox.Click += delegate + Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { - if (!SerialPortManager.Get.Sp.IsOpen) + Application.Current.Dispatcher.Invoke(delegate { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - } - else - { - if (SensorBCheckBox.IsChecked == true) + if (model.IsRedSensor) { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - SensorBCheckBox.IsChecked = false; + RedSensorScottPlotChart.Plot.Clear(); + RedSensorScottPlotChart.Refresh(); + + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + RedSensorScottPlotChart.Refresh(); } - - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - } - }; - - SensorBCheckBox.Click += delegate - { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - } - else - { - if (SensorACheckBox.IsChecked == true) + else { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - SensorACheckBox.IsChecked = false; - } + BlueSensorScottPlotChart.Plot.Clear(); + BlueSensorScottPlotChart.Refresh(); - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - } - }; + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + BlueSensorScottPlotChart.Refresh(); + } + }); + }); + + // SensorACheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // } + // else + // { + // if (SensorBCheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // SensorBCheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); + // } + // }; + // + // SensorBCheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // } + // else + // { + // if (SensorACheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // SensorACheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); + // } + // }; } private void SendSoundCollectCmd(object devCode) diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index aacb1d0..7c1bc95 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -396,20 +396,23 @@ Grid.Column="0" Width="38" Height="82" - Margin="20,0,0,40" + Margin="20,0,0,20" VerticalAlignment="Bottom" Source="{Binding RedTransmitterSignalIntensity, ConverterParameter=0, Converter={StaticResource SignalImageConverter}}" /> - + Margin="0,20" + BorderBrush="LightGray" + BorderThickness="1"> + + diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index 6593596..ae60c81 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -20,10 +20,12 @@ InitializeComponent(); var scottPlot = ScottplotView.Plot; - scottPlot.XLabel("频率(Hz)"); - scottPlot.YLabel("相关系数"); - ScottplotView.Refresh(); - + //去掉四周坐标轴 + scottPlot.XAxis.IsVisible = false; + scottPlot.XAxis2.IsVisible = false; + scottPlot.YAxis.IsVisible = false; + scottPlot.YAxis2.IsVisible = false; + #region 渲染、清空数据波形图 Messenger.Default.Register(this, MessengerToken.RenderOscillogram, array => @@ -100,11 +102,11 @@ ListenAudioButton.Click += delegate { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } var auditionWindow = new AuditionWindow { diff --git a/Correlator/View/MainWindow.xaml.cs b/Correlator/View/MainWindow.xaml.cs index 99ff383..8a8bfff 100644 --- a/Correlator/View/MainWindow.xaml.cs +++ b/Correlator/View/MainWindow.xaml.cs @@ -33,7 +33,7 @@ { InitializeComponent(); - _checkSerialPortTimer.Start(); + // _checkSerialPortTimer.Start(); _checkSerialPortTimer.Tick += CheckSerialPortState; //倒计时显示大屏Logo diff --git a/Correlator/ViewModel/AuditionViewModel.cs b/Correlator/ViewModel/AuditionViewModel.cs index 393712f..b43b47e 100644 --- a/Correlator/ViewModel/AuditionViewModel.cs +++ b/Correlator/ViewModel/AuditionViewModel.cs @@ -1,100 +1,129 @@ using System; +using System.Diagnostics; using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Threading; +using Correlator.Model; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; -using LiveCharts; -using LiveCharts.Defaults; +using GalaSoft.MvvmLight.Messaging; +using NAudio.CoreAudioApi; +using NAudio.Wave; +using WaveFormat = NAudio.Wave.WaveFormat; namespace Correlator.ViewModel { public class AuditionViewModel : ViewModelBase { - public RelayCommand MuteCommand { get; set; } - public IChartValues ColumnValues { get; set; } = new ChartValues(); + #region RelayCommand - /// - /// 传感器A信号强度0-5 - /// - private int _sensorASignalIntensity; + public RelayCommand ListenRedSensorCommand { get; } + public RelayCommand RedSensorMuteCommand { get; } + public RelayCommand ListenBlueSensorCommand { get; } + public RelayCommand BlueSensorMuteCommand { get; } - public int SensorASignalIntensity + #endregion + + #region VM + + private int _currentVolume; + + public int CurrentVolume { - get => _sensorASignalIntensity; - private set - { - _sensorASignalIntensity = value; - RaisePropertyChanged(() => SensorASignalIntensity); - } - } - - /// - /// 传感器B信号强度0-5 - /// - private int _sensorBSignalIntensity; - - public int SensorBSignalIntensity - { - get => _sensorBSignalIntensity; - private set - { - _sensorBSignalIntensity = value; - RaisePropertyChanged(() => SensorBSignalIntensity); - } - } - - /// - /// 传感器A按钮 - /// - private bool _sensorAIsEnable; - - public bool SensorAIsEnable - { - get => _sensorAIsEnable; + get => _currentVolume; set { - _sensorAIsEnable = value; - RaisePropertyChanged(() => SensorAIsEnable); + _currentVolume = value; + RaisePropertyChanged(); } } + #endregion + + private static readonly Lazy LazyWaveIn = + new Lazy(() => new WaveIn { WaveFormat = new WaveFormat(7500, 1) }); + + private bool _isStartRecording; + private bool _isRedSensor; + private WaveFileWriter _waveFileWriter; + + public AuditionViewModel() + { + CurrentVolume = GetCurrentMicVolume(); + + ListenRedSensorCommand = new RelayCommand(delegate + { + _isRedSensor = true; + RecordAudio(); + }); + + RedSensorMuteCommand = new RelayCommand(SetCurrentMicVolume); + + ListenBlueSensorCommand = new RelayCommand(delegate + { + _isRedSensor = false; + RecordAudio(); + }); + BlueSensorMuteCommand = new RelayCommand(SetCurrentMicVolume); + + //音频监听 + LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) + { + _isStartRecording = true; + + var buffer = args.Buffer; + var bytesRecorded = args.BytesRecorded; + //写入wav文件 + _waveFileWriter.Write(buffer, 0, bytesRecorded); + + var sts = new float[buffer.Length / 2]; + var outIndex = 0; + for (var i = 0; i < buffer.Length; i += 2) + { + sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; + } + + var audioWaveModel = new AudioWaveModel + { + IsRedSensor = _isRedSensor, + WavePoints = sts + }; + + Messenger.Default.Send(audioWaveModel, MessengerToken.RenderAudioOscillogram); + }; + + LazyWaveIn.Value.RecordingStopped += delegate + { + if (_waveFileWriter != null) + { + _waveFileWriter.Close(); + _waveFileWriter = null; + } + + _isStartRecording = false; + }; + } + /// - /// 传感器B按钮 + /// 录音 /// - private bool _sensorBIsEnable; - - public bool SensorBIsEnable + private void RecordAudio() { - get => _sensorBIsEnable; - set + if (_isStartRecording) { - _sensorBIsEnable = value; - RaisePropertyChanged(() => SensorBIsEnable); + LazyWaveIn.Value.StopRecording(); + } + else + { + _waveFileWriter = new WaveFileWriter( + $"{DirectoryManager.GetAudioDir()}/Audio_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.wav", + LazyWaveIn.Value.WaveFormat + ); + + LazyWaveIn.Value.StartRecording(); } } - private bool _muteIsChecked = true; - - public bool MuteIsChecked - { - get => _muteIsChecked; - set - { - _muteIsChecked = value; - RaisePropertyChanged(() => MuteIsChecked); - } - } - - #region user32.dll - - private const byte VkVolumeMute = 0xAD; - private const byte VkVolumeDown = 0xAE; - private const byte VkVolumeUp = 0xAF; - private const uint KeyEventExtendedKey = 0x0001; - private const uint KeyEventKeyUp = 0x0002; + #region 静音 //函数名不能改,否则会报找不到函数错误,dll里面定好了的 [DllImport("user32.dll")] @@ -103,74 +132,36 @@ [DllImport("user32.dll")] private static extern byte MapVirtualKey(uint uCode, uint uMapType); - #endregion - - private readonly DispatcherTimer _statusTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; - - public AuditionViewModel() + private void SetCurrentMicVolume() { - //静音 - MuteCommand = new RelayCommand(() => + if (_currentVolume > 0) { - if (_muteIsChecked) - { - //静音 - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), KeyEventExtendedKey, 0); - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), - KeyEventExtendedKey | KeyEventKeyUp, 0); - } - else - { - //非静音 - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), KeyEventExtendedKey, 0); - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), - KeyEventExtendedKey | KeyEventKeyUp, 0); - } - }); + //静音 + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - var random = new Random(); - for (var i = 0; i < 100; i++) - { - var p = new ObservablePoint - { - X = i, - Y = random.Next(-60, 60) - }; - - ColumnValues.Add(p); + CurrentVolume = 0; } - - //动态显示折线图 - Task.Factory.StartNew(RandomTempValue); - - //每秒查询信号状态 - _statusTimer.Tick += delegate + else { - SensorASignalIntensity = 5; - SensorAIsEnable = FlowStatus.RedSensorIsEnable; - SensorBSignalIntensity = 5; - SensorBIsEnable = FlowStatus.BlueSensorIsEnable; - }; - _statusTimer.Start(); + //非静音 + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); + + CurrentVolume = GetCurrentMicVolume(); + } } - private void RandomTempValue() - { - var random = new Random(); - var i = 100; - while (true) - { - Thread.Sleep(100); + #endregion - i++; - var y = random.Next(-60, 60); - ColumnValues.Add(new ObservablePoint(i, y)); - //设置最多显示150个点 - if (ColumnValues.Count > 100) - { - ColumnValues.RemoveAt(0); - } - } + private int GetCurrentMicVolume() + { + var enumerator = new MMDeviceEnumerator(); + + //获取音频输入设备 + var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); + Debug.WriteLine($"AuditionViewModel => {device.FriendlyName}"); + return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); } } } \ No newline at end of file diff --git a/Correlator/Converter/MuteStateConverter.cs b/Correlator/Converter/MuteStateConverter.cs index 132636d..15f89c1 100644 --- a/Correlator/Converter/MuteStateConverter.cs +++ b/Correlator/Converter/MuteStateConverter.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Media.Imaging; namespace Correlator.Converter { @@ -8,16 +9,17 @@ { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - try + if (value == null) { - var state = (bool)value; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); + } - return state ? "打开静音" : "关闭静音"; - } - catch + if ((int)value == 0) { - return ""; + return new BitmapImage(new Uri(@"..\..\Image\t_icon3.png", UriKind.Relative)); } + + return new BitmapImage(new Uri(@"..\..\Image\t_icon6.png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 2477c72..b4dbca9 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -77,20 +77,38 @@ ..\packages\HandyControl.3.3.0\lib\net48\HandyControl.dll - - ..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll - - - ..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll - ..\packages\log4net.2.0.15\lib\net45\log4net.dll + + ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll + False C:\Users\Administrator\Desktop\dll\MWArray.dll + + ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll + + + ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll + + + ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll + + + ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll + + + ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll + + + ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll + + + ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -143,6 +161,12 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -189,6 +213,7 @@ SoundSpeedDialog.xaml + diff --git a/Correlator/Model/AudioWaveModel.cs b/Correlator/Model/AudioWaveModel.cs new file mode 100644 index 0000000..1a61bbb --- /dev/null +++ b/Correlator/Model/AudioWaveModel.cs @@ -0,0 +1,8 @@ +namespace Correlator.Model +{ + public class AudioWaveModel + { + public bool IsRedSensor { get; set; } + public float[] WavePoints { get; set; } + } +} \ No newline at end of file diff --git a/Correlator/Util/MessengerToken.cs b/Correlator/Util/MessengerToken.cs index 759ffde..3eab0d3 100644 --- a/Correlator/Util/MessengerToken.cs +++ b/Correlator/Util/MessengerToken.cs @@ -17,5 +17,8 @@ //显示点名弹窗 public const string ShowCheckResponseDialog = "202306060101"; + + //渲染听音波形图 + public const string RenderAudioOscillogram = "202308110101"; } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml b/Correlator/View/AuditionWindow.xaml index db149ba..d3ceb40 100644 --- a/Correlator/View/AuditionWindow.xaml +++ b/Correlator/View/AuditionWindow.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" MinWidth="1366" MinHeight="768" @@ -17,15 +16,13 @@ mc:Ignorable="d"> - - - + - - - - + + + + + + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="20,0,0,0" + BorderBrush="LightGray" + BorderThickness="1" + CornerRadius="5"> + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index f63b937..7d28afb 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,7 +1,11 @@ -using System.Threading; +using System.Collections.Generic; +using System.Drawing; +using System.Threading; using System.Windows; +using Correlator.Model; using Correlator.SensorHubTag; using Correlator.Util; +using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using MessageBox = System.Windows.MessageBox; using Window = System.Windows.Window; @@ -14,55 +18,109 @@ { InitializeComponent(); + //去掉四周坐标轴 + RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; + RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + + BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; + BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; + GoBackButton.Click += delegate { Close(); }; - SensorACheckBox.Click += delegate + Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { - if (!SerialPortManager.Get.Sp.IsOpen) + Application.Current.Dispatcher.Invoke(delegate { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - } - else - { - if (SensorBCheckBox.IsChecked == true) + if (model.IsRedSensor) { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - SensorBCheckBox.IsChecked = false; + RedSensorScottPlotChart.Plot.Clear(); + RedSensorScottPlotChart.Refresh(); + + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + RedSensorScottPlotChart.Refresh(); } - - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - } - }; - - SensorBCheckBox.Click += delegate - { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - } - else - { - if (SensorACheckBox.IsChecked == true) + else { - CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - SensorACheckBox.IsChecked = false; - } + BlueSensorScottPlotChart.Plot.Clear(); + BlueSensorScottPlotChart.Refresh(); - new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - } - }; + var xDoubles = new List(); + var yDoubles = new List(); + + for (var i = 0; i < model.WavePoints.Length; i++) + { + xDoubles.Add(i); + yDoubles.Add(model.WavePoints[i]); + } + + BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), + Color.LimeGreen); + BlueSensorScottPlotChart.Refresh(); + } + }); + }); + + // SensorACheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // } + // else + // { + // if (SensorBCheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // SensorBCheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); + // } + // }; + // + // SensorBCheckBox.Click += delegate + // { + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); + // } + // else + // { + // if (SensorACheckBox.IsChecked == true) + // { + // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); + // SensorACheckBox.IsChecked = false; + // } + // + // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); + // } + // }; } private void SendSoundCollectCmd(object devCode) diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index aacb1d0..7c1bc95 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -396,20 +396,23 @@ Grid.Column="0" Width="38" Height="82" - Margin="20,0,0,40" + Margin="20,0,0,20" VerticalAlignment="Bottom" Source="{Binding RedTransmitterSignalIntensity, ConverterParameter=0, Converter={StaticResource SignalImageConverter}}" /> - + Margin="0,20" + BorderBrush="LightGray" + BorderThickness="1"> + + diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index 6593596..ae60c81 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -20,10 +20,12 @@ InitializeComponent(); var scottPlot = ScottplotView.Plot; - scottPlot.XLabel("频率(Hz)"); - scottPlot.YLabel("相关系数"); - ScottplotView.Refresh(); - + //去掉四周坐标轴 + scottPlot.XAxis.IsVisible = false; + scottPlot.XAxis2.IsVisible = false; + scottPlot.YAxis.IsVisible = false; + scottPlot.YAxis2.IsVisible = false; + #region 渲染、清空数据波形图 Messenger.Default.Register(this, MessengerToken.RenderOscillogram, array => @@ -100,11 +102,11 @@ ListenAudioButton.Click += delegate { - if (!SerialPortManager.Get.Sp.IsOpen) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // if (!SerialPortManager.Get.Sp.IsOpen) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } var auditionWindow = new AuditionWindow { diff --git a/Correlator/View/MainWindow.xaml.cs b/Correlator/View/MainWindow.xaml.cs index 99ff383..8a8bfff 100644 --- a/Correlator/View/MainWindow.xaml.cs +++ b/Correlator/View/MainWindow.xaml.cs @@ -33,7 +33,7 @@ { InitializeComponent(); - _checkSerialPortTimer.Start(); + // _checkSerialPortTimer.Start(); _checkSerialPortTimer.Tick += CheckSerialPortState; //倒计时显示大屏Logo diff --git a/Correlator/ViewModel/AuditionViewModel.cs b/Correlator/ViewModel/AuditionViewModel.cs index 393712f..b43b47e 100644 --- a/Correlator/ViewModel/AuditionViewModel.cs +++ b/Correlator/ViewModel/AuditionViewModel.cs @@ -1,100 +1,129 @@ using System; +using System.Diagnostics; using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Threading; +using Correlator.Model; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; -using LiveCharts; -using LiveCharts.Defaults; +using GalaSoft.MvvmLight.Messaging; +using NAudio.CoreAudioApi; +using NAudio.Wave; +using WaveFormat = NAudio.Wave.WaveFormat; namespace Correlator.ViewModel { public class AuditionViewModel : ViewModelBase { - public RelayCommand MuteCommand { get; set; } - public IChartValues ColumnValues { get; set; } = new ChartValues(); + #region RelayCommand - /// - /// 传感器A信号强度0-5 - /// - private int _sensorASignalIntensity; + public RelayCommand ListenRedSensorCommand { get; } + public RelayCommand RedSensorMuteCommand { get; } + public RelayCommand ListenBlueSensorCommand { get; } + public RelayCommand BlueSensorMuteCommand { get; } - public int SensorASignalIntensity + #endregion + + #region VM + + private int _currentVolume; + + public int CurrentVolume { - get => _sensorASignalIntensity; - private set - { - _sensorASignalIntensity = value; - RaisePropertyChanged(() => SensorASignalIntensity); - } - } - - /// - /// 传感器B信号强度0-5 - /// - private int _sensorBSignalIntensity; - - public int SensorBSignalIntensity - { - get => _sensorBSignalIntensity; - private set - { - _sensorBSignalIntensity = value; - RaisePropertyChanged(() => SensorBSignalIntensity); - } - } - - /// - /// 传感器A按钮 - /// - private bool _sensorAIsEnable; - - public bool SensorAIsEnable - { - get => _sensorAIsEnable; + get => _currentVolume; set { - _sensorAIsEnable = value; - RaisePropertyChanged(() => SensorAIsEnable); + _currentVolume = value; + RaisePropertyChanged(); } } + #endregion + + private static readonly Lazy LazyWaveIn = + new Lazy(() => new WaveIn { WaveFormat = new WaveFormat(7500, 1) }); + + private bool _isStartRecording; + private bool _isRedSensor; + private WaveFileWriter _waveFileWriter; + + public AuditionViewModel() + { + CurrentVolume = GetCurrentMicVolume(); + + ListenRedSensorCommand = new RelayCommand(delegate + { + _isRedSensor = true; + RecordAudio(); + }); + + RedSensorMuteCommand = new RelayCommand(SetCurrentMicVolume); + + ListenBlueSensorCommand = new RelayCommand(delegate + { + _isRedSensor = false; + RecordAudio(); + }); + BlueSensorMuteCommand = new RelayCommand(SetCurrentMicVolume); + + //音频监听 + LazyWaveIn.Value.DataAvailable += delegate(object sender, WaveInEventArgs args) + { + _isStartRecording = true; + + var buffer = args.Buffer; + var bytesRecorded = args.BytesRecorded; + //写入wav文件 + _waveFileWriter.Write(buffer, 0, bytesRecorded); + + var sts = new float[buffer.Length / 2]; + var outIndex = 0; + for (var i = 0; i < buffer.Length; i += 2) + { + sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; + } + + var audioWaveModel = new AudioWaveModel + { + IsRedSensor = _isRedSensor, + WavePoints = sts + }; + + Messenger.Default.Send(audioWaveModel, MessengerToken.RenderAudioOscillogram); + }; + + LazyWaveIn.Value.RecordingStopped += delegate + { + if (_waveFileWriter != null) + { + _waveFileWriter.Close(); + _waveFileWriter = null; + } + + _isStartRecording = false; + }; + } + /// - /// 传感器B按钮 + /// 录音 /// - private bool _sensorBIsEnable; - - public bool SensorBIsEnable + private void RecordAudio() { - get => _sensorBIsEnable; - set + if (_isStartRecording) { - _sensorBIsEnable = value; - RaisePropertyChanged(() => SensorBIsEnable); + LazyWaveIn.Value.StopRecording(); + } + else + { + _waveFileWriter = new WaveFileWriter( + $"{DirectoryManager.GetAudioDir()}/Audio_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.wav", + LazyWaveIn.Value.WaveFormat + ); + + LazyWaveIn.Value.StartRecording(); } } - private bool _muteIsChecked = true; - - public bool MuteIsChecked - { - get => _muteIsChecked; - set - { - _muteIsChecked = value; - RaisePropertyChanged(() => MuteIsChecked); - } - } - - #region user32.dll - - private const byte VkVolumeMute = 0xAD; - private const byte VkVolumeDown = 0xAE; - private const byte VkVolumeUp = 0xAF; - private const uint KeyEventExtendedKey = 0x0001; - private const uint KeyEventKeyUp = 0x0002; + #region 静音 //函数名不能改,否则会报找不到函数错误,dll里面定好了的 [DllImport("user32.dll")] @@ -103,74 +132,36 @@ [DllImport("user32.dll")] private static extern byte MapVirtualKey(uint uCode, uint uMapType); - #endregion - - private readonly DispatcherTimer _statusTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; - - public AuditionViewModel() + private void SetCurrentMicVolume() { - //静音 - MuteCommand = new RelayCommand(() => + if (_currentVolume > 0) { - if (_muteIsChecked) - { - //静音 - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), KeyEventExtendedKey, 0); - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), - KeyEventExtendedKey | KeyEventKeyUp, 0); - } - else - { - //非静音 - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), KeyEventExtendedKey, 0); - keybd_event(VkVolumeMute, MapVirtualKey(VkVolumeMute, 0), - KeyEventExtendedKey | KeyEventKeyUp, 0); - } - }); + //静音 + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); - var random = new Random(); - for (var i = 0; i < 100; i++) - { - var p = new ObservablePoint - { - X = i, - Y = random.Next(-60, 60) - }; - - ColumnValues.Add(p); + CurrentVolume = 0; } - - //动态显示折线图 - Task.Factory.StartNew(RandomTempValue); - - //每秒查询信号状态 - _statusTimer.Tick += delegate + else { - SensorASignalIntensity = 5; - SensorAIsEnable = FlowStatus.RedSensorIsEnable; - SensorBSignalIntensity = 5; - SensorBIsEnable = FlowStatus.BlueSensorIsEnable; - }; - _statusTimer.Start(); + //非静音 + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001, 0); + keybd_event(0xAD, MapVirtualKey(0xAD, 0), 0x0001 | 0x0002, 0); + + CurrentVolume = GetCurrentMicVolume(); + } } - private void RandomTempValue() - { - var random = new Random(); - var i = 100; - while (true) - { - Thread.Sleep(100); + #endregion - i++; - var y = random.Next(-60, 60); - ColumnValues.Add(new ObservablePoint(i, y)); - //设置最多显示150个点 - if (ColumnValues.Count > 100) - { - ColumnValues.RemoveAt(0); - } - } + private int GetCurrentMicVolume() + { + var enumerator = new MMDeviceEnumerator(); + + //获取音频输入设备 + var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); + Debug.WriteLine($"AuditionViewModel => {device.FriendlyName}"); + return (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); } } } \ No newline at end of file diff --git a/Correlator/packages.config b/Correlator/packages.config index 681f3d4..2630746 100644 --- a/Correlator/packages.config +++ b/Correlator/packages.config @@ -1,26 +1,33 @@  - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file