From 34f5a8fb975d78addd9b184f3d01e996b71f004e Mon Sep 17 00:00:00 2001 From: rpurdon Date: Sun, 7 Feb 2016 18:54:22 +0200 Subject: [PATCH] bugfix: close file streams - this is needed for raspi, else it cannot access the files againafter program has been terminated --- lib/artoo/adaptors/io/digital_pin.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/artoo/adaptors/io/digital_pin.rb b/lib/artoo/adaptors/io/digital_pin.rb index 6de70273..337fca6b 100644 --- a/lib/artoo/adaptors/io/digital_pin.rb +++ b/lib/artoo/adaptors/io/digital_pin.rb @@ -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 @@ -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 @@ -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