Class: HumbleRPiPluginPhotocell

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

Instance Method Summary collapse

Constructor Details

#initialize(settings: {}, variables: {}) ⇒ HumbleRPiPluginPhotocell

Returns a new instance of HumbleRPiPluginPhotocell.



13
14
15
16
17
18
19
20
21
# File 'lib/humble_rpi-plugin-photocell.rb', line 13

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

  @channel = settings[:channel] || 0
  @threshold = settings[:threshold] || 10
  @notifier = variables[:notifier]
  @device_id = variables[:device_id] || 'pi'
  @photocell = RPiPhotocell.new pin: @channel
  
end

Instance Method Details

#startObject Also known as: on_start



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/humble_rpi-plugin-photocell.rb', line 23

def start()
  
  puts 'ready to monitor photocell'
  
  @notifier.notice "%s/photocell: %s" % [@device_id, val=@photocell.read]
  old_val = val
  
  loop do
    
    val = @photocell.read

    if (old_val - val).abs >= @threshold then
      @notifier.notice "%s/photocell: %s" % [@device_id, val]
      old_val = val        
    end      

    sleep 1
    
  end
        
end