Skip to content

Instantly share code, notes, and snippets.

@lwu
Created September 11, 2009 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwu/185488 to your computer and use it in GitHub Desktop.
Save lwu/185488 to your computer and use it in GitHub Desktop.
Pressure-sensitive keyboard IO in Ruby (experimental MSFT hw!)
#!/usr/bin/env ruby
#
# Pressure-sensitive keyboard IO in Ruby (experimental MSFT hw!)
%w(rubygems serialport).each { |lib| require lib } # sudo gem install serialport pls
ser = SerialPort.new("/dev/tty.usbserial-A6007kA6", 115200, 8, 1, SerialPort::NONE)
ser.write("q") # initiate continuous ASCII mode
while true
line = ''
until (line =~ /\n/) do line += ser.getc.chr end
next unless line =~ /^\(/ # ignore lines that don't start with '('
row, col, pressure = *(line.scan /\d+/).map { |x| x.to_i } # parse out 3 numbers
print line
end
ser.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment