Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Commits on Jun 03, 2012
@ardumont ardumont A workaround that make the code work on my machine.
Otherwise, the key :digital-out in not populated and i got a NPE when i a call to digital-write.
@ardumont ardumont Fix a problem on the opening of the conn to the board. e3b9656
Commits on Jun 04, 2012
@nakkaya Merge pull request #3 from ardumont/master
Wrapping of the code that initiates the :digital-out key
Showing with 19 additions and 15 deletions.
  1. +19 −15 src/clodiuno/firmata.clj
34 src/clodiuno/firmata.clj
@@ -4,8 +4,8 @@
:doc "Firmata Library for Clojure."}
(:use clodiuno.core)
(:import ( InputStream)
- ( SerialPort CommPortIdentifier
- SerialPortEventListener SerialPortEvent
+ ( SerialPort CommPortIdentifier
+ SerialPortEventListener SerialPortEvent
(def DIGITAL-MESSAGE 0x90) ;;send data for a digital port
@@ -26,7 +26,7 @@
;; Serial Setup
-(defn- port-identifier
+(defn- port-identifier
"Given a port name return its identifier."
@@ -37,7 +37,7 @@
port (recur (.nextElement ports) (.getName port)))))
(catch Exception e (throw (NoSuchPortException.)))))
-(defn- open
+(defn- open
"Open serial interface."
(doto (.open identifier "clojure" 1)
@@ -49,18 +49,18 @@
(defmethod close :firmata [conn]
(.close (:port @conn)))
-(defn- listener
+(defn- listener
"f will be called whenever there is data availible on the stream."
- (proxy [SerialPortEventListener] []
- (serialEvent
+ (proxy [SerialPortEventListener] []
+ (serialEvent
(if (= (.getEventType event) SerialPortEvent/DATA_AVAILABLE)
(defn- write-bytes [conn & bs]
(let [out (.getOutputStream (:port @conn))]
- (doseq [b bs]
+ (doseq [b bs]
(.write out b))
(.flush out)))
@@ -116,7 +116,7 @@
val (bit-or (bit-shift-left msb 7) lsb)]
[lsb msb val]))
-(defn- process-input
+(defn- process-input
"Parse input from firmata."
[conn in]
(while (> (.available in) 2)
@@ -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)

No commit comments for this range

Something went wrong with that request. Please try again.