Created
September 11, 2009 18:36
-
-
Save lwu/185488 to your computer and use it in GitHub Desktop.
Pressure-sensitive keyboard IO in Ruby (experimental MSFT hw!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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