mi100 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mi100/version.rb +3 -3
- data/lib/mi100.rb +367 -315
- data/spec/mi100_spec.rb +408 -301
- metadata +8 -8
data/spec/mi100_spec.rb
CHANGED
@@ -1,301 +1,408 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mi100 do
|
4
|
-
|
5
|
-
it 'should have a version number' do
|
6
|
-
expect(Mi100::VERSION).not_to be nil
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
Mi100.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
expect(mi100).to
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
expect(mi100).to
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
expect(mi100).to
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
expect(mi100).to
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
expect(mi100).to
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expect(mi100).to
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
expect(mi100).to
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
expect(mi100).to
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
expect(mi100).to
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
expect(mi100).to
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
expect(mi100).to
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
expect(mi100).to
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
expect(mi100).to
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
expect(mi100).to
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
expect(mi100).to
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
expect(mi100).to
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
expect(mi100).to
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
expect(mi100).to
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
mi100
|
182
|
-
expect(mi100
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
Mi100.
|
188
|
-
mi100
|
189
|
-
expect(mi100
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
Mi100.
|
195
|
-
mi100
|
196
|
-
expect(mi100
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
Mi100.
|
202
|
-
mi100
|
203
|
-
expect(mi100
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
Mi100.
|
209
|
-
mi100
|
210
|
-
expect(mi100
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
Mi100.
|
216
|
-
mi100
|
217
|
-
expect(mi100
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
Mi100.
|
223
|
-
mi100
|
224
|
-
mi100.
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
Mi100.
|
230
|
-
mi100
|
231
|
-
mi100.
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
mi100 = Mi100.new "COM5"
|
237
|
-
mi100.
|
238
|
-
mi100.
|
239
|
-
expect(mi100).
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'should send
|
243
|
-
Mi100.
|
244
|
-
mi100 = Mi100.new "COM5"
|
245
|
-
mi100.
|
246
|
-
expect(mi100).to have_received(:
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'should send
|
250
|
-
Mi100.
|
251
|
-
mi100 = Mi100.new "COM5"
|
252
|
-
mi100.
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
expect(mi100).to
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
mi100
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
expect(
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mi100 do
|
4
|
+
|
5
|
+
it 'should have a version number' do
|
6
|
+
expect(Mi100::VERSION).not_to be nil
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
allow_any_instance_of(Mi100).to receive(:initialize_serialport)
|
11
|
+
allow_any_instance_of(Mi100).to receive(:initialize_robo)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should create the instance' do
|
15
|
+
mi100 = Mi100.new "COM5"
|
16
|
+
expect(mi100).to be_a Mi100
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should send "H" on :ping' do
|
20
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_PING,1234])
|
21
|
+
mi100 = Mi100.new "COM5"
|
22
|
+
expect(mi100.ping).to eq(["H",1234])
|
23
|
+
expect(mi100).to have_received(:send_command_get_response).with("H")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should send "H" and return rounded power level on :power' do
|
27
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_GET_POWER_LEVEL,1188])
|
28
|
+
mi100 = Mi100.new "COM5"
|
29
|
+
expect(mi100.power).to eq(1.19)
|
30
|
+
expect(mi100).to have_received(:send_command_get_response).with("H")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should send "P" and get light level on :light' do
|
34
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_GET_LIGHT,1188])
|
35
|
+
mi100 = Mi100.new "COM5"
|
36
|
+
expect(mi100.light).to eq(1188)
|
37
|
+
expect(mi100).to have_received(:send_command_get_response).with("P")
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should send "F,duration" on move "FORWARD"' do
|
41
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_MOVE_FORWARD,1234])
|
42
|
+
mi100 = Mi100.new "COM5"
|
43
|
+
expect(mi100.move "FORWARD").to eq(["F",1234])
|
44
|
+
expect(mi100).to have_received(:send_command_get_response).with("F,300")
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should send "B,duration" on move "BACKWARD"' do
|
48
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_MOVE_BACKWARD,1234])
|
49
|
+
mi100 = Mi100.new "COM5"
|
50
|
+
expect(mi100.move "BACKWARD").to eq(["B",1234])
|
51
|
+
expect(mi100).to have_received(:send_command_get_response).with("B,300")
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should send "R,140" on spin "RIGHT"' do
|
55
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SPIN_RIGHT,1234])
|
56
|
+
mi100 = Mi100.new "COM5"
|
57
|
+
expect(mi100.spin "RIGHT").to eq(["R",1234])
|
58
|
+
expect(mi100).to have_received(:send_command_get_response).with("R,140")
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should send "L,140" on spin "LEFT"' do
|
62
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SPIN_LEFT,1234])
|
63
|
+
mi100 = Mi100.new "COM5"
|
64
|
+
expect(mi100.spin "LEFT").to eq(["L",1234])
|
65
|
+
expect(mi100).to have_received(:send_command_get_response).with("L,140")
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should send "F,duration" on move_forward duration' do
|
69
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_MOVE_FORWARD,1234])
|
70
|
+
mi100 = Mi100.new "COM5"
|
71
|
+
expect(mi100.move_forward 500).to eq(["F",1234])
|
72
|
+
expect(mi100).to have_received(:send_command_get_response).with("F,500")
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should send "B,duration" move_backward duration' do
|
76
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_MOVE_BACKWARD,1234])
|
77
|
+
mi100 = Mi100.new "COM5"
|
78
|
+
expect(mi100.move_backward 500).to eq(["B",1234])
|
79
|
+
expect(mi100).to have_received(:send_command_get_response).with("B,500")
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should send "R,duration" spin_right duration' do
|
83
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SPIN_RIGHT,1234])
|
84
|
+
mi100 = Mi100.new "COM5"
|
85
|
+
expect(mi100.spin_right 500).to eq(["R",1234])
|
86
|
+
expect(mi100).to have_received(:send_command_get_response).with("R,500")
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should send "L,duration" on spin_left duration' do
|
90
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SPIN_LEFT,1234])
|
91
|
+
mi100 = Mi100.new "COM5"
|
92
|
+
expect(mi100.spin_left 500).to eq(["L",1234])
|
93
|
+
expect(mi100).to have_received(:send_command_get_response).with("L,500")
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should send "U,duration" on turn_right duration' do
|
97
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TURN_RIGHT,123])
|
98
|
+
mi100 = Mi100.new "COM5"
|
99
|
+
expect(mi100.turn_right 500).to eq(["U",123])
|
100
|
+
expect(mi100).to have_received(:send_command_get_response).with("U,500")
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should send "A,duration" on turn_left duration' do
|
104
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TURN_LEFT,123])
|
105
|
+
mi100 = Mi100.new "COM5"
|
106
|
+
expect(mi100.turn_left 500).to eq(["A",123])
|
107
|
+
expect(mi100).to have_received(:send_command_get_response).with("A,500")
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should send "F, 300" on movef' do
|
111
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_MOVE_FORWARD,1234])
|
112
|
+
mi100 = Mi100.new "COM5"
|
113
|
+
expect(mi100.movef).to eq(["F",1234])
|
114
|
+
expect(mi100).to have_received(:send_command_get_response).with("F,300")
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should send "B,300" on moveb' do
|
118
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_MOVE_BACKWARD,1234])
|
119
|
+
mi100 = Mi100.new "COM5"
|
120
|
+
expect(mi100.moveb).to eq(["B",1234])
|
121
|
+
expect(mi100).to have_received(:send_command_get_response).with("B,300")
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should send "R,140" spinr' do
|
125
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SPIN_RIGHT,1234])
|
126
|
+
mi100 = Mi100.new "COM5"
|
127
|
+
expect(mi100.spinr).to eq(["R",1234])
|
128
|
+
expect(mi100).to have_received(:send_command_get_response).with("R,140")
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should send "L,140" on spinl' do
|
132
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SPIN_LEFT,1234])
|
133
|
+
mi100 = Mi100.new "COM5"
|
134
|
+
expect(mi100.spinl).to eq(["L",1234])
|
135
|
+
expect(mi100).to have_received(:send_command_get_response).with("L,140")
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive right_speed, left_speed, duration' do
|
139
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_DRIVE,1234])
|
140
|
+
mi100 = Mi100.new "COM5"
|
141
|
+
expect(mi100.drive 123, 234, 56).to eq(["Z",1234])
|
142
|
+
expect(mi100).to have_received(:send_command_get_response).with("Z,123,234,56")
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive right_speed, left_speed' do
|
146
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_DRIVE,1234])
|
147
|
+
mi100 = Mi100.new "COM5"
|
148
|
+
mi100.instance_variable_set(:@drive_duration, Mi100::DEFAULT_DRIVE_DURATION)
|
149
|
+
expect(mi100.drive 123, 234).to eq(["Z",1234])
|
150
|
+
expect(mi100).to have_received(:send_command_get_response).with("Z,123,234,50")
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_right turn_speed, speed, duration' do
|
154
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_DRIVE,1234])
|
155
|
+
mi100 = Mi100.new "COM5"
|
156
|
+
expect(mi100.drive_right 111, 123, 56).to eq(["Z",1234])
|
157
|
+
expect(mi100).to have_received(:send_command_get_response).with("Z,123,234,56")
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_right turn_speed' do
|
161
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_DRIVE,1234])
|
162
|
+
mi100 = Mi100.new "COM5"
|
163
|
+
mi100.instance_variable_set(:@speed, 123)
|
164
|
+
mi100.instance_variable_set(:@drive_duration, Mi100::DEFAULT_DRIVE_DURATION)
|
165
|
+
expect(mi100.drive_right 111).to eq(["Z",1234])
|
166
|
+
expect(mi100).to have_received(:send_command_get_response).with("Z,123,234,50")
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_left turn_speed, speed, duration' do
|
170
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_DRIVE,1234])
|
171
|
+
mi100 = Mi100.new "COM5"
|
172
|
+
expect(mi100.drive_left 111, 123, 56).to eq(["Z",1234])
|
173
|
+
expect(mi100).to have_received(:send_command_get_response).with("Z,234,123,56")
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_left turn_speed' do
|
177
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_DRIVE,1234])
|
178
|
+
mi100 = Mi100.new "COM5"
|
179
|
+
mi100.instance_variable_set(:@speed, 123)
|
180
|
+
mi100.instance_variable_set(:@drive_duration, Mi100::DEFAULT_DRIVE_DURATION)
|
181
|
+
expect(mi100.drive_left 111).to eq(["Z",1234])
|
182
|
+
expect(mi100).to have_received(:send_command_get_response).with("Z,234,123,50")
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should send "F,duration" on move_forward! duration in async (via sendln)' do
|
186
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
187
|
+
mi100 = Mi100.new "COM5"
|
188
|
+
expect(mi100.move_forward! 500).to eq(6)
|
189
|
+
expect(mi100).to have_received(:sendln).with("F,500")
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should send "B,duration" on move_backward! duration in async' do
|
193
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
194
|
+
mi100 = Mi100.new "COM5"
|
195
|
+
expect(mi100.move_backward! 500).to eq(6)
|
196
|
+
expect(mi100).to have_received(:sendln).with("B,500")
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should send "R,duration" on spin_right! duration in async' do
|
200
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
201
|
+
mi100 = Mi100.new "COM5"
|
202
|
+
expect(mi100.spin_right! 500).to eq(6)
|
203
|
+
expect(mi100).to have_received(:sendln).with("R,500")
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should send "L,duration" on spin_left! duration in async' do
|
207
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
208
|
+
mi100 = Mi100.new "COM5"
|
209
|
+
expect(mi100.spin_left! 500).to eq(6)
|
210
|
+
expect(mi100).to have_received(:sendln).with("L,500")
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should send "U,duration" on turn_right! duration in async' do
|
214
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
215
|
+
mi100 = Mi100.new "COM5"
|
216
|
+
expect(mi100.turn_right! 500).to eq(6)
|
217
|
+
expect(mi100).to have_received(:sendln).with("U,500")
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should send "A,duration" on turn_left! duration in async' do
|
221
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
222
|
+
mi100 = Mi100.new "COM5"
|
223
|
+
expect(mi100.turn_left! 500).to eq(6)
|
224
|
+
expect(mi100).to have_received(:sendln).with("A,500")
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive! right_speed, left_speed, duration in async' do
|
228
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
229
|
+
mi100 = Mi100.new "COM5"
|
230
|
+
expect(mi100.drive! 123, 234, 56).to eq(6)
|
231
|
+
expect(mi100).to have_received(:sendln).with("Z,123,234,56")
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive! right_speed, left_speed in async' do
|
235
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
236
|
+
mi100 = Mi100.new "COM5"
|
237
|
+
mi100.instance_variable_set(:@drive_duration, Mi100::DEFAULT_DRIVE_DURATION)
|
238
|
+
expect(mi100.drive! 123, 234).to eq(6)
|
239
|
+
expect(mi100).to have_received(:sendln).with("Z,123,234,50")
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_right! turn_speed, speed, duration in async' do
|
243
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
244
|
+
mi100 = Mi100.new "COM5"
|
245
|
+
expect(mi100.drive_right! 111, 123, 56).to eq(6)
|
246
|
+
expect(mi100).to have_received(:sendln).with("Z,123,234,56")
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_right! turn_speed in async' do
|
250
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
251
|
+
mi100 = Mi100.new "COM5"
|
252
|
+
mi100.instance_variable_set(:@speed, 123)
|
253
|
+
mi100.instance_variable_set(:@drive_duration, Mi100::DEFAULT_DRIVE_DURATION)
|
254
|
+
expect(mi100.drive_right! 111).to eq(6)
|
255
|
+
expect(mi100).to have_received(:sendln).with("Z,123,234,50")
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_left! turn_speed, speed, duration in async' do
|
259
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
260
|
+
mi100 = Mi100.new "COM5"
|
261
|
+
expect(mi100.drive_left! 111, 123, 56).to eq(6)
|
262
|
+
expect(mi100).to have_received(:sendln).with("Z,234,123,56")
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'should send "Z,right_speed,left_speed,duration" on drive_left! turn_speed in async' do
|
266
|
+
allow_any_instance_of(Mi100).to receive(:sendln).and_return(6)
|
267
|
+
mi100 = Mi100.new "COM5"
|
268
|
+
mi100.instance_variable_set(:@speed, 123)
|
269
|
+
mi100.instance_variable_set(:@drive_duration, Mi100::DEFAULT_DRIVE_DURATION)
|
270
|
+
expect(mi100.drive_left! 111).to eq(6)
|
271
|
+
expect(mi100).to have_received(:sendln).with("Z,234,123,50")
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should send "W,pwm_value" on speed pwm_value' do
|
275
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SET_SPEED,1234])
|
276
|
+
mi100 = Mi100.new "COM5"
|
277
|
+
expect(mi100.speed 500).to eq(["W",1234])
|
278
|
+
expect(mi100).to have_received(:send_command_get_response).with("W,500")
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should reset default speed' do
|
282
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_SET_SPEED,1234])
|
283
|
+
mi100 = Mi100.new "COM5"
|
284
|
+
expect(mi100.speed Mi100::DEFAULT_SPEED).to eq(["W",1234])
|
285
|
+
expect(mi100).to have_received(:send_command_get_response).with("W,1023")
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'should set drive_duration to 56mS' do
|
289
|
+
mi100 = Mi100.new "COM5"
|
290
|
+
expect(mi100.drive_duration 56).to eq(mi100.instance_variable_get(:@drive_duration))
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'should send "M" and get free ram memory area on :free_ram' do
|
294
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_FREE_RAM,1234])
|
295
|
+
mi100 = Mi100.new "COM5"
|
296
|
+
expect(mi100.free_ram).to eq(["M",1234])
|
297
|
+
expect(mi100).to have_received(:send_command_get_response).with("M")
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should send "D,100,50,50,duration" on blink 100,50,50,duration' do
|
301
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_BLINK_LED,1234])
|
302
|
+
mi100 = Mi100.new "COM5"
|
303
|
+
expect(mi100.blink 100,50,50,100).to eq(["D",1234])
|
304
|
+
expect(mi100).to have_received(:send_command_get_response).with("D,100,50,50,100")
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should send "V,100,0,100" on turn_led 100,0,100' do
|
308
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TURN_LED_RGB,1234])
|
309
|
+
mi100 = Mi100.new "COM5"
|
310
|
+
expect(mi100.turn_led 100,0,100).to eq(["V",1234])
|
311
|
+
expect(mi100).to have_received(:send_command_get_response).with("V,100,0,100")
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'should send "S" on stop' do
|
315
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_STOP,1234])
|
316
|
+
mi100 = Mi100.new "COM5"
|
317
|
+
expect(mi100.stop).to eq(["S",1234])
|
318
|
+
expect(mi100).to have_received(:send_command_get_response).with("S")
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'should send "T,random frequency, 300" on tone' do
|
322
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TONE,1234])
|
323
|
+
mi100 = Mi100.new "COM5"
|
324
|
+
expect(mi100.tone).to eq(["T",1234])
|
325
|
+
expect(mi100).to have_received(:send_command_get_response).with(/T,\d{2,4},300/)
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'should limit minimum tone frequency to 28 on tome' do
|
329
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TONE,1234])
|
330
|
+
mi100 = Mi100.new "COM5"
|
331
|
+
mi100.tone 20, 500
|
332
|
+
expect(mi100).to have_received(:send_command_get_response).with("T,28,500")
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'should send "T,440,1000" on sound "la", 1000' do
|
336
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TONE,1234])
|
337
|
+
mi100 = Mi100.new "COM5"
|
338
|
+
mi100.sound "la",1000
|
339
|
+
expect(mi100).to have_received(:send_command_get_response).with("T,440,1000")
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'sound should not call tone with false frequency' do
|
343
|
+
mi100 = Mi100.new "COM5"
|
344
|
+
allow(mi100).to receive(:tone)
|
345
|
+
mi100.sound false, 300
|
346
|
+
expect(mi100).not_to have_received(:tone)
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'should send three good tones on good' do
|
350
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TONE,1234])
|
351
|
+
mi100 = Mi100.new "COM5"
|
352
|
+
mi100.good
|
353
|
+
expect(mi100).to have_received(:send_command_get_response).exactly(3).times
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'should send one bad tone on bad' do
|
357
|
+
allow_any_instance_of(Mi100).to receive(:send_command_get_response).and_return([Mi100::CMD_TONE,1234])
|
358
|
+
mi100 = Mi100.new "COM5"
|
359
|
+
mi100.bad
|
360
|
+
expect(mi100).to have_received(:send_command_get_response).once
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'should talk morse code' do
|
364
|
+
mi100 = Mi100.new "COM5"
|
365
|
+
allow(mi100).to receive(:tone)
|
366
|
+
mi100.talk "sos"
|
367
|
+
expect(mi100).to have_received(:tone).exactly(6).times.with(4000,50)
|
368
|
+
expect(mi100).to have_received(:tone).exactly(3).times.with(4000,150)
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'should access to morse_frequency' do
|
372
|
+
mi100 = Mi100.new "COM5"
|
373
|
+
expect(mi100.morse_frequency).to eq(4000)
|
374
|
+
expect(mi100.morse_frequency = 440).to eq(440)
|
375
|
+
expect(mi100.morse_frequency).to eq(440)
|
376
|
+
end
|
377
|
+
|
378
|
+
it 'should access to morse_unit' do
|
379
|
+
mi100 = Mi100.new "COM5"
|
380
|
+
expect(mi100.morse_unit).to eq(50)
|
381
|
+
expect(mi100.morse_unit = 100).to eq(100)
|
382
|
+
expect(mi100.morse_unit).to eq(100)
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should talk with new default frequency and unit' do
|
386
|
+
mi100 = Mi100.new "COM5"
|
387
|
+
allow(mi100).to receive(:tone)
|
388
|
+
mi100.talk "sos"
|
389
|
+
expect(mi100).to have_received(:tone).exactly(6).times.with(440,100)
|
390
|
+
expect(mi100).to have_received(:tone).exactly(3).times.with(440,300)
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'should reset default frequency and unit' do
|
394
|
+
Mi100::Morsecoder.reset
|
395
|
+
expect(Mi100::Morsecoder.default_frequency).to eq(4000)
|
396
|
+
expect(Mi100::Morsecoder.default_unit).to eq(50)
|
397
|
+
mi100 = Mi100.new "COM5"
|
398
|
+
expect(mi100.morse_frequency).to eq(4000)
|
399
|
+
expect(mi100.morse_unit).to eq(50)
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'should provide Morsecode.to_morse_from class method converting the string to the morse code array' do
|
403
|
+
morsecode = Mi100::Morsecoder.to_morse_from "sos"
|
404
|
+
expect(morsecode.size).to eq(21)
|
405
|
+
expect(morsecode[0]).to eq ({:frequency=>4000, :duration=>50})
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|