Class: RPicSim::Pin

Inherits:
Object
  • Object
show all
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

Instance Method Details

#driving_high?Boolean

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

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


35
36
37
# File 'lib/rpicsim/pin.rb', line 35

def input?
  !@mplab_pin.output?
end

#inspectString

Returns:

  • (String)


64
65
66
# File 'lib/rpicsim/pin.rb', line 64

def inspect
  '#<%s %s>' % [self.class, to_s]
end

#namesString

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

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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_sString

Returns:

  • (String)


59
60
61
# File 'lib/rpicsim/pin.rb', line 59

def to_s
  @mplab_pin.name
end