Class: HumbleRPiPluginButton

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

Instance Method Summary collapse

Constructor Details

#initialize(settings: {}, variables: {}) ⇒ 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
# File 'lib/humble_rpi-plugin-button.rb', line 12

def initialize(settings: {}, variables: {})

  @pins = settings[:pins]
  @notifier = variables[:notifier]
  @device_id = variables[:device_id] || 'pi'
    
  at_exit do
    
    @pins.each do |pin|

      uexp = open("/sys/class/gpio/unexport", "w")
      uexp.write(pin)
      uexp.close
    
    end
  end

  
end

Instance Method Details

#startObject Also known as: on_start



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
# File 'lib/humble_rpi-plugin-button.rb', line 32

def start()
  
  notifier = @notifier
  device_id = @device_id
      
  puts 'ready to detect buttons'
  
  @pins.each.with_index do |button, i|
    
    puts 'button %s on GPIO %s enabled ' % [i+1, button]
    
    n = (i+1).to_s
    
    PiPiper.watch :pin => button.to_i, :invert => true do |pin|
      
      notifier.notice "%s/button/%s: value %s" % [device_id, i, pin.value]

    end
    
  end
  
  PiPiper.wait    

  
end