1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 12:53:22 +00:00

Initial commit, working GPIO for all available CHIP GPIO pins, have not tested edge detection and callbacks

This commit is contained in:
xtacocorex
2016-02-24 21:48:40 -06:00
parent 3f17904ea1
commit 01ae605491
24 changed files with 2707 additions and 2 deletions

Binary file not shown.

Binary file not shown.

35
test/gptest.py Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/python
import CHIP_IO.GPIO as GPIO
import time, os
print "SETUP CSIDO"
GPIO.setup("CSID0", GPIO.OUT)
#print os.path.exists('/sys/class/gpio/gpio132')
print "SETUP XIO-P1"
GPIO.setup("XIO-P1", GPIO.IN)
#GPIO.setup("U14_13", GPIO.IN)
print "READING XIO-P1"
GPIO.output("CSID0", GPIO.HIGH)
print "HIGH", GPIO.input("XIO-P1")
GPIO.output("CSID0", GPIO.LOW)
GPIO.output("CSID0", GPIO.LOW)
time.sleep(1)
print "LOW", GPIO.input("XIO-P1")
GPIO.output("CSID0", GPIO.HIGH)
GPIO.output("CSID0", GPIO.HIGH)
print "HIGH", GPIO.input("XIO-P1")
time.sleep(1)
GPIO.output("CSID0", GPIO.LOW)
GPIO.output("CSID0", GPIO.LOW)
print "LOW", GPIO.input("XIO-P1")
print "CLEANUP"
GPIO.cleanup()

24
test/test_gpio_input.py Executable file
View File

@ -0,0 +1,24 @@
import pytest
import os
import time
import CHIP_IO.GPIO as GPIO
def teardown_module(module):
GPIO.cleanup()
class TestGPIOInput:
def test_input(self):
GPIO.setup("CSID6", GPIO.IN)
#returned as an int type
input_value = GPIO.input("CSID6")
#value read from the file will have a \n new line
value = open('/sys/class/gpio/gpio138/value').read()
assert int(value) == input_value
time.sleep(30)
GPIO.cleanup()
def test_direction_readback(self):
GPIO.setup("CSID6", GPIO.IN)
direction = GPIO.gpio_function("CSID6")
assert direction == GPIO.IN

44
test/test_gpio_output.py Normal file
View File

@ -0,0 +1,44 @@
import pytest
import os
import CHIP_IO.GPIO as GPIO
def teardown_module(module):
GPIO.cleanup()
class TestGPIOOutput:
def test_output_high(self):
GPIO.setup("CSID6", GPIO.OUT)
GPIO.output("CSID6", GPIO.HIGH)
value = open('/sys/class/gpio/gpio138/value').read()
assert int(value)
GPIO.cleanup()
def test_output_low(self):
GPIO.setup("CSID6", GPIO.OUT)
GPIO.output("CSID6", GPIO.LOW)
value = open('/sys/class/gpio/gpio138/value').read()
assert not int(value)
GPIO.cleanup()
def test_direction_readback(self):
GPIO.setup("CSID6", GPIO.OUT)
direction = GPIO.gpio_function("CSID6")
assert direction == GPIO.OUT
def test_output_greater_than_one(self):
GPIO.setup("CSID6", GPIO.OUT)
GPIO.output("CSID6", 2)
value = open('/sys/class/gpio/gpio138/value').read()
assert int(value)
GPIO.cleanup()
def test_output_of_pin_not_setup(self):
with pytest.raises(RuntimeError):
GPIO.output("CSID7", GPIO.LOW)
GPIO.cleanup()
def test_output_setup_as_input(self):
GPIO.setup("CSID6", GPIO.IN)
with pytest.raises(RuntimeError):
GPIO.output("CSID6", GPIO.LOW)
GPIO.cleanup()

72
test/test_gpio_setup.py Normal file
View File

@ -0,0 +1,72 @@
import pytest
import os
import CHIP_IO.GPIO as GPIO
def teardown_module(module):
GPIO.cleanup()
class TestSetup:
def test_setup_output_key(self):
GPIO.setup("U14_37", GPIO.OUT)
assert os.path.exists('/sys/class/gpio/gpio138')
direction = open('/sys/class/gpio/gpio138/direction').read()
assert direction == 'out\n'
GPIO.cleanup()
def test_setup_output_name(self):
GPIO.setup("CSID6", GPIO.OUT)
assert os.path.exists('/sys/class/gpio/gpio138')
direction = open('/sys/class/gpio/gpio138/direction').read()
assert direction == 'out\n'
GPIO.cleanup()
def test_setup_input_key(self):
GPIO.setup("U14_37", GPIO.IN)
assert os.path.exists('/sys/class/gpio/gpio138')
direction = open('/sys/class/gpio/gpio138/direction').read()
assert direction == 'in\n'
GPIO.cleanup()
def test_setup_input_name(self):
GPIO.setup("CSID6", GPIO.IN)
assert os.path.exists('/sys/class/gpio/gpio138')
direction = open('/sys/class/gpio/gpio138/direction').read()
assert direction == 'in\n'
GPIO.cleanup()
def test_setup_input_pull_up(self):
GPIO.setup("U14_37", GPIO.IN, pull_up_down=GPIO.PUD_UP)
assert os.path.exists('/sys/class/gpio/gpio138')
direction = open('/sys/class/gpio/gpio138/direction').read()
assert direction == 'in\n'
GPIO.cleanup()
def test_setup_input_pull_down(self):
GPIO.setup("U14_37", GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
assert os.path.exists('/sys/class/gpio/gpio138')
direction = open('/sys/class/gpio/gpio138/direction').read()
assert direction == 'in\n'
GPIO.cleanup()
def test_setup_cleanup(self):
GPIO.setup("U14_37", GPIO.OUT)
assert os.path.exists('/sys/class/gpio/gpio138')
GPIO.cleanup()
assert not os.path.exists('/sys/class/gpio/gpio138')
def test_setup_failed_type_error(self):
with pytest.raises(TypeError):
GPIO.setup("U14_37", "WEIRD")
GPIO.cleanup()
def test_setup_failed_value_error(self):
with pytest.raises(ValueError):
GPIO.setup("U14_37", 3)
GPIO.cleanup()
def test_setup_expanded_gpio(self):
GPIO.setup("XIO-P1", GPIO.OUT)
assert os.path.exists('/sys/class/gpio/gpio409')
GPIO.cleanup()
assert not os.path.exists('/sys/class/gpio/gpio409')