This commit is contained in:
GukSang.Jin
2026-01-29 14:59:33 +08:00
parent 5fbc7d2ee5
commit 971cd0cd24
3 changed files with 112 additions and 10 deletions

View File

@@ -39,6 +39,7 @@ namespace COFTester.ViewModels
private bool _showAllCurves = true; private bool _showAllCurves = true;
private int _testCounter = 0; private int _testCounter = 0;
private bool _disposed = false; private bool _disposed = false;
private string _selectedDirection = ""; // 选中的方向Up/Down/Right/Left
public MainViewModel(IDataAcquisitionService daqService, DataProcessingService processingService, AppConfig config) public MainViewModel(IDataAcquisitionService daqService, DataProcessingService processingService, AppConfig config)
{ {
@@ -604,17 +605,33 @@ namespace COFTester.ViewModels
return; return;
} }
if (string.IsNullOrEmpty(_selectedDirection))
{
StatusMessage = "请先选择测试方向";
MessageBox.Show("请先选择测试方向(上升/下降/向右/向左)", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
_realTimePoints.Clear(); _realTimePoints.Clear();
OnPropertyChanged(nameof(DataPointsCount)); OnPropertyChanged(nameof(DataPointsCount));
LatestResult = null; LatestResult = null;
IsTesting = true; IsTesting = true;
StatusMessage = Lang.Testing; StatusMessage = $"开始测试 - {_selectedDirection}方向";
UpdateScottPlot(); UpdateScottPlot();
// 向选定方向的寄存器写入1开始测试
_daqService.StartDirectionTest(_selectedDirection);
_daqService.StartAcquisition(Parameters); _daqService.StartAcquisition(Parameters);
} }
private void StopTest() private void StopTest()
{ {
if (!string.IsNullOrEmpty(_selectedDirection))
{
// 向选定方向的寄存器写入0停止测试
_daqService.StopDirectionTest(_selectedDirection);
}
_daqService.StopAcquisition(); _daqService.StopAcquisition();
IsTesting = false; IsTesting = false;
StatusMessage = Lang.TestStopped; StatusMessage = Lang.TestStopped;
@@ -778,6 +795,36 @@ namespace COFTester.ViewModels
} }
} }
/// <summary>
/// 选择测试方向
/// </summary>
public void SelectDirection(string direction)
{
if (_isTesting)
{
StatusMessage = "测试进行中,无法更改方向";
return;
}
_selectedDirection = direction;
string directionText = direction switch
{
"Up" => "上升",
"Down" => "下降",
"Right" => "向右",
"Left" => "向左",
_ => direction
};
StatusMessage = $"已选择方向: {directionText}";
OnPropertyChanged(nameof(SelectedDirection));
System.Diagnostics.Debug.WriteLine($"[ViewModel] 选择方向: {direction}");
}
/// <summary>
/// 当前选中的方向
/// </summary>
public string SelectedDirection => _selectedDirection;
/// <summary> /// <summary>
/// 添加曲线到图表 /// 添加曲线到图表
/// </summary> /// </summary>

View File

