Class: Tochka::PiTFTButton

Inherits:
Object
  • Object
show all
Defined in:
lib/tochka/pitft_button.rb

Constant Summary collapse

PIN1 =
4
PIN2 =
3
PIN3 =
2
PIN4 =
1
PIN_MODE_INPUT =
0

Instance Method Summary collapse

Constructor Details

#initializePiTFTButton

Returns a new instance of PiTFTButton.



12
13
14
15
16
17
18
19
20
21
# File 'lib/tochka/pitft_button.rb', line 12

def initialize
  if ENV['BUTTON_MOCK'] != nil
    dummy_init
  else
    real_init
  end

  @prev = [false, false, false, false]

end

Instance Method Details

#backlight_offObject



77
78
79
# File 'lib/tochka/pitft_button.rb', line 77

def backlight_off
  set_backlight(0)
end

#backlight_onObject



73
74
75
# File 'lib/tochka/pitft_button.rb', line 73

def backlight_on
  set_backlight(1)
end

#button1Object



42
43
44
# File 'lib/tochka/pitft_button.rb', line 42

def button1
  read_button(PIN1)
end

#button2Object



46
47
48
# File 'lib/tochka/pitft_button.rb', line 46

def button2
  read_button(PIN2)
end

#button3Object



50
51
52
# File 'lib/tochka/pitft_button.rb', line 50

def button3
  read_button(PIN3)
end

#button4Object



54
55
56
# File 'lib/tochka/pitft_button.rb', line 54

def button4
  read_button(PIN4)
end

#button_allObject



38
39
40
# File 'lib/tochka/pitft_button.rb', line 38

def button_all
  return [button1, button2, button3, button4]
end

#button_all_edgeObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tochka/pitft_button.rb', line 58

def button_all_edge
  buttons = button_all()
  edges = []
  0.upto(3) do |n|
    if buttons[n] == true and buttons[n] != @prev[n]
      edges[n] = true
    else
      edges[n] = false
    end
  end

  @prev = buttons
  return edges
end

#dummy_initObject



23
24
25
# File 'lib/tochka/pitft_button.rb', line 23

def dummy_init
  # do nothing
end

#real_initObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/tochka/pitft_button.rb', line 27

def real_init
  @io = WiringPi::GPIO.new

  [PIN1, PIN2, PIN3, PIN4].each do |pin|
    @io.pin_mode(pin, PIN_MODE_INPUT)
    @io.pull_up_dn_control(pin, WiringPi::PUD_UP)
  end

  backlight_on()
end