ir_ptz 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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(key)
27
+ ir_remote.send action
27
28
  else
28
29
  print_instructions
29
30
  end
@@ -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 ir_code = IrPtz.configuration.actions[action]
11
- ir.write ir_code
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 = ArduinoIrRemote.connect IrPtz.configuration.device_path
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
@@ -1,3 +1,3 @@
1
1
  module IrPtz
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.1
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: 2013-10-29 00:00:00.000000000 Z
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