Class: Tochka::PiTFTButton
- Inherits:
-
Object
- Object
- Tochka::PiTFTButton
- 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
- #backlight_off ⇒ Object
- #backlight_on ⇒ Object
- #button1 ⇒ Object
- #button2 ⇒ Object
- #button3 ⇒ Object
- #button4 ⇒ Object
- #button_all ⇒ Object
- #button_all_edge ⇒ Object
- #dummy_init ⇒ Object
-
#initialize ⇒ PiTFTButton
constructor
A new instance of PiTFTButton.
- #real_init ⇒ Object
Constructor Details
#initialize ⇒ PiTFTButton
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_off ⇒ Object
77 78 79 |
# File 'lib/tochka/pitft_button.rb', line 77 def backlight_off set_backlight(0) end |
#backlight_on ⇒ Object
73 74 75 |
# File 'lib/tochka/pitft_button.rb', line 73 def backlight_on set_backlight(1) end |
#button1 ⇒ Object
42 43 44 |
# File 'lib/tochka/pitft_button.rb', line 42 def (PIN1) end |
#button2 ⇒ Object
46 47 48 |
# File 'lib/tochka/pitft_button.rb', line 46 def (PIN2) end |
#button3 ⇒ Object
50 51 52 |
# File 'lib/tochka/pitft_button.rb', line 50 def (PIN3) end |
#button4 ⇒ Object
54 55 56 |
# File 'lib/tochka/pitft_button.rb', line 54 def (PIN4) end |
#button_all ⇒ Object
38 39 40 |
# File 'lib/tochka/pitft_button.rb', line 38 def return [, , , ] end |
#button_all_edge ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tochka/pitft_button.rb', line 58 def = () edges = [] 0.upto(3) do |n| if [n] == true and [n] != @prev[n] edges[n] = true else edges[n] = false end end @prev = return edges end |
#dummy_init ⇒ Object
23 24 25 |
# File 'lib/tochka/pitft_button.rb', line 23 def dummy_init # do nothing end |
#real_init ⇒ Object
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 |