mi100 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mi100/version.rb +1 -1
- data/lib/mi100.rb +74 -45
- data/spec/mi100_spec.rb +83 -34
- metadata +8 -8
data/lib/mi100/version.rb
CHANGED
data/lib/mi100.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# mi100.rb
|
2
2
|
# Copyright (c) 2014 Masami Yamakawa
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# This software is released under the MIT License.
|
5
5
|
# http://opensource.org/lisenses/mit-license.php
|
6
6
|
|
@@ -25,15 +25,20 @@ class Mi100
|
|
25
25
|
CMD_BLINK_LED = "D"
|
26
26
|
CMD_TONE = "T"
|
27
27
|
CMD_GET_LIGHT = "P"
|
28
|
-
|
28
|
+
CMD_TURN_RIGHT = "U"
|
29
|
+
CMD_TURN_LEFT = "A"
|
30
|
+
CMD_SET_SPEED = "W"
|
31
|
+
CMD_FREE_RAM = "M"
|
32
|
+
|
33
|
+
DEFAULT_SPEED = 1023
|
29
34
|
DEFAULT_MOVE_DURATION = 300
|
30
35
|
DEFAULT_SPIN_DURATION = 140
|
31
36
|
DEFAULT_BLINK_DURATION = 600
|
32
37
|
DEFAULT_TONE_DURATION = 300
|
33
|
-
|
38
|
+
|
34
39
|
DEFAULT_MOVE_DIRECTION = "FORWARD"
|
35
40
|
DEFAULT_SPIN_DIRECTION = "RIGHT"
|
36
|
-
|
41
|
+
|
37
42
|
FREQUENCY = { DO: 262,
|
38
43
|
DOS: 277,
|
39
44
|
RE: 294,
|
@@ -58,7 +63,7 @@ class Mi100
|
|
58
63
|
HLA: 880,
|
59
64
|
HSI: 988,
|
60
65
|
}
|
61
|
-
|
66
|
+
|
62
67
|
def initialize(dev)
|
63
68
|
retries_left = DEFAULT_RETRIES
|
64
69
|
begin
|
@@ -70,87 +75,111 @@ class Mi100
|
|
70
75
|
puts "Bluetooth connection failed."
|
71
76
|
raise
|
72
77
|
end
|
73
|
-
|
78
|
+
|
74
79
|
end
|
75
|
-
|
80
|
+
|
76
81
|
def close
|
77
82
|
sleep 2
|
78
83
|
@sp.close
|
79
84
|
end
|
80
|
-
|
85
|
+
|
81
86
|
def ping
|
82
87
|
send_command_get_response CMD_PING
|
83
88
|
end
|
84
|
-
|
89
|
+
|
85
90
|
def power
|
86
91
|
response = send_command_get_response CMD_GET_POWER_LEVEL
|
87
92
|
voltage = response[1].to_i / 1000.0
|
88
93
|
voltage.round 2
|
89
94
|
end
|
90
|
-
|
95
|
+
|
91
96
|
def light
|
92
97
|
response = send_command_get_response CMD_GET_LIGHT
|
93
98
|
response[1].to_i
|
94
99
|
end
|
95
|
-
|
100
|
+
|
96
101
|
def move(direction = DEFAULT_MOVE_DIRECTION, duration = DEFAULT_MOVE_DURATION)
|
97
102
|
cmd = direction.upcase == "BACKWARD" ? CMD_MOVE_BACKWARD : CMD_MOVE_FORWARD
|
98
103
|
send_command_get_response "#{cmd},#{duration.to_s}"
|
99
104
|
end
|
100
|
-
|
105
|
+
|
101
106
|
def spin(direction = DEFAULT_SPIN_DIRECTION, duration = DEFAULT_SPIN_DURATION)
|
102
107
|
cmd = direction.upcase == "LEFT" ? CMD_SPIN_LEFT : CMD_SPIN_RIGHT
|
103
108
|
send_command_get_response "#{cmd},#{duration.to_s}"
|
104
|
-
end
|
105
|
-
|
109
|
+
end
|
110
|
+
|
106
111
|
def move_forward(duration)
|
107
112
|
send_command_get_response "#{CMD_MOVE_FORWARD},#{duration.to_s}"
|
108
113
|
end
|
109
|
-
|
114
|
+
|
110
115
|
def move_backward(duration)
|
111
116
|
send_command_get_response "#{CMD_MOVE_BACKWARD},#{duration.to_s}"
|
112
117
|
end
|
113
|
-
|
118
|
+
|
114
119
|
def spin_right(duration)
|
115
120
|
send_command_get_response "#{CMD_SPIN_RIGHT},#{duration.to_s}"
|
116
121
|
end
|
117
|
-
|
122
|
+
|
118
123
|
def spin_left(duration)
|
119
124
|
send_command_get_response "#{CMD_SPIN_LEFT},#{duration.to_s}"
|
120
125
|
end
|
121
|
-
|
126
|
+
|
127
|
+
def turn_right(duration)
|
128
|
+
send_command_get_response "#{CMD_TURN_RIGHT},#{duration.to_s}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def turn_left(duration)
|
132
|
+
send_command_get_response "#{CMD_TURN_LEFT},#{duration.to_s}"
|
133
|
+
end
|
134
|
+
|
122
135
|
def movef(duration = DEFAULT_MOVE_DURATION)
|
123
136
|
move_forward duration
|
124
137
|
end
|
125
|
-
|
138
|
+
|
126
139
|
def moveb(duration = DEFAULT_MOVE_DURATION)
|
127
140
|
move_backward duration
|
128
141
|
end
|
129
|
-
|
142
|
+
|
130
143
|
def spinr(duration = DEFAULT_SPIN_DURATION)
|
131
144
|
spin_right duration
|
132
145
|
end
|
133
|
-
|
146
|
+
|
134
147
|
def spinl(duration = DEFAULT_SPIN_DURATION)
|
135
148
|
spin_left duration
|
136
149
|
end
|
137
|
-
|
150
|
+
|
138
151
|
def move_forward!(duration)
|
139
152
|
sendln "#{CMD_MOVE_FORWARD},#{duration.to_s}"
|
140
153
|
end
|
141
|
-
|
154
|
+
|
142
155
|
def move_backward!(duration)
|
143
156
|
sendln "#{CMD_MOVE_BACKWARD},#{duration.to_s}"
|
144
157
|
end
|
145
|
-
|
158
|
+
|
146
159
|
def spin_right!(duration)
|
147
160
|
sendln "#{CMD_SPIN_RIGHT},#{duration.to_s}"
|
148
161
|
end
|
149
|
-
|
162
|
+
|
150
163
|
def spin_left!(duration)
|
151
164
|
sendln "#{CMD_SPIN_LEFT},#{duration.to_s}"
|
152
165
|
end
|
153
|
-
|
166
|
+
|
167
|
+
def turn_right!(duration)
|
168
|
+
sendln "#{CMD_TURN_RIGHT},#{duration.to_s}"
|
169
|
+
end
|
170
|
+
|
171
|
+
def turn_left!(duration)
|
172
|
+
sendln "#{CMD_TURN_LEFT},#{duration.to_s}"
|
173
|
+
end
|
174
|
+
|
175
|
+
def speed(pwm_value = DEFAULT_SPEED)
|
176
|
+
send_command_get_response "#{CMD_SET_SPEED},#{pwm_value.to_s}"
|
177
|
+
end
|
178
|
+
|
179
|
+
def free_ram
|
180
|
+
send_command_get_response "#{CMD_FREE_RAM}"
|
181
|
+
end
|
182
|
+
|
154
183
|
def blink(r = nil, g = nil, b = nil, duration = DEFAULT_BLINK_DURATION)
|
155
184
|
r ||= rand(100)+1
|
156
185
|
g ||= rand(100)+1
|
@@ -164,27 +193,27 @@ class Mi100
|
|
164
193
|
def stop
|
165
194
|
send_command_get_response CMD_STOP
|
166
195
|
end
|
167
|
-
|
196
|
+
|
168
197
|
def tone(frequency = nil, duration = DEFAULT_TONE_DURATION)
|
169
198
|
frequency ||= rand(4186 - 28) + 28
|
170
199
|
frequency = 4186 if frequency > 4186
|
171
200
|
frequency = 28 if frequency < 28
|
172
201
|
send_command_get_response "#{CMD_TONE},#{frequency.to_s},#{duration.to_s}"
|
173
202
|
end
|
174
|
-
|
203
|
+
|
175
204
|
def sound(pitch = "?", duration = DEFAULT_TONE_DURATION)
|
176
|
-
|
205
|
+
|
177
206
|
if pitch.instance_of?(String)
|
178
207
|
pitch = FREQUENCY.keys[rand(FREQUENCY.size)].to_s if pitch == "?"
|
179
208
|
frequency = FREQUENCY[pitch.upcase.to_sym]
|
180
209
|
else
|
181
210
|
frequency = pitch
|
182
211
|
end
|
183
|
-
|
212
|
+
|
184
213
|
tone frequency, duration if frequency
|
185
214
|
sleep duration.to_f / 1000.0
|
186
215
|
end
|
187
|
-
|
216
|
+
|
188
217
|
def good
|
189
218
|
freqs = [440,880,1760]
|
190
219
|
duration = 100.0
|
@@ -193,38 +222,38 @@ class Mi100
|
|
193
222
|
sleep duration / 1000.0
|
194
223
|
end
|
195
224
|
end
|
196
|
-
|
225
|
+
|
197
226
|
def bad
|
198
227
|
duration = 400.0
|
199
228
|
freq = 100
|
200
229
|
tone freq, duration
|
201
230
|
sleep duration / 1000.0
|
202
231
|
end
|
203
|
-
|
232
|
+
|
204
233
|
def talk(str)
|
205
234
|
morsecoder = Morsecoder.new str
|
206
235
|
morsecoder.each {|frequency, duration| sound(frequency,duration)}
|
207
236
|
end
|
208
|
-
|
237
|
+
|
209
238
|
def morse_frequency
|
210
239
|
Morsecoder.default_frequency
|
211
240
|
end
|
212
|
-
|
241
|
+
|
213
242
|
def morse_frequency=(frequency)
|
214
243
|
Morsecoder.default_frequency = frequency
|
215
244
|
end
|
216
|
-
|
245
|
+
|
217
246
|
def morse_unit
|
218
247
|
Morsecoder.default_unit
|
219
248
|
end
|
220
|
-
|
249
|
+
|
221
250
|
def morse_unit=(millisec)
|
222
251
|
Morsecoder.default_unit = millisec
|
223
252
|
end
|
224
|
-
|
253
|
+
|
225
254
|
# Private methods
|
226
255
|
private
|
227
|
-
|
256
|
+
|
228
257
|
def initialize_serialport(dev)
|
229
258
|
require 'serialport'
|
230
259
|
@sp = SerialPort.new dev, 38400, 8, 1, SerialPort::NONE
|
@@ -233,8 +262,8 @@ class Mi100
|
|
233
262
|
@sp.write_timeout = WRITE_TIMEOUT
|
234
263
|
end
|
235
264
|
end
|
236
|
-
|
237
|
-
|
265
|
+
|
266
|
+
|
238
267
|
def send_command_get_response(cmd = CMD_PING)
|
239
268
|
empty_receive_buffer
|
240
269
|
sendln cmd
|
@@ -249,11 +278,11 @@ class Mi100
|
|
249
278
|
end
|
250
279
|
received_line.chomp.split(",")
|
251
280
|
end
|
252
|
-
|
281
|
+
|
253
282
|
def sendln str
|
254
283
|
@sp.write str + "\n"
|
255
284
|
end
|
256
|
-
|
285
|
+
|
257
286
|
def empty_receive_buffer
|
258
287
|
@sp.read_timeout = SHORT_READ_TIMEOUT
|
259
288
|
begin
|
@@ -261,7 +290,7 @@ class Mi100
|
|
261
290
|
end while char && char.length > 0
|
262
291
|
@sp.read_timeout = READ_TIMEOUT
|
263
292
|
end
|
264
|
-
|
293
|
+
|
265
294
|
def receiveln
|
266
295
|
if is_windows?
|
267
296
|
start_time = Time.now
|
@@ -282,5 +311,5 @@ class Mi100
|
|
282
311
|
def is_windows?
|
283
312
|
os = RUBY_PLATFORM.split("-")[1]
|
284
313
|
os == 'mswin' or os == 'bccwin' or os == 'mingw' or os == 'mingw32'
|
285
|
-
end
|
314
|
+
end
|
286
315
|
end
|
data/spec/mi100_spec.rb
CHANGED
@@ -14,41 +14,41 @@ describe Mi100 do
|
|
14
14
|
mi100 = Mi100.new "COM5"
|
15
15
|
expect(mi100).to be_a Mi100
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it 'should send "H" on :ping' do
|
19
19
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_PING,1234])
|
20
20
|
mi100 = Mi100.new "COM5"
|
21
21
|
expect(mi100.ping).to eq(["H",1234])
|
22
22
|
expect(mi100).to have_received(:send_command_get_response).with("H")
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it 'should send "H" and return rounded power level on :power' do
|
26
26
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_GET_POWER_LEVEL,1188])
|
27
27
|
mi100 = Mi100.new "COM5"
|
28
28
|
expect(mi100.power).to eq(1.19)
|
29
29
|
expect(mi100).to have_received(:send_command_get_response).with("H")
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it 'should send "P" and get light level on :light' do
|
33
33
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_GET_LIGHT,1188])
|
34
34
|
mi100 = Mi100.new "COM5"
|
35
35
|
expect(mi100.light).to eq(1188)
|
36
36
|
expect(mi100).to have_received(:send_command_get_response).with("P")
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it 'should send "F,duration" on :move with "FORWARD"' do
|
40
40
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_MOVE_FORWARD,1234])
|
41
41
|
mi100 = Mi100.new "COM5"
|
42
42
|
expect(mi100.move "FORWARD").to eq(["F",1234])
|
43
43
|
expect(mi100).to have_received(:send_command_get_response).with("F,300")
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it 'should send "B,duration" on move "BACKWARD"' do
|
47
47
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_MOVE_BACKWARD,1234])
|
48
48
|
mi100 = Mi100.new "COM5"
|
49
49
|
expect(mi100.move "BACKWARD").to eq(["B",1234])
|
50
50
|
expect(mi100).to have_received(:send_command_get_response).with("B,300")
|
51
|
-
end
|
51
|
+
end
|
52
52
|
|
53
53
|
it 'should send "R,140" on spin "RIGHT"' do
|
54
54
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_SPIN_RIGHT,1234])
|
@@ -77,34 +77,48 @@ describe Mi100 do
|
|
77
77
|
expect(mi100.move_backward 500).to eq(["B",1234])
|
78
78
|
expect(mi100).to have_received(:send_command_get_response).with("B,500")
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it 'should send "R,duration" spin_right duration' do
|
82
82
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_SPIN_RIGHT,1234])
|
83
83
|
mi100 = Mi100.new "COM5"
|
84
84
|
expect(mi100.spin_right 500).to eq(["R",1234])
|
85
85
|
expect(mi100).to have_received(:send_command_get_response).with("R,500")
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it 'should send "L,duration" on spin_left duration' do
|
89
89
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_SPIN_LEFT,1234])
|
90
90
|
mi100 = Mi100.new "COM5"
|
91
91
|
expect(mi100.spin_left 500).to eq(["L",1234])
|
92
92
|
expect(mi100).to have_received(:send_command_get_response).with("L,500")
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
|
+
it 'should send "U,duration" on turn_right duration' do
|
96
|
+
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_TURN_RIGHT,1234])
|
97
|
+
mi100 = Mi100.new "COM5"
|
98
|
+
expect(mi100.turn_right 500).to eq(["U",1234])
|
99
|
+
expect(mi100).to have_received(:send_command_get_response).with("U,500")
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should send "A,duration" on turn_left duration' do
|
103
|
+
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_TURN_LEFT,1234])
|
104
|
+
mi100 = Mi100.new "COM5"
|
105
|
+
expect(mi100.turn_left 500).to eq(["A",1234])
|
106
|
+
expect(mi100).to have_received(:send_command_get_response).with("A,500")
|
107
|
+
end
|
108
|
+
|
95
109
|
it 'should send "F, 300" on movef' do
|
96
110
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_MOVE_FORWARD,1234])
|
97
111
|
mi100 = Mi100.new "COM5"
|
98
112
|
expect(mi100.movef).to eq(["F",1234])
|
99
113
|
expect(mi100).to have_received(:send_command_get_response).with("F,300")
|
100
114
|
end
|
101
|
-
|
115
|
+
|
102
116
|
it 'should send "B,300" on moveb' do
|
103
117
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_MOVE_BACKWARD,1234])
|
104
118
|
mi100 = Mi100.new "COM5"
|
105
119
|
expect(mi100.moveb).to eq(["B",1234])
|
106
120
|
expect(mi100).to have_received(:send_command_get_response).with("B,300")
|
107
|
-
end
|
121
|
+
end
|
108
122
|
|
109
123
|
it 'should send "R,140" spinr' do
|
110
124
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_SPIN_RIGHT,1234])
|
@@ -126,27 +140,62 @@ describe Mi100 do
|
|
126
140
|
expect(mi100.move_forward! 500).to eq(6)
|
127
141
|
expect(mi100).to have_received(:sendln).with("F,500")
|
128
142
|
end
|
129
|
-
|
143
|
+
|
130
144
|
it 'should send "B,duration" on move_backward! duration in async' do
|
131
145
|
Mi100.any_instance.stub(:sendln => 6)
|
132
146
|
mi100 = Mi100.new "COM5"
|
133
147
|
expect(mi100.move_backward! 500).to eq(6)
|
134
148
|
expect(mi100).to have_received(:sendln).with("B,500")
|
135
149
|
end
|
136
|
-
|
137
|
-
|
150
|
+
|
151
|
+
it 'should send "R,duration" on spin_right! duration in async' do
|
138
152
|
Mi100.any_instance.stub(:sendln => 6)
|
139
153
|
mi100 = Mi100.new "COM5"
|
140
154
|
expect(mi100.spin_right! 500).to eq(6)
|
141
155
|
expect(mi100).to have_received(:sendln).with("R,500")
|
142
156
|
end
|
143
|
-
|
157
|
+
|
144
158
|
it 'should send "L,duration" on spin_left! duration in async' do
|
145
159
|
Mi100.any_instance.stub(:sendln => 6)
|
146
160
|
mi100 = Mi100.new "COM5"
|
147
161
|
expect(mi100.spin_left! 500).to eq(6)
|
148
162
|
expect(mi100).to have_received(:sendln).with("L,500")
|
149
|
-
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should send "U,duration" on turn_right! duration in async' do
|
166
|
+
Mi100.any_instance.stub(:sendln => 6)
|
167
|
+
mi100 = Mi100.new "COM5"
|
168
|
+
expect(mi100.turn_right! 500).to eq(6)
|
169
|
+
expect(mi100).to have_received(:sendln).with("U,500")
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should send "A,duration" on turn_left! duration in async' do
|
173
|
+
Mi100.any_instance.stub(:sendln => 6)
|
174
|
+
mi100 = Mi100.new "COM5"
|
175
|
+
expect(mi100.turn_left! 500).to eq(6)
|
176
|
+
expect(mi100).to have_received(:sendln).with("A,500")
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should send "W,pwm_value" on speed pwm_value' do
|
180
|
+
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_SET_SPEED,1234])
|
181
|
+
mi100 = Mi100.new "COM5"
|
182
|
+
expect(mi100.speed 500).to eq(["W",1234])
|
183
|
+
expect(mi100).to have_received(:send_command_get_response).with("W,500")
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should reset default speed' do
|
187
|
+
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_SET_SPEED,1234])
|
188
|
+
mi100 = Mi100.new "COM5"
|
189
|
+
expect(mi100.speed).to eq(["W",1234])
|
190
|
+
expect(mi100).to have_received(:send_command_get_response).with("W,1023")
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should send "M" and get free ram memory area on :free_ram' do
|
194
|
+
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_FREE_RAM,1234])
|
195
|
+
mi100 = Mi100.new "COM5"
|
196
|
+
expect(mi100.free_ram).to eq(["M",1234])
|
197
|
+
expect(mi100).to have_received(:send_command_get_response).with("M")
|
198
|
+
end
|
150
199
|
|
151
200
|
it 'should send "D,100, 50, 50,duration on blink 100,50,50,duration' do
|
152
201
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_BLINK_LED,1234])
|
@@ -168,72 +217,72 @@ describe Mi100 do
|
|
168
217
|
expect(mi100.tone).to eq(["T",1234])
|
169
218
|
expect(mi100).to have_received(:send_command_get_response).with(/T,\d{2,4},300/)
|
170
219
|
end
|
171
|
-
|
220
|
+
|
172
221
|
it 'should limit minimum tone frequency to 28 on tome' do
|
173
222
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_TONE,1234])
|
174
223
|
mi100 = Mi100.new "COM5"
|
175
224
|
mi100.tone 20, 500
|
176
225
|
expect(mi100).to have_received(:send_command_get_response).with("T,28,500")
|
177
226
|
end
|
178
|
-
|
227
|
+
|
179
228
|
it 'should send "T,440,1000" on sound "la", 1000' do
|
180
229
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_TONE,1234])
|
181
230
|
mi100 = Mi100.new "COM5"
|
182
231
|
mi100.sound "la",1000
|
183
232
|
expect(mi100).to have_received(:send_command_get_response).with("T,440,1000")
|
184
|
-
end
|
233
|
+
end
|
185
234
|
|
186
235
|
it 'sound should not call tone with false frequency' do
|
187
236
|
mi100 = Mi100.new "COM5"
|
188
237
|
mi100.stub(:tone)
|
189
238
|
mi100.sound false, 300
|
190
239
|
expect(mi100).not_to have_received(:tone)
|
191
|
-
end
|
240
|
+
end
|
192
241
|
|
193
242
|
it 'should send three good tones on good' do
|
194
243
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_TONE,1234])
|
195
244
|
mi100 = Mi100.new "COM5"
|
196
245
|
mi100.good
|
197
246
|
expect(mi100).to have_received(:send_command_get_response).exactly(3).times
|
198
|
-
end
|
199
|
-
|
247
|
+
end
|
248
|
+
|
200
249
|
it 'should send one bad tone on bad' do
|
201
250
|
Mi100.any_instance.stub(:send_command_get_response => [Mi100::CMD_TONE,1234])
|
202
251
|
mi100 = Mi100.new "COM5"
|
203
252
|
mi100.bad
|
204
253
|
expect(mi100).to have_received(:send_command_get_response).once
|
205
|
-
end
|
206
|
-
|
254
|
+
end
|
255
|
+
|
207
256
|
it 'should talk morse code' do
|
208
257
|
mi100 = Mi100.new "COM5"
|
209
258
|
mi100.stub(:tone)
|
210
259
|
mi100.talk "sos"
|
211
260
|
expect(mi100).to have_received(:tone).exactly(6).times.with(4000,50)
|
212
261
|
expect(mi100).to have_received(:tone).exactly(3).times.with(4000,150)
|
213
|
-
end
|
214
|
-
|
262
|
+
end
|
263
|
+
|
215
264
|
it 'should access to morse_frequency' do
|
216
265
|
mi100 = Mi100.new "COM5"
|
217
266
|
expect(mi100.morse_frequency).to eq(4000)
|
218
267
|
expect(mi100.morse_frequency = 440).to eq(440)
|
219
268
|
expect(mi100.morse_frequency).to eq(440)
|
220
|
-
end
|
221
|
-
|
269
|
+
end
|
270
|
+
|
222
271
|
it 'should access to morse_unit' do
|
223
272
|
mi100 = Mi100.new "COM5"
|
224
273
|
expect(mi100.morse_unit).to eq(50)
|
225
274
|
expect(mi100.morse_unit = 100).to eq(100)
|
226
275
|
expect(mi100.morse_unit).to eq(100)
|
227
276
|
end
|
228
|
-
|
277
|
+
|
229
278
|
it 'should talk with new default frequency and unit' do
|
230
279
|
mi100 = Mi100.new "COM5"
|
231
280
|
mi100.stub(:tone)
|
232
281
|
mi100.talk "sos"
|
233
282
|
expect(mi100).to have_received(:tone).exactly(6).times.with(440,100)
|
234
283
|
expect(mi100).to have_received(:tone).exactly(3).times.with(440,300)
|
235
|
-
end
|
236
|
-
|
284
|
+
end
|
285
|
+
|
237
286
|
it 'should reset default frequency and unit' do
|
238
287
|
Mi100::Morsecoder.reset
|
239
288
|
expect(Mi100::Morsecoder.default_frequency).to eq(4000)
|
@@ -242,11 +291,11 @@ describe Mi100 do
|
|
242
291
|
expect(mi100.morse_frequency).to eq(4000)
|
243
292
|
expect(mi100.morse_unit).to eq(50)
|
244
293
|
end
|
245
|
-
|
294
|
+
|
246
295
|
it 'should provide Morsecode.to_morse_from class method converting the string to the morse code array' do
|
247
296
|
morsecode = Mi100::Morsecoder.to_morse_from "sos"
|
248
297
|
expect(morsecode.size).to eq(21)
|
249
298
|
expect(morsecode[0]).to eq ({:frequency=>4000, :duration=>50})
|
250
|
-
end
|
251
|
-
|
299
|
+
end
|
300
|
+
|
252
301
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mi100
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &15936960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15936960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &15936696 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15936696
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &15936420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *15936420
|
47
47
|
description: A ruby gem for controlling MI100 of monoxit through bluetooth virtual
|
48
48
|
serial port.
|
49
49
|
email:
|