class RPicSim::Pin

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.

@api public

Public Class Methods

new(mplab_pin) click to toggle source

Initializes a new Pin object to wrap the given MplabPin. @param mplab_pin [Mplab::MplabPin] @api private

# File lib/rpicsim/pin.rb, line 12
def initialize(mplab_pin)
  raise ArgumentError, 'mplab_pin is nil' if mplab_pin.nil?
  @mplab_pin = mplab_pin
end

Public Instance Methods

driving_high?() click to toggle source

Returns true if the pin is currently configured to be an output and it is driving high.

# File lib/rpicsim/pin.rb, line 41
def driving_high?
  output? && @mplab_pin.high?
end
driving_low?() click to toggle source

Returns true if the pin is currently configured to be an output and it is driving low.

# File lib/rpicsim/pin.rb, line 47
def driving_low?
  output? && !@mplab_pin.high?
end
input?() click to toggle source

Returns true if the pin is currently configured to be an input.

# File lib/rpicsim/pin.rb, line 35
def input?
  !@mplab_pin.output?
end
inspect() click to toggle source

@return [String]

# File lib/rpicsim/pin.rb, line 64
def inspect
  '#<%s %s>' % [self.class, to_s]
end
names() click to toggle source

Returns an array of all the pin's names from the datasheet, like “RA4” or “TX”. @return [String]

# File lib/rpicsim/pin.rb, line 54
def names
  @mplab_pin.names
end
output?() click to toggle source

Returns true if the pin is currently configured to be an output.

# File lib/rpicsim/pin.rb, line 30
def output?
  @mplab_pin.output?
end
set(state) click to toggle source

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.

# 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() click to toggle source

@return [String]

# File lib/rpicsim/pin.rb, line 59
def to_s
  @mplab_pin.name
end