Bläddra i källkod

feat(log): 各界面按钮Click埋点记录操作+参数

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
huangjie 1 vecka sedan
förälder
incheckning
18ef6335d9
5 ändrade filer med 29 tillägg och 4 borttagningar
  1. 4 2
      MainWindow.Calib.cs
  2. 7 0
      MainWindow.Camera.cs
  3. 13 2
      MainWindow.Motor.cs
  4. 2 0
      MainWindow.Scan.cs
  5. 3 0
      MainWindow.xaml.cs

+ 4 - 2
MainWindow.Calib.cs

@@ -54,6 +54,7 @@ namespace AutoFocusTool
         // 标定合格(检到圆且峰比>1.2)才用JSON,否则降级到EEPROM。
         private void BtnGoWell_Click(object sender, RoutedEventArgs e)
         {
+            LogAction($"点击 转到well={CmbWell.SelectedIndex + 1}");
             if (_motor == null) { Log("未连接。"); return; }
             if (_busy) { Log("设备忙。"); return; }
             int well = CmbWell.SelectedIndex + 1;
@@ -91,13 +92,14 @@ namespace AutoFocusTool
 
         // ── 需求2:全选/全不选 ──
         private void BtnWellAll_Click(object sender, RoutedEventArgs e)
-        { foreach (var cb in _wellChecks) cb.IsChecked = true; }
+        { LogAction("点击 全选well"); foreach (var cb in _wellChecks) cb.IsChecked = true; }
         private void BtnWellNone_Click(object sender, RoutedEventArgs e)
-        { foreach (var cb in _wellChecks) cb.IsChecked = false; }
+        { LogAction("点击 全不选well"); foreach (var cb in _wellChecks) cb.IsChecked = false; }
 
         // ── 需求2、3:一键全自动初始化(勾选well + 独立窗口显示)──
         private void BtnAutoInit_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 一键全自动初始化");
             if (_camera == null || _motor == null) { Log("需要先连接相机+串口。"); return; }
             if (_busy) { Log("设备忙,请稍候。"); return; }
 

+ 7 - 0
MainWindow.Camera.cs

@@ -46,6 +46,7 @@ namespace AutoFocusTool
         // ── 抓一帧 ──
         private void BtnGrab_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 抓一帧");
             Task.Run(() => GrabAndShow());
         }
 
