Skip to content

Commit

Permalink
A workaround that make the code work on my machine.
Browse files Browse the repository at this point in the history
Otherwise, the key :digital-out in not populated and i got a NPE when i a call to digital-write.
  • Loading branch information
ardumont committed Jun 3, 2012
1 parent df01d9c commit 49e91f3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/clodiuno/firmata.clj
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,29 @@
(= (bit-and data 0xF0) ANALOG-MESSAGE) (let [pin (bit-and data 0x0F)
[_ _ val] (read-multibyte in)]
(assoc-in! conn [:analog pin] val))

(= (bit-and data 0xF0) DIGITAL-MESSAGE) (let [port (bit-and data 0x0F)
[lsb msb val] (read-multibyte in)]
(assoc-in! conn [:digital-in port] (bits val)))

(= 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})]

(doto port
(.addEventListener (listener #(process-input conn (.getInputStream (:port @conn)))))
(.notifyOnDataAvailable true))

(while (nil? (:version @conn))
(Thread/sleep 100))

(dotimes [i (count (keys (:digital-in @conn)))]
(assoc-in! conn [:digital-out i] (repeat 8 0)))

(update-digital-out! conn)

conn))

0 comments on commit 49e91f3

Please sign in to comment.