 
 (declare device-agents)
 
+(defn wait-for-device [dev]
+  (when (and dev (pos? (.length dev)))
+    (core waitForDevice dev)))
+
 (defn create-device-agents []
   (def device-agents
     (let [devs (seq (core getLoadedDevices))]

            (let [z (compute-z-position event)]
              (when (not= z (@state :last-z-position))
                (do (set-stage-position z-drive z)
                    (core waitForDevice z-drive)))))
          #(do (expose event)
               (collect-image event out-queue))))))


      (doall (map (partial await-for 10000) (vals device-agents))))
    (do
      (doseq [[dev action] action-map]
        (action) (wait-for-device dev)))))

(defn run-autofocus []
  (.. gui getAutofocusManager getDevice fullFocus)
