Skip to content

Instantly share code, notes, and snippets.

@marxjohnson
Created January 7, 2012 14:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marxjohnson/1574863 to your computer and use it in GitHub Desktop.
Save marxjohnson/1574863 to your computer and use it in GitHub Desktop.
A script to detect and report Boogie Board Rip events on linux via USB
require 'rubygems'
require 'hex_string'
begin
lsusb = `lsusb`
if lsusb.split("\n").select{|l| l.include? "2047:ffe7"}.count == 0
raise "Boogie Board Rip not currently connected"
end
begin
dmesg = `dmesg`
bbdev = dmesg.split("\n").select{|l| l.match "2047:FFE7.*hidraw[0-9]"}.pop.match("(hidraw[0-9]+)").to_s
raise RuntimeError if bbdev.empty?
rescue NoMethodError, RuntimeError
raise "Boogie Board Rip detected, but device's path could not be determined"
end
events = []
threads = []
thread = Thread.new do
board = File.new("/dev/"+bbdev, 'r')
while true do
data = board.sysread(32)
events << data.to_hex_string.split(' ')
end
end
threads << thread
thread = Thread.new do
previous = Array.new(32, "00")
current = []
while true do
current = events.shift
next if current.nil?
if current[10] != previous[10]
state = current[10].hex
pstate = previous[10].hex
lock = 32
erase = 4
wake = 2
if (pstate == pstate | lock) && (state != state | lock)
puts "Board unlocked"
elsif (pstate != pstate | lock) && (state == state | lock)
puts "Board locked"
end
if (pstate == pstate | erase) && (state != state | erase)
puts "Erase released"
elsif (pstate != pstate | erase) && (state == state | erase)
puts "Erase Pressed"
end
if (pstate == pstate | wake) && (state != state | wake)
puts "Wake released"
elsif (pstate != pstate | wake) && (state == state | wake)
puts "Wake Pressed"
end
end
if current[3] != previous[3]
state = current[3].hex
pstate = previous[3].hex
detected = 32
contact = 1
if (pstate == pstate | detected) && (state != state | detected)
puts "Pen Lost"
elsif (pstate != pstate | detected) && (state == state | detected)
puts "Pen Detected"
end
if (pstate == pstate | contact) && (state != state | contact)
puts "Pen contact lost"
elsif (pstate != pstate | contact) && (state == state | contact)
puts "Pen contact detected"
end
end
cury = current[5]+current[4]
curx = current[7]+current[6]
prey = previous[5]+previous[4]
prex = previous[7]+previous[6]
if cury != prey || curx != prex
cury = cury.hex
curx = curx.hex
prey = prey.hex
prex = prex.hex
puts "Pen moved from ("+prex.to_s+","+prey.to_s+") to ("+curx.to_s+","+cury.to_s+")"
end
previous = current
end
end
threads << thread
threads.each{ |thread| thread.join}
rescue RuntimeError => error
puts error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment