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



82
83
84
# File 'lib/tochka/pitft_button.rb', line 82

def backlight_off
  set_backlight(0)
end

#backlight_onObject



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

def backlight_on
  set_backlight(1)
end

#button1Object



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

def button1
  read_button(PIN1)
end

#button2Object



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

def button2
  read_button(PIN2)
end

#button3Object



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

def button3
  read_button(PIN3)
end

#button4Object



59
60
61
# File 'lib/tochka/pitft_button.rb', line 59

def button4
  read_button(PIN4)
end

#button_allObject



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

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

#button_all_edgeObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tochka/pitft_button.rb', line 63

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
37
38
39
40
41
# 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

  if !File.exists?("/sys/class/gpio/gpio508")
    system("echo 508 > /sys/class/gpio/export")
    system("echo out > /sys/class/gpio/gpio508/direction")
  end

  backlight_on()
end