@@ -186,27 +186,71 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<!-- 向左按钮 --> <!-- 向左按钮 -->
<Button x:Name="BtnLeft" Content="{Binding Lang.DirectionLeft}" <Button x:Name="BtnLeft" Content="{Binding Lang.DirectionLeft}"
Height="70" Width="100" Background="#E67E22" Foreground="White" Height="70" Width="100"
FontSize="16" FontWeight="Bold" BorderThickness="0" FontSize="16" FontWeight="Bold" BorderThickness="0"
Cursor="Hand" Margin="5" Style="{StaticResource IndustrialButtonStyle}"/> Cursor="Hand" Margin="5">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource IndustrialButtonStyle}">
<Setter Property="Background" Value="#E67E22"/>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedDirection}" Value="Left">
<Setter Property="Background" Value="#27AE60"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<!-- 向右按钮 --> <!-- 向右按钮 -->
<Button x:Name="BtnRight" Content="{Binding Lang.DirectionRight}" <Button x:Name="BtnRight" Content="{Binding Lang.DirectionRight}"
Height="70" Width="100" Background="#E67E22" Foreground="White" Height="70" Width="100"
FontSize="16" FontWeight="Bold" BorderThickness="0" FontSize="16" FontWeight="Bold" BorderThickness="0"
Cursor="Hand" Margin="5" Style="{StaticResource IndustrialButtonStyle}"/> Cursor="Hand" Margin="5">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource IndustrialButtonStyle}">
<Setter Property="Background" Value="#E67E22"/>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedDirection}" Value="Right">
<Setter Property="Background" Value="#27AE60"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<!-- 上升按钮 --> <!-- 上升按钮 -->
<Button x:Name="BtnUp" Content="{Binding Lang.DirectionUp}" <Button x:Name="BtnUp" Content="{Binding Lang.DirectionUp}"
Height="70" Width="100" Background="#E67E22" Foreground="White" Height="70" Width="100"
FontSize="16" FontWeight="Bold" BorderThickness="0" FontSize="16" FontWeight="Bold" BorderThickness="0"
Cursor="Hand" Margin="5" Style="{StaticResource IndustrialButtonStyle}"/> Cursor="Hand" Margin="5">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource IndustrialButtonStyle}">
<Setter Property="Background" Value="#E67E22"/>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedDirection}" Value="Up">
<Setter Property="Background" Value="#27AE60"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<!-- 下降按钮 --> <!-- 下降按钮 -->
<Button x:Name="BtnDown" Content="{Binding Lang.DirectionDown}" <Button x:Name="BtnDown" Content="{Binding Lang.DirectionDown}"
Height="70" Width="100" Background="#E67E22" Foreground="White" Height="70" Width="100"
FontSize="16" FontWeight="Bold" BorderThickness="0" FontSize="16" FontWeight="Bold" BorderThickness="0"
Cursor="Hand" Margin="5" Style="{StaticResource IndustrialButtonStyle}"/> Cursor="Hand" Margin="5">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource IndustrialButtonStyle}">
<Setter Property="Background" Value="#E67E22"/>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedDirection}" Value="Down">
<Setter Property="Background" Value="#27AE60"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<!-- 分隔线 --> <!-- 分隔线 -->
<Separator Width="2" Margin="10,10" Background="#BDC3C7"/> <Separator Width="2" Margin="10,10" Background="#BDC3C7"/>

View File

@@ -12,7 +12,13 @@ namespace COFTester.Views
{ {
InitializeComponent(); InitializeComponent();
// 绑定方向控制按钮事件 // 绑定方向选择按钮事件(单击选择方向)
BtnUp.Click += (s, e) => SelectDirection("Up");
BtnDown.Click += (s, e) => SelectDirection("Down");
BtnRight.Click += (s, e) => SelectDirection("Right");
BtnLeft.Click += (s, e) => SelectDirection("Left");
// 绑定方向控制按钮事件(长按手动控制)
BtnUp.PreviewMouseDown += (s, e) => OnDirectionButtonPressed("Up"); BtnUp.PreviewMouseDown += (s, e) => OnDirectionButtonPressed("Up");
BtnUp.PreviewMouseUp += (s, e) => OnDirectionButtonReleased("Up"); BtnUp.PreviewMouseUp += (s, e) => OnDirectionButtonReleased("Up");
BtnUp.MouseLeave += (s, e) => OnDirectionButtonReleased("Up"); BtnUp.MouseLeave += (s, e) => OnDirectionButtonReleased("Up");
@@ -37,6 +43,11 @@ namespace COFTester.Views
viewModel.SetPlot(FrictionPlot); viewModel.SetPlot(FrictionPlot);
} }
private void SelectDirection(string direction)
{
_viewModel?.SelectDirection(direction);
}
private void OnDirectionButtonPressed(string direction) private void OnDirectionButtonPressed(string direction)
{ {
_viewModel?.OnDirectionControl(direction, true); _viewModel?.OnDirectionControl(direction, true);