Permalink
Browse files

can check whether device/interaction are closed

  • Loading branch information...
1 parent 706738e commit aa0802270a96ff4eaa19e506b04369a75410a12f Thomas Jachmann committed Nov 13, 2009
Showing with 49 additions and 1 deletion.
  1. +0 −1 README.rdoc
  2. +5 −0 lib/launchpad/device.rb
  3. +6 −0 lib/launchpad/interaction.rb
  4. +4 −0 test/helper.rb
  5. +23 −0 test/test_device.rb
  6. +11 −0 test/test_interaction.rb
View
@@ -62,7 +62,6 @@ For more details, see the examples. examples/color_picker.rb is the most complex
== Near future plans
-* close devices properly
* interaction responses for presses on single grid buttons/button areas
* double buffering
* bitmap rendering
View
@@ -55,6 +55,11 @@ def close
@output = nil
end
+ # Determines whether this device has been closed
+ def closed?
+ @input.nil? && @output.nil?
+ end
+
# Resets the launchpad - all settings are reset and all LEDs are switched off
def reset
output(Status::CC, Status::NIL, Status::NIL)
@@ -31,10 +31,16 @@ def start
raise CommunicationError.new(e)
end
+ # Closes the interaction's device - nothing can be done with the interaction/device afterwards
def close
@device.close
end
+ # Determines whether this interaction's device has been closed
+ def closed?
+ @device.closed?
+ end
+
# Stops interacting with the launchpad
def stop
@active = false
View
@@ -24,13 +24,17 @@ class Input
def initialize(device_id)
self.device_id = device_id
end
+ def read(*args); nil; end
+ def close; nil; end
end
class Output
attr_accessor :device_id
def initialize(device_id)
self.device_id = device_id
end
+ def write(*args); nil; end
+ def close; nil; end
end
def self.input_devices; mock_devices; end
View
@@ -143,6 +143,29 @@ def stub_input(device, *args)
end
+ context 'closed?' do
+
+ should 'return true when neither input nor output are there' do
+ assert Launchpad::Device.new(:input => false, :output => false).closed?
+ end
+
+ should 'return false when initialized with input' do
+ assert !Launchpad::Device.new(:input => true, :output => false).closed?
+ end
+
+ should 'return false when initialized with output' do
+ assert !Launchpad::Device.new(:input => false, :output => true).closed?
+ end
+
+ should 'return false when initialized with both but true after calling close' do
+ d = Launchpad::Device.new
+ assert !d.closed?
+ d.close
+ assert d.closed?
+ end
+
+ end
+
{
:reset => [0xB0, 0x00, 0x00],
:flashing_on => [0xB0, 0x00, 0x20],
View
@@ -44,6 +44,17 @@ class TestInteraction < Test::Unit::TestCase
end
+ context 'closed?' do
+
+ should 'return false on a newly created interaction, but true after closing' do
+ interaction = Launchpad::Interaction.new
+ assert !interaction.closed?
+ interaction.close
+ assert interaction.closed?
+ end
+
+ end
+
context 'start' do
# this is kinda greybox tested, since I couldn't come up with another way to test a loop [thomas, 2009-11-11]

0 comments on commit aa08022

Please sign in to comment.