Thanks, Karsten, useful links!

As it happens I managed to get it working on 64-bit Windows last night 
using Sam's regular serial-port. 

Code here for anyone interested:

https://github.com/mikera/motion-sensor/blob/develop/src/main/clojure/mikera/sensor/core.clj

Interestingly, I found a nice way to batch up a series of individual bytes 
arriving on the COM port into complete Bluetooth LE messages using 
core.async. I'd be interested in any comments from core.async experts on 
whether I'm doing this correctly but it seems to work:

(defn ble-messages 
  "Creates a Bluetooth LE listener channel that reads bytes from a channel c
   and returns a new value when the message is complete"
  ([c]
    (let [result-chan (chan)]
      (go (loop []
            (let [eb (<! c)]  ;; Type, expected to be 0x04 (Event)
              (when-not (== 0x04 eb) (println (str "Unknown byte: " 
(hex/hex-string eb))) (recur))
              (let [ec (<! c) ;; Event code, typically 0xFF 
(HCI_LE_ExtEvent)
                    elen (<! c)  ;; Event data length in bytes
                    ^bytes res (byte-array (+ 3 elen))]
                (aset res 0 (unchecked-byte eb))
                (aset res 1 (unchecked-byte ec))
                (aset res 2 (unchecked-byte elen))
                (dotimes [i elen]
                  (aset res (+ i 3) (unchecked-byte (<! c))))
                (>! result-chan res)
                (recur)))))
      result-chan)))

On Tuesday, 22 October 2013 05:42:50 UTC+8, Karsten Schmidt wrote:
>
> IIRC Sam's wrapper is using the original RXTX lib which hasn't been 
> updated since ~2006 and is only 32bits. There're a couple of more 
> recent forks (w/ x-platform 64bit binaries), most notable the one by 
> CMU's Robotics dept: 
>
>
> https://code.google.com/p/create-lab-commons/source/browse/#svn%2Ftrunk%2Fjava%2Flib%2Frxtx
>  
>
> It shouldn't be too hard to bundle these up and do a Clojure wrapper... 
>
> Alternatively, if you're targeting Android, you'll get API access from 
> 4.3 onwards: 
> http://developer.android.com/guide/topics/connectivity/bluetooth-le.html 
>
> Hth! K. 
>
> On 21 October 2013 09:07, Mikera <mike.r.an...@gmail.com <javascript:>> 
> wrote: 
> > Hi all, 
> > 
> > I'm doing some experiments with Bluetooth LE sensors using Clojure. Fun 
> > stuff. 
> > 
> > The library ecosystem seems a bit sparse though (both in the Clojure and 
> > Java space). Currently I'm thinking of hacking together a quick 
> > communications stack using Sam Aarons nice little serial-port library 
> > (https://github.com/samaaron/serial-port) but I'm hoping there may be a 
> > better way. Seems like an interesting use case for core.async in 
> particular. 
> > 
> > Has anyone else tries this / discovered any good resources? 
> > 
> >    Mike. 
> > 
> > -- 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@googlegroups.com<javascript:> 
> > Note that posts from new members are moderated - please be patient with 
> your 
> > first post. 
> > To unsubscribe from this group, send email to 
> > clojure+u...@googlegroups.com <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/clojure?hl=en 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Clojure" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to clojure+u...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>
>
>
> -- 
> Karsten Schmidt 
> http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk 
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to