Skip to content

Commit

Permalink
manually populate digital in/out ports
Browse files Browse the repository at this point in the history
  • Loading branch information
nakkaya committed Jun 4, 2012
1 parent a8119da commit d37e004
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/clodiuno/firmata.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
(def END-SYSEX 0xF7) ;;end a MIDI SysEx message
(def baudrate 57600)

(def arduino-port-count 7)

(defn- byte [v]
(.byteValue (- v 256)))

Expand Down Expand Up @@ -132,11 +134,6 @@

(= data REPORT-VERSION) (assoc-in! conn [:version] [(.read in) (.read in)])))))

(defn- update-digital-out! "Workaround because else the digital-out is not populated."
[conn]
(dotimes [i (count (keys (:digital-in @conn)))]
(assoc-in! conn [:digital-out i] (repeat 8 0))))

(defmethod arduino :firmata [type port]
(let [port (open (port-identifier port))
conn (ref {:port port :interface :firmata})]
Expand All @@ -148,6 +145,10 @@
(while (nil? (:version @conn))
(Thread/sleep 100))

(update-digital-out! conn)
(dotimes [i arduino-port-count]
(assoc-in! conn [:digital-out i] (repeat 8 0)))

(dotimes [i arduino-port-count]
(assoc-in! conn [:digital-in i] (repeat 8 0)))

conn))

0 comments on commit d37e004

Please sign in to comment.