def test_input(self):
     GPIO.setup("P8_10", GPIO.IN)
     #returned as an int type
     input_value = GPIO.input("P8_10")
     #value read from the file will have a \n new line
     value = open('/sys/class/gpio/gpio68/value').read()
     assert int(value) == input_value
     GPIO.cleanup()
示例#2
0
def choose_tc(num):
	if num > 8 or num < 1:
		print "invalid choice"
		return
	bits = "{0:03b}".format(num - 1)
#        logging.debug('bits: %s'%bits)
	GPIO.output("P8_12", int(bits[0]))
	GPIO.output("P8_14", int(bits[1]))
	GPIO.output("P8_16", int(bits[2]))
示例#3
0
#!/usr/bin/python

import BBIO.GPIO as GPIO
import time

GPIO.setup("P9_15", GPIO.OUT)	# Set BBB pin as output.
print 'Reseteando el mbed...'
GPIO.output("P9_15", GPIO.LOW)	# Set pin as low to reset the Mbed.
time.sleep(0.5)			# Wait 0.2 seconds.
GPIO.output("P9_15", GPIO.HIGH)	# Set pins as high.
GPIO.cleanup()			# Unexport pin from user space.
示例#4
0
#!/usr/bin/python

import BBIO.GPIO as GPIO
import time

GPIO.setup("P9_15", GPIO.OUT)  # Set BBB pin as output.
print 'Reseteando el mbed...'
GPIO.output("P9_15", GPIO.LOW)  # Set pin as low to reset the Mbed.
time.sleep(0.5)  # Wait 0.2 seconds.
GPIO.output("P9_15", GPIO.HIGH)  # Set pins as high.
GPIO.cleanup()  # Unexport pin from user space.
def teardown_module(module):
    GPIO.cleanup()
 def test_output_high(self):
     GPIO.setup("P8_10", GPIO.OUT)
     GPIO.output("P8_10", GPIO.HIGH)
     value = open('/sys/class/gpio/gpio68/value').read()
     assert int(value)
     GPIO.cleanup()
import BBIO.GPIO as GPIO
GPIO.setup("P8_12", GPIO.OUT)
GPIO.setup("P8_14", GPIO.OUT)
GPIO.setup("P8_16", GPIO.OUT)

GPIO.output("P8_12", GPIO.HIGH)
GPIO.output("P8_14", GPIO.HIGH)
GPIO.output("P8_16", GPIO.HIGH)
 def test_output_of_pin_not_setup(self):
     with pytest.raises(RuntimeError):
         GPIO.output("P8_11", GPIO.LOW)
         GPIO.cleanup() 
 def test_output_setup_as_input(self):
     GPIO.setup("P8_10", GPIO.IN)
     with pytest.raises(RuntimeError):
         GPIO.output("P8_10", GPIO.LOW)
         GPIO.cleanup()
 def test_setup_output_key(self):
     GPIO.setup("P8_10", GPIO.OUT)
     assert os.path.exists('/sys/class/gpio/gpio68')
     direction = open('/sys/class/gpio/gpio68/direction').read()
     assert direction == 'out\n'        
     GPIO.cleanup()
 def test_output_greater_than_one(self):
     GPIO.setup("P8_10", GPIO.OUT)
     GPIO.output("P8_10", 2)
     value = open('/sys/class/gpio/gpio68/value').read()
     assert int(value)
     GPIO.cleanup()
 def test_setup_failed_value_error(self):
     with pytest.raises(ValueError):
         GPIO.setup("P8_10", 3)
         GPIO.cleanup()
 def test_setup_failed_type_error(self):
     with pytest.raises(TypeError):
         GPIO.setup("P8_10", "WEIRD")
         GPIO.cleanup()
 def test_setup_cleanup(self):
     GPIO.setup("P8_10", GPIO.OUT)
     assert os.path.exists('/sys/class/gpio/gpio68')
     GPIO.cleanup()
     assert not os.path.exists('/sys/class/gpio/gpio68')
 def test_setup_input_pull_down(self):
     GPIO.setup("P8_10", GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
     assert os.path.exists('/sys/class/gpio/gpio68')
     direction = open('/sys/class/gpio/gpio68/direction').read()
     assert direction == 'in\n'        
     GPIO.cleanup()
 def test_setup_input_name(self):
     GPIO.setup("TIMER6", GPIO.IN)
     assert os.path.exists('/sys/class/gpio/gpio68')
     direction = open('/sys/class/gpio/gpio68/direction').read()
     assert direction == 'in\n'        
     GPIO.cleanup()