Class: Shutter3

Inherits:
Object
  • Object
show all
Defined in:
lib/shutter3.rb

Instance Method Summary collapse

Constructor Details

#initialize(bdid = '', debug: false) ⇒ Shutter3

Returns a new instance of Shutter3.



16
17
18
19
# File 'lib/shutter3.rb', line 16

def initialize(bdid='', debug: false)
  @bdid = bdid.split(':').reverse.join(' ')
  @debug = debug
end

Instance Method Details

#startObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shutter3.rb', line 21

def start()

  button = nil
  found = 0

  IO.popen('sudo hcidump --raw').each_line do |x| 

    case x
    when /#{@bdid}/

      found += 1

      if found > 2 then
        on_connect()
        next
      end
    when /> 04 05 04 00 40 00 08 \n/
      on_disconnect()
      next
    end

    case x[/> 02 40 20 09 00 05 00 04 00 1B (\w+ \w+ \w+ \w+)(?= \n$)/,1]
    when "17 00 00 28"
      on_android_keydown()
      on_android_keypress()
      button = :android
    when "17 00 00 00"
      on_android_keyup()
      button = nil
    when "13 00 01 00"
      next if button == :android
      on_ios_keydown()
      on_ios_keypress()
    when "13 00 00 00"
      next if button == :android
      on_ios_keyup()
    when ""
    end
    puts x.inspect if @debug
  end

end