Skip to content

Misc fixes - #11

Merged
marktsuchida merged 3 commits into
mainfrom
misc-fixes
Sep 25, 2026
Merged

marktsuchida merged 3 commits into
mainfrom
misc-fixes

Conversation

@marktsuchida

Copy link
Copy Markdown
Owner

Thread safety, resource cleanup bugs.
Also make the origin marker 4x smaller so that it fits in the frame at 100x.

- Hub pointer: Initialize() now stores the parent hub once in hub_ and
  returns DEVICE_COMM_HUB_MISSING if there isn't one. Nothing calls
  GetParentHub() per frame any more.
- Settings lock: a new settingsMutex_ guards exposure, ROI and Mode in
  their getters, setters and the Mode property handler.
- Settings during a sequence: each frame takes a copy of the settings
  when it starts, so exposure and Mode changes apply from the next
  frame. The frame interval follows that frame's exposure, and
  InsertImage gets that frame's width and height.
- ROI and snaps while capturing: SetROI and SnapImage both return
  DEVICE_CAMERA_BUSY_ACQUIRING during a sequence.
- Rendering moved out: the frame rendering now lives in
  GenerateFrame(const FrameSettings &), which doesn't sleep. SnapImage()
  calls it and then sleeps for the exposure; the sequence thread calls
  it from RunSequence().
- Capture state: a new std::atomic<bool> capturing_ backs IsCapturing().
  The thread clears it after AcqFinished, so snaps and new sequences
  work after a finite sequence ends on its own. StartSequenceAcquisition
  cleans up the finished thread before starting a new one.
- Stopping: stop now interrupts the exposure wait and throws away the
  frame in progress. StopSequenceAcquisition() always cleans up the
  thread. Shutdown() and a new destructor both call it.

(Assisted by Claude Code; any errors are mine.)
- SimHub.h: a new mutex mut_ guards the five functions the peripherals
  register. Setting a function takes the lock, and each getter holds it
  while calling the function. A short comment explains why: a
  peripheral's Shutdown() can't return while the camera is still calling
  into it.
- All four peripherals: each stores hub_ at the start of Initialize()
  and returns DEVICE_COMM_HUB_MISSING if there's no hub. Shutdown()
  resets the hub function and clears hub_ only if it was set. In the
  shutter and turret this replaces the initialized_ flag, which is gone.
- SimObjectiveTurret.h: state_ is now a std::atomic<long>, with .load()
  in the hub functions and OnState. The cast in GetNumberOfPositions()
  is fixed to unsigned long.
- SimFocus.h / SimXY.h:
  - model_ is now declared last, so it is destroyed first and its slew
    thread stops before the members it uses go away. A comment says so.
  - if (ProcModel::isAsync) in Initialize() is now if constexpr.
  - The constructor's ReciprocalSlewRateSeconds call is wrapped in if
    constexpr too.
- ProcessModel.h:
  - Halt() and Setpoint(value) now write setpoint_ under mut_.
  - Setpoint() compares against the parameter.
  - The header comment now says which functions can be called from any
    thread and which need outside locking.

(Assisted by Claude Code; any errors are mine.)
Fit in frame at 100x.

(Assisted by Claude Code; any errors are mine.)
@marktsuchida
marktsuchida merged commit 0b27b2a into main Sep 25, 2026
6 checks passed
@marktsuchida
marktsuchida deleted the misc-fixes branch September 25, 2026 22:37
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.

1 participant