Class: GPIO::Pin

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

Direct Known Subclasses

InputPin, OutputPin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Pin

(pin, mode, device=:RaspberryPi)



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gpio/pin.rb', line 4

def initialize(params) #(pin, mode, device=:RaspberryPi)
	@device = GPIO.const_get(params[:device]||:RaspberryPi)

	@pin = params[:pin].to_int
	@hardware_pin = device.hardware_pin(pin)
	@software_pin = device.software_pin(pin)

	@mode = params[:mode].to_s
	raise "Mode should be :in, :out, :bi, :pwm." unless ['in','out'].include? @mode

	device.initialize_pin(software_pin, @mode)
	@mode ||= get_direction
	@file = @device.pin_file(pin, mode)
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



3
4
5
# File 'lib/gpio/pin.rb', line 3

def device
  @device
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/gpio/pin.rb', line 3

def file
  @file
end

#hardware_pinObject (readonly)

Returns the value of attribute hardware_pin.



3
4
5
# File 'lib/gpio/pin.rb', line 3

def hardware_pin
  @hardware_pin
end

#modeObject (readonly)

Returns the value of attribute mode.



3
4
5
# File 'lib/gpio/pin.rb', line 3

def mode
  @mode
end

#pinObject (readonly)

Returns the value of attribute pin.



3
4
5
# File 'lib/gpio/pin.rb', line 3

def pin
  @pin
end

#software_pinObject (readonly)

Returns the value of attribute software_pin.



3
4
5
# File 'lib/gpio/pin.rb', line 3

def software_pin
  @software_pin
end

Instance Method Details

#readObject



19
20
21
# File 'lib/gpio/pin.rb', line 19

def read
	file.rewind; file.getc
end