Class: Denko::DigitalIO::Input

Inherits:
Object
  • Object
show all
Includes:
Behaviors::InputPin, Behaviors::Listener, Behaviors::Poller, Behaviors::Reader
Defined in:
lib/denko/digital_io/input.rb

Direct Known Subclasses

Button, Sensor::GenericPIR

Instance Attribute Summary

Attributes included from Behaviors::Listener

#divider

Attributes included from Behaviors::Callbacks

#callback_mutex

Attributes included from Behaviors::Threaded

#interrupts_enabled, #thread

Attributes included from Behaviors::SinglePin

#mode, #pin

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::Listener

#listen, #stop

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #initialize, #remove_callback, #update

Methods included from Behaviors::State

#initialize, #state

Methods included from Behaviors::Poller

#poll, #poll_using, #stop

Methods included from Behaviors::Threaded

#enable_interrupts, included, #stop, #stop_thread, #threaded, #threaded_loop

Methods included from Behaviors::Reader

#read, #read_using, #wait_for_read

Methods included from Behaviors::InputPin

#_stop_listener

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Method Details

#_listen(divider = nil) ⇒ Object



19
20
21
22
# File 'lib/denko/digital_io/input.rb', line 19

def _listen(divider=nil)
  @divider = divider || @divider
  board.digital_listen(pin, @divider)
end

#_readObject



15
16
17
# File 'lib/denko/digital_io/input.rb', line 15

def _read
  board.digital_read(pin)
end

#after_initialize(options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/denko/digital_io/input.rb', line 9

def after_initialize(options={})
  super(options)
  @divider = 4
  _listen
end

#high?Boolean

Returns:

  • (Boolean)


40
# File 'lib/denko/digital_io/input.rb', line 40

def high?; state == board.high end

#low?Boolean

Returns:

  • (Boolean)


41
# File 'lib/denko/digital_io/input.rb', line 41

def low?;  state == board.low  end

#on_high(&block) ⇒ Object



24
25
26
27
28
# File 'lib/denko/digital_io/input.rb', line 24

def on_high(&block)
  add_callback(:high) do |data|
    block.call(data) if data.to_i == board.high
  end
end

#on_low(&block) ⇒ Object



30
31
32
33
34
# File 'lib/denko/digital_io/input.rb', line 30

def on_low(&block)
  add_callback(:low) do |data|
    block.call(data) if data.to_i == board.low
  end
end

#pre_callback_filter(value) ⇒ Object



36
37
38
# File 'lib/denko/digital_io/input.rb', line 36

def pre_callback_filter(value)
  value.to_i
end