浏览代码

fixes for gui and startup

spacexerq 1 周之前
父节点
当前提交
39ee226a90
共有 5 个文件被更改,包括 121 次插入8 次删除
  1. 2 2
      apps/gui/cfg/hw_config.json
  2. 90 2
      apps/gui/src/tabs/seq_interp_tab.py
  3. 2 2
      services/seq-interp/cfg/hw_config.json
  4. 14 1
      start.ps1
  5. 13 1
      update.ps1

+ 2 - 2
apps/gui/cfg/hw_config.json

@@ -7,12 +7,12 @@
     "device_model": "PS4000A",
     "srate": 8000000,
     "n_channels": 3,
-    "channel_ranges": [5, 5, 5],
+    "channel_ranges": [2, 2, 2],
     "n_triggers": 1,
     "averaging": 100,
     "averaging_delay": 10,
     "trigger_channel": 2,
-    "trig_direction": 0,
+    "trig_direction": 1,
     "threshold": 5000,
     "auto_measure_time": 10000,
     "enabled": true

+ 90 - 2
apps/gui/src/tabs/seq_interp_tab.py

@@ -16,10 +16,27 @@ from PySide6.QtGui import QFont, QColor
 from PySide6.QtWidgets import (
     QApplication, QWidget, QSplitter, QVBoxLayout, QHBoxLayout,
     QGroupBox, QFormLayout, QLabel, QListWidget, QListWidgetItem,
-    QFrame, QPushButton, QProgressBar,
+    QFrame, QPushButton, QProgressBar, QComboBox,
     QMessageBox, QScrollArea, QSizePolicy, QFileDialog,
 )
 
+# ADC dynamic-range codes  →  (code, label shown in UI)
+_ADC_RANGES: list[tuple[int, str]] = [
+    (0,  "10 мВ"),
+    (1,  "20 мВ"),
+    (2,  "50 мВ"),
+    (3,  "100 мВ"),
+    (4,  "200 мВ"),
+    (5,  "500 мВ"),
+    (6,  "1 В"),
+    (7,  "2 В"),
+    (8,  "5 В"),
+    (9,  "10 В"),
+    (10, "20 В"),
+    (11, "50 В"),
+]
+_ADC_RANGE_DEFAULT_CODE = 2   # 50 мВ
+
 from src.gui.tr_widgets import TrGroupBox, TrPushButton
 from src.gui.adapters import (
     build_block_rows, seq_metadata, validate_timing, find_block_at_time,
@@ -192,6 +209,28 @@ class SeqInterpTab(QWidget):
 
         lay.addStretch()
 
+        # -- ADC dynamic range selector ----------------------------------------
+        lay.addWidget(sep())
+        _range_lbl = QLabel("АЦП диап.:")
+        _range_lbl.setToolTip("Динамический диапазон АЦП (channel_ranges в iadc)")
+        lay.addWidget(_range_lbl)
+
+        self._adc_range_combo = QComboBox()
+        self._adc_range_combo.setToolTip(
+            "Динамический диапазон АЦП.\n"
+            "Значение записывается в iadc.channel_ranges для всех каналов."
+        )
+        for code, label in _ADC_RANGES:
+            self._adc_range_combo.addItem(label, userData=code)
+        # set default
+        default_idx = next(
+            (i for i, (c, _) in enumerate(_ADC_RANGES) if c == _ADC_RANGE_DEFAULT_CODE),
+            0,
+        )
+        self._adc_range_combo.setCurrentIndex(default_idx)
+        self._adc_range_combo.currentIndexChanged.connect(self._on_adc_range_changed)
+        lay.addWidget(self._adc_range_combo)
+
         self._progress = QProgressBar()
         self._progress.setRange(0, 0)
         self._progress.setFixedWidth(120)
@@ -489,8 +528,11 @@ class SeqInterpTab(QWidget):
         try:
             post_info = result.get("post_json", {})
             self._post_info = post_info.get("info", post_info)
+            self._sync_combo_from_post_info()   # reflect hw_config range in combo
+            self._patch_adc_range(self._post_info)  # then apply current selection
             xml_text = result.get("xml_text", "")
-            post_text = __import__("json").dumps(post_info, indent=2, default=str)
+            import json as _json
+            post_text = _json.dumps({"info": self._post_info}, indent=2, default=str)
             self._preview.set_xml_text(xml_text)
             self._preview.set_post_json_text(post_text)
 
@@ -542,6 +584,8 @@ class SeqInterpTab(QWidget):
             import json as _json
             payload = _json.loads(post_text)
             self._post_info = payload.get("info", payload)
+            self._sync_combo_from_post_info()
+            self._patch_adc_range(self._post_info)
         except Exception:
             self._post_info = None
         if self._post_info:
@@ -551,8 +595,52 @@ class SeqInterpTab(QWidget):
             self, "Export complete", f"Artifacts written to:\n{output_dir}"
         )
 
