Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

File.new f.rewind f.getc is a bit faster than IO.new IO.sysopen accor…

…ding to the benchmrks
  • Loading branch information...
commit b354a59ed94539a62b4e65831ee781baf9a58073 1 parent 25d138f
@klappy authored
Showing with 5 additions and 5 deletions.
  1. +2 −2 lib/gpio/device.rb
  2. +3 −3 lib/gpio/pin.rb
View
4 lib/gpio/device.rb
@@ -41,13 +41,13 @@ def unexport!(software_pin)
!exported? software_pin
end
- def pin_io(software_pin, mode)
+ def pin_file(software_pin, mode)
m = case mode.to_s
when 'in'; 'r'
when 'out'; 'w'
when 'bi'; 'r+'
end
- IO.new IO.sysopen(value_path(software_pin)), m
+ File.new value_path(software_pin), m
end
def read(software_pin)
View
6 lib/gpio/pin.rb
@@ -1,6 +1,6 @@
module GPIO
class Pin
- attr_reader :pin, :mode, :device, :hardware_pin, :software_pin, :io
+ attr_reader :pin, :mode, :device, :hardware_pin, :software_pin, :file
def initialize(params) #(pin, mode, device=:RaspberryPi)
@device = GPIO.const_get(params[:device]||:RaspberryPi)
@@ -13,11 +13,11 @@ def initialize(params) #(pin, mode, device=:RaspberryPi)
device.initialize_pin(software_pin, @mode)
@mode ||= get_direction
- @io = @device.pin_io(pin, mode)
+ @file = @device.pin_file(pin, mode)
end
def read
- io.rewind; io.getc
+ file.rewind; file.getc
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.