feat(xrayeye): add pixel clock slider; fix exposure slider's physical bound
Adds a "Pixel clock" slider (MHz) below the exposure-time slider, bounded to the device's pixel_clock_min/max -- previously that control was script-only via IDSCamera.set_pixel_clock(). Needed because the exposure slider's max is bounded by the current pixel clock, and operators hitting that ceiling need a way to raise it from the GUI. Also fixes the exposure-time slider allowing a literal 0 ms: its bounds were rounded to nearest tenth-of-a-ms, which could round a small nonzero hardware minimum down to 0. Now rounds the min up (ceil, clamped to >= 1) and the max down (floor) instead, so the slider never claims a bound the hardware won't actually accept. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PYQTHuSxSaLCijvayoRkX5
This commit is contained in:
1 parent
9a999bed37
commit
69ad5135a9
1 file changed
+54
-6
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
|
||||
import pyqtgraph as pg
|
||||
from bec_lib import bec_logger
|
||||
from bec_lib.endpoints import MessageEndpoints
|
||||
@@ -446,7 +448,10 @@ class OMNY_XRayEye(BECWidget, QWidget):
|
||||
# resolution on the display label.
|
||||
self.exposure_time_label = QLabel("Exposure time", parent=self)
|
||||
self.exposure_time_slider = QSlider(Qt.Orientation.Horizontal, parent=self)
|
||||
self.exposure_time_slider.setRange(0, 10000) # placeholder; reseeded on connect
|
||||
# Placeholder until reseeded from hardware on connect (see
|
||||
# getting_camera_status()) -- minimum is 1 (0.1 ms), never 0, since
|
||||
# 0 ms exposure isn't physical.
|
||||
self.exposure_time_slider.setRange(1, 10000)
|
||||
self.exposure_time_slider.setEnabled(False) # auto-exposure starts enabled
|
||||
self.exposure_time_value_label = QLabel("-- ms", parent=self)
|
||||
self.exposure_time_value_label.setMinimumWidth(60)
|
||||
@@ -461,6 +466,21 @@ class OMNY_XRayEye(BECWidget, QWidget):
|
||||
exposure_grid.addWidget(self.exposure_time_slider, 1, 2, 1, 2)
|
||||
exposure_grid.addWidget(self.exposure_time_value_label, 1, 4, Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
# Pixel clock (MHz): lowering it raises the max achievable exposure
|
||||
# time (at the cost of frame rate) -- exposed here since operators
|
||||
# hitting the exposure slider's ceiling need this knob to go further.
|
||||
self.pixel_clock_label = QLabel("Pixel clock", parent=self)
|
||||
self.pixel_clock_slider = QSlider(Qt.Orientation.Horizontal, parent=self)
|
||||
self.pixel_clock_slider.setRange(1, 100) # MHz; placeholder, reseeded on connect
|
||||
self.pixel_clock_value_label = QLabel("-- MHz", parent=self)
|
||||
self.pixel_clock_value_label.setMinimumWidth(60)
|
||||
self.pixel_clock_slider.valueChanged.connect(self._update_pixel_clock_value_label)
|
||||
self.pixel_clock_slider.sliderReleased.connect(self.pixel_clock_submitted)
|
||||
|
||||
exposure_grid.addWidget(self.pixel_clock_label, 2, 1, _right_vcenter)
|
||||
exposure_grid.addWidget(self.pixel_clock_slider, 2, 2, 1, 2)
|
||||
exposure_grid.addWidget(self.pixel_clock_value_label, 2, 4, Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
self.control_panel_layout.addWidget(self.exposure_grid_widget)
|
||||
|
||||
# separator: below the exposure/gain section, above the alignment
|
||||
@@ -973,14 +993,36 @@ class OMNY_XRayEye(BECWidget, QWidget):
|
||||
self.auto_gain_toggle.checked = bool(auto_gain.get("value"))
|
||||
self.auto_gain_toggle.blockSignals(False)
|
||||
|
||||
# Reseed the slider's bounds first (rare -- only changes if the pixel
|
||||
# clock changed), so a value arriving in the same message is clamped
|
||||
# against up-to-date min/max rather than a stale range.
|
||||
# Reseed the pixel-clock slider's bounds/value before the exposure
|
||||
# ones below -- changing the pixel clock changes the exposure range,
|
||||
# and both arrive together in this same message.
|
||||
pixel_clock_min = signals.get(f"{CAMERA[0]}_pixel_clock_min")
|
||||
pixel_clock_max = signals.get(f"{CAMERA[0]}_pixel_clock_max")
|
||||
if pixel_clock_min is not None and pixel_clock_max is not None:
|
||||
lo = int(pixel_clock_min.get("value"))
|
||||
hi = int(pixel_clock_max.get("value"))
|
||||
if (lo, hi) != (self.pixel_clock_slider.minimum(), self.pixel_clock_slider.maximum()):
|
||||
self.pixel_clock_slider.setRange(lo, hi)
|
||||
|
||||
pixel_clock = signals.get(f"{CAMERA[0]}_pixel_clock")
|
||||
if pixel_clock is not None:
|
||||
self.pixel_clock_slider.blockSignals(True)
|
||||
self.pixel_clock_slider.setValue(int(pixel_clock.get("value")))
|
||||
self.pixel_clock_slider.blockSignals(False)
|
||||
self._update_pixel_clock_value_label(self.pixel_clock_slider.value())
|
||||
|
||||
# Reseed the exposure slider's bounds next (rare -- only changes if
|
||||
# the pixel clock changed), so a value arriving in the same message
|
||||
# is clamped against up-to-date min/max rather than a stale range.
|
||||
# Round the min UP and the max DOWN (never the other way) -- e.g. a
|
||||
# hardware min of 0.04 ms rounds to 0 in tenths-of-ms units, which
|
||||
# would let the slider claim 0 ms exposure is settable when it isn't;
|
||||
# ceil (clamped to at least 1) keeps the bound physical instead.
|
||||
exposure_min = signals.get(f"{CAMERA[0]}_exposure_time_min")
|
||||
exposure_max = signals.get(f"{CAMERA[0]}_exposure_time_max")
|
||||
if exposure_min is not None and exposure_max is not None:
|
||||
lo = round(float(exposure_min.get("value")) * self._EXPOSURE_SLIDER_SCALE)
|
||||
hi = round(float(exposure_max.get("value")) * self._EXPOSURE_SLIDER_SCALE)
|
||||
lo = max(1, math.ceil(float(exposure_min.get("value")) * self._EXPOSURE_SLIDER_SCALE))
|
||||
hi = math.floor(float(exposure_max.get("value")) * self._EXPOSURE_SLIDER_SCALE)
|
||||
if (lo, hi) != (self.exposure_time_slider.minimum(), self.exposure_time_slider.maximum()):
|
||||
self.exposure_time_slider.setRange(lo, hi)
|
||||
|
||||
@@ -1023,6 +1065,12 @@ class OMNY_XRayEye(BECWidget, QWidget):
|
||||
value_ms = self.exposure_time_slider.value() / self._EXPOSURE_SLIDER_SCALE
|
||||
self.dev.get(CAMERA[0]).exposure_time.put(value_ms)
|
||||
|
||||
def _update_pixel_clock_value_label(self, value: int):
|
||||
self.pixel_clock_value_label.setText(f"{value} MHz")
|
||||
|
||||
def pixel_clock_submitted(self):
|
||||
self.dev.get(CAMERA[0]).pixel_clock.put(self.pixel_clock_slider.value())
|
||||
|
||||
@SafeSlot(bool)
|
||||
def opening_shutter(self, enabled: bool):
|
||||
if self._manual_toggle_blocked_by_queue():
|
||||
|
||||
Reference in new issue
Block a user