       (set (@state :init-system-state))
       (set (get-system-config-cached))))))
 
-(defn prepare []
-  (when (@state :init-continuous-focus)
-    (core enableContinuousFocus false)))
-
 (defn cleanup []
   (log "cleanup")
   (do-when #(.update %) (:display @state))

  (if (pos? (count stage)) (core getPosition stage) 0))
  
(defn set-z-stage-position [stage pos]
  (if (pos? (count stage)) (core setPosition stage pos)))

(defn set-stage-position
  ([stage-dev z] (log "setting z position to " z)
     (core setPosition stage-dev z)
     (state-assoc! :last-z-position z))
  ([stage-dev x y] (log "setting x,y position to " x "," y)
                   (when (and x y) (core setXYPosition stage-dev x y))))

  (while (and (:pause @state) (not (:stop @state))) (Thread/sleep 5)))

(defn interruptible-sleep [time-ms]
  (when (and (@state :init-continuous-focus)
             (not (core isContinuousFocusEnabled)))
    (core enableContinuousFocus true))
  (let [sleepy (CountDownLatch. 1)]
    (state-assoc! :sleepy sleepy :next-wake-time (+ (clock-ms) time-ms))
    (.await sleepy time-ms TimeUnit/MILLISECONDS)))
