 
 ;; globals
 
-(def ^:dynamic state (atom {:stop false}))
+(def ^:dynamic state nil)
 
 (def attached-runnables (atom (vec nil)))
 

    (annotate-image image event @state time-stamp)))

(defn produce-burst-images
  "Pops images from circular buffer and sends them to output queue."
  [burst-events camera-channel-names timeout-ms out-queue]
  (let [total (* (count burst-events)
                 (count camera-channel-names))
        camera-index-tag (str (. mmc getCameraDevice) "-CameraChannelIndex")
        image-number-offset (if (first-trigger-missing?) -1 0)
        image-queue (pop-burst-images total timeout-ms)]
    (doseq [_ (range total) :while (not (@state :stop))]
      (.put out-queue
            (-> (.take image-queue)
                (tag-burst-image burst-events camera-channel-names camera-index-tag


(defn run [this settings cleanup?]
  (def last-acq this)
  (def last-state (.state this))
    (reset! (.state this) {:stop false :pause false :finished false})
    (let [out-queue (LinkedBlockingQueue. 10)
          acq-thread (Thread. #(binding [state (.state this)]
