 
 ;; hardware control
 
+(defn set-exposure [camera exp]
+  (when (not= exp (get-in @state [camera :exposures]))
+    (device-best-effort (core setExposure exp))
+    (swap! state assoc-in [camera :exposures] exp)))
+
 (defn wait-for-device [dev]
   (when-not (empty? dev)
     (try

      :reference-z z
      :start-time (jvm-time-ms)
      :init-auto-shutter (core getAutoShutter)
      :init-exposure (core getExposure)
      :default-z-drive default-z-drive
      :default-xy-stage default-xy-stage
      :init-z-position z


(defn cleanup []
  (try
    (log "cleanup")
    ; (do-when #(.update %) (:display @state))
    (state-assoc! :finished true :display nil)
    (when (core isSequenceRunning)
      (core stopSequenceAcquisition))
    (stop-trigger)
    (core setAutoShutter (@state :init-auto-shutter))
    (core set-exposure (core getCameraDevice) (@state :init-exposure))
    (set-stage-position (@state :default-z-drive) (@state :init-z-position))
    (when (and (@state :init-continuous-focus)
               (not (core isContinuousFocusEnabled)))
      (core enableContinuousFocus true))
    (return-config)
    (catch Throwable t (ReportingUtils/showError t "Acquisition cleanup failed."))))

;; running events
