Skip to content

Commit

Permalink
Merge pull request #162 from banchee/bugfix/io-digital-write-file-close
Browse files Browse the repository at this point in the history
bugfix: close file streams - this is needed for raspi, else it cannot…
  • Loading branch information
deadprogram committed Feb 15, 2016
2 parents eab3f0f + 4d88792 commit 35d1d84
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/artoo/adaptors/io/digital_pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(pin_num, mode)
@pin_num = pin_num

File.open("#{ GPIO_PATH }/export", "w") { |f| f.write("#{ pin_num }") }

File.close
# Sets the pin for read or write
set_mode(mode)
end
Expand Down Expand Up @@ -60,6 +60,7 @@ def set_pin(settings)
mode = settings[:mode]
direction = settings[:direction]
File.open("#{ GPIO_PATH }/gpio#{ pin_num }/direction", "w") { |f| f.write(direction) }
File.close
@pin_file = File.open("#{ GPIO_PATH }/gpio#{ pin_num }/value", mode)
end

Expand All @@ -85,6 +86,8 @@ def off!
def close
off! if @mode == 'w'
File.open("#{ GPIO_PATH }/unexport", "w") { |f| f.write("#{pin_num}") }
File.close
@pin_file.close
end
end
end
Expand Down

0 comments on commit 35d1d84

Please sign in to comment.