This commit is contained in:
xyy
2026-05-25 17:35:18 +08:00
parent 23a818a000
commit 1c6e33c6c8
2 changed files with 59 additions and 15 deletions

View File

@@ -300,9 +300,9 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Style="{StaticResource TabButtonStyle}" Grid.Column="0" Content="主页" Click="GoHome"/>
<Button Style="{StaticResource TabButtonStyle}" Grid.Column="1" Content="测试界面" Click="GoTest"/>
<Button Style="{StaticResource TabButtonStyle}" Grid.Column="2" Content="记录画面" Click="GoView"/>
<Button x:Name="btnNavHome" Style="{StaticResource TabButtonStyle}" Grid.Column="0" Content="主页" Click="GoHome"/>
<Button x:Name="btnNavTest" Style="{StaticResource TabButtonStyle}" Grid.Column="1" Content="测试界面" Click="GoTest"/>
<Button x:Name="btnNavRecord" Style="{StaticResource TabButtonStyle}" Grid.Column="2" Content="记录画面" Click="GoView"/>
</Grid>
</Grid>
</Page>

View File

@@ -58,6 +58,7 @@ namespace 头罩视野.Views
private double _lastAngle = -1;
private bool _fullTestCompleted = false; // 是否已完成一组完整测试(左右眼都测完)
private double _binocularTotalArea = 0; // 双目总视野面积
@@ -167,12 +168,24 @@ namespace 头罩视野.Views
ma.BtnClickFunction(Function.ButtonType., 103);
ButtonTest.Content = "测试";
_isTesting = false;
SetNavButtonsEnabled(true); // 启用导航栏
testTimer.Stop();
}
//测试按钮
private async void Button_Click_Test(object sender, RoutedEventArgs e)
{
if (_fullTestCompleted)
{
MessageBox.Show("请先点击“复位”按钮清除上次测试数据,再进行新测试!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (_isTesting)
{
// 停止测试
@@ -195,6 +208,10 @@ namespace 头罩视野.Views
ButtonTest.Content = "测试中...";
SetNavButtonsEnabled(false); // 禁用导航栏
// 在开始测试前清空当前眼的数据,保留另一眼的数据(如果有)
if (btnLeft.Content.ToString() == "左眼关" && btnRight.Content.ToString() == "右眼开")
{
@@ -257,6 +274,7 @@ namespace 头罩视野.Views
testTimer.Stop();
await _modbusMaster.WriteSingleCoilAsync(1, 102, false);
FinishTestAndCompute(); // 新方法
SetNavButtonsEnabled(true); // 启用导航栏
}
}
}
@@ -298,7 +316,7 @@ namespace 头罩视野.Views
System.Diagnostics.Debug.WriteLine($"右眼面积: {rightArea}");
System.Diagnostics.Debug.WriteLine($"总视野面积: {totalArea}");
System.Diagnostics.Debug.WriteLine($"双目视野面积: {biArea}");
_fullTestCompleted = true;
// 更新界面
Dispatcher.Invoke(() =>
{
@@ -357,7 +375,7 @@ namespace 头罩视野.Views
zsysaveSum.Text = totalRate.ToString("F2");
}
});
_fullTestCompleted = true; // 新增
ShowAreaData(); // 保存记录
}
@@ -522,7 +540,7 @@ namespace 头罩视野.Views
{
// 选中 → 试样测试
//_fullTestCompleted = false;
tbTest.Content = "空白测试";
GlobalData.CurrentMode = "空白测试";
@@ -533,7 +551,7 @@ namespace 头罩视野.Views
private async void TbTest_Checked(object sender, RoutedEventArgs e)
{
// 取消 → 空白测试
//_fullTestCompleted = false;
tbTest.Content = "试样测试";
GlobalData.CurrentMode = "试样测试";
tbTest.Background = System.Windows.Media.Brushes.LightGray;
@@ -700,14 +718,14 @@ namespace 头罩视野.Views
//btnRight.Content = "右眼开";
//LedOff(led1);
//LedOff(led0);
_fullTestCompleted = false;
_leftBoundaries = new List<double>();
_rightBoundaries = new List<double>();
_binocularTotalArea = 0;
maxBottomViewAngle = 0;
SetNavButtonsEnabled(true); // 启用导航栏
//初始化全部设为0
_leftFinalData = Enumerable.Repeat(0, 240).ToList();
_rightFinalData = Enumerable.Repeat(0, 240).ToList();
@@ -851,12 +869,11 @@ namespace 头罩视野.Views
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
// ===== 新增:恢复之前保存的状态 =====
// ===== 恢复之前保存的状态 =====
if (Application.Current.Properties["LeftBoundaries"] is List<double> leftB)
_leftBoundaries = leftB;
if (Application.Current.Properties["RightBoundaries"] is List<double> rightB)
_rightBoundaries = rightB;
// 恢复左右眼独立的角度列表
if (Application.Current.Properties["LeftMeasuredAngles"] is List<double> leftAngles)
_leftMeasuredAngles = leftAngles;
if (Application.Current.Properties["RightMeasuredAngles"] is List<double> rightAngles)
@@ -877,12 +894,22 @@ namespace 头罩视野.Views
if (Application.Current.Properties["NextTargetAngle"] is double next)
_nextTargetAngle = next;
// 恢复界面显示值
if (Application.Current.Properties["Zmsyarea"] is string zmsy) zmsyarea.Text = zmsy;
if (Application.Current.Properties["Ymsyarea"] is string ymsy) ymsyarea.Text = ymsy;
if (Application.Current.Properties["Smsyarea"] is string smsy) smsyarea.Text = smsy;
if (Application.Current.Properties["ZsyareaNum"] is string zsya) zsyareaNum.Text = zsya;
if (Application.Current.Properties["Xfsyarea"] is string xfsy) xfsyarea.Text = xfsy;
if (Application.Current.Properties["Sybhl"] is string syb) sybhl.Text = syb;
if (Application.Current.Properties["ZsysaveSum"] is string zss) zsysaveSum.Text = zss;
// 如果之前正在测试,重新启动定时器
if (_isTesting)
{
testTimer.Start();
}
// 根据测试状态设置导航栏启用/禁用
SetNavButtonsEnabled(!_isTesting);
_timer.Start();
ma = new Function(_modbusMaster);
c = new DataChange();
@@ -896,10 +923,9 @@ namespace 头罩视野.Views
_cts = null;
_serialPort?.Close();
// ===== 新增:保存状态到应用程序属性 =====
// ===== 保存状态到应用程序属性 =====
Application.Current.Properties["LeftBoundaries"] = _leftBoundaries?.ToList();
Application.Current.Properties["RightBoundaries"] = _rightBoundaries?.ToList();
// 保存左右眼独立的角度列表
Application.Current.Properties["LeftMeasuredAngles"] = _leftMeasuredAngles?.ToList();
Application.Current.Properties["RightMeasuredAngles"] = _rightMeasuredAngles?.ToList();
@@ -910,10 +936,20 @@ namespace 头罩视野.Views
Application.Current.Properties["IsTesting"] = _isTesting;
Application.Current.Properties["StepAngle"] = _stepAngle;
Application.Current.Properties["NextTargetAngle"] = _nextTargetAngle;
// 保存界面显示值
Application.Current.Properties["Zmsyarea"] = zmsyarea.Text;
Application.Current.Properties["Ymsyarea"] = ymsyarea.Text;
Application.Current.Properties["Smsyarea"] = smsyarea.Text;
Application.Current.Properties["ZsyareaNum"] = zsyareaNum.Text;
Application.Current.Properties["Xfsyarea"] = xfsyarea.Text;
Application.Current.Properties["Sybhl"] = sybhl.Text;
Application.Current.Properties["ZsysaveSum"] = zsysaveSum.Text;
}
private IModbusMaster _serialMaster;
private SerialPort _serialPort; // 保存串口对象以便关闭
private bool _isSerialInitialized = false;
@@ -1032,7 +1068,15 @@ namespace 头罩视野.Views
}
}
/// <summary>
/// 设置底部导航按钮的启用/禁用状态
/// </summary>
private void SetNavButtonsEnabled(bool enabled)
{
btnNavHome.IsEnabled = enabled;
btnNavTest.IsEnabled = enabled;
btnNavRecord.IsEnabled = enabled;
}
}
}