class EstormButton::Button

Public Class Methods

held() click to toggle source
# File lib/estorm_button/button.rb, line 22
def self.held
puts "button HELD: "
end
led_mgr(cmd) click to toggle source
# File lib/estorm_button/button.rb, line 17
def self.led_mgr(cmd)
  @@led.on
  cmd
  @@led.off
end
tap() click to toggle source
# File lib/estorm_button/button.rb, line 8
def self.tap
puts "button TAPPED"
end
test_flag() click to toggle source
# File lib/estorm_button/button.rb, line 11
def self.test_flag
  true
end

Public Instance Methods

bootup() click to toggle source
# File lib/estorm_button/button.rb, line 14
def bootup
puts " bootup script"
end
manage_buttons() click to toggle source

ADD MUTEX TO MANAGE TIME

# File lib/estorm_button/button.rb, line 26
def manage_buttons
  bootup
  @@pin=PiPiper::Pin.new(:pin => 23, :pull => :up)
  @@led=PiPiper::Pin.new(:pin => 18, :direction => :out)
  @@led.on
  @@t=Time.now
  PiPiper.watch :pin => 23,:trigger => :falling , :pull => :up do
    #puts "Button pressed changed from #{last_value} to #{value}"
    #puts "."
    @@t=Time.now
  end
  PiPiper.watch :pin => 23,:trigger => :rising , :pull => :up do
    delta = Time.now.to_f - @@t.to_f
    @@t = Time.now
    EstormLottoGem::Button.led_mgr(EstormLottoGem::Button.tap()) if 0.03 <= delta and delta < 0.7
    EstormLottoGem::Button.led_mgr(EstormLottoGem::Button.held())  if 2 < delta and  delta < 20
    #puts "debounce" if 0.1 > delta
  end
  sleep 5
 
  @@led.off
  @@t=Time.now
  PiPiper.wait
end