Created
November 11, 2009 00:48
-
-
Save halfbyte/231451 to your computer and use it in GitHub Desktop.
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
require 'autotest/fsevent' | |
require 'autotest/growl' | |
require 'redgreen/autotest' | |
# sudo gem install portmidi term_ansicolor | |
require 'launchpad/device' | |
require 'term/ansicolor' | |
include Term::ANSIColor | |
begin | |
Portmidi.start | |
device = Launchpad::Device.new(:input => false) | |
device.reset | |
device.flashing_auto | |
Autotest.add_hook :run_command do |at| | |
device.reset | |
device.flashing_auto | |
device.change(:grid, :x => 0, :y => 0, :red => :high, :green => :high, :mode => :flashing) | |
#return true | |
end | |
Autotest.add_hook :ran_command do |at| | |
resultstring = at.results.map{|line| uncolored(line)}.select { |line| line.strip.match(/^[\.FE]+$/) }.map{|line| line.strip } | |
i = 0; | |
device.reset | |
device.flashing_auto | |
device.change(:grid, :x => 0, :y => 0, :red => :low, :green => :low, :mode => :normal) | |
resultstring.first.each_char do |char| | |
color = case(char) | |
when "." | |
nil | |
when "F" | |
{:green => :off, :red => :high, :mode => :normal } | |
when "E" | |
{:green => :off, :red => :high, :mode => :flashing } | |
else | |
{:green => :high, :red => :high, :mode => :flashing } | |
end | |
begin | |
if (i < 64 && color) | |
device.change(:grid, {:x => (i % 8), :y => (i/8)}.merge(color)) | |
i += 1 | |
end | |
rescue => e | |
puts e | |
end | |
end | |
if (i == 0) #all tests green | |
device.change(:grid, :x => 0, :y => 0, :red => :off, :green => :high, :mode => :normal) | |
end | |
#return true | |
end | |
rescue => e | |
puts "sorry, no Launchpad available" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment