20 October, 2013

17 October, 2013

libpebble on debian

Getting my pebble talking to my linux laptop took a while - mostly because I didn't know much about the linux bluetooth stack.

I'm running all this as root. I might eventually figure out how to do it as a normal user.

Can we see the pebble at all? This doesn't always show the pebble to me - i think because its not waiting long enough for the pebble to be active on bluetooth.

# hcitool scan
Scanning ...
        00:18:2F:CC:EC:A9       Pebble ECA9

In one window:

# bluez-simple-agent
Agent registered

In another window:

# l2ping 00:18:2f:cc:ec:a9
Ping: 00:18:2f:cc:ec:a9 from E0:06:E6:BA:33:AB (data size 44) ...
44 bytes from 00:18:2f:cc:ec:a9 id 0 time 8.54ms
Send failed: Connection reset by peer
It gives that connect reset message every time I try this ping... but carry on anyway.
# rfcomm bind 0 00:18:2f:cc:ec:a9
next:
./p.py --pebble_id ECA9 ping
will make the pebble buzz and show a ping message on screen.

Now run as many p.py commands as you like.

At some point when I did this previously, it got a persistent pairing with the pebble - I have no idea where in my hacking around the persistent pairing happened as at one stage I had to do it for every interaction...

14 October, 2013

list monad character to html entity encoding

This isn't particularly fancy, but it struck me as interesting from the "trying to abstract more" perspective.

Given a string with some funny characters in them, change the characters into HTML entities.

Here's a puffing-out function that given a character c :: Char returns a string (a list of characters, [Char]) for it to be replaced with. In the default case, the returned list contains only the original character.

generalPuffer c = case c of 
  c | ord c == 163 -> "£"
  c | ord c == 174 -> "®"
  c | ord c == 153 -> "™"
  c | ord c == 188 -> "¼"
  c | ord c > 128 -> error $ "unknown high character code " ++ (show $ ord c) ++ " encountered."
  c -> [c]

So how to use this? concatMap will handle this, and that was my first implementation (after fusing map and concat in my head).

concatMap f "£1 Shop™"
but concatMap is monadic bind, restricted to the list monad...

So equivalently you could write:

"£1 Shop™" >>= f
or
f =<< "£1 Shop™"
or
 do { l <- "£1 Shop™" ; c l }