<commit_before>(ns org.playasophy.wonderdome.display.pixel-pusher
  (:require
    [com.stuartsierra.component :as component]
    [org.playasophy.wonderdome.display.core :as display])
  #_
  (:import
    [com.heroicrobot.dropbit.registry *]
    com.heroicrobot.dropbit.devices.pixelpusher.Strip))


;;;;; WONDERDOME DISPLAY ;;;;;

(defrecord PixelPusherDisplay
  [registry strips running])

(extend-type PixelPusherDisplay
  component/Lifecycle

  (start
    [this]
    (println "Starting PixelPusher display...")
    ; TODO: add device observer
    (assoc this :running true))


  (stop
    [this]
    (println "Stopping PixelPusher display...")
    ; TODO: clear strips, remove device observer?
    (assoc this :running false))


  display/Display

  (set-colors!
    [this colors]
    ; TODO: implementation
    nil))


(defn pixel-pusher-display
  "Creates a new display streaming color commands to connected pixel-pusher
  hardware."
  ([registry]
   (PixelPusherDisplay. registry (atom []) false)))<commit_msg>Flesh out pixel-pusher display a bit more.<commit_after>(ns org.playasophy.wonderdome.display.pixel-pusher
  (:require
    [com.stuartsierra.component :as component]
    [org.playasophy.wonderdome.display.core :as display])
  (:import
    #_
    (com.heroicrobot.dropbit.devices.pixelpusher
      Strip)
    #_
    (com.heroicrobot.dropbit.registry
      DeviceRegistry)))


;;;;; CONFIGURATION ;;;;;

; Suppress spurious log output.
#_
(->
  DeviceRegistry
  .getName
  java.util.logging.Logger/getLogger
  (.setLevel java.util.logger.Level/WARNING))


(defn- registry-observer
  "Constructs a new callback function which will update the strips in the given
  atom when the device registry changes."
  [registry strips]
  (reify java.util.Observer
    (update [this target device]
      (let [new-strips (vec (.getStrips registry))]
        (println "Updated device:" device (str "(" (count new-strips) " strips)"))
        (reset! strips new-strips)))))



;;;;; PIXEL PUSHER DISPLAY ;;;;;

(defrecord PixelPusherDisplay
  [registry strips running]

  component/Lifecycle

  (start
    [this]
    (println "Starting PixelPusher display...")
    (doto registry
      (.addObserver (registry-observer registry strips))
      (.startPushing)
      (.setExtraDelay 0)
      (.setAutoThrottle true))
    (assoc this :running true))


  (stop
    [this]
    (println "Stopping PixelPusher display...")
    ; TODO: clear strips, remove device observer?
    (.stopPushing registry)
    (assoc this :running false))


  display/Display

  (set-colors!
    [this colors]
    ; TODO: implementation
    nil))


(defn pixel-pusher
  "Creates a new display streaming color commands to connected pixel-pusher
  hardware."
  [registry]
  (PixelPusherDisplay. registry (atom []) false))
{'fraction_non_alphanumeric': 0.11876569788302835, 'fraction_numerical': 0.0003588087549336204, 'mean_word_length': 3.4183835182250397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3015076', 'n_tokens_mistral': 923, 'n_tokens_neox': 880, 'n_words': 224}