 
 
 (defn- repeat-events
-  "Builds a function which will repeatedly fire events every period ms if their
-  value differs from the default given."
-  [defaults period]
-  ; TODO: implement repeat events function
-  ; probably store 'last repeat time' in an atom
-  (constantly nil))
+  "Calculates repeated button 'hold' events, where the value differs from some
+  default value. Sends an event with the button and the elapsed ms it has been
+  pressed for."
+  [defaults state elapsed]
+  (for [[button default] defaults]
+    (let [value (get state button)]
+      (when (and (some? value) (not= value default))
+        {:type :gamepad/repeat
+         :button button
+         :value value
+         :elapsed elapsed}))))
 
 
 



(defn- button-events
  "Determines button press and release events from old and new state maps.
  Returns a seq of button events."
  [buttons old-state new-state]
  (for [button buttons]
    (let [old-val (get old-state button)


(defn- snes-state-events
  [old-state new-state elapsed]
  (let [axes {:x-axis 0.0, :y-axis 0.0}
        buttons (remove (keys axes) (keys new-state))]
    (remove nil?
      (concat
        (repeat-events axes old-state elapsed)
        (button-events buttons old-state new-state)))))


(defn snes
