class Shutter3
note: To use hcidump, `apt-get install bluez-hcidump`.
Public Class Methods
new(bdid='', debug: false)
click to toggle source
# File lib/shutter3.rb, line 16 def initialize(bdid='', debug: false) @bdid = bdid @debug = debug end
Public Instance Methods
start()
click to toggle source
# File lib/shutter3.rb, line 21 def start() button = nil found = 0 IO.popen('sudo hcidump --raw -i '+ @bdid).each_line do |x| case x when /#{@bdid.split(':').reverse.join(' ')}/ found += 1 if found > 2 then on_connect() found = 0 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
Protected Instance Methods
on_android_keydown()
click to toggle source
# File lib/shutter3.rb, line 71 def on_android_keydown() end
on_android_keypress()
click to toggle source
# File lib/shutter3.rb, line 67 def on_android_keypress() puts 'android button pressed' end
on_android_keyup()
click to toggle source
# File lib/shutter3.rb, line 74 def on_android_keyup() end
on_connect()
click to toggle source
# File lib/shutter3.rb, line 77 def on_connect() puts 'connected to ' + @bdid end
on_disconnect()
click to toggle source
# File lib/shutter3.rb, line 81 def on_disconnect() puts @bdid + ' disconnected' end
on_ios_keydown()
click to toggle source
# File lib/shutter3.rb, line 89 def on_ios_keydown() end
on_ios_keypress()
click to toggle source
# File lib/shutter3.rb, line 85 def on_ios_keypress() puts 'iOS button pressed' end
on_ios_keyup()
click to toggle source
# File lib/shutter3.rb, line 92 def on_ios_keyup() end