Class: HumbleRPiPluginButton

Inherits:
Object
  • Object
show all
Defined in:
lib/humble_rpi-plugin-button.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings: {}, variables: {}, verbose: false) ⇒ HumbleRPiPluginButton

Returns a new instance of HumbleRPiPluginButton.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/humble_rpi-plugin-button.rb', line 12

def initialize(settings: {}, variables: {}, verbose: false)
  
  pins = settings[:pins]
  settings.delete :pins
  
  h1 = {
    capture_rate: 0.25, # seconds
    mode: :default
    }.merge settings

  h2 = {device_id: 'pi'}.merge variables
  
  h3 = {
    pull: :up, 
    subtopic: 'button', 
    descriptor: 'pressed',
    verbose: verbose
  }
      
  h = h1.merge(h2).merge(h3)
  
  @pins = pins.map.with_index do |x,i|
    
    RPiPinInMsgOut.new x, h.merge(index: i+1)
    
  end    
  
end

Instance Method Details

#startObject Also known as: on_start



41
42
43
44
45
46
47
# File 'lib/humble_rpi-plugin-button.rb', line 41

def start()
      
  puts 'ready to detect buttons'
  
  @pins.each {|pin| Thread.new { pin.capture} }

end