Class: RPi

Inherits:
Object
  • Object
show all
Defined in:
lib/rpi.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = []) ⇒ RPi

Returns a new instance of RPi.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rpi.rb', line 10

def initialize(x=[])
  
  a = case x
  when Integer
    [x]    
  when Fixnum
    [x]
  when String
    [x]
  when Array
    x
  end
  
  @pins = a.map {|pin| RPiPinOut.new pin }
  
  def @pins.[](i)

    if i.to_i >= self.length then
      puts "RPi warning: RPiPinOut instance #{i.inspect} not found"
      PinX::Void.new
    else
      self.at(i)
    end 
  end    

end

Class Method Details

.[](i) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rpi.rb', line 25

def @pins.[](i)

  if i.to_i >= self.length then
    puts "RPi warning: RPiPinOut instance #{i.inspect} not found"
    PinX::Void.new
  else
    self.at(i)
  end 
end

Instance Method Details

#pin ⇒ Object



37
# File 'lib/rpi.rb', line 37

def pin()   @pins.first  end

#pins ⇒ Object



38
# File 'lib/rpi.rb', line 38

def pins()  @pins        end