Skip to content

Update/stream detectorparameters to frontend during auto#276

Open
gokugiant wants to merge 18 commits into
masterfrom
update/stream_detectorparameters_to_frontend_during_auto
Open

Update/stream detectorparameters to frontend during auto#276
gokugiant wants to merge 18 commits into
masterfrom
update/stream_detectorparameters_to_frontend_during_auto

Conversation

@gokugiant
Copy link
Copy Markdown
Contributor

This pull request refactors the detector parameters UI to use Redux state and real-time WebSocket updates, providing a more responsive and robust experience. The component now updates immediately when the backend changes detector parameters (such as in auto mode), and the UI is improved with more intuitive controls and tooltips. A new Redux slice manages detector parameters, and the WebSocket middleware is updated to handle parameter updates from the backend.

State management and real-time updates:

  • Migrated detector parameter state from local React state to Redux, using a new DetectorParametersSlice to manage parameters and synchronize with backend changes via WebSocket events. (frontend/src/components/DetectorParameters.js, frontend/src/state/slices/DetectorParametersSlice.js) [1] [2]
  • Updated WebSocket middleware to handle sigDetectorParametersUpdated events, normalizing and updating detector parameters in Redux when they change on the backend. (frontend/src/middleware/WebSocketHandler.js) [1] [2]

UI/UX improvements:

  • Redesigned the detector parameters UI to use grid layouts, add increment/decrement buttons for numeric fields, and provide tooltips and info icons for better usability and clarity. (frontend/src/components/DetectorParameters.js) [1] [2] [3]
  • Added an "Auto once" button for single-pass auto-exposure, with proper disabling and loading feedback. (frontend/src/components/DetectorParameters.js)

Code quality and maintainability:

  • Refactored event handlers to immediately update Redux state and backend on user input, and to sync local UI fields with Redux state only when not being edited. (frontend/src/components/DetectorParameters.js) [1] [2]

These changes make detector parameter handling more robust, real-time, and user-friendly.

gokugiant added 14 commits May 12, 2026 14:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR streams detector parameter changes from the backend to the frontend in real time so that auto-mode adjustments (exposure/gain) are reflected in the UI without polling. On the backend, SettingsController now periodically snapshots and emits detector parameters via a new sigDetectorParametersUpdated signal on CommunicationChannel, adds a "set exposure once" API, and tightens parameter access (getParameter fixes, Picamera2 live metadata reads, Hik refactor). On the frontend, a new DetectorParametersSlice holds parameters in Redux, the WebSocket middleware dispatches updates, and DetectorParameters.js is rewritten with grid layout, ▲/▼ steppers, an "Auto once" button, and immediate-write inputs.

Changes:

  • Add real-time detector-parameter streaming pipeline (backend Signal/Timer → WebSocket → Redux slice → React component).
  • Refactor Picamera2 / Hik getPropertyValue and detector-manager getParameter checks; add setDetectorExposureOnce API.
  • Redesign the Detector Parameters UI (grid layout, steppers, tooltips, "Auto once" button) and switch from local React state to Redux.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
imswitch/imcontrol/model/managers/detectors/Picamera2Manager.py Fixes broken name not in self._parameters check to use the public parameters property.
imswitch/imcontrol/model/managers/detectors/HikCamManager.py Same fix as above for the Hik manager.
imswitch/imcontrol/model/managers/detectors/DetectorManager.py Excludes exposure_mode from the legacy posure → exposure rename.
imswitch/imcontrol/model/interfaces/picamera2_interface.py Reads live ExposureTime/AnalogueGain via capture_metadata() for exposure/gain queries.
imswitch/imcontrol/model/interfaces/hikcamera.py Rewrites getPropertyValue to return per-property typed values and proper int reads for width/height.
imswitch/imcontrol/controller/controllers/SettingsController.py Adds Timer-driven parameter broadcasting, setDetectorExposureOnce, and a more flexible setDetectorMode.
imswitch/imcontrol/controller/CommunicationChannel.py Declares the new sigDetectorParametersUpdated signal.
frontend/src/state/slices/DetectorParametersSlice.js New Redux slice holding detector parameters with normalize/update reducers.
frontend/src/state/store.js Registers the new slice in the root reducer.
frontend/src/middleware/WebSocketHandler.js Dispatches sigDetectorParametersUpdated events into the new slice.
frontend/src/components/DetectorParameters.js Redesigns UI, switches state to Redux, replaces blur-commit with immediate writes, adds "Auto once".
frontend/src/version.js, frontend/package.json, frontend/package-lock.json Bumps frontend version 1.6.4 → 1.6.5.
Files not reviewed (1)
  • frontend/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)

frontend/src/components/DetectorParameters.js:186

  • The comment "triggers onBlur → commitField" is now stale: commitField was removed in this PR and the TextFields no longer have an onBlur handler. Pressing Enter only blurs the field with no further effect. Either remove this helper (it has no functional purpose now) or update the comment and wire it to actually commit.
  // Helper: handle Enter key to commit
  const handleKeyDown = (field, localValue) => (e) => {
    if (e.key === "Enter") {
      e.target.blur(); // triggers onBlur → commitField
    }
  };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/components/DetectorParameters.js
Comment thread frontend/src/components/DetectorParameters.js
Comment thread imswitch/imcontrol/model/interfaces/picamera2_interface.py Outdated
Comment thread imswitch/imcontrol/model/interfaces/picamera2_interface.py Outdated
Comment thread imswitch/imcontrol/model/interfaces/hikcamera.py Outdated
state.isLoading = action.payload;
},
resetState: (state) => {
return initialDetectorParametersState;
),
storageState: storageReducer,
goniometerState: goniometerReducer,
detectorParametersState: detectorParametersReducer,
Comment on lines +888 to +896
const parametersUpdate = dataJson.args?.p0 || dataJson.args || {};
// Extract parameters from the update
const { detectorName, parameters } = parametersUpdate;
if (parameters) {
dispatch(detectorParametersSlice.normalizeParameters(parameters));
if (detectorName) {
dispatch(
detectorParametersSlice.setCurrentDetectorName(detectorName),
);
Comment on lines +168 to +177
const handleAutoExposureOnce = useCallback(async () => {
setAutoOncePending(true);
try {
await fetch(
`${hostIP}:${hostPort}/imswitch/api/SettingsController/setDetectorExposureOnce`,
);
} catch (error) {
console.error("Error running one-shot exposure auto:", error);
} finally {
setAutoOncePending(false);
Comment thread imswitch/imcontrol/model/interfaces/hikcamera.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants