Module: PiPiper::StubDriver

Extended by:
StubDriver
Includes:
PinValues
Included in:
StubDriver
Defined in:
lib/pi_piper/stub_driver.rb

Constant Summary

Constants included from PinValues

PinValues::GPIO_FSEL_ALT0, PinValues::GPIO_FSEL_ALT1, PinValues::GPIO_FSEL_ALT2, PinValues::GPIO_FSEL_ALT3, PinValues::GPIO_FSEL_ALT4, PinValues::GPIO_FSEL_ALT5, PinValues::GPIO_FSEL_INPT, PinValues::GPIO_FSEL_MASK, PinValues::GPIO_FSEL_OUTP, PinValues::GPIO_HIGH, PinValues::GPIO_LOW, PinValues::GPIO_PUD_DOWN, PinValues::GPIO_PUD_OFF, PinValues::GPIO_PUD_UP, PinValues::PWM_MODE, PinValues::PWM_PIN

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



109
110
111
# File 'lib/pi_piper/stub_driver.rb', line 109

def method_missing(meth, *args, &block)
  puts "Needs Implementation: StubDriver##{meth}"
end

Instance Method Details

#gpio_select_function(pin_number, alt_fun) ⇒ Object



30
31
# File 'lib/pi_piper/stub_driver.rb', line 30

def gpio_select_function(pin_number, alt_fun)
end

#new(options = {}) ⇒ Object Also known as: reset



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pi_piper/stub_driver.rb', line 14

def new(options = {})
  opts = {
      :logger => NullLogger.new
  }.merge(options)

  @logger = opts[:logger]

  @pins = {}

  @spi = {data:[], chip_select:0,}

  self
end

#pin_direction(pin_number) ⇒ Object



45
46
47
# File 'lib/pi_piper/stub_driver.rb', line 45

def pin_direction(pin_number)
  pin(pin_number)[:direction] if @pins[pin_number]
end

#pin_input(pin_number) ⇒ Object



33
34
35
36
37
# File 'lib/pi_piper/stub_driver.rb', line 33

def pin_input(pin_number)
  #@pins[pin_number] = { direction: :in }
  pin(pin_number)[:direction] = :in
  @logger.debug("Pin ##{pin_number} -> Input")
end

#pin_output(pin_number) ⇒ Object



39
40
41
42
43
# File 'lib/pi_piper/stub_driver.rb', line 39

def pin_output(pin_number)
  #@pins[pin_number] = { direction: :in }
  pin(pin_number)[:direction] = :out
  @logger.debug("Pin ##{pin_number} -> Output")
end

#pin_read(pin_number) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/pi_piper/stub_driver.rb', line 92

def pin_read(pin_number)
  val = pin(pin_number)[:value]
  val ||= case pin(pin_number)[:pud]
            when GPIO_PUD_UP   then GPIO_HIGH
            when GPIO_PUD_DOWN then GPIO_LOW
            else nil
          end
end

#pin_set(pin_number, value) ⇒ Object



49
50
51
52
# File 'lib/pi_piper/stub_driver.rb', line 49

def pin_set(pin_number, value)
  pin(pin_number)[:value] = value
  @logger.debug("Pin ##{pin_number} -> #{value}")
end

#pin_set_pud(pin_number, value) ⇒ Object



54
55
56
57
# File 'lib/pi_piper/stub_driver.rb', line 54

def pin_set_pud(pin_number, value)
  pin(pin_number)[:pud] = value
  @logger.debug("PinPUD ##{pin_number} -> #{value}")
end

#pwm_clock(clock_divider) ⇒ Object



59
60
# File 'lib/pi_piper/stub_driver.rb', line 59

def pwm_clock(clock_divider)
end

#pwm_data(channel, data) ⇒ Object



68
69
# File 'lib/pi_piper/stub_driver.rb', line 68

def pwm_data(channel, data)
end

#pwm_mode(channel, mode, start) ⇒ Object



62
63
# File 'lib/pi_piper/stub_driver.rb', line 62

def pwm_mode(channel, mode, start)
end

#pwm_range(channel, range) ⇒ Object



65
66
# File 'lib/pi_piper/stub_driver.rb', line 65

def pwm_range(channel, range)
end

#release_pin(pin_number) ⇒ Object



105
106
107
# File 'lib/pi_piper/stub_driver.rb', line 105

def release_pin(pin_number)
  @pins.delete(pin_number)
end

#release_pinsObject



101
102
103
# File 'lib/pi_piper/stub_driver.rb', line 101

def release_pins
  @pins.keys.each { |pin_number| release_pin(pin_number) }
end

#spi_beginObject



76
77
78
79
# File 'lib/pi_piper/stub_driver.rb', line 76

def spi_begin
  @logger.debug("SPI Begin")
  @spi[:data] = []
end

#spi_chip_select(chip = nil) ⇒ Object



86
87
88
89
90
# File 'lib/pi_piper/stub_driver.rb', line 86

def spi_chip_select(chip = nil)
  chip = chip || @spi[:chip_select]
  @logger.debug("SPI Chip Select = #{chip}")
  @spi[:chip_select] = chip
end

#spi_transfer_bytes(data) ⇒ Object



81
82
83
84
# File 'lib/pi_piper/stub_driver.rb', line 81

def spi_transfer_bytes(data)
  @logger.debug("SPI CS#{@spi[:chip_select]} <- #{data.to_s}")
  @spi[:data] = Array(data)
end

#spidev_out(array) ⇒ Object



71
72
73
74
# File 'lib/pi_piper/stub_driver.rb', line 71

def spidev_out(array)
  @spi[:data] = array
  @logger.debug("SPIDEV -> #{array.pack('C*')}")
end