minilab 1.0.0-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. data/.document +2 -0
  2. data/CHANGES +2 -0
  3. data/LICENSE +19 -0
  4. data/README +107 -0
  5. data/Rakefile +145 -0
  6. data/config/environment.rb +15 -0
  7. data/config/objects.yml +22 -0
  8. data/lib/analog_io.rb +30 -0
  9. data/lib/digital_auxport_io.rb +49 -0
  10. data/lib/digital_configuration.rb +66 -0
  11. data/lib/digital_port_io.rb +68 -0
  12. data/lib/extension/extconf.rb +4 -0
  13. data/lib/extension/minilab_hardware.c +235 -0
  14. data/lib/extension/minilab_hardware.so +0 -0
  15. data/lib/library_translator.rb +48 -0
  16. data/lib/minilab.rb +149 -0
  17. data/lib/minilab_context.rb +39 -0
  18. data/lib/result_verifier.rb +14 -0
  19. data/test/integration/analog_input_output_test.rb +43 -0
  20. data/test/integration/connect_to_hardware_test.rb +13 -0
  21. data/test/integration/digital_input_output_test.rb +114 -0
  22. data/test/integration/integration_test.rb +53 -0
  23. data/test/integration/require_minilab_test.rb +9 -0
  24. data/test/system/analog_input.test +3 -0
  25. data/test/system/analog_output.test +37 -0
  26. data/test/system/digital_port_input.test +5 -0
  27. data/test/system/digital_port_output.test +39 -0
  28. data/test/system/digital_port_read_byte.test +26 -0
  29. data/test/system/digital_screw_terminals_input.test +2 -0
  30. data/test/system/digital_screw_terminals_output.test +11 -0
  31. data/test/system/minilab_driver.rb +85 -0
  32. data/test/test_helper.rb +11 -0
  33. data/test/unit/analog_io_test.rb +87 -0
  34. data/test/unit/digital_auxport_io_test.rb +114 -0
  35. data/test/unit/digital_configuration_test.rb +136 -0
  36. data/test/unit/digital_port_io_test.rb +117 -0
  37. data/test/unit/library_translator_test.rb +100 -0
  38. data/test/unit/minilab_context_test.rb +82 -0
  39. data/test/unit/minilab_hardware_test.rb +83 -0
  40. data/test/unit/minilab_test.rb +131 -0
  41. data/test/unit/result_verifier_test.rb +33 -0
  42. data/vendor/behaviors/lib/behaviors.rb +50 -0
  43. data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
  44. data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
  45. data/vendor/behaviors/test/behaviors_test.rb +50 -0
  46. data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
  47. data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
  48. data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
  49. data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
  50. data/vendor/constructor/Rakefile +44 -0
  51. data/vendor/constructor/config/environment.rb +12 -0
  52. data/vendor/constructor/lib/constructor.rb +132 -0
  53. data/vendor/constructor/test/constructor_test.rb +366 -0
  54. data/vendor/constructor/test/helper.rb +3 -0
  55. data/vendor/diy/README +26 -0
  56. data/vendor/diy/Rakefile +18 -0
  57. data/vendor/diy/lib/constructor.rb +114 -0
  58. data/vendor/diy/lib/diy.rb +329 -0
  59. data/vendor/diy/proto/context.rb +117 -0
  60. data/vendor/diy/proto/context.yml +20 -0
  61. data/vendor/diy/test/diy_test.rb +370 -0
  62. data/vendor/diy/test/files/broken_construction.yml +7 -0
  63. data/vendor/diy/test/files/cat/cat.rb +4 -0
  64. data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
  65. data/vendor/diy/test/files/cat/heritage.rb +2 -0
  66. data/vendor/diy/test/files/cat/needs_input.yml +3 -0
  67. data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
  68. data/vendor/diy/test/files/dog/dog_model.rb +4 -0
  69. data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
  70. data/vendor/diy/test/files/dog/dog_view.rb +2 -0
  71. data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
  72. data/vendor/diy/test/files/dog/other_thing.rb +2 -0
  73. data/vendor/diy/test/files/dog/simple.yml +11 -0
  74. data/vendor/diy/test/files/donkey/foo.rb +8 -0
  75. data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
  76. data/vendor/diy/test/files/fud/objects.yml +13 -0
  77. data/vendor/diy/test/files/fud/toy.rb +15 -0
  78. data/vendor/diy/test/files/gnu/objects.yml +14 -0
  79. data/vendor/diy/test/files/gnu/thinger.rb +8 -0
  80. data/vendor/diy/test/files/goat/base.rb +8 -0
  81. data/vendor/diy/test/files/goat/can.rb +6 -0
  82. data/vendor/diy/test/files/goat/goat.rb +6 -0
  83. data/vendor/diy/test/files/goat/objects.yml +12 -0
  84. data/vendor/diy/test/files/goat/paper.rb +6 -0
  85. data/vendor/diy/test/files/goat/plane.rb +8 -0
  86. data/vendor/diy/test/files/goat/shirt.rb +6 -0
  87. data/vendor/diy/test/files/goat/wings.rb +8 -0
  88. data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
  89. data/vendor/diy/test/files/horse/objects.yml +7 -0
  90. data/vendor/diy/test/files/yak/core_model.rb +4 -0
  91. data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
  92. data/vendor/diy/test/files/yak/core_view.rb +1 -0
  93. data/vendor/diy/test/files/yak/data_source.rb +1 -0
  94. data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
  95. data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
  96. data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
  97. data/vendor/diy/test/files/yak/my_objects.yml +21 -0
  98. data/vendor/diy/test/test_helper.rb +40 -0
  99. data/vendor/hardmock/CHANGES +8 -0
  100. data/vendor/hardmock/LICENSE +7 -0
  101. data/vendor/hardmock/README +48 -0
  102. data/vendor/hardmock/Rakefile +100 -0
  103. data/vendor/hardmock/TODO +7 -0
  104. data/vendor/hardmock/config/environment.rb +12 -0
  105. data/vendor/hardmock/homepage/demo.rb +21 -0
  106. data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
  107. data/vendor/hardmock/homepage/index.html +65 -0
  108. data/vendor/hardmock/init.rb +3 -0
  109. data/vendor/hardmock/lib/hardmock.rb +634 -0
  110. data/vendor/hardmock/lib/method_cleanout.rb +14 -0
  111. data/vendor/hardmock/rcov.rake +18 -0
  112. data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
  113. data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
  114. data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
  115. data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
  116. data/vendor/hardmock/test/test_helper.rb +23 -0
  117. data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
  118. data/vendor/hardmock/test/unit/expector_test.rb +56 -0
  119. data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
  120. data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
  121. data/vendor/hardmock/test/unit/mock_test.rb +273 -0
  122. data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
  123. data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
  124. data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
  125. data/vendor/systir/systir.rb +403 -0
  126. data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
  127. data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
  128. metadata +235 -0
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+ require 'diy'
3
+
4
+ class MinilabContext #:nodoc:
5
+ def build
6
+ minilab_context = self.class.get_context
7
+ minilab_context.build_everything
8
+ minilab_context
9
+ end
10
+
11
+ def self.clear
12
+ @@context = nil
13
+ end
14
+
15
+ def self.inject(options)
16
+ object, instance = get_parameters(options)
17
+
18
+ get_context[object] = instance
19
+ end
20
+
21
+ private
22
+ def self.get_parameters(options)
23
+ raise "parameters hash was nil" if options.nil?
24
+ object = options[:object]
25
+ instance = options[:instance]
26
+ raise "missing parameter :object" if object.nil?
27
+ raise "missing parameter :instance" if instance.nil?
28
+ [object, instance]
29
+ end
30
+
31
+ def self.get_context
32
+ @@context ||= DIY::Context.new(YAML.load(object_definition))
33
+ @@context
34
+ end
35
+
36
+ def self.object_definition
37
+ File.read(APP_ROOT + "/config/objects.yml")
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ require 'constructor'
2
+
3
+ class ResultVerifier #:nodoc:
4
+ constructor :minilab_hardware
5
+
6
+ def verify(result, user_message="Command")
7
+ if result[:error]
8
+ library_message = @minilab_hardware.get_error_string(result[:error])
9
+ raise "#{user_message} caused a hardware error: #{library_message}"
10
+ end
11
+
12
+ return true
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'integration_test'
3
+ require 'minilab'
4
+
5
+ class AnalogInputOutputTest < IntegrationTest
6
+ def setup
7
+ super
8
+ build_and_connect_to_minilab
9
+ end
10
+
11
+ should "read analog data" do
12
+ for_all_input_channels do |channel|
13
+ @minilab_hardware.expects.read_analog(channel).returns(no_error_and_value(3.22))
14
+ end
15
+
16
+ for_all_input_channels do |channel|
17
+ assert_equal 3.22, @minilab.read_analog(channel), "wrong value analog value read"
18
+ end
19
+ end
20
+
21
+ should "write analog data" do
22
+ for_all_output_channels do |channel|
23
+ @minilab_hardware.expects.write_analog(channel, 1.78).returns(no_error)
24
+ end
25
+
26
+ for_all_output_channels do |channel|
27
+ assert @minilab.write_analog(channel, 1.78)
28
+ end
29
+ end
30
+
31
+ private
32
+ def for_all_input_channels
33
+ 0.upto(7) do |channel|
34
+ yield channel
35
+ end
36
+ end
37
+
38
+ def for_all_output_channels
39
+ 0.upto(1) do |channel|
40
+ yield channel
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'integration_test'
3
+ require 'minilab'
4
+
5
+ class ConnectToHardwareTest < IntegrationTest
6
+ def setup
7
+ super
8
+ end
9
+
10
+ should "setup error handling, declare the library revision, and setup each digital port for input when connecting" do
11
+ build_and_connect_to_minilab
12
+ end
13
+ end
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'integration_test'
3
+ require 'minilab'
4
+
5
+ class DigitalInputOutputTest < IntegrationTest
6
+ def setup
7
+ super
8
+ build_and_connect_to_minilab
9
+ end
10
+
11
+ should "read digital data from the terminals on the top of the device" do
12
+ for_all_screw_terminals do |terminal|
13
+ terminal_number = get_terminal_number(terminal)
14
+ configuration = { :direction => DIGITALIN, :pin => terminal_number }
15
+ @minilab_hardware.expects.configure_auxport(configuration).returns(no_error)
16
+ @minilab_hardware.expects.read_auxport(terminal_number).returns(no_error_and_value(1))
17
+ end
18
+
19
+ for_all_screw_terminals do |terminal|
20
+ assert_equal 1, @minilab.read_digital(terminal)
21
+ end
22
+ end
23
+
24
+ should "write digital data to the terminals" do
25
+ for_all_screw_terminals do |terminal|
26
+ terminal_number = get_terminal_number(terminal)
27
+ configuration = { :direction => DIGITALOUT, :pin => terminal_number }
28
+ @minilab_hardware.expects.configure_auxport(configuration).returns(no_error)
29
+ @minilab_hardware.expects.write_auxport(terminal_number, 0).returns(no_error)
30
+ end
31
+
32
+ for_all_screw_terminals do |terminal|
33
+ assert @minilab.write_digital(terminal, 0)
34
+ end
35
+ end
36
+
37
+ should "read digital data from the external digital pins only if the port is configured for input" do
38
+ configure_each_port_for_input
39
+
40
+ # We'll go with just one pin for each of the four ports.
41
+ # Finer grained testing of each pin is left to the unit tests.
42
+ for_some_digital_pins do |numbered_pin, library_pin|
43
+ @minilab_hardware.expects.read_digital_pin(library_pin).returns(no_error_and_value(0))
44
+ assert_equal 0, @minilab.read_digital(numbered_pin), "wrong value"
45
+ end
46
+ end
47
+
48
+ should "raise an error when there is a problem reading a digital pin" do
49
+ configure_each_port_for_input
50
+ for_some_digital_pins do |numbered_pin, library_pin|
51
+ @minilab_hardware.expects.read_digital_pin(library_pin).returns(error(2))
52
+ expect_get_error_string :error => 2, :message => "yoink"
53
+ assert_error(RuntimeError, /yoink/) { @minilab.read_digital(numbered_pin) }
54
+ end
55
+ end
56
+
57
+ should "write digital data to the external digital pins only if the port is configured for output" do
58
+ configure_each_port_for_output
59
+
60
+ for_some_digital_pins do |numbered_pin, library_pin|
61
+ @minilab_hardware.expects.write_digital_pin(library_pin, 1).returns(no_error)
62
+ assert @minilab.write_digital(numbered_pin, 1), "should have written with no error"
63
+ end
64
+ end
65
+
66
+ should "read an entire byte from a single port only if the port is configured for input" do
67
+ configure_each_port_for_input
68
+ @port_to_library_port_mapping.each do |port, library_port|
69
+ @minilab_hardware.expects.read_port(library_port).returns(no_error_and_value(167))
70
+ assert_equal 167, @minilab.read_digital_byte(port), "read wrong value"
71
+ end
72
+ end
73
+
74
+ private
75
+ def get_terminal_number(terminal)
76
+ terminal[-1..-1].to_i
77
+ end
78
+
79
+ def for_some_digital_pins
80
+ # The pins numbered on the external ports don't match what the
81
+ # minilab library uses. The ruby code is responsible for doing the
82
+ # correct translation.
83
+ {
84
+ 32 => 5,
85
+ 6 => 12,
86
+ 26 => 19,
87
+ 25 => 20
88
+ }.each do |numbered_pin, library_pin|
89
+ yield numbered_pin, library_pin
90
+ end
91
+ end
92
+
93
+ def for_all_screw_terminals
94
+ ['DIO0', 'DIO1', 'DIO2', 'DIO3'].each do |terminal|
95
+ yield terminal
96
+ end
97
+ end
98
+
99
+ def configure_each_port_for_input
100
+ @port_to_library_port_mapping.each do |port, library_port|
101
+ expected_configuration = { :direction => DIGITALIN, :port => library_port }
102
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(no_error)
103
+ @minilab.configure_input_port(port)
104
+ end
105
+ end
106
+
107
+ def configure_each_port_for_output
108
+ @port_to_library_port_mapping.each do |port, library_port|
109
+ expected_configuration = { :direction => DIGITALOUT, :port => library_port }
110
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(no_error)
111
+ @minilab.configure_output_port(port)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,53 @@
1
+ require 'minilab_context'
2
+ require 'extension/minilab_hardware'
3
+
4
+ class IntegrationTest < Test::Unit::TestCase
5
+ include MinilabConstants
6
+
7
+ def setup
8
+ MinilabContext.clear
9
+ create_mock :minilab_hardware
10
+ MinilabContext.inject :object => :minilab_hardware, :instance => @minilab_hardware
11
+
12
+ @port_to_library_port_mapping = {
13
+ :porta => FIRSTPORTA,
14
+ :portb => FIRSTPORTB,
15
+ :portcl => FIRSTPORTCL,
16
+ :portch => FIRSTPORTCH
17
+ }
18
+ end
19
+
20
+ def no_error
21
+ {:no => :error}
22
+ end
23
+
24
+ def error(number)
25
+ {:error => number}
26
+ end
27
+
28
+ def no_error_and_value(value)
29
+ {:no => :error, :value => value}
30
+ end
31
+
32
+ def expect_get_error_string(optz)
33
+ @minilab_hardware.expects.get_error_string(optz[:error]).returns(optz[:message])
34
+ end
35
+
36
+ def build_and_connect_to_minilab
37
+ @minilab = Minilab.build
38
+
39
+ @minilab_hardware.expects.setup_error_handling(DONTPRINT, STOPALL).returns(no_error)
40
+ @minilab_hardware.expects.declare_revision(CURRENTREVNUM).returns(no_error)
41
+
42
+ configure_input_result = {:no => :error}
43
+ [:porta, :portb, :portcl, :portch].each do |port|
44
+ expected_configuration = { :direction => DIGITALIN, :port => @port_to_library_port_mapping[port] }
45
+ @minilab_hardware.expects.configure_port(expected_configuration).returns(no_error)
46
+ end
47
+
48
+ @minilab.connect
49
+ end
50
+
51
+ should "have an empty test case so that Test::Unit::TestCase doesn't complain" do
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
2
+ require 'integration_test'
3
+
4
+ class RequireMinilabTest < IntegrationTest
5
+ should "be able to require the minilab class without error" do
6
+ `ruby -e "require 'lib/minilab'"`
7
+ assert $?.success?, "failed to require minilab without error"
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ analog_input_4_should_be_about 5.0
2
+
3
+ analog_input_1_should_be_about 0.0
@@ -0,0 +1,37 @@
1
+ # The sleeps are required, as it takes time for the
2
+ # commanded voltages to reach the desired value
3
+
4
+ # test analog output 1
5
+ write_analog_1 5.0
6
+ sleep 0.1
7
+ analog_input_0_should_be_about 5.0
8
+
9
+ write_analog_1 0.0
10
+ sleep 0.1
11
+ analog_input_0_should_be_about 0.0
12
+
13
+ write_analog_1 2.77
14
+ sleep 0.1
15
+ analog_input_0_should_be_about 2.77
16
+
17
+ write_analog_1 3.19
18
+ sleep 0.1
19
+ analog_input_0_should_be_about 3.19
20
+
21
+ # test analog output 0
22
+ write_analog_0 5.0
23
+ sleep 0.1
24
+ analog_input_6_should_be_about 5.0
25
+
26
+ write_analog_0 0.0
27
+ sleep 0.1
28
+ analog_input_6_should_be_about 0.0
29
+
30
+ write_analog_0 3.75
31
+ sleep 0.1
32
+ analog_input_6_should_be_about 3.75
33
+
34
+ write_analog_0 1.88
35
+ sleep 0.1
36
+ analog_input_6_should_be_about 1.88
37
+
@@ -0,0 +1,5 @@
1
+ configure_portb_for_input
2
+ digital_pin_10_should_be 1
3
+
4
+ configure_porta_for_input
5
+ digital_pin_30_should_be 0
@@ -0,0 +1,39 @@
1
+ # Port A --> Port B test
2
+ configure_porta_for_output
3
+ configure_portb_for_input
4
+
5
+ write_digital_pin_36 1
6
+ digital_pin_7_should_be 1
7
+
8
+ write_digital_pin_36 0
9
+ digital_pin_7_should_be 0
10
+
11
+ # Port B --> Port CL test
12
+ configure_portb_for_output
13
+ configure_portcl_for_input
14
+
15
+ write_digital_pin_5 0
16
+ digital_pin_28_should_be 0
17
+
18
+ write_digital_pin_5 1
19
+ digital_pin_28_should_be 1
20
+
21
+ # Port CL -> Port CH test
22
+ configure_portcl_for_output
23
+ configure_portch_for_input
24
+
25
+ write_digital_pin_27 1
26
+ digital_pin_22_should_be 1
27
+
28
+ write_digital_pin_27 0
29
+ digital_pin_22_should_be 0
30
+
31
+ # Port CH -> Port A test
32
+ configure_portch_for_output
33
+ configure_porta_for_input
34
+
35
+ write_digital_pin_24 0
36
+ digital_pin_34_should_be 0
37
+
38
+ write_digital_pin_24 1
39
+ digital_pin_34_should_be 1
@@ -0,0 +1,26 @@
1
+ configure_porta_for_output
2
+ configure_portcl_for_output
3
+ configure_portb_for_input
4
+
5
+ # GND to pin 3 (portb bit 7)
6
+ # GND to pin 4 (portb bit 6)
7
+ write_digital_pin_28 1 # map to pin 5 (portb bit 5)
8
+ # GND to pin 6 (portb bit 4)
9
+ write_digital_pin_36 1 # map to pin 7 (portb bit 3)
10
+ # GND to pin 8 (portb bit 2)
11
+ # GND to pin 9 (portb bit 1)
12
+ # +5v to pin 10 (portb bit 0)
13
+ digital_portb_should_be 0x29
14
+
15
+
16
+
17
+ configure_porta_for_output
18
+ configure_portcl_for_output
19
+ configure_portch_for_input
20
+
21
+ write_digital_pin_27 1 # map to pin 22 (portch bit 3)
22
+ # GND to pin 23 (portch bit 2)
23
+ write_digital_pin_32 1 # map to pin 24 (portch bit 1)
24
+ # GND to pin 22 (portch bit 0)
25
+ digital_portch_should_be 0x0A
26
+
@@ -0,0 +1,2 @@
1
+ DIO1_should_be 1
2
+ DIO2_should_be 0
@@ -0,0 +1,11 @@
1
+ write_DIO0 1
2
+ DIO3_should_be 1
3
+
4
+ write_DIO0 0
5
+ DIO3_should_be 0
6
+
7
+ write_DIO0 0
8
+ analog_input_2_should_be_about 0.0
9
+
10
+ write_DIO0 1
11
+ analog_input_2_should_be_greater_than 0.0
@@ -0,0 +1,85 @@
1
+ require 'systir'
2
+ require 'minilab'
3
+
4
+ class MinilabDriver < Systir::LanguageDriver
5
+ GOOD_DELTA = 0.12
6
+ VALID_PORTS = [:porta, :portb, :portcl, :portch]
7
+ VALID_PINS = (30..37).to_a + (3..10).to_a + (26..29).to_a + (22..25).to_a
8
+
9
+ def setup
10
+ @minilab = Minilab.build
11
+ @minilab.connect
12
+ end
13
+
14
+ # Analog input methods
15
+ 0.upto(7) do |channel|
16
+ define_method("analog_input_#{channel}_should_be_about") do |value|
17
+ expect_read_analog(channel, value)
18
+ end
19
+
20
+ define_method("analog_input_#{channel}_should_be_greater_than") do |value|
21
+ volts = @minilab.read_analog(channel)
22
+ assert volts > (value + GOOD_DELTA)
23
+ end
24
+ end
25
+
26
+ # Analog output methods
27
+ [0, 1].each do |channel|
28
+ define_method("write_analog_#{channel}") do |value|
29
+ @minilab.write_analog(channel, value)
30
+ end
31
+ end
32
+
33
+ # DIOx input and output methods
34
+ 0.upto(3) do |pin|
35
+ define_method("DIO#{pin}_should_be") do |value|
36
+ assert_equal value, @minilab.read_digital("DIO#{pin}")
37
+ end
38
+
39
+ define_method("write_DIO#{pin}") do |value|
40
+ @minilab.write_digital("DIO#{pin}", value)
41
+ end
42
+ end
43
+
44
+ # Digital pin input and output methods
45
+ VALID_PINS.each do |pin|
46
+ define_method("digital_pin_#{pin}_should_be") do |value|
47
+ assert_equal value, @minilab.read_digital(pin)
48
+ end
49
+
50
+ define_method("write_digital_pin_#{pin}") do |value|
51
+ @minilab.write_digital(pin, value)
52
+ end
53
+ end
54
+
55
+ # Digital port read (entire bytes) methods
56
+ VALID_PORTS.each do |port|
57
+ define_method("digital_#{port}_should_be") do |value|
58
+ assert_equal value, @minilab.read_digital_byte(port)
59
+ end
60
+ end
61
+
62
+ # Configuration methods
63
+ VALID_PORTS.each do |port|
64
+ define_method("configure_#{port}_for_input") do
65
+ @minilab.configure_input_port(port)
66
+ end
67
+
68
+ define_method("configure_#{port}_for_output") do
69
+ @minilab.configure_output_port(port)
70
+ end
71
+ end
72
+
73
+ # Other
74
+ def minilab_revision_should_be(revision)
75
+ assert_equal revision, @minilab.get_revision
76
+ end
77
+
78
+ private
79
+ def expect_read_analog(channel, volts)
80
+ input = @minilab.read_analog(channel)
81
+
82
+ assert_in_delta(volts, input, GOOD_DELTA,
83
+ "Input voltage was not ~#{volts} volts")
84
+ end
85
+ end