@@ -64,6 +65,7 @@ namespace AutoFocusTool
         // ── 实时预览 ──
         private void TglLive_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 实时预览(切换)");
             if (TglLive.IsChecked == true)
             {
                 _liveCts = new CancellationTokenSource();
@@ -97,6 +99,7 @@ namespace AutoFocusTool
         // ── 曝光 ──
         private void BtnSetExp_Click(object sender, RoutedEventArgs e)
         {
+            LogAction($"点击 设置曝光={TxtExposure.Text}");
             if (_camera == null) return;
             int exp = ParseInt(TxtExposure.Text, 400);
             int r = _camera.SetExposure(exp);
@@ -115,6 +118,7 @@ namespace AutoFocusTool
         // ── 增益 ──
         private void BtnSetGain_Click(object sender, RoutedEventArgs e)
         {
+            LogAction($"点击 设置增益 R={TxtGainR.Text} G={TxtGainG.Text} B={TxtGainB.Text}");
             if (_camera == null) return;
             byte rr = (byte)ParseInt(TxtGainR.Text, 25);
             byte gg = (byte)ParseInt(TxtGainG.Text, 14);
@@ -128,12 +132,14 @@ namespace AutoFocusTool
         // ── 光源 ──
         private void BtnLedOn_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 开光源");
             if (_motor == null) return;
             Task.Run(() => { _busy = true; bool ok = _motor.OpenLED(); _busy = false; Log($"开光源 {(ok ? "OK" : "失败")}"); });
         }
 
         private void BtnLedOff_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 关光源");
             if (_motor == null) return;
             Task.Run(() => { _busy = true; bool ok = _motor.CloseLED(); _busy = false; Log($"关光源 {(ok ? "OK" : "失败")}"); });
         }
@@ -141,6 +147,7 @@ namespace AutoFocusTool
         // ── 存图 ──
         private void BtnSaveImg_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 存图");
             if (_lastFrame == null) { Log("还没有图像。"); return; }
             var dlg = new SaveFileDialog
             {

+ 13 - 2
MainWindow.Motor.cs

@@ -33,21 +33,27 @@ namespace AutoFocusTool
         private void BtnZUp_Click(object sender, RoutedEventArgs e)
         {
             int step = ParseInt2(TxtZStep.Text, 128);
+            LogAction($"点击 Z正转, 步距={step}");
             MotorAction($"Z正转 {step}步", () => _motor.VerticalForward(step));
         }
 
         private void BtnZDown_Click(object sender, RoutedEventArgs e)
         {
             int step = ParseInt2(TxtZStep.Text, 128);
+            LogAction($"点击 Z反转, 步距={step}");
             MotorAction($"Z反转 {step}步", () => _motor.VerticalBackward(step));
         }
 
         private void BtnZReset_Click(object sender, RoutedEventArgs e)
-            => MotorAction("Z复位", () => _motor.VerticalReset());
+        {
+            LogAction("点击 Z复位");
+            MotorAction("Z复位", () => _motor.VerticalReset());
+        }
 
         private void BtnZMoveTo_Click(object sender, RoutedEventArgs e)
         {
             int abs = ParseInt2(TxtZAbs.Text, 0);
+            LogAction($"点击 Z绝对移动, 目标={abs}");
             MotorAction($"Z绝对移动→{abs}", () => _motor.VerticalMoveTo(abs));
         }
 
@@ -55,17 +61,22 @@ namespace AutoFocusTool
         private void BtnHFwd_Click(object sender, RoutedEventArgs e)
         {
             int step = ParseInt2(TxtHStep.Text, 100);
+            LogAction($"点击 水平正转, 步距={step}");
             MotorAction($"水平正转 {step}步", () => _motor.HorizontalForward(step));
         }
 
         private void BtnHBwd_Click(object sender, RoutedEventArgs e)
         {
             int step = ParseInt2(TxtHStep.Text, 100);
+            LogAction($"点击 水平反转, 步距={step}");
             MotorAction($"水平反转 {step}步", () => _motor.HorizontalBackward(step));
         }
 
         private void BtnHReset_Click(object sender, RoutedEventArgs e)
-            => MotorAction("水平复位", () => _motor.HorizontalReset());
+        {
+            LogAction("点击 水平复位");
+            MotorAction("水平复位", () => _motor.HorizontalReset());
+        }
 
         // ── 读位置并显示 ──
         private void RefreshPositions()

+ 2 - 0
MainWindow.Scan.cs

@@ -17,6 +17,7 @@ namespace AutoFocusTool
         // ── Z 扫描:逐层移动→等稳→抓帧→算分,画曲线,取全局峰 ──
         private void BtnZScan_Click(object sender, RoutedEventArgs e)
         {
+            LogAction($"点击 Z扫描 起点={TxtScanStart.Text} 层距={TxtScanStep.Text} 层数={TxtScanCount.Text}");
             if (_camera == null || _motor == null) { Log("需要相机+串口都连接。"); return; }
             if (_busy) { Log("串口忙。"); return; }
 
@@ -90,6 +91,7 @@ namespace AutoFocusTool
 
         private void BtnStop_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 停止扫描");
             _scanCts?.Cancel();
             _liveCts?.Cancel();
             _calibCts?.Cancel();

+ 3 - 0
MainWindow.xaml.cs

@@ -72,6 +72,7 @@ namespace AutoFocusTool
         // ───────────────────────── 扫描设备 ─────────────────────────
         private async void BtnScan_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 扫描设备");
             BtnScan.IsEnabled = false;
             Log("开始扫描设备(枚举相机 + 扫串口握手)...");
             try
@@ -104,6 +105,7 @@ namespace AutoFocusTool
         // ───────────────────────── 连接 / 断开 ─────────────────────────
         private void BtnConnect_Click(object sender, RoutedEventArgs e)
         {
+            LogAction($"点击 连接 舱室索引={CmbHouse.SelectedIndex}");
             int idx = CmbHouse.SelectedIndex;
             if (idx < 0 || idx >= _houses.Count)
             {
@@ -166,6 +168,7 @@ namespace AutoFocusTool
 
         private void BtnDisconnect_Click(object sender, RoutedEventArgs e)
         {
+            LogAction("点击 断开");
             Cleanup();
             TxtConnState.Text = "未连接";
             TxtConnState.Foreground = Brushes.Salmon;