Class: Dino::Components::Button
Constant Summary
collapse
- UP =
"01"
- DOWN =
"00"
Instance Attribute Summary
#board, #pin, #pullup
Instance Method Summary
collapse
#initialize
Instance Method Details
#after_initialize(options = {}) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/dino/components/button.rb', line 7
def after_initialize(options={})
@down_callbacks, @up_callbacks, @state = [], [], UP
self.board.add_digital_hardware(self)
self.board.start_read
end
|
#down(&callback) ⇒ Object
14
15
16
|
# File 'lib/dino/components/button.rb', line 14
def down(&callback)
@down_callbacks << callback
end
|
#up(&callback) ⇒ Object
18
19
20
|
# File 'lib/dino/components/button.rb', line 18
def up(&callback)
@up_callbacks << callback
end
|
#update(data) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/dino/components/button.rb', line 22
def update(data)
return if data == @state
@state = data
case data
when UP
button_up
when DOWN
button_down
else
return
end
end
|