ir_ptz 0.0.1 → 0.0.2
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.
- data/lib/ir_ptz/command_line.rb +2 -1
- data/lib/ir_ptz/ir_remote.rb +18 -4
- data/lib/ir_ptz/version.rb +1 -1
- data/spec/ir_ptz/ir_remote_spec.rb +9 -0
- metadata +2 -2
data/lib/ir_ptz/command_line.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'io/console'
|
2
|
+
require 'thread'
|
2
3
|
|
3
4
|
module IrPtz
|
4
5
|
class CommandLine
|
@@ -23,7 +24,7 @@ module IrPtz
|
|
23
24
|
ir_command_recorder.record.save
|
24
25
|
else
|
25
26
|
if action = action(key)
|
26
|
-
ir_remote.send action
|
27
|
+
ir_remote.send action
|
27
28
|
else
|
28
29
|
print_instructions
|
29
30
|
end
|
data/lib/ir_ptz/ir_remote.rb
CHANGED
@@ -3,12 +3,14 @@ require 'singleton'
|
|
3
3
|
|
4
4
|
module IrPtz
|
5
5
|
class IrRemote
|
6
|
+
TIME_NEEDED_BETWEEN_IR_BLAST = 0.18 # seconds
|
7
|
+
|
6
8
|
include Singleton
|
7
9
|
|
8
10
|
IrPtz.configuration.actions.keys.each do |action|
|
9
11
|
define_method(action) do
|
10
|
-
if
|
11
|
-
|
12
|
+
if actions.max != actions.size
|
13
|
+
actions.push action
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -31,10 +33,22 @@ module IrPtz
|
|
31
33
|
|
32
34
|
private
|
33
35
|
|
34
|
-
attr_reader :ir
|
36
|
+
attr_reader :ir, :actions, :ir_thread
|
35
37
|
|
36
38
|
def initialize
|
37
|
-
@ir
|
39
|
+
@ir = ArduinoIrRemote.connect IrPtz.configuration.device_path
|
40
|
+
@actions = SizedQueue.new(1)
|
41
|
+
@ir_thread = Thread.new do
|
42
|
+
loop do
|
43
|
+
action = actions.pop(false) # wait for action
|
44
|
+
|
45
|
+
if ir_code = IrPtz.configuration.actions[action]
|
46
|
+
ir.write ir_code
|
47
|
+
end
|
48
|
+
|
49
|
+
sleep TIME_NEEDED_BETWEEN_IR_BLAST
|
50
|
+
end
|
51
|
+
end
|
38
52
|
end
|
39
53
|
end
|
40
54
|
end
|
data/lib/ir_ptz/version.rb
CHANGED
@@ -10,6 +10,13 @@ describe IrPtz::IrRemote do
|
|
10
10
|
ir.stubs(:ir).returns arduino_ir
|
11
11
|
end
|
12
12
|
|
13
|
+
# Helper
|
14
|
+
def wait_for_thread
|
15
|
+
while !ir.send(:actions).empty? do
|
16
|
+
# U G L Y - but it works
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
13
20
|
# concrete example
|
14
21
|
describe 'zoom_in' do
|
15
22
|
before do
|
@@ -19,6 +26,7 @@ describe IrPtz::IrRemote do
|
|
19
26
|
|
20
27
|
it 'sends the zoom in signal to the board' do
|
21
28
|
ir.zoom_in
|
29
|
+
wait_for_thread
|
22
30
|
expect(arduino_ir).to have_received(:write).with 'some value'
|
23
31
|
end
|
24
32
|
end
|
@@ -33,6 +41,7 @@ describe IrPtz::IrRemote do
|
|
33
41
|
|
34
42
|
it 'can send a defined singnal to the board' do
|
35
43
|
ir.send(action)
|
44
|
+
wait_for_thread
|
36
45
|
expect(arduino_ir).to have_received(:write).with 'some value'
|
37
46
|
end
|
38
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ir_ptz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arduino_ir_remote
|