+    # -- ADC range helpers -------------------------------------------------
+
+    def _selected_adc_code(self) -> int:
+        """Return the currently selected ADC range code (0–11)."""
+        return self._adc_range_combo.currentData()
+
+    def _patch_adc_range(self, info: dict) -> None:
+        """
+        Overwrite channel_ranges in info['iadc'] with the selected code
+        for every channel.  Operates in-place.
+        """
+        iadc = info.get("iadc")
+        if not isinstance(iadc, dict):
+            return
+        code = self._selected_adc_code()
+        n = len(iadc.get("channel_ranges", [])) or 1
+        iadc["channel_ranges"] = [code] * n
+
+    def _sync_combo_from_post_info(self) -> None:
+        """
+        After loading post_info, update the combo to reflect the first
+        channel_ranges value (if it corresponds to a known code).
+        """
+        if not self._post_info:
+            return
+        iadc = self._post_info.get("iadc", {})
+        ranges = iadc.get("channel_ranges", [])
+        if ranges:
+            code = ranges[0]
+            idx = next(
+                (i for i, (c, _) in enumerate(_ADC_RANGES) if c == code),
+                None,
+            )
+            if idx is not None:
+                self._adc_range_combo.blockSignals(True)
+                self._adc_range_combo.setCurrentIndex(idx)
+                self._adc_range_combo.blockSignals(False)
+
+    def _on_adc_range_changed(self) -> None:
+        """Live-patch _post_info when the user changes the range selector."""
+        if self._post_info:
+            self._patch_adc_range(self._post_info)
+
     def _send_to_scanner(self) -> None:
         if self._post_info:
+            self._patch_adc_range(self._post_info)   # ensure latest selection applied
             self.ready_for_scan.emit(self._post_info)
 
     def _on_worker_error(self, msg: str) -> None:

+ 2 - 2
services/seq-interp/cfg/hw_config.json

@@ -7,12 +7,12 @@
     "device_model": "PS4000A",
     "srate": 8000000,
     "n_channels": 3,
-    "channel_ranges": [5, 5, 5],
+    "channel_ranges": [2, 2, 2],
     "n_triggers": 1,
     "averaging": 100,
     "averaging_delay": 10,
     "trigger_channel": 2,
-    "trig_direction": 0,
+    "trig_direction": 1,
     "threshold": 5000,
     "auto_measure_time": 10000,
     "enabled": true

+ 14 - 1
start.ps1

@@ -28,7 +28,20 @@ $EnvExample = Join-Path $Root  ".env.example"
 function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
 function Write-OK($msg)   { Write-Host "    [OK] $msg" -ForegroundColor Green }
 function Write-Warn($msg) { Write-Host "    [!!] $msg" -ForegroundColor Yellow }
-function Write-Fail($msg) { Write-Host "`n[FAIL] $msg" -ForegroundColor Red; exit 1 }
+function Write-Fail($msg) {
+    Write-Host "`n[FAIL] $msg" -ForegroundColor Red
+    Write-Host "`n  Press Enter to close..." -ForegroundColor DarkGray
+    $null = Read-Host
+    exit 1
+}
+
+# Catch any unhandled terminating error — keep window open so user can read it
+trap {
+    Write-Host "`n[ERROR] $_" -ForegroundColor Red
+    Write-Host "`n  Press Enter to close..." -ForegroundColor DarkGray
+    $null = Read-Host
+    exit 1
+}
 function Get-EnvPort($key, $default) {
     if (Test-Path $EnvFile) {
         $line = Get-Content $EnvFile | Select-String "^$key=(\d+)"

+ 13 - 1
update.ps1

@@ -19,7 +19,19 @@ $EnvFile = Join-Path $Root ".env"
 function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
 function Write-OK($msg)   { Write-Host "    [OK] $msg" -ForegroundColor Green }
 function Write-Warn($msg) { Write-Host "    [!!] $msg" -ForegroundColor Yellow }
-function Write-Fail($msg) { Write-Host "`n[FAIL] $msg" -ForegroundColor Red; exit 1 }
+function Write-Fail($msg) {
+    Write-Host "`n[FAIL] $msg" -ForegroundColor Red
+    Write-Host "`n  Press Enter to close..." -ForegroundColor DarkGray
+    $null = Read-Host
+    exit 1
+}
+
+trap {
+    Write-Host "`n[ERROR] $_" -ForegroundColor Red
+    Write-Host "`n  Press Enter to close..." -ForegroundColor DarkGray
+    $null = Read-Host
+    exit 1
+}
 
 
 # -- 1. Git pull ---------------------------------------------------------------