farmbot-serial 0.0.1

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.
@@ -0,0 +1,289 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fb::HardwareInterface do
4
+
5
+ before do
6
+ Fb::HardwareInterface.current = Fb::HardwareInterface.new(true)
7
+ Fb::HardwareInterface.current.status = Fb::Status.new
8
+ end
9
+
10
+ it "servo standard move" do
11
+ pin = rand(9999999).to_i
12
+ value = rand(9999999).to_i
13
+
14
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
15
+ Fb::HardwareInterface.current.servo_std_move(pin, value)
16
+
17
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F61 P#{pin} V#{value}\n")
18
+ end
19
+
20
+ it "servo standard move" do
21
+ pin = rand(9999999).to_i
22
+ value = rand(9999999).to_i
23
+ mode = rand(9999999).to_i
24
+
25
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
26
+ Fb::HardwareInterface.current.pin_std_set_value(pin, value, mode)
27
+
28
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F41 P#{pin} V#{value} M#{mode}\n")
29
+ end
30
+
31
+ # def pin_std_read_value(pin, mode, external_info)
32
+
33
+ it "pin standard read value" do
34
+ pin = rand(9999999).to_i
35
+ mode = rand(9999999).to_i
36
+ value = rand(9999999).to_i
37
+ ext_info = rand(9999999).to_s
38
+
39
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR41 P#{pin} V#{value}\nR02\n"
40
+ Fb::HardwareInterface.current.pin_std_read_value(pin, mode, ext_info)
41
+
42
+ pin_value = 0
43
+
44
+ expect(pin_value.to_i).to eq(value.to_i)
45
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F42 P#{pin} M#{mode}\n")
46
+ end
47
+
48
+ # def pin_std_set_mode(pin, mode)
49
+
50
+ it "pin standard set mode" do
51
+ pin = rand(9999999).to_i
52
+ mode = rand(9999999).to_i
53
+
54
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
55
+ Fb::HardwareInterface.current.pin_std_set_mode(pin, mode)
56
+
57
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F43 P#{pin} M#{mode}\n")
58
+ end
59
+
60
+ it "pin standard set pulse" do
61
+ pin = rand(9999999).to_i
62
+ value1 = rand(9999999).to_i
63
+ value2 = rand(9999999).to_i
64
+ time = rand(9999999).to_i
65
+ mode = rand(9999999).to_i
66
+
67
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
68
+ Fb::HardwareInterface.current.pin_std_pulse(pin, value1, value2, time, mode)
69
+
70
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F44 P#{pin} V#{value1} W#{value2} T#{time} M#{mode}\n")
71
+ end
72
+
73
+ it "dose water" do
74
+ amount = rand(9999999).to_i
75
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
76
+ Fb::HardwareInterface.current.dose_water(amount)
77
+
78
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F01 Q#{amount}\n")
79
+ end
80
+
81
+ it "read end stops" do
82
+ xa = (rand(2) >= 1) ? 1 : 0
83
+ xb = (rand(2) >= 1) ? 1 : 0
84
+ ya = (rand(2) >= 1) ? 1 : 0
85
+ yb = (rand(2) >= 1) ? 1 : 0
86
+ za = (rand(2) >= 1) ? 1 : 0
87
+ zb = (rand(2) >= 1) ? 1 : 0
88
+
89
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR81 XA#{xa} XB#{xb} YA#{ya} YB#{yb} ZA#{za} ZB#{zb}\nR02\n"
90
+ Fb::HardwareInterface.current.read_end_stops()
91
+
92
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F81\n")
93
+ expect(Fb::HardwareInterface.current.status.info_end_stop_x_a).to eq(xa == 1)
94
+ expect(Fb::HardwareInterface.current.status.info_end_stop_x_b).to eq(xb == 1)
95
+ expect(Fb::HardwareInterface.current.status.info_end_stop_y_a).to eq(ya == 1)
96
+ expect(Fb::HardwareInterface.current.status.info_end_stop_y_b).to eq(yb == 1)
97
+ expect(Fb::HardwareInterface.current.status.info_end_stop_z_a).to eq(za == 1)
98
+ expect(Fb::HardwareInterface.current.status.info_end_stop_z_b).to eq(zb == 1)
99
+ end
100
+
101
+ it "read position" do
102
+
103
+ x = rand(9999999).to_i
104
+ y = rand(9999999).to_i
105
+ z = rand(9999999).to_i
106
+
107
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR82 X#{x} Y#{y} Z#{z}\nR02\n"
108
+ Fb::HardwareInterface.current.read_postition()
109
+
110
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F82\n")
111
+ expect(Fb::HardwareInterface.current.status.info_current_x_steps).to eq(x)
112
+ expect(Fb::HardwareInterface.current.status.info_current_y_steps).to eq(y)
113
+ expect(Fb::HardwareInterface.current.status.info_current_z_steps).to eq(z)
114
+ end
115
+
116
+ it "read device version" do
117
+
118
+ version = rand(9999999).to_s
119
+
120
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR83 #{version}\nR02\n"
121
+ Fb::HardwareInterface.current.read_device_version()
122
+
123
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F83\n")
124
+ expect(Fb::HardwareInterface.current.status.device_version).to eq(version)
125
+ end
126
+
127
+ it "home all" do
128
+
129
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
130
+ Fb::HardwareInterface.current.move_home_all()
131
+
132
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("G28\n")
133
+ end
134
+
135
+ it "home x" do
136
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
137
+ Fb::HardwareInterface.current.move_home_x()
138
+
139
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F11\n")
140
+ end
141
+
142
+ it "home y" do
143
+
144
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
145
+ Fb::HardwareInterface.current.move_home_y()
146
+
147
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F12\n")
148
+ end
149
+
150
+ it "home z" do
151
+
152
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
153
+ Fb::HardwareInterface.current.move_home_z()
154
+
155
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F13\n")
156
+
157
+ end
158
+
159
+ # def calibrate_x
160
+
161
+ it "calibrate x" do
162
+
163
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
164
+ Fb::HardwareInterface.current.calibrate_x()
165
+
166
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F14\n")
167
+
168
+ end
169
+
170
+ # def calibrate_y
171
+
172
+ it "calibrate y" do
173
+
174
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
175
+ Fb::HardwareInterface.current.calibrate_y()
176
+
177
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F15\n")
178
+
179
+ end
180
+
181
+ # def calibrate_z
182
+
183
+ it "calibrate z" do
184
+
185
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
186
+ Fb::HardwareInterface.current.calibrate_z()
187
+
188
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F16\n")
189
+
190
+ end
191
+
192
+ # def move_absolute( coord_x, coord_y, coord_z)
193
+
194
+ it "move absolute" do
195
+
196
+ x = rand(9999999).to_i
197
+ y = rand(9999999).to_i
198
+ z = rand(9999999).to_i
199
+
200
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
201
+ Fb::HardwareInterface.current.move_absolute( x, y, z)
202
+
203
+ part_x = "X#{x * Fb::HardwareInterface.current.ramps_param.axis_x_steps_per_unit}"
204
+ part_y = "Y#{y * Fb::HardwareInterface.current.ramps_param.axis_y_steps_per_unit}"
205
+ part_z = "Z#{z * Fb::HardwareInterface.current.ramps_param.axis_z_steps_per_unit}"
206
+
207
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("G00 #{part_x} #{part_y} #{part_z}\n")
208
+ end
209
+
210
+
211
+ # def move_relative( amount_x, amount_y, amount_z)
212
+
213
+ it "move relative" do
214
+
215
+ x = rand(9999999).to_i
216
+ y = rand(9999999).to_i
217
+ z = rand(9999999).to_i
218
+
219
+ current_x = rand(9999999).to_i
220
+ current_y = rand(9999999).to_i
221
+ current_z = rand(9999999).to_i
222
+
223
+ Fb::HardwareInterface.current.status.info_current_x_steps = current_x
224
+ Fb::HardwareInterface.current.status.info_current_y_steps = current_y
225
+ Fb::HardwareInterface.current.status.info_current_z_steps = current_z
226
+
227
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
228
+ Fb::HardwareInterface.current.move_relative( x, y, z)
229
+
230
+ part_x = "X#{x * Fb::HardwareInterface.current.ramps_param.axis_x_steps_per_unit + current_x}"
231
+ part_y = "Y#{y * Fb::HardwareInterface.current.ramps_param.axis_y_steps_per_unit + current_y}"
232
+ part_z = "Z#{z * Fb::HardwareInterface.current.ramps_param.axis_z_steps_per_unit + current_z}"
233
+
234
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("G00 #{part_x} #{part_y} #{part_z}\n")
235
+ end
236
+
237
+ # def move_steps(steps_x, steps_y, steps_z)
238
+
239
+ it "move steps" do
240
+
241
+ x = rand(9999999).to_i
242
+ y = rand(9999999).to_i
243
+ z = rand(9999999).to_i
244
+
245
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
246
+ Fb::HardwareInterface.current.move_steps( x, y, z)
247
+
248
+ part_x = "X#{x}"
249
+ part_y = "Y#{y}"
250
+ part_z = "Z#{z}"
251
+
252
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("G01 #{part_x} #{part_y} #{part_z}\n")
253
+ end
254
+
255
+ # def move_to_coord(steps_x, steps_y, steps_z)
256
+
257
+ it "move to coord" do
258
+
259
+ x = rand(9999999).to_i
260
+ y = rand(9999999).to_i
261
+ z = rand(9999999).to_i
262
+
263
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R01\nR02\n"
264
+ Fb::HardwareInterface.current.move_to_coord( x, y, z)
265
+
266
+ part_x = "X#{x}"
267
+ part_y = "Y#{y}"
268
+ part_z = "Z#{z}"
269
+
270
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("G00 #{part_x} #{part_y} #{part_z}\n")
271
+ end
272
+
273
+ # def check_parameters
274
+
275
+ it "check parameters" do
276
+
277
+ db_version = rand(9999999).to_i
278
+
279
+
280
+
281
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write = ""
282
+ Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_read = "R21 P0 V#{db_version}\n"
283
+ Fb::HardwareInterface.current.check_parameters()
284
+
285
+ expect(Fb::HardwareInterface.current.ramps_arduino.serial_port.test_serial_write).to eq("F21 P0\n")
286
+ end
287
+
288
+
289
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+ require 'pry'
7
+ require 'farmbot-serial'
8
+
9
+ RSpec.configure do |config|
10
+ config.expect_with :rspec do |expectations|
11
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12
+ end
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.verify_partial_doubles = true
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ HOME Y,0,0,0
2
+ HOME X,0,0,0
3
+ MOVE ABSOLUTE, 0, 30, 0, 0
4
+
5
+ MOVE ABSOLUTE, 30, 30, 0, 0
6
+ DOSE WATER, 0, 0, 0, 5
7
+ MOVE ABSOLUTE, 60, 30, 0, 0
8
+ DOSE WATER, 0, 0, 0, 5
9
+ MOVE ABSOLUTE, 90, 30, 0, 0
10
+ DOSE WATER, 0, 0, 0, 5
11
+ MOVE ABSOLUTE,120, 30, 0, 0
12
+ DOSE WATER, 0, 0, 0, 5
13
+
14
+ MOVE ABSOLUTE,120, 60, 0, 0
15
+ DOSE WATER, 0, 0, 0, 5
16
+ MOVE ABSOLUTE, 90, 60, 0, 0
17
+ DOSE WATER, 0, 0, 0, 5
18
+ MOVE ABSOLUTE, 60, 60, 0, 0
19
+ DOSE WATER, 0, 0, 0, 5
20
+ MOVE ABSOLUTE, 30, 60, 0, 0
21
+ DOSE WATER, 0, 0, 0, 5
22
+
23
+
24
+ HOME Y,0,0,0
25
+ HOME X,0,0,0
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: farmbot-serial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tim Evers
8
+ - Rick Carlino
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: serialport
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Serial library for Farmbot
99
+ email:
100
+ - rick.carlino@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - farmbot-serial.gemspec
110
+ - lib/arduino_default_params.rb
111
+ - lib/farmbot-serial.rb
112
+ - lib/hardware_interface.rb
113
+ - lib/hardware_interface_arduino.rb
114
+ - lib/hardware_interface_arduino_values_received.rb
115
+ - lib/hardware_interface_arduino_write_status.rb
116
+ - lib/hardware_interface_param.rb
117
+ - lib/serial_port_sim.rb
118
+ - lib/status.rb
119
+ - spec/lib/ramps_arduino_spec.rb
120
+ - spec/lib/ramps_arduino_values_received_spec.rb
121
+ - spec/lib/ramps_arduino_write_status_spec.rb
122
+ - spec/lib/ramps_param_spec.rb
123
+ - spec/lib/ramps_spec.rb
124
+ - spec/spec_helper.rb
125
+ - testcommands.csv
126
+ homepage: http://github.com/farmbot/farmbot-serial
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.5
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Serial library for Farmbot
150
+ test_files:
151
+ - spec/lib/ramps_arduino_spec.rb
152
+ - spec/lib/ramps_arduino_values_received_spec.rb
153
+ - spec/lib/ramps_arduino_write_status_spec.rb
154
+ - spec/lib/ramps_param_spec.rb
155
+ - spec/lib/ramps_spec.rb
156
+ - spec/spec_helper.rb