class HumbleRPiPluginLirc

Public Class Methods

new(settings: {}, variables: {}) click to toggle source
# File lib/humble_rpi-plugin-lirc.rb, line 10
def initialize(settings: {}, variables: {})
  
  @notifier = variables[:notifier]
  @device_id = variables[:device_id] || 'pi'    
  @topic = settings[:topic] || @device_id + '/lirc'
  @device = variables[:device] || '/var/run/lirc/lircd'
  
end

Public Instance Methods

on_start()
Alias for: start
start() click to toggle source
# File lib/humble_rpi-plugin-lirc.rb, line 19
def start()
  
  lirc = LIRC::Client.new  @device
  combi_keys = []
  combination_keys = false

  t = Time.now
  puts 'HumbleRpiPluginLirc ready'
  
  lirc.each_event do |e|
    
    if t + 0.6 < Time.now then   
           
      on_keypress(e.name)
      
      (combination_keys = true; next) if e.name == 'KEY_MODE'        
      
      if combination_keys then          
        
        if e.name == 'KEY_ENTER' then
          
          combination_keys = false
          @notifier.notice "%s: KEYS_%s pressed" % [@topic, combi_keys.join]
          combi_keys = []
        else
          combi_keys << e.name[/[^_]+$/]            
        end
        
      else        
        @notifier.notice "%s: %s pressed" % [@topic, e.name]
      end
    end
    
    t = Time.now
  end
end
Also aliased as: on_start

Private Instance Methods

on_keypress(key) click to toggle source
# File lib/humble_rpi-plugin-lirc.rb, line 60
def on_keypress(key)
end