Class: RPicSim::Pin
- Inherits:
-
Object
- Object
- RPicSim::Pin
- Defined in:
- lib/rpicsim/pin.rb
Overview
This class represents an external pin of the simulated device. It provides methods for reading the pin's output value and setting its input value.
Instance Method Summary collapse
-
#driving_high? ⇒ Boolean
Returns true if the pin is currently configured to be an output and it is driving high.
-
#driving_low? ⇒ Boolean
Returns true if the pin is currently configured to be an output and it is driving low.
-
#input? ⇒ Boolean
Returns true if the pin is currently configured to be an input.
- #inspect ⇒ String
-
#names ⇒ String
Returns an array of all the pin's names from the datasheet, like “RA4” or “TX”.
-
#output? ⇒ Boolean
Returns true if the pin is currently configured to be an output.
-
#set(state) ⇒ Object
Sets the external stimulus input voltage applied to the pin.
- #to_s ⇒ String
Instance Method Details
#driving_high? ⇒ Boolean
Returns true if the pin is currently configured to be an output and it is driving high.
41 42 43 |
# File 'lib/rpicsim/pin.rb', line 41 def driving_high? output? && @mplab_pin.high? end |
#driving_low? ⇒ Boolean
Returns true if the pin is currently configured to be an output and it is driving low.
47 48 49 |
# File 'lib/rpicsim/pin.rb', line 47 def driving_low? output? && !@mplab_pin.high? end |
#input? ⇒ Boolean
Returns true if the pin is currently configured to be an input.
35 36 37 |
# File 'lib/rpicsim/pin.rb', line 35 def input? !@mplab_pin.output? end |
#inspect ⇒ String
64 65 66 |
# File 'lib/rpicsim/pin.rb', line 64 def inspect '#<%s %s>' % [self.class, to_s] end |
#names ⇒ String
Returns an array of all the pin's names from the datasheet, like “RA4” or “TX”.
54 55 56 |
# File 'lib/rpicsim/pin.rb', line 54 def names @mplab_pin.names end |
#output? ⇒ Boolean
Returns true if the pin is currently configured to be an output.
30 31 32 |
# File 'lib/rpicsim/pin.rb', line 30 def output? @mplab_pin.output? end |
#set(state) ⇒ Object
Sets the external stimulus input voltage applied to the pin. The boolean values true and false correspond to high and low, respectively. Numeric values (e.g. Float or Integer) correspond to analog voltages.
20 21 22 23 24 25 26 27 |
# File 'lib/rpicsim/pin.rb', line 20 def set(state) case state when false then @mplab_pin.set_low when true then @mplab_pin.set_high when Numeric then @mplab_pin.set_analog(state) else raise ArgumentError, "Invalid pin state: #{state.inspect}." end end |
#to_s ⇒ String
59 60 61 |
# File 'lib/rpicsim/pin.rb', line 59 def to_s @mplab_pin.name end |