pytools/gpioutil: Don't set direction if already set

Writing "out" to GPIO direction will actually clear the output value.
This makes it impossible to read the value of outputs with gpioutil
since it always sets value to 0 before reading it.

Fix: don't write direction if the direction already matches that
requested.

Change-Id: I2116e6c7f5800239dd89c4f47fe7fd087b3a87cd
Signed-off-by: Xo Wang <xow@google.com>
diff --git a/pytools/gpioutil b/pytools/gpioutil
index 0654cd9..5ed13e2 100644
--- a/pytools/gpioutil
+++ b/pytools/gpioutil
@@ -59,10 +59,11 @@
 			self.write(self.getPath('edge'),self.interrupt)
 		else:
 			raise Exception("ERROR - Invalid Direction: "+dir)
-		
-			
-		self.write(self.getPath('direction'),self.direction)
-			
+
+		current_direction = self.read(self.getPath('direction'))
+		if current_direction != self.direction:
+			self.write(self.getPath('direction'),self.direction)
+
 	def setValue(self,value):
 		if (value == '0'):
 			self.write(self.getPath('value'),'0')