Update/stream detectorparameters to frontend during auto#276
Update/stream detectorparameters to frontend during auto#276gokugiant wants to merge 18 commits into
Conversation
…and Redux state management
…end updates during auto adjustments
…dling and metadata access
…dates and improved UI controls
…ock.json, and version.js
There was a problem hiding this comment.
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
getPropertyValueand detector-managergetParameterchecks; addsetDetectorExposureOnceAPI. - 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:
commitFieldwas removed in this PR and the TextFields no longer have anonBlurhandler. 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.
| state.isLoading = action.payload; | ||
| }, | ||
| resetState: (state) => { | ||
| return initialDetectorParametersState; |
| ), | ||
| storageState: storageReducer, | ||
| goniometerState: goniometerReducer, | ||
| detectorParametersState: detectorParametersReducer, |
| 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), | ||
| ); |
| 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); |
…with improved editing state management
…ead of False for better consistency
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:
DetectorParametersSliceto manage parameters and synchronize with backend changes via WebSocket events. (frontend/src/components/DetectorParameters.js,frontend/src/state/slices/DetectorParametersSlice.js) [1] [2]sigDetectorParametersUpdatedevents, normalizing and updating detector parameters in Redux when they change on the backend. (frontend/src/middleware/WebSocketHandler.js) [1] [2]UI/UX improvements:
frontend/src/components/DetectorParameters.js) [1] [2] [3]frontend/src/components/DetectorParameters.js)Code quality and maintainability:
frontend/src/components/DetectorParameters.js) [1] [2]These changes make detector parameter handling more robust, real-time, and user-friendly.