farmbot-serial 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,289 +0,0 @@
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