Class: BBB::Pins::DigitalPin
- Inherits:
-
Object
- Object
- BBB::Pins::DigitalPin
- Includes:
- Pinnable
- Defined in:
- lib/BBB/pins/digital_pin.rb
Overview
A Digital Pin on the board. The digital pins uses GPIO on the filesystem to communicate. This class assumes its the only actor on the pin. Therfore it can cache the status in memory instead of reading it from the filesystem every time.
It is advised to use the DigitalInputPin and DigitalOutputPin classes for clarity, buy, nothings stops you from using a DigitalPin with the :input or :output direction.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#status ⇒ Symbol
readonly
Read value from the pin for input pins, or from memory for output pins.
Attributes included from Pinnable
Instance Method Summary collapse
-
#direction ⇒ Symbol
Gets the direction of the pin from the options and memoizes it in the.
-
#off! ⇒ void
Set the pin into :low state.
-
#off? ⇒ Boolean
Check if the pin state is low.
-
#on! ⇒ void
Set the pin into :high state.
-
#on? ⇒ Boolean
Check if the pin state is high.
-
#write(value) ⇒ Object
Write value to the specified pin Digitally.
Methods included from Pinnable
#initialize, #io, #mock?, #pinnable?
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
16 17 18 |
# File 'lib/BBB/pins/digital_pin.rb', line 16 def opts @opts end |
#status ⇒ Symbol (readonly)
Read value from the pin for input pins, or from memory for output pins.
42 43 44 |
# File 'lib/BBB/pins/digital_pin.rb', line 42 def status @status end |
Instance Method Details
#direction ⇒ Symbol
Gets the direction of the pin from the options and memoizes it in the
23 24 25 |
# File 'lib/BBB/pins/digital_pin.rb', line 23 def direction @direction ||= @opts.fetch(:direction) end |
#off! ⇒ void
This method returns an undefined value.
Set the pin into :low state
60 61 62 |
# File 'lib/BBB/pins/digital_pin.rb', line 60 def off! write(:low) end |
#off? ⇒ Boolean
Check if the pin state is low
74 75 76 |
# File 'lib/BBB/pins/digital_pin.rb', line 74 def off? !on? end |
#on! ⇒ void
This method returns an undefined value.
Set the pin into :high state
53 54 55 |
# File 'lib/BBB/pins/digital_pin.rb', line 53 def on! write(:high) end |
#on? ⇒ Boolean
Check if the pin state is high
67 68 69 |
# File 'lib/BBB/pins/digital_pin.rb', line 67 def on? status == :high end |
#write(value) ⇒ Object
Write value to the specified pin Digitally. This might fail hard if you try to write to an input pin. However, for performance reasons we do not want to check the direction of the pin every write.
32 33 34 35 |
# File 'lib/BBB/pins/digital_pin.rb', line 32 def write(value) @status = value io.write(value) end |