更新
This commit is contained in:
@@ -39,6 +39,7 @@ namespace COFTester.ViewModels
|
||||
private bool _showAllCurves = true;
|
||||
private int _testCounter = 0;
|
||||
private bool _disposed = false;
|
||||
private string _selectedDirection = ""; // 选中的方向:Up/Down/Right/Left
|
||||
|
||||
public MainViewModel(IDataAcquisitionService daqService, DataProcessingService processingService, AppConfig config)
|
||||
{
|
||||
@@ -604,17 +605,33 @@ namespace COFTester.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_selectedDirection))
|
||||
{
|
||||
StatusMessage = "请先选择测试方向";
|
||||
MessageBox.Show("请先选择测试方向(上升/下降/向右/向左)", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
_realTimePoints.Clear();
|
||||
OnPropertyChanged(nameof(DataPointsCount));
|
||||
LatestResult = null;
|
||||
IsTesting = true;
|
||||
StatusMessage = Lang.Testing;
|
||||
StatusMessage = $"开始测试 - {_selectedDirection}方向";
|
||||
UpdateScottPlot();
|
||||
|
||||
// 向选定方向的寄存器写入1,开始测试
|
||||
_daqService.StartDirectionTest(_selectedDirection);
|
||||
_daqService.StartAcquisition(Parameters);
|
||||
}
|
||||
|
||||
private void StopTest()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_selectedDirection))
|
||||
{
|
||||
// 向选定方向的寄存器写入0,停止测试
|
||||
_daqService.StopDirectionTest(_selectedDirection);
|
||||
}
|
||||
|
||||
_daqService.StopAcquisition();
|
||||
IsTesting = false;
|
||||
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>
|
||||
|
||||
@@ -186,27 +186,71 @@
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<!-- 向左按钮 -->
|
||||
<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"
|
||||
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}"
|
||||
Height="70" Width="100" Background="#E67E22" Foreground="White"
|
||||
Height="70" Width="100"
|
||||
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}"
|
||||
Height="70" Width="100" Background="#E67E22" Foreground="White"
|
||||
Height="70" Width="100"
|
||||
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}"
|
||||
Height="70" Width="100" Background="#E67E22" Foreground="White"
|
||||
Height="70" Width="100"
|
||||
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"/>
|
||||
|
||||
@@ -12,7 +12,13 @@ namespace COFTester.Views
|
||||
{
|
||||
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.PreviewMouseUp += (s, e) => OnDirectionButtonReleased("Up");
|
||||
BtnUp.MouseLeave += (s, e) => OnDirectionButtonReleased("Up");
|
||||
@@ -37,6 +43,11 @@ namespace COFTester.Views
|
||||
viewModel.SetPlot(FrictionPlot);
|
||||
}
|
||||
|
||||
private void SelectDirection(string direction)
|
||||
{
|
||||
_viewModel?.SelectDirection(direction);
|
||||
}
|
||||
|
||||
private void OnDirectionButtonPressed(string direction)
|
||||
{
|
||||
_viewModel?.OnDirectionControl(direction, true);
|
||||
|
||||
Reference in New Issue
Block a user