diff options
author | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-05-04 17:01:01 +0100 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-05-04 17:01:01 +0100 |
commit | 8c76e10aeafc16bbd136e2f4f3991855b10a1ab2 (patch) | |
tree | 7bc01553497681015e47c2af1313b3b0df81a495 | |
parent | f7025d4317adde917d0cc0de2d119c1843b5559a (diff) |
gpio: improved testing output
Signed-off-by: Milosz Wasilewski <milosz.wasilewski@linaro.org>
-rw-r--r-- | gpiotest/writer.py | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/gpiotest/writer.py b/gpiotest/writer.py index 102c4a1..51c4b5b 100644 --- a/gpiotest/writer.py +++ b/gpiotest/writer.py @@ -1,27 +1,42 @@ """ This is a simple GPIO manipulation program. It works together with Sensor board mezzanine and arduino program. The program writes -value 1 (HIGH) to GPIO_A which should be connected to arduino +value 1 (HIGH) to GPIO_A which should be connected to arduino digital pin 4. Than it reads value from GPIO_B which should be connected to arduino digital pin 5. """ import mraa +import unittest from time import sleep -print (mraa.getVersion()) -# GPIO_A on 96boards -output = mraa.Gpio(23) -output.dir(mraa.DIR_OUT) - -# GPIO_B on 96boards -input = mraa.Gpio(24) -input.dir(mraa.DIR_IN) - -print "Initial input value: %s" % input.read() -# ToDo: check the value and report test result -output.write(1) -sleep(10) -print "Final input value: %s" % input.read() -# ToDo: check the value and report test result -output.write(0) +class GpioTestCase(unittest.TestCase): + def setUp(self): + # GPIO_A on 96boards + self.output = mraa.Gpio(23) + self.output.dir(mraa.DIR_OUT) + + # GPIO_B on 96boards + self.input = mraa.Gpio(24) + self.input.dir(mraa.DIR_IN) + + def test_gpio_initial_value(self): + print "Initial input value: %s" % self.input.read() + self.assertEqual(self.input.read(), 0) + + def test_gpio_write_high(self): + self.output.write(1) + sleep(10) + print "First read input value (expecting 1): %s" % self.input.read() + self.assertEqual(self.input.read(), 1) + + def test_gpio_write_low(self): + output.write(0) + sleep(10) + print "Second read input value (expecting 0): %s" % self.input.read() + self.assertEqual(self.input.read(), 0) + + +if __name__ == '__main__': + print (mraa.getVersion()) + unittest.main(verbosity=2, buffer=True) |