Class: EventMachine::Gpio::Pin

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/em-gpio/pin.rb

Constant Summary collapse

PINS =
0..22
MODES =
[:in, :out]
HIGH =
1
LOW =
0

Constants included from Callbacks

Callbacks::VALID_ON_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#callback

Constructor Details

#initialize(pin, options = {}) ⇒ Pin

Returns a new instance of Pin.



13
14
15
16
17
18
# File 'lib/em-gpio/pin.rb', line 13

def initialize(pin, options={})
  @direction = options[:direction] || :out
  @pin       = pin
  validate
  setup_mode
end

Instance Attribute Details

#directionObject

Returns the value of attribute direction.



11
12
13
# File 'lib/em-gpio/pin.rb', line 11

def direction
  @direction
end

#last_valueObject

Returns the value of attribute last_value.



11
12
13
# File 'lib/em-gpio/pin.rb', line 11

def last_value
  @last_value
end

#pinObject

Returns the value of attribute pin.



11
12
13
# File 'lib/em-gpio/pin.rb', line 11

def pin
  @pin
end

#valueObject

Returns the value of attribute value.



11
12
13
# File 'lib/em-gpio/pin.rb', line 11

def value
  @value
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/em-gpio/pin.rb', line 29

def changed?
  value != last_value
end

#readObject



20
21
22
23
# File 'lib/em-gpio/pin.rb', line 20

def read
  @last_value = value
  @value      = adapter.read
end

#write(value) ⇒ Object



25
26
27
# File 'lib/em-gpio/pin.rb', line 25

def write(value)
  adapter.write(value)
end