Class: EstormButton::Button

Inherits:
Object
  • Object
show all
Includes:
PiPiper
Defined in:
lib/estorm_button/button.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.heldObject



22
23
24
# File 'lib/estorm_button/button.rb', line 22

def self.held
puts "button HELD: "
end

.led_mgr(cmd) ⇒ Object



17
18
19
20
21
# File 'lib/estorm_button/button.rb', line 17

def self.led_mgr(cmd)
  @@led.on
  cmd
  @@led.off
end

.tapObject



8
9
10
# File 'lib/estorm_button/button.rb', line 8

def self.tap
puts "button TAPPED"
end

.test_flagObject



11
12
13
# File 'lib/estorm_button/button.rb', line 11

def self.test_flag
  true
end

Instance Method Details

#bootupObject



14
15
16
# File 'lib/estorm_button/button.rb', line 14

def bootup
puts " bootup script"
end

#manage_buttonsObject

ADD MUTEX TO MANAGE TIME